Skip to contentSkip to conversation

Add shared workqueue support for idxd driver

PATCH Applied Dave Jiang 6 participants 26 messages Sep 24, 2020 – Oct 7, 2020

Subsystems (3)

v6 of 8 Applied Latest is v8 →

lore
Share & tools
lore

Dave Jiang

author reviewer
#0 lore raw

v6 cover Add shared workqueue support for idxd driver

v6:
Boris:
- Fixup MOBDIR64B inline asm input/output constraints

v5:
Boris:
- Fixup commit headers
- Fixup var names for movdir64b()
- Move enqcmds() to special_insns.h
- Fix up comments for enqcmds()
- Change enqcmds() to reflect instruction return. 0 as success, -EAGAIN for fail.

DavidL:
- Fixup enqcmds() gas constraints

v4:
- Rebased against latest dmaengine/next tree
- Split out enqcmd and pasid dependency.

V3:
- Rebased against latest dmaengine/next tree.
- Updated API doc with new kernel version and dates.
- Changed to allow driver to load without ENQCMD support.
- Break out some patches that can be sent ahead of this series for inclusion.

v2:
- Dropped device feature enabling (GregKH)
- Dropped PCI device feature enabling (Bjorn)
- https://members.pcisig.com/wg/PCI-SIG/document/14237
- After some internal discussion, we have decided to hold off on the enabling of DMWR due to the following reasons. 1. Most first gen hw will not have the feature bits. 2. First gen hw that support the feature are all Root Complex integrated endpoints. 3. PCI devices that are not RCiEP’s with this capability won’t surface for a few years so we can wait until we can test the full code.
- Dropped special ioremap (hch)
- Added proper support for WQ flush (tony, dan)
- Changed descriptor submission to use sbitmap_queue for blocking. (dan)

Driver stage 1 postings for context: [1]

The patch series has compilation and functional dependency on Fenghua's "Tag application address space for devices" patch series for the ENQCMD CPU command enumeration and the PASID MSR support. [2]

== Background ==
A typical DMA device requires the driver to translate application buffers to hardware addresses, and a kernel-user transition to notify the hardware of new work. Shared Virtual Addressing (SVA) allows the processor and device to use the same virtual addresses without requiring software to translate between the address spaces. ENQCMD is a new instruction on Intel Platforms that allows user applications to directly notify hardware of new work, much like how doorbells are used in some hardware, but it carries a payload along with it. ENQCMDS is the supervisor version (ring0) of ENQCMD.

== ENQCMDS ==
Introduce enqcmds(), a helper funciton that copies an input payload to a 64B aligned destination and confirms whether the payload was accepted by the device or not. enqcmds() wraps the new ENQCMDS CPU instruction. The ENQCMDS is a ring 0 CPU instruction that performs similar to the ENQCMD instruction. Descriptor submission must use ENQCMD(S) for shared workqueues (swq) on an Intel DSA device.

== Shared WQ support ==
Introduce shared workqueue (swq) support for the idxd driver. The current idxd driver contains dedicated workqueue (dwq) support only. A dwq accepts descriptors from a MOVDIR64B instruction. MOVDIR64B is a posted instruction on the PCIe bus, it does not wait for any response from the device. If the wq is full, submitted descriptors are dropped. A swq utilizes the ENQCMDS in ring 0, which is a non-posted instruction. The zero flag would be set to 1 if the device rejects the descriptor or if the wq is full. A swq can be shared between multiple users (kernel or userspace) due to not having to keep track of the wq full condition for submission. A swq requires PASID and can only run with SVA support.

== IDXD SVA support ==
Add utilization of PASID to support Shared Virtual Addressing (SVA). With PASID support, the descriptors can be programmed with host virtual address (HVA) rather than IOVA. The hardware will work with the IOMMU in fulfilling page requests. With SVA support, a user app using the char device interface can now submit descriptors without having to pin the virtual memory range it wants to DMA in its own address space.

The series does not add SVA support for the dmaengine subsystem. That support is coming at a later time.

[1]: https://lore.kernel.org/lkml/157965011794.73301.15960052071729101309.stgit@djiang5-desk3.ch.intel.com/
[2]: https://lore.kernel.org/lkml/[email protected]/
[3]: https://software.intel.com/en-us/articles/intel-sdm
[4]: https://software.intel.com/en-us/download/intel-scalable-io-virtualization-technical-specification
[5]: https://software.intel.com/en-us/download/intel-data-streaming-accelerator-preliminary-architecture-specification
[6]: https://01.org/blogs/2019/introducing-intel-data-streaming-accelerator
[7]: https://intel.github.io/idxd/
[8]: https://github.com/intel/idxd-driver idxd-stage2

---

Dave Jiang (5):
x86/asm: Carve out a generic movdir64b() helper for general usage x86/asm: Add enqcmds() to support ENQCMDS instruction
dmaengine: idxd: Add shared workqueue support
dmaengine: idxd: Clean up descriptors with fault error
dmaengine: idxd: Add ABI documentation for shared wq

 .../ABI/stable/sysfs-driver-dma-idxd          |  14 ++
 arch/x86/include/asm/io.h                     |  17 +--
 arch/x86/include/asm/special_insns.h          |  56 +++++++
 drivers/dma/Kconfig                           |  10 ++
 drivers/dma/idxd/cdev.c                       |  49 +++++-
 drivers/dma/idxd/device.c                     |  91 ++++++++++-
 drivers/dma/idxd/dma.c                        |   9 --
 drivers/dma/idxd/idxd.h                       |  33 +++-
 drivers/dma/idxd/init.c                       |  92 ++++++++---
 drivers/dma/idxd/irq.c                        | 143 ++++++++++++++++--
 drivers/dma/idxd/registers.h                  |  14 ++
 drivers/dma/idxd/submit.c                     |  35 ++++-
 drivers/dma/idxd/sysfs.c                      | 127 ++++++++++++++++
 13 files changed, 620 insertions(+), 70 deletions(-)
Signature · 1 line
2.21.3
author reviewer
#1 lore raw

PATCH v6 1/5 x86/asm: Carve out a generic movdir64b() helper for general usage

The MOVDIR64B instruction can be used by other wrapper instructions. Move the asm code to special_insns.h and have iosubmit_cmds512() call the asm function.

---
 arch/x86/include/asm/io.h            | 17 +++--------------
 arch/x86/include/asm/special_insns.h | 22 ++++++++++++++++++++++
 2 files changed, 25 insertions(+), 14 deletions(-)
arch/x86/include/asm/io.h +3 -14
index e1aa17a468a8..d726459d08e5 100644
@@ -401,7 +401,7 @@ extern bool phys_mem_access_encrypted(unsigned long phys_addr,
 
 /**
  * iosubmit_cmds512 - copy data to single MMIO location, in 512-bit units
- * @__dst: destination, in MMIO space (must be 512-bit aligned)
+ * @dst: destination, in MMIO space (must be 512-bit aligned)
  * @src: source
  * @count: number of 512 bits quantities to submit
  *
@@ -412,25 +412,14 @@ extern bool phys_mem_access_encrypted(unsigned long phys_addr,
  * Warning: Do not use this helper unless your driver has checked that the CPU
  * instruction is supported on the platform.
  */
-static inline void iosubmit_cmds512(void __iomem *__dst, const void *src,
+static inline void iosubmit_cmds512(void __iomem *dst, const void *src,
 				    size_t count)
 {
-	/*
-	 * Note that this isn't an "on-stack copy", just definition of "dst"
-	 * as a pointer to 64-bytes of stuff that is going to be overwritten.
-	 * In the MOVDIR64B case that may be needed as you can use the
-	 * MOVDIR64B instruction to copy arbitrary memory around. This trick
-	 * lets the compiler know how much gets clobbered.
-	 */
-	volatile struct { char _[64]; } *dst = __dst;
 	const u8 *from = src;
 	const u8 *end = from + count * 64;
 
 	while (from < end) {
-		/* MOVDIR64B [rdx], rax */
-		asm volatile(".byte 0x66, 0x0f, 0x38, 0xf8, 0x02"
-			     : "=m" (dst)
-			     : "d" (from), "a" (dst));
+		movdir64b(dst, from);
 		from += 64;
 	}
 }
arch/x86/include/asm/special_insns.h +22 -0
index 59a3e13204c3..2258c7d6e281 100644
@@ -234,6 +234,28 @@ static inline void clwb(volatile void *__p)
 
 #define nop() asm volatile ("nop")
 
+/* The dst parameter must be 64-bytes aligned */
+static inline void movdir64b(void *dst, const void *src)
+{
+	const struct { char _[64]; } *__src = src;
+	struct { char _[64]; } *__dst = dst;
+
+	/*
+	 * MOVDIR64B %(rdx), rax.
+	 *
+	 * Both __src and __dst must be memory constraints in order to tell the
+	 * compiler that no other memory accesses should be reordered around
+	 * this one.
+	 *
+	 * Also, both must be supplied as lvalues because this tells
+	 * the compiler what the object is (its size) the instruction accesses.
+	 * I.e., not the pointers but what they point, thus the deref'ing '*'.
+	 */
+	asm volatile(".byte 0x66, 0x0f, 0x38, 0xf8, 0x02"
+		     : "+m" (*__dst)
+		     :  "m" (*__src), "a" (__dst), "d" (__src));
+}
+
 #endif /* __KERNEL__ */
 
 #endif /* _ASM_X86_SPECIAL_INSNS_H */
Signature · 1 line
2.21.3
maintainer Reviewed-by on v6 1/5
#2 lore raw

Re: [PATCH v6 1/5] x86/asm: Carve out a generic movdir64b() helper for general usage

Quoted 6 lines · Dave Jiang

The MOVDIR64B instruction can be used by other wrapper instructions. Move the asm code to special_insns.h and have iosubmit_cmds512() call the asm function.

Signature · 4 lines
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette
author reviewer
#3 lore raw

PATCH v6 2/5 x86/asm: Add enqcmds() to support ENQCMDS instruction

In reply to Dave Jiang

Currently, the MOVDIR64B instruction is used to atomically submit 64-byte work descriptors to devices. Although it can encounter errors like device queue full, command not accepted, device not ready, etc when writing to a device MMIO, MOVDIR64B can not report back on errors from the device itself. This means that MOVDIR64B users need to separately interact with a device to see if a descriptor was successfully queued, which slows down device interactions.

ENQCMD and ENQCMDS also atomically submit 64-byte work descriptors to devices. But, they *can* report back errors directly from the device, such as if the device was busy, or device not enabled or does not support the command. This immediate feedback from the submission instruction itself reduces the number of interactions with the device and can greatly increase efficiency.

ENQCMD can be used at any privilege level, but can effectively only submit work on behalf of the current process. ENQCMDS is a ring0-only instruction and can explicitly specify a process context instead of being tied to the current process or needing to reprogram the IA32_PASID MSR.

Use ENQCMDS for work submission within the kernel because a Process Address ID (PASID) is setup to translate the kernel virtual address space. This PASID is provided to ENQCMDS from the descriptor structure submitted to the device and not retrieved from IA32_PASID MSR, which is setup for the current user address space.

See Intel Software Developer’s Manual for more information on the instructions.

---
 arch/x86/include/asm/special_insns.h | 34 ++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)
arch/x86/include/asm/special_insns.h +34 -0
index 2258c7d6e281..b4d2ce300c94 100644
@@ -256,6 +256,40 @@ static inline void movdir64b(void *dst, const void *src)
 		     :  "m" (*__src), "a" (__dst), "d" (__src));
 }
 
+/**
+ * enqcmds - copy a 512 bits data unit to single MMIO location
+ * @dst: destination, in MMIO space (must be 512-bit aligned)
+ * @src: source
+ *
+ * The ENQCMDS instruction allows software to write a 512 bits command to
+ * a 512 bits aligned special MMIO region that supports the instruction.
+ * A return status is loaded into the ZF flag in the RFLAGS register.
+ * ZF = 0 equates to success, and ZF = 1 indicates retry or error.
+ *
+ * The enqcmds() function uses the ENQCMDS instruction to submit data from
+ * kernel space to MMIO space, in a unit of 512 bits. Order of data access
+ * is not guaranteed, nor is a memory barrier performed afterwards. The
+ * function returns 0 on success and -EAGAIN on failure.
+ *
+ * Warning: Do not use this helper unless your driver has checked that the CPU
+ * instruction is supported on the platform and the device accepts ENQCMDS.
+ */
+static inline int enqcmds(void __iomem *dst, const void *src)
+{
+	int zf;
+
+	/* ENQCMDS [rdx], rax */
+	asm volatile(".byte 0xf3, 0x0f, 0x38, 0xf8, 0x02, 0x66, 0x90"
+		     CC_SET(z)
+		     : CC_OUT(z) (zf)
+		     : "a" (dst), "d" (src));
+	/* Submission failure is indicated via EFLAGS.ZF=1 */
+	if (zf)
+		return -EAGAIN;
+
+	return 0;
+}
+
 #endif /* __KERNEL__ */
 
 #endif /* _ASM_X86_SPECIAL_INSNS_H */
Signature · 1 line
2.21.3
maintainer Reviewed-by Tony Luck on v6 2/5
#4 lore raw

Re: [PATCH v6 2/5] x86/asm: Add enqcmds() to support ENQCMDS instruction

Quoted 2 lines · Dave Jiang

+/**
+ * enqcmds - copy a 512 bits data unit to single MMIO location

You forgot to fix this.

Quoted 16 lines

+ * @dst: destination, in MMIO space (must be 512-bit aligned)
+ * @src: source
+ *
+ * The ENQCMDS instruction allows software to write a 512 bits command to
+ * a 512 bits aligned special MMIO region that supports the instruction.
+ * A return status is loaded into the ZF flag in the RFLAGS register.
+ * ZF = 0 equates to success, and ZF = 1 indicates retry or error.
+ *
+ * The enqcmds() function uses the ENQCMDS instruction to submit data from
+ * kernel space to MMIO space, in a unit of 512 bits. Order of data access
+ * is not guaranteed, nor is a memory barrier performed afterwards. The
+ * function returns 0 on success and -EAGAIN on failure.
+ *
+ * Warning: Do not use this helper unless your driver has checked that the CPU
+ * instruction is supported on the platform and the device accepts ENQCMDS.
+ */

Review

Quoted 9 lines
(quoted diff) +9 -0
+static inline int enqcmds(void __iomem *dst, const void *src)
+{
+	int zf;
+
+	/* ENQCMDS [rdx], rax */
+	asm volatile(".byte 0xf3, 0x0f, 0x38, 0xf8, 0x02, 0x66, 0x90"
+		     CC_SET(z)
+		     : CC_OUT(z) (zf)
+		     : "a" (dst), "d" (src));

Those operands need to be specified the same way as for movdir64b.

I've done that to save roundtrip time - simply replace yours with this one after having tested it on actual hardware, of course.

---
From 39cbdc81d657efcb73c0f7d7ab5e5c53f439f267 Mon Sep 17 00:00:00 2001
From: Dave Jiang <[email protected]>
Date: Thu, 24 Sep 2020 11:00:38 -0700
Subject: [PATCH] x86/asm: Add an enqcmds() wrapper for the ENQCMDS instruction
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Currently, the MOVDIR64B instruction is used to atomically submit 64-byte work descriptors to devices. Although it can encounter errors like device queue full, command not accepted, device not ready, etc when writing to a device MMIO, MOVDIR64B can not report back on errors from the device itself. This means that MOVDIR64B users need to separately interact with a device to see if a descriptor was successfully queued, which slows down device interactions.

ENQCMD and ENQCMDS also atomically submit 64-byte work descriptors to devices. But, they *can* report back errors directly from the device, such as if the device was busy, or device not enabled or does not support the command. This immediate feedback from the submission instruction itself reduces the number of interactions with the device and can greatly increase efficiency.

ENQCMD can be used at any privilege level, but can effectively only submit work on behalf of the current process. ENQCMDS is a ring0-only instruction and can explicitly specify a process context instead of being tied to the current process or needing to reprogram the IA32_PASID MSR.

Use ENQCMDS for work submission within the kernel because a Process Address ID (PASID) is setup to translate the kernel virtual address space. This PASID is provided to ENQCMDS from the descriptor structure submitted to the device and not retrieved from IA32_PASID MSR, which is setup for the current user address space.

See Intel Software Developer’s Manual for more information on the instructions.

[ bp:
- Make operand constraints like movdir64b() because both insns are basically doing the same thing, more or less.
- Fixup comments and cleanup. ]

---
 arch/x86/include/asm/special_insns.h | 42 ++++++++++++++++++++++++++++
 1 file changed, 42 insertions(+)
arch/x86/include/asm/special_insns.h +42 -0
index 2f0c8a39c796..2c18c780b2d5 100644
@@ -262,6 +262,48 @@ static inline void movdir64b(void *dst, const void *src)
 		     :  "m" (*__src), "a" (__dst), "d" (__src));
 }
 
+/**
+ * enqcmds - Enqueue a command in supervisor (CPL0) mode
+ * @dst: destination, in MMIO space (must be 512-bit aligned)
+ * @src: 512 bits memory operand
+ *
+ * The ENQCMDS instruction allows software to write a 512-bit command to
+ * a 512-bit-aligned special MMIO region that supports the instruction.
+ * A return status is loaded into the ZF flag in the RFLAGS register.
+ * ZF = 0 equates to success, and ZF = 1 indicates retry or error.
+ *
+ * This function issues the ENQCMDS instruction to submit data from
+ * kernel space to MMIO space, in a unit of 512 bits. Order of data access
+ * is not guaranteed, nor is a memory barrier performed afterwards. It
+ * returns 0 on success and -EAGAIN on failure.
+ *
+ * Warning: Do not use this helper unless your driver has checked that the
+ * ENQCMDS instruction is supported on the platform and the device accepts
+ * ENQCMDS.
+ */
+static inline int enqcmds(void __iomem *dst, const void *src)
+{
+	const struct { char _[64]; } *__src = src;
+	struct { char _[64]; } *__dst = dst;
+	int zf;
+
+	/*
+	 * ENQCMDS %(rdx), rax
+	 *
+	 * See movdir64b()'s comment on operand specification.
+	 */
+	asm volatile(".byte 0xf3, 0x0f, 0x38, 0xf8, 0x02, 0x66, 0x90"
+		     CC_SET(z)
+		     : CC_OUT(z) (zf), "+m" (*__dst)
+		     : "m" (*__src), "a" (__dst), "d" (__src));
+
+	/* Submission failure is indicated via EFLAGS.ZF=1 */
+	if (zf)
+		return -EAGAIN;
+
+	return 0;
+}
+
 #endif /* __KERNEL__ */
 
 #endif /* _ASM_X86_SPECIAL_INSNS_H */
Signature · 7 lines
2.21.0

-- 
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette
author reviewer
#5 lore raw

Re: [PATCH v6 2/5] x86/asm: Add enqcmds() to support ENQCMDS instruction

Quoted 34 lines · Borislav Petkov
Quoted 2 lines · Dave Jiang

+/**
+ * enqcmds - copy a 512 bits data unit to single MMIO location

You forgot to fix this.

Quoted 16 lines

+ * @dst: destination, in MMIO space (must be 512-bit aligned)
+ * @src: source
+ *
+ * The ENQCMDS instruction allows software to write a 512 bits command to
+ * a 512 bits aligned special MMIO region that supports the instruction.
+ * A return status is loaded into the ZF flag in the RFLAGS register.
+ * ZF = 0 equates to success, and ZF = 1 indicates retry or error.
+ *
+ * The enqcmds() function uses the ENQCMDS instruction to submit data from
+ * kernel space to MMIO space, in a unit of 512 bits. Order of data access
+ * is not guaranteed, nor is a memory barrier performed afterwards. The
+ * function returns 0 on success and -EAGAIN on failure.
+ *
+ * Warning: Do not use this helper unless your driver has checked that the CPU
+ * instruction is supported on the platform and the device accepts ENQCMDS.
+ */

arch/x86/include/asm/special_insns.h static inline void movdir64b(void *dst, const void *src)

