Received: by 2002:ab2:6991:0:b0:1f2:fff1:ace7 with SMTP id v17csp165681lqo; Wed, 27 Mar 2024 09:34:42 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCU6P1DzPYS00BEGcRFdNqCusAQtnZt3zY5Z+HAHio44ryWT4+km69K+dKSfV0mihQsAkbpVfz43rP8cXccPr+d0jJFC85WHr7ZGPm1tFw== X-Google-Smtp-Source: AGHT+IF3qXvTPECWKnznHKsh7mLQULkYV0PWLSUBCQPJFZdNSuQ05XAHXM4bruexvidf/Ioldjk/ X-Received: by 2002:a05:6a20:2446:b0:1a5:6a21:cd47 with SMTP id t6-20020a056a20244600b001a56a21cd47mr95766pzc.6.1711557281968; Wed, 27 Mar 2024 09:34:41 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711557281; cv=pass; d=google.com; s=arc-20160816; b=tuGxsgmYTlYHSL2eJwgYHV9+43cgINeQpALdYHxjALaQoWGT23f2cYfIgLQ4xcZVLv oyGPHS+DqT4F1yAyfwdgr0p35wC5xPVGsKm8/dM0rlPYv6qqG/AX3aTFc+WlpB7cdvgD Jrdh75ycmRZPyhVyvwQxwx1lBh4nXufaGHFQcbbjNHxs5momYaNlLH7jN/c6KN5PsOqF XXmqH2K9C4vTYXH/BXBgX3uH6eZ4O36z4JqGCb6tnToTlYJEuV2bctmvDyvh8+mwYDjh GRPr5U9Gwn0Z+6kxm2R3YBYhSiLYfnyFapNGe/Um8biki3ZEw9micM6tU6DaeGhZmWeA 5QBw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:to:from:cc:in-reply-to :subject:date:dkim-signature; bh=62e02ZJiOBiUx9nE4yZd2VXfIcaCZ5n4EKmL0LL89oM=; fh=d2RQ/gvzRx/IRR/KSL1/fec0BQ3/8w3WgLCSpCM4NXU=; b=j+GRDblZohhxI+zxbRJ/BbsrFw0AQtp8zmpSMC0IHyW+mhCbD0ci3jyu3odB1gtnto 9YDkomUQbisW3coSyvhlQa+k/1HUgTjIucfYV5Ba1QqYK8mgpxI9a4FUdD8E0V2YGVHw +Lq7an4eRFoq2Y2tspv87zOGOcAURlJTFwc2u5aroyVqV/i3i4OxXjcZk9HiFPOcLxUw VpnMMjnj/w4nDbm7JRI19ZNozErNpivk8hsX461q6ApJ611ULmpzD4fQRXizN1IZ/JkM RCcLAeQnuBBASWhceh4Mq7ovnzm2FXOA6GZvBepbpaUBsZ+RCQ4K0zNDZMlElxVO+jaU dj0w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@dabbelt-com.20230601.gappssmtp.com header.s=20230601 header.b="MpO8/+GA"; arc=pass (i=1 spf=pass spfdomain=dabbelt.com dkim=pass dkdomain=dabbelt-com.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-121449-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-121449-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id b2-20020a62cf02000000b006ea8cb1b66dsi9637294pfg.66.2024.03.27.09.34.41 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Mar 2024 09:34:41 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-121449-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@dabbelt-com.20230601.gappssmtp.com header.s=20230601 header.b="MpO8/+GA"; arc=pass (i=1 spf=pass spfdomain=dabbelt.com dkim=pass dkdomain=dabbelt-com.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-121449-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-121449-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 5C259B33F87 for ; Wed, 27 Mar 2024 15:11:37 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2E34013A3EC; Wed, 27 Mar 2024 14:38:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=dabbelt-com.20230601.gappssmtp.com header.i=@dabbelt-com.20230601.gappssmtp.com header.b="MpO8/+GA" Received: from mail-pf1-f170.google.com (mail-pf1-f170.google.com [209.85.210.170]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6F27212BEA5 for ; Wed, 27 Mar 2024 14:38:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.170 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711550290; cv=none; b=NLJnvdziIwBMVtWIYuOMnX0e2jszkweYPfBntqlttgzuk82+EA0NP9UNks9b7sJgMurrrrz4WL0IW5Fhc3CVHupyz8thSqPLMwNiUl2pytPIJGx4nzAKIaYmPeUMlZ8buq29Q5K1WBjUPAn/cihPkPrXVS+JuVkHbfCu00d061c= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711550290; c=relaxed/simple; bh=OqfsbWxJhB0KkgW/C4LbkHCHdj0o/wX9MgKrtRP9oeU=; h=Date:Subject:In-Reply-To:CC:From:To:Message-ID:Mime-Version: Content-Type; b=Cg3mZNshAkMG3V9ThLd96yfs992vOj9yrw+U1TVcAVZLX0CKk/TMTkrBP3ALkw0O4aHD5SQroHNZWzHdkoBgHCW85W9+uiTx+h9mnUl29Csl18LHkQsJopueS2XigWueAGkRTezQd7o+jyHZ5YpNp3TbUl5T09cTrMvnfj1IYtU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=dabbelt.com; spf=pass smtp.mailfrom=dabbelt.com; dkim=pass (2048-bit key) header.d=dabbelt-com.20230601.gappssmtp.com header.i=@dabbelt-com.20230601.gappssmtp.com header.b=MpO8/+GA; arc=none smtp.client-ip=209.85.210.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=dabbelt.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=dabbelt.com Received: by mail-pf1-f170.google.com with SMTP id d2e1a72fcca58-6e6ca2ac094so5882377b3a.0 for ; Wed, 27 Mar 2024 07:38:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dabbelt-com.20230601.gappssmtp.com; s=20230601; t=1711550288; x=1712155088; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:to:from:cc :in-reply-to:subject:date:from:to:cc:subject:date:message-id :reply-to; bh=62e02ZJiOBiUx9nE4yZd2VXfIcaCZ5n4EKmL0LL89oM=; b=MpO8/+GAwdzGQSlhNxNvMpYV/Hv1iLuJGlG3Xeaw3f2+UUG03o1AK87oSB7MHWezOC ZliYIzjVrX2TUKNGBTQj+/ntbdLPWumFuz+jFvrTadBPAV1X5T3W4t0nrPxXvCP0bVwn MdmxwpCTbkAquOsBe/Lc7XXefkqqcbVFNSuLm1g7menTAQRJQiyZZlvgQfB4+yjVUjtl LWrH+QwcZzC+SV6FupX7tjgr70uaeCffyONmwoxleqXb7gnG5J5kIWI1+dnf5dQ+AUtM vb9ZxaIJta54Q7Jnsoh2NqfOPYSRehcN8VwEmmLlHANGVaH9G7aiJdpLhUulJYQpDCf4 Lk/w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711550288; x=1712155088; h=content-transfer-encoding:mime-version:message-id:to:from:cc :in-reply-to:subject:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=62e02ZJiOBiUx9nE4yZd2VXfIcaCZ5n4EKmL0LL89oM=; b=re392Cx2Y6DbFgpIXZIyLf3Tl3++rGjDbMaJeTMc/pFYQDqh9iQVkvcADTXUztq3Xf SV+MMTHcxY9AGS15zh+dOBEVvJDWdqjTsc4Sew/T4PdVMVWuyS95PXrs9/mL18RjjmtG w0yPOlRW3IJpOtF/qLOvyHMnSX7tZa6u89o7to5H9DCct4xQYNvctRLkY7mKVe9YrsAl RPau45dyAcoKKP9C/OjaYF0eOrcd8IA4/LYtNTgAoLvNO2DXDf84oYWPEHJskdCk29oh 6/dek9Hx3c7uOfol1XcIKnn6XW7GdlMSfWi4OriDt5Qgvxm9f6LX0LpawLM8h+PNH1z3 x4jA== X-Forwarded-Encrypted: i=1; AJvYcCUxzjKI+bs0CnQLetWg/50QLFJDdY2pCaVINPYKsARzXCFaffGf6S5VfeJo6tTlmVFQdyBpb7Uqp3/9Nyvy1xDOQyFTg5wqwW8aZfmT X-Gm-Message-State: AOJu0YydsKMb6lCvMEWifYKS3MmePJejk8QWohdOzVnnjTvKN19WreyB lBbetgTeZ4Ov/vIfrx90uHt6V8GNJjgACfF1t29F9p4CGRgW/cSqmwsFuDjN6u8= X-Received: by 2002:a05:6a00:14d3:b0:6ea:acbe:517a with SMTP id w19-20020a056a0014d300b006eaacbe517amr1635574pfu.16.1711550287270; Wed, 27 Mar 2024 07:38:07 -0700 (PDT) Received: from localhost ([192.184.165.199]) by smtp.gmail.com with ESMTPSA id c14-20020a056a000ace00b006eab60bca64sm4144777pfl.177.2024.03.27.07.38.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Mar 2024 07:38:06 -0700 (PDT) Date: Wed, 27 Mar 2024 07:38:06 -0700 (PDT) X-Google-Original-Date: Wed, 27 Mar 2024 07:38:05 PDT (-0700) Subject: Re: [PATCH v2 2/5] arm64, powerpc, riscv, s390, x86: ptdump: Refactor CONFIG_DEBUG_WX In-Reply-To: CC: akpm@linux-foundation.org, keescook@chromium.org, christophe.leroy@csgroup.eu, linux@armlinux.org.uk, Catalin Marinas , Will Deacon , mpe@ellerman.id.au, npiggin@gmail.com, aneesh.kumar@kernel.org, naveen.n.rao@linux.ibm.com, Paul Walmsley , aou@eecs.berkeley.edu, hca@linux.ibm.com, gor@linux.ibm.com, agordeev@linux.ibm.com, borntraeger@linux.ibm.com, svens@linux.ibm.com, gerald.schaefer@linux.ibm.com, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org, hpa@zytor.com, luto@kernel.org, peterz@infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-riscv@lists.infradead.org, linux-s390@vger.kernel.org, linux-mm@kvack.org, steven.price@arm.com, tranmanphong@gmail.com, Mark Rutland , greg@kroah.com, alexghiti@rivosinc.com From: Palmer Dabbelt To: christophe.leroy@csgroup.eu Message-ID: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 (MHng) Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit On Tue, 30 Jan 2024 02:34:33 PST (-0800), christophe.leroy@csgroup.eu wrote: > All architectures using the core ptdump functionality also implement > CONFIG_DEBUG_WX, and they all do it more or less the same way, with a > function called debug_checkwx() that is called by mark_rodata_ro(), > which is a substitute to ptdump_check_wx() when CONFIG_DEBUG_WX is > set and a no-op otherwise. > > Refactor by centraly defining debug_checkwx() in linux/ptdump.h and > call debug_checkwx() immediately after calling mark_rodata_ro() > instead of calling it at the end of every mark_rodata_ro(). > > On x86_32, mark_rodata_ro() first checks __supported_pte_mask has > _PAGE_NX before calling debug_checkwx(). Now the check is inside the > callee ptdump_walk_pgd_level_checkwx(). > > On powerpc_64, mark_rodata_ro() bails out early before calling > ptdump_check_wx() when the MMU doesn't have KERNEL_RO feature. The > check is now also done in ptdump_check_wx() as it is called outside > mark_rodata_ro(). > > Signed-off-by: Christophe Leroy > Reviewed-by: Alexandre Ghiti > --- > v2: For x86 change macro ptdump_check_wx() to ptdump_check_wx > --- > arch/arm64/include/asm/ptdump.h | 7 ------- > arch/arm64/mm/mmu.c | 2 -- > arch/powerpc/mm/mmu_decl.h | 6 ------ > arch/powerpc/mm/pgtable_32.c | 4 ---- > arch/powerpc/mm/pgtable_64.c | 3 --- > arch/powerpc/mm/ptdump/ptdump.c | 3 +++ > arch/riscv/include/asm/ptdump.h | 22 ---------------------- > arch/riscv/mm/init.c | 3 --- > arch/riscv/mm/ptdump.c | 1 - > arch/s390/include/asm/ptdump.h | 14 -------------- > arch/s390/mm/dump_pagetables.c | 1 - > arch/s390/mm/init.c | 2 -- > arch/x86/include/asm/pgtable.h | 3 +-- > arch/x86/mm/dump_pagetables.c | 3 +++ > arch/x86/mm/init_32.c | 2 -- > arch/x86/mm/init_64.c | 2 -- > include/linux/ptdump.h | 7 +++++++ > init/main.c | 2 ++ > 18 files changed, 16 insertions(+), 71 deletions(-) > delete mode 100644 arch/riscv/include/asm/ptdump.h > delete mode 100644 arch/s390/include/asm/ptdump.h > > diff --git a/arch/arm64/include/asm/ptdump.h b/arch/arm64/include/asm/ptdump.h > index 581caac525b0..5b1701c76d1c 100644 > --- a/arch/arm64/include/asm/ptdump.h > +++ b/arch/arm64/include/asm/ptdump.h > @@ -29,13 +29,6 @@ void __init ptdump_debugfs_register(struct ptdump_info *info, const char *name); > static inline void ptdump_debugfs_register(struct ptdump_info *info, > const char *name) { } > #endif > -void ptdump_check_wx(void); > #endif /* CONFIG_PTDUMP_CORE */ > > -#ifdef CONFIG_DEBUG_WX > -#define debug_checkwx() ptdump_check_wx() > -#else > -#define debug_checkwx() do { } while (0) > -#endif > - > #endif /* __ASM_PTDUMP_H */ > diff --git a/arch/arm64/mm/mmu.c b/arch/arm64/mm/mmu.c > index 1ac7467d34c9..3a27d887f7dd 100644 > --- a/arch/arm64/mm/mmu.c > +++ b/arch/arm64/mm/mmu.c > @@ -632,8 +632,6 @@ void mark_rodata_ro(void) > section_size = (unsigned long)__init_begin - (unsigned long)__start_rodata; > update_mapping_prot(__pa_symbol(__start_rodata), (unsigned long)__start_rodata, > section_size, PAGE_KERNEL_RO); > - > - debug_checkwx(); > } > > static void __init map_kernel_segment(pgd_t *pgdp, void *va_start, void *va_end, > diff --git a/arch/powerpc/mm/mmu_decl.h b/arch/powerpc/mm/mmu_decl.h > index 72341b9fb552..90dcc2844056 100644 > --- a/arch/powerpc/mm/mmu_decl.h > +++ b/arch/powerpc/mm/mmu_decl.h > @@ -171,12 +171,6 @@ static inline void mmu_mark_rodata_ro(void) { } > void __init mmu_mapin_immr(void); > #endif > > -#ifdef CONFIG_DEBUG_WX > -void ptdump_check_wx(void); > -#else > -static inline void ptdump_check_wx(void) { } > -#endif > - > static inline bool debug_pagealloc_enabled_or_kfence(void) > { > return IS_ENABLED(CONFIG_KFENCE) || debug_pagealloc_enabled(); > diff --git a/arch/powerpc/mm/pgtable_32.c b/arch/powerpc/mm/pgtable_32.c > index 5c02fd08d61e..12498017da8e 100644 > --- a/arch/powerpc/mm/pgtable_32.c > +++ b/arch/powerpc/mm/pgtable_32.c > @@ -153,7 +153,6 @@ void mark_rodata_ro(void) > > if (v_block_mapped((unsigned long)_stext + 1)) { > mmu_mark_rodata_ro(); > - ptdump_check_wx(); > return; > } > > @@ -166,9 +165,6 @@ void mark_rodata_ro(void) > PFN_DOWN((unsigned long)_stext); > > set_memory_ro((unsigned long)_stext, numpages); > - > - // mark_initmem_nx() should have already run by now > - ptdump_check_wx(); > } > #endif > > diff --git a/arch/powerpc/mm/pgtable_64.c b/arch/powerpc/mm/pgtable_64.c > index 5ac1fd30341b..1b366526f4f2 100644 > --- a/arch/powerpc/mm/pgtable_64.c > +++ b/arch/powerpc/mm/pgtable_64.c > @@ -150,9 +150,6 @@ void mark_rodata_ro(void) > radix__mark_rodata_ro(); > else > hash__mark_rodata_ro(); > - > - // mark_initmem_nx() should have already run by now > - ptdump_check_wx(); > } > > void mark_initmem_nx(void) > diff --git a/arch/powerpc/mm/ptdump/ptdump.c b/arch/powerpc/mm/ptdump/ptdump.c > index 2313053fe679..620d4917ebe8 100644 > --- a/arch/powerpc/mm/ptdump/ptdump.c > +++ b/arch/powerpc/mm/ptdump/ptdump.c > @@ -343,6 +343,9 @@ void ptdump_check_wx(void) > } > }; > > + if (IS_ENABLED(CONFIG_PPC_BOOK3S_64) && !mmu_has_feature(MMU_FTR_KERNEL_RO)) > + return; > + > ptdump_walk_pgd(&st.ptdump, &init_mm, NULL); > > if (st.wx_pages) > diff --git a/arch/riscv/include/asm/ptdump.h b/arch/riscv/include/asm/ptdump.h > deleted file mode 100644 > index 3c9ea6dd5af7..000000000000 > --- a/arch/riscv/include/asm/ptdump.h > +++ /dev/null > @@ -1,22 +0,0 @@ > -/* SPDX-License-Identifier: GPL-2.0 */ > -/* > - * Copyright (C) 2019 SiFive > - */ > - > -#ifndef _ASM_RISCV_PTDUMP_H > -#define _ASM_RISCV_PTDUMP_H > - > -void ptdump_check_wx(void); > - > -#ifdef CONFIG_DEBUG_WX > -static inline void debug_checkwx(void) > -{ > - ptdump_check_wx(); > -} > -#else > -static inline void debug_checkwx(void) > -{ > -} > -#endif > - > -#endif /* _ASM_RISCV_PTDUMP_H */ > diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c > index 32cad6a65ccd..c5c69f38d11e 100644 > --- a/arch/riscv/mm/init.c > +++ b/arch/riscv/mm/init.c > @@ -29,7 +29,6 @@ > #include > #include > #include > -#include > #include > #include > #include > @@ -723,8 +722,6 @@ void mark_rodata_ro(void) > if (IS_ENABLED(CONFIG_64BIT)) > set_kernel_memory(lm_alias(__start_rodata), lm_alias(_data), > set_memory_ro); > - > - debug_checkwx(); > } > #else > static __init pgprot_t pgprot_from_va(uintptr_t va) > diff --git a/arch/riscv/mm/ptdump.c b/arch/riscv/mm/ptdump.c > index 657c27bc07a7..075265603313 100644 > --- a/arch/riscv/mm/ptdump.c > +++ b/arch/riscv/mm/ptdump.c > @@ -9,7 +9,6 @@ > #include > #include > > -#include > #include > #include > > diff --git a/arch/s390/include/asm/ptdump.h b/arch/s390/include/asm/ptdump.h > deleted file mode 100644 > index f960b2896606..000000000000 > --- a/arch/s390/include/asm/ptdump.h > +++ /dev/null > @@ -1,14 +0,0 @@ > -/* SPDX-License-Identifier: GPL-2.0 */ > - > -#ifndef _ASM_S390_PTDUMP_H > -#define _ASM_S390_PTDUMP_H > - > -void ptdump_check_wx(void); > - > -static inline void debug_checkwx(void) > -{ > - if (IS_ENABLED(CONFIG_DEBUG_WX)) > - ptdump_check_wx(); > -} > - > -#endif /* _ASM_S390_PTDUMP_H */ > diff --git a/arch/s390/mm/dump_pagetables.c b/arch/s390/mm/dump_pagetables.c > index d37a8f607b71..8dcb4e0c71bd 100644 > --- a/arch/s390/mm/dump_pagetables.c > +++ b/arch/s390/mm/dump_pagetables.c > @@ -6,7 +6,6 @@ > #include > #include > #include > -#include > #include > #include > #include > diff --git a/arch/s390/mm/init.c b/arch/s390/mm/init.c > index 43e612bc2bcd..d2e5eff9d1de 100644 > --- a/arch/s390/mm/init.c > +++ b/arch/s390/mm/init.c > @@ -37,7 +37,6 @@ > #include > #include > #include > -#include > #include > #include > #include > @@ -109,7 +108,6 @@ void mark_rodata_ro(void) > > __set_memory_ro(__start_ro_after_init, __end_ro_after_init); > pr_info("Write protected read-only-after-init data: %luk\n", size >> 10); > - debug_checkwx(); > } > > int set_memory_encrypted(unsigned long vaddr, int numpages) > diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h > index 9d077bca6a10..6c979028e521 100644 > --- a/arch/x86/include/asm/pgtable.h > +++ b/arch/x86/include/asm/pgtable.h > @@ -32,6 +32,7 @@ void ptdump_walk_pgd_level(struct seq_file *m, struct mm_struct *mm); > void ptdump_walk_pgd_level_debugfs(struct seq_file *m, struct mm_struct *mm, > bool user); > void ptdump_walk_pgd_level_checkwx(void); > +#define ptdump_check_wx ptdump_walk_pgd_level_checkwx > void ptdump_walk_user_pgd_level_checkwx(void); > > /* > @@ -41,10 +42,8 @@ void ptdump_walk_user_pgd_level_checkwx(void); > #define pgprot_decrypted(prot) __pgprot(cc_mkdec(pgprot_val(prot))) > > #ifdef CONFIG_DEBUG_WX > -#define debug_checkwx() ptdump_walk_pgd_level_checkwx() > #define debug_checkwx_user() ptdump_walk_user_pgd_level_checkwx() > #else > -#define debug_checkwx() do { } while (0) > #define debug_checkwx_user() do { } while (0) > #endif > > diff --git a/arch/x86/mm/dump_pagetables.c b/arch/x86/mm/dump_pagetables.c > index e1b599ecbbc2..0008524eebe9 100644 > --- a/arch/x86/mm/dump_pagetables.c > +++ b/arch/x86/mm/dump_pagetables.c > @@ -433,6 +433,9 @@ void ptdump_walk_user_pgd_level_checkwx(void) > > void ptdump_walk_pgd_level_checkwx(void) > { > + if (!(__supported_pte_mask & _PAGE_NX)) > + return; > + > ptdump_walk_pgd_level_core(NULL, &init_mm, INIT_PGD, true, false); > } > > diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c > index b63403d7179d..5c736b707cae 100644 > --- a/arch/x86/mm/init_32.c > +++ b/arch/x86/mm/init_32.c > @@ -800,6 +800,4 @@ void mark_rodata_ro(void) > set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT); > #endif > mark_nxdata_nx(); > - if (__supported_pte_mask & _PAGE_NX) > - debug_checkwx(); > } > diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c > index a0dffaca6d2b..ebdbcae48011 100644 > --- a/arch/x86/mm/init_64.c > +++ b/arch/x86/mm/init_64.c > @@ -1412,8 +1412,6 @@ void mark_rodata_ro(void) > (void *)text_end, (void *)rodata_start); > free_kernel_image_pages("unused kernel image (rodata/data gap)", > (void *)rodata_end, (void *)_sdata); > - > - debug_checkwx(); > } > > /* > diff --git a/include/linux/ptdump.h b/include/linux/ptdump.h > index 2a3a95586425..c10513739bf9 100644 > --- a/include/linux/ptdump.h > +++ b/include/linux/ptdump.h > @@ -19,5 +19,12 @@ struct ptdump_state { > }; > > void ptdump_walk_pgd(struct ptdump_state *st, struct mm_struct *mm, pgd_t *pgd); > +void ptdump_check_wx(void); > + > +static inline void debug_checkwx(void) > +{ > + if (IS_ENABLED(CONFIG_DEBUG_WX)) > + ptdump_check_wx(); > +} > > #endif /* _LINUX_PTDUMP_H */ > diff --git a/init/main.c b/init/main.c > index e24b0780fdff..749a9f8d2c9b 100644 > --- a/init/main.c > +++ b/init/main.c > @@ -99,6 +99,7 @@ > #include > #include > #include > +#include > #include > > #include > @@ -1408,6 +1409,7 @@ static void mark_readonly(void) > */ > rcu_barrier(); > mark_rodata_ro(); > + debug_checkwx(); > rodata_test(); > } else > pr_info("Kernel memory protection disabled.\n"); Acked-by: Palmer Dabbelt # RISC-V