From patchwork Mon Jan 23 22:04:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Kirill A. Shutemov" X-Patchwork-Id: 13113081 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 A1A78C54EED for ; Mon, 23 Jan 2023 22:05:38 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5B9E36B008C; Mon, 23 Jan 2023 17:05:37 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 568CD6B0092; Mon, 23 Jan 2023 17:05:37 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3BBEF6B0095; Mon, 23 Jan 2023 17:05:37 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 1AC196B008C for ; Mon, 23 Jan 2023 17:05:37 -0500 (EST) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id EC6121C606B for ; Mon, 23 Jan 2023 22:05:36 +0000 (UTC) X-FDA: 80387446272.16.BF0F3D8 Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by imf15.hostedemail.com (Postfix) with ESMTP id D8198A0016 for ; Mon, 23 Jan 2023 22:05:34 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b="ApXgL/oy"; spf=none (imf15.hostedemail.com: domain of kirill.shutemov@linux.intel.com has no SPF policy when checking 192.55.52.115) smtp.mailfrom=kirill.shutemov@linux.intel.com; dmarc=pass (policy=none) header.from=intel.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1674511535; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=jalrD7nqZv10CRswVZmChr9ky4Zab9mWxCuyLV858Iw=; b=CLg5DRPAHUjvBGI0uA1wxM+cLFbBoO0p/wNaCLgOFy2ThOiU5TCgV0g7hR0ZCXoDdqy7RK OXjg7StF2pH24ch6zjT6PcpwdZMbPa0qb0hW3iLl7zWmUuZvlI3PSZ3rQV6Av+GZdIpLTx ug4d+m7dXqnx1X6OePhT/PXvZ/JltGg= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b="ApXgL/oy"; spf=none (imf15.hostedemail.com: domain of kirill.shutemov@linux.intel.com has no SPF policy when checking 192.55.52.115) smtp.mailfrom=kirill.shutemov@linux.intel.com; dmarc=pass (policy=none) header.from=intel.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1674511535; a=rsa-sha256; cv=none; b=fJLTTnjbmnbTcoSR47pH/0Wwcv0X3IZI2Z6BNo8w6Y59Vru3LD565bi+C8XjpzFfJ2Cg5H KyTlA1tKLXzKs5cEF6nDDVWk6MGWZmaGR2Fcl9r8qEK3mGFe8/hmJ3KsqHYi15EhWtFsFA gJcMZ3U9lRT0O50effWa4Ml1ZRrcBz4= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1674511534; x=1706047534; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=PE6h3wytuKJk3kXgRyY8lFutpFDe1IptHJikql0qTdY=; b=ApXgL/oyvBA0ZDRddIrOKeQDBm8ViBRAZJmmovXPiYZchyMa5hRlZyqF l9JzV8/W3En1GR2oc7YDv1+qStYhAaO7QYrjsS4QjMtxXyzC0cYJvVZ2t ugTuQbxAddMcTWcDdLGaE2BhS9aLcmXVneIR/zm2nvA+0c4OyCrPo259G i98H0rrNpnx1LddzgcZYzncAV/7kXL4cjxmvVgaJ0hw+BGu0LwfAMxQI1 FuGPNcxGf9TIykYAS5qt8XmUL3m7WUSznIrehySNDS9WtGylHb4zQWEV+ ULu5PpLnvktC+Hvmac6e6jFKhbxNyi2DGo3014xIO5cw5ZIIdhGVwQT1+ w==; X-IronPort-AV: E=McAfee;i="6500,9779,10599"; a="326198135" X-IronPort-AV: E=Sophos;i="5.97,240,1669104000"; d="scan'208";a="326198135" Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Jan 2023 14:05:14 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10599"; a="694103346" X-IronPort-AV: E=Sophos;i="5.97,240,1669104000"; d="scan'208";a="694103346" Received: from ssauty-mobl1.ger.corp.intel.com (HELO box.shutemov.name) ([10.249.46.171]) by orsmga001-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Jan 2023 14:05:07 -0800 Received: by box.shutemov.name (Postfix, from userid 1000) id 2C979109437; Tue, 24 Jan 2023 01:05:03 +0300 (+03) 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 , Bharata B Rao , Jacob Pan , Ashok Raj , Linus Torvalds , linux-mm@kvack.org, linux-kernel@vger.kernel.org, "Kirill A. Shutemov" Subject: [PATCHv15 02/17] x86: Allow atomic MM_CONTEXT flags setting Date: Tue, 24 Jan 2023 01:04:45 +0300 Message-Id: <20230123220500.21077-3-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230123220500.21077-1-kirill.shutemov@linux.intel.com> References: <20230123220500.21077-1-kirill.shutemov@linux.intel.com> MIME-Version: 1.0 X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: D8198A0016 X-Stat-Signature: 15rc5p4hox58d6iquwow3y95zhew7a8a X-Rspam-User: X-HE-Tag: 1674511534-429314 X-HE-Meta: U2FsdGVkX1/Qp/7PLwuzsld96cnL7t//+kjqIAcUe55fawxikIDty4VcaP7mIrMm2Wi0/q6k55wvD4yMevBJ/7iiSpSMdxZsSXOTlKQQ1DnxXRzcFeeAFxdcURxCO79bMacM2Fw8yXVixpdA1dlOCx+c7pdski3UKA1MfxwuFrdpbi7zqanr2qlye3YMkvukuUMzz+bcg1V0omd6PCyFKFMphRSNFGYOmPmwZhBbi0glRlE63WXivFvcacJNBXrn5n8717HU8J5ZQEoXzK7up59WNzZEeFyZ/+fxLtBquUsxFcqwJ82sh4AJ1rJmRYVE+G9lbMkYraOCcfjeofoy0Iny1Jabq6mWnUuV8FRKnn1khaEqeIR5prcE65jMHBftjzfJmoRjsurXUP0QxevyjxlJNmxGizbDgbp0mHMpvaG9UL5C7JjnqR+hRYZ8i7fyCQzLAgTeij0N+StSRU9ioxZvZq+3W1FJ44MpTp96QxPpzBwYurl1VuWSuW+m120kPd1rLQ+eA+K0kH413QryrqDlqOJmtamA5Fm2FvvIFWXqJyYV9vWypYSzl5P9mR3JOPpcMl8aWWbmVgRbq+pfAby7uYf3okNWmN/YC7VBr8nfZFQWxdUAZwMh22DuvOkLtP0fzMSu2ycfQVBfSSKmoDtLv3BPX0rsjb4yAGP1UGtGS7ufEkhY3NbpVXSxigB9QYvChbOq7jvM8pb5+SxXAfQiYCeELF9/un3qC/GzQIQ6JDfvermCYCSOD7+/K1tljLLA7JjUrFfdvY8E1nGZs9ER5BlVQHkGXFr0HFbZN8qKEfTwI+mHZYr9UJAY8l/D/IVKWl0T9jKmRc/u7N8Ydc5aQ1j/5DbRGdeAAsOwwpdM5heG7FV+7P4gi8JcoLGbMwiS7m3J1dAgtPEZFYGfVMEI6aUhniOI1GyYVBngqxzLa0EuPWK71dc+SklgukN0sw4STL3xL27/ZosyLEG woEqvqXJ q7y50gbbeqnNlaNJ+loh3reD8bd9my241FvPUxJzvm1ikZ4GxrgvkwUHqTuIY77ddLCdYieED8JBrXqg3aLTbfz8R8butNyGVP1mP5tXrkpXFu7Fm5u8Xjumiie2lzcEueg61nJa7gK3l8WAsm5nX7d+1ksUv4/mHpwmbJ6j2v/dJEvLUV8aN6eQ9HsRkYLquUJXeBkQOGyOqEDCIAesAsNChVYgf4TScbhPqcsD6FnpCxdQPYzHp3OcR2jD0tWQF++dxJriXRltXKt+APJ5tgHE2iKvY3Yy/EoiTswLUrsTYT9VmRE5aQCMsOQeVckBWvLOzFe+uq6/KohoD7d9hBTyMCg== 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: So far there's no need in atomic setting of MM context flags in mm_context_t::flags. The flags set early in exec and never change after that. LAM enabling requires atomic flag setting. The upcoming flag MM_CONTEXT_FORCE_TAGGED_SVA can be set much later in the process lifetime where multiple threads exist. Convert the field to unsigned long and do MM_CONTEXT_* accesses with __set_bit() and test_bit(). No functional changes. Signed-off-by: Kirill A. Shutemov Acked-by: Peter Zijlstra (Intel) Tested-by: Alexander Potapenko --- arch/x86/entry/vsyscall/vsyscall_64.c | 2 +- arch/x86/include/asm/mmu.h | 6 +++--- arch/x86/include/asm/mmu_context.h | 2 +- arch/x86/kernel/process_64.c | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/arch/x86/entry/vsyscall/vsyscall_64.c b/arch/x86/entry/vsyscall/vsyscall_64.c index 4af81df133ee..aa226f451c52 100644 --- a/arch/x86/entry/vsyscall/vsyscall_64.c +++ b/arch/x86/entry/vsyscall/vsyscall_64.c @@ -317,7 +317,7 @@ static struct vm_area_struct gate_vma __ro_after_init = { struct vm_area_struct *get_gate_vma(struct mm_struct *mm) { #ifdef CONFIG_COMPAT - if (!mm || !(mm->context.flags & MM_CONTEXT_HAS_VSYSCALL)) + if (!mm || !test_bit(MM_CONTEXT_HAS_VSYSCALL, &mm->context.flags)) return NULL; #endif if (vsyscall_mode == NONE) diff --git a/arch/x86/include/asm/mmu.h b/arch/x86/include/asm/mmu.h index 5d7494631ea9..efa3eaee522c 100644 --- a/arch/x86/include/asm/mmu.h +++ b/arch/x86/include/asm/mmu.h @@ -9,9 +9,9 @@ #include /* Uprobes on this MM assume 32-bit code */ -#define MM_CONTEXT_UPROBE_IA32 BIT(0) +#define MM_CONTEXT_UPROBE_IA32 0 /* vsyscall page is accessible on this MM */ -#define MM_CONTEXT_HAS_VSYSCALL BIT(1) +#define MM_CONTEXT_HAS_VSYSCALL 1 /* * x86 has arch-specific MMU state beyond what lives in mm_struct. @@ -39,7 +39,7 @@ typedef struct { #endif #ifdef CONFIG_X86_64 - unsigned short flags; + unsigned long flags; #endif struct mutex lock; diff --git a/arch/x86/include/asm/mmu_context.h b/arch/x86/include/asm/mmu_context.h index b8d40ddeab00..53ef591a6166 100644 --- a/arch/x86/include/asm/mmu_context.h +++ b/arch/x86/include/asm/mmu_context.h @@ -181,7 +181,7 @@ static inline void arch_exit_mmap(struct mm_struct *mm) static inline bool is_64bit_mm(struct mm_struct *mm) { return !IS_ENABLED(CONFIG_IA32_EMULATION) || - !(mm->context.flags & MM_CONTEXT_UPROBE_IA32); + !test_bit(MM_CONTEXT_UPROBE_IA32, &mm->context.flags); } #else static inline bool is_64bit_mm(struct mm_struct *mm) diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c index 4e34b3b68ebd..8b06034e8c70 100644 --- a/arch/x86/kernel/process_64.c +++ b/arch/x86/kernel/process_64.c @@ -671,7 +671,7 @@ void set_personality_64bit(void) task_pt_regs(current)->orig_ax = __NR_execve; current_thread_info()->status &= ~TS_COMPAT; if (current->mm) - current->mm->context.flags = MM_CONTEXT_HAS_VSYSCALL; + __set_bit(MM_CONTEXT_HAS_VSYSCALL, ¤t->mm->context.flags); /* TBD: overwrites user setup. Should have two bits. But 64bit processes have always behaved this way, @@ -708,7 +708,7 @@ static void __set_personality_ia32(void) * uprobes applied to this MM need to know this and * cannot use user_64bit_mode() at that time. */ - current->mm->context.flags = MM_CONTEXT_UPROBE_IA32; + __set_bit(MM_CONTEXT_UPROBE_IA32, ¤t->mm->context.flags); } current->personality |= force_personality32;