Received: by 2002:a05:7412:40d:b0:e2:908c:2ebd with SMTP id 13csp503330rdf; Tue, 21 Nov 2023 08:19:13 -0800 (PST) X-Google-Smtp-Source: AGHT+IEuRNUNhZhBOXSLSd8NeMVY/rXIyyeR7BDKyt5BTLflqtSB6twSCcdHdPU2k6O6PT127UJ5 X-Received: by 2002:a05:6a20:440b:b0:18a:e7cf:7be with SMTP id ce11-20020a056a20440b00b0018ae7cf07bemr2464227pzb.52.1700583553156; Tue, 21 Nov 2023 08:19:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700583553; cv=none; d=google.com; s=arc-20160816; b=tDnd6Rl4QIfiGgJbEK4+txjLc+CcpyyLYVAaOWjRAMHxnhcrOsuCYL8QeiFMAKLeqr J8bYo9DEEYJ/JaCqKIcHOh8oNq9+d5ipRt9JxxgUMZszLwe5mJjMyORLjtvZAWZfLRHu tJLN6p5b71csTQE+fUaW/v12vn5JrEXfOrbKnHAO0HaenzRWd3QYdk2bDLdBvrnX/aCi EMHQUiO4hu0e4e0AZvVixjGDLsNMLXPn2RiiDMZaIseh96+hzV8Kbe9KN5JyQDbt1AD8 TgBRhWTHH8el4qF2X/UvaVavMNSWqRScEyEzKW4awnojP6ouozd3OM7wcQq63Pfjn6+v 6/4Q== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=WFqNUgYlEmeyI2jMz7oftmQGDudnV4XcWjYIJzI7HY0=; fh=srb/EijQIrMEdOeqn3qQX6qrsAGyqHAqeSFkl/qDdLM=; b=nWPTNvKsHm2o3HXkKbYaN1lhFKAN5/GbEMYy4rkrXWsxkQKGhgCBvH6833yWg8sLrt lHnmNEyciMRWYevh2b7udVGSxPGgK6Y7B4Mo4bJSpowvaVQL4MKqZOEBsjEA8eUNEfzK XsZN6mGXvzOuxTEYUaSabuDb788aLjkDkPW80T1V2cqUPx/pk+VLCKMWa4MBPL4SGeVx v+Au59KW+fh/Pqp+4oSEKaOaHGRCMqzapFrwur7uOxR15wbPjbSjSUTPbbdIx25qEmm2 DSRjTB4fcE8oK9i3PPbhUSqr19UDUeVZdcCWjSmxIIDEBuf9SP15saPt13zb+ssHtMxA ooPQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=hwSMC2wp; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from groat.vger.email (groat.vger.email. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id z123-20020a633381000000b005c1b2ca8915si11062710pgz.331.2023.11.21.08.19.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Nov 2023 08:19:13 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) client-ip=2620:137:e000::3:5; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=hwSMC2wp; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id 416F48078CA8; Tue, 21 Nov 2023 08:19:10 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230464AbjKUQTE (ORCPT + 99 others); Tue, 21 Nov 2023 11:19:04 -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: 8bit X-Spam-Status: No, score=-1.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Tue, 21 Nov 2023 08:19:10 -0800 (PST) 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 --- 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/pgtable.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_area_struct *vma, return ptep_test_and_clear_young(vma, address, ptep); } +#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) { -- 2.42.0