From: Vasant Hegde <vasant.hegde@amd.com>
To: <iommu@lists.linux.dev>, <joro@8bytes.org>
Cc: <suravee.suthikulpanit@amd.com>, <jgg@nvidia.com>,
Vasant Hegde <vasant.hegde@amd.com>,
Daniel Marcovitch <dmarcovitch@nvidia.com>
Subject: [PATCH 0/3] iommu/amd/iommu_v2: Fix refcount related issues
Date: Tue, 24 Jan 2023 10:43:52 +0000 [thread overview]
Message-ID: <20230124104355.119166-1-vasant.hegde@amd.com> (raw)
This patch series fixes various issues around pasid refcount handling.
Issues addressed in this patchset are as follows:
1. refcount_dec assumes that refcount will never reach 0:
threfore: REFCOUNT_WARN("decrement hit 0; leaking memory")
will be invoked on pasid unbind
* Fixed by changing refcount_dec to refcount_dec_and_test
to explicitly handle refcount=1 (skip waiting for wait queue)
2. ppr_handler calls the wake_up API on the pasid_state wait_queue.
However, once refcount has been decremented, unbind_pasid may have
already freed this object - causing unallocated memory access
* Fixed by adding spinlock to ensure atomicity between refcount
check and event queue handling. Moved wait_queue APIs to
wake_up_locked / wake_event_interruptible_locked accordingly
3. If new ppr_handler arrives after get_pasid_wait once pasid unbind
has decremented refcount to 0 - get_pasid_state can still acquire
a pointer to pasid_state after being freed by unbind_pasid causing
unallocated memory access
* Fixed by changing ref_count_inc to ref_count_inc_not_zero
to ensure no new ppr_handle starts after pasid has been unbound
and NULL (invalid) pasid_state is returned on zero.
Signed-off-by: Daniel Marcovitch <dmarcovitch@nvidia.com>
Signed-off-by: Vasant Hegde <vasant.hegde@amd.com>
Base commit: v6.2-rc5
Daniel Marcovitch (3):
iommu/amd/iommu_v2: Fix pasid_state refcount dec hit 0 warning on pasid unbind
iommu/amd/iommu_v2: Fix pasid_state->wq race
iommu/amd/iommu_v2: Prevent scheduling new ppr notifier during unbind_pasid
drivers/iommu/amd/iommu_v2.c | 19 ++++++++++++++-----
1 file changed, 14 insertions(+), 5 deletions(-)
--
2.31.1
next reply other threads:[~2023-01-24 10:44 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-01-24 10:43 Vasant Hegde [this message]
2023-01-24 10:43 ` [PATCH 1/3] iommu/amd/iommu_v2: Fix pasid_state refcount dec hit 0 warning on pasid unbind Vasant Hegde
2023-01-24 15:23 ` Jason Gunthorpe
2023-01-27 4:44 ` Vasant Hegde
2023-01-27 12:58 ` Jason Gunthorpe
2023-01-24 10:43 ` [PATCH 2/3] iommu/amd/iommu_v2: Fix pasid_state->wq race Vasant Hegde
2023-01-24 15:30 ` Jason Gunthorpe
2023-01-24 10:43 ` [PATCH 3/3] iommu/amd/iommu_v2: Prevent scheduling new ppr notifier during unbind_pasid Vasant Hegde
2023-01-24 15:33 ` Jason Gunthorpe
2023-01-27 4:58 ` Vasant Hegde
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=20230124104355.119166-1-vasant.hegde@amd.com \
--to=vasant.hegde@amd.com \
--cc=dmarcovitch@nvidia.com \
--cc=iommu@lists.linux.dev \
--cc=jgg@nvidia.com \
--cc=joro@8bytes.org \
--cc=suravee.suthikulpanit@amd.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;
as well as URLs for NNTP newsgroup(s).