From nobody Fri Dec 19 20:35:45 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C28C7C43334 for ; Tue, 12 Jul 2022 23:14:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234221AbiGLXOK (ORCPT ); Tue, 12 Jul 2022 19:14:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41964 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233911AbiGLXNg (ORCPT ); Tue, 12 Jul 2022 19:13:36 -0400 Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 910D9B0B for ; Tue, 12 Jul 2022 16:13:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1657667611; x=1689203611; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ccx0RgNBfz7piuZWOrmJMdKV3R7Gsc2VojQmQ6vSEyk=; b=ifL0xduc/fDMqiPNBhFClh9G4EwjNcFoQlebl7l5MhYE6iQUsTBgmgk9 UAqniLm9Sa1UqsLs2BatJb6rtuqDP9rxxEyRFPOB94Gq+6+zCWztIAmax ZapTFsw0bL9i7cPkJ8YBEp6VkQAneDHuanlDOjTSHyph+qy6UWD7vjmF8 zXO1W/8n0KkXtn120Vl/LjDJ7ySeIG2l4R6ZKg+S8NE38dgESgi7vNH5C d6ju6jfVuoem4RqedvC1IiDjf2d6fy9iUltcU53pQzdfTh5GDDVf+bW3e 8erim6MGybFleHelJlulHGawl7Xy5qi+mWWwf6+qkwJ3BhiSi6gQK1G/A g==; X-IronPort-AV: E=McAfee;i="6400,9594,10406"; a="285808447" X-IronPort-AV: E=Sophos;i="5.92,266,1650956400"; d="scan'208";a="285808447" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Jul 2022 16:13:30 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.92,266,1650956400"; d="scan'208";a="592792970" Received: from black.fi.intel.com ([10.237.72.28]) by orsmga007.jf.intel.com with ESMTP; 12 Jul 2022 16:13:26 -0700 Received: by black.fi.intel.com (Postfix, from userid 1000) id 4ABDA6CE; Wed, 13 Jul 2022 02:13:30 +0300 (EEST) From: "Kirill A. Shutemov" To: Dave Hansen , Andy Lutomirski , Peter Zijlstra Cc: x86@kernel.org, Kostya Serebryany , Andrey Ryabinin , Andrey Konovalov , Alexander Potapenko , Taras Madan , Dmitry Vyukov , "H . J . Lu" , Andi Kleen , Rick Edgecombe , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Weihong Zhang , "Kirill A . Shutemov" Subject: [PATCHv5 OPTIONAL 13/13] selftests/x86/lam: Add tests cases for LAM_U48 Date: Wed, 13 Jul 2022 02:13:28 +0300 Message-Id: <20220712231328.5294-14-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220712231328.5294-1-kirill.shutemov@linux.intel.com> References: <20220712231328.5294-1-kirill.shutemov@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Weihong Zhang LAM supports configurations that differ regarding which pointer bits are ma= sked. With LAM_U48, bits 62:48 in pointers can be masked as metadata bits, the wi= dth 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 Signed-off-by: Kirill A. Shutemov --- 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/x8= 6/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 =3D 0; uint64_t ptr =3D 0; =20 - if (lam !=3D LAM_U57_BITS && lam !=3D LAM_NONE) + if (lam !=3D LAM_U48_BITS && lam !=3D LAM_U57_BITS && lam !=3D LAM_NONE) return -1; =20 /* Skip check return */ @@ -138,6 +139,8 @@ static int set_lam(unsigned long lam) /* Check mask returned is expected */ if (lam =3D=3D LAM_U57_BITS) ret =3D (ptr !=3D ~(0x3fULL << 57)); + else if (lam =3D=3D LAM_U48_BITS) + ret =3D (ptr !=3D ~(0x7fffULL << 48)); else if (lam =3D=3D LAM_NONE) ret =3D (ptr !=3D -1ULL); =20 @@ -161,6 +164,8 @@ static int get_lam(void) ret =3D LAM_U57_BITS; else if (ptr =3D=3D -1ULL) ret =3D LAM_NONE; + else if (ptr =3D=3D ~(0x7fffULL << 48)) + ret =3D LAM_U48_BITS; =20 =20 return ret; @@ -176,6 +181,9 @@ static uint64_t get_metadata(uint64_t src, unsigned lon= g lam) metadata =3D rand(); =20 switch (lam) { + case LAM_U48_BITS: /* Set metadata in bits 62:48 */ + metadata =3D (src & ~(0x7fffULL << 48)) | ((metadata & 0x7fff) << 48); + break; case LAM_U57_BITS: /* Set metadata in bits 62:57 */ metadata =3D (src & ~(0x3fULL << 57)) | ((metadata & 0x3f) << 57); break; @@ -552,6 +560,9 @@ int do_uring(unsigned long lam) uint64_t addr =3D ((uint64_t)fi->iovecs[i].iov_base); =20 switch (lam) { + case LAM_U48_BITS: /* Clear bits 62:48 */ + addr =3D (addr & ~(0x7fffULL << 48)); + break; case LAM_U57_BITS: /* Clear bits 62:57 */ addr =3D (addr & ~(0x3fULL << 57)); break; @@ -696,6 +707,12 @@ static struct testcases uring_cases[] =3D { .test_func =3D handle_uring, .msg =3D "URING: LAM_U57. Dereferencing pointer with metadata\n", }, + { + .later =3D 0, + .lam =3D LAM_U48_BITS, + .test_func =3D handle_uring, + .msg =3D "URING: LAM_U48. Dereferencing pointer with metadata.\n", + }, { .later =3D 1, .expected =3D 1, @@ -712,6 +729,12 @@ static struct testcases malloc_cases[] =3D { .test_func =3D handle_malloc, .msg =3D "MALLOC: LAM_U57. Dereferencing pointer with metadata\n", }, + { + .later =3D 0, + .lam =3D LAM_U48_BITS, + .test_func =3D handle_malloc, + .msg =3D "MALLOC: LAM_U48. Dereferencing pointer with metadata.\n", + }, { .later =3D 1, .expected =3D 2, @@ -728,6 +751,12 @@ static struct testcases syscall_cases[] =3D { .test_func =3D handle_syscall, .msg =3D "SYSCALL: LAM_U57. syscall with metadata\n", }, + { + .later =3D 0, + .lam =3D LAM_U48_BITS, + .test_func =3D handle_syscall, + .msg =3D "SYSCALL: LAM_U48. syscall with metadata\n", + }, { .later =3D 1, .expected =3D 1, @@ -738,6 +767,14 @@ static struct testcases syscall_cases[] =3D { }; =20 static struct testcases mmap_cases[] =3D { + { + .later =3D 0, + .expected =3D 2, + .lam =3D LAM_U48_BITS, + .addr =3D HIGH_ADDR, + .test_func =3D handle_mmap, + .msg =3D "MMAP: [Negtive] First LAM_U48, then High address.\n", + }, { .later =3D 1, .expected =3D 0, @@ -746,6 +783,14 @@ static struct testcases mmap_cases[] =3D { .test_func =3D handle_mmap, .msg =3D "MMAP: First mmap high address, then set LAM_U57.\n", }, + { + .later =3D 1, + .expected =3D 1, + .lam =3D LAM_U48_BITS, + .addr =3D HIGH_ADDR, + .test_func =3D handle_mmap, + .msg =3D "MMAP: [Negtive] First mmap high address, then set LAM_U48.\n", + }, { .later =3D 0, .expected =3D 0, @@ -762,6 +807,14 @@ static struct testcases mmap_cases[] =3D { .test_func =3D handle_mmap, .msg =3D "MMAP: First LAM_U57, then Low address.\n", }, + { + .later =3D 0, + .expected =3D 0, + .lam =3D LAM_U48_BITS, + .addr =3D LOW_ADDR, + .test_func =3D handle_mmap, + .msg =3D "MMAP: First LAM_U48, then low address.\n", + }, }; =20 static struct testcases inheritance_cases[] =3D { @@ -771,12 +824,24 @@ static struct testcases inheritance_cases[] =3D { .test_func =3D handle_inheritance, .msg =3D "FORK: LAM_U57, child process should get LAM mode same as paren= t\n", }, + { + .expected =3D 0, + .lam =3D LAM_U48_BITS, + .test_func =3D handle_inheritance, + .msg =3D "FORK: LAM_U48, child process should get LAM mode same as paren= t\n", + }, { .expected =3D 0, .lam =3D LAM_U57_BITS, .test_func =3D handle_execve, .msg =3D "EXECVE: LAM_U57, child process should get disabled LAM mode\n", }, + { + .expected =3D 0, + .lam =3D LAM_U48_BITS, + .test_func =3D handle_execve, + .msg =3D "EXECVE: LAM_U48, child process should get disabled LAM mode\n", + }, }; =20 static void cmd_help(void) --=20 2.35.1