From: Vasant Hegde <vasant.hegde@amd.com>
To: Yi Liu <yi.l.liu@intel.com>,
joro@8bytes.org, jgg@nvidia.com, kevin.tian@intel.com,
baolu.lu@linux.intel.com
Cc: alex.williamson@redhat.com, eric.auger@redhat.com,
nicolinc@nvidia.com, kvm@vger.kernel.org,
chao.p.peng@linux.intel.com, iommu@lists.linux.dev,
zhenzhong.duan@intel.com, linux-kselftest@vger.kernel.org
Subject: Re: [PATCH v3 4/4] iommufd: Extend IOMMU_GET_HW_INFO to report PASID capability
Date: Tue, 22 Oct 2024 15:38:15 +0530 [thread overview]
Message-ID: <94b67623-17a4-412b-959b-a1d3c50190bf@amd.com> (raw)
In-Reply-To: <20240912131729.14951-5-yi.l.liu@intel.com>
Hi Yi,
On 9/12/2024 6:47 PM, Yi Liu wrote:
> PASID usage requires PASID support in both device and IOMMU. Since the
> iommu drivers always enable the PASID capability for the device if it
> is supported, so it is reasonable to extend the IOMMU_GET_HW_INFO to
> report the PASID capability to userspace.
>
> Signed-off-by: Yi Liu <yi.l.liu@intel.com>
> ---
> drivers/iommu/iommufd/device.c | 27 ++++++++++++++++++++++++++-
> drivers/pci/ats.c | 32 ++++++++++++++++++++++++++++++++
> include/linux/pci-ats.h | 3 +++
> include/uapi/linux/iommufd.h | 14 +++++++++++++-
> 4 files changed, 74 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/iommu/iommufd/device.c b/drivers/iommu/iommufd/device.c
> index 18f94aa462ea..6b7e3e5f4598 100644
> --- a/drivers/iommu/iommufd/device.c
> +++ b/drivers/iommu/iommufd/device.c
> @@ -4,6 +4,8 @@
> #include <linux/iommufd.h>
> #include <linux/slab.h>
> #include <linux/iommu.h>
> +#include <linux/pci.h>
> +#include <linux/pci-ats.h>
> #include <uapi/linux/iommufd.h>
> #include "../iommu-priv.h"
>
> @@ -1185,7 +1187,8 @@ int iommufd_get_hw_info(struct iommufd_ucmd *ucmd)
> void *data;
> int rc;
>
> - if (cmd->flags || cmd->__reserved)
> + if (cmd->flags || cmd->__reserved[0] || cmd->__reserved[1] ||
> + cmd->__reserved[2])
> return -EOPNOTSUPP;
>
> idev = iommufd_get_device(ucmd, cmd->dev_id);
> @@ -1242,6 +1245,28 @@ int iommufd_get_hw_info(struct iommufd_ucmd *ucmd)
> if (device_iommu_capable(idev->dev, IOMMU_CAP_DIRTY_TRACKING))
> cmd->out_capabilities |= IOMMU_HW_CAP_DIRTY_TRACKING;
>
> + cmd->out_max_pasid_log2 = 0;
> +
> + if (dev_is_pci(idev->dev)) {
> + struct pci_dev *pdev = to_pci_dev(idev->dev);
> + int ctrl;
> +
> + if (pdev->is_virtfn)
> + pdev = pci_physfn(pdev);
> +
> + ctrl = pci_pasid_ctrl_status(pdev);
> + if (ctrl >= 0 && (ctrl & PCI_PASID_CTRL_ENABLE)) {
> + cmd->out_max_pasid_log2 =
> + ilog2(idev->dev->iommu->max_pasids);
> + if (ctrl & PCI_PASID_CTRL_EXEC)
> + cmd->out_capabilities |=
> + IOMMU_HW_CAP_PCI_PASID_EXEC;
> + if (ctrl & PCI_PASID_CTRL_PRIV)
> + cmd->out_capabilities |=
> + IOMMU_HW_CAP_PCI_PASID_PRIV;
> + }
> + }
> +
> rc = iommufd_ucmd_respond(ucmd, sizeof(*cmd));
> out_free:
> kfree(data);
> diff --git a/drivers/pci/ats.c b/drivers/pci/ats.c
> index c570892b2090..886f24e3999f 100644
> --- a/drivers/pci/ats.c
> +++ b/drivers/pci/ats.c
> @@ -505,4 +505,36 @@ int pci_max_pasids(struct pci_dev *pdev)
> return (1 << FIELD_GET(PCI_PASID_CAP_WIDTH, supported));
> }
> EXPORT_SYMBOL_GPL(pci_max_pasids);
> +
> +/**
> + * pci_pasid_ctrl_status - Check the PASID status
> + * @pdev: PCI device structure
> + *
> + * Returns a negative value when no PASI capability is present.
s/PASI/PASID/
> + * Otherwise the value of the control register is returned.
> + * Status reported are:
> + *
> + * PCI_PASID_CTRL_ENABLE - PASID enabled
> + * PCI_PASID_CTRL_EXEC - Execute permission enabled
> + * PCI_PASID_CTRL_PRIV - Privileged mode enabled
> + */
> +int pci_pasid_ctrl_status(struct pci_dev *pdev)
> +{
> + u16 ctrl = 0;
No need to initialize ctrl.
-Vasant
next prev parent reply other threads:[~2024-10-22 10:08 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-09-12 13:17 [PATCH v3 0/4] vfio-pci support pasid attach/detach Yi Liu
2024-09-12 13:17 ` [PATCH v3 1/4] ida: Add ida_find_first_range() Yi Liu
2024-09-12 15:11 ` Matthew Wilcox
2024-09-13 11:45 ` Yi Liu
2024-09-13 15:09 ` Matthew Wilcox
2024-09-14 4:16 ` Yi Liu
2024-09-26 19:11 ` Jason Gunthorpe
2024-09-30 7:49 ` Tian, Kevin
2024-09-12 13:17 ` [PATCH v3 2/4] vfio-iommufd: Support pasid [at|de]tach for physical VFIO devices Yi Liu
2024-09-26 19:13 ` Jason Gunthorpe
2024-09-12 13:17 ` [PATCH v3 3/4] vfio: Add VFIO_DEVICE_PASID_[AT|DE]TACH_IOMMUFD_PT Yi Liu
2024-09-26 19:16 ` Jason Gunthorpe
2024-09-30 7:55 ` Tian, Kevin
2024-10-01 12:11 ` Jason Gunthorpe
2024-10-12 13:49 ` Yi Liu
2024-10-14 15:49 ` Alex Williamson
2024-10-15 11:07 ` Yi Liu
2024-10-15 16:22 ` Alex Williamson
2024-10-16 3:35 ` Yi Liu
2024-10-16 16:11 ` Alex Williamson
2024-10-18 5:40 ` Yi Liu
2024-10-30 12:54 ` Yi Liu
2024-10-30 17:51 ` Alex Williamson
2024-10-31 7:23 ` Yi Liu
2024-09-12 13:17 ` [PATCH v3 4/4] iommufd: Extend IOMMU_GET_HW_INFO to report PASID capability Yi Liu
2024-09-26 19:35 ` Jason Gunthorpe
2024-09-27 3:08 ` Yi Liu
2024-09-30 8:03 ` Tian, Kevin
2024-10-22 10:08 ` Vasant Hegde [this message]
2024-10-28 6:41 ` Zhangfei Gao
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=94b67623-17a4-412b-959b-a1d3c50190bf@amd.com \
--to=vasant.hegde@amd.com \
--cc=alex.williamson@redhat.com \
--cc=baolu.lu@linux.intel.com \
--cc=chao.p.peng@linux.intel.com \
--cc=eric.auger@redhat.com \
--cc=iommu@lists.linux.dev \
--cc=jgg@nvidia.com \
--cc=joro@8bytes.org \
--cc=kevin.tian@intel.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=nicolinc@nvidia.com \
--cc=yi.l.liu@intel.com \
--cc=zhenzhong.duan@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 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.