Message ID | 20230227222957.24501-16-rick.p.edgecombe@intel.com (mailing list archive) |
---|---|
State | New |
Headers | show
Return-Path: <owner-linux-mm@kvack.org> 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 B1D08C83005 for <linux-mm@archiver.kernel.org>; Mon, 27 Feb 2023 22:32:00 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D3CFE6B008A; Mon, 27 Feb 2023 17:31:47 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id A41A06B0096; Mon, 27 Feb 2023 17:31:47 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 69A3B6B0093; Mon, 27 Feb 2023 17:31:47 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 275F56B008A for <linux-mm@kvack.org>; Mon, 27 Feb 2023 17:31:47 -0500 (EST) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 09FD51A05A5 for <linux-mm@kvack.org>; Mon, 27 Feb 2023 22:31:47 +0000 (UTC) X-FDA: 80514520254.15.D691236 Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by imf24.hostedemail.com (Postfix) with ESMTP id 08E2A180009 for <linux-mm@kvack.org>; Mon, 27 Feb 2023 22:31:44 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=RhOrvd+M; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf24.hostedemail.com: domain of rick.p.edgecombe@intel.com designates 192.55.52.136 as permitted sender) smtp.mailfrom=rick.p.edgecombe@intel.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1677537105; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:content-type: content-transfer-encoding:in-reply-to:in-reply-to: references:references:dkim-signature; bh=5N0lFCbFu8gwpBsmCT1OeqTBC2+wwCTV8SigqvCE8fg=; b=0qKZWl/i0Gd48ANjZDXhFskK+dSaN9BWVXjJWc+Q9h4NR3mcI02LOHyKQvTA94ycgFGOjd 81H/iAppktyOm73AN9thMg7RTcAYs+UefFxVg0y94JIxal/ubG2c93PZyY7Pt5PjsoVVs7 XNKUUiNdiG2ABeYCxlEAuSjQDUwCHFg= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=RhOrvd+M; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf24.hostedemail.com: domain of rick.p.edgecombe@intel.com designates 192.55.52.136 as permitted sender) smtp.mailfrom=rick.p.edgecombe@intel.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1677537105; a=rsa-sha256; cv=none; b=TQI6bQH9HSMtJlpu/QB7YWve2F0xkTTIW0TsEIqZkGWU9ajc3g9bdRgR5BOfhfwjHwZKLm saGOgXOSTL8OBqik4UvfD6QAy6G0KtOtKPJNvhH11yiT4YP8WCvopzbglAlWtuH/py0o2f LQxndwLafqPcFJels7tm5n22uW/xyYw= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1677537105; x=1709073105; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=Pl+T1+xmSBSUgFqJaHPWJP+BmegywDM6GYKzVKSMXoQ=; b=RhOrvd+MjCj46UIbdgPZrlU22DVQXSsU7b2FM6A7cxk1nLipVM56ZbdM AqO+nUCr0cgh/9q0V4vNNnHMJXRfydVZc0pV9t6u5mVUzcpIAzRjQMwdG UesWZs6T8XK/4W/Fxt0C8kd9eVYqX/CEde4a5qk+kjBwMn7pbOzdy4RO9 mlD8SwXe0k/GNUz52u3G2+cK3dEs1sNNT3X0XQrsX68cqIoVDNnQRR4/i OfX80XlVfYcxyksZPqDjbBpJzSMdccDe6EZBBdAya3IRDNE4FQm//I/N3 Wr6cOBN7HV/27TSBc/UIETMkJznvNhFgNCwPzpQ0CEohpLWgG6mc/f0t1 g==; X-IronPort-AV: E=McAfee;i="6500,9779,10634"; a="313657391" X-IronPort-AV: E=Sophos;i="5.98,220,1673942400"; d="scan'208";a="313657391" Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Feb 2023 14:31:23 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10634"; a="848024576" X-IronPort-AV: E=Sophos;i="5.98,220,1673942400"; d="scan'208";a="848024576" Received: from leonqu-mobl1.amr.corp.intel.com (HELO rpedgeco-desk.amr.corp.intel.com) ([10.209.72.19]) by orsmga005-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Feb 2023 14:31:18 -0800 From: Rick Edgecombe <rick.p.edgecombe@intel.com> To: x86@kernel.org, "H . Peter Anvin" <hpa@zytor.com>, Thomas Gleixner <tglx@linutronix.de>, Ingo Molnar <mingo@redhat.com>, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, linux-mm@kvack.org, linux-arch@vger.kernel.org, linux-api@vger.kernel.org, Arnd Bergmann <arnd@arndb.de>, Andy Lutomirski <luto@kernel.org>, Balbir Singh <bsingharora@gmail.com>, Borislav Petkov <bp@alien8.de>, Cyrill Gorcunov <gorcunov@gmail.com>, Dave Hansen <dave.hansen@linux.intel.com>, Eugene Syromiatnikov <esyr@redhat.com>, Florian Weimer <fweimer@redhat.com>, "H . J . Lu" <hjl.tools@gmail.com>, Jann Horn <jannh@google.com>, Jonathan Corbet <corbet@lwn.net>, Kees Cook <keescook@chromium.org>, Mike Kravetz <mike.kravetz@oracle.com>, Nadav Amit <nadav.amit@gmail.com>, Oleg Nesterov <oleg@redhat.com>, Pavel Machek <pavel@ucw.cz>, Peter Zijlstra <peterz@infradead.org>, Randy Dunlap <rdunlap@infradead.org>, Weijiang Yang <weijiang.yang@intel.com>, "Kirill A . Shutemov" <kirill.shutemov@linux.intel.com>, John Allen <john.allen@amd.com>, kcc@google.com, eranian@google.com, rppt@kernel.org, jamorris@linux.microsoft.com, dethoma@microsoft.com, akpm@linux-foundation.org, Andrew.Cooper3@citrix.com, christina.schimpe@intel.com, david@redhat.com, debug@rivosinc.com Cc: rick.p.edgecombe@intel.com, Yu-cheng Yu <yu-cheng.yu@intel.com> Subject: [PATCH v7 15/41] x86/mm: Update ptep/pmdp_set_wrprotect() for _PAGE_SAVED_DIRTY Date: Mon, 27 Feb 2023 14:29:31 -0800 Message-Id: <20230227222957.24501-16-rick.p.edgecombe@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230227222957.24501-1-rick.p.edgecombe@intel.com> References: <20230227222957.24501-1-rick.p.edgecombe@intel.com> X-Rspamd-Queue-Id: 08E2A180009 X-Rspamd-Server: rspam09 X-Rspam-User: X-Stat-Signature: qjq8bzwap5z6m3pdkgi6or9au1qufrq9 X-HE-Tag: 1677537104-818712 X-HE-Meta: U2FsdGVkX1/pnCdx1qcUQcLLFV+Nch0rLI2/0/iyy1MRJwEn4MU5lr1nJ0clGngnwIbNTEt8FZpiPHsKluJM1D2WZv0ftXKFYaLenbxzp4bJ+GzNRHGq/xD2gGtYfs2Ys43bpCmU4gjhpxaNim+VA/s6uuMKRcGaNuPK7Akf6AcdSg5BfSytxVUQvbIs4UdjGj4fggeBodGc7egCm5xYpV9bR+N8IQiw7pAScFfBqzGx30JEbe5L1YXaf9sES68FxJceN/FoRcWvY54mEkuVd3EX8MKykipOE0JDML7Kn1eNkqocUS/WvPWfxuh2wO/IQVPzRFHISVzayc8kJY1lCo0NihA9inlIOMxBQVdIO2nW5LZW7mevLHyx773lTME+1tzOe46ROGNHRdqRJm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: owner-majordomo@kvack.org List-ID: <linux-mm.kvack.org> |
Series |
Shadow stacks for userspace
|
expand
|
diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h index 7360783f2140..349fcab0405a 100644 --- a/arch/x86/include/asm/pgtable.h +++ b/arch/x86/include/asm/pgtable.h @@ -1192,6 +1192,23 @@ static inline pte_t ptep_get_and_clear_full(struct mm_struct *mm, static inline void ptep_set_wrprotect(struct mm_struct *mm, unsigned long addr, pte_t *ptep) { +#ifdef CONFIG_X86_USER_SHADOW_STACK + /* + * Avoid accidentally creating shadow stack PTEs + * (Write=0,Dirty=1). Use cmpxchg() to prevent races with + * the hardware setting Dirty=1. + */ + if (cpu_feature_enabled(X86_FEATURE_USER_SHSTK)) { + pte_t old_pte, new_pte; + + old_pte = READ_ONCE(*ptep); + do { + new_pte = pte_wrprotect(old_pte); + } while (!try_cmpxchg(&ptep->pte, &old_pte.pte, new_pte.pte)); + + return; + } +#endif clear_bit(_PAGE_BIT_RW, (unsigned long *)&ptep->pte); } @@ -1244,6 +1261,24 @@ static inline pud_t pudp_huge_get_and_clear(struct mm_struct *mm, static inline void pmdp_set_wrprotect(struct mm_struct *mm, unsigned long addr, pmd_t *pmdp) { +#ifdef CONFIG_X86_USER_SHADOW_STACK + /* + * Avoid accidentally creating shadow stack PTEs + * (Write=0,Dirty=1). Use cmpxchg() to prevent races with + * the hardware setting Dirty=1. + */ + if (cpu_feature_enabled(X86_FEATURE_USER_SHSTK)) { + pmd_t old_pmd, new_pmd; + + old_pmd = READ_ONCE(*pmdp); + do { + new_pmd = pmd_wrprotect(old_pmd); + } while (!try_cmpxchg(&pmdp->pmd, &old_pmd.pmd, new_pmd.pmd)); + + return; + } +#endif + clear_bit(_PAGE_BIT_RW, (unsigned long *)pmdp); }