Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp2803660rwb; Thu, 29 Sep 2022 15:32:21 -0700 (PDT) X-Google-Smtp-Source: AMsMyM48/484Q7LoMnjlPInHi4MgwnCiTmZUOCxSU1L9dBLxlqIf/G9pscnwPJu14w1/ZJ/Bb7LP X-Received: by 2002:a63:3e4a:0:b0:439:246d:e681 with SMTP id l71-20020a633e4a000000b00439246de681mr4727285pga.424.1664490740938; Thu, 29 Sep 2022 15:32:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664490740; cv=none; d=google.com; s=arc-20160816; b=fQNoerpZRvvJXy+bO/UWpU42aNG9Y2Hk/rlRne3wWw9GncOeG11PLJMPoZfTErYndS Fn+lkWL9BVe69QQhXrhd4lt8wXf99MXaH4eDXSzkyuhjGxdY9eDoEq0lM9hLJmrl4n70 1PvqUl1nSjx9I+U/nQF1pfQRaz02vqy5Q7OujBTnOH5iMWscvDlEFQHo/6giRNmpbuDO jrnIjZHaX4fJW2MsEP4oTS3G/Pqze0KTlun/iZEJHeQj8or0pgnoM/HPw0PW3BcITXT0 Ber0xSuVvxhRkTvF0t/oQKLKJVf0kkaaDqFNavSD3bs0ZsN/YCfPf7yAQF+6C6Ff02BC 56Jg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from:dkim-signature; bh=D79JqGchwmU9nIUWIHs/9FxJjSmWLWFdR7CBX3VhdCM=; b=cp/8dVfkZsbn/72HE+Uk0tXwd3/clsXzNJczYfH3K4hbaezSjCwM4L3qqdBFAt5/o1 ZWxI52x3mbZcTpC56qVsZYiFcrGxw/A4FzdQE7iFKvegs5fe98rhPXfqQ7WeNRBcKFDp LwFeR6e14pjWQcg4nm19RueqNTVQdK0fmgxQT7Qu6ypUJICxegqHJ0FG+YnpaYfCOvvH AoOxnFPJonxSlF4uvAuN0YekFoyqcHjIyg4R00mPqiwZcTKc91qY7m2eIzBAVdUDHb+f eD3ueG9Bt4gg5kJYmnSJiiBtUtkDe4vlvPU9dVXspFY9P0/Ycdu4p8B7dNdkdFjcXYkw 1TCQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=M9lkRtx3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h5-20020a654045000000b00439f012ca7asi896311pgp.743.2022.09.29.15.32.09; Thu, 29 Sep 2022 15:32:20 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=M9lkRtx3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229935AbiI2Wao (ORCPT + 99 others); Thu, 29 Sep 2022 18:30:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52654 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230023AbiI2Wa0 (ORCPT ); Thu, 29 Sep 2022 18:30:26 -0400 Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6B6C32E9E2; Thu, 29 Sep 2022 15:30:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1664490609; x=1696026609; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=SxXCrRN2y+PQFpGewVcJHXNAHqkkdqYVarKu7dXm5kc=; b=M9lkRtx3A6hskEjtCU/jj4jZ6XpXu9mgaQ0y8qQ0aUIzDKkpV7H7Ts/S yY+pgJQnMbb+5fPdQqz6OjI49dp2y8inetgZGyG1zrLxil2MTW6QY9AI2 AcGULR6gNNcMPuQDfvy0jtg50dg1f/z+DycNI+pThXUwKf4oyFhcj09fq ndPLE+05FNfed8Zs1pqy9PFE8o2Xs725/kOU1Bub/bfLngLXfg/BFb9Y4 AVpbgsPV4eMuSZDjHIAeb78vBZEoUmm0uW50YXkyavOTrBAgiAnptQXHg 7YZRUvKRrbzM+RoYeQBsdPI9ITYta3xFek2UvseTQF3Lpsc4kOOBC2ri+ Q==; X-IronPort-AV: E=McAfee;i="6500,9779,10485"; a="303531365" X-IronPort-AV: E=Sophos;i="5.93,356,1654585200"; d="scan'208";a="303531365" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga103.jf.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> X-Spam-Status: No, score=-4.5 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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) -- 2.17.1