From: Nicolin Chen <nicolinc@nvidia.com>
To: Baolu Lu <baolu.lu@linux.intel.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>, <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 v4 14/14] iommu/arm-smmu-v3: Report events that belong to devices attached to vIOMMU
Date: Mon, 6 Jan 2025 20:36:54 -0800 [thread overview]
Message-ID: <Z3yvZsq77bpnaoAb@Asurada-Nvidia> (raw)
In-Reply-To: <Z3wk9TvmUhB3/zlk@Asurada-Nvidia>
On Mon, Jan 06, 2025 at 10:46:21AM -0800, Nicolin Chen wrote:
> On Mon, Jan 06, 2025 at 11:01:32AM +0800, Baolu Lu wrote:
> > Nit: I think it would be more readable to add a check in the vevent
> > reporting helper.
> >
> > diff --git a/drivers/iommu/iommufd/driver.c b/drivers/iommu/iommufd/driver.c
> > index 77c34f8791ef..ccada0ada5ff 100644
> > --- a/drivers/iommu/iommufd/driver.c
> > +++ b/drivers/iommu/iommufd/driver.c
> > @@ -86,6 +86,9 @@ int iommufd_viommu_report_event(struct iommufd_viommu
> > *viommu,
> > if (WARN_ON_ONCE(!data_len || !event_data))
> > return -EINVAL;
> >
> > + if (WARN_ON_ONCE(type != IOMMU_VEVENTQ_TYPE_ARM_SMMUV3))
> > + return -EINVAL;
> > +
>
> Hmm, that's a good point I think.
>
> > down_read(&viommu->veventqs_rwsem);
> >
> > veventq = iommufd_viommu_find_veventq(viommu, type);
> ^
> |
> We actually have been missing a type validation entirely, so the
> type could have been rejected by this function. Perhaps we should
> add a static list of supported types to struct iommufd_viommu_ops
> for drivers to report so that then the core could reject from the
> first place during a vEVENTQ allocation.
I added something like this. Will send a v5.
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 0c7a5894ba07..348179f3cf2a 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
@@ -399,9 +399,15 @@ static int arm_vsmmu_cache_invalidate(struct iommufd_viommu *viommu,
return ret;
}
+static bool arm_vsmmu_supports_veventq(unsigned int type)
+{
+ return type == IOMMU_VIOMMU_TYPE_ARM_SMMUV3;
+}
+
static const struct iommufd_viommu_ops arm_vsmmu_ops = {
.alloc_domain_nested = arm_vsmmu_alloc_domain_nested,
.cache_invalidate = arm_vsmmu_cache_invalidate,
+ .supports_veventq = arm_vsmmu_supports_veventq,
};
struct iommufd_viommu *arm_vsmmu_alloc(struct device *dev,
diff --git a/drivers/iommu/iommufd/eventq.c b/drivers/iommu/iommufd/eventq.c
index bf0c04f571a7..b5be629f38ed 100644
--- a/drivers/iommu/iommufd/eventq.c
+++ b/drivers/iommu/iommufd/eventq.c
@@ -555,6 +555,11 @@ int iommufd_veventq_alloc(struct iommufd_ucmd *ucmd)
viommu = iommufd_get_viommu(ucmd, cmd->viommu_id);
if (IS_ERR(viommu))
return PTR_ERR(viommu);
+
+ if (!viommu->ops || !viommu->ops->supports_veventq ||
+ !viommu->ops->supports_veventq(cmd->type))
+ return -EOPNOTSUPP;
+
down_write(&viommu->veventqs_rwsem);
if (iommufd_viommu_find_veventq(viommu, cmd->type)) {
diff --git a/include/linux/iommufd.h b/include/linux/iommufd.h
index 6b3b46e382f8..55e71dca3664 100644
--- a/include/linux/iommufd.h
+++ b/include/linux/iommufd.h
@@ -117,6 +117,7 @@ struct iommufd_viommu {
* array->entry_num to report the number of handled requests.
* The data structure of the array entry must be defined in
* include/uapi/linux/iommufd.h
+ * @supports_veventq: Whether the vIOMMU supports a given vEVENTQ type
*/
struct iommufd_viommu_ops {
void (*destroy)(struct iommufd_viommu *viommu);
@@ -125,6 +126,7 @@ struct iommufd_viommu_ops {
const struct iommu_user_data *user_data);
int (*cache_invalidate)(struct iommufd_viommu *viommu,
struct iommu_user_data_array *array);
+ bool (*supports_veventq)(unsigned int type);
};
#if IS_ENABLED(CONFIG_IOMMUFD)
next prev parent reply other threads:[~2025-01-07 4:37 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-01-03 19:43 [PATCH v4 00/14] iommufd: Add vIOMMU infrastructure (Part-3: vEVENTQ) Nicolin Chen
2025-01-03 19:43 ` [PATCH v4 01/14] iommufd: Keep IOCTL list in an alphabetical order Nicolin Chen
2025-01-06 2:47 ` Baolu Lu
2025-01-03 19:43 ` [PATCH v4 02/14] iommufd/fault: Add an iommufd_fault_init() helper Nicolin Chen
2025-01-06 2:48 ` Baolu Lu
2025-01-03 19:43 ` [PATCH v4 03/14] iommufd/fault: Move iommufd_fault_iopf_handler() to header Nicolin Chen
2025-01-06 2:48 ` Baolu Lu
2025-01-03 19:43 ` [PATCH v4 04/14] iommufd: Abstract an iommufd_eventq from iommufd_fault Nicolin Chen
2025-01-06 2:49 ` Baolu Lu
2025-01-03 19:43 ` [PATCH v4 05/14] iommufd: Rename fault.c to eventq.c Nicolin Chen
2025-01-06 2:49 ` Baolu Lu
2025-01-03 19:43 ` [PATCH v4 06/14] iommufd: Add IOMMUFD_OBJ_VEVENTQ and IOMMUFD_CMD_VEVENTQ_ALLOC Nicolin Chen
2025-01-06 2:50 ` Baolu Lu
2025-01-03 19:43 ` [PATCH v4 07/14] iommufd/viommu: Add iommufd_viommu_get_vdev_id helper Nicolin Chen
2025-01-06 2:50 ` Baolu Lu
2025-01-03 19:43 ` [PATCH v4 08/14] iommufd/viommu: Add iommufd_viommu_report_event helper Nicolin Chen
2025-01-06 2:51 ` Baolu Lu
2025-01-03 19:43 ` [PATCH v4 09/14] iommufd/selftest: Require vdev_id when attaching to a nested domain Nicolin Chen
2025-01-03 19:43 ` [PATCH v4 10/14] iommufd/selftest: Add IOMMU_TEST_OP_TRIGGER_VEVENT for vEVENTQ coverage Nicolin Chen
2025-01-03 19:43 ` [PATCH v4 11/14] iommufd/selftest: Add IOMMU_VEVENTQ_ALLOC test coverage Nicolin Chen
2025-01-03 19:43 ` [PATCH v4 12/14] Documentation: userspace-api: iommufd: Update FAULT and VEVENTQ Nicolin Chen
2025-01-06 2:51 ` Baolu Lu
2025-01-03 19:43 ` [PATCH v4 13/14] iommu/arm-smmu-v3: Introduce struct arm_smmu_vmaster Nicolin Chen
2025-01-03 19:43 ` [PATCH v4 14/14] iommu/arm-smmu-v3: Report events that belong to devices attached to vIOMMU Nicolin Chen
2025-01-06 3:01 ` Baolu Lu
2025-01-06 18:46 ` Nicolin Chen
2025-01-07 4:36 ` Nicolin Chen [this message]
2025-01-07 5:33 ` Nicolin Chen
2025-01-07 5:54 ` Baolu Lu
2025-01-07 6:00 ` Nicolin Chen
2025-01-07 6:27 ` Baolu Lu
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=Z3yvZsq77bpnaoAb@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=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).