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

Re: [PATCH] x86/hvm: Improve hvm_set_guest_pat() code generation again


  • To: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Edwin Török <edvin.torok@xxxxxxxxxx>
  • From: Jan Beulich <jbeulich@xxxxxxxx>
  • Date: Wed, 10 Aug 2022 16:06:54 +0200
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=suse.com; dmarc=pass action=none header.from=suse.com; dkim=pass header.d=suse.com; 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=wkCbFM/D2/rz8tgaTG4ZilBApXaCxtFpSGGlp/ns37M=; b=E6DHZmXQbsSbUiCjLp/rhMz2ZW/x4jLBrOpuSDakkwDq0cssI/4GjCfNkKYOcssQleDihDI74XA8uurquYNmCTv3I7nklTNFsM6iPL6mfl0x62zTxe7024E/oQdXLYCYJKVGrvM1v0BLTCYRJo1Q8g2oFB/craQiV+9dk/64nrtKCwMwhQXLEJC8jfrWOsF8vPqA/37/T2sK2bZPZ3KWM0imavmsy2LdgmjokOAVn2augPjTXSGmjf548QNJviRKg9IH1zBu7Lc7v4nZHXq86Y3BgvhFW4VWoIFgu6jCrC3l9Ab0naREzBuTg5dlzqwIN+R/Q5cMROcgP92yf0SBoA==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=BVdBGHSmXDtk1pAE+Sxn0LuElK0YLMXD9q9FMGnGvEolJilWNiu/hsncWu8ie4ECUhPQK/l4wcHVQ2Spumt75OYt+9W/NsribCEarqX5lcd3i3A1ldP7gHCiba0JV/2loX+bvMrUIKSco9mx4iUvXFKpTo03r7X36mj0AtwRYFM89ajZrN9zrohpp23L6YNyd+Vy2IZRzomtOJODhpOlf+e+EhkBIf8pUpaRRDK2ET3SGfokHcu+4uSs/iPFX9BJ0+9zXb1bgocZaZh2e8lehN9IsHZhOJek/547omw9AlQQK+VvisMo1tsApfiXUzMdULrIgUkG+pV2CI2Ngh5EoQ==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com;
  • Cc: Roger Pau Monné <roger.pau@xxxxxxxxxx>, Wei Liu <wl@xxxxxxx>, Xen-devel <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • Delivery-date: Wed, 10 Aug 2022 14:07:08 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On 10.08.2022 15:36, Andrew Cooper wrote:
> From: Edwin Török <edvin.torok@xxxxxxxxxx>
> 
> Following on from cset 9ce0a5e207f3 ("x86/hvm: Improve hvm_set_guest_pat()
> code generation"), and the discovery that Clang/LLVM makes some especially
> disastrous code generation for the loop at -O2
> 
>   https://github.com/llvm/llvm-project/issues/54644
> 
> Edvin decided to remove the loop entirely by fully vectorising it.  This is
> substantially more efficient than the loop, and rather harder for a typical
> compiler to mess up.
> 
> Signed-off-by: Edwin Török <edvin.torok@xxxxxxxxxx>
> Signed-off-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>

The main downside being that changing the code to fit in a new PAT
type will now be harder. I wonder in particular whether with that
in mind it wouldn't be better to express the check not in terms of
relations, but in terms of set / clear bits ("bits 3-7 clear AND
(bit 2 set OR bit 1 clear)"). The code kind of does so already, but
the variable names don't reflect that (and would hence need to
change in such an event).

> --- a/xen/arch/x86/hvm/hvm.c
> +++ b/xen/arch/x86/hvm/hvm.c
> @@ -302,24 +302,43 @@ void hvm_get_guest_pat(struct vcpu *v, u64 *guest_pat)
>          *guest_pat = v->arch.hvm.pat_cr;
>  }
>  
> -int hvm_set_guest_pat(struct vcpu *v, uint64_t guest_pat)
> +/*
> + * MSR_PAT takes 8 uniform fields, each of which must be a valid 
> architectural
> + * memory type (0, 1, 4-7).  This is a fully vectorised form of the
> + * 8-iteration loop over bytes looking for PAT_TYPE_* constants.

While grep-ing for PAT_TYPE_ will hit this line, I think we want
every individual type to also be found here when grep-ing for one.
The actual values aren't going to change, but perhaps the beast
way to do so would still be by way of BUILD_BUG_ON()s.

> + */
> +static bool pat_valid(uint64_t val)
>  {
> -    unsigned int i;
> -    uint64_t tmp;
> +    /* Yields a non-zero value in any lane which had value greater than 7. */
> +    uint64_t any_gt_7   =  val & 0xf8f8f8f8f8f8f8f8;

This and the other constant want to gain UL suffixes. (While I'm
open to be convinced otherwise on the earlier two points, this one
I'm going to insist on. Yet in case it would end up being the only
change in need of making, it could of course be done while
committing.)

Jan



 


Rackspace

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