linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com>
To: Dave Hansen <dave.hansen@linux.intel.com>,
	Andy Lutomirski <luto@kernel.org>,
	Peter Zijlstra <peterz@infradead.org>
Cc: x86@kernel.org, Kostya Serebryany <kcc@google.com>,
	Andrey Ryabinin <ryabinin.a.a@gmail.com>,
	Andrey Konovalov <andreyknvl@gmail.com>,
	Alexander Potapenko <glider@google.com>,
	Taras Madan <tarasmadan@google.com>,
	Dmitry Vyukov <dvyukov@google.com>,
	"H . J . Lu" <hjl.tools@gmail.com>,
	Andi Kleen <ak@linux.intel.com>,
	Rick Edgecombe <rick.p.edgecombe@intel.com>,
	linux-mm@kvack.org, linux-kernel@vger.kernel.org,
	Weihong Zhang <weihong.zhang@intel.com>,
	"Kirill A . Shutemov" <kirill.shutemov@linux.intel.com>
Subject: [PATCHv5 OPTIONAL 13/13] selftests/x86/lam: Add tests cases for LAM_U48
Date: Wed, 13 Jul 2022 02:13:28 +0300	[thread overview]
Message-ID: <20220712231328.5294-14-kirill.shutemov@linux.intel.com> (raw)
In-Reply-To: <20220712231328.5294-1-kirill.shutemov@linux.intel.com>

From: Weihong Zhang <weihong.zhang@intel.com>

LAM supports configurations that differ regarding which pointer bits are masked.
With LAM_U48, bits 62:48 in pointers can be masked as metadata bits, the width
of LAM is 15.

Add test cases in existed test scenarios:

MALLOC:

 - Enable LAM_U48, masks bits 48:62 of user pointers as metadata, the
   process can dereference these pointers.

MMAP:

 - Enable LAM_U48, mmaping with high address (above bits 47) have to be
   failed, which lead to trigger SIGSEGV.

 - LAM_U48 can't be enabled if there is a mmaping with high
   address(above bits 47) before enable LAM_U48.

SYSCALL:

 - LAM supports set metadata in high bits 62:48 (LAM48) of user process,
   pass these pointers to SYSCALL, SYSCALL can dereference pointers and
   return correct result.

IO_URING:

 - Add LAM_U48 test on IO_URING, Enable LAM_U48, set metadata in bits
   62:48 of buffers, IO_URING can handle these buffers well.

FORK/EXEC:

 - Add LAM_U48 test cases in inherit scenarios. these cases should same
   as LAM_U57;

Signed-off-by: Weihong Zhang <weihong.zhang@intel.com>
Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
---
 tools/testing/selftests/x86/lam.c | 67 ++++++++++++++++++++++++++++++-
 1 file changed, 66 insertions(+), 1 deletion(-)

diff --git a/tools/testing/selftests/x86/lam.c b/tools/testing/selftests/x86/lam.c
index fcac5feb47d0..b354e57bf072 100644
--- a/tools/testing/selftests/x86/lam.c
+++ b/tools/testing/selftests/x86/lam.c
@@ -24,6 +24,7 @@
 /* LAM modes, these definitions were copied from kernel code */
 #define LAM_NONE                0
 #define LAM_U57_BITS            6
+#define LAM_U48_BITS            15
 /* arch prctl for LAM */
 #define ARCH_GET_UNTAG_MASK     0x4001
 #define ARCH_ENABLE_TAGGED_ADDR 0x4002
@@ -126,7 +127,7 @@ static int set_lam(unsigned long lam)
 	int ret = 0;
 	uint64_t ptr = 0;
 
-	if (lam != LAM_U57_BITS && lam != LAM_NONE)
+	if (lam != LAM_U48_BITS && lam != LAM_U57_BITS && lam != LAM_NONE)
 		return -1;
 
 	/* Skip check return */
@@ -138,6 +139,8 @@ static int set_lam(unsigned long lam)
 	/* Check mask returned is expected */
 	if (lam == LAM_U57_BITS)
 		ret = (ptr != ~(0x3fULL << 57));
+	else if (lam == LAM_U48_BITS)
+		ret = (ptr != ~(0x7fffULL << 48));
 	else if (lam == LAM_NONE)
 		ret = (ptr != -1ULL);
 
@@ -161,6 +164,8 @@ static int get_lam(void)
 		ret = LAM_U57_BITS;
 	else if (ptr == -1ULL)
 		ret = LAM_NONE;
+	else if (ptr == ~(0x7fffULL << 48))
+		ret = LAM_U48_BITS;
 
 
 	return ret;
