Re: [PATCH v2 11/13] Documentation: userspace-api: iommufd: Update EVENTQ_IOPF and EVENTQ_VIRQ

2024-12-12 Thread Nicolin Chen
On Wed, Dec 11, 2024 at 08:11:03AM +, Tian, Kevin wrote: > > From: Nicolin Chen > > Sent: Wednesday, December 4, 2024 6:10 AM > > > > With the introduction of the new objects, update the doc to reflect that. > > > > Signed-off-by: Nicolin Chen >

Re: [PATCH v2 12/13] iommu/arm-smmu-v3: Introduce struct arm_smmu_vmaster

2024-12-12 Thread Nicolin Chen
On Wed, Dec 11, 2024 at 08:15:35AM +, Tian, Kevin wrote: > > From: Nicolin Chen > > Sent: Wednesday, December 4, 2024 6:10 AM > > > > Use it to store all vSMMU-related data. The vsid (Virtual Stream ID) will > > be the first use case. Then, add a rw_semaphore to

Re: [PATCH v2 13/13] iommu/arm-smmu-v3: Report IRQs that belong to devices attached to vIOMMU

2024-12-12 Thread Nicolin Chen
On Wed, Dec 11, 2024 at 08:21:42AM +, Tian, Kevin wrote: > > From: Nicolin Chen > > Sent: Wednesday, December 4, 2024 6:10 AM > > > > + > > +/** > > + * struct iommu_virq_arm_smmuv3 - ARM SMMUv3 Virtual IRQ > > + *(IOM

Re: [PATCH v2 03/13] iommufd: Rename IOMMUFD_OBJ_FAULT to IOMMUFD_OBJ_EVENTQ_IOPF

2024-12-12 Thread Nicolin Chen
On Wed, Dec 11, 2024 at 07:40:52AM +, Tian, Kevin wrote: > > From: Nicolin Chen > > Sent: Wednesday, December 4, 2024 6:10 AM > > > > The fault object was designed exclusively for hwpt's IO page faults (PRI). > > But its implementation can actually be

Re: [PATCH v2 01/13] iommufd/fault: Add an iommufd_fault_init() helper

2024-12-12 Thread Nicolin Chen
On Wed, Dec 11, 2024 at 07:27:40AM +, Tian, Kevin wrote: > > From: Nicolin Chen > > Sent: Wednesday, December 4, 2024 6:10 AM > > > > +static int iommufd_fault_init(struct iommufd_fault *fault, char *name, > > + struct iommufd_ctx *ic

Re: [PATCH v2 05/13] iommufd: Add IOMMUFD_OBJ_EVENTQ_VIRQ and IOMMUFD_CMD_VIRQ_ALLOC

2024-12-12 Thread Nicolin Chen
On Wed, Dec 11, 2024 at 07:55:53AM +, Tian, Kevin wrote: > > From: Nicolin Chen > > Sent: Wednesday, December 4, 2024 6:10 AM > > + > > +/* An iommufd_virq represents a vIOMMU interrupt in an eventq_virq > > queue */ > > +struct iommufd_virq { > > +

Re: [PATCH v2 06/13] iommufd/viommu: Add iommufd_viommu_get_vdev_id helper

2024-12-12 Thread Nicolin Chen
On Wed, Dec 11, 2024 at 08:02:48AM +, Tian, Kevin wrote: > > From: Nicolin Chen > > Sent: Wednesday, December 4, 2024 6:10 AM > > > > +/* Return 0 if device is not associated to the vIOMMU */ > > +unsigned long iommufd_viommu_get_vdev_id(str

Re: [PATCH v2 07/13] iommufd/viommu: Add iommufd_viommu_report_irq helper

2024-12-12 Thread Nicolin Chen
On Wed, Dec 11, 2024 at 08:05:45AM +, Tian, Kevin wrote: > > From: Nicolin Chen > > Sent: Wednesday, December 4, 2024 6:10 AM > > > > +/* Typically called in driver's threaded IRQ handler */ > > +int iommufd_viommu_report_irq(struct iommufd_vi

Re: [PATCH v3 07/14] iommufd/viommu: Add iommufd_viommu_get_vdev_id helper

2024-12-18 Thread Nicolin Chen
On Thu, Dec 19, 2024 at 10:05:53AM +0800, Baolu Lu wrote: > On 12/18/24 13:00, Nicolin Chen wrote: > > This is a reverse search v.s. iommufd_viommu_find_dev, as drivers may want > > to convert a struct device pointer (physical) to its virtual device ID for > > an event inject

Re: [PATCH v3 01/14] iommufd: Keep IOCTL list in an alphabetical order

2024-12-19 Thread Nicolin Chen
On Tue, Dec 17, 2024 at 09:00:14PM -0800, Nicolin Chen wrote: > Move VDEVICE upward to keep the order. Also run clang-format keep the same > coding style at line wrappings. No functional change. It should fix the order in ucmd_buffer too. Will include in v4. Nicolin

Re: [PATCH v3 06/14] iommufd: Add IOMMUFD_OBJ_VIRQ and IOMMUFD_CMD_VIRQ_ALLOC

2024-12-19 Thread Nicolin Chen
On Tue, Dec 17, 2024 at 09:00:19PM -0800, Nicolin Chen wrote: > diff --git a/drivers/iommu/iommufd/main.c b/drivers/iommu/iommufd/main.c > index cfbdf7b0e3c1..9d15978ef882 100644 > --- a/drivers/iommu/iommufd/main.c > +++ b/drivers/iommu/iommufd/main.c > @@ -367,6 +367,8 @@ stat

[PATCH v2 00/13] iommufd: Add vIOMMU infrastructure (Part-3: vIRQ)

2024-12-03 Thread Nicolin Chen
ain driver v1 https://lore.kernel.org/all/cover.1724777091.git.nicol...@nvidia.com/ Thanks! Nicolin Nicolin Chen (13): iommufd/fault: Add an iommufd_fault_init() helper iommufd/fault: Move iommufd_fault_iopf_handler() to header iommufd: Rename IOMMUFD_OBJ_FAULT to IOMMUFD_OBJ_EVENTQ_IOPF iom

[PATCH v2 01/13] iommufd/fault: Add an iommufd_fault_init() helper

2024-12-03 Thread Nicolin Chen
need "response", leave the xa_init_flags in its original location. Signed-off-by: Nicolin Chen --- drivers/iommu/iommufd/fault.c | 48 --- 1 file changed, 28 insertions(+), 20 deletions(-) diff --git a/drivers/iommu/iommufd/fault.c b/drivers/iommu/

Re: [PATCH v5 06/14] iommufd: Add IOMMUFD_OBJ_VEVENTQ and IOMMUFD_CMD_VEVENTQ_ALLOC

2025-01-10 Thread Nicolin Chen
On Fri, Jan 10, 2025 at 03:49:50PM -0400, Jason Gunthorpe wrote: > On Fri, Jan 10, 2025 at 11:27:53AM -0800, Nicolin Chen wrote: > > On Fri, Jan 10, 2025 at 01:48:42PM -0400, Jason Gunthorpe wrote: > > > On Tue, Jan 07, 2025 at 09:10:09AM -0800, Nicolin Chen wrote: > > &g

Re: [PATCH v5 08/14] iommufd/viommu: Add iommufd_viommu_report_event helper

2025-01-22 Thread Nicolin Chen
On Wed, Jan 22, 2025 at 09:33:35AM +, Tian, Kevin wrote: > > From: Nicolin Chen > > Sent: Wednesday, January 22, 2025 3:16 PM > > > > On Tue, Jan 21, 2025 at 08:21:28PM -0400, Jason Gunthorpe wrote: > > > On Tue, Jan 21, 2025 at 01:40:05PM -0800, Nicolin Ch

Re: [PATCH v5 08/14] iommufd/viommu: Add iommufd_viommu_report_event helper

2025-01-22 Thread Nicolin Chen
On Wed, Jan 22, 2025 at 12:05:27AM -0800, Nicolin Chen wrote: > On Tue, Jan 21, 2025 at 01:40:13PM -0800, Nicolin Chen wrote: > > On Tue, Jan 21, 2025 at 05:14:04PM -0400, Jason Gunthorpe wrote: > > > Since we don't hold the spinlock the whole time there is a race where

Re: [PATCH v5 08/14] iommufd/viommu: Add iommufd_viommu_report_event helper

2025-01-21 Thread Nicolin Chen
On Tue, Jan 21, 2025 at 04:09:24PM -0400, Jason Gunthorpe wrote: > On Tue, Jan 21, 2025 at 11:55:16AM -0800, Nicolin Chen wrote: > > > > > IOMMU_VEVENTQ_STATE_OVERFLOW with a 0 length event is seen if events > > > > > have been lost and no subsequent

Re: [PATCH v5 08/14] iommufd/viommu: Add iommufd_viommu_report_event helper

2025-01-21 Thread Nicolin Chen
On Tue, Jan 21, 2025 at 02:36:11PM -0400, Jason Gunthorpe wrote: > On Mon, Jan 20, 2025 at 12:52:09PM -0800, Nicolin Chen wrote: > > The counter of the number of events in the vEVENTQ could decrease > > when userspace reads the queue. But you were saying "the number of >

Re: [PATCH v5 08/14] iommufd/viommu: Add iommufd_viommu_report_event helper

2025-01-22 Thread Nicolin Chen
On Wed, Jan 22, 2025 at 10:02:49AM -0800, Nicolin Chen wrote: > On Wed, Jan 22, 2025 at 12:05:27AM -0800, Nicolin Chen wrote: > > On Tue, Jan 21, 2025 at 01:40:13PM -0800, Nicolin Chen wrote: > > > On Tue, Jan 21, 2025 at 05:14:04PM -0400, Jason Gunthorpe wrote: > > >

[PATCH v6 01/14] iommufd/fault: Move two fault functions out of the header

2025-01-24 Thread Nicolin Chen
There is no need to keep them in the header. The vEVENTQ version of these two functions will turn out to be a different implementation and will not share with this fault version. Thus, move them out of the header. Signed-off-by: Nicolin Chen --- drivers/iommu/iommufd/iommufd_private.h | 25

[PATCH v6 00/14] iommufd: Add vIOMMU infrastructure (Part-3: vEVENTQ)

2025-01-24 Thread Nicolin Chen
3-iommufd file to simplify the routine in arm_smmu_handle_evt() of the main driver v1 https://lore.kernel.org/all/cover.1724777091.git.nicol...@nvidia.com/ Thanks! Nicolin Nicolin Chen (14): iommufd/fault: Move two fault functions out of the header iommufd/fault: Add an iom

[PATCH v6 05/14] iommufd: Add IOMMUFD_OBJ_VEVENTQ and IOMMUFD_CMD_VEVENTQ_ALLOC

2025-01-24 Thread Nicolin Chen
iommufd_veventq_ops for the new ioctl. Reviewed-by: Lu Baolu Signed-off-by: Nicolin Chen --- drivers/iommu/iommufd/iommufd_private.h | 88 ++ include/linux/iommufd.h | 3 + include/uapi/linux/iommufd.h| 85 ++ drivers/iommu/iommufd/eventq.c | 206

[PATCH v6 07/14] iommufd/viommu: Add iommufd_viommu_report_event helper

2025-01-24 Thread Nicolin Chen
Similar to iommu_report_device_fault, this allows IOMMU drivers to report vIOMMU events from threaded IRQ handlers to user space hypervisors. Reviewed-by: Lu Baolu Signed-off-by: Nicolin Chen --- include/linux/iommufd.h| 11 + drivers/iommu/iommufd/driver.c | 45

[PATCH v6 02/14] iommufd/fault: Add an iommufd_fault_init() helper

2025-01-24 Thread Nicolin Chen
iommufd_fault_fops_release(). Since the new vEVENTQ doesn't need "response" and its "mutex", so keep the xa_init_flags and mutex_init in their original locations. Reviewed-by: Kevin Tian Reviewed-by: Lu Baolu Reviewed-by: Jason Gunthorpe Signed-off-by: Nicolin Chen --- drivers/i

[PATCH v6 04/14] iommufd: Rename fault.c to eventq.c

2025-01-24 Thread Nicolin Chen
Rename the file, aligning with the new eventq object. Reviewed-by: Kevin Tian Reviewed-by: Lu Baolu Reviewed-by: Jason Gunthorpe Signed-off-by: Nicolin Chen --- drivers/iommu/iommufd/Makefile | 2 +- drivers/iommu/iommufd/{fault.c => eventq.c} | 0 2 files changed, 1 insert

[PATCH v6 10/14] iommufd/selftest: Add IOMMU_VEVENTQ_ALLOC test coverage

2025-01-24 Thread Nicolin Chen
Trigger vEVENTs by feeding an idev ID and validating the returned output virt_ids whether they equal to the value that was set to the vDEVICE. Signed-off-by: Nicolin Chen --- tools/testing/selftests/iommu/iommufd_utils.h | 115 ++ tools/testing/selftests/iommu/iommufd.c

[PATCH v6 08/14] iommufd/selftest: Require vdev_id when attaching to a nested domain

2025-01-24 Thread Nicolin Chen
. Signed-off-by: Nicolin Chen --- drivers/iommu/iommufd/selftest.c| 24 tools/testing/selftests/iommu/iommufd.c | 5 + 2 files changed, 29 insertions(+) diff --git a/drivers/iommu/iommufd/selftest.c b/drivers/iommu/iommufd/selftest.c index a0de6d6d4e68

[PATCH v6 11/14] Documentation: userspace-api: iommufd: Update FAULT and VEVENTQ

2025-01-24 Thread Nicolin Chen
With the introduction of the new objects, update the doc to reflect that. Reviewed-by: Lu Baolu Reviewed-by: Kevin Tian Signed-off-by: Nicolin Chen --- Documentation/userspace-api/iommufd.rst | 17 + 1 file changed, 17 insertions(+) diff --git a/Documentation/userspace-api

[PATCH v6 14/14] iommu/arm-smmu-v3: Set MEV bit in nested STE for DoS mitigations

2025-01-24 Thread Nicolin Chen
llows to configure the SMMU HW to merge similar event records, though there is no guarantee. Set it in a nested STE for DoS mitigations. Signed-off-by: Nicolin Chen --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h | 1 + drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-iommufd.c | 2 ++ drivers/

[PATCH v6 09/14] iommufd/selftest: Add IOMMU_TEST_OP_TRIGGER_VEVENT for vEVENTQ coverage

2025-01-24 Thread Nicolin Chen
The handler will get vDEVICE object from the given mdev and convert it to its per-vIOMMU virtual ID to mimic a real IOMMU driver. Signed-off-by: Nicolin Chen --- drivers/iommu/iommufd/iommufd_test.h | 10 ++ drivers/iommu/iommufd/selftest.c | 30 2 files

[PATCH v6 06/14] iommufd/viommu: Add iommufd_viommu_get_vdev_id helper

2025-01-24 Thread Nicolin Chen
-by: Lu Baolu Reviewed-by: Kevin Tian Signed-off-by: Nicolin Chen --- include/linux/iommufd.h| 9 + drivers/iommu/iommufd/driver.c | 24 2 files changed, 33 insertions(+) diff --git a/include/linux/iommufd.h b/include/linux/iommufd.h index 8948b1836940

[PATCH v6 12/14] iommu/arm-smmu-v3: Introduce struct arm_smmu_vmaster

2025-01-24 Thread Nicolin Chen
gned-off-by: Nicolin Chen --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h | 23 ++ .../arm/arm-smmu-v3/arm-smmu-v3-iommufd.c | 45 +++ drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 32 - 3 files changed, 99 insertions(+), 1 deletion(-) diff --git a/driver

[PATCH v6 13/14] iommu/arm-smmu-v3: Report events that belong to devices attached to vIOMMU

2025-01-24 Thread Nicolin Chen
Aside from the IOPF framework, iommufd provides an additional pathway to report hardware events, via the vEVENTQ of vIOMMU infrastructure. Define an iommu_vevent_arm_smmuv3 uAPI structure, and report stage-1 events in the threaded IRQ handler. Signed-off-by: Nicolin Chen --- drivers/iommu/arm

[PATCH v6 03/14] iommufd: Abstract an iommufd_eventq from iommufd_fault

2025-01-24 Thread Nicolin Chen
Queue). Reviewed-by: Lu Baolu Reviewed-by: Kevin Tian Signed-off-by: Nicolin Chen --- drivers/iommu/iommufd/iommufd_private.h | 28 -- drivers/iommu/iommufd/fault.c | 111 +--- drivers/iommu/iommufd/hw_pagetable.c| 6 +- 3 files changed, 82 inserti

Re: [PATCH v5 08/14] iommufd/viommu: Add iommufd_viommu_report_event helper

2025-01-17 Thread Nicolin Chen
On Tue, Jan 14, 2025 at 09:41:58AM -0400, Jason Gunthorpe wrote: > On Mon, Jan 13, 2025 at 12:44:37PM -0800, Nicolin Chen wrote: > > IOMMU_VEVENT_HEADER_FLAGS_OVERFLOW = (1 << 0), > > }; > > > > struct iommufd_vevent_header_v1 { > > __u64 flags;

Re: [PATCH v5 08/14] iommufd/viommu: Add iommufd_viommu_report_event helper

2025-01-20 Thread Nicolin Chen
On Mon, Jan 20, 2025 at 02:18:54PM -0400, Jason Gunthorpe wrote: > On Fri, Jan 17, 2025 at 02:11:15PM -0800, Nicolin Chen wrote: > > +/** > > + * struct iommufd_vevent_header - Virtual Event Header for a vEVENTQ Status > > + * @state: One of enum iommu_veventq_state >

Re: [PATCH v5 08/14] iommufd/viommu: Add iommufd_viommu_report_event helper

2025-01-21 Thread Nicolin Chen
On Tue, Jan 21, 2025 at 05:14:04PM -0400, Jason Gunthorpe wrote: > On Tue, Jan 21, 2025 at 01:02:16PM -0800, Nicolin Chen wrote: > > On Tue, Jan 21, 2025 at 04:09:24PM -0400, Jason Gunthorpe wrote: > > > On Tue, Jan 21, 2025 at 11:55:16AM -0800,

Re: [PATCH v5 08/14] iommufd/viommu: Add iommufd_viommu_report_event helper

2025-01-21 Thread Nicolin Chen
On Tue, Jan 21, 2025 at 08:21:28PM -0400, Jason Gunthorpe wrote: > On Tue, Jan 21, 2025 at 01:40:05PM -0800, Nicolin Chen wrote: > > > There is also the minor detail of what happens if the hypervisor HW > > > queue overflows - I don't know the answer here. It is security

Re: [PATCH v5 08/14] iommufd/viommu: Add iommufd_viommu_report_event helper

2025-01-22 Thread Nicolin Chen
On Tue, Jan 21, 2025 at 01:40:13PM -0800, Nicolin Chen wrote: > On Tue, Jan 21, 2025 at 05:14:04PM -0400, Jason Gunthorpe wrote: > > Since we don't hold the spinlock the whole time there is a race where > > we could pull the overflow off and then another entry could be pushed

Re: [PATCH v5 08/14] iommufd/viommu: Add iommufd_viommu_report_event helper

2025-01-12 Thread Nicolin Chen
On Fri, Jan 10, 2025 at 03:51:14PM -0400, Jason Gunthorpe wrote: > On Fri, Jan 10, 2025 at 10:38:42AM -0800, Nicolin Chen wrote: > > > The virtual event queue should behave the same as if the physical > > > event queue overflows, and that logic should be in the smmu drive

Re: [PATCH v5 06/14] iommufd: Add IOMMUFD_OBJ_VEVENTQ and IOMMUFD_CMD_VEVENTQ_ALLOC

2025-01-12 Thread Nicolin Chen
On Mon, Jan 13, 2025 at 02:52:32AM +, Tian, Kevin wrote: > > From: Nicolin Chen > > Sent: Saturday, January 11, 2025 5:29 AM > > > > On Fri, Jan 10, 2025 at 07:06:49AM +, Tian, Kevin wrote: > > > > From: Nicolin Chen > > &g

Re: [PATCH v5 13/14] iommu/arm-smmu-v3: Introduce struct arm_smmu_vmaster

2025-01-13 Thread Nicolin Chen
On Mon, Jan 13, 2025 at 03:29:27PM -0400, Jason Gunthorpe wrote: > On Tue, Jan 07, 2025 at 09:10:16AM -0800, Nicolin Chen wrote: > > > +int arm_smmu_attach_prepare_vmaster(struct arm_smmu_attach_state *state, > > + struct iommu_domain *domain) >

Re: [PATCH v5 08/14] iommufd/viommu: Add iommufd_viommu_report_event helper

2025-01-13 Thread Nicolin Chen
On Mon, Jan 13, 2025 at 03:21:44PM -0400, Jason Gunthorpe wrote: > On Sun, Jan 12, 2025 at 09:37:41PM -0800, Nicolin Chen wrote: > > > > > > I supposed we will need a way to indicate lost events to userspace on > > > > > top of this? > > &g

Re: [PATCH v5 14/14] iommu/arm-smmu-v3: Report events that belong to devices attached to vIOMMU

2025-01-13 Thread Nicolin Chen
On Thu, Jan 09, 2025 at 07:04:10PM +0800, kernel test robot wrote: > sparse warnings: (new ones prefixed by >>) > >> drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-iommufd.c:461:21: sparse: > >> sparse: invalid assignment: &= >drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-iommufd.c:461:21: sparse:

Re: [PATCH v5 14/14] iommu/arm-smmu-v3: Report events that belong to devices attached to vIOMMU

2025-01-13 Thread Nicolin Chen
On Mon, Jan 13, 2025 at 03:06:41PM -0400, Jason Gunthorpe wrote: > On Mon, Jan 13, 2025 at 11:01:10AM -0800, Nicolin Chen wrote: > > > +/* This is basically iommu_vevent_arm_smmuv3 in u64 for conversion */ > > +struct arm_vsmmu_evt { > > + union { > > +

Re: [PATCH v5 06/14] iommufd: Add IOMMUFD_OBJ_VEVENTQ and IOMMUFD_CMD_VEVENTQ_ALLOC

2025-01-13 Thread Nicolin Chen
On Mon, Jan 13, 2025 at 03:12:25PM -0400, Jason Gunthorpe wrote: > On Fri, Jan 10, 2025 at 01:58:21PM -0800, Nicolin Chen wrote: > > Hmm, it seems that I haven't got your first narrative straight.. > > > > Would you mind elaborate "copy_to_user() can block while wai

Re: [PATCH v5 08/14] iommufd/viommu: Add iommufd_viommu_report_event helper

2025-01-13 Thread Nicolin Chen
On Mon, Jan 13, 2025 at 03:54:33PM -0400, Jason Gunthorpe wrote: > On Mon, Jan 13, 2025 at 11:47:52AM -0800, Nicolin Chen wrote: > > > The other approach would be to add a sequence number to each event and > > > let userspace detect the non-montonicity. It would require add

Re: [PATCH v3 06/14] iommufd: Add IOMMUFD_OBJ_VIRQ and IOMMUFD_CMD_VIRQ_ALLOC

2025-01-02 Thread Nicolin Chen
On Thu, Jan 02, 2025 at 04:52:46PM -0400, Jason Gunthorpe wrote: > On Tue, Dec 17, 2024 at 09:00:19PM -0800, Nicolin Chen wrote: > > +/* An iommufd_virq_header packs a vIOMMU interrupt in an iommufd_virq > > queue */ > > +struct iommufd_virq_header { > > + struct list

Re: [PATCH v3 07/14] iommufd/viommu: Add iommufd_viommu_get_vdev_id helper

2024-12-23 Thread Nicolin Chen
On Mon, Dec 23, 2024 at 10:28:32AM +0800, Baolu Lu wrote: > On 12/19/24 13:06, Nicolin Chen wrote: > > On Thu, Dec 19, 2024 at 10:05:53AM +0800, Baolu Lu wrote: > > > On 12/18/24 13:00, Nicolin Chen wrote: > > > > This is a reverse search v.s. iommufd_viommu_find_dev

Re: [PATCH v5 08/14] iommufd/viommu: Add iommufd_viommu_report_event helper

2025-01-10 Thread Nicolin Chen
On Fri, Jan 10, 2025 at 03:51:14PM -0400, Jason Gunthorpe wrote: > On Fri, Jan 10, 2025 at 10:38:42AM -0800, Nicolin Chen wrote: > > > The virtual event queue should behave the same as if the physical > > > event queue overflows, and that logic should be in the smmu drive

Re: [PATCH v5 08/14] iommufd/viommu: Add iommufd_viommu_report_event helper

2025-01-10 Thread Nicolin Chen
On Fri, Jan 10, 2025 at 01:41:32PM -0400, Jason Gunthorpe wrote: > On Tue, Jan 07, 2025 at 09:10:11AM -0800, Nicolin Chen wrote: > > +/* > > + * Typically called in driver's threaded IRQ handler. > > + * The @type and @event_data must be defined in > &

Re: [PATCH v5 08/14] iommufd/viommu: Add iommufd_viommu_report_event helper

2025-01-10 Thread Nicolin Chen
On Fri, Jan 10, 2025 at 10:51:49AM -0400, Jason Gunthorpe wrote: > On Fri, Jan 10, 2025 at 07:12:46AM +, Tian, Kevin wrote: > > > > + if (!viommu) > > > + return -ENODEV; > > > + if (WARN_ON_ONCE(!viommu->ops || !viommu->ops- > > > >supports_veventq || > > > + !viommu-

Re: [PATCH v5 06/14] iommufd: Add IOMMUFD_OBJ_VEVENTQ and IOMMUFD_CMD_VEVENTQ_ALLOC

2025-01-10 Thread Nicolin Chen
On Fri, Jan 10, 2025 at 01:48:42PM -0400, Jason Gunthorpe wrote: > On Tue, Jan 07, 2025 at 09:10:09AM -0800, Nicolin Chen wrote: > > > +static ssize_t iommufd_veventq_fops_read(struct iommufd_eventq *eventq, > > +char __user

Re: [PATCH v5 04/14] iommufd: Abstract an iommufd_eventq from iommufd_fault

2025-01-10 Thread Nicolin Chen
On Fri, Jan 10, 2025 at 01:26:37PM -0400, Jason Gunthorpe wrote: > +#define INIT_EVENTQ_FOPS(read_op, write_op) \ > + (struct file_operations){ \ > + .owner = THIS_MODULE, \ > + .open = nonseekab

Re: [PATCH v5 06/14] iommufd: Add IOMMUFD_OBJ_VEVENTQ and IOMMUFD_CMD_VEVENTQ_ALLOC

2025-01-10 Thread Nicolin Chen
On Fri, Jan 10, 2025 at 07:06:49AM +, Tian, Kevin wrote: > > From: Nicolin Chen > > Sent: Wednesday, January 8, 2025 1:10 AM > > + > > +int iommufd_veventq_alloc(struct iommufd_ucmd *ucmd) > > +{ > > + struct iommu_veventq_alloc *cmd = ucmd->cmd;

Re: [PATCH v5 07/14] iommufd/viommu: Add iommufd_viommu_get_vdev_id helper

2025-01-10 Thread Nicolin Chen
On Fri, Jan 10, 2025 at 07:07:36AM +, Tian, Kevin wrote: > > From: Nicolin Chen > > Sent: Wednesday, January 8, 2025 1:10 AM > > + > > + xa_lock(&viommu->vdevs); > > + xa_for_each(&viommu->vdevs, index, vdev) {

Re: [PATCH v8 12/14] iommu/arm-smmu-v3: Introduce struct arm_smmu_vmaster

2025-04-09 Thread Nicolin Chen
On Mon, Apr 07, 2025 at 08:08:57PM +0800, Zhangfei Gao wrote: > Hi, Nico > > On Wed, 26 Feb 2025 at 01:35, Nicolin Chen wrote: > > > > Use it to store all vSMMU-related data. The vsid (Virtual Stream ID) will > > be the first use case. Since the vsid reader will be

Re: [PATCH v8 12/14] iommu/arm-smmu-v3: Introduce struct arm_smmu_vmaster

2025-03-17 Thread Nicolin Chen
On Mon, Mar 17, 2025 at 12:44:23PM -0300, Jason Gunthorpe wrote: > On Tue, Mar 11, 2025 at 10:43:08AM -0700, Nicolin Chen wrote: > > > > +int arm_smmu_attach_prepare_vmaster(struct arm_smmu_attach_state > > > > *state, > > > > +

Re: [PATCH v2 05/22] iommufd: Add iommufd_struct_destroy to revert iommufd_viommu_alloc

2025-04-28 Thread Nicolin Chen
On Sun, Apr 27, 2025 at 02:55:40PM +0800, Baolu Lu wrote: > On 4/26/25 13:58, Nicolin Chen wrote: > > An IOMMU driver that allocated a vIOMMU may want to revert the allocation, > > if it encounters an internal error after the allocation. So, there needs a > > destroy help

Re: [PATCH v2 08/22] iommufd: Abstract iopt_pin_pages and iopt_unpin_pages helpers

2025-04-28 Thread Nicolin Chen
On Sun, Apr 27, 2025 at 03:22:13PM +0800, Baolu Lu wrote: > On 4/26/25 13:58, Nicolin Chen wrote: > > The new vCMDQ object will be added for HW to access the guest memory for a > > HW-accelerated virtualization feature. It needs to ensure the guest memory > > pages are pinned

Re: [PATCH v2 02/22] iommu: Pass in a driver-level user data structure to viommu_alloc op

2025-04-28 Thread Nicolin Chen
On Sun, Apr 27, 2025 at 02:31:54PM +0800, Baolu Lu wrote: > On 4/26/25 13:57, Nicolin Chen wrote: > > The new type of vIOMMU for tegra241-cmdqv needs to pass in a driver-level > > data structure from user space via iommufd, so add a user_data to the op. > > > > R

Re: [PATCH v2 08/22] iommufd: Abstract iopt_pin_pages and iopt_unpin_pages helpers

2025-04-28 Thread Nicolin Chen
On Mon, Apr 28, 2025 at 03:12:33PM -0700, Nicolin Chen wrote: > On Mon, Apr 28, 2025 at 08:14:19PM +, Pranjal Shrivastava wrote: > > On Fri, Apr 25, 2025 at 10:58:03PM -0700, Nicolin Chen wrote: > > > + iopt_for_each_contig_area(&iter, area, iopt, iova, last_iova) { &g

Re: [PATCH v2 08/22] iommufd: Abstract iopt_pin_pages and iopt_unpin_pages helpers

2025-04-28 Thread Nicolin Chen
On Mon, Apr 28, 2025 at 08:14:19PM +, Pranjal Shrivastava wrote: > On Fri, Apr 25, 2025 at 10:58:03PM -0700, Nicolin Chen wrote: > > + iopt_for_each_contig_area(&iter, area, iopt, iova, last_iova) { > > + unsigned long last = min(last_iova, iopt_

Re: [PATCH v2 10/22] iommufd/viommmu: Add IOMMUFD_CMD_VCMDQ_ALLOC ioctl

2025-04-28 Thread Nicolin Chen
On Mon, Apr 28, 2025 at 09:34:05PM +, Pranjal Shrivastava wrote: > On Fri, Apr 25, 2025 at 10:58:05PM -0700, Nicolin Chen wrote: > > @@ -501,6 +504,9 @@ static const struct iommufd_object_ops > > iommufd_object_ops[] = { > > [IOMMUFD_OBJ_IOAS] = { >

Re: [PATCH v1 15/16] iommu/tegra241-cmdqv: Add user-space use support

2025-04-23 Thread Nicolin Chen
On Wed, Apr 23, 2025 at 08:55:51AM -0300, Jason Gunthorpe wrote: > On Wed, Apr 23, 2025 at 08:05:49AM +, Tian, Kevin wrote: > > > It's not a good idea having the kernel trust the VMM. > > It certainly shouldn't trust it, but it can validate the VMM's choice > and generate a failure if it isn

Re: [PATCH v1 00/16] iommufd: Add vIOMMU infrastructure (Part-4 vCMDQ)

2025-04-23 Thread Nicolin Chen
On Wed, Apr 23, 2025 at 12:58:19PM +0530, Vasant Hegde wrote: > On 4/11/2025 12:07 PM, Nicolin Chen wrote: > > The vIOMMU object is designed to represent a slice of an IOMMU HW for its > > virtualization features shared with or passed to user space (a VM mostly) > > in a w

[PATCH v2 07/22] iommufd/selftest: Add covearge for viommu data

2025-04-25 Thread Nicolin Chen
Extend the existing test_cmd/err_viommu_alloc helpers to accept optional user data. And add a TEST_F for a loopback test. Signed-off-by: Nicolin Chen --- tools/testing/selftests/iommu/iommufd_utils.h | 21 +- tools/testing/selftests/iommu/iommufd.c | 29

[PATCH v2 01/22] iommufd/viommu: Add driver-allocated vDEVICE support

2025-04-25 Thread Nicolin Chen
Gunthorpe Signed-off-by: Nicolin Chen --- drivers/iommu/iommufd/iommufd_private.h | 8 -- include/linux/iommufd.h | 34 + drivers/iommu/iommufd/viommu.c | 9 ++- 3 files changed, 42 insertions(+), 9 deletions(-) diff --git a/drivers/iommu

[PATCH v2 00/22] iommufd: Add vIOMMU infrastructure (Part-4 vCMDQ)

2025-04-25 Thread Nicolin Chen
lftest coverage for IOMMUFD_CMD_VCMDQ_ALLOC * [iommufd] Add iopt_pin_pages() to prevent queue memory from unmapping v1 https://lore.kernel.org/all/cover.1744353300.git.nicol...@nvidia.com/ Thanks Nicolin Nicolin Chen (22): iommufd/viommu: Add driver-allocated vDEVICE support iommu: Pass i

[PATCH v2 05/22] iommufd: Add iommufd_struct_destroy to revert iommufd_viommu_alloc

2025-04-25 Thread Nicolin Chen
iommufd_struct_destroy() helper that will abort all kinds of driver structures, not confined to iommufd_viommu but also the new ones being added in the future. Reviewed-by: Jason Gunthorpe Signed-off-by: Nicolin Chen --- drivers/iommu/iommufd/iommufd_private.h | 1 - include/linux/iommufd.h | 15

[PATCH v2 12/22] iommufd/selftest: Add coverage for IOMMUFD_CMD_VCMDQ_ALLOC

2025-04-25 Thread Nicolin Chen
Some simple tests for IOMMUFD_CMD_VCMDQ_ALLOC infrastructure covering the new iommufd_vcmdq_depend/undepend() helpers. Signed-off-by: Nicolin Chen --- drivers/iommu/iommufd/iommufd_test.h | 3 + tools/testing/selftests/iommu/iommufd_utils.h | 30 + drivers/iommu/iommufd

[PATCH v2 16/22] iommu/arm-smmu-v3-iommufd: Add vsmmu_alloc impl op

2025-04-25 Thread Nicolin Chen
An impl driver might support its own vIOMMU object, as tegra241-cmdqv will add IOMMU_VIOMMU_TYPE_TEGRA241_CMDQV. Add a vsmmu_alloc op to give impl a try, upon failure fallback to standard vsmmu allocation for IOMMU_VIOMMU_TYPE_ARM_SMMUV3. Signed-off-by: Nicolin Chen --- drivers/iommu/arm/arm

Re: [PATCH v2 10/22] iommufd/viommmu: Add IOMMUFD_CMD_VCMDQ_ALLOC ioctl

2025-04-30 Thread Nicolin Chen
On Wed, Apr 30, 2025 at 09:52:09AM +0530, Vasant Hegde wrote: > >>> Will the hardware replace the physical device ID in the event with > >>> the virtual device ID when injecting the event to a guest event/PPR > >>> queue? > >>> If so, yea, I think you can define them separately using the> vCMDQ >

Re: [PATCH v2 13/22] iommufd: Add mmap interface

2025-04-29 Thread Nicolin Chen
On Tue, Apr 29, 2025 at 09:35:07PM +, Pranjal Shrivastava wrote: > On Tue, Apr 29, 2025 at 02:05:12PM -0700, Nicolin Chen wrote: > > On Tue, Apr 29, 2025 at 08:55:47PM +, Pranjal Shrivastava wrote: > > > On Tue, Apr 29, 2025 at 01:39:09PM -0700, Nicolin Chen wrote: >

Re: [PATCH v2 20/22] iommu/tegra241-cmdqv: Do not statically map LVCMDQs

2025-04-29 Thread Nicolin Chen
On Tue, Apr 29, 2025 at 10:32:19PM +, Pranjal Shrivastava wrote: > On Fri, Apr 25, 2025 at 10:58:15PM -0700, Nicolin Chen wrote: > > To simplify the mappings from global VCMDQs to VINTFs' LVCMDQs, the design > > chose to do static allocations and mappings in the g

[PATCH v1 02/16] iommufd/viommu: Allow driver-specific user data for a vIOMMU object

2025-04-10 Thread Nicolin Chen
The new type of vIOMMU for tegra241-cmdqv driver needs a driver-specific user data. So, add data_len/uptr to the iommu_viommu_alloc uAPI and pass it in via the viommu_alloc iommu op. Signed-off-by: Nicolin Chen --- include/uapi/linux/iommufd.h | 6 ++ drivers/iommu/iommufd/viommu.c | 8

[PATCH v1 08/16] iommufd/viommu: Introduce IOMMUFD_OBJ_VCMDQ and its related struct

2025-04-10 Thread Nicolin Chen
eue - AMD vIOMMU's command buffer Inroduce a struct iommufd_vcmdq and its allocator iommufd_vcmdq_alloc(). Also, add a pair of viommu ops for iommufd to forward user space ioctls to IOMMU drivers. Signed-off-by: Nicolin Chen --- include/linux/iommufd.h | 31 +++ 1 f

[PATCH v1 10/16] iommufd: Add mmap interface

2025-04-10 Thread Nicolin Chen
. And give IOMMU drivers a pair of helpers to add and delete mmap regions onto the mt_mmap. Signed-off-by: Nicolin Chen --- drivers/iommu/iommufd/iommufd_private.h | 9 ++ include/linux/iommufd.h | 15 ++ drivers/iommu/iommufd/driver.c | 40

[PATCH v1 05/16] iommufd/selftest: Support user_data in mock_viommu_alloc

2025-04-10 Thread Nicolin Chen
Add a simple user_data for an input-to-output loopback test. Signed-off-by: Nicolin Chen --- drivers/iommu/iommufd/iommufd_test.h | 13 + drivers/iommu/iommufd/selftest.c | 19 +++ 2 files changed, 32 insertions(+) diff --git a/drivers/iommu/iommufd

[PATCH v1 00/16] iommufd: Add vIOMMU infrastructure (Part-4 vCMDQ)

2025-04-10 Thread Nicolin Chen
nc/iommufd/commits/iommufd_vcmdq-v1 Paring QEMU branch for testing: https://github.com/nicolinc/qemu/commits/wip/for_iommufd_vcmdq-v1 Thanks Nicolin Nicolin Chen (16): iommu: Pass in a driver-level user data structure to viommu_alloc op iommufd/viommu: Allow driver-specific user data for a vIO

[PATCH v1 01/16] iommu: Pass in a driver-level user data structure to viommu_alloc op

2025-04-10 Thread Nicolin Chen
The new type of vIOMMU for tegra241-cmdqv needs to pass in a driver-level data structure from user space via iommufd, so add a user_data to the op. Signed-off-by: Nicolin Chen --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h | 3 ++- include/linux/iommu.h

[PATCH v1 03/16] iommu: Add iommu_copy_struct_to_user helper

2025-04-10 Thread Nicolin Chen
Similar to the iommu_copy_struct_from_user helper receiving data from the user space, add an iommu_copy_struct_to_user helper to report output data back to the user space data pointer. Signed-off-by: Nicolin Chen --- include/linux/iommu.h | 40 1 file

[PATCH v1 07/16] iommufd/viommu: Add driver-allocated vDEVICE support

2025-04-10 Thread Nicolin Chen
To allow IOMMU drivers to allocate own vDEVICE structures, move the struct iommufd_vdevice to the public header and provide a pair of viommu ops. The iommufd_vdevice_alloc_ioctl will prioritize the callback function from the viommu ops, i.e. a driver-allocated vDEVICE. Signed-off-by: Nicolin

[PATCH v1 04/16] iommufd: Add iommufd_struct_destroy to revert iommufd_viommu_alloc

2025-04-10 Thread Nicolin Chen
iommufd_struct_destroy() helper that will abort all kinds of driver structures, not confined to iommufd_viommu but also the new ones being added by the following patches. Signed-off-by: Nicolin Chen --- drivers/iommu/iommufd/iommufd_private.h | 1 - include/linux/iommufd.h | 15

[PATCH v1 12/16] Documentation: userspace-api: iommufd: Update vCMDQ

2025-04-10 Thread Nicolin Chen
With the introduction of the new object and its infrastructure, update the doc to reflect that. Signed-off-by: Nicolin Chen --- Documentation/userspace-api/iommufd.rst | 11 +++ 1 file changed, 11 insertions(+) diff --git a/Documentation/userspace-api/iommufd.rst b/Documentation

[PATCH v1 09/16] iommufd/viommmu: Add IOMMUFD_CMD_VCMDQ_ALLOC ioctl

2025-04-10 Thread Nicolin Chen
Introduce a new IOMMUFD_CMD_VCMDQ_ALLOC ioctl for user space to allocate a vCMDQ for a vIOMMU object. Simply increase the refcount of the vIOMMU. Signed-off-by: Nicolin Chen --- drivers/iommu/iommufd/iommufd_private.h | 2 + include/uapi/linux/iommufd.h| 32 + drivers

[PATCH v1 15/16] iommu/tegra241-cmdqv: Add user-space use support

2025-04-10 Thread Nicolin Chen
hypercall. As an initial version, the number of VCMDQs per VINTF is fixed to two. Signed-off-by: Nicolin Chen --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h | 15 + include/uapi/linux/iommufd.h | 34 ++ .../arm/arm-smmu-v3/arm-smmu-v3-iommufd.c | 6 +- .../iommu/arm/a

[PATCH v1 16/16] iommu/tegra241-cmdqv: Add IOMMU_VEVENTQ_TYPE_TEGRA241_CMDQV support

2025-04-10 Thread Nicolin Chen
Add a new vEVENTQ type for VINTFs that are assigned to the user space. Simply report the two 64-bit LVCMDQ_ERR_MAPs register values. Signed-off-by: Nicolin Chen --- include/uapi/linux/iommufd.h | 15 + .../iommu/arm/arm-smmu-v3/tegra241-cmdqv.c| 22

[PATCH v1 14/16] iommu/arm-smmu-v3: Add vsmmu_alloc impl op

2025-04-10 Thread Nicolin Chen
An impl driver might support its own vIOMMU object, as the following patch will add IOMMU_VIOMMU_TYPE_TEGRA241_CMDQV. Add a vsmmu_alloc op to give impl a try, upon failure fallback to standard vsmmu allocation for IOMMU_VIOMMU_TYPE_ARM_SMMUV3. Signed-off-by: Nicolin Chen --- drivers/iommu/arm

[PATCH v1 11/16] iommufd/selftest: Add coverage for the new mmap interface

2025-04-10 Thread Nicolin Chen
Extend the loopback test to a new mmap page. Signed-off-by: Nicolin Chen --- drivers/iommu/iommufd/iommufd_test.h| 4 +++ drivers/iommu/iommufd/selftest.c| 47 - tools/testing/selftests/iommu/iommufd.c | 5 +++ 3 files changed, 48 insertions(+), 8 deletions

[PATCH v1 13/16] iommu/tegra241-cmdqv: Use request_threaded_irq

2025-04-10 Thread Nicolin Chen
A vIRQ can be reported only from a threaded IRQ context. Change to use to request_threaded_irq to support that. Signed-off-by: Nicolin Chen --- drivers/iommu/arm/arm-smmu-v3/tegra241-cmdqv.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/iommu/arm/arm-smmu-v3

[PATCH v1 06/16] iommufd/selftest: Add covearge for viommu data

2025-04-10 Thread Nicolin Chen
Extend the existing test_cmd/err_viommu_alloc helpers to accept optional user data. And add a TEST_F for a loopback test. Signed-off-by: Nicolin Chen --- tools/testing/selftests/iommu/iommufd_utils.h | 21 +- tools/testing/selftests/iommu/iommufd.c | 29

Re: [PATCH v1 03/16] iommu: Add iommu_copy_struct_to_user helper

2025-04-14 Thread Nicolin Chen
On Mon, Apr 14, 2025 at 08:25:40AM -0700, Matt Ochs wrote: > > On Apr 11, 2025, at 1:37 AM, Nicolin Chen wrote: > > +__iommu_copy_struct_to_user(const struct iommu_user_data *dst_data, > > +void *src_data, unsigned int data_type, > > +size_t data_len, size_t

Re: [PATCH v1 03/16] iommu: Add iommu_copy_struct_to_user helper

2025-04-14 Thread Nicolin Chen
On Fri, Apr 11, 2025 at 06:05:30PM +0530, ALOK TIWARI wrote: > On 11-04-2025 12:07, Nicolin Chen wrote: > > + * iommu_copy_struct_to_user - Report iommu driver specific user space data > > + * @user_data: Pointer to a struct iommu_user_data for user space data > > location &

Re: [PATCH v2 08/22] iommufd: Abstract iopt_pin_pages and iopt_unpin_pages helpers

2025-05-05 Thread Nicolin Chen
On Mon, May 05, 2025 at 12:01:09PM -0300, Jason Gunthorpe wrote: > On Mon, Apr 28, 2025 at 10:41:45AM -0700, Nicolin Chen wrote: > > > I'm uncertain, but perhaps pr_warn_ratelimited() would be a better > > > alternative to WARN_ON() here? WARN_ON_ONCE() generates warning

Re: [PATCH v2 09/22] iommufd/viommu: Introduce IOMMUFD_OBJ_VCMDQ and its related struct

2025-05-05 Thread Nicolin Chen
On Mon, May 05, 2025 at 12:02:14PM -0300, Jason Gunthorpe wrote: > On Mon, Apr 28, 2025 at 11:10:40AM -0700, Nicolin Chen wrote: > > > > +struct iommufd_vcmdq { > > > > + struct iommufd_object obj; > > > > + struct iommufd_ctx *ictx; > &

Re: [PATCH v2 08/22] iommufd: Abstract iopt_pin_pages and iopt_unpin_pages helpers

2025-05-05 Thread Nicolin Chen
On Mon, May 05, 2025 at 12:55:05PM -0300, Jason Gunthorpe wrote: > On Mon, May 05, 2025 at 08:44:22AM -0700, Nicolin Chen wrote: > > On Mon, May 05, 2025 at 12:01:09PM -0300, Jason Gunthorpe wrote: > > > On Mon, Apr 28, 2025 at 10:41:45AM -0700, Nicolin Chen wrote: > >

Re: [PATCH v2 08/22] iommufd: Abstract iopt_pin_pages and iopt_unpin_pages helpers

2025-05-05 Thread Nicolin Chen
On Mon, May 05, 2025 at 01:05:54PM -0300, Jason Gunthorpe wrote: > On Mon, May 05, 2025 at 09:03:28AM -0700, Nicolin Chen wrote: > > On Mon, May 05, 2025 at 12:55:05PM -0300, Jason Gunthorpe wrote: > > > On Mon, May 05, 2025 at 08:44:22AM -0700, Nicolin Chen wrote: > > >

Re: [PATCH v2 21/22] iommu/tegra241-cmdqv: Add user-space use support

2025-04-30 Thread Nicolin Chen
On Wed, Apr 30, 2025 at 09:59:13PM +, Pranjal Shrivastava wrote: > On Fri, Apr 25, 2025 at 10:58:16PM -0700, Nicolin Chen wrote: > > The CMDQV HW supports a user-space use for virtualization cases. It allows > > the VM to issue guest-level TLBI or ATC_INV commands directly to th

Re: [PATCH v2 21/22] iommu/tegra241-cmdqv: Add user-space use support

2025-04-30 Thread Nicolin Chen
On Wed, Apr 30, 2025 at 03:39:22PM -0700, Nicolin Chen wrote: > On Wed, Apr 30, 2025 at 09:59:13PM +, Pranjal Shrivastava wrote: > > > enum iommu_viommu_type { > > > IOMMU_VIOMMU_TYPE_DEFAULT = 0, > > > IOMMU_VIOMMU_TYPE_ARM_SMMUV3 = 1, > > >

<    1   2   3   4   5   6   7   8   >