From nobody Wed Dec 17 22:58:03 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D3691C61D90 for ; Tue, 21 Nov 2023 16:19:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231210AbjKUQTF (ORCPT ); Tue, 21 Nov 2023 11:19:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43874 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230348AbjKUQTD (ORCPT ); Tue, 21 Nov 2023 11:19:03 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6C8E3112 for ; Tue, 21 Nov 2023 08:19:00 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CDA4FC433C8; Tue, 21 Nov 2023 16:18:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1700583540; bh=+NPX7FyBwDK3KyfbI/LU1WpPwCOApvDfHFYotMW+iEQ=; h=From:To:Cc:Subject:Date:From; b=hwSMC2wphiYqVQTwwY7y4jEPXdini07VezqwCyCKhS31YxQKVmd9qNUlNElupHfWL hSu1OAR8NlVtmKi1Pawxe6gvzMrwlXmMRfiDmrhdyREeY3ByVllyqMVsDDeTvXKXGW r4ZvU71anuIdaRU4IjH1cr3A7cO4oSyEqvkWMgE+NtrY+Xe820ZQzvsxKG8t/Jaa28 gAAjpqSeuNfAnLzRF+agtkbFk0DeJCo6Fi2HDOJtz4Sc1hvWRvI1wRmSRTZxbFRCG4 DJ5/ZcSsAoHnyFhzEUfHgXPBOdBD+uq547K2rj8ENsoeb3WXTPHVqZ3xcLNGrQXTZn HVkf/EjKwexiA== From: Jisheng Zhang To: Paul Walmsley , Palmer Dabbelt , Albert Ou Cc: linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH] riscv: mm: implement pgprot_nx Date: Wed, 22 Nov 2023 00:06:37 +0800 Message-Id: <20231121160637.3856-1-jszhang@kernel.org> X-Mailer: git-send-email 2.40.0 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" commit cca98e9f8b5e ("mm: enforce that vmap can't map pages executable") enforces the W^X protection by not allowing remapping existing pages as executable. Add riscv bits so that riscv can benefit the same protection. Signed-off-by: Jisheng Zhang Reviewed-by: Alexandre Ghiti Reviewed-by: Christoph Hellwig Reviewed-by: Samuel Holland Tested-by: Samuel Holland --- arch/riscv/include/asm/pgtable.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/arch/riscv/include/asm/pgtable.h b/arch/riscv/include/asm/pgta= ble.h index 294044429e8e..4fc6ee5226fb 100644 --- a/arch/riscv/include/asm/pgtable.h +++ b/arch/riscv/include/asm/pgtable.h @@ -608,6 +608,12 @@ static inline int ptep_clear_flush_young(struct vm_are= a_struct *vma, return ptep_test_and_clear_young(vma, address, ptep); } =20 +#define pgprot_nx pgprot_nx +static inline pgprot_t pgprot_nx(pgprot_t _prot) +{ + return __pgprot(pgprot_val(_prot) & ~_PAGE_EXEC); +} + #define pgprot_noncached pgprot_noncached static inline pgprot_t pgprot_noncached(pgprot_t _prot) { --=20 2.42.0