Quoted 9 lines
arch/x86/include/asm/special_insns.h +9 -0
+static inline int enqcmds(void __iomem *dst, const void *src)
+{
+	int zf;
+
+	/* ENQCMDS [rdx], rax */
+	asm volatile(".byte 0xf3, 0x0f, 0x38, 0xf8, 0x02, 0x66, 0x90"
+		     CC_SET(z)
+		     : CC_OUT(z) (zf)
+		     : "a" (dst), "d" (src));

Those operands need to be specified the same way as for movdir64b.

Quoted 2 lines

I've done that to save roundtrip time - simply replace yours with this one after having tested it on actual hardware, of course.

Thanks Boris! Very much appreciate this. I have tested and everything is good.

Quoted 107 lines

---
From 39cbdc81d657efcb73c0f7d7ab5e5c53f439f267 Mon Sep 17 00:00:00 2001
From: Dave Jiang <[email protected]>
Date: Thu, 24 Sep 2020 11:00:38 -0700
Subject: [PATCH] x86/asm: Add an enqcmds() wrapper for the ENQCMDS instruction
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Currently, the MOVDIR64B instruction is used to atomically submit 64-byte work descriptors to devices. Although it can encounter errors like device queue full, command not accepted, device not ready, etc when writing to a device MMIO, MOVDIR64B can not report back on errors from the device itself. This means that MOVDIR64B users need to separately interact with a device to see if a descriptor was successfully queued, which slows down device interactions.

ENQCMD and ENQCMDS also atomically submit 64-byte work descriptors to devices. But, they *can* report back errors directly from the device, such as if the device was busy, or device not enabled or does not support the command. This immediate feedback from the submission instruction itself reduces the number of interactions with the device and can greatly increase efficiency.

ENQCMD can be used at any privilege level, but can effectively only submit work on behalf of the current process. ENQCMDS is a ring0-only instruction and can explicitly specify a process context instead of being tied to the current process or needing to reprogram the IA32_PASID MSR.

Use ENQCMDS for work submission within the kernel because a Process Address ID (PASID) is setup to translate the kernel virtual address space. This PASID is provided to ENQCMDS from the descriptor structure submitted to the device and not retrieved from IA32_PASID MSR, which is setup for the current user address space.

See Intel Software Developer’s Manual for more information on the instructions.

[ bp:
- Make operand constraints like movdir64b() because both insns are basically doing the same thing, more or less.
- Fixup comments and cleanup. ]

---
  arch/x86/include/asm/special_insns.h | 42 ++++++++++++++++++++++++++++
  1 file changed, 42 insertions(+)
arch/x86/include/asm/special_insns.h +42 -0
index 2f0c8a39c796..2c18c780b2d5 100644
@@ -262,6 +262,48 @@ static inline void movdir64b(void *dst, const void *src)
  		     :  "m" (*__src), "a" (__dst), "d" (__src));
  }
 
+/**
+ * enqcmds - Enqueue a command in supervisor (CPL0) mode
+ * @dst: destination, in MMIO space (must be 512-bit aligned)
+ * @src: 512 bits memory operand
+ *
+ * The ENQCMDS instruction allows software to write a 512-bit command to
+ * a 512-bit-aligned special MMIO region that supports the instruction.
+ * A return status is loaded into the ZF flag in the RFLAGS register.
+ * ZF = 0 equates to success, and ZF = 1 indicates retry or error.
+ *
+ * This function issues the ENQCMDS instruction to submit data from
+ * kernel space to MMIO space, in a unit of 512 bits. Order of data access
+ * is not guaranteed, nor is a memory barrier performed afterwards. It
+ * returns 0 on success and -EAGAIN on failure.
+ *
+ * Warning: Do not use this helper unless your driver has checked that the
+ * ENQCMDS instruction is supported on the platform and the device accepts
+ * ENQCMDS.
+ */
+static inline int enqcmds(void __iomem *dst, const void *src)
+{
+	const struct { char _[64]; } *__src = src;
+	struct { char _[64]; } *__dst = dst;
+	int zf;
+
+	/*
+	 * ENQCMDS %(rdx), rax
+	 *
+	 * See movdir64b()'s comment on operand specification.
+	 */
+	asm volatile(".byte 0xf3, 0x0f, 0x38, 0xf8, 0x02, 0x66, 0x90"
+		     CC_SET(z)
+		     : CC_OUT(z) (zf), "+m" (*__dst)
+		     : "m" (*__src), "a" (__dst), "d" (__src));
+
+	/* Submission failure is indicated via EFLAGS.ZF=1 */
+	if (zf)
+		return -EAGAIN;
+
+	return 0;
+}
+
  #endif /* __KERNEL__ */
 
  #endif /* _ASM_X86_SPECIAL_INSNS_H */
#6 lore raw

RE: [PATCH v6 2/5] x86/asm: Add enqcmds() to support ENQCMDS instruction

In reply to Dave Jiang

From: Dave Jiang

Quoted 72 lines

Sent: 24 September 2020 19:01

Currently, the MOVDIR64B instruction is used to atomically submit 64-byte work descriptors to devices. Although it can encounter errors like device queue full, command not accepted, device not ready, etc when writing to a device MMIO, MOVDIR64B can not report back on errors from the device itself. This means that MOVDIR64B users need to separately interact with a device to see if a descriptor was successfully queued, which slows down device interactions.

ENQCMD and ENQCMDS also atomically submit 64-byte work descriptors to devices. But, they *can* report back errors directly from the device, such as if the device was busy, or device not enabled or does not support the command. This immediate feedback from the submission instruction itself reduces the number of interactions with the device and can greatly increase efficiency.

ENQCMD can be used at any privilege level, but can effectively only submit work on behalf of the current process. ENQCMDS is a ring0-only instruction and can explicitly specify a process context instead of being tied to the current process or needing to reprogram the IA32_PASID MSR.

Use ENQCMDS for work submission within the kernel because a Process Address ID (PASID) is setup to translate the kernel virtual address space. This PASID is provided to ENQCMDS from the descriptor structure submitted to the device and not retrieved from IA32_PASID MSR, which is setup for the current user address space.

See Intel Software Developer’s Manual for more information on the instructions.

---
 arch/x86/include/asm/special_insns.h | 34 ++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)
arch/x86/include/asm/special_insns.h +24 -0
index 2258c7d6e281..b4d2ce300c94 100644
@@ -256,6 +256,40 @@ static inline void movdir64b(void *dst, const void *src)
 		     :  "m" (*__src), "a" (__dst), "d" (__src));
 }
 
+/**
+ * enqcmds - copy a 512 bits data unit to single MMIO location
+ * @dst: destination, in MMIO space (must be 512-bit aligned)
+ * @src: source
+ *
+ * The ENQCMDS instruction allows software to write a 512 bits command to
+ * a 512 bits aligned special MMIO region that supports the instruction.
+ * A return status is loaded into the ZF flag in the RFLAGS register.
+ * ZF = 0 equates to success, and ZF = 1 indicates retry or error.
+ *
+ * The enqcmds() function uses the ENQCMDS instruction to submit data from
+ * kernel space to MMIO space, in a unit of 512 bits. Order of data access
+ * is not guaranteed, nor is a memory barrier performed afterwards. The
+ * function returns 0 on success and -EAGAIN on failure.
+ *
+ * Warning: Do not use this helper unless your driver has checked that the CPU
+ * instruction is supported on the platform and the device accepts ENQCMDS.
+ */
+static inline int enqcmds(void __iomem *dst, const void *src)
+{
+	int zf;
+
+	/* ENQCMDS [rdx], rax */
+	asm volatile(".byte 0xf3, 0x0f, 0x38, 0xf8, 0x02, 0x66, 0x90"

arch/x86/include/asm/special_insns.h static inline void movdir64b(void *dst, const void *src) · line 292

Quoted 10 lines
arch/x86/include/asm/special_insns.h +10 -0
+		     CC_SET(z)
+		     : CC_OUT(z) (zf)
+		     : "a" (dst), "d" (src));
+	/* Submission failure is indicated via EFLAGS.ZF=1 */
+	if (zf)
+		return -EAGAIN;
+
+	return 0;
+}
+

Doesn't this need an "m" input constraint for the source buffer. Otherwise if it is a local on-stack buffer the compiler will optimise away the instructions that write to it.

The missing output memory constraint is less of a problem. The driver needs to be using barriers of its own.

David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)

merge bot Applied
#7 lore raw

[tip: x86/pasid] x86/asm: Add an enqcmds() wrapper for the ENQCMDS instruction

In reply to Dave Jiang
The following commit has been merged into the x86/pasid branch of tip:

The following commit has been merged into the x86/pasid branch of tip:

Commit-ID:     7f5933f81bd85a0bf6a87d65c7327ea048a75e54
Gitweb:        https://git.kernel.org/tip/7f5933f81bd85a0bf6a87d65c7327ea048a75e54
Author:        Dave Jiang <[email protected]>
AuthorDate:    Mon, 05 Oct 2020 08:11:23 -07:00
Committer:     Borislav Petkov <[email protected]>
CommitterDate: Wed, 07 Oct 2020 17:53:08 +02:00

x86/asm: Add an enqcmds() wrapper for the ENQCMDS instruction

Currently, the MOVDIR64B instruction is used to atomically submit 64-byte work descriptors to devices. Although it can encounter errors like device queue full, command not accepted, device not ready, etc when writing to a device MMIO, MOVDIR64B can not report back on errors from the device itself. This means that MOVDIR64B users need to separately interact with a device to see if a descriptor was successfully queued, which slows down device interactions.

ENQCMD and ENQCMDS also atomically submit 64-byte work descriptors to devices. But, they *can* report back errors directly from the device, such as if the device was busy, or device not enabled or does not support the command. This immediate feedback from the submission instruction itself reduces the number of interactions with the device and can greatly increase efficiency.

ENQCMD can be used at any privilege level, but can effectively only submit work on behalf of the current process. ENQCMDS is a ring0-only instruction and can explicitly specify a process context instead of being tied to the current process or needing to reprogram the IA32_PASID MSR.

Use ENQCMDS for work submission within the kernel because a Process Address ID (PASID) is setup to translate the kernel virtual address space. This PASID is provided to ENQCMDS from the descriptor structure submitted to the device and not retrieved from IA32_PASID MSR, which is setup for the current user address space.

See Intel Software Developer’s Manual for more information on the instructions.

[ bp:
- Make operand constraints like movdir64b() because both insns are basically doing the same thing, more or less.
- Fixup comments and cleanup. ]

---
 arch/x86/include/asm/special_insns.h | 42 +++++++++++++++++++++++++++-
 1 file changed, 42 insertions(+)
arch/x86/include/asm/special_insns.h +42 -0
index d4baa0e..5482c2d 100644
@@ -256,6 +256,48 @@ static inline void movdir64b(void *dst, const void *src)
 		     :  "m" (*__src), "a" (__dst), "d" (__src));
 }
 
+/**
+ * enqcmds - Enqueue a command in supervisor (CPL0) mode
+ * @dst: destination, in MMIO space (must be 512-bit aligned)
+ * @src: 512 bits memory operand
+ *
+ * The ENQCMDS instruction allows software to write a 512-bit command to
+ * a 512-bit-aligned special MMIO region that supports the instruction.
+ * A return status is loaded into the ZF flag in the RFLAGS register.
+ * ZF = 0 equates to success, and ZF = 1 indicates retry or error.
+ *
+ * This function issues the ENQCMDS instruction to submit data from
+ * kernel space to MMIO space, in a unit of 512 bits. Order of data access
+ * is not guaranteed, nor is a memory barrier performed afterwards. It
+ * returns 0 on success and -EAGAIN on failure.
+ *
+ * Warning: Do not use this helper unless your driver has checked that the
+ * ENQCMDS instruction is supported on the platform and the device accepts
+ * ENQCMDS.
+ */
+static inline int enqcmds(void __iomem *dst, const void *src)
+{
+	const struct { char _[64]; } *__src = src;
+	struct { char _[64]; } *__dst = dst;
+	int zf;
+
+	/*
+	 * ENQCMDS %(rdx), rax
+	 *
+	 * See movdir64b()'s comment on operand specification.
+	 */
+	asm volatile(".byte 0xf3, 0x0f, 0x38, 0xf8, 0x02, 0x66, 0x90"
+		     CC_SET(z)
+		     : CC_OUT(z) (zf), "+m" (*__dst)
+		     : "m" (*__src), "a" (__dst), "d" (__src));
+
+	/* Submission failure is indicated via EFLAGS.ZF=1 */
+	if (zf)
+		return -EAGAIN;
+
+	return 0;
+}
+
 #endif /* __KERNEL__ */
 
 #endif /* _ASM_X86_SPECIAL_INSNS_H */
author reviewer
#8 lore raw

PATCH v6 3/5 dmaengine: idxd: Add shared workqueue support

In reply to Dave Jiang

Add shared workqueue support that includes the support of Shared Virtual memory (SVM) or in similar terms On Demand Paging (ODP). The shared workqueue uses the enqcmds command in kernel and will respond with retry if the workqueue is full. Shared workqueue only works when there is PASID support from the IOMMU.

---
 drivers/dma/Kconfig          |  10 +++
 drivers/dma/idxd/cdev.c      |  49 +++++++++++++-
 drivers/dma/idxd/device.c    |  91 ++++++++++++++++++++++---
 drivers/dma/idxd/dma.c       |   9 ---
 drivers/dma/idxd/idxd.h      |  28 +++++++-
 drivers/dma/idxd/init.c      |  91 +++++++++++++++++++------
 drivers/dma/idxd/registers.h |  14 ++++
 drivers/dma/idxd/submit.c    |  35 ++++++++--
 drivers/dma/idxd/sysfs.c     | 127 +++++++++++++++++++++++++++++++++++
 9 files changed, 410 insertions(+), 44 deletions(-)
drivers/dma/Kconfig +10 -0
index 518a1437862a..6a908785a5f7 100644
@@ -296,6 +296,16 @@ config INTEL_IDXD
 
 	  If unsure, say N.
 
+# Config symbol that collects all the dependencies that's necessary to
+# support shared virtual memory for the devices supported by idxd.
+config INTEL_IDXD_SVM
+	bool "Accelerator Shared Virtual Memory Support"
+	depends on INTEL_IDXD
+	depends on INTEL_IOMMU_SVM
+	depends on PCI_PRI
+	depends on PCI_PASID
+	depends on PCI_IOV
+
 config INTEL_IOATDMA
 	tristate "Intel I/OAT DMA support"
 	depends on PCI && X86_64
drivers/dma/idxd/cdev.c +48 -1

86 lines not on this page · raw message

drivers/dma/idxd/device.c +83 -8

125 lines not on this page · raw message

