All of lore.kernel.org
 help / color / mirror / Atom feed
From: Eric Auger <eric.auger@redhat.com>
To: Andrew Jones <drjones@redhat.com>, kvm@vger.kernel.org
Subject: Re: [PATCH kvm-unit-tests] arm64: gic-v3: Avoid NULL dereferences
Date: Tue, 12 Oct 2021 08:53:44 +0200	[thread overview]
Message-ID: <28da2e28-34dc-5516-678b-be4b4153c0ae@redhat.com> (raw)
In-Reply-To: <20211011160420.26785-1-drjones@redhat.com>

Hi Drew,
On 10/11/21 6:04 PM, Andrew Jones wrote:
> LPI allocation requires that the redistributors are configured first.
> It's unlikely that offline cpus have had their redistributors
> configured, so filter them out right away. Also, assert on any cpu,
> not just the calling cpu, in gicv3_lpi_alloc_tables() when we detect
> a unit test failed to follow instructions. Improve the assert with a
> hint message while we're at it.
>
> Cc: Eric Auger <eric.auger@redhat.com>
> Signed-off-by: Andrew Jones <drjones@redhat.com>
Reviewed-by: Eric Auger <eric.auger@redhat.com>

Eric
> ---
>  lib/arm/gic-v3.c       | 6 +++---
>  lib/arm64/gic-v3-its.c | 2 +-
>  2 files changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/lib/arm/gic-v3.c b/lib/arm/gic-v3.c
> index 2c067e4e9ba2..2f7870ab28bf 100644
> --- a/lib/arm/gic-v3.c
> +++ b/lib/arm/gic-v3.c
> @@ -171,17 +171,17 @@ void gicv3_lpi_alloc_tables(void)
>  	u64 prop_val;
>  	int cpu;
>  
> -	assert(gicv3_redist_base());
> -
>  	gicv3_data.lpi_prop = alloc_pages(order);
>  
>  	/* ID bits = 13, ie. up to 14b LPI INTID */
>  	prop_val = (u64)(virt_to_phys(gicv3_data.lpi_prop)) | 13;
>  
> -	for_each_present_cpu(cpu) {
> +	for_each_online_cpu(cpu) {
>  		u64 pend_val;
>  		void *ptr;
>  
> +		assert_msg(gicv3_data.redist_base[cpu], "Redistributor for cpu%d not initialized. "
> +							"Did cpu%d enable the GIC?", cpu, cpu);
>  		ptr = gicv3_data.redist_base[cpu];
>  
>  		writeq(prop_val, ptr + GICR_PROPBASER);
> diff --git a/lib/arm64/gic-v3-its.c b/lib/arm64/gic-v3-its.c
> index c22bda3a8ba2..2c69cfda0963 100644
> --- a/lib/arm64/gic-v3-its.c
> +++ b/lib/arm64/gic-v3-its.c
> @@ -104,7 +104,7 @@ void its_enable_defaults(void)
>  	/* Allocate LPI config and pending tables */
>  	gicv3_lpi_alloc_tables();
>  
> -	for_each_present_cpu(cpu)
> +	for_each_online_cpu(cpu)
>  		gicv3_lpi_rdist_enable(cpu);
>  
>  	writel(GITS_CTLR_ENABLE, its_data.base + GITS_CTLR);


      reply	other threads:[~2021-10-12  6:54 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-11 16:04 [PATCH kvm-unit-tests] arm64: gic-v3: Avoid NULL dereferences Andrew Jones
2021-10-12  6:53 ` Eric Auger [this message]

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=28da2e28-34dc-5516-678b-be4b4153c0ae@redhat.com \
    --to=eric.auger@redhat.com \
    --cc=drjones@redhat.com \
    --cc=kvm@vger.kernel.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.