Received: by 2002:a05:6a10:a841:0:0:0:0 with SMTP id d1csp4831413pxy; Tue, 27 Apr 2021 13:45:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzGzSHDifqTz2XskymF98G6uiThEBaS5AYPWuZNH7ngvtVfELdvCkZ5oEli0FTBQ2mXNdIM X-Received: by 2002:a17:90a:1382:: with SMTP id i2mr21112709pja.176.1619556354802; Tue, 27 Apr 2021 13:45:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1619556354; cv=none; d=google.com; s=arc-20160816; b=Vuko2otpp8Uohuq0U2Dc68Ux3EX6LAfjCgfYA8ZOaOj7cB0sQB8nZ8VZskZ7g4z6dt MbcMvLr9HJ6hPUs1D3AuK3zTpsARB4nIAbm+Mol4mDmye/T7ReKdVNTTTRAtnm5T6bVt eXsuW1Q7mf9gstX0bwivMLQXd8B2zYG2/JNoiUw8jrOqrzXexnZi1oqlydOFg2yffYQu qb2/0OMktl6ly/13eWQxm4ZW1RBwJ5cpoA/xeTmkEMrodnB923aSu+zTmuRhvNt7AzCZ hnFcTs8tqf8b/oq0pUdqI8Yp5ZHXrSUI8zELaOMKTz7n5FfW8DAJubovY/BTdbGboNsP ouvw== 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=5fe5RGklqCTPvr0DABPvNYXgaCw59WRsut8TlMvKlo8=; b=m/jEgNK7lUESsMFU5cr7VfzaksU3UldjOoDygXPMfAQmzuXIwB2HwZlJ/kd5OVqxg/ 1/SzTwVx+B8U4O1FWRUUedETit0T9nlL69aHfJ3dF8jmnU55fAp6UCtO/yWPV7V7wyCW PFXKHwPq/kTuBq59gS/eBsb3Vz08CZiJhf6qJnAkmLIvAhuuJNWy9g2j0Si3wG1MLJd4 d7ntUF9l/PDNQMnvm4CKxDLVzMBS/98kyuC5dyoRlYpKhkxAkmbTxd57HqDwJ2+ddoOB QDlsITlq3pv46J7XPJFh5ack3Z6OLA3DVZ2AgIF9srTldZnXveqx34sfrK3MBJykf89Q yYsw== 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 y2si1204421plt.47.2021.04.27.13.45.40; Tue, 27 Apr 2021 13:45: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 S239071AbhD0UpT (ORCPT + 99 others); Tue, 27 Apr 2021 16:45:19 -0400 Received: from mga05.intel.com ([192.55.52.43]:31780 "EHLO mga05.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236965AbhD0UpH (ORCPT ); Tue, 27 Apr 2021 16:45:07 -0400 IronPort-SDR: lEr8frMY1NuyychZAnES9u4XNJAKrdgZ9CTIwE4KyXbB9GruH8VexYWUpxXcZjsmUwjsQjuAwz Vyjaq/dTwsKA== X-IronPort-AV: E=McAfee;i="6200,9189,9967"; a="281922457" X-IronPort-AV: E=Sophos;i="5.82,255,1613462400"; d="scan'208";a="281922457" Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Apr 2021 13:44:10 -0700 IronPort-SDR: xGVQoIBCa5wVQaRj17c3pGosd4YAlB9P5BSnsIvO51vRFOH3QlAffJhWv6WnbCmr426HDlEOCX bKzQW3tyUGSw== X-IronPort-AV: E=Sophos;i="5.82,255,1613462400"; d="scan'208";a="465623455" Received: from yyu32-desk.sc.intel.com ([143.183.136.146]) by orsmga001-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Apr 2021 13:44:10 -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 , Haitao Huang Cc: Yu-cheng Yu , "Kirill A . Shutemov" , Christoph Hellwig Subject: [PATCH v26 07/30] x86/mm: Remove _PAGE_DIRTY from kernel RO pages Date: Tue, 27 Apr 2021 13:42:52 -0700 Message-Id: <20210427204315.24153-8-yu-cheng.yu@intel.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20210427204315.24153-1-yu-cheng.yu@intel.com> References: <20210427204315.24153-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 The x86 family of processors do not directly create read-only and Dirty PTEs. These PTEs are created by software. One such case is that kernel read-only pages are historically setup as Dirty. New processors that support Shadow Stack regard read-only and Dirty PTEs as shadow stack pages. This results in ambiguity between shadow stack and kernel read-only pages. To resolve this, removed Dirty from kernel read- only pages. Signed-off-by: Yu-cheng Yu Reviewed-by: Kirill A. Shutemov 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 f24d7ef8fffa..9db61817dfff 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 16f878c26667..6bebb95a6988 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), 0); } int set_memory_rw(unsigned long addr, int numpages) -- 2.21.0