Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp1108734ybz; Wed, 29 Apr 2020 15:13:26 -0700 (PDT) X-Google-Smtp-Source: APiQypLAFKEItqSDVgUvdrSbREc9Kmlg1/4IjbcoWz/Ib69PsN+1oDA85EZGWbhY9GCjJxN9OAsL X-Received: by 2002:aa7:dac3:: with SMTP id x3mr102512eds.379.1588198406292; Wed, 29 Apr 2020 15:13:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588198406; cv=none; d=google.com; s=arc-20160816; b=PdIhYFeT5QY5fOvb8iXocV4k5O+tf84oEyvStoZmIQqGpGVcz+aeQSRF9scVxmICBw iMbInW9EbZU9aBe1gv5DnWIW+EkSKOhHRv+8XZK4na7P8Psx71m8ztaV999L8nXPO93w cOGcr2BDitMAOCtd3MsqqSNRGfEbImgDbGstK383T02E61YuAj5yf58D5imBfJ6DZAcD +fquKJs+T38UwdfPJ28ZlyrvA9vB4RCX88f8FvmivU/kNRLaQlan2dwnhuZILyllLov+ RRFkQmQ/Mc84YJUxcW4vew0tyudDRhLEsRvS80xZ1f4tj4adGEs8e+uLO/ql26Jyxg8K G8JQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :ironport-sdr:ironport-sdr; bh=3qCgvUV2JE1cEbn4jVGd6G/0SuRFdaCQQj/DDXRU1UA=; b=E414MiQLbF4FwFb44qvjsXFKjKAfbZoSg0+1fusUVsjzHSHTZHhC/ZAxrOkB855iu7 hBRBhVQseUKALQNUbcEyGR3art82gYay3xvBUx8sr8n0cfZUDKVQWwy7U/RUDBHycPyo l0+K0tzvJVbukdf2i0EBb4Nd1uosIRN96vag2bd2qoR9gsR+JQ49t79sL1PCIYN/2VsN 8heln+CMDbK5aBs7I7nNmBlJTPf0T2PSZPxuHNwWOPK4BACA9WeVHOmFfpWWad0pnQMY h2RY17xrdPl/Dkxf6pQvQ7+XWlSVMMtXmZbYIdDtKmIEYZHTLfRp6ts9phCmpkD3W6EG WfCg== 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 c3si4373943eja.251.2020.04.29.15.13.01; Wed, 29 Apr 2020 15:13:26 -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 S1728355AbgD2WK0 (ORCPT + 99 others); Wed, 29 Apr 2020 18:10:26 -0400 Received: from mga09.intel.com ([134.134.136.24]:61300 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727857AbgD2WIn (ORCPT ); Wed, 29 Apr 2020 18:08:43 -0400 IronPort-SDR: ooRKz/M5i/wD0zoUA76PonvrgkrlC89YlgrKQMiPk2FcpxHrUraN9c9DzeIri7Oz9wyJdWA5zI DT9WdBl1z3IA== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Apr 2020 15:08:43 -0700 IronPort-SDR: NlYnfBlQ5psdLBR6iqozVLAVCQMzWAljpX+34eRUFI+/jP34SmNcB+YT1hYKkUuX24TiMsWy7W f+dCLMw55hZw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.73,333,1583222400"; d="scan'208";a="276308870" Received: from yyu32-desk.sc.intel.com ([143.183.136.146]) by orsmga002.jf.intel.com with ESMTP; 29 Apr 2020 15:08:42 -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 Cc: Yu-cheng Yu Subject: [PATCH v10 07/26] x86/mm: Remove _PAGE_DIRTY_HW from kernel RO pages Date: Wed, 29 Apr 2020 15:07:13 -0700 Message-Id: <20200429220732.31602-8-yu-cheng.yu@intel.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20200429220732.31602-1-yu-cheng.yu@intel.com> References: <20200429220732.31602-1-yu-cheng.yu@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org 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: 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 b82e0f167879..522b80b952f4 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_RX (__PP| 0| 0|___A| 0|___D| 0|___G) +#define __PAGE_KERNEL_RO (__PP| 0| 0|___A|__NX| 0| 0|___G) +#define __PAGE_KERNEL_RX (__PP| 0| 0|___A| 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 59eca6a94ce7..87751b7e2131 100644 --- a/arch/x86/mm/pat/set_memory.c +++ b/arch/x86/mm/pat/set_memory.c @@ -1923,7 +1923,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