From: Dave Jiang <dave.jiang@intel.com>
To: vkoul@kernel.org, bp@alien8.de, dan.j.williams@intel.com,
tony.luck@intel.com, ashok.raj@intel.com, kevin.tian@intel.com,
fenghua.yu@intel.com
Cc: dmaengine@vger.kernel.org, linux-kernel@vger.kernel.org,
Michael Matz <matz@suse.de>, Borislav Petkov <bp@suse.de>
Subject: [PATCH v7 1/5] x86/asm: Carve out a generic movdir64b() helper for general usage
Date: Mon, 5 Oct 2020 08:11:22 -0700 [thread overview]
Message-ID: <20201005151126.657029-2-dave.jiang@intel.com> (raw)
In-Reply-To: <20201005151126.657029-1-dave.jiang@intel.com>
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.
Reviewed-by: Tony Luck <tony.luck@intel.com>
Suggested-by: Michael Matz <matz@suse.de>
Reviewed-by: Borislav Petkov <bp@suse.de>
Signed-off-by: Dave Jiang <dave.jiang@intel.com>
---
arch/x86/include/asm/io.h | 17 +++--------------
arch/x86/include/asm/special_insns.h | 22 ++++++++++++++++++++++
2 files changed, 25 insertions(+), 14 deletions(-)
diff --git a/arch/x86/include/asm/io.h b/arch/x86/include/asm/io.h
index e1aa17a468a8..d726459d08e5 100644
--- a/arch/x86/include/asm/io.h
+++ b/arch/x86/include/asm/io.h
@@ -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;
}
}
diff --git a/arch/x86/include/asm/special_insns.h b/arch/x86/include/asm/special_insns.h
index 59a3e13204c3..2258c7d6e281 100644
--- a/arch/x86/include/asm/special_insns.h
+++ b/arch/x86/include/asm/special_insns.h
@@ -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 */
--
2.26.2
next prev parent reply other threads:[~2020-10-05 15:11 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-10-05 15:11 [PATCH v7 0/5] Add shared workqueue support for idxd driver Dave Jiang
2020-10-05 15:11 ` Dave Jiang [this message]
2020-10-07 16:14 ` [tip: x86/pasid] x86/asm: Carve out a generic movdir64b() helper for general usage tip-bot2 for Dave Jiang
2020-10-07 17:08 ` Peter Zijlstra
2020-10-07 21:13 ` Borislav Petkov
2020-10-08 6:49 ` Peter Zijlstra
2020-10-05 15:11 ` [PATCH v7 2/5] x86/asm: Add an enqcmds() wrapper for the ENQCMDS instruction Dave Jiang
2020-10-05 15:11 ` [PATCH v7 3/5] dmaengine: idxd: Add shared workqueue support Dave Jiang
2020-10-05 15:11 ` [PATCH v7 4/5] dmaengine: idxd: Clean up descriptors with fault error Dave Jiang
2020-10-05 15:11 ` [PATCH v7 5/5] dmaengine: idxd: Add ABI documentation for shared wq Dave Jiang
2020-10-07 7:01 ` [PATCH v7 0/5] Add shared workqueue support for idxd driver Vinod Koul
2020-10-07 8:48 ` Borislav Petkov
2020-10-07 9:53 ` Vinod Koul
2020-10-07 10:04 ` Borislav Petkov
2020-10-07 14:57 ` Vinod Koul
2020-10-07 16:16 ` Borislav Petkov
2020-10-07 16:50 ` 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=20201005151126.657029-2-dave.jiang@intel.com \
--to=dave.jiang@intel.com \
--cc=ashok.raj@intel.com \
--cc=bp@alien8.de \
--cc=bp@suse.de \
--cc=dan.j.williams@intel.com \
--cc=dmaengine@vger.kernel.org \
--cc=fenghua.yu@intel.com \
--cc=kevin.tian@intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=matz@suse.de \
--cc=tony.luck@intel.com \
--cc=vkoul@kernel.org \
/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
Powered by JetHome