Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp4069760pxu; Mon, 12 Oct 2020 08:43:54 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz8h1MmGcBCo2cwihZ6809oCKAQzt4Jz05IN9MnIwwmKV3k6LT4LAz14JwJjeENWHcYlwYq X-Received: by 2002:a17:906:3ada:: with SMTP id z26mr6706100ejd.151.1602517434406; Mon, 12 Oct 2020 08:43:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1602517434; cv=none; d=google.com; s=arc-20160816; b=FoeFZSd3hC+C/h/MU2r2qvgxnBVihgaQ/y78VqJUiANwbOTbtL3/nTM9lgej5RdJ3Z RDeg45bQM5qnVuFsQegYJlc6eCbOlBeb9TbzFgX6/8Cb3mWus7xkXyyZKFSZiWhx6iiT 4wOQpdoloCJ9T9dwdKj4qPShfITwIodTQpFAgg3p3YhB8X3M7I2ND6NfQTJS9wDEmE3G wJhc8P5inKJMV2QR3izZiO7t/ZNJxGdymXE/0XLeS1s/F1KHffi6BzTTl6qankePVSMw yrQYLUv0ihxWPXwLflRB7720n/9+juRepbe3TDnKIxH31ukmkJW5z4aDhlzB0Detcn1I L0tQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :ironport-sdr:ironport-sdr; bh=4Wv0KnO7oWp+CJjPtYz4f98b+XKnJw95jq4/HmkZ8bg=; b=cx3d9ffaDog6LuzDGiY8qRIHpLyar1Kt0RX8/vZjbQfYmZiRwyS2LiTxBS8Fq8miIy GmfRP0rZz2NhxoqWe/EVeNZy/RvShNxX/Z8EzBBv5JYeVTE9NyKOX3pnNQpfDvpmzNd2 erRyBKxYYvxX6vyBsHkXwcZfHBLM9nJumhdb4SzFmTT2g6MzFJ2VLaqNAsbJfJZ6SLaV 9z/flXzoIovUgLs9sRin7QbrwhYRxm89hdzHCMv2LoQ31hswymfmcS2ZBpc1ZM7gT0wr uALXEccakHbkmBYNez52+FD1/F3glMXATsE0r+lf10pEq50XgMawt6xPw6eRi9gjZICz +Vug== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ec11si12746595ejb.540.2020.10.12.08.43.32; Mon, 12 Oct 2020 08:43:54 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390292AbgJLPlh (ORCPT + 99 others); Mon, 12 Oct 2020 11:41:37 -0400 Received: from mga05.intel.com ([192.55.52.43]:1378 "EHLO mga05.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390299AbgJLPkC (ORCPT ); Mon, 12 Oct 2020 11:40:02 -0400 IronPort-SDR: 3Q7ehtDFB1E3Mv1Qq1tmlFGZANXHaA8b+zAFyJJ8VJ+uZfRv5f5KB7FPW6kQZGS5NkOuVdP+KR nMGQvqzK+gwQ== X-IronPort-AV: E=McAfee;i="6000,8403,9772"; a="250452654" X-IronPort-AV: E=Sophos;i="5.77,367,1596524400"; d="scan'208";a="250452654" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Oct 2020 08:39:48 -0700 IronPort-SDR: J48ZbiC5D6y9A0lao5qBgtIABndhRbUe1+LceEIsKublXpdLEbMcc7GICHJnoionYzkI27Owv6 lUXodCjkiH5A== X-IronPort-AV: E=Sophos;i="5.77,367,1596524400"; d="scan'208";a="530010806" Received: from yyu32-desk.sc.intel.com ([143.183.136.146]) by orsmga005-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Oct 2020 08:39:48 -0700 From: Yu-cheng Yu 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" , Vedvyas Shanbhogue , Dave Martin , Weijiang Yang , Pengfei Xu Cc: Yu-cheng Yu , Christoph Hellwig Subject: [PATCH v14 07/26] x86/mm: Remove _PAGE_DIRTY_HW from kernel RO pages Date: Mon, 12 Oct 2020 08:38:31 -0700 Message-Id: <20201012153850.26996-8-yu-cheng.yu@intel.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20201012153850.26996-1-yu-cheng.yu@intel.com> References: <20201012153850.26996-1-yu-cheng.yu@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Kernel read-only PTEs are setup as _PAGE_DIRTY_HW. Since these become shadow stack PTEs, remove the dirty bit. Signed-off-by: Yu-cheng Yu 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 --- 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 192e1326b3db..5f31f1c407b9 100644 --- a/arch/x86/include/asm/pgtable_types.h +++ b/arch/x86/include/asm/pgtable_types.h @@ -193,10 +193,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 d1b2a889f035..962434fdf0d9 100644 --- a/arch/x86/mm/pat/set_memory.c +++ b/arch/x86/mm/pat/set_memory.c @@ -1932,7 +1932,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_HW), 0); } int set_memory_rw(unsigned long addr, int numpages) -- 2.21.0