@@ -176,6 +181,9 @@ static uint64_t get_metadata(uint64_t src, unsigned long lam)
 	metadata = rand();
 
 	switch (lam) {
+	case LAM_U48_BITS: /* Set metadata in bits 62:48 */
+		metadata = (src & ~(0x7fffULL << 48)) | ((metadata & 0x7fff) << 48);
+		break;
 	case LAM_U57_BITS: /* Set metadata in bits 62:57 */
 		metadata = (src & ~(0x3fULL << 57)) | ((metadata & 0x3f) << 57);
 		break;
@@ -552,6 +560,9 @@ int do_uring(unsigned long lam)
 			uint64_t addr = ((uint64_t)fi->iovecs[i].iov_base);
 
 			switch (lam) {
+			case LAM_U48_BITS: /* Clear bits 62:48 */
+				addr = (addr & ~(0x7fffULL << 48));
+				break;
 			case LAM_U57_BITS: /* Clear bits 62:57 */
 				addr = (addr & ~(0x3fULL << 57));
 				break;
@@ -696,6 +707,12 @@ static struct testcases uring_cases[] = {
 		.test_func = handle_uring,
 		.msg = "URING: LAM_U57. Dereferencing pointer with metadata\n",
 	},
+	{
+		.later = 0,
+		.lam = LAM_U48_BITS,
+		.test_func = handle_uring,
+		.msg = "URING: LAM_U48. Dereferencing pointer with metadata.\n",
+	},
 	{
 		.later = 1,
 		.expected = 1,
@@ -712,6 +729,12 @@ static struct testcases malloc_cases[] = {
 		.test_func = handle_malloc,
 		.msg = "MALLOC: LAM_U57. Dereferencing pointer with metadata\n",
 	},
+	{
+		.later = 0,
+		.lam = LAM_U48_BITS,
+		.test_func = handle_malloc,
+		.msg = "MALLOC: LAM_U48. Dereferencing pointer with metadata.\n",
+	},
 	{
 		.later = 1,
 		.expected = 2,
@@ -728,6 +751,12 @@ static struct testcases syscall_cases[] = {
 		.test_func = handle_syscall,
 		.msg = "SYSCALL: LAM_U57. syscall with metadata\n",
 	},
+	{
+		.later = 0,
+		.lam = LAM_U48_BITS,
+		.test_func = handle_syscall,
+		.msg = "SYSCALL: LAM_U48. syscall with metadata\n",
+	},
 	{
 		.later = 1,
 		.expected = 1,
@@ -738,6 +767,14 @@ static struct testcases syscall_cases[] = {
 };
 
 static struct testcases mmap_cases[] = {
+	{
+		.later = 0,
+		.expected = 2,
+		.lam = LAM_U48_BITS,
+		.addr = HIGH_ADDR,
+		.test_func = handle_mmap,
+		.msg = "MMAP: [Negtive] First LAM_U48, then High address.\n",
+	},
 	{
 		.later = 1,
 		.expected = 0,
@@ -746,6 +783,14 @@ static struct testcases mmap_cases[] = {
 		.test_func = handle_mmap,
 		.msg = "MMAP: First mmap high address, then set LAM_U57.\n",
 	},
+	{
+		.later = 1,
+		.expected = 1,
+		.lam = LAM_U48_BITS,
+		.addr = HIGH_ADDR,
+		.test_func = handle_mmap,
+		.msg = "MMAP: [Negtive] First mmap high address, then set LAM_U48.\n",
+	},
 	{
 		.later = 0,
 		.expected = 0,
@@ -762,6 +807,14 @@ static struct testcases mmap_cases[] = {
 		.test_func = handle_mmap,
 		.msg = "MMAP: First LAM_U57, then Low address.\n",
 	},
+	{
+		.later = 0,
+		.expected = 0,
+		.lam = LAM_U48_BITS,
+		.addr = LOW_ADDR,
+		.test_func = handle_mmap,
+		.msg = "MMAP: First LAM_U48, then low address.\n",
+	},
 };
 
 static struct testcases inheritance_cases[] = {
@@ -771,12 +824,24 @@ static struct testcases inheritance_cases[] = {
 		.test_func = handle_inheritance,
 		.msg = "FORK: LAM_U57, child process should get LAM mode same as parent\n",
 	},
+	{
+		.expected = 0,
+		.lam = LAM_U48_BITS,
+		.test_func = handle_inheritance,
+		.msg = "FORK: LAM_U48, child process should get LAM mode same as parent\n",
+	},
 	{
 		.expected = 0,
 		.lam = LAM_U57_BITS,
 		.test_func = handle_execve,
 		.msg = "EXECVE: LAM_U57, child process should get disabled LAM mode\n",
 	},
+	{
+		.expected = 0,
+		.lam = LAM_U48_BITS,
+		.test_func = handle_execve,
+		.msg = "EXECVE: LAM_U48, child process should get disabled LAM mode\n",
+	},
 };
 
 static void cmd_help(void)
-- 
2.35.1



  parent reply	other threads:[~2022-07-12 23:13 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-12 23:13 [PATCHv5 00/13] Linear Address Masking enabling Kirill A. Shutemov
2022-07-12 23:13 ` [PATCHv5 01/13] x86/mm: Fix CR3_ADDR_MASK Kirill A. Shutemov
2022-07-21 13:10   ` Alexander Potapenko
2022-07-29  3:00   ` Hu, Robert
2022-07-12 23:13 ` [PATCHv5 02/13] x86: CPUID and CR3/CR4 flags for Linear Address Masking Kirill A. Shutemov
2022-07-21 13:10   ` Alexander Potapenko
2022-07-12 23:13 ` [PATCHv5 03/13] mm: Pass down mm_struct to untagged_addr() Kirill A. Shutemov
2022-07-21 13:12   ` Alexander Potapenko
2022-07-12 23:13 ` [PATCHv5 04/13] x86/mm: Handle LAM on context switch Kirill A. Shutemov
2022-07-12 23:13 ` [PATCHv5 05/13] x86/uaccess: Provide untagged_addr() and remove tags before address check Kirill A. Shutemov
2022-07-13 15:02   ` [PATCHv5.1 04/13] x86/mm: Handle LAM on context switch Kirill A. Shutemov
2022-07-20  8:57     ` Alexander Potapenko
2022-07-20 12:38       ` Kirill A. Shutemov
2022-07-21 13:13     ` Alexander Potapenko
2022-07-21 13:14   ` [PATCHv5 05/13] x86/uaccess: Provide untagged_addr() and remove tags before address check Alexander Potapenko
2022-07-12 23:13 ` [PATCHv5 06/13] x86/mm: Provide ARCH_GET_UNTAG_MASK and ARCH_ENABLE_TAGGED_ADDR Kirill A. Shutemov
2022-07-18 17:47   ` Alexander Potapenko
2022-07-20  0:57     ` Kirill A. Shutemov
2022-07-20  8:19       ` Alexander Potapenko
2022-07-20 12:47         ` Kirill A. Shutemov
2022-07-20 12:54           ` Alexander Potapenko
2022-07-12 23:13 ` [PATCHv5 07/13] x86: Expose untagging mask in /proc/$PID/arch_status Kirill A. Shutemov
2022-07-21 13:47   ` Alexander Potapenko
2022-07-12 23:13 ` [PATCHv5 08/13] selftests/x86/lam: Add malloc test cases for linear-address masking Kirill A. Shutemov
2022-07-12 23:13 ` [PATCHv5 09/13] selftests/x86/lam: Add mmap and SYSCALL " Kirill A. Shutemov
2022-07-12 23:13 ` [PATCHv5 10/13] selftests/x86/lam: Add io_uring " Kirill A. Shutemov
2022-07-12 23:13 ` [PATCHv5 11/13] selftests/x86/lam: Add inherit " Kirill A. Shutemov
2022-07-12 23:13 ` [PATCHv5 OPTIONAL 12/13] x86/mm: Extend LAM to support to LAM_U48 Kirill A. Shutemov
2022-07-12 23:13 ` Kirill A. Shutemov [this message]
2022-07-18 17:39 ` [PATCHv5 00/13] Linear Address Masking enabling Alexander Potapenko
2022-07-20  0:59   ` Kirill A. Shutemov
2022-07-21 13:09     ` Alexander Potapenko
2022-07-21 17:07     ` Dave Hansen

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=20220712231328.5294-14-kirill.shutemov@linux.intel.com \
    --to=kirill.shutemov@linux.intel.com \
    --cc=ak@linux.intel.com \
    --cc=andreyknvl@gmail.com \
    --cc=dave.hansen@linux.intel.com \
    --cc=dvyukov@google.com \
    --cc=glider@google.com \
    --cc=hjl.tools@gmail.com \
    --cc=kcc@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=luto@kernel.org \
    --cc=peterz@infradead.org \
    --cc=rick.p.edgecombe@intel.com \
    --cc=ryabinin.a.a@gmail.com \
    --cc=tarasmadan@google.com \
    --cc=weihong.zhang@intel.com \
    --cc=x86@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;
as well as URLs for NNTP newsgroup(s).