From patchwork Thu Jan 25 14:58:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jisheng Zhang X-Patchwork-Id: 192133 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:e09d:b0:103:945f:af90 with SMTP id gm29csp48521dyb; Thu, 25 Jan 2024 07:22:18 -0800 (PST) X-Google-Smtp-Source: AGHT+IG9D5BvWli2kKvua3/HgUPnJaf08Wh/prHyO49LlIGRNp9splFzlYTLo96WlEhnadVEA1zC X-Received: by 2002:a05:6e02:68c:b0:360:a3fd:1493 with SMTP id o12-20020a056e02068c00b00360a3fd1493mr1374867ils.42.1706196138199; Thu, 25 Jan 2024 07:22:18 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706196138; cv=pass; d=google.com; s=arc-20160816; b=w+K8D0rr6B4JxgvWi2K+cqx9Oe9zlu+h5m4udS/KnCxMtIL6ICum/AAE0Gclqvb8Op mTdffa9Pl6qQtK1QHX6fUQkMBgQPuZqch5JWk1nPiQGhL7RmoUzdENLt0hAb5jNLKa72 UXFcDiv6htLp/id9RIH5XzeahZfsRng7em5608iHRr7/0czyxQs/oH8ymQvuEScyZ+EM ecF2rN31tLEdom86sI1OxZlG6e+oRmUWqv60DuF0cGcUNlmpK4LKBIAgY/IHUa1o3M+d 8jPwh/5z7OP2j3MT7pmnBNLaxm6V9lEHVy1hAHskJYJqtoFK2Ylebqt8SGZLv5AfOD66 0hjQ== 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:date:subject:cc:to :from:dkim-signature; bh=muOJuvhRyB2KU2OmrhvdAVcdYv62QvF8+MusI68b6Lk=; fh=Owy+qTVqGN9gnI22GfT3FpCnMspYP1OOd7whkMle+3w=; b=B+Ue7gTFNwMyxO2TSGgiS+ZIuyNyCpHK9OfPD3q704pF3ifpEKEU6fcbjW6/1tQWDA 7V+gzy8uOHn3+Q7EashBlOK4AGNMjTy3pcTzyHvTCghjliRouZL6q5Hnq/b6pMmc81lu K88fDXc25ChHDEf0QPXHGmjAiNqrgrNZZfzFJK6nGq2b5QZqgunb2EGTkhgwwltz1cMJ 5kuAuybwfYr/ZPrzC5gFXUWPWG9RzAoiRD9UHlnzbFHSro/8YV4al1Y3IGEprOFdsc2i O9on/Ry9YkcEhKX4S06byKWdtmD6cmX9eKWJpCwudQkPgsDbzx1q0FyUN8wdHTfdYON+ 8FmA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Ij1pUEAQ; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-38798-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-38798-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id b11-20020a655ccb000000b005cdfd6f30a0si13423686pgt.748.2024.01.25.07.22.17 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Jan 2024 07:22:18 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-38798-ouuuleilei=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=@kernel.org header.s=k20201202 header.b=Ij1pUEAQ; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-38798-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-38798-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=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 8E0F1B238E7 for ; Thu, 25 Jan 2024 15:11:15 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1516C6EB70; Thu, 25 Jan 2024 15:10:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Ij1pUEAQ" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7C3CF6E2C9 for ; Thu, 25 Jan 2024 15:10:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706195455; cv=none; b=YB4C3RzlHwka7FdbgObfuvkKLXH1KyO3uOyGxaRpm0qa9zKejovjRVlUOFq+39TeMnblrNvigTF7jtLp7CaT8IDJE6qQHrkdfPCfIZRaRvXYN+5tBDv/jK3SB5I2hQ77jYxNdOzlfVLTepyDRn6JDxZka0cx0W9zQ1sY2oste7M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706195455; c=relaxed/simple; bh=aiagvA75HtW5poT6xWiLeVnkWkTmbI5Tbf6wRBi0vHw=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=Os1aHSOYUIuhz1ooiWkK0vby/xkB80fuGorsktWd791fNgTYqYyznQYyO7B8vOXphIIWTHxdOdrB83I4NAk0ac2Pv5127/eQWMEdqVaJLvs+gQ2BD+mMa0MN82UTDFmG3vGyt2Amo+upoDyl1lTOxe1H+J0fZ9DxloO+nf2o5ro= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Ij1pUEAQ; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3394CC433C7; Thu, 25 Jan 2024 15:10:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1706195455; bh=aiagvA75HtW5poT6xWiLeVnkWkTmbI5Tbf6wRBi0vHw=; h=From:To:Cc:Subject:Date:From; b=Ij1pUEAQqNLvjJQFRqvQCVYs/CBS9MkCzvkpTxre4q0x05oixWvMoB4acBW5xjCxU rWNbwMb04w6sj36leFQHmm9IYNesSR8Hs8/3EvGy7ZWf61z0/i/7NcJZSGXlvUFlpZ EM52ul/U0h7BqugeRktj6OFfeflFxBN/4oqNrBAjFMQcibapWIdttHHPl9IVz+TPO/ bAOXsB2FescT/oFQWxOZ5Ee7U9ZUgTHFqOes+UrO+2XFBRocCW2RUxHt9P3SkTJkYy 1rr5HnEdhdU0OK/p8PbpvLFCSdnzuYMT25ou4uslnTTA7t8d7iQi1+Zfv1wRDeUQHp QDOJ+f4e+y4aA== From: Jisheng Zhang To: Paul Walmsley , Palmer Dabbelt , Albert Ou Cc: linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, Christoph Hellwig , Samuel Holland , Alexandre Ghiti Subject: [PATCH v2] riscv: mm: implement pgprot_nx Date: Thu, 25 Jan 2024 22:58:06 +0800 Message-ID: <20240125145806.933-1-jszhang@kernel.org> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789076322051014419 X-GMAIL-MSGID: 1789076322051014419 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: Christoph Hellwig Reviewed-by: Samuel Holland Tested-by: Samuel Holland Reviewed-by: Alexandre Ghiti --- since v1: - rebase on v6.8-rc1 - collect Reviewed-by and Tested-by tag 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 0c94260b5d0c..c931863bbd1a 100644 --- a/arch/riscv/include/asm/pgtable.h +++ b/arch/riscv/include/asm/pgtable.h @@ -591,6 +591,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) {