drivers/dma/idxd/dma.c +0 -9
index 0c892cbd72e0..8ed2773d8285 100644
@@ -61,8 +61,6 @@ static inline void idxd_prep_desc_common(struct idxd_wq *wq,
 					 u64 addr_f1, u64 addr_f2, u64 len,
 					 u64 compl, u32 flags)
 {
-	struct idxd_device *idxd = wq->idxd;
-
 	hw->flags = flags;
 	hw->opcode = opcode;
 	hw->src_addr = addr_f1;
@@ -70,13 +68,6 @@ static inline void idxd_prep_desc_common(struct idxd_wq *wq,
 	hw->xfer_size = len;
 	hw->priv = !!(wq->type == IDXD_WQT_KERNEL);
 	hw->completion_addr = compl;
-
-	/*
-	 * Descriptor completion vectors are 1-8 for MSIX. We will round
-	 * robin through the 8 vectors.
-	 */
-	wq->vec_ptr = (wq->vec_ptr % idxd->num_wq_irqs) + 1;
-	hw->int_handle =  wq->vec_ptr;
 }
 
 static struct dma_async_tx_descriptor *
drivers/dma/idxd/idxd.h +27 -1
index c64df197e724..43a216c42d25 100644
@@ -59,6 +59,7 @@ enum idxd_wq_state {
 
 enum idxd_wq_flag {
 	WQ_FLAG_DEDICATED = 0,
+	WQ_FLAG_BLOCK_ON_FAULT,
 };
 
 enum idxd_wq_type {
@@ -86,10 +87,11 @@ enum idxd_op_type {
 enum idxd_complete_type {
 	IDXD_COMPLETE_NORMAL = 0,
 	IDXD_COMPLETE_ABORT,
+	IDXD_COMPLETE_DEV_FAIL,
 };
 
 struct idxd_wq {
-	void __iomem *dportal;
+	void __iomem *portal;
 	struct device conf_dev;
 	struct idxd_cdev idxd_cdev;
 	struct idxd_device *idxd;
@@ -145,6 +147,7 @@ enum idxd_device_state {
 enum idxd_device_flag {
 	IDXD_FLAG_CONFIGURABLE = 0,
 	IDXD_FLAG_CMD_RUNNING,
+	IDXD_FLAG_PASID_ENABLED,
 };
 
 struct idxd_device {
@@ -167,6 +170,9 @@ struct idxd_device {
 	struct idxd_wq *wqs;
 	struct idxd_engine *engines;
 
+	struct iommu_sva *sva;
+	unsigned int pasid;
+
 	int num_groups;
 
 	u32 msix_perm_offset;
@@ -214,11 +220,28 @@ struct idxd_desc {
 
 extern struct bus_type dsa_bus_type;
 
+extern bool support_enqcmd;
+
 static inline bool wq_dedicated(struct idxd_wq *wq)
 {
 	return test_bit(WQ_FLAG_DEDICATED, &wq->flags);
 }
 
+static inline bool wq_shared(struct idxd_wq *wq)
+{
+	return !test_bit(WQ_FLAG_DEDICATED, &wq->flags);
+}
+
+static inline bool device_pasid_enabled(struct idxd_device *idxd)
+{
+	return test_bit(IDXD_FLAG_PASID_ENABLED, &idxd->flags);
+}
+
+static inline bool device_swq_supported(struct idxd_device *idxd)
+{
+	return (support_enqcmd && device_pasid_enabled(idxd));
+}
+
 enum idxd_portal_prot {
 	IDXD_PORTAL_UNLIMITED = 0,
 	IDXD_PORTAL_LIMITED,
@@ -287,6 +310,7 @@ void idxd_device_reset(struct idxd_device *idxd);
 void idxd_device_cleanup(struct idxd_device *idxd);
 int idxd_device_config(struct idxd_device *idxd);
 void idxd_device_wqs_clear_state(struct idxd_device *idxd);
+void idxd_device_drain_pasid(struct idxd_device *idxd, int pasid);
 
 /* work queue control */
 int idxd_wq_alloc_resources(struct idxd_wq *wq);
@@ -297,6 +321,8 @@ void idxd_wq_drain(struct idxd_wq *wq);
 int idxd_wq_map_portal(struct idxd_wq *wq);
 void idxd_wq_unmap_portal(struct idxd_wq *wq);
 void idxd_wq_disable_cleanup(struct idxd_wq *wq);
+int idxd_wq_set_pasid(struct idxd_wq *wq, int pasid);
+int idxd_wq_disable_pasid(struct idxd_wq *wq);
 
 /* submission */
 int idxd_submit_desc(struct idxd_wq *wq, struct idxd_desc *desc);
drivers/dma/idxd/init.c +71 -20

182 lines not on this page · raw message

drivers/dma/idxd/registers.h +14 -0
index a39e7ae6b3d9..a0df4f3fe1fb 100644
@@ -333,4 +333,18 @@ union wqcfg {
 	};
 	u32 bits[8];
 } __packed;
+
+/*
+ * This macro calculates the offset into the WQCFG register
+ * idxd - struct idxd *
+ * n - wq id
+ * ofs - the index of the 32b dword for the config register
+ *
+ * The WQCFG register block is divided into groups per each wq. The n index
+ * allows us to move to the register group that's for that particular wq.
+ * Each register is 32bits. The ofs gives us the number of register to access.
+ */
+#define WQCFG_OFFSET(idxd_dev, n, ofs) ((idxd_dev)->wqcfg_offset +\
+					(n) * sizeof(union wqcfg) +\
+					sizeof(u32) * (ofs))
 #endif
drivers/dma/idxd/submit.c +30 -5
index 156a1ee233aa..efca5d8468a6 100644
@@ -11,11 +11,22 @@
 static struct idxd_desc *__get_desc(struct idxd_wq *wq, int idx, int cpu)
 {
 	struct idxd_desc *desc;
+	struct idxd_device *idxd = wq->idxd;
 
 	desc = wq->descs[idx];
 	memset(desc->hw, 0, sizeof(struct dsa_hw_desc));
 	memset(desc->completion, 0, sizeof(struct dsa_completion_record));
 	desc->cpu = cpu;
+
+	if (device_pasid_enabled(idxd))
+		desc->hw->pasid = idxd->pasid;
+
+	/*
+	 * Descriptor completion vectors are 1-8 for MSIX. We will round
+	 * robin through the 8 vectors.
+	 */
+	wq->vec_ptr = (wq->vec_ptr % idxd->num_wq_irqs) + 1;
+	desc->hw->int_handle = wq->vec_ptr;
 	return desc;
 }
 
@@ -70,18 +81,32 @@ int idxd_submit_desc(struct idxd_wq *wq, struct idxd_desc *desc)
 	struct idxd_device *idxd = wq->idxd;
 	int vec = desc->hw->int_handle;
 	void __iomem *portal;
+	int rc;
 
 	if (idxd->state != IDXD_DEV_ENABLED)
 		return -EIO;
 
-	portal = wq->dportal + idxd_get_wq_portal_offset(IDXD_PORTAL_UNLIMITED);
+	portal = wq->portal + idxd_get_wq_portal_offset(IDXD_PORTAL_LIMITED);
+
 	/*
-	 * The wmb() flushes writes to coherent DMA data before possibly
-	 * triggering a DMA read. The wmb() is necessary even on UP because
-	 * the recipient is a device.
+	 * The wmb() flushes writes to coherent DMA data before
+	 * possibly triggering a DMA read. The wmb() is necessary
+	 * even on UP because the recipient is a device.
 	 */
 	wmb();
-	iosubmit_cmds512(portal, desc->hw, 1);
+	if (wq_dedicated(wq)) {
+		iosubmit_cmds512(portal, desc->hw, 1);
+	} else {
+		/*
+		 * It's not likely that we would receive queue full rejection
+		 * since the descriptor allocation gates at wq size. If we
+		 * receive a -EAGAIN, that means something went wrong such as the
+		 * device is not accepting descriptor at all.
+		 */
+		rc = enqcmds(portal, desc->hw);
+		if (rc < 0)
+			return rc;
+	}
 
 	/*
 	 * Pending the descriptor to the lockless list for the irq_entry
drivers/dma/idxd/sysfs.c +127 -0

169 lines not on this page · raw message

Signature · 1 line
2.21.3
#9 lore raw

Re: [PATCH v6 3/5] dmaengine: idxd: Add shared workqueue support

I love your patch! Yet something to improve:

Hi Dave,

I love your patch! Yet something to improve:

[auto build test ERROR on vkoul-dmaengine/next]
[also build test ERROR on linus/master v5.9-rc6]
[cannot apply to tip/x86/core tip/master next-20200924]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Dave-Jiang/Add-shared-workqueue-support-for-idxd-driver/20200925-020242
base:   https://git.kernel.org/pub/scm/linux/kernel/git/vkoul/dmaengine.git next
config: x86_64-allyesconfig (attached as .config)
compiler: gcc-9 (Debian 9.3.0-15) 9.3.0
reproduce (this is a W=1 build):
        # save the attached .config to linux build tree
        make W=1 ARCH=x86_64 

If you fix the issue, kindly add following tag as appropriate

All errors (new ones prefixed by >>):

In file included from arch/x86/include/asm/tsc.h:9,

                    from arch/x86/include/asm/timex.h:6,
                    from include/linux/timex.h:65,
                    from include/linux/time32.h:13,
                    from include/linux/time.h:73,
                    from include/linux/stat.h:19,
                    from include/linux/module.h:13,
                    from drivers/dma/idxd/init.c:5:
   drivers/dma/idxd/init.c: In function 'idxd_init_module':
>> drivers/dma/idxd/init.c:525:20: error: 'X86_FEATURE_ENQCMD' undeclared (first use in this function); did you mean 'X86_FEATURE_PCID'?
     525 |  if (!boot_cpu_has(X86_FEATURE_ENQCMD))
         |                    ^~~~~~~~~~~~~~~~~~
   arch/x86/include/asm/cpufeature.h:118:24: note: in definition of macro 'cpu_has'
     118 |  (__builtin_constant_p(bit) && REQUIRED_MASK_BIT_SET(bit) ? 1 : \
         |                        ^~~
   drivers/dma/idxd/init.c:525:7: note: in expansion of macro 'boot_cpu_has'
     525 |  if (!boot_cpu_has(X86_FEATURE_ENQCMD))
         |       ^~~~~~~~~~~~
   drivers/dma/idxd/init.c:525:20: note: each undeclared identifier is reported only once for each function it appears in
     525 |  if (!boot_cpu_has(X86_FEATURE_ENQCMD))
         |                    ^~~~~~~~~~~~~~~~~~
   arch/x86/include/asm/cpufeature.h:118:24: note: in definition of macro 'cpu_has'
     118 |  (__builtin_constant_p(bit) && REQUIRED_MASK_BIT_SET(bit) ? 1 : \
         |                        ^~~
   drivers/dma/idxd/init.c:525:7: note: in expansion of macro 'boot_cpu_has'
     525 |  if (!boot_cpu_has(X86_FEATURE_ENQCMD))
         |       ^~~~~~~~~~~~

# https://github.com/0day-ci/linux/commit/8c78721a970a316ba914bdaaea606e152462fe94
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Dave-Jiang/Add-shared-workqueue-support-for-idxd-driver/20200925-020242 git checkout 8c78721a970a316ba914bdaaea606e152462fe94
vim +525 drivers/dma/idxd/init.c

511
512 static int __init idxd_init_module(void)
513 {
514 int err, i;
515
516 /*
517 * If the CPU does not support MOVDIR64B or ENQCMDS, there's no point in
518 * enumerating the device. We can not utilize it.
519 */
520 if (!boot_cpu_has(X86_FEATURE_MOVDIR64B)) {
521 pr_warn("idxd driver failed to load without MOVDIR64B.\n");
522 return -ENODEV;
523 }
524

 > 525		if (!boot_cpu_has(X86_FEATURE_ENQCMD))

526 pr_warn("Platform does not have ENQCMD(S) support.\n");
527 else
528 support_enqcmd = true;
529
530 mutex_init(&idxd_idr_lock);
531 for (i = 0; i < IDXD_TYPE_MAX; i++)
532 idr_init(&idxd_idrs[i]);
533
534 err = idxd_register_bus_type();
535 if (err < 0)
536 return err;
537
538 err = idxd_register_driver();
539 if (err < 0)
540 goto err_idxd_driver_register;
541
542 err = idxd_cdev_register();
543 if (err)
544 goto err_cdev_register;
545
546 err = pci_register_driver(&idxd_pci_driver);
547 if (err)
548 goto err_pci_register;
549
550 return 0;
551
552 err_pci_register:
553 idxd_cdev_remove();
554 err_cdev_register:
555 idxd_unregister_driver();
556 err_idxd_driver_register:
557 idxd_unregister_bus_type();
558 return err;
559 }
560 module_init(idxd_init_module);
561

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/[email protected]

author reviewer
#10 lore raw

Re: [PATCH v6 3/5] dmaengine: idxd: Add shared workqueue support

Quoted 8 lines · kernel test robot

Hi Dave,

I love your patch! Yet something to improve:

[auto build test ERROR on vkoul-dmaengine/next]
[also build test ERROR on linus/master v5.9-rc6]
[cannot apply to tip/x86/core tip/master next-20200924]
[If your patch is applied to the wrong git tree, kindly drop us a note.

Hi 0-day team. This is a tricky one. The code is based on vkou-dmaengine/next, however, it's missing the patch series from the tip tree branch x86/pasid:
https://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git/log/?h=x86/pasid

This is where the compile error comes from. We are missing the ENQCMD enumeration support from the tip tree. Essentially if you merge in the tip branch it should address this issue. If there's a better solution for the future please let me know.

Quoted 106 lines

And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Dave-Jiang/Add-shared-workqueue-support-for-idxd-driver/20200925-020242
base:   https://git.kernel.org/pub/scm/linux/kernel/git/vkoul/dmaengine.git next
config: x86_64-allyesconfig (attached as .config)
compiler: gcc-9 (Debian 9.3.0-15) 9.3.0
reproduce (this is a W=1 build):
         # save the attached .config to linux build tree
         make W=1 ARCH=x86_64

If you fix the issue, kindly add following tag as appropriate

All errors (new ones prefixed by >>):

In file included from arch/x86/include/asm/tsc.h:9,
from arch/x86/include/asm/timex.h:6, from include/linux/timex.h:65, from include/linux/time32.h:13, from include/linux/time.h:73, from include/linux/stat.h:19, from include/linux/module.h:13, from drivers/dma/idxd/init.c:5:
drivers/dma/idxd/init.c: In function 'idxd_init_module':

Quoted 1 line
Quoted 1 line

drivers/dma/idxd/init.c:525:20: error: 'X86_FEATURE_ENQCMD' undeclared (first use in this function); did you mean 'X86_FEATURE_PCID'?

      525 |  if (!boot_cpu_has(X86_FEATURE_ENQCMD))
          |                    ^~~~~~~~~~~~~~~~~~
    arch/x86/include/asm/cpufeature.h:118:24: note: in definition of macro 'cpu_has'
      118 |  (__builtin_constant_p(bit) && REQUIRED_MASK_BIT_SET(bit) ? 1 : \
          |                        ^~~
    drivers/dma/idxd/init.c:525:7: note: in expansion of macro 'boot_cpu_has'
      525 |  if (!boot_cpu_has(X86_FEATURE_ENQCMD))
          |       ^~~~~~~~~~~~
    drivers/dma/idxd/init.c:525:20: note: each undeclared identifier is reported only once for each function it appears in
      525 |  if (!boot_cpu_has(X86_FEATURE_ENQCMD))
          |                    ^~~~~~~~~~~~~~~~~~
    arch/x86/include/asm/cpufeature.h:118:24: note: in definition of macro 'cpu_has'
      118 |  (__builtin_constant_p(bit) && REQUIRED_MASK_BIT_SET(bit) ? 1 : \
          |                        ^~~
    drivers/dma/idxd/init.c:525:7: note: in expansion of macro 'boot_cpu_has'
      525 |  if (!boot_cpu_has(X86_FEATURE_ENQCMD))
          |       ^~~~~~~~~~~~

# https://github.com/0day-ci/linux/commit/8c78721a970a316ba914bdaaea606e152462fe94
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Dave-Jiang/Add-shared-workqueue-support-for-idxd-driver/20200925-020242 git checkout 8c78721a970a316ba914bdaaea606e152462fe94
vim +525 drivers/dma/idxd/init.c

    511	
    512	static int __init idxd_init_module(void)
    513	{
    514		int err, i;
    515	
    516		/*
    517		 * If the CPU does not support MOVDIR64B or ENQCMDS, there's no point in
    518		 * enumerating the device. We can not utilize it.
    519		 */
    520		if (!boot_cpu_has(X86_FEATURE_MOVDIR64B)) {
    521			pr_warn("idxd driver failed to load without MOVDIR64B.\n");
    522			return -ENODEV;
    523		}
    524	
Quoted 1 line

525 if (!boot_cpu_has(X86_FEATURE_ENQCMD))

    526			pr_warn("Platform does not have ENQCMD(S) support.\n");
    527		else
    528			support_enqcmd = true;
    529	
    530		mutex_init(&idxd_idr_lock);
    531		for (i = 0; i < IDXD_TYPE_MAX; i++)
    532			idr_init(&idxd_idrs[i]);
    533	
    534		err = idxd_register_bus_type();
    535		if (err < 0)
    536			return err;
    537	
    538		err = idxd_register_driver();
    539		if (err < 0)
    540			goto err_idxd_driver_register;
    541	
    542		err = idxd_cdev_register();
    543		if (err)
    544			goto err_cdev_register;
    545	
    546		err = pci_register_driver(&idxd_pci_driver);
    547		if (err)
    548			goto err_pci_register;
    549	
    550		return 0;
    551	
    552	err_pci_register:
    553		idxd_cdev_remove();
    554	err_cdev_register:
    555		idxd_unregister_driver();
    556	err_idxd_driver_register:
    557		idxd_unregister_bus_type();
    558		return err;
    559	}
    560	module_init(idxd_init_module);
    561	

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

maintainer
#11 lore raw

Re: [PATCH v6 3/5] dmaengine: idxd: Add shared workqueue support

Quoted 9 lines · Dave Jiang

Hi 0-day team. This is a tricky one. The code is based on vkou-dmaengine/next, however, it's missing the patch series from the tip tree branch x86/pasid:
https://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git/log/?h=x86/pasid

This is where the compile error comes from. We are missing the ENQCMD enumeration support from the tip tree. Essentially if you merge in the tip branch it should address this issue. If there's a better solution for the future please let me know.

Yes, so what would be the usual process which we do with other maintainers too, is if I apply your first two and then Vinod merges tip:x86/pasid and adds your other patches ontop.

Then when the merge window comes, I'll send the pasid branch first and then, when he sends his pull request, the pasid patches will be upstream already.

If he's fine with that approach, I'll make sure we don't rebase tip:x86/pasid anymore.

Lemme know.

Thx.

Signature · 4 lines
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette
maintainer
#12 lore raw

Re: [PATCH v6 3/5] dmaengine: idxd: Add shared workqueue support

In reply to Dave Jiang
Quoted 27 lines · Dave Jiang
drivers/dma/idxd/sysfs.c +12 -0
@@ -1154,6 +1268,8 @@ static struct attribute *idxd_wq_attributes[] = {
 	&dev_attr_wq_mode.attr,
 	&dev_attr_wq_size.attr,
 	&dev_attr_wq_priority.attr,
+	&dev_attr_wq_block_on_fault.attr,
+	&dev_attr_wq_threshold.attr,
 	&dev_attr_wq_type.attr,
 	&dev_attr_wq_name.attr,
 	&dev_attr_wq_cdev_minor.attr,
@@ -1305,6 +1421,16 @@ static ssize_t clients_show(struct device *dev,
 }
 static DEVICE_ATTR_RO(clients);
 
+static ssize_t pasid_enabled_show(struct device *dev,
+				  struct device_attribute *attr, char *buf)
+{
+	struct idxd_device *idxd =
+		container_of(dev, struct idxd_device, conf_dev);
+
+	return sprintf(buf, "%u\n", device_pasid_enabled(idxd));
+}
+static DEVICE_ATTR_RO(pasid_enabled);
+
 static ssize_t state_show(struct device *dev,
 			  struct device_attribute *attr, char *buf)
 {

drivers/dma/idxd/sysfs.c static struct attribute *idxd_device_attributes[] = { · line 1553

Quoted 4 lines
drivers/dma/idxd/sysfs.c +1 -0
@@ -1424,6 +1550,7 @@ static struct attribute *idxd_device_attributes[] = {
 	&dev_attr_gen_cap.attr,
 	&dev_attr_configurable.attr,
 	&dev_attr_clients.attr,
+	&dev_attr_pasid_enabled.attr,

No Documentation again for these new files! Please add them as well

Signature · 1 line
~Vinod
author reviewer
#13 lore raw

PATCH v6 4/5 dmaengine: idxd: Clean up descriptors with fault error

In reply to Dave Jiang

Add code to "complete" a descriptor when the descriptor or its completion address hit a fault error when SVA mode is being used. This error can be triggered due to bad programming by the user. A lock is introduced in order to protect the descriptor completion lists since the fault handler will run from the system work queue after being scheduled in the interrupt handler.

---
 drivers/dma/idxd/idxd.h |   5 ++
 drivers/dma/idxd/init.c |   1 +
 drivers/dma/idxd/irq.c  | 143 ++++++++++++++++++++++++++++++++++++----
 3 files changed, 137 insertions(+), 12 deletions(-)
drivers/dma/idxd/idxd.h +5 -0
index 43a216c42d25..b64b6266ca97 100644
@@ -34,6 +34,11 @@ struct idxd_irq_entry {
 	int id;
 	struct llist_head pending_llist;
 	struct list_head work_list;
+	/*
+	 * Lock to protect access between irq thread process descriptor
+	 * and irq thread processing error descriptor.
+	 */
+	spinlock_t list_lock;
 };
 
 struct idxd_group {
drivers/dma/idxd/init.c +1 -0
index 626401a71fdd..1bb7637b02eb 100644
@@ -97,6 +97,7 @@ static int idxd_setup_interrupts(struct idxd_device *idxd)
 	for (i = 0; i < msixcnt; i++) {
 		idxd->irq_entries[i].id = i;
 		idxd->irq_entries[i].idxd = idxd;
+		spin_lock_init(&idxd->irq_entries[i].list_lock);
 	}
 
 	msix = &idxd->msix_entries[0];
drivers/dma/idxd/irq.c +131 -12

218 lines not on this page · raw message

Signature · 1 line
2.21.3
maintainer
#14 lore raw

Re: [PATCH v6 4/5] dmaengine: idxd: Clean up descriptors with fault error

Quoted 122 lines · Dave Jiang

Add code to "complete" a descriptor when the descriptor or its completion address hit a fault error when SVA mode is being used. This error can be triggered due to bad programming by the user. A lock is introduced in order to protect the descriptor completion lists since the fault handler will run from the system work queue after being scheduled in the interrupt handler.

---
 drivers/dma/idxd/idxd.h |   5 ++
 drivers/dma/idxd/init.c |   1 +
 drivers/dma/idxd/irq.c  | 143 ++++++++++++++++++++++++++++++++++++----
 3 files changed, 137 insertions(+), 12 deletions(-)
drivers/dma/idxd/idxd.h +5 -0
index 43a216c42d25..b64b6266ca97 100644
@@ -34,6 +34,11 @@ struct idxd_irq_entry {
 	int id;
 	struct llist_head pending_llist;
 	struct list_head work_list;
+	/*
+	 * Lock to protect access between irq thread process descriptor
+	 * and irq thread processing error descriptor.
+	 */
+	spinlock_t list_lock;
 };
 
 struct idxd_group {
drivers/dma/idxd/init.c +1 -0
index 626401a71fdd..1bb7637b02eb 100644
@@ -97,6 +97,7 @@ static int idxd_setup_interrupts(struct idxd_device *idxd)
 	for (i = 0; i < msixcnt; i++) {
 		idxd->irq_entries[i].id = i;
 		idxd->irq_entries[i].idxd = idxd;
+		spin_lock_init(&idxd->irq_entries[i].list_lock);
 	}
 
 	msix = &idxd->msix_entries[0];
drivers/dma/idxd/irq.c +58 -0
index 17a65a13fb64..9e6cc55ad22f 100644
@@ -11,6 +11,24 @@
 #include "idxd.h"
 #include "registers.h"
 
+enum irq_work_type {
+	IRQ_WORK_NORMAL = 0,
+	IRQ_WORK_PROCESS_FAULT,
+};
+
+struct idxd_fault {
+	struct work_struct work;
+	u64 addr;
+	struct idxd_device *idxd;
+};
+
+static int irq_process_work_list(struct idxd_irq_entry *irq_entry,
+				 enum irq_work_type wtype,
+				 int *processed, u64 data);
+static int irq_process_pending_llist(struct idxd_irq_entry *irq_entry,
+				     enum irq_work_type wtype,
+				     int *processed, u64 data);
+
 static void idxd_device_reinit(struct work_struct *work)
 {
 	struct idxd_device *idxd = container_of(work, struct idxd_device, work);
@@ -44,6 +62,46 @@ static void idxd_device_reinit(struct work_struct *work)
 	idxd_device_wqs_clear_state(idxd);
 }
 
+static void idxd_device_fault_work(struct work_struct *work)
+{
+	struct idxd_fault *fault = container_of(work, struct idxd_fault, work);
+	struct idxd_irq_entry *ie;
+	int i;
+	int processed;
+	int irqcnt = fault->idxd->num_wq_irqs + 1;
+
+	for (i = 1; i < irqcnt; i++) {
+		ie = &fault->idxd->irq_entries[i];
+		irq_process_work_list(ie, IRQ_WORK_PROCESS_FAULT,
+				      &processed, fault->addr);
+		if (processed)
+			break;
+
+		irq_process_pending_llist(ie, IRQ_WORK_PROCESS_FAULT,
+					  &processed, fault->addr);
+		if (processed)
+			break;
+	}
+
+	kfree(fault);
+}
+
+static int idxd_device_schedule_fault_process(struct idxd_device *idxd,
+					      u64 fault_addr)
+{
+	struct idxd_fault *fault;
+
+	fault = kmalloc(sizeof(*fault), GFP_ATOMIC);
+	if (!fault)
+		return -ENOMEM;
+
+	fault->addr = fault_addr;
+	fault->idxd = idxd;
+	INIT_WORK(&fault->work, idxd_device_fault_work);
+	queue_work(idxd->wq, &fault->work);
+	return 0;
+}
+
 irqreturn_t idxd_irq_handler(int vec, void *data)
 {
 	struct idxd_irq_entry *irq_entry = data;
@@ -125,6 +183,16 @@ irqreturn_t idxd_misc_thread(int vec, void *data)
 	if (!err)
 		goto out;

drivers/dma/idxd/irq.c irqreturn_t idxd_misc_thread(int vec, void *data) · line 194

Quoted 10 lines
drivers/dma/idxd/irq.c +9 -0
 
+	/*
+	 * This case should rarely happen and typically is due to software
+	 * programming error by the driver.
+	 */
+	if (idxd->sw_err.valid &&
+	    idxd->sw_err.desc_valid &&
+	    idxd->sw_err.fault_addr)
+		idxd_device_schedule_fault_process(idxd,
+						   idxd->sw_err.fault_addr);

This should fit in a single line ;)

drivers/dma/idxd/irq.c irqreturn_t idxd_misc_thread(int vec, void *data) · line 226

Quoted 12 lines
drivers/dma/idxd/irq.c +5 -0
+
 	gensts.bits = ioread32(idxd->reg_base + IDXD_GENSTATS_OFFSET);
 	if (gensts.state == IDXD_DEVICE_STATE_HALT) {
 		idxd->state = IDXD_DEV_HALTED;
@@ -152,57 +220,106 @@ irqreturn_t idxd_misc_thread(int vec, void *data)
 	return IRQ_HANDLED;
 }
 
+static bool process_fault(struct idxd_desc *desc, u64 fault_addr)
+{
+	if ((u64)desc->hw == fault_addr ||
+	    (u64)desc->completion == fault_addr) {

you are casting descriptor address and completion, I can understand former, but later..? Can you explain this please

Signature · 1 line
~Vinod
author reviewer
#15 lore raw

Re: [PATCH v6 4/5] dmaengine: idxd: Clean up descriptors with fault error

Quoted 124 lines · Vinod Koul
Quoted 123 lines · Dave Jiang

Add code to "complete" a descriptor when the descriptor or its completion address hit a fault error when SVA mode is being used. This error can be triggered due to bad programming by the user. A lock is introduced in order to protect the descriptor completion lists since the fault handler will run from the system work queue after being scheduled in the interrupt handler.

---
  drivers/dma/idxd/idxd.h |   5 ++
  drivers/dma/idxd/init.c |   1 +
  drivers/dma/idxd/irq.c  | 143 ++++++++++++++++++++++++++++++++++++----
  3 files changed, 137 insertions(+), 12 deletions(-)
drivers/dma/idxd/idxd.h +5 -0
index 43a216c42d25..b64b6266ca97 100644
@@ -34,6 +34,11 @@ struct idxd_irq_entry {
  	int id;
  	struct llist_head pending_llist;
  	struct list_head work_list;
+	/*
+	 * Lock to protect access between irq thread process descriptor
+	 * and irq thread processing error descriptor.
+	 */
+	spinlock_t list_lock;
  };
 
  struct idxd_group {
drivers/dma/idxd/init.c +1 -0
index 626401a71fdd..1bb7637b02eb 100644
@@ -97,6 +97,7 @@ static int idxd_setup_interrupts(struct idxd_device *idxd)
  	for (i = 0; i < msixcnt; i++) {
  		idxd->irq_entries[i].id = i;
  		idxd->irq_entries[i].idxd = idxd;
+		spin_lock_init(&idxd->irq_entries[i].list_lock);
  	}
 
  	msix = &idxd->msix_entries[0];
drivers/dma/idxd/irq.c +58 -0
index 17a65a13fb64..9e6cc55ad22f 100644
@@ -11,6 +11,24 @@
  #include "idxd.h"
  #include "registers.h"
 
+enum irq_work_type {
+	IRQ_WORK_NORMAL = 0,
+	IRQ_WORK_PROCESS_FAULT,
+};
+
+struct idxd_fault {
+	struct work_struct work;
+	u64 addr;
+	struct idxd_device *idxd;
+};
+
+static int irq_process_work_list(struct idxd_irq_entry *irq_entry,
+				 enum irq_work_type wtype,
+				 int *processed, u64 data);
+static int irq_process_pending_llist(struct idxd_irq_entry *irq_entry,
+				     enum irq_work_type wtype,
+				     int *processed, u64 data);
+
  static void idxd_device_reinit(struct work_struct *work)
  {
  	struct idxd_device *idxd = container_of(work, struct idxd_device, work);
@@ -44,6 +62,46 @@ static void idxd_device_reinit(struct work_struct *work)
  	idxd_device_wqs_clear_state(idxd);
  }
 
+static void idxd_device_fault_work(struct work_struct *work)
+{
+	struct idxd_fault *fault = container_of(work, struct idxd_fault, work);
+	struct idxd_irq_entry *ie;
+	int i;
+	int processed;
+	int irqcnt = fault->idxd->num_wq_irqs + 1;
+
+	for (i = 1; i < irqcnt; i++) {
+		ie = &fault->idxd->irq_entries[i];
+		irq_process_work_list(ie, IRQ_WORK_PROCESS_FAULT,
+				      &processed, fault->addr);
+		if (processed)
+			break;
+
+		irq_process_pending_llist(ie, IRQ_WORK_PROCESS_FAULT,
+					  &processed, fault->addr);
+		if (processed)
+			break;
+	}
+
+	kfree(fault);
+}
+
+static int idxd_device_schedule_fault_process(struct idxd_device *idxd,
+					      u64 fault_addr)
+{
+	struct idxd_fault *fault;
+
+	fault = kmalloc(sizeof(*fault), GFP_ATOMIC);
+	if (!fault)
+		return -ENOMEM;
+
+	fault->addr = fault_addr;
+	fault->idxd = idxd;
+	INIT_WORK(&fault->work, idxd_device_fault_work);
+	queue_work(idxd->wq, &fault->work);
+	return 0;
+}
+
  irqreturn_t idxd_irq_handler(int vec, void *data)
  {
  	struct idxd_irq_entry *irq_entry = data;
@@ -125,6 +183,16 @@ irqreturn_t idxd_misc_thread(int vec, void *data)
  	if (!err)
  		goto out;
 
Quoted 11 lines

drivers/dma/idxd/irq.c irqreturn_t idxd_misc_thread(int vec, void *data) · line 194

Quoted 9 lines
drivers/dma/idxd/irq.c +9 -0
+	/*
+	 * This case should rarely happen and typically is due to software
+	 * programming error by the driver.
+	 */
+	if (idxd->sw_err.valid &&
+	    idxd->sw_err.desc_valid &&
+	    idxd->sw_err.fault_addr)
+		idxd_device_schedule_fault_process(idxd,
+						   idxd->sw_err.fault_addr);

This should fit in a single line ;)

Yes. With the new 100 col guideline this should be single line.

Quoted 9 lines
Quoted 9 lines
drivers/dma/idxd/irq.c +1 -0
+
  	gensts.bits = ioread32(idxd->reg_base + IDXD_GENSTATS_OFFSET);
  	if (gensts.state == IDXD_DEVICE_STATE_HALT) {
  		idxd->state = IDXD_DEV_HALTED;
@@ -152,57 +220,106 @@ irqreturn_t idxd_misc_thread(int vec, void *data)
  	return IRQ_HANDLED;
  }
 
Quoted 8 lines

drivers/dma/idxd/irq.c irqreturn_t idxd_misc_thread(int vec, void *data) · line 226

Quoted 4 lines
drivers/dma/idxd/irq.c +4 -0
+static bool process_fault(struct idxd_desc *desc, u64 fault_addr)
+{
+	if ((u64)desc->hw == fault_addr ||
+	    (u64)desc->completion == fault_addr) {

you are casting descriptor address and completion, I can understand former, but later..? Can you explain this please

It is possible to fail on the completion writeback address if the completion address programmed into the descriptor is bad.

maintainer
#16 lore raw

Re: [PATCH v6 4/5] dmaengine: idxd: Clean up descriptors with fault error

Quoted 11 lines · Dave Jiang
Quoted 8 lines

drivers/dma/idxd/irq.c irqreturn_t idxd_misc_thread(int vec, void *data) · line 226

Quoted 4 lines
drivers/dma/idxd/irq.c +4 -0
+static bool process_fault(struct idxd_desc *desc, u64 fault_addr)
+{
+	if ((u64)desc->hw == fault_addr ||
+	    (u64)desc->completion == fault_addr) {

you are casting descriptor address and completion, I can understand former, but later..? Can you explain this please

It is possible to fail on the completion writeback address if the completion address programmed into the descriptor is bad.

Okay thanks for clarifying, maybe would help to add a comment.

Signature · 1 line
~Vinod
author reviewer
#17 lore raw

PATCH v6 5/5 dmaengine: idxd: Add ABI documentation for shared wq

In reply to Dave Jiang

Add the sysfs attribute bits in ABI/stable for shared wq support.

---
 Documentation/ABI/stable/sysfs-driver-dma-idxd | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
Documentation/ABI/stable/sysfs-driver-dma-idxd +14 -0
index b44183880935..42d3dc03ffea 100644
@@ -77,6 +77,13 @@ Contact:        [email protected]
 Description:    The operation capability bit mask specify the operation types
 		supported by the this device.
 
+What:		/sys/bus/dsa/devices/dsa<m>/pasid_enabled
+Date:		Sep 17, 2020
+KernelVersion:	5.10.0
+Contact:	[email protected]
+Description:	To indicate if PASID (process address space identifier) is
+		enabled or not for this device.
+
 What:           /sys/bus/dsa/devices/dsa<m>/state
 Date:           Oct 25, 2019
 KernelVersion:  5.6.0
@@ -122,6 +129,13 @@ KernelVersion:	5.10.0
 Contact:	[email protected]
 Description:	The last executed device administrative command's status/error.
 
+What:		/sys/bus/dsa/devices/wq<m>.<n>/block_on_fault
+Date:		Sept 17, 2020
+KernelVersion:	5.10.0
+Contact:	[email protected]
+Description:	To indicate block on fault is allowed or not for the work queue
+		to support on demand paging.
+
 What:           /sys/bus/dsa/devices/wq<m>.<n>/group_id
 Date:           Oct 25, 2019
 KernelVersion:  5.6.0
Signature · 1 line
2.21.3
maintainer
#18 lore raw

Re: [PATCH v6 5/5] dmaengine: idxd: Add ABI documentation for shared wq

Quoted 1 line · Dave Jiang

Add the sysfs attribute bits in ABI/stable for shared wq support.

OK I take back the documentation comment now....

Quoted 43 lines
---
 Documentation/ABI/stable/sysfs-driver-dma-idxd | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
Documentation/ABI/stable/sysfs-driver-dma-idxd +14 -0
index b44183880935..42d3dc03ffea 100644
@@ -77,6 +77,13 @@ Contact:        [email protected]
 Description:    The operation capability bit mask specify the operation types
 		supported by the this device.
 
+What:		/sys/bus/dsa/devices/dsa<m>/pasid_enabled
+Date:		Sep 17, 2020
+KernelVersion:	5.10.0
+Contact:	[email protected]
+Description:	To indicate if PASID (process address space identifier) is
+		enabled or not for this device.
+
 What:           /sys/bus/dsa/devices/dsa<m>/state
 Date:           Oct 25, 2019
 KernelVersion:  5.6.0
@@ -122,6 +129,13 @@ KernelVersion:	5.10.0
 Contact:	[email protected]
 Description:	The last executed device administrative command's status/error.
 
+What:		/sys/bus/dsa/devices/wq<m>.<n>/block_on_fault
+Date:		Sept 17, 2020
+KernelVersion:	5.10.0
+Contact:	[email protected]
+Description:	To indicate block on fault is allowed or not for the work queue
+		to support on demand paging.
+
 What:           /sys/bus/dsa/devices/wq<m>.<n>/group_id
 Date:           Oct 25, 2019
 KernelVersion:  5.6.0
Signature · 1 line
2.21.3
Signature · 1 line
~Vinod
author reviewer
#19 lore raw
In reply to Dave Jiang
Quoted 3 lines · Dave Jiang

v6:
Boris:
- Fixup MOBDIR64B inline asm input/output constraints

Hi Vinod,
Looks like we are cleared on the x86 patches for this series with sign offs from maintainer Boris. Please consider the series for 5.10 inclusion. Thank you!

Quoted 110 lines

v5:
Boris:
- Fixup commit headers
- Fixup var names for movdir64b()
- Move enqcmds() to special_insns.h
- Fix up comments for enqcmds()
- Change enqcmds() to reflect instruction return. 0 as success, -EAGAIN for fail.

DavidL:
- Fixup enqcmds() gas constraints

v4:
- Rebased against latest dmaengine/next tree
- Split out enqcmd and pasid dependency.

V3:
- Rebased against latest dmaengine/next tree.
- Updated API doc with new kernel version and dates.
- Changed to allow driver to load without ENQCMD support.
- Break out some patches that can be sent ahead of this series for inclusion.

v2:
- Dropped device feature enabling (GregKH)
- Dropped PCI device feature enabling (Bjorn)
- https://members.pcisig.com/wg/PCI-SIG/document/14237
- After some internal discussion, we have decided to hold off on the enabling of DMWR due to the following reasons. 1. Most first gen hw will not have the feature bits. 2. First gen hw that support the feature are all Root Complex integrated endpoints. 3. PCI devices that are not RCiEP’s with this capability won’t surface for a few years so we can wait until we can test the full code.
- Dropped special ioremap (hch)
- Added proper support for WQ flush (tony, dan)
- Changed descriptor submission to use sbitmap_queue for blocking. (dan)

Driver stage 1 postings for context: [1]

The patch series has compilation and functional dependency on Fenghua's "Tag application address space for devices" patch series for the ENQCMD CPU command enumeration and the PASID MSR support. [2]

== Background ==
A typical DMA device requires the driver to translate application buffers to hardware addresses, and a kernel-user transition to notify the hardware of new work. Shared Virtual Addressing (SVA) allows the processor and device to use the same virtual addresses without requiring software to translate between the address spaces. ENQCMD is a new instruction on Intel Platforms that allows user applications to directly notify hardware of new work, much like how doorbells are used in some hardware, but it carries a payload along with it. ENQCMDS is the supervisor version (ring0) of ENQCMD.

== ENQCMDS ==
Introduce enqcmds(), a helper funciton that copies an input payload to a 64B aligned destination and confirms whether the payload was accepted by the device or not. enqcmds() wraps the new ENQCMDS CPU instruction. The ENQCMDS is a ring 0 CPU instruction that performs similar to the ENQCMD instruction. Descriptor submission must use ENQCMD(S) for shared workqueues (swq) on an Intel DSA device.

== Shared WQ support ==
Introduce shared workqueue (swq) support for the idxd driver. The current idxd driver contains dedicated workqueue (dwq) support only. A dwq accepts descriptors from a MOVDIR64B instruction. MOVDIR64B is a posted instruction on the PCIe bus, it does not wait for any response from the device. If the wq is full, submitted descriptors are dropped. A swq utilizes the ENQCMDS in ring 0, which is a non-posted instruction. The zero flag would be set to 1 if the device rejects the descriptor or if the wq is full. A swq can be shared between multiple users (kernel or userspace) due to not having to keep track of the wq full condition for submission. A swq requires PASID and can only run with SVA support.

== IDXD SVA support ==
Add utilization of PASID to support Shared Virtual Addressing (SVA). With PASID support, the descriptors can be programmed with host virtual address (HVA) rather than IOVA. The hardware will work with the IOMMU in fulfilling page requests. With SVA support, a user app using the char device interface can now submit descriptors without having to pin the virtual memory range it wants to DMA in its own address space.

The series does not add SVA support for the dmaengine subsystem. That support is coming at a later time.

[1]: https://lore.kernel.org/lkml/157965011794.73301.15960052071729101309.stgit@djiang5-desk3.ch.intel.com/
[2]: https://lore.kernel.org/lkml/[email protected]/
[3]: https://software.intel.com/en-us/articles/intel-sdm
[4]: https://software.intel.com/en-us/download/intel-scalable-io-virtualization-technical-specification
[5]: https://software.intel.com/en-us/download/intel-data-streaming-accelerator-preliminary-architecture-specification
[6]: https://01.org/blogs/2019/introducing-intel-data-streaming-accelerator
[7]: https://intel.github.io/idxd/
[8]: https://github.com/intel/idxd-driver idxd-stage2

---

Dave Jiang (5):
x86/asm: Carve out a generic movdir64b() helper for general usage x86/asm: Add enqcmds() to support ENQCMDS instruction
dmaengine: idxd: Add shared workqueue support
dmaengine: idxd: Clean up descriptors with fault error
dmaengine: idxd: Add ABI documentation for shared wq

  .../ABI/stable/sysfs-driver-dma-idxd          |  14 ++
  arch/x86/include/asm/io.h                     |  17 +--
  arch/x86/include/asm/special_insns.h          |  56 +++++++
  drivers/dma/Kconfig                           |  10 ++
  drivers/dma/idxd/cdev.c                       |  49 +++++-
  drivers/dma/idxd/device.c                     |  91 ++++++++++-
  drivers/dma/idxd/dma.c                        |   9 --
  drivers/dma/idxd/idxd.h                       |  33 +++-
  drivers/dma/idxd/init.c                       |  92 ++++++++---
  drivers/dma/idxd/irq.c                        | 143 ++++++++++++++++--
  drivers/dma/idxd/registers.h                  |  14 ++
  drivers/dma/idxd/submit.c                     |  35 ++++-
  drivers/dma/idxd/sysfs.c                      | 127 ++++++++++++++++
  13 files changed, 620 insertions(+), 70 deletions(-)
maintainer
#20 lore raw
Quoted 4 lines · Dave Jiang

Hi Vinod,
Looks like we are cleared on the x86 patches for this series with sign offs from maintainer Boris. Please consider the series for 5.10 inclusion. Thank you!

As I said here, I'd strongly suggest we do this:

https://lists.01.org/hyperkitty/list/[email protected]/thread/5FKNWNCCRV3AXUAEXUGQFF4EDQNANF3F/

and Vinod should merge the x86/pasid branch. Otherwise is his branch and incomplete you could not have tested it properly.

Signature · 4 lines
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette
author reviewer
#21 lore raw
Quoted 6 lines · Borislav Petkov
Quoted 4 lines · Dave Jiang

Hi Vinod,
Looks like we are cleared on the x86 patches for this series with sign offs from maintainer Boris. Please consider the series for 5.10 inclusion. Thank you!

Quoted 7 lines

As I said here, I'd strongly suggest we do this:

https://lists.01.org/hyperkitty/list/[email protected]/thread/5FKNWNCCRV3AXUAEXUGQFF4EDQNANF3F/

and Vinod should merge the x86/pasid branch. Otherwise is his branch and incomplete you could not have tested it properly.

Thanks Boris. Locally I have based on the latest dmaengine/next branch, merged in the x86/pasid branch, and then applied the series on top for testing. But yes, if Vinod accepts the series into his dmaengine/next tree, we will need all the parts for testing.

author reviewer
#22 lore raw
In reply to Borislav Petkov
Quoted 6 lines · Borislav Petkov
Quoted 4 lines · Dave Jiang

Hi Vinod,
Looks like we are cleared on the x86 patches for this series with sign offs from maintainer Boris. Please consider the series for 5.10 inclusion. Thank you!

Quoted 7 lines

As I said here, I'd strongly suggest we do this:

https://lists.01.org/hyperkitty/list/[email protected]/thread/5FKNWNCCRV3AXUAEXUGQFF4EDQNANF3F/

and Vinod should merge the x86/pasid branch. Otherwise is his branch and incomplete you could not have tested it properly.

Hi Vinod,
Just checking to see if you have any objections or concerns with respect to this series. We are hoping it can be queued for the 5.10 merge if there are no objections. Thanks!

maintainer
#23 lore raw

Hi Dave,

Quoted 13 lines · Dave Jiang
Quoted 10 lines · Borislav Petkov
Quoted 4 lines · Dave Jiang

Hi Vinod,
Looks like we are cleared on the x86 patches for this series with sign offs from maintainer Boris. Please consider the series for 5.10 inclusion. Thank you!

As I said here, I'd strongly suggest we do this:

https://lists.01.org/hyperkitty/list/[email protected]/thread/5FKNWNCCRV3AXUAEXUGQFF4EDQNANF3F/

Quoted 8 lines
Quoted 3 lines

and Vinod should merge the x86/pasid branch. Otherwise is his branch and incomplete you could not have tested it properly.

Hi Vinod,
Just checking to see if you have any objections or concerns with respect to this series. We are hoping it can be queued for the 5.10 merge if there are no objections. Thanks!

I was out for last few days, so haven't checked on this yet, but given that we are very close to merge widow I fear it is bit late to merge this late. I will go thru the series today though..

Thanks

Signature · 1 line
~Vinod
maintainer
#24 lore raw
Quoted 3 lines · Vinod Koul

I was out for last few days, so haven't checked on this yet, but given that we are very close to merge widow I fear it is bit late to merge this late.

There is time because we will have -rc8 so you have an additional week.

Quoted 1 line

I will go thru the series today though..

If you do and you wanna take them, I'd suggest this:

https://lists.01.org/hyperkitty/list/[email protected]/message/P4TZ4AU6MBIPT2OROPDOKEN7U2QCS7FX/

(it's on the same thread).

Thx.

Signature · 4 lines
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette
author reviewer
#25 lore raw
In reply to Vinod Koul
Quoted 24 lines · Vinod Koul

Hi Dave,

Quoted 18 lines · Dave Jiang
Quoted 16 lines · Borislav Petkov
Quoted 4 lines · Dave Jiang

Hi Vinod,
Looks like we are cleared on the x86 patches for this series with sign offs from maintainer Boris. Please consider the series for 5.10 inclusion. Thank you!

As I said here, I'd strongly suggest we do this:

https://lists.01.org/hyperkitty/list/[email protected]/thread/5FKNWNCCRV3AXUAEXUGQFF4EDQNANF3F/

and Vinod should merge the x86/pasid branch. Otherwise is his branch and incomplete you could not have tested it properly.

Quoted 8 lines
Quoted 4 lines

Hi Vinod,
Just checking to see if you have any objections or concerns with respect to this series. We are hoping it can be queued for the 5.10 merge if there are no objections. Thanks!

I was out for last few days, so haven't checked on this yet, but given that we are very close to merge widow I fear it is bit late to merge this late. I will go thru the series today though..

Thanks Vinod. Very much appreciate it either way.

Quoted 3 lines

Thanks

Signature · 1 line
~Vinod