From patchwork Thu Sep 29 22:29:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rick Edgecombe X-Patchwork-Id: 12994662 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 69A81C4332F for ; Thu, 29 Sep 2022 22:30:04 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 09F446B0080; Thu, 29 Sep 2022 18:30:04 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 04FF48D0001; Thu, 29 Sep 2022 18:30:04 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DE3C26B0082; Thu, 29 Sep 2022 18:30:03 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id D05DB6B0080 for ; Thu, 29 Sep 2022 18:30:03 -0400 (EDT) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id B1A6B813CB for ; Thu, 29 Sep 2022 22:30:03 +0000 (UTC) X-FDA: 79966567086.27.4488325 Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by imf12.hostedemail.com (Postfix) with ESMTP id 1F7CE40009 for ; Thu, 29 Sep 2022 22:30:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1664490603; x=1696026603; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=SxXCrRN2y+PQFpGewVcJHXNAHqkkdqYVarKu7dXm5kc=; b=jI+ZTxGUpuVcbznEetAoSbJD6GKKimte+u/IT5rPtt/g7Pcnsz6XBY+f Pv/lgQqWf+vywihLRaJLqXle8bc4UPDN/FysN/tBaIrMiytzizldD0QAy tHz6KFciHy72WVnPhP0pX6zLBkDPehJgbZdEi3q3VfOs/vmNBAULom4d+ H9QW01cNCTcnrGfKYYkmChXywOcSXtgM4FCpmlaMRgNskeT92h0OiurzL 6KvBtySzlznfAbiYYcXN3Dakk34eAtSJswC2+m4/fPm1/8h3VivptJ+XZ RMtUUvGyusuRSCTDpXJnMeQ3DKJ1IRKgypn5p76lFI6wNgB+8+D3V7q1h A==; X-IronPort-AV: E=McAfee;i="6500,9779,10485"; a="328420352" X-IronPort-AV: E=Sophos;i="5.93,356,1654585200"; d="scan'208";a="328420352" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Sep 2022 15:30:02 -0700 X-IronPort-AV: E=McAfee;i="6500,9779,10485"; a="691016133" X-IronPort-AV: E=Sophos;i="5.93,356,1654585200"; d="scan'208";a="691016133" Received: from sergungo-mobl.amr.corp.intel.com (HELO rpedgeco-desk.amr.corp.intel.com) ([10.251.25.88]) by fmsmga004-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Sep 2022 15:30:00 -0700 From: Rick Edgecombe To: x86@kernel.org, "H . Peter Anvin" , Thomas Gleixner , Ingo Molnar , 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 , Andy Lutomirski , Balbir Singh , Borislav Petkov , Cyrill Gorcunov , Dave Hansen , Eugene Syromiatnikov , Florian Weimer , "H . J . Lu" , Jann Horn , Jonathan Corbet , Kees Cook , Mike Kravetz , Nadav Amit , Oleg Nesterov , Pavel Machek , Peter Zijlstra , Randy Dunlap , "Ravi V . Shankar" , Weijiang Yang , "Kirill A . Shutemov" , joao.moreira@intel.com, John Allen , kcc@google.com, eranian@google.com, rppt@kernel.org, jamorris@linux.microsoft.com, dethoma@microsoft.com Cc: rick.p.edgecombe@intel.com, Yu-cheng Yu , Christoph Hellwig Subject: [PATCH v2 08/39] x86/mm: Remove _PAGE_DIRTY from kernel RO pages Date: Thu, 29 Sep 2022 15:29:05 -0700 Message-Id: <20220929222936.14584-9-rick.p.edgecombe@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220929222936.14584-1-rick.p.edgecombe@intel.com> References: <20220929222936.14584-1-rick.p.edgecombe@intel.com> ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1664490603; a=rsa-sha256; cv=none; b=DqR8gpm9De/MrfiwL4CD8mAkctTqJ9Tbs5siVA7L3JKjJc4d/QRRCak56vuHoyBoWoOLez zXKFDRGq9k5Rc+ibeyjgi8LIF8mtxVsiRWQqhPXs69c5bXoXMxZA2DSCKcH6U0nysEcCm5 T7QAJiuY7/GBoqQ9IEu2BXiWBHOE+O0= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=none ("invalid DKIM record") header.d=intel.com header.s=Intel header.b=jI+ZTxGU; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf12.hostedemail.com: domain of rick.p.edgecombe@intel.com designates 192.55.52.88 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=1664490603; 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=D79JqGchwmU9nIUWIHs/9FxJjSmWLWFdR7CBX3VhdCM=; b=ZT1TaHBJvIfVValYjBVzTAc84fIr1XGAtpl78Ow9HBJJ+Yuvbj4O4kDRSP65B8s/SLObyF /Y6WGOhd3yJvSlhOuvEftYPyX6oqTNO8SFJXI6tmSn9HqzNCQc3d9mWUus/VAG/gxZQTLn cZa1o3JmjmvxJas/bKU2K7PHZFR1PE8= X-Rspamd-Queue-Id: 1F7CE40009 X-Rspam-User: Authentication-Results: imf12.hostedemail.com; dkim=none ("invalid DKIM record") header.d=intel.com header.s=Intel header.b=jI+ZTxGU; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf12.hostedemail.com: domain of rick.p.edgecombe@intel.com designates 192.55.52.88 as permitted sender) smtp.mailfrom=rick.p.edgecombe@intel.com X-Rspamd-Server: rspam03 X-Stat-Signature: smq7qqrxshspb4jkqctjd6b4f4wo9xtp X-HE-Tag: 1664490602-284817 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: Yu-cheng Yu Processors sometimes directly create Write=0,Dirty=1 PTEs. These PTEs are created by software. One such case is that kernel read-only pages are historically set up as Dirty. New processors that support Shadow Stack regard Write=0,Dirty=1 PTEs as shadow stack pages. When CR4.CET=1 and IA32_S_CET.SH_STK_EN=1, some instructions can write to such supervisor memory. The kernel does not set IA32_S_CET.SH_STK_EN, but to reduce ambiguity between shadow stack and regular Write=0 pages, removed Dirty=1 from any kernel Write=0 PTEs. Signed-off-by: Yu-cheng Yu Co-developed-by: Rick Edgecombe Signed-off-by: Rick Edgecombe Cc: "H. Peter Anvin" Cc: Kees Cook Cc: Thomas Gleixner Cc: Dave Hansen Cc: Christoph Hellwig Cc: Andy Lutomirski Cc: Ingo Molnar Cc: Borislav Petkov Cc: Peter Zijlstra --- v2: - Normalize PTE bit descriptions between patches arch/x86/include/asm/pgtable_types.h | 6 +++--- arch/x86/mm/pat/set_memory.c | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h index aa174fed3a71..ff82237e7b6b 100644 --- a/arch/x86/include/asm/pgtable_types.h +++ b/arch/x86/include/asm/pgtable_types.h @@ -192,10 +192,10 @@ enum page_cache_mode { #define _KERNPG_TABLE (__PP|__RW| 0|___A| 0|___D| 0| 0| _ENC) #define _PAGE_TABLE_NOENC (__PP|__RW|_USR|___A| 0|___D| 0| 0) #define _PAGE_TABLE (__PP|__RW|_USR|___A| 0|___D| 0| 0| _ENC) -#define __PAGE_KERNEL_RO (__PP| 0| 0|___A|__NX|___D| 0|___G) -#define __PAGE_KERNEL_ROX (__PP| 0| 0|___A| 0|___D| 0|___G) +#define __PAGE_KERNEL_RO (__PP| 0| 0|___A|__NX| 0| 0|___G) +#define __PAGE_KERNEL_ROX (__PP| 0| 0|___A| 0| 0| 0|___G) #define __PAGE_KERNEL_NOCACHE (__PP|__RW| 0|___A|__NX|___D| 0|___G| __NC) -#define __PAGE_KERNEL_VVAR (__PP| 0|_USR|___A|__NX|___D| 0|___G) +#define __PAGE_KERNEL_VVAR (__PP| 0|_USR|___A|__NX| 0| 0|___G) #define __PAGE_KERNEL_LARGE (__PP|__RW| 0|___A|__NX|___D|_PSE|___G) #define __PAGE_KERNEL_LARGE_EXEC (__PP|__RW| 0|___A| 0|___D|_PSE|___G) #define __PAGE_KERNEL_WP (__PP|__RW| 0|___A|__NX|___D| 0|___G| __WP) diff --git a/arch/x86/mm/pat/set_memory.c b/arch/x86/mm/pat/set_memory.c index 1abd5438f126..ed9193b469ba 100644 --- a/arch/x86/mm/pat/set_memory.c +++ b/arch/x86/mm/pat/set_memory.c @@ -1977,7 +1977,7 @@ int set_memory_nx(unsigned long addr, int numpages) int set_memory_ro(unsigned long addr, int numpages) { - return change_page_attr_clear(&addr, numpages, __pgprot(_PAGE_RW), 0); + return change_page_attr_clear(&addr, numpages, __pgprot(_PAGE_RW | _PAGE_DIRTY), 0); } int set_memory_rw(unsigned long addr, int numpages)