From patchwork Thu Mar 10 11:15:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bharata B Rao X-Patchwork-Id: 12776164 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 03A55C433F5 for ; Thu, 10 Mar 2022 11:16:20 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 94E2B8D0005; Thu, 10 Mar 2022 06:16:20 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 8D7028D0001; Thu, 10 Mar 2022 06:16:20 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 750C98D0005; Thu, 10 Mar 2022 06:16:20 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0154.hostedemail.com [216.40.44.154]) by kanga.kvack.org (Postfix) with ESMTP id 612268D0001 for ; Thu, 10 Mar 2022 06:16:20 -0500 (EST) Received: from smtpin21.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 1E57B8248D52 for ; Thu, 10 Mar 2022 11:16:20 +0000 (UTC) X-FDA: 79228222920.21.FBAF9C1 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2063.outbound.protection.outlook.com [40.107.243.63]) by imf23.hostedemail.com (Postfix) with ESMTP id 6970B140012 for ; Thu, 10 Mar 2022 11:16:19 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=m+dMWlBTcEhj9HicwINstZ/vnqWgX2sXkDIp8RzXSXOy2lXtvexwqu9fMngiYt8S67PtVRRyPu2utyDGSJyB3hKvC6E5HeNalsHSEadMD+PK+kvJ2S+aDltTClcS+kEO/XmlQ/kU0R8MBjqBetXag4vVX9j8xwqidI0H5WDXMZYaA20UZ6wOgA/sVtBvM40QnlJDx2/VO1nMyAFIP4fcyiXAypx6LBb2O1AytxqEmj3ugDnjC3TP97I8fjb7J40TreCwDedqS52CSxGfs1x3yCYcp4t5tj2NNDgWbi+3T0tBRkg491N/qHlOt2V3lv7HCg2nmSgJ51txWgQvy1g8gQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=qZsu1j80b51aVDCZsYbxSMhONhjprdDenKJTK/70D+0=; b=TMz/RlkZvYlJqdCbvGtksFc2H8mEVv5mfdaqK2EotSWb5V2TYYeVyalPCAfsUOE36FEVwcJO8rHLku9GM65GTHFnfIZpVgX8bJ+sYCDD7aGvFqlj/BHMs0c9kzHx9qoAdtqO3siADn46HlLt/muF6eN7M6thSe6GvPasBKoeGFT0NredSzPuUnnnZWNFpO7AIj/S1jA1O96kEXLC+hPNUUCdLzOEUwB4fZBjyti3KCXPb/uk/Kru6WP2d2XduQAyMsHeXly5vYFANL+v/UJKVbUfIZeuLQWaR2/j8R5DTyB7SaYKfGDkd/lzXbIewdUeiJfbYvz22eYoDG1wtWR3eQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=qZsu1j80b51aVDCZsYbxSMhONhjprdDenKJTK/70D+0=; b=ONVtwFcP6hqdTY+jdLUuuPxCPuU/gDArpHOlwxu0TQIlYoQ+jo66dxAVmharB0yMLAoMg0pW8+EbLlI9Lroot7W3LR0meecCmopKPcPwkXEfLTa0laqiWhAtdfhEvK/k5TJz8T0JLJ+/HhNxCrTevKR4LFnMEABaCZA1bOcNvrE= Received: from CO2PR05CA0092.namprd05.prod.outlook.com (2603:10b6:104:1::18) by DM5PR1201MB0106.namprd12.prod.outlook.com (2603:10b6:4:4f::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5038.17; Thu, 10 Mar 2022 11:16:16 +0000 Received: from CO1NAM11FT005.eop-nam11.prod.protection.outlook.com (2603:10b6:104:1:cafe::ec) by CO2PR05CA0092.outlook.office365.com (2603:10b6:104:1::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5081.7 via Frontend Transport; Thu, 10 Mar 2022 11:16:16 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; Received: from SATLEXMB04.amd.com (165.204.84.17) by CO1NAM11FT005.mail.protection.outlook.com (10.13.174.147) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5038.14 via Frontend Transport; Thu, 10 Mar 2022 11:16:15 +0000 Received: from BLR-5CG1133937.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Thu, 10 Mar 2022 05:16:09 -0600 From: Bharata B Rao To: CC: , , , , , , , , , , , , "Bharata B Rao" Subject: [RFC PATCH v0 1/6] mm, arm64: Update PR_SET/GET_TAGGED_ADDR_CTRL interface Date: Thu, 10 Mar 2022 16:45:40 +0530 Message-ID: <20220310111545.10852-2-bharata@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220310111545.10852-1-bharata@amd.com> References: <20220310111545.10852-1-bharata@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 9d7f5d4a-813c-45e2-1c33-08da028764b9 X-MS-TrafficTypeDiagnostic: DM5PR1201MB0106:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: /Yz+qSkQhVpN4l8JLdSaE2RDTrDBmt1vpMM0htHJkQKa3KMjM0Ly5Km7wusIHlwuYxuDUeOeW2yywO65q4lvwo9QvcLyfaPAw47FKQ25fiOxmyNfIUSY1mnT/2to0s68knWZRPR5Db9SYhmHdhddf688QfoVUBV0RrTB17/JIl3URUMnykxkeCK9kV32W5JYVGXGrdgPEvPGSjszVuOd5PjwVJMtLLNkCjwxHOIr0tWSk+p/bBJ2EWi+kBJQbe+DY/donKsA0B+UpXDaJ/Q9Faly41Z+LY/V660mA2o6bieQ0hpz4Ki7IsqupemRnWavrbJAfmA9VvAx55Af/G++N3FYLk1MFanQE641mo43U6I7iFb2AUB2T+omHEHUJ/wzcjbecoJDqWsdfPsUdzyShKxnRsGOnRzJGbobsc3QRqcLjneevHOBwWineArfHuDAoVlZMAPpZIfCmE4faaetWDDjotS/E6SUXYA9D9t8E26h9zfvKZyp9xGiNOn/C/V8DrLOQ/2v676+whmpRYPyzPeE23sAupIzS+tXSqv+a7hFa+jgaAfq8o5U8z+H+i1K57s9zfDcP9xAsL18zd5Tm49yYcjxjUQpHnDpaNZt2tIc78dRWfPo6+hQURsX9K9L/HJaPHiIDGd1TceuOSI8W/l61J7vB+qCb9vTgBDIt5SuSIUtAwh7qnBS0AGyIHTFu53ZLsuE6EKIijmS+ru8+ueHkFqbLwb+M3h6YZxlcJhbdFM1y9ZDd7hWI4ZsBNNa X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230001)(4636009)(46966006)(40470700004)(36840700001)(508600001)(86362001)(70586007)(40460700003)(16526019)(426003)(26005)(83380400001)(336012)(1076003)(2616005)(6666004)(7696005)(47076005)(186003)(2906002)(30864003)(5660300002)(81166007)(4326008)(70206006)(8676002)(316002)(36860700001)(7416002)(54906003)(15650500001)(356005)(8936002)(36756003)(6916009)(82310400004)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Mar 2022 11:16:15.8008 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 9d7f5d4a-813c-45e2-1c33-08da028764b9 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT005.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR1201MB0106 X-Rspam-User: X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: 6970B140012 X-Stat-Signature: 49oyyp1srp3ta98m5p6s6o8kwdjihcnr Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=ONVtwFcP; dmarc=pass (policy=quarantine) header.from=amd.com; spf=pass (imf23.hostedemail.com: domain of bharata@amd.com designates 40.107.243.63 as permitted sender) smtp.mailfrom=bharata@amd.com X-HE-Tag: 1646910979-656734 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: "Kirill A. Shutemov" The interface for enabling tagged addresses is very inflexible. It implies tag size and tag shift implemented by ARM TBI. Rework the interface to accommodate different shifts and tag sizes. PR_SET_TAGGED_ADDR_CTRL now accepts two new arguments: - nr_bits is pointer to int. The caller specifies the tag size it wants. Kernel updates the value of actual tag size that can be larger. - offset is pointer to int. Kernel returns there a shift of tag in the address. The change doesn't break existing users of the interface: if any of these pointers are NULL (as we had before the change), the user expects ARM TBI implementation: nr_bits == 8 && offset == 56 as it was implied before. The initial implementation checked that these argument are NULL and the change wouldn't not break any legacy users. If tagging is enabled, GET_TAGGED_ADDR_CTRL would return size of tags and offset in the additional arguments. If tagging is disable, GET_TAGGED_ADDR_CTRL would return the maximum tag size in nr_bits. The selftest is updated accordingly and moved out of arm64-specific directory as we going to enable the interface on x86. As alternative to this approach we could introduce a totally new API and leave the legacy one as is. But it would slow down adoption: new prctl(2) flag wound need to propogate to the userspace headers. Signed-off-by: Kirill A. Shutemov [selftests/vm/tags/tags_test.c: Set ptr tag only when tagging is enabled and a couple of checkpatch warning fixes] Signed-off-by: Bharata B Rao --- arch/arm64/include/asm/processor.h | 12 ++-- arch/arm64/kernel/process.c | 45 +++++++++++--- arch/arm64/kernel/ptrace.c | 4 +- kernel/sys.c | 14 +++-- .../testing/selftests/arm64/tags/tags_test.c | 31 ---------- .../selftests/{arm64 => vm}/tags/.gitignore | 0 .../selftests/{arm64 => vm}/tags/Makefile | 0 .../{arm64 => vm}/tags/run_tags_test.sh | 0 tools/testing/selftests/vm/tags/tags_test.c | 59 +++++++++++++++++++ 9 files changed, 115 insertions(+), 50 deletions(-) delete mode 100644 tools/testing/selftests/arm64/tags/tags_test.c rename tools/testing/selftests/{arm64 => vm}/tags/.gitignore (100%) rename tools/testing/selftests/{arm64 => vm}/tags/Makefile (100%) rename tools/testing/selftests/{arm64 => vm}/tags/run_tags_test.sh (100%) create mode 100644 tools/testing/selftests/vm/tags/tags_test.c diff --git a/arch/arm64/include/asm/processor.h b/arch/arm64/include/asm/processor.h index 6f41b65f9962..c3936bebf006 100644 --- a/arch/arm64/include/asm/processor.h +++ b/arch/arm64/include/asm/processor.h @@ -367,10 +367,14 @@ extern void __init minsigstksz_setup(void); #ifdef CONFIG_ARM64_TAGGED_ADDR_ABI /* PR_{SET,GET}_TAGGED_ADDR_CTRL prctl */ -long set_tagged_addr_ctrl(struct task_struct *task, unsigned long arg); -long get_tagged_addr_ctrl(struct task_struct *task); -#define SET_TAGGED_ADDR_CTRL(arg) set_tagged_addr_ctrl(current, arg) -#define GET_TAGGED_ADDR_CTRL() get_tagged_addr_ctrl(current) +long set_tagged_addr_ctrl(struct task_struct *task, unsigned long flags, + int __user *nr_bits, int __user *offset); +long get_tagged_addr_ctrl(struct task_struct *task, + int __user *nr_bits, int __user *offset); +#define SET_TAGGED_ADDR_CTRL(flags, nr_bits, offset) \ + set_tagged_addr_ctrl(current, flags, nr_bits, offset) +#define GET_TAGGED_ADDR_CTRL(nr_bits, offset) \ + get_tagged_addr_ctrl(current, nr_bits, offset) #endif /* diff --git a/arch/arm64/kernel/process.c b/arch/arm64/kernel/process.c index 5369e649fa79..fc0240f5ead0 100644 --- a/arch/arm64/kernel/process.c +++ b/arch/arm64/kernel/process.c @@ -621,15 +621,21 @@ void arch_setup_new_exec(void) } #ifdef CONFIG_ARM64_TAGGED_ADDR_ABI + +#define TBI_TAG_BITS 8 +#define TBI_TAG_SHIFT 56 + /* * Control the relaxed ABI allowing tagged user addresses into the kernel. */ static unsigned int tagged_addr_disabled; -long set_tagged_addr_ctrl(struct task_struct *task, unsigned long arg) +long set_tagged_addr_ctrl(struct task_struct *task, unsigned long flags, + int __user *nr_bits, int __user *offset) { unsigned long valid_mask = PR_TAGGED_ADDR_ENABLE; struct thread_info *ti = task_thread_info(task); + int val; if (is_compat_thread(ti)) return -EINVAL; @@ -637,25 +643,41 @@ long set_tagged_addr_ctrl(struct task_struct *task, unsigned long arg) if (system_supports_mte()) valid_mask |= PR_MTE_TCF_MASK | PR_MTE_TAG_MASK; - if (arg & ~valid_mask) + if (flags & ~valid_mask) return -EINVAL; + if (nr_bits) { + if (get_user(val, nr_bits)) + return -EFAULT; + if (val > TBI_TAG_BITS || val < 1) + return -EINVAL; + } + /* * Do not allow the enabling of the tagged address ABI if globally * disabled via sysctl abi.tagged_addr_disabled. */ - if (arg & PR_TAGGED_ADDR_ENABLE && tagged_addr_disabled) + if (flags & PR_TAGGED_ADDR_ENABLE && tagged_addr_disabled) return -EINVAL; - if (set_mte_ctrl(task, arg) != 0) + if (set_mte_ctrl(task, flags) != 0) return -EINVAL; - update_ti_thread_flag(ti, TIF_TAGGED_ADDR, arg & PR_TAGGED_ADDR_ENABLE); + if (flags & PR_TAGGED_ADDR_ENABLE) { + if (nr_bits && put_user(TBI_TAG_BITS, nr_bits)) + return -EFAULT; + if (offset && put_user(TBI_TAG_SHIFT, offset)) + return -EFAULT; + } + + update_ti_thread_flag(ti, TIF_TAGGED_ADDR, + flags & PR_TAGGED_ADDR_ENABLE); return 0; } -long get_tagged_addr_ctrl(struct task_struct *task) +long get_tagged_addr_ctrl(struct task_struct *task, + int __user *nr_bits, int __user *offset) { long ret = 0; struct thread_info *ti = task_thread_info(task); @@ -663,8 +685,17 @@ long get_tagged_addr_ctrl(struct task_struct *task) if (is_compat_thread(ti)) return -EINVAL; - if (test_ti_thread_flag(ti, TIF_TAGGED_ADDR)) + if (test_ti_thread_flag(ti, TIF_TAGGED_ADDR)) { ret = PR_TAGGED_ADDR_ENABLE; + if (nr_bits && put_user(TBI_TAG_BITS, nr_bits)) + return -EFAULT; + if (offset && put_user(TBI_TAG_SHIFT, offset)) + return -EFAULT; + } else { + /* Report maximum tag size */ + if (nr_bits && put_user(TBI_TAG_BITS, nr_bits)) + return -EFAULT; + } ret |= get_mte_ctrl(task); diff --git a/arch/arm64/kernel/ptrace.c b/arch/arm64/kernel/ptrace.c index 39dbdfdc38d3..471fd40f7d4e 100644 --- a/arch/arm64/kernel/ptrace.c +++ b/arch/arm64/kernel/ptrace.c @@ -1073,7 +1073,7 @@ static int tagged_addr_ctrl_get(struct task_struct *target, const struct user_regset *regset, struct membuf to) { - long ctrl = get_tagged_addr_ctrl(target); + long ctrl = get_tagged_addr_ctrl(target, NULL, NULL); if (IS_ERR_VALUE(ctrl)) return ctrl; @@ -1093,7 +1093,7 @@ static int tagged_addr_ctrl_set(struct task_struct *target, const struct if (ret) return ret; - return set_tagged_addr_ctrl(target, ctrl); + return set_tagged_addr_ctrl(target, ctrl, NULL, NULL); } #endif diff --git a/kernel/sys.c b/kernel/sys.c index 97dc9e5d6bf9..3af5c5098b3c 100644 --- a/kernel/sys.c +++ b/kernel/sys.c @@ -126,10 +126,10 @@ # define PAC_GET_ENABLED_KEYS(a) (-EINVAL) #endif #ifndef SET_TAGGED_ADDR_CTRL -# define SET_TAGGED_ADDR_CTRL(a) (-EINVAL) +# define SET_TAGGED_ADDR_CTRL(a, b, c) (-EINVAL) #endif #ifndef GET_TAGGED_ADDR_CTRL -# define GET_TAGGED_ADDR_CTRL() (-EINVAL) +# define GET_TAGGED_ADDR_CTRL(a, b) (-EINVAL) #endif /* @@ -2557,14 +2557,16 @@ SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3, error = PAC_GET_ENABLED_KEYS(me); break; case PR_SET_TAGGED_ADDR_CTRL: - if (arg3 || arg4 || arg5) + if (arg5) return -EINVAL; - error = SET_TAGGED_ADDR_CTRL(arg2); + error = SET_TAGGED_ADDR_CTRL(arg2, (int __user *)arg3, + (int __user *)arg4); break; case PR_GET_TAGGED_ADDR_CTRL: - if (arg2 || arg3 || arg4 || arg5) + if (arg4 || arg5) return -EINVAL; - error = GET_TAGGED_ADDR_CTRL(); + error = GET_TAGGED_ADDR_CTRL((int __user *)arg2, + (int __user *)arg3); break; case PR_SET_IO_FLUSHER: if (!capable(CAP_SYS_RESOURCE)) diff --git a/tools/testing/selftests/arm64/tags/tags_test.c b/tools/testing/selftests/arm64/tags/tags_test.c deleted file mode 100644 index 5701163460ef..000000000000 --- a/tools/testing/selftests/arm64/tags/tags_test.c +++ /dev/null @@ -1,31 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 - -#include -#include -#include -#include -#include -#include - -#define SHIFT_TAG(tag) ((uint64_t)(tag) << 56) -#define SET_TAG(ptr, tag) (((uint64_t)(ptr) & ~SHIFT_TAG(0xff)) | \ - SHIFT_TAG(tag)) - -int main(void) -{ - static int tbi_enabled = 0; - unsigned long tag = 0; - struct utsname *ptr; - int err; - - if (prctl(PR_SET_TAGGED_ADDR_CTRL, PR_TAGGED_ADDR_ENABLE, 0, 0, 0) == 0) - tbi_enabled = 1; - ptr = (struct utsname *)malloc(sizeof(*ptr)); - if (tbi_enabled) - tag = 0x42; - ptr = (struct utsname *)SET_TAG(ptr, tag); - err = uname(ptr); - free(ptr); - - return err; -} diff --git a/tools/testing/selftests/arm64/tags/.gitignore b/tools/testing/selftests/vm/tags/.gitignore similarity index 100% rename from tools/testing/selftests/arm64/tags/.gitignore rename to tools/testing/selftests/vm/tags/.gitignore diff --git a/tools/testing/selftests/arm64/tags/Makefile b/tools/testing/selftests/vm/tags/Makefile similarity index 100% rename from tools/testing/selftests/arm64/tags/Makefile rename to tools/testing/selftests/vm/tags/Makefile diff --git a/tools/testing/selftests/arm64/tags/run_tags_test.sh b/tools/testing/selftests/vm/tags/run_tags_test.sh similarity index 100% rename from tools/testing/selftests/arm64/tags/run_tags_test.sh rename to tools/testing/selftests/vm/tags/run_tags_test.sh diff --git a/tools/testing/selftests/vm/tags/tags_test.c b/tools/testing/selftests/vm/tags/tags_test.c new file mode 100644 index 000000000000..c8486b6398b1 --- /dev/null +++ b/tools/testing/selftests/vm/tags/tags_test.c @@ -0,0 +1,59 @@ +// SPDX-License-Identifier: GPL-2.0 + +#include +#include +#include +#include +#include +#include + +static int tag_bits; +static int tag_offset; + +#define SHIFT_TAG(tag) ((uint64_t)(tag) << tag_offset) +#define SET_TAG(ptr, tag) (((uint64_t)(ptr) & ~SHIFT_TAG((1 << tag_bits) - 1)) \ + | SHIFT_TAG(tag)) + +static int max_tag_bits(void) +{ + int nr; + + if (prctl(PR_GET_TAGGED_ADDR_CTRL, 0, 0, 0) < 0) + return 0; + + if (prctl(PR_GET_TAGGED_ADDR_CTRL, &nr, 0, 0) < 0) + return 8; /* Assume ARM TBI */ + + return nr; +} + +int main(void) +{ + static int tags_enabled; + unsigned long tag = 0; + struct utsname *ptr; + int err; + + tag_bits = max_tag_bits(); + + if (tag_bits && !prctl(PR_SET_TAGGED_ADDR_CTRL, PR_TAGGED_ADDR_ENABLE, + &tag_bits, &tag_offset, 0)) { + tags_enabled = 1; + } else if (tag_bits == 8 && !prctl(PR_SET_TAGGED_ADDR_CTRL, + PR_TAGGED_ADDR_ENABLE, 0, 0)) { + /* ARM TBI with legacy interface*/ + tags_enabled = 1; + tag_offset = 56; + } + + ptr = (struct utsname *)malloc(sizeof(*ptr)); + if (tags_enabled) { + tag = (1UL << tag_bits) - 1; + ptr = (struct utsname *)SET_TAG(ptr, tag); + } + err = uname(ptr); + printf("Sysname: %s\n", ptr->sysname); + free(ptr); + + return err; +} From patchwork Thu Mar 10 11:15:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bharata B Rao X-Patchwork-Id: 12776165 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 37285C433FE for ; Thu, 10 Mar 2022 11:16:26 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CAA258D0006; Thu, 10 Mar 2022 06:16:25 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id C32D98D0001; Thu, 10 Mar 2022 06:16:25 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AD3A68D0006; Thu, 10 Mar 2022 06:16:25 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0196.hostedemail.com [216.40.44.196]) by kanga.kvack.org (Postfix) with ESMTP id 9DF408D0001 for ; Thu, 10 Mar 2022 06:16:25 -0500 (EST) Received: from smtpin30.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 61B919A281 for ; Thu, 10 Mar 2022 11:16:25 +0000 (UTC) X-FDA: 79228223130.30.64D6018 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2044.outbound.protection.outlook.com [40.107.93.44]) by imf22.hostedemail.com (Postfix) with ESMTP id BF94BC001B for ; Thu, 10 Mar 2022 11:16:24 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=UjeUmMjUkHehHX7EBQbrpYsxNQhCpseYPNz2fS6BuWCSAD+e2caMrRvhTSugRT4ddwZeSt4DEr8aJE/YQ+iQ9/96v2vXx8sPq2/Zc237xbaud0rCKa7jW4ZqQwBVLyGkeoGOoLPvDdHcszMXFmcl+2WeibxS7SkAtXaQTh1F40x3R2ZJei5mN7E7CXp35hxBB58+/o73vhjVu7PegPPoZSBypDQNr6KZmR9sLO8AU09fQt0uklH56Ld9mLyfN7Y7Pqn5+XLpND91j9s5nw6fynDpAFhZ6bgWtmDabXjImypMqST9VyCvhCZpNoqMtF3XMhqtzNuUnF1RNhcV7r6omQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=irr2hZii6rdNNuY/EL2TLNU++YjSdRudQr8Tk9/mCMQ=; b=YcS3RS8CGLBCUcKztuUcd2B+tJUKIGHxymzYs87HMQWQrJFMshD5l4QaM6fcokXw5RLHhSC0r1CfLaoI4COnRAFaAf7+hBkPSuRuFleBRsO3tBn3yNKvqWkTxmsC8+KowVKvFL3fQd7jB4K2Yl715cc5ZHx6cZ7vz2TdH/e7mDOdyQeRGGLRxUZP2/Z9Z/6M3gLSDhwUo+YqDwSSLwJHodhTb608LMN9rOMTSOq615M9fie4H/nNVl6J8F32SS3vMFRl6I9gv7WNTmvGE+glxRlfsGgJoDv5CQYjxq6mmS627777i1B/5WuKHLLBKpYUODni4OWWBbQCe3zd0lt/pw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=irr2hZii6rdNNuY/EL2TLNU++YjSdRudQr8Tk9/mCMQ=; b=YJRZaocepxslC8CUaqHVPGYEfXt4m8+7/V5ADjbB8+7lf7L26Nalwm1CR6c/2WPw3GmlCq5CEqpwG6XRWav+w4xMp4XAOia5Z4WxZpV3T46OdiUjg+ybVyErG+HQ+9SxtBzRSsa6Q7i5o/TgVkN0paqjvAhazDAqUET73zr8NXY= Received: from MW4PR04CA0304.namprd04.prod.outlook.com (2603:10b6:303:82::9) by BL0PR12MB2388.namprd12.prod.outlook.com (2603:10b6:207:4a::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5061.22; Thu, 10 Mar 2022 11:16:22 +0000 Received: from CO1NAM11FT017.eop-nam11.prod.protection.outlook.com (2603:10b6:303:82:cafe::ab) by MW4PR04CA0304.outlook.office365.com (2603:10b6:303:82::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5061.22 via Frontend Transport; Thu, 10 Mar 2022 11:16:21 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; Received: from SATLEXMB04.amd.com (165.204.84.17) by CO1NAM11FT017.mail.protection.outlook.com (10.13.175.108) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5061.22 via Frontend Transport; Thu, 10 Mar 2022 11:16:21 +0000 Received: from BLR-5CG1133937.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Thu, 10 Mar 2022 05:16:15 -0600 From: Bharata B Rao To: CC: , , , , , , , , , , , , "Bharata B Rao" Subject: [RFC PATCH v0 2/6] x86/cpufeatures: Add Upper Address Ignore(UAI) as CPU feature Date: Thu, 10 Mar 2022 16:45:41 +0530 Message-ID: <20220310111545.10852-3-bharata@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220310111545.10852-1-bharata@amd.com> References: <20220310111545.10852-1-bharata@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 8ec121ed-844a-4d92-35a0-08da0287680e X-MS-TrafficTypeDiagnostic: BL0PR12MB2388:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 1hhctx1XeHMFfNbpLvvVWo3kwzZLf6VQPqTAKmNjfmfSRSk1pRcgfUaznEMq2I+64rFLbXkuvEnQI8S3AmZLUkaCKF7nFZSbQTzmMzlaThAIwcW5CM9BRI/YhPpuGyy9+V9U43ukMZs8BXi46+0VdbEhl2lDwW2Ejn6GOrKUm2guSr3IX8qD8xC4pkf72hHOtVzFuUWr/d5Jc/URs6nM2VkNicW3CjrIzc6SXsEhdQLgASU6cQEVnuajAPBZ8Q0dYwWSDoknUqfS4k9zrRfWUZpq+CN3UogFZK49cqRP1z02dOwGJTCABdq1A0I8/Rvj1HQ9IiXpkRC3ro0VazFg/DcZfu6221bJpzUXDW0zwrZ/8NkDoPnGJbNt3VH3RTlUh5Qql7CLJnK8ZPUboCuuXVkl6LlktDrQ3if1G1q0AMP5f8kIaC+S0ce2+YQdcHk81d/eM8Bfu7wIue5LxY0WdyMRvpUJmRkWHc5M+aoQHa+uhi1baeU0iMBPJad+h1KB7QO7GBb0clp3xjla7wz4fHXyLLJ2HRuDHlFlwhZjyesSV4/zC6YyUGa/UdWzFEnHsXidscmgCpCPGM7rMNN0du/5cngksfBiXhAO25VKVNBBSMWkknhkK0S1k8q5lruF2XdbqURxMaZp17fh6J43+pnITcxxmhsqMhA2a8pcaw4Bj8asR+bDjQM4zpksgBXjhui8GyUW03evSkUQ6vGEqA== X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230001)(4636009)(46966006)(40470700004)(36840700001)(356005)(81166007)(86362001)(40460700003)(1076003)(2616005)(26005)(186003)(16526019)(336012)(7696005)(83380400001)(36756003)(316002)(426003)(54906003)(6916009)(2906002)(70586007)(47076005)(6666004)(70206006)(508600001)(7416002)(5660300002)(4326008)(82310400004)(8676002)(8936002)(36860700001)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Mar 2022 11:16:21.3917 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 8ec121ed-844a-4d92-35a0-08da0287680e X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT017.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL0PR12MB2388 X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: BF94BC001B X-Stat-Signature: b4f64mkxh1ubn73zt6njwfc8mfkxyukb Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=YJRZaoce; spf=pass (imf22.hostedemail.com: domain of bharata@amd.com designates 40.107.93.44 as permitted sender) smtp.mailfrom=bharata@amd.com; dmarc=pass (policy=quarantine) header.from=amd.com X-HE-Tag: 1646910984-205639 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Currently the maximum logical address size for AMD processors in 64 bit mode is 57 bits. This means that the remaining 7 upper bits [63:57] are available for software use. With UAI feature turned ON, the processor ignores these upper bits when performing canonical check on these addresses. Add UAI as a CPU feature. Signed-off-by: Bharata B Rao --- arch/x86/include/asm/cpufeatures.h | 2 +- arch/x86/kernel/cpu/scattered.c | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/arch/x86/include/asm/cpufeatures.h b/arch/x86/include/asm/cpufeatures.h index 6db4e2932b3d..5f4e88e67feb 100644 --- a/arch/x86/include/asm/cpufeatures.h +++ b/arch/x86/include/asm/cpufeatures.h @@ -201,7 +201,7 @@ #define X86_FEATURE_INVPCID_SINGLE ( 7*32+ 7) /* Effectively INVPCID && CR4.PCIDE=1 */ #define X86_FEATURE_HW_PSTATE ( 7*32+ 8) /* AMD HW-PState */ #define X86_FEATURE_PROC_FEEDBACK ( 7*32+ 9) /* AMD ProcFeedbackInterface */ -/* FREE! ( 7*32+10) */ +#define X86_FEATURE_UAI ( 7*32+10) /* AMD Upper Address Ignore */ #define X86_FEATURE_PTI ( 7*32+11) /* Kernel Page Table Isolation enabled */ #define X86_FEATURE_RETPOLINE ( 7*32+12) /* "" Generic Retpoline mitigation for Spectre variant 2 */ #define X86_FEATURE_RETPOLINE_AMD ( 7*32+13) /* "" AMD Retpoline mitigation for Spectre variant 2 */ diff --git a/arch/x86/kernel/cpu/scattered.c b/arch/x86/kernel/cpu/scattered.c index 21d1f062895a..5c19f6f525cf 100644 --- a/arch/x86/kernel/cpu/scattered.c +++ b/arch/x86/kernel/cpu/scattered.c @@ -42,6 +42,7 @@ static const struct cpuid_bit cpuid_bits[] = { { X86_FEATURE_CPB, CPUID_EDX, 9, 0x80000007, 0 }, { X86_FEATURE_PROC_FEEDBACK, CPUID_EDX, 11, 0x80000007, 0 }, { X86_FEATURE_MBA, CPUID_EBX, 6, 0x80000008, 0 }, + { X86_FEATURE_UAI, CPUID_EAX, 7, 0x80000021, 0 }, { 0, 0, 0, 0, 0 } }; From patchwork Thu Mar 10 11:15:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bharata B Rao X-Patchwork-Id: 12776166 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 25BA9C433EF for ; Thu, 10 Mar 2022 11:16:32 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BBFAB8D0007; Thu, 10 Mar 2022 06:16:31 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id B6F498D0001; Thu, 10 Mar 2022 06:16:31 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9E98B8D0007; Thu, 10 Mar 2022 06:16:31 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0189.hostedemail.com [216.40.44.189]) by kanga.kvack.org (Postfix) with ESMTP id 8FBD88D0001 for ; Thu, 10 Mar 2022 06:16:31 -0500 (EST) Received: from smtpin19.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 35717181C9BAD for ; Thu, 10 Mar 2022 11:16:31 +0000 (UTC) X-FDA: 79228223382.19.69E3171 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2045.outbound.protection.outlook.com [40.107.243.45]) by imf20.hostedemail.com (Postfix) with ESMTP id 91DD81C001F for ; Thu, 10 Mar 2022 11:16:30 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=O9nrffsGI//KGXb3Yd8TSuQB96lE6oTBRAjGUnelNyiNJJ19d0H9CRunGZA5eWpGmebjYJkc27+CZIWawId3U2apR0crtwvYB7O7dW3n5+V5U2/XCD3bEDRypot23HMzYwx9E/9/Zllgs1lOQYcFthnUuirGEeMZunDVrM81EvxrAUzXAcqXSTk6Zhs9sa7mqjOPZgTbShphjd7MUInGsfVMyymnaMF3dkYLEgvISR9NjN6nrrkDEE+ZrUaCH8yxX+oXIsHiKu4CIy2sg2icjKWCxejq4telHJv33Vzs/0zOFoc4KonGtk+gsVtO8/Z3GVyFo/XSd8pH7X3dGJj7KA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=SudsVIi3obuN2snFXsZgYoY2KU/BgUvR8OGtpfgZI+I=; b=U8XGmIawe8vL8DufxXRJAhWKNOom25XnDMCmdTxc6uj+aw/MuJV9rqZOFUi66OSz/6+a0PM8AA753fQ1yRSo27DvQQZ0nnGz+kGK85Sh5JmDZsyM5Drm3u6Hd5BZ4k/YV3zctoSuD+ezpySB6GKEtIDlCYsq/DRRxAsAGwGOSxyGwMutYoq00JUNkniXPzM5i5vuKexFpjWV05zsOnNsbbslaKeWdvoJKbKSfBqd6laYsGu9W6V4VVwC4UBCCEFbCYcA3azyY0Esl6l3TKonKYjarWvv9A40jgCudMzn2pUiYriMOZg0RvOVhm9FWAJsqMlMT9z+2gQ2+hJC2/4Peg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=SudsVIi3obuN2snFXsZgYoY2KU/BgUvR8OGtpfgZI+I=; b=PQ2zmnzdsvSAZPRM57neB0W8wWBmJGITm+c/2SNz5BMDjQ6LlVp8KxM3YoVllrHkb5wpHnopozsLro7kf1YKiL8rDG0wZGVbsj/FY7kCbOBhlzufG2D9MiNnGNhdgAo4WKsvMg3gQR75qHixaoXX0HrHQvReG40QV1rF1zPgpWk= Received: from MW4PR04CA0066.namprd04.prod.outlook.com (2603:10b6:303:6b::11) by BL0PR12MB2820.namprd12.prod.outlook.com (2603:10b6:208:80::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5038.29; Thu, 10 Mar 2022 11:16:28 +0000 Received: from CO1NAM11FT045.eop-nam11.prod.protection.outlook.com (2603:10b6:303:6b:cafe::d2) by MW4PR04CA0066.outlook.office365.com (2603:10b6:303:6b::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5061.22 via Frontend Transport; Thu, 10 Mar 2022 11:16:27 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; Received: from SATLEXMB04.amd.com (165.204.84.17) by CO1NAM11FT045.mail.protection.outlook.com (10.13.175.181) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5038.14 via Frontend Transport; Thu, 10 Mar 2022 11:16:26 +0000 Received: from BLR-5CG1133937.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Thu, 10 Mar 2022 05:16:20 -0600 From: Bharata B Rao To: CC: , , , , , , , , , , , , "Bharata B Rao" Subject: [RFC PATCH v0 3/6] x86: Enable Upper Address Ignore(UAI) feature Date: Thu, 10 Mar 2022 16:45:42 +0530 Message-ID: <20220310111545.10852-4-bharata@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220310111545.10852-1-bharata@amd.com> References: <20220310111545.10852-1-bharata@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: f33297ab-f11a-4c4e-e3bf-08da02876b62 X-MS-TrafficTypeDiagnostic: BL0PR12MB2820:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: pgTzMtLQLEqbV+ZNMgggJCsI2DhZf12KazrmuNnKVFM0bXSRshGxq9Mu6LtVQAuKAEmPDAo6FnZ2Acq/iuXwDzDSGNH90IuJJbdY6nJ4lu0daAaIBgZNWtfOx+XuUOFPCoJ8OoWfoioxlOG3zcwDiSQCt6EhJCIGAM7k9HzBhDuuzz0VY1GTCwE7pB6wqu6SkYz3q2PN+CCgcX6OFCu/9Q8lbSqnVccX7X3QGy1JUG4HiVH6SDtbcpsUsfIljQnQYFGaz0Vcg5iEZPl+ZuQU68aCFBcP8CFw561ivQSRDXxrRT930YrN3jG6kuf0pxiRngIzwpDOzjQitpbTAEKIIV3MQiL84u3bVsrnSGpmF5JtAPGoItZGT7H8iBv05hDDNksoKObTlFu6hFboeWlcIdjOW6YJGuIJ13S4CD5HAtUsQ0j6JQSle4b4UM2pmZ8z37XOJ9U4XlGhnJxCdmzsZ9YRcApJDKzQ43wuDHDi51KBu9OQ4m90/ZuO+o73fNgxJDh1cBpijgh70unaPPTNX1ajz/NwJNp6Sgtv9wX333FhsWoCGaQhY7JmJLLIDjx5HigXb5ExMSFgWyPzhF199k62KeBSQWePD+thT2OFoJ4sjb9jdICAlf4ZIa1iqL8MoGQWfnYk7Opjr/HFgVS+jdqk9ELsCKwHqbnTL96KVZZK+ADo+8YtB4kJlTvPFDR61zgAmhC2GJXyBYBhVVLhSA== X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230001)(4636009)(36840700001)(46966006)(40470700004)(356005)(2616005)(6666004)(47076005)(81166007)(1076003)(8936002)(82310400004)(83380400001)(7416002)(5660300002)(8676002)(70206006)(70586007)(2906002)(316002)(4326008)(40460700003)(36860700001)(6916009)(7696005)(86362001)(36756003)(16526019)(26005)(54906003)(508600001)(426003)(336012)(186003)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Mar 2022 11:16:26.9955 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: f33297ab-f11a-4c4e-e3bf-08da02876b62 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT045.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL0PR12MB2820 X-Rspamd-Queue-Id: 91DD81C001F X-Stat-Signature: yiyh7jmn1mkgud4hz3aby1a6un74ony1 X-Rspam-User: Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=PQ2zmnzd; dmarc=pass (policy=quarantine) header.from=amd.com; spf=pass (imf20.hostedemail.com: domain of bharata@amd.com designates 40.107.243.45 as permitted sender) smtp.mailfrom=bharata@amd.com X-Rspamd-Server: rspam03 X-HE-Tag: 1646910990-146126 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: UAI feature is enabled by setting bit 20 in EFER MSR. Signed-off-by: Bharata B Rao --- arch/x86/include/asm/msr-index.h | 2 ++ arch/x86/kernel/setup.c | 8 ++++++++ 2 files changed, 10 insertions(+) diff --git a/arch/x86/include/asm/msr-index.h b/arch/x86/include/asm/msr-index.h index a4a39c3e0f19..ce763952278f 100644 --- a/arch/x86/include/asm/msr-index.h +++ b/arch/x86/include/asm/msr-index.h @@ -30,6 +30,7 @@ #define _EFER_SVME 12 /* Enable virtualization */ #define _EFER_LMSLE 13 /* Long Mode Segment Limit Enable */ #define _EFER_FFXSR 14 /* Enable Fast FXSAVE/FXRSTOR */ +#define _EFER_UAI 20 /* Enable Upper Address Ignore */ #define EFER_SCE (1<<_EFER_SCE) #define EFER_LME (1<<_EFER_LME) @@ -38,6 +39,7 @@ #define EFER_SVME (1<<_EFER_SVME) #define EFER_LMSLE (1<<_EFER_LMSLE) #define EFER_FFXSR (1<<_EFER_FFXSR) +#define EFER_UAI (1<<_EFER_UAI) /* Intel MSRs. Some also available on other CPUs */ diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c index f7a132eb794d..12615b1b4af5 100644 --- a/arch/x86/kernel/setup.c +++ b/arch/x86/kernel/setup.c @@ -740,6 +740,12 @@ dump_kernel_offset(struct notifier_block *self, unsigned long v, void *p) return 0; } +static inline void __init uai_enable(void) +{ + if (boot_cpu_has(X86_FEATURE_UAI)) + msr_set_bit(MSR_EFER, _EFER_UAI); +} + /* * Determine if we were loaded by an EFI loader. If so, then we have also been * passed the efi memmap, systab, etc., so we should use these data structures @@ -1146,6 +1152,8 @@ void __init setup_arch(char **cmdline_p) x86_init.paging.pagetable_init(); + uai_enable(); + kasan_init(); /* From patchwork Thu Mar 10 11:15:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bharata B Rao X-Patchwork-Id: 12776167 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id E6108C433EF for ; Thu, 10 Mar 2022 11:16:38 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 864178D0008; Thu, 10 Mar 2022 06:16:38 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 7ECA78D0001; Thu, 10 Mar 2022 06:16:38 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 68CF78D0008; Thu, 10 Mar 2022 06:16:38 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0066.hostedemail.com [216.40.44.66]) by kanga.kvack.org (Postfix) with ESMTP id 5B23C8D0001 for ; Thu, 10 Mar 2022 06:16:38 -0500 (EST) Received: from smtpin26.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 102578249980 for ; Thu, 10 Mar 2022 11:16:38 +0000 (UTC) X-FDA: 79228223676.26.3445CC7 Received: from NAM02-BN1-obe.outbound.protection.outlook.com (mail-bn1nam07on2070.outbound.protection.outlook.com [40.107.212.70]) by imf17.hostedemail.com (Postfix) with ESMTP id 710AC4001D for ; Thu, 10 Mar 2022 11:16:37 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=TZ0eQYGlCBLRC2bjhHg69PnXEBYHNwu/AGtTtiSt3iCraKZFv6xn2Kvp8raGkkbM2wQZTZvxmlTgZ3J+RHLVLtUU6/MH6+WcaaMCqNmqPah18yfAZXaRQfNAFhKj8tIWvfundWu3yAF9Q10D7hwuPW/Jc0+Q3Pu+GPXSVjEYqV9sDm/gXp2JKh5M72las9+JOs9Q3vtcbloiKVywxmudjQ1d3d1CLJ14dd1NxnQ9KvzMjJ5zk/g5salUZq7KR58omVmHBgYuiSdGgTfXNbgUOeWH9x5sc9sGozok1UcOwlX8WlReeNh6dtmbHrPfsFyKXSOc9uQXybOTVNPyjwvC+g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=HYLRfgxtKoZIiXg2eWMGLkEDmmehjVWD4/SeCQnWfcU=; b=d5btnERBnD3CLF0IDBUu5p3UkTGQTtTzTQPS12kXDmXMs0/DXO6MOqpZ7i1cgv0gxRmCZTqsqN37VJg/AjrJO9p0MtD9nC0wW6Qb46UbHt8Q6a41L2LlQPjF04tSQcKHmkJOH5fmSRkiL5aC+E51vU9/sufG2t33j9eRo/J8XSUfIUQvBD0C/oxZ1Kt0I9gWzSBAMWmCVp8U+R2uGyLrVX/N5BAZgDm/VTwAomFRzt2OnV4PSsHKzSnhtWXEyEnrONxWbSeAPDW8CYEdAtbAxN0f6rM1c31vGWYRyjinbG9sM6/17aWTLbaJsKMzTZ2QaCAGyCxvNvWXAiGgpaQ4pA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=HYLRfgxtKoZIiXg2eWMGLkEDmmehjVWD4/SeCQnWfcU=; b=tTaad1dlBuAjS0CB5PUrNsYPvbKhuW+Q3t+daGogC4aVSpmFazZtrhUOPmMc+fuRKPpzFruvITQjy+CofUYRc7atcjwL1NzCQ+659qzROR4mvQj2NO6CP4orL1TTW2h13ndN+ZLs6P8n3lukTxAX5P7Gp0ho1uFxNFLXwM7CeMY= Received: from MW4PR04CA0170.namprd04.prod.outlook.com (2603:10b6:303:85::25) by MWHPR1201MB0157.namprd12.prod.outlook.com (2603:10b6:301:55::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5038.17; Thu, 10 Mar 2022 11:16:34 +0000 Received: from CO1NAM11FT033.eop-nam11.prod.protection.outlook.com (2603:10b6:303:85:cafe::ee) by MW4PR04CA0170.outlook.office365.com (2603:10b6:303:85::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5061.20 via Frontend Transport; Thu, 10 Mar 2022 11:16:34 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; Received: from SATLEXMB04.amd.com (165.204.84.17) by CO1NAM11FT033.mail.protection.outlook.com (10.13.174.247) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5061.22 via Frontend Transport; Thu, 10 Mar 2022 11:16:34 +0000 Received: from BLR-5CG1133937.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Thu, 10 Mar 2022 05:16:26 -0600 From: Bharata B Rao To: CC: , , , , , , , , , , , , "Bharata B Rao" Subject: [RFC PATCH v0 4/6] x86: Provide an implementation of untagged_addr() Date: Thu, 10 Mar 2022 16:45:43 +0530 Message-ID: <20220310111545.10852-5-bharata@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220310111545.10852-1-bharata@amd.com> References: <20220310111545.10852-1-bharata@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: e35e95ad-af4b-429d-3d30-08da02876f90 X-MS-TrafficTypeDiagnostic: MWHPR1201MB0157:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Ve9KRyIQnSjG675v3UcG5cQU2a6JcX7T/qqrWtpyxX6d62atj2wK6aXOTYxBulZcT1PtyqMgLAGSAThjwEh6ikZH2eV6/S2dN08BhmoaipiZ0gCGFGHsjBxgJqGu/kcssqXUrevOALrTiR+sdgeX+P5mhRppzsGwFL6bHLrtmOGTMIZ1RScjlZOH6qingVVJMxQZgfMR8CzVr87CLud6sEf1zj5dW4TTrMi7Ikx3Uo92MNeozGqi/LAeplqNsJvrMjtk2RoGp/2VFj3BEGuE1+dyp9xXeoHDtn9Adj0dvKPxeltXZruq8TeLsoQ0qspaxR52qaqdqmVsPRwyFA4fIq9rOdhERsBv4SNke2Q997M9vAdWUleNi7rNXydbq90WrVg41KZmN/XwOIEuZG8nWgFcrFVZUjcLdS58zmuw9bheXCPFTRVkdSddd9V+dA+cAs6s0gwhIolgmMUGFWrhktdVVW/cDxtjsxofp7okGiC5eOxtCxivk+IOmCoOGecy3xAND4lkk+VJ8QGdlM4gJfupmaX1N4qL6onhl4YX8+F9Vl8ssKwkEgV/6Z29mUkAuAK0tzuHlHeUdAxwxJjHUMhX5H4MTdn48d3jMOJp0fqNxmB90CLQPBCxOOVTbafQwYoLYHQsJ5HvMXQkUBK3/my6KGAF7KxQv79M6vmPa3dwTIwXlbFZsfrObsEm50xALSwuTdYD3TSCCbjKKwAKFw== X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230001)(4636009)(46966006)(36840700001)(40470700004)(316002)(2616005)(426003)(336012)(186003)(81166007)(16526019)(26005)(1076003)(36860700001)(83380400001)(86362001)(356005)(40460700003)(47076005)(82310400004)(6916009)(54906003)(36756003)(2906002)(5660300002)(7416002)(8936002)(70586007)(70206006)(4326008)(8676002)(7696005)(6666004)(508600001)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Mar 2022 11:16:34.0035 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: e35e95ad-af4b-429d-3d30-08da02876f90 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT033.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR1201MB0157 X-Rspamd-Queue-Id: 710AC4001D X-Stat-Signature: us8gbgfspzwap6uhb7f3b7bot8drfcbg X-Rspam-User: Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=tTaad1dl; spf=pass (imf17.hostedemail.com: domain of bharata@amd.com designates 40.107.212.70 as permitted sender) smtp.mailfrom=bharata@amd.com; dmarc=pass (policy=quarantine) header.from=amd.com X-Rspamd-Server: rspam07 X-HE-Tag: 1646910997-244375 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: untagged_addr() will be used by core mm routines to remove the tag bits and convert the address to canonical form. Limit the implementation to AMD CPUs as Intel's version of the same is likely to be different. Signed-off-by: Bharata B Rao --- arch/x86/include/asm/page_32.h | 3 +++ arch/x86/include/asm/page_64.h | 26 ++++++++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/arch/x86/include/asm/page_32.h b/arch/x86/include/asm/page_32.h index df42f8aa99e4..8309aa987354 100644 --- a/arch/x86/include/asm/page_32.h +++ b/arch/x86/include/asm/page_32.h @@ -30,6 +30,9 @@ static inline void copy_page(void *to, void *from) { memcpy(to, from, PAGE_SIZE); } + +#define untagged_addr(addr) (addr) +#define untagged_ptr(ptr) (ptr) #endif /* !__ASSEMBLY__ */ #endif /* _ASM_X86_PAGE_32_H */ diff --git a/arch/x86/include/asm/page_64.h b/arch/x86/include/asm/page_64.h index e9c86299b835..41d4a729e783 100644 --- a/arch/x86/include/asm/page_64.h +++ b/arch/x86/include/asm/page_64.h @@ -90,6 +90,32 @@ static __always_inline unsigned long task_size_max(void) } #endif /* CONFIG_X86_5LEVEL */ +#ifdef CONFIG_CPU_SUP_AMD +/* + * Tag bits are in same position [63:57] for both 4 and 5 level page + * tables. For both the cases we sign-extend from 56th bit since + * bits [56:48] are anyway expected to be canonical for 4 level page tables. + */ +#define __untagged_addr(addr) \ + ((__force __typeof__(addr))sign_extend64((__force u64)(addr), 56)) + +#define untagged_addr(addr) ({ \ + u64 __addr = (__force u64)(addr); \ + __addr &= __untagged_addr(__addr); \ + (__force __typeof__(addr))__addr; \ +}) + +#define untagged_ptr(ptr) ({ \ + u64 __ptrval = (__force u64)(ptr); \ + __ptrval = untagged_addr(__ptrval); \ + (__force __typeof__(*(ptr)) *)__ptrval; \ +}) + +#else +#define untagged_addr(addr) (addr) +#define untagged_ptr(ptr) (ptr) +#endif + #endif /* !__ASSEMBLY__ */ #ifdef CONFIG_X86_VSYSCALL_EMULATION From patchwork Thu Mar 10 11:15:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bharata B Rao X-Patchwork-Id: 12776168 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id EF0F2C433F5 for ; Thu, 10 Mar 2022 11:16:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8DA858D0009; Thu, 10 Mar 2022 06:16:45 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 887F88D0001; Thu, 10 Mar 2022 06:16:45 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 729048D0009; Thu, 10 Mar 2022 06:16:45 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0088.hostedemail.com [216.40.44.88]) by kanga.kvack.org (Postfix) with ESMTP id 63BD38D0001 for ; Thu, 10 Mar 2022 06:16:45 -0500 (EST) Received: from smtpin28.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 1C4B0181C9B9B for ; Thu, 10 Mar 2022 11:16:45 +0000 (UTC) X-FDA: 79228223970.28.70233FB Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2053.outbound.protection.outlook.com [40.107.220.53]) by imf19.hostedemail.com (Postfix) with ESMTP id 0CF671A000D for ; Thu, 10 Mar 2022 11:16:43 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=H0nCF/A7I5jQ8QB2lWFo/0ujvV4WkIQcMKSVkbwtiUIaWAKBq85WGqWsFu6M2LyR84ii3WkYqjOQZc+I3OxdrzCN9X+MHcXHL+bzAcUqMoCaTAgha8BxMHa/c5iT8kWKR28dFhg/yM26ZW2/1PLwkoYmnsFcJfMqGfLX78Gx3DSNJZuyW2FcvOUzu/ZCa2ZuX9VF0rdzPSBS2U77I5sQfpYcfwNGBkB+FIMIjg969zC3gl32IItkJhs+38p7urRZyvEo6ddZQfKy/DH/H2wy49DIEM6vWQ+73oy7asdwGUge8yWftpcSgXFAZO00VUzdTnamPiTPqCpj1jKmDQ+K1w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=cFWi1O1bzOqLyHFf0gT/BNjKx4Kjm5hsOsFAWydQRTY=; b=gylIzh6QbxyzDBXpNnyx93xDmmMl7hLJYWN6nRsSRjjzCeeszm7E10vLHyCEBm632x3yPIPNZjoFiAP+GrdjRtdsc+yMAZvNpmHJDa2FrR43OQNaYwIiSq0BxZiPLejknbFdAnoXf191OKsTijdLIArmcDTVW8naL31ZeniibqMHv35BgKYRF7KkBk3+6DgVSzelYSuFafeJrU9KXvHB/Qp3tvJAWKMlVDlbpYle85APyBbGPnZ3Z3JO7yiNPitGKDsqhMw7NF7yLKCOW6R8GXMuH4biUk1EbX4ZNWuoFkKd8bCq3xWkTvlg16iBZKBqwANIMW1fTPmBhhKLcwWqGQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=cFWi1O1bzOqLyHFf0gT/BNjKx4Kjm5hsOsFAWydQRTY=; b=ExzsUtUnwbj6c1RhgZrjtL8P3Bi4zFtIAoujK6eie3zcNJxdehhhyt9I61/41uSTDVExTVOo82NdenSGhaCEw+w68sTx82EpIzEA3Z6MAolH8+Ovp2DZfCjvDOjkOOJa2eEayvrhhEVQVxGIJOCQCA7fvceDilDy1WZ5Y84yR+M= Received: from CO2PR04CA0160.namprd04.prod.outlook.com (2603:10b6:104:4::14) by BL1PR12MB5947.namprd12.prod.outlook.com (2603:10b6:208:39a::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5038.14; Thu, 10 Mar 2022 11:16:40 +0000 Received: from CO1NAM11FT060.eop-nam11.prod.protection.outlook.com (2603:10b6:104:4:cafe::35) by CO2PR04CA0160.outlook.office365.com (2603:10b6:104:4::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5038.27 via Frontend Transport; Thu, 10 Mar 2022 11:16:39 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; Received: from SATLEXMB04.amd.com (165.204.84.17) by CO1NAM11FT060.mail.protection.outlook.com (10.13.175.132) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5061.22 via Frontend Transport; Thu, 10 Mar 2022 11:16:39 +0000 Received: from BLR-5CG1133937.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Thu, 10 Mar 2022 05:16:32 -0600 From: Bharata B Rao To: CC: , , , , , , , , , , , , "Bharata B Rao" Subject: [RFC PATCH v0 5/6] x86: Untag user pointers in access_ok() Date: Thu, 10 Mar 2022 16:45:44 +0530 Message-ID: <20220310111545.10852-6-bharata@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220310111545.10852-1-bharata@amd.com> References: <20220310111545.10852-1-bharata@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 1f876cfd-bbff-4382-72cf-08da028772b4 X-MS-TrafficTypeDiagnostic: BL1PR12MB5947:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: XTiV/uuAyzcyclK7GVgNwlU8GXrY0qAGoOGSQ5f/LBiG8l8PBLRyYMEZK4OgWoshXOsANYvAhvYR2+OfxAm2k6/Ke8up45waJsnriJDxZEsPAe2t6RVywbR7/digxvrPK/9uuDvoT7sAe27dpGyClgiHwqflMRlKhhyuZNSRKvdQ2uC1Jjs3ZTyCPFMSmgOSV4OvF9PSMaP30bX3zboMvAhhAFygRRO4Rigu7d27d9u1x/bOoB27iyVwntVasDimywqyxIpdkjL13ULZsbs5TRQV6Ap2Aas81f/g7jkg4gPOFZcz5uefrgdsLyU2+0z1Lp5dfuWyPriOzLLEr6MDutK8xuW2/EV7Z64RgCdU4+KM2R9C59Y4iKDb8KPiOuBd6+OOFGVAJ1Iq+zcG7ZaUfVM4rdwms/rluGI9RgWA8z4XxQfF7xuXI4VpmUc2hiEbyz1a0wGBDdDEEc6nrU0L8ionyMYife/5R3hBmEiE3Nl8SJ5KmZScnTRs+bXCDefAojT8clVBp7CRkY8dSQCFgVxfQNh3vMxAouY45LDgLb+Oi+GshFZwnZXSFL5M8k/yl0JzZ2tFO972pa+SA3a6jZbqfP48trxMMBY6My3ujt8GGfLYRXLa1sJ7SnCaQCrRIU2g2y7ZdG6lQFqGjUxCai3SX3BgC/9vkUAszq1d9eM8t9ne47XvGHJngVSypKQjilECZLZ8Zl4Gh1WSnIJn3w== X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230001)(4636009)(36840700001)(46966006)(40470700004)(70586007)(2906002)(70206006)(8676002)(4326008)(82310400004)(356005)(81166007)(54906003)(40460700003)(6916009)(8936002)(5660300002)(7416002)(47076005)(7696005)(508600001)(36860700001)(316002)(86362001)(16526019)(186003)(26005)(36756003)(426003)(336012)(83380400001)(1076003)(6666004)(2616005)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Mar 2022 11:16:39.2740 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 1f876cfd-bbff-4382-72cf-08da028772b4 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT060.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL1PR12MB5947 X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 0CF671A000D X-Stat-Signature: eb3u851nn1mqxyt33ah33uezg1qy8qq3 Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=ExzsUtUn; spf=pass (imf19.hostedemail.com: domain of bharata@amd.com designates 40.107.220.53 as permitted sender) smtp.mailfrom=bharata@amd.com; dmarc=pass (policy=quarantine) header.from=amd.com X-HE-Tag: 1646911003-138282 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: This is a preparatory work to allow passing of tagged user pointers (with a top few bits other than zeroes) as syscall arguments. Since user can provide tagged pointer to syscalls they need to be untagged before validating them in access_ok(). Untagging is done only if flag TIF_TAGGED_ADDR is set for the thread. This is set via prctl() option which will be introduced in a subsequent patch. get_user() and put_user() don't use access_ok(), but check access against TASK_SIZE direcly in assembly. Strip tags, before calling into the assembly helper. [kirill.shutemov@linux.intel.com - get/put_user() changes] Signed-off-by: Bharata B Rao --- arch/x86/include/asm/thread_info.h | 2 ++ arch/x86/include/asm/uaccess.h | 28 +++++++++++++++++++++------- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h index ebec69c35e95..c786103a5325 100644 --- a/arch/x86/include/asm/thread_info.h +++ b/arch/x86/include/asm/thread_info.h @@ -101,6 +101,7 @@ struct thread_info { #define TIF_BLOCKSTEP 25 /* set when we want DEBUGCTLMSR_BTF */ #define TIF_LAZY_MMU_UPDATES 27 /* task is updating the mmu lazily */ #define TIF_ADDR32 29 /* 32-bit address space on 64 bits */ +#define TIF_TAGGED_ADDR 30 /* Allow tagged user addresses */ #define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME) #define _TIF_SIGPENDING (1 << TIF_SIGPENDING) @@ -124,6 +125,7 @@ struct thread_info { #define _TIF_BLOCKSTEP (1 << TIF_BLOCKSTEP) #define _TIF_LAZY_MMU_UPDATES (1 << TIF_LAZY_MMU_UPDATES) #define _TIF_ADDR32 (1 << TIF_ADDR32) +#define _TIF_TAGGED_ADDR (1 << TIF_TAGGED_ADDR) /* flags to check in __switch_to() */ #define _TIF_WORK_CTXSW_BASE \ diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h index ac96f9b2d64b..feb2e21c7e09 100644 --- a/arch/x86/include/asm/uaccess.h +++ b/arch/x86/include/asm/uaccess.h @@ -35,11 +35,15 @@ static inline bool __chk_range_not_ok(unsigned long addr, unsigned long size, un return unlikely(addr > limit); } -#define __range_not_ok(addr, size, limit) \ -({ \ - __chk_user_ptr(addr); \ - __chk_range_not_ok((unsigned long __force)(addr), size, limit); \ -}) +static inline bool __range_not_ok(const void __user *addr, unsigned long size, + unsigned long limit) +{ + if (test_thread_flag(TIF_TAGGED_ADDR)) + addr = untagged_addr(addr); + + __chk_user_ptr(addr); + return __chk_range_not_ok((unsigned long __force)(addr), size, limit); +} #ifdef CONFIG_DEBUG_ATOMIC_SLEEP static inline bool pagefault_disabled(void); @@ -152,7 +156,12 @@ extern int __get_user_bad(void); * Return: zero on success, or -EFAULT on error. * On error, the variable @x is set to zero. */ -#define get_user(x,ptr) ({ might_fault(); do_get_user_call(get_user,x,ptr); }) +#define get_user(x,ptr) \ +({ \ + __typeof__(*(ptr)) *ptr_untagged = untagged_ptr(ptr); \ + might_fault(); \ + do_get_user_call(get_user,x,ptr_untagged); \ +}) /** * __get_user - Get a simple variable from user space, with less checking. @@ -249,7 +258,12 @@ extern void __put_user_nocheck_8(void); * * Return: zero on success, or -EFAULT on error. */ -#define put_user(x, ptr) ({ might_fault(); do_put_user_call(put_user,x,ptr); }) +#define put_user(x, ptr) \ +({ \ + __typeof__(*(ptr)) *ptr_untagged = untagged_ptr(ptr); \ + might_fault(); \ + do_put_user_call(put_user,x,ptr_untagged); \ +}) /** * __put_user - Write a simple value into user space, with less checking. From patchwork Thu Mar 10 11:15:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bharata B Rao X-Patchwork-Id: 12776169 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5B514C433EF for ; Thu, 10 Mar 2022 11:16:49 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id ECCB98D000A; Thu, 10 Mar 2022 06:16:48 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id E54B18D0001; Thu, 10 Mar 2022 06:16:48 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CCEF58D000A; Thu, 10 Mar 2022 06:16:48 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0245.hostedemail.com [216.40.44.245]) by kanga.kvack.org (Postfix) with ESMTP id BC4F38D0001 for ; Thu, 10 Mar 2022 06:16:48 -0500 (EST) Received: from smtpin24.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 68BDA96F23 for ; Thu, 10 Mar 2022 11:16:48 +0000 (UTC) X-FDA: 79228224096.24.771F131 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2052.outbound.protection.outlook.com [40.107.94.52]) by imf26.hostedemail.com (Postfix) with ESMTP id C1CF7140011 for ; Thu, 10 Mar 2022 11:16:47 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=AdS0rd7JEURGAQWdz8jzvqalPkzITeIhmceeHkuyyEn1zAj6MzFaVWZrqOAqXDi5+M6PdvROzhXMeWwoE12TrDtr5Q541uCg0acY2pDiwg6XTxEF5OrttMeZ+D1n/n3CqkZyh5Ga/orb/DDPFlqB9mz/0YAXNcNHQnEfrTQvkK/lZfZFkVUyhIqE2ZTUOfLJ5KBtEqX55ehyelTyvm7S+CTqA+7XdDe/L+yJNOHc8Cin05+HMtlaW1U5eDtl2Psq85wd0cNWcLCLyhyGmK1RdTtjrTkZ6cQldFfnIYwco+PvS4CNtuGPtL3HSxByPNXk/vgzOmYAe84vEGmjftpcNA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=4rfYUlsXYPJNu5slNzpLm+592cDa0WcESV4Wg5wtHZk=; b=MYKORmd6FmRA2MejJGvfKhKPGrS3/ev3s3axqWclFO4N2Sazz8HCmmwSBS2XNLe9DG/uKJMkIB2EcxXjY0ck/DxkL6hlruGDCkQljHcn33jlySPIm+zS1Q4w+YRO5mY1UGosxlQaeWYZIWxrmz8TiqYHlhbIy1LjulhSRlxwTu4syU2ukpnz+it7/hUo2j3LZTDU/x2lJPcdl2SoNJh73e9wlYc+ZFlnFyGcQPrZbEaE5nXv5OFTHbAYhV3TtBABszS0LMjoGrBvBppGIlWfTvb8UtbJ9WwG5SK996U1qNvEKdmSyoS95CpOeeUBMUbtaboUlMQNUBqRBM2gkKZc+Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=4rfYUlsXYPJNu5slNzpLm+592cDa0WcESV4Wg5wtHZk=; b=qtKqSnBDTLa22tagngmj0PRNplB/2FPofd0RTA2GLuKVcP7vdi7zBCpMTLEHEBNx48sq+sctOgoMvQUiFTL9mngQowIsz/z/ydSRK9LMQyvcX66CD1d6o+IDRHXIjcfhDpNGUMRSDeUcaIicVum4f6Zue2+CTY5VzZxwu90xnxM= Received: from MW4PR03CA0114.namprd03.prod.outlook.com (2603:10b6:303:b7::29) by DM6PR12MB3643.namprd12.prod.outlook.com (2603:10b6:5:3d::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5038.15; Thu, 10 Mar 2022 11:16:45 +0000 Received: from CO1NAM11FT046.eop-nam11.prod.protection.outlook.com (2603:10b6:303:b7:cafe::bc) by MW4PR03CA0114.outlook.office365.com (2603:10b6:303:b7::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5038.14 via Frontend Transport; Thu, 10 Mar 2022 11:16:45 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; Received: from SATLEXMB04.amd.com (165.204.84.17) by CO1NAM11FT046.mail.protection.outlook.com (10.13.174.203) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5061.22 via Frontend Transport; Thu, 10 Mar 2022 11:16:44 +0000 Received: from BLR-5CG1133937.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Thu, 10 Mar 2022 05:16:38 -0600 From: Bharata B Rao To: CC: , , , , , , , , , , , , "Bharata B Rao" Subject: [RFC PATCH v0 6/6] x86: Add prctl() options to control tagged user addresses ABI Date: Thu, 10 Mar 2022 16:45:45 +0530 Message-ID: <20220310111545.10852-7-bharata@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220310111545.10852-1-bharata@amd.com> References: <20220310111545.10852-1-bharata@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 54ad381d-831f-48d6-562f-08da028775d8 X-MS-TrafficTypeDiagnostic: DM6PR12MB3643:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: kbcvRvV/lmgpXlu27R1XgpN84sc7HI3qrJYbNg30Ht35PJ8A7rf7i+OnKrVtoMxtV13gqtLpxeJGqrbzWg+ApeD+RwVKeplD4ypIFvVCa6Np1WRcgwUjbG0gLrWIGrADxq7KfSkKC60DLTlRVBqV1tujOjunRUlmc8ofbSRHAXzyU6TBUJYsfppexRwvQFgHztz6o7fjLLzmvZ0ixnaezRbY9yv8IMLdLKxUnvww7oZZioRerF80kuVV1xppLpCwDznAklKdA848s3MMBGt3XfAa0fz3UQgM7xF2uXofMEI4b/6mfbzoT2QpHb6g4F9Sn9HnrD/7sw0c1gkVuxK+2QZ+JXabYjQZjTxWnCBMzkbPb2scfG+2YFg/PrJotyjFNrHh75uXUWgkvnNP1fsp6JNKWuIP4yW9j5iqoVwg9YFErf0RAtcGfoicBSOfVW9gTDw/M8zi/D6OpmTKN3piWzgoTxhQda5gqYF1b0cOzcWJmpOWP2KbGUXwsM/DvFL0kZeDWp4U6YcU5KHNdKhvgWSgcsKCDXRdu28GA/huuURULJwNhDyhYASPqhQ4+tonoTnpIt4n83bar+XvCNR8uguDVpLae1BR1lxcv8nG198imbURcCSbD0BjC7ToZnrqHx8GH4+zpQX/WF3VuljEZzCJXD8J/V8Rvszv0jy3iRkb0kTHiljSsNBhNOIcjmIrfy7ZB/wOCpYMmIstDk3Cdg== X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230001)(4636009)(40470700004)(36840700001)(46966006)(6916009)(81166007)(426003)(54906003)(1076003)(70206006)(8676002)(5660300002)(70586007)(356005)(2906002)(40460700003)(83380400001)(316002)(47076005)(36756003)(2616005)(336012)(7416002)(86362001)(16526019)(26005)(82310400004)(8936002)(186003)(4326008)(7696005)(6666004)(508600001)(36860700001)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Mar 2022 11:16:44.5424 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 54ad381d-831f-48d6-562f-08da028775d8 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT046.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB3643 X-Rspamd-Queue-Id: C1CF7140011 X-Stat-Signature: x9ocfec97akpi8454n6ngue1ekkjeg33 X-Rspam-User: Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=qtKqSnBD; spf=pass (imf26.hostedemail.com: domain of bharata@amd.com designates 40.107.94.52 as permitted sender) smtp.mailfrom=bharata@amd.com; dmarc=pass (policy=quarantine) header.from=amd.com X-Rspamd-Server: rspam07 X-HE-Tag: 1646911007-620012 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Provide an option for applications to opt-in for a relaxed tagged ABI via prtcl(). This allows them to pass tagged addresses to syscalls as pointer arguments. The implementation is kept separate for AMD UAI as the equivalent implementation for Intel LAM is likely to be different. Signed-off-by: Bharata B Rao --- arch/x86/Kconfig | 9 +++ arch/x86/include/asm/processor.h | 12 +++ arch/x86/include/asm/uaccess.h | 3 +- arch/x86/kernel/process.c | 134 +++++++++++++++++++++++++++++++ 4 files changed, 157 insertions(+), 1 deletion(-) diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig index 9f5bd41bf660..b73414eb1c01 100644 --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig @@ -2436,6 +2436,15 @@ config STRICT_SIGALTSTACK_SIZE source "kernel/livepatch/Kconfig" +config X86_TAGGED_ADDR_ABI + bool "Enable the tagged user addresses syscall ABI" + depends on X86_64 && CPU_SUP_AMD + default y + help + When this option is enabled, user applications can opt-in to a + relaxed ABI via prctl() allowing tagged addresses to be passed + to system calls as pointer arguments. + endmenu config ARCH_HAS_ADD_PAGES diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h index 2c5f12ae7d04..414e2c039c34 100644 --- a/arch/x86/include/asm/processor.h +++ b/arch/x86/include/asm/processor.h @@ -863,4 +863,16 @@ bool arch_is_platform_page(u64 paddr); #define arch_is_platform_page arch_is_platform_page #endif +#ifdef CONFIG_X86_TAGGED_ADDR_ABI +/* PR_{SET,GET}_TAGGED_ADDR_CTRL prctl */ +long set_tagged_addr_ctrl(struct task_struct *task, unsigned long flags, + int __user *nr_bits, int __user *offset); +long get_tagged_addr_ctrl(struct task_struct *task, + int __user *nr_bits, int __user *offset); +#define SET_TAGGED_ADDR_CTRL(flags, nr_bits, offset) \ + set_tagged_addr_ctrl(current, flags, nr_bits, offset) +#define GET_TAGGED_ADDR_CTRL(nr_bits, offset) \ + get_tagged_addr_ctrl(current, nr_bits, offset) +#endif + #endif /* _ASM_X86_PROCESSOR_H */ diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h index feb2e21c7e09..e415523dc425 100644 --- a/arch/x86/include/asm/uaccess.h +++ b/arch/x86/include/asm/uaccess.h @@ -38,7 +38,8 @@ static inline bool __chk_range_not_ok(unsigned long addr, unsigned long size, un static inline bool __range_not_ok(const void __user *addr, unsigned long size, unsigned long limit) { - if (test_thread_flag(TIF_TAGGED_ADDR)) + if (IS_ENABLED(CONFIG_X86_TAGGED_ADDR_ABI) && + (current->flags & PF_KTHREAD || test_thread_flag(TIF_TAGGED_ADDR))) addr = untagged_addr(addr); __chk_user_ptr(addr); diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c index 81d8ef036637..2bc44efdd994 100644 --- a/arch/x86/kernel/process.c +++ b/arch/x86/kernel/process.c @@ -26,6 +26,7 @@ #include #include #include +#include #include #include #include @@ -231,6 +232,12 @@ static void pkru_flush_thread(void) pkru_write_default(); } +static void flush_tagged_addr_state(void) +{ + if (IS_ENABLED(CONFIG_X86_TAGGED_ADDR_ABI)) + clear_thread_flag(TIF_TAGGED_ADDR); +} + void flush_thread(void) { struct task_struct *tsk = current; @@ -240,6 +247,7 @@ void flush_thread(void) fpu_flush_thread(); pkru_flush_thread(); + flush_tagged_addr_state(); } void disable_TSC(void) @@ -1000,3 +1008,129 @@ long do_arch_prctl_common(struct task_struct *task, int option, return -EINVAL; } + +#ifdef CONFIG_X86_TAGGED_ADDR_ABI +/* + * Control the relaxed ABI allowing tagged user addresses into the kernel. + */ +static unsigned int tagged_addr_disabled; + +#ifdef CONFIG_CPU_SUP_AMD +#define UAI_TAG_BITS 7 + +static long amd_set_tagged_addr_ctrl(unsigned long flags, int __user *nr_bits, + int __user *offset) +{ + int val; + + if (!boot_cpu_has(X86_FEATURE_UAI)) + return -EINVAL; + + /* Disable tagging */ + if (!(flags & PR_TAGGED_ADDR_ENABLE)) { + clear_thread_flag(TIF_TAGGED_ADDR); + return 0; + } + + if (!nr_bits || !offset) + return -EINVAL; + + /* + * Do not allow the enabling of the tagged address ABI if globally + * disabled via sysctl abi.tagged_addr_disabled. + */ + if (tagged_addr_disabled) + return -EINVAL; + + if (get_user(val, nr_bits)) + return -EFAULT; + + if (val != UAI_TAG_BITS) + return -EINVAL; + + if (put_user(val, nr_bits) || put_user(64 - val, offset)) + return -EFAULT; + + set_thread_flag(TIF_TAGGED_ADDR); + return 0; +} + +static long amd_get_tagged_addr_ctrl(int __user *nr_bits, int __user *offset) +{ + long ret = 0; + + if (!boot_cpu_has(X86_FEATURE_UAI)) + return -EINVAL; + + if (test_thread_flag(TIF_TAGGED_ADDR)) { + if (nr_bits && put_user(UAI_TAG_BITS, nr_bits)) + return -EFAULT; + if (offset && put_user(64 - UAI_TAG_BITS, offset)) + return -EFAULT; + ret = PR_TAGGED_ADDR_ENABLE; + } else { + /* Report max tag size */ + if (nr_bits && put_user(UAI_TAG_BITS, nr_bits)) + return -EFAULT; + } + return ret; +} +#endif + +long set_tagged_addr_ctrl(struct task_struct *task, unsigned long flags, + int __user *nr_bits, int __user *offset) +{ + unsigned long valid_mask = PR_TAGGED_ADDR_ENABLE; + + if (in_32bit_syscall()) + return -EINVAL; + + if (flags & ~valid_mask) + return -EINVAL; + + if (IS_ENABLED(CONFIG_CPU_SUP_AMD)) + return amd_set_tagged_addr_ctrl(flags, nr_bits, offset); + else + return -EINVAL; +} + +long get_tagged_addr_ctrl(struct task_struct *task, + int __user *nr_bits, int __user *offset) +{ + + if (in_32bit_syscall()) + return -EINVAL; + + if (IS_ENABLED(CONFIG_CPU_SUP_AMD)) + return amd_get_tagged_addr_ctrl(nr_bits, offset); + else + return -EINVAL; +} + +/* + * Global sysctl to disable the tagged user addresses support. This control + * only prevents the tagged address ABI enabling via prctl() and does not + * disable it for tasks that already opted in to the relaxed ABI. + */ +static struct ctl_table tagged_addr_sysctl_table[] = { + { + .procname = "tagged_addr_disabled", + .mode = 0644, + .data = &tagged_addr_disabled, + .maxlen = sizeof(int), + .proc_handler = proc_dointvec_minmax, + .extra1 = SYSCTL_ZERO, + .extra2 = SYSCTL_ONE, + }, + { } +}; + +static int __init tagged_addr_init(void) +{ + if (!register_sysctl("abi", tagged_addr_sysctl_table)) + return -EINVAL; + return 0; +} + +core_initcall(tagged_addr_init); +#endif /* CONFIG_X86_TAGGED_ADDR_ABI */