[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] x86emul: recognize CLDEMOTE


  • To: Jan Beulich <jbeulich@xxxxxxxx>
  • From: Roger Pau Monné <roger.pau@xxxxxxxxxx>
  • Date: Tue, 25 Jan 2022 15:35:58 +0100
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=bZuHOmjuRJ7LVEPOKb7OCO65RnBMkUFp8aDB2S5upjg=; b=VRqx1oOQaWK6LTLWYcsJSgXu7PniHw69ixs47kLZe8sCxEhseVgX6vHKFQjJq/MX08DwyTC/bEZpGSNPIMVwk7qbE37kYVGmb9TwIjc/MFrsvHvSJlddDUOHxcYFtj9NUOS09pYd4t/+I5lpMUu0kWNKX+gBqeb2gqRMWkWRTQ6UtVjymS85skk7VNA1hd6NfxpwLc5XcqiluK6ksuqOseWGxofMCxvp+TJ9WJ6CWnkb3oqU+7K6YW+qXXBa+Og4VkueOs349i6iC8UmS1BWIMAx2zG92pK1gEKBH3+0mvWmm3wQju3faKuFQ0ifJ4fBag0heLauTs01Yj226JOebA==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=FqKzL4lOQ0lJIVn0ibqFZA/9F1ZS2IO8woLAojJ0jMML3T2o99weVU6pVqksGZCRij316Lb9/qu7+syeqKGOP0KqBJhNM3db1wGb/KoQlDkQGDHnde5XSqoj3GSHJdrBHDrtNgJv460POrX18AmKrSAiu01gEAgzKT8cj+L9zaiA/RW+2I1i47UuU1h4ZBvcDgnT1tkjRU/Vd0RVzW0RlBBvEGSBFP3YskYOVF2QLslhhIJqqjqOSkfKTATcG/AdBeZ/IDFadcLzePeZnvAxb1QHhdhT8DnwMPLOYGCwcBV9oBODvmxiku+p7igEoknss/5JAjHTlE1QXZJXEVdDCA==
  • Authentication-results: esa4.hc3370-68.iphmx.com; dkim=pass (signature verified) header.i=@citrix.onmicrosoft.com
  • Cc: "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>, "Andrew Cooper" <andrew.cooper3@xxxxxxxxxx>, Wei Liu <wl@xxxxxxx>
  • Delivery-date: Tue, 25 Jan 2022 14:36:28 +0000
  • Ironport-data: A9a23:h+4c6K7T/A/EsXJIXxT9ygxRtN7AchMFZxGqfqrLsTDasY5as4F+v mJLWG+FOfyDYWLxLtpxYIm+9UoDvJGEm9Q2GgM+qnwwHi5G8cbLO4+Ufxz6V8+wwmwvb67FA +E2MISowBUcFyeEzvuV3zyIQUBUjclkfJKlYAL/En03FV8MpBsJ00o5wbZg2NMw27BVPivW0 T/Mi5yHULOa82Yc3lI8s8pvfzs24ZweEBtB1rAPTagjUG32zhH5P7pGTU2FFFPqQ5E8IwKPb 72rIIdVXI/u10xF5tuNyt4Xe6CRK1LYFVDmZnF+A8BOjvXez8CbP2lS2Pc0MC9qZzu1c99Zw 9lUjM2/ShYSHoLip+hGaTpmSgteBPgTkFPHCSDXXc27ykTHdz3nwul0DVFwNoodkgp1KTgQr 7pCcmlLN03dwbLtqF64YrAEasALNs7kMZlZonh95TrYEewnUdbIRKCiCdpwgmtg2ZARR6y2i 8wxVxg2YT7fbAR1ZV4zMJB5zd2tm3LzWmgNwL6SjfVuuDWCpOBr65DyNPLFd9rMQt9a9m6Iq 2SD82nnDxUyMN2E1SHD4n+qnvXIny7wRMQVDrLQ3vxgjUCXx2cTIAYLTlb9qv684nNSQPoGd RZSoHB36/Fvqgr7FbERQiFUvlaPsgclCtVTAtYaxy+yxvHuwDjALEg9G2sphMMdiOc6Qjkj1 1msltzvBCByvLD9dU9x5ot4vhvpZ3FLcDZqiTssCFJcvo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hD0JczpzfHcGIzWvUvECZe WhD4d81nGdUEVSSv7+KmgOXuDFqdGOvJX6YSQeDxpizAWVlzun5JPzDhDdh34lIn5y6IZn1V KAvx3y562lvf3+4hjA11XL55ATvNf60NNMCOGFl8BQADTxjQSDYphnRtS5zXoIidDqzGxvvM jHoh8mMcg2w3TNflutqR+o4AXk2CZG0Q6V9XaoxV/Y5eDpTjMzDMRMwahDdAHC1kYmtNZglI pWwmOwrfNsfF39tRW4w+KNewBhl0Kyr3Znu/UUlWZjXYwXb6IUhZAD/XlSDIwLEEvBmc8a+d FVfYHhDcttABCnhyizhBgs/DXsZAV+Iv6+eDlChiTPuAIm2UyQzCMjtbsidzk7hdYAoqJ/lp f525JT5cVzp/8tHNJA7dg6MLmK40z2MFvx2TGpUBza/J9uAQO5l3ew2sRz2N2X
  • Ironport-sdr: gxxWkUsWrfMzhAgXnZC7C2my7h2bttfefnqosc2y+DVeUfJmZrwe5bRFMQWNh7YACoFaTjLPws L1kkHa/9/oiBTOr7wcI2ckpwupN+OadYf69C5+bPPN57kj9fYvkj2AsDnMq/tSmjBBzmlvizJz ui0kfZKqKghSeE/6S0fvoy7kl6AABT6SaxeuKvdLAFr1d656J0RurijB47NAhYXzPCpe5PTwez 5xgMel5G1KqKteFd7XsS8bQf3ErF4A+fZ4ocZMXmxf4aB+MKUb5kBHqtCNsWej32QTchd0Atrh H8AZMgwZXg0SRhtLuMe8NZS6
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On Tue, Jan 25, 2022 at 03:22:25PM +0100, Jan Beulich wrote:
> We claim to support the insn, but so far the emulator has been handling
> it as a NOP.

While not ideal, the SDM mentions that "The CLDEMOTE instruction may
be ignored by hardware in certain cases and is not a guarantee.".

> Signed-off-by: Jan Beulich <jbeulich@xxxxxxxx>
> ---
> While handling x86emul_cldemote separately in hvmemul_cache_op() means
> to carry some redundant code, folding it with CLFLUSH{,OPT} / CLWB
> didn't seem very attractive either.
> 
> --- a/xen/arch/x86/arch.mk
> +++ b/xen/arch/x86/arch.mk
> @@ -23,6 +23,7 @@ $(call as-option-add,CFLAGS,CC,"xsaveopt
>  $(call as-option-add,CFLAGS,CC,"rdseed %eax",-DHAVE_AS_RDSEED)
>  $(call as-option-add,CFLAGS,CC,"clac",-DHAVE_AS_CLAC_STAC)
>  $(call as-option-add,CFLAGS,CC,"clwb (%rax)",-DHAVE_AS_CLWB)
> +$(call as-option-add,CFLAGS,CC,"cldemote (%rax)",-DHAVE_AS_CLDEMOTE)
>  $(call as-option-add,CFLAGS,CC,".equ \"x\"$$(comma)1",-DHAVE_AS_QUOTED_SYM)
>  $(call as-option-add,CFLAGS,CC,"invpcid 
> (%rax)$$(comma)%rax",-DHAVE_AS_INVPCID)
>  $(call as-option-add,CFLAGS,CC,"movdiri 
> %rax$$(comma)(%rax)",-DHAVE_AS_MOVDIR)
> --- a/xen/arch/x86/hvm/emulate.c
> +++ b/xen/arch/x86/hvm/emulate.c
> @@ -2351,6 +2351,28 @@ static int hvmemul_cache_op(
>           * to be sensibly used is in (virtualization unaware) firmware.
>           */
>          break;
> +
> +    case x86emul_cldemote:
> +        ASSERT(!is_x86_system_segment(seg));
> +
> +        if ( !boot_cpu_has(X86_FEATURE_CLDEMOTE) ||
> +             hvmemul_virtual_to_linear(seg, offset, 0, NULL, hvm_access_none,
> +                                       hvmemul_ctxt, &addr) != X86EMUL_OKAY )
> +            break;
> +
> +        if ( hvmemul_ctxt->seg_reg[x86_seg_ss].dpl == 3 )
> +            pfec |= PFEC_user_mode;
> +
> +        mapping = hvmemul_map_linear_addr(addr, 0, pfec, hvmemul_ctxt);

I think the emulator should map the address using the same cache
attributes as the guest, or else the result might be different than
intended?

Thanks, Roger.



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.