From: Nicolin Chen <nicolinc@nvidia.com>
To: Pranjal Shrivastava <praan@google.com>
Cc: <jgg@nvidia.com>, <kevin.tian@intel.com>, <corbet@lwn.net>,
<will@kernel.org>, <joro@8bytes.org>,
<suravee.suthikulpanit@amd.com>, <robin.murphy@arm.com>,
<dwmw2@infradead.org>, <baolu.lu@linux.intel.com>,
<shuah@kernel.org>, <linux-kernel@vger.kernel.org>,
<iommu@lists.linux.dev>, <linux-arm-kernel@lists.infradead.org>,
<linux-kselftest@vger.kernel.org>, <linux-doc@vger.kernel.org>,
<eric.auger@redhat.com>, <jean-philippe@linaro.org>,
<mdf@kernel.org>, <mshavit@google.com>,
<shameerali.kolothum.thodi@huawei.com>, <smostafa@google.com>,
<ddutile@redhat.com>, <yi.l.liu@intel.com>,
<patches@lists.linux.dev>
Subject: Re: [PATCH v7 12/14] iommu/arm-smmu-v3: Introduce struct arm_smmu_vmaster
Date: Mon, 24 Feb 2025 15:45:33 -0800 [thread overview]
Message-ID: <Z70EnQ5CXacc4ysT@Asurada-Nvidia> (raw)
In-Reply-To: <Z7zxsbJsOFp41Dzd@Asurada-Nvidia>
On Mon, Feb 24, 2025 at 02:24:55PM -0800, Nicolin Chen wrote:
> On Mon, Feb 24, 2025 at 09:53:58PM +0000, Pranjal Shrivastava wrote:
> > On Mon, Feb 24, 2025 at 01:31:11PM -0800, Nicolin Chen wrote:
> > > On Mon, Feb 24, 2025 at 08:35:56PM +0000, Pranjal Shrivastava wrote:
> > > > oN sAt, Feb 22, 2025 at 07:54:09AM -0800, Nicolin Chen wrote:
> > > > > diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-iommufd.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-iommufd.c
> > > > > index 5aa2e7af58b4..364d8469a480 100644
> > > > > --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-iommufd.c
> > > > > +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-iommufd.c
> > > > > @@ -85,6 +85,59 @@ static void arm_smmu_make_nested_domain_ste(
> > > > > }
> > > > > }
> > > > >
> > > > > +int arm_smmu_attach_prepare_vmaster(struct arm_smmu_attach_state *state,
> > > > > + struct iommu_domain *domain)
> > > > > +{
> > > > > + struct arm_smmu_nested_domain *nested_domain;
> > > > > + struct arm_smmu_vmaster *vmaster;
> > > > > + unsigned long vsid;
> > > > > + int ret;
> > > > > +
> > > > > + iommu_group_mutex_assert(state->master->dev);
> > > > > +
> > > > > + if (domain->type != IOMMU_DOMAIN_NESTED)
> > > > > + return 0;
> > > > > + nested_domain = to_smmu_nested_domain(domain);
> > > > > +
> > > > > + /* Skip invalid vSTE */
> > > > > + if (!(nested_domain->ste[0] & cpu_to_le64(STRTAB_STE_0_V)))
> > > > > + return 0;
> > > > > +
> > > > > + ret = iommufd_viommu_get_vdev_id(&nested_domain->vsmmu->core,
> > > > > + state->master->dev, &vsid);
> > > > > + if (ret)
> > > > > + return ret;
> > > > > +
> > > > > + vmaster = kzalloc(sizeof(*vmaster), GFP_KERNEL);
> > > > > + if (!vmaster)
> > > > > + return -ENOMEM;
> > > > > + vmaster->vsmmu = nested_domain->vsmmu;
> > > > > + vmaster->vsid = vsid;
> > > > > + state->vmaster = vmaster;
> > > > > +
> > > > > + return 0;
> > > > > +}
> > > > > +
> > > > > +void arm_smmu_attach_commit_vmaster(struct arm_smmu_attach_state *state)
> > > > > +{
> > > > > + struct arm_smmu_master *master = state->master;
> > > > > +
> > > > > + mutex_lock(&master->smmu->streams_mutex);
> > > > > + if (state->vmaster != master->vmaster) {
> > > > > + kfree(master->vmaster);
> > > > > + master->vmaster = state->vmaster;
> > > > > + }
> > > >
> > > > Does this condition suggest that we might end up calling
> > > > `arm_smmu_attach_prepare_vmaster()` multiple times before __actually__
> > > > commiting to a vmaster?
> > >
> > > No. prepare() and commit() are 1:1. How is it interpreted to have
> > > "multiple times"?
> >
> > Ohh alright. I was just confused about why do we need to check:
> > `if (state->vmaster != master->vmaster)` ?
>
> Hmm, it's probably not necessary, since we always allocate a new
> vmaster pointer to the "state" or set a NULL.
>
> I will clean that up a bit.
I made the following change on top of this patch (will squash):
-------------------------------------------------------------
diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-iommufd.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-iommufd.c
index 364d8469a480..2c1a51c360fe 100644
--- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-iommufd.c
+++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-iommufd.c
@@ -95,8 +95,6 @@ int arm_smmu_attach_prepare_vmaster(struct arm_smmu_attach_state *state,
iommu_group_mutex_assert(state->master->dev);
- if (domain->type != IOMMU_DOMAIN_NESTED)
- return 0;
nested_domain = to_smmu_nested_domain(domain);
/* Skip invalid vSTE */
@@ -122,19 +120,9 @@ void arm_smmu_attach_commit_vmaster(struct arm_smmu_attach_state *state)
{
struct arm_smmu_master *master = state->master;
- mutex_lock(&master->smmu->streams_mutex);
- if (state->vmaster != master->vmaster) {
- kfree(master->vmaster);
- master->vmaster = state->vmaster;
- }
- mutex_unlock(&master->smmu->streams_mutex);
-}
-
-void arm_smmu_master_clear_vmaster(struct arm_smmu_master *master)
-{
mutex_lock(&master->smmu->streams_mutex);
kfree(master->vmaster);
- master->vmaster = NULL;
+ master->vmaster = state->vmaster;
mutex_unlock(&master->smmu->streams_mutex);
}
diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c
index 9e50bcee69d1..b9d0cf571da0 100644
--- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c
+++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c
@@ -2833,9 +2833,11 @@ int arm_smmu_attach_prepare(struct arm_smmu_attach_state *state,
}
if (smmu_domain) {
- ret = arm_smmu_attach_prepare_vmaster(state, new_domain);
- if (ret)
- return ret;
+ if (new_domain->type == IOMMU_DOMAIN_NESTED) {
+ ret = arm_smmu_attach_prepare_vmaster(state, new_domain);
+ if (ret)
+ return ret;
+ }
master_domain = kzalloc(sizeof(*master_domain), GFP_KERNEL);
if (!master_domain) {
@@ -3171,8 +3173,9 @@ static int arm_smmu_attach_dev_identity(struct iommu_domain *domain,
{
struct arm_smmu_ste ste;
struct arm_smmu_master *master = dev_iommu_priv_get(dev);
+ struct arm_smmu_attach_state state = { .master = master };
- arm_smmu_master_clear_vmaster(master);
+ arm_smmu_attach_commit_vmaster(&state);
arm_smmu_make_bypass_ste(master->smmu, &ste);
arm_smmu_attach_dev_ste(domain, dev, &ste, STRTAB_STE_1_S1DSS_BYPASS);
return 0;
@@ -3192,8 +3195,9 @@ static int arm_smmu_attach_dev_blocked(struct iommu_domain *domain,
{
struct arm_smmu_ste ste;
struct arm_smmu_master *master = dev_iommu_priv_get(dev);
+ struct arm_smmu_attach_state state = { .master = master };
- arm_smmu_master_clear_vmaster(master);
+ arm_smmu_attach_commit_vmaster(&state);
arm_smmu_make_abort_ste(&ste);
arm_smmu_attach_dev_ste(domain, dev, &ste,
STRTAB_STE_1_S1DSS_TERMINATE);
diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h
index 85352504343b..eeec302f1b4b 100644
--- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h
+++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h
@@ -1066,7 +1066,6 @@ struct iommufd_viommu *arm_vsmmu_alloc(struct device *dev,
int arm_smmu_attach_prepare_vmaster(struct arm_smmu_attach_state *state,
struct iommu_domain *domain);
void arm_smmu_attach_commit_vmaster(struct arm_smmu_attach_state *state);
-void arm_smmu_master_clear_vmaster(struct arm_smmu_master *master);
#else
#define arm_smmu_hw_info NULL
#define arm_vsmmu_alloc NULL
@@ -1082,9 +1081,6 @@ static inline void
arm_smmu_attach_commit_vmaster(struct arm_smmu_attach_state *state)
{
}
-static inline void arm_smmu_master_clear_vmaster(struct arm_smmu_master *master)
-{
-}
#endif /* CONFIG_ARM_SMMU_V3_IOMMUFD */
#endif /* _ARM_SMMU_V3_H */
-------------------------------------------------------------
Thanks
Nicolin
next prev parent reply other threads:[~2025-02-24 23:47 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-22 15:53 [PATCH v7 00/14] iommufd: Add vIOMMU infrastructure (Part-3: vEVENTQ) Nicolin Chen
2025-02-22 15:53 ` [PATCH v7 01/14] iommufd/fault: Move two fault functions out of the header Nicolin Chen
2025-02-22 15:53 ` [PATCH v7 02/14] iommufd/fault: Add an iommufd_fault_init() helper Nicolin Chen
2025-02-22 15:54 ` [PATCH v7 03/14] iommufd: Abstract an iommufd_eventq from iommufd_fault Nicolin Chen
2025-02-22 15:54 ` [PATCH v7 04/14] iommufd: Rename fault.c to eventq.c Nicolin Chen
2025-02-22 15:54 ` [PATCH v7 05/14] iommufd: Add IOMMUFD_OBJ_VEVENTQ and IOMMUFD_CMD_VEVENTQ_ALLOC Nicolin Chen
2025-02-25 15:29 ` Jason Gunthorpe
2025-02-22 15:54 ` [PATCH v7 06/14] iommufd/viommu: Add iommufd_viommu_get_vdev_id helper Nicolin Chen
2025-02-22 15:54 ` [PATCH v7 07/14] iommufd/viommu: Add iommufd_viommu_report_event helper Nicolin Chen
2025-02-25 15:40 ` Jason Gunthorpe
2025-02-22 15:54 ` [PATCH v7 08/14] iommufd/selftest: Require vdev_id when attaching to a nested domain Nicolin Chen
2025-02-22 15:54 ` [PATCH v7 09/14] iommufd/selftest: Add IOMMU_TEST_OP_TRIGGER_VEVENT for vEVENTQ coverage Nicolin Chen
2025-02-22 15:54 ` [PATCH v7 10/14] iommufd/selftest: Add IOMMU_VEVENTQ_ALLOC test coverage Nicolin Chen
2025-02-22 15:54 ` [PATCH v7 11/14] Documentation: userspace-api: iommufd: Update FAULT and VEVENTQ Nicolin Chen
2025-02-22 15:54 ` [PATCH v7 12/14] iommu/arm-smmu-v3: Introduce struct arm_smmu_vmaster Nicolin Chen
2025-02-24 20:35 ` Pranjal Shrivastava
2025-02-24 21:31 ` Nicolin Chen
2025-02-24 21:53 ` Pranjal Shrivastava
2025-02-24 22:24 ` Nicolin Chen
2025-02-24 23:45 ` Nicolin Chen [this message]
2025-02-25 16:02 ` Jason Gunthorpe
2025-02-25 16:41 ` Nicolin Chen
2025-02-25 17:08 ` Pranjal Shrivastava
2025-02-25 17:22 ` Nicolin Chen
2025-02-25 16:45 ` Pranjal Shrivastava
2025-02-22 15:54 ` [PATCH v7 13/14] iommu/arm-smmu-v3: Report events that belong to devices attached to vIOMMU Nicolin Chen
2025-02-24 21:35 ` Pranjal Shrivastava
2025-02-24 21:56 ` Nicolin Chen
2025-02-24 23:35 ` Jason Gunthorpe
2025-02-25 16:50 ` Pranjal Shrivastava
2025-02-25 16:47 ` Pranjal Shrivastava
2025-02-25 16:05 ` Jason Gunthorpe
2025-02-22 15:54 ` [PATCH v7 14/14] iommu/arm-smmu-v3: Set MEV bit in nested STE for DoS mitigations Nicolin Chen
2025-02-24 4:38 ` Pranjal Shrivastava
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=Z70EnQ5CXacc4ysT@Asurada-Nvidia \
--to=nicolinc@nvidia.com \
--cc=baolu.lu@linux.intel.com \
--cc=corbet@lwn.net \
--cc=ddutile@redhat.com \
--cc=dwmw2@infradead.org \
--cc=eric.auger@redhat.com \
--cc=iommu@lists.linux.dev \
--cc=jean-philippe@linaro.org \
--cc=jgg@nvidia.com \
--cc=joro@8bytes.org \
--cc=kevin.tian@intel.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=mdf@kernel.org \
--cc=mshavit@google.com \
--cc=patches@lists.linux.dev \
--cc=praan@google.com \
--cc=robin.murphy@arm.com \
--cc=shameerali.kolothum.thodi@huawei.com \
--cc=shuah@kernel.org \
--cc=smostafa@google.com \
--cc=suravee.suthikulpanit@amd.com \
--cc=will@kernel.org \
--cc=yi.l.liu@intel.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).