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

Re: [PATCH 2/4] ARM/vgic: Correct the expression for lr_all_full()


  • To: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Xen-devel <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Michal Orzel <michal.orzel@xxxxxxx>
  • Date: Tue, 3 Sep 2024 10:42:26 +0200
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=citrix.com smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0)
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=0OtoUIB3vNakXl0AincEeUFF41hacaC/stvMFeYizaI=; b=R42hKEkM1/HAh7o/98laGPs1Hq4R/CSBfqJS4VHIg3WnQ0YLXfEVTduXmYeaClzu4J1CMXJ7Z4WtT3J2dzzE+WLzhF8tfkgTodZtW0OO1ajs+xg2fGyVeOt4XYXdFCaLHeRJucveOxYCChs4LjhbuDVxtsKtNIiRhJ7tOvVwib8ye5ChwiU7Y++rOnoWFvQlopKMxAo+N6SLfTLWP5/EDJerKtD4+k1HhMfs02f0m20f31Ml9mUs4/v6KTrqsI+TGAEd6esKVbkpdZ7NrlXsUSgG9caY6va+p6zdRBks94zFryzLyUYYVBxIHmXrMN/O11Pyk8DizZX3aRIB8L1lFw==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=uXEyI9Z+9oPh1o3yLva+UZJLun0cX8eS7oyDcGhaC2yT7Kzu0szvJfb+RIG3zuV7oEv/AlYdtSqWyi7N+gdAc3Y93s6F0SeT2BF3BN20gFduUSKZsF+KfZnzDHHoF0Tsj3IM/2BxLVCXNoOs/mUyQ0DJZC12/u5rJQZN1MePnbezi/tFGMOI/zuZ/l8GNrqAYU+rsdZUr6Ti3EIWuHAQKt/ko2GcXTqni4HqkYDHEs/D7hXiomyFK8vr+QY3M0/fZpR3U5JzTiziUljCw9pUjtTrIEwRswrnIXw/kc6NThQxvEJLpqj05DVN+vuM2CNx6N1nYcfk5l1Q+WGEaEKrZg==
  • Cc: Stefano Stabellini <sstabellini@xxxxxxxxxx>, Julien Grall <julien@xxxxxxx>, Volodymyr Babchuk <Volodymyr_Babchuk@xxxxxxxx>, "Bertrand Marquis" <bertrand.marquis@xxxxxxx>
  • Delivery-date: Tue, 03 Sep 2024 08:42:42 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>


On 02/09/2024 12:03, Andrew Cooper wrote:
> 
> 
> The current expression hits UB with 31 LRs (shifting into the sign bit), and
> malfunctions with 32 LRs (shifting beyond the range of int).  Swapping 1 for
> 1ULL fixes some of these, but still malfunctions at 64 LRs which is the
> architectural limit.
> 
> Instead, shift -1ULL right in order to create the mask.
> 
> Fixes: 596f885a3202 ("xen/arm: set GICH_HCR_UIE if all the LRs are in use")
> Signed-off-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
Reviewed-by: Michal Orzel <michal.orzel@xxxxxxx>

> ---
> CC: Stefano Stabellini <sstabellini@xxxxxxxxxx>
> CC: Julien Grall <julien@xxxxxxx>
> CC: Volodymyr Babchuk <Volodymyr_Babchuk@xxxxxxxx>
> CC: Bertrand Marquis <bertrand.marquis@xxxxxxx>
> CC: Michal Orzel <michal.orzel@xxxxxxx>
> 
> Found by code inspection while doing bitops work.  I don't even know if
> there's a platform that really has 31 LRs, but the rest of Xen's code is
> written with the expectation that there may be 64.
So, for GICv2 the limit is 64 and for GICv3 the limit is 16. This made me 
realize we need to
fix the mask for GICv3 (ICH_VTR_NRLRGS) from 0x3f to 0xf. I'll send a patch.

> ---
>  xen/arch/arm/gic-vgic.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/xen/arch/arm/gic-vgic.c b/xen/arch/arm/gic-vgic.c
> index 9aa245a36d98..3f14aab2efc7 100644
> --- a/xen/arch/arm/gic-vgic.c
> +++ b/xen/arch/arm/gic-vgic.c
> @@ -16,7 +16,8 @@
>  #include <asm/gic.h>
>  #include <asm/vgic.h>
> 
> -#define lr_all_full() (this_cpu(lr_mask) == ((1 << gic_get_nr_lrs()) - 1))
> +#define lr_all_full()                                           \
> +    (this_cpu(lr_mask) == (-1ULL >> (64 - gic_get_nr_lrs())))
> 
>  #undef GIC_DEBUG
> 
> --
> 2.39.2
> 

~Michal



 


Rackspace

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