dmaengine.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Dave Jiang <dave.jiang@intel.com>
To: dmaengine@vger.kernel.org, linux-kernel@vger.kernel.org,
	vkoul@kernel.org
Cc: dan.j.williams@intel.com, tony.luck@intel.com,
	jing.lin@intel.com, ashok.raj@intel.com,
	sanjay.k.kumar@intel.com, megha.dey@intel.com,
	jacob.jun.pan@intel.com, yi.l.liu@intel.com, axboe@kernel.dk,
	akpm@linux-foundation.org, tglx@linutronix.de, mingo@redhat.com,
	bp@alien8.de, fenghua.yu@intel.com, hpa@zytor.com
Subject: [PATCH RFC 01/14] x86/asm: add iosubmit_cmds512() based on movdir64b CPU instruction
Date: Wed, 20 Nov 2019 14:23:49 -0700	[thread overview]
Message-ID: <157428502934.36836.8119026517510193201.stgit@djiang5-desk3.ch.intel.com> (raw)
In-Reply-To: <157428480574.36836.14057238306923901253.stgit@djiang5-desk3.ch.intel.com>

With the introduction of movdir64b instruction, there is now an instruction
that can write 64 bytes of data atomicaly.

Quoting from Intel SDM:
"There is no atomicity guarantee provided for the 64-byte load operation
from source address, and processor implementations may use multiple
load operations to read the 64-bytes. The 64-byte direct-store issued
by MOVDIR64B guarantees 64-byte write-completion atomicity. This means
that the data arrives at the destination in a single undivided 64-byte
write transaction."

We have identified at least 3 different use cases for this instruction in
the format of func(dst, src, count):
1) Clear poison / Initialize MKTME memory
   Destination is normal memory.
   Source in normal memory. Does not increment. (Copy same line to all
   targets)
   Count (to clear/init multiple lines)
2) Submit command(s) to new devices
   Destination is a special MMIO region for a device. Does not increment.
   Source is normal memory. Increments.
   Count usually is 1, but can be multiple.
3) Copy to iomem in big chunks
   Destination is iomem and increments
   Source in normal memory and increments
   Count is number of chunks to copy

This commit adds support for case #2 to support device that will accept
commands via this instruction.

Signed-off-by: Dave Jiang <dave.jiang@intel.com>
---
 arch/x86/include/asm/io.h |   44 ++++++++++++++++++++++++++++++++++++++++++++
 include/linux/io.h        |   11 +++++++++++
 2 files changed, 55 insertions(+)

diff --git a/arch/x86/include/asm/io.h b/arch/x86/include/asm/io.h
index 6bed97ff6db2..3126f6e1d5b8 100644
--- a/arch/x86/include/asm/io.h
+++ b/arch/x86/include/asm/io.h
@@ -403,5 +403,49 @@ extern bool arch_memremap_can_ram_remap(resource_size_t offset,
 
 extern bool phys_mem_access_encrypted(unsigned long phys_addr,
 				      unsigned long size);
+#include <linux/cpufeature.h>
+static inline bool cpu_has_write512(void)
+{
+	return cpu_feature_enabled(X86_FEATURE_MOVDIR64B);
+}
+
+#define cpu_has_write512 cpu_has_write512
+
+static inline void __iowrite512(void __iomem *__dst, const void *src)
+{
+	volatile struct { char _[64]; } *dst = __dst;
+
+	/* movdir64b [rdx], rax */
+	asm volatile(".byte 0x66, 0x0f, 0x38, 0xf8, 0x02"
+			: "=m" (dst)
+			: "d" (src), "a" (dst));
+}
+
+/**
+ * iosubmit_cmds512 - copy data to single MMIO location, in 512-bit units
+ * @dst: destination, in MMIO space (must be 512-bit aligned)
+ * @src: source
+ * @count: number of 512 bits quantities to submit
+ *
+ * Submit data from kernel space to MMIO space, in units of 512 bits at a
+ * time.  Order of access is not guaranteed, nor is a memory barrier
+ * performed afterwards.
+ */
+static inline void iosubmit_cmds512(void __iomem *dst, const void *src,
+				    size_t count)
+{
+	const u8 *from = src;
+	const u8 *end = from + count * 64;
+
+	if (!cpu_has_write512())
+		return;
+
+	while (from < end) {
+		__iowrite512(dst, from);
+		from += 64;
+	}
+}
+
+#define iosubmit_cmds512 iosubmit_cmds512
 
 #endif /* _ASM_X86_IO_H */
diff --git a/include/linux/io.h b/include/linux/io.h
index accac822336a..ca14af3e84de 100644
--- a/include/linux/io.h
+++ b/include/linux/io.h
@@ -20,6 +20,17 @@ __visible void __iowrite32_copy(void __iomem *to, const void *from, size_t count
 void __ioread32_copy(void *to, const void __iomem *from, size_t count);
 void __iowrite64_copy(void __iomem *to, const void *from, size_t count);
 
+#ifndef cpu_has_write512
+#define cpu_has_write512() (0)
+#endif
+
+#ifndef iosubmit_cmds512
+static inline void iosubmit_cmds512(void __iomem *to, const void *from,
+				    size_t count)
+{
+}
+#endif
+
 #ifdef CONFIG_MMU
 int ioremap_page_range(unsigned long addr, unsigned long end,
 		       phys_addr_t phys_addr, pgprot_t prot);


  reply	other threads:[~2019-11-20 21:23 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-20 21:23 [PATCH RFC 00/14] idxd driver for Intel Data Streaming Accelerator Dave Jiang
2019-11-20 21:23 ` Dave Jiang [this message]
2019-11-20 21:50   ` [PATCH RFC 01/14] x86/asm: add iosubmit_cmds512() based on movdir64b CPU instruction Dave Hansen
2019-11-20 23:46     ` Dave Jiang
2019-11-20 21:53   ` Borislav Petkov
2019-11-20 23:19     ` Luck, Tony
2019-11-20 23:26       ` Borislav Petkov
2019-11-21  0:15         ` Luck, Tony
2019-11-21  0:27         ` Dan Williams
2019-11-21  0:53           ` Thomas Gleixner
2019-11-21  1:32             ` Dan Williams
2019-11-21 10:37               ` Borislav Petkov
2019-11-21  0:21       ` Dan Williams
2019-11-21  0:22       ` Thomas Gleixner
2019-11-21  0:27         ` Dave Jiang
2019-11-21  0:10     ` Dave Jiang
2019-11-21 10:59       ` Borislav Petkov
2019-11-21 16:52         ` Dave Jiang
2019-11-22  8:59           ` Borislav Petkov
2019-11-22 17:20             ` Dan Williams
2019-11-22 18:44               ` Borislav Petkov
2019-11-22 18:50                 ` Dan Williams
2019-11-20 21:23 ` [PATCH RFC 02/14] dmaengine: break out channel registration Dave Jiang
2019-11-20 21:24 ` [PATCH RFC 03/14] dmaengine: add new dma device registration Dave Jiang
2019-11-20 21:24 ` [PATCH RFC 04/14] mm: create common code from request allocation based from blk-mq code Dave Jiang
2019-11-20 21:24 ` [PATCH RFC 05/14] dmaengine: add dma_request support functions Dave Jiang
2019-11-20 21:24 ` [PATCH RFC 06/14] dmaengine: add dma request submit and completion path support Dave Jiang
2019-11-20 21:24 ` [PATCH RFC 07/14] dmaengine: update dmatest to support dma request Dave Jiang
2019-11-20 21:24 ` [PATCH RFC 08/14] dmaengine: idxd: Init and probe for Intel data accelerators Dave Jiang
2019-11-20 21:24 ` [PATCH RFC 09/14] dmaengine: idxd: add configuration component of driver Dave Jiang
2019-11-20 21:24 ` [PATCH RFC 10/14] dmaengine: idxd: add descriptor manipulation routines Dave Jiang
2019-11-20 21:24 ` [PATCH RFC 11/14] dmaengine: idxd: connect idxd to dmaengine subsystem Dave Jiang
2019-11-20 21:24 ` [PATCH RFC 12/14] dmaengine: request submit optimization Dave Jiang
2019-11-20 21:25 ` [PATCH RFC 13/14] dmaengine: idxd: add char driver to expose submission portal to userland Dave Jiang
2019-11-20 21:25 ` [PATCH RFC 14/14] dmaengine: idxd: add sysfs ABI for idxd driver Dave Jiang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=157428502934.36836.8119026517510193201.stgit@djiang5-desk3.ch.intel.com \
    --to=dave.jiang@intel.com \
    --cc=akpm@linux-foundation.org \
    --cc=ashok.raj@intel.com \
    --cc=axboe@kernel.dk \
    --cc=bp@alien8.de \
    --cc=dan.j.williams@intel.com \
    --cc=dmaengine@vger.kernel.org \
    --cc=fenghua.yu@intel.com \
    --cc=hpa@zytor.com \
    --cc=jacob.jun.pan@intel.com \
    --cc=jing.lin@intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=megha.dey@intel.com \
    --cc=mingo@redhat.com \
    --cc=sanjay.k.kumar@intel.com \
    --cc=tglx@linutronix.de \
    --cc=tony.luck@intel.com \
    --cc=vkoul@kernel.org \
    --cc=yi.l.liu@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).