From: Michal Orzel <michal.orzel@amd.com>
To: Andrew Cooper <andrew.cooper3@citrix.com>,
Xen-devel <xen-devel@lists.xenproject.org>
Cc: Stefano Stabellini <sstabellini@kernel.org>,
Julien Grall <julien@xen.org>,
Volodymyr Babchuk <Volodymyr_Babchuk@epam.com>,
"Bertrand Marquis" <bertrand.marquis@arm.com>
Subject: Re: [PATCH 2/4] ARM/vgic: Correct the expression for lr_all_full()
Date: Tue, 3 Sep 2024 10:42:26 +0200 [thread overview]
Message-ID: <4feb41ff-eecb-4cc0-ab2b-57e8a526da0e@amd.com> (raw)
In-Reply-To: <20240902100355.3032079-3-andrew.cooper3@citrix.com>
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@citrix.com>
Reviewed-by: Michal Orzel <michal.orzel@amd.com>
> ---
> CC: Stefano Stabellini <sstabellini@kernel.org>
> CC: Julien Grall <julien@xen.org>
> CC: Volodymyr Babchuk <Volodymyr_Babchuk@epam.com>
> CC: Bertrand Marquis <bertrand.marquis@arm.com>
> CC: Michal Orzel <michal.orzel@amd.com>
>
> 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
next prev parent reply other threads:[~2024-09-03 8:42 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-09-02 10:03 [PATCH 0/4] ARM: Cleanup following bitops improvements Andrew Cooper
2024-09-02 10:03 ` [PATCH 1/4] ARM/div: Drop __div64_fls() Andrew Cooper
2024-09-03 8:37 ` Michal Orzel
2024-09-02 10:03 ` [PATCH 2/4] ARM/vgic: Correct the expression for lr_all_full() Andrew Cooper
2024-09-03 8:42 ` Michal Orzel [this message]
2024-09-02 10:03 ` [PATCH 3/4] ARM/vgic: Use for_each_set_bit() in gic_find_unused_lr() Andrew Cooper
2024-09-03 8:46 ` Michal Orzel
2024-09-03 13:07 ` Andrew Cooper
2024-09-02 10:03 ` [PATCH 4/4] ARM/vgic: Use for_each_set_bit() in vgic-mmio* Andrew Cooper
2024-09-03 10:30 ` Michal Orzel
2024-09-03 13:19 ` Andrew Cooper
2024-09-09 21:54 ` Julien Grall
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4feb41ff-eecb-4cc0-ab2b-57e8a526da0e@amd.com \
--to=michal.orzel@amd.com \
--cc=Volodymyr_Babchuk@epam.com \
--cc=andrew.cooper3@citrix.com \
--cc=bertrand.marquis@arm.com \
--cc=julien@xen.org \
--cc=sstabellini@kernel.org \
--cc=xen-devel@lists.xenproject.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.