From: Bjorn Helgaas <helgaas@kernel.org>
To: Logan Gunthorpe <logang@deltatee.com>
Cc: linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org,
Bjorn Helgaas <bhelgaas@google.com>,
Chaitanya Kulkarni <chaitanyak@nvidia.com>,
kernel test robot <lkp@intel.com>
Subject: Re: [PATCH] PCI/P2PDMA: Annotate RCU dereference
Date: Tue, 14 Feb 2023 16:08:49 -0600 [thread overview]
Message-ID: <20230214220849.GA3088019@bhelgaas> (raw)
In-Reply-To: <20230209172953.4597-1-logang@deltatee.com>
On Thu, Feb 09, 2023 at 10:29:53AM -0700, Logan Gunthorpe wrote:
> A dereference of the __rcu pointer was noticed by sparse:
>
> drivers/pci/p2pdma.c:199:44: sparse: sparse: dereference of noderef expression
>
> The __rcu pointer should be dereferenced using
> rcu_dereference_protected() instead of accessed directly. Its safe
> to use rcu_derference_protected() seeing a reference is held on
> the pgmap's percpu reference counter and thus it cannot disappear.
>
> Reported-by: kernel test robot <lkp@intel.com>
> Signed-off-by: Logan Gunthorpe <logang@deltatee.com>
Applied with Chaitanya's reviewed-by to pci/p2pdma for v6.3, thanks!
> ---
>
> Based on v6.2-rc7
>
> drivers/pci/p2pdma.c | 8 +++++---
> 1 file changed, 5 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/pci/p2pdma.c b/drivers/pci/p2pdma.c
> index 86812d2073ea..9e8205572830 100644
> --- a/drivers/pci/p2pdma.c
> +++ b/drivers/pci/p2pdma.c
> @@ -194,11 +194,13 @@ static const struct attribute_group p2pmem_group = {
> static void p2pdma_page_free(struct page *page)
> {
> struct pci_p2pdma_pagemap *pgmap = to_p2p_pgmap(page->pgmap);
> + /* safe to dereference while a reference is held to the percpu ref */
> + struct pci_p2pdma *p2pdma =
> + rcu_dereference_protected(pgmap->provider->p2pdma, 1);
> struct percpu_ref *ref;
>
> - gen_pool_free_owner(pgmap->provider->p2pdma->pool,
> - (uintptr_t)page_to_virt(page), PAGE_SIZE,
> - (void **)&ref);
> + gen_pool_free_owner(p2pdma->pool, (uintptr_t)page_to_virt(page),
> + PAGE_SIZE, (void **)&ref);
> percpu_ref_put(ref);
> }
>
>
> base-commit: 4ec5183ec48656cec489c49f989c508b68b518e3
> --
> 2.30.2
prev parent reply other threads:[~2023-02-14 22:08 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-02-09 17:29 [PATCH] PCI/P2PDMA: Annotate RCU dereference Logan Gunthorpe
2023-02-09 17:53 ` Chaitanya Kulkarni
2023-02-14 22:08 ` Bjorn Helgaas [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=20230214220849.GA3088019@bhelgaas \
--to=helgaas@kernel.org \
--cc=bhelgaas@google.com \
--cc=chaitanyak@nvidia.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=lkp@intel.com \
--cc=logang@deltatee.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox