From patchwork Thu Sep 12 23:16:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Deepak Gupta X-Patchwork-Id: 13802835 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id A086DEEE272 for ; Thu, 12 Sep 2024 23:18:02 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 331F36B00A7; Thu, 12 Sep 2024 19:18:02 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2B8C56B00A8; Thu, 12 Sep 2024 19:18:02 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0E59A6B00A9; Thu, 12 Sep 2024 19:18:02 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id DE5CA6B00A7 for ; Thu, 12 Sep 2024 19:18:01 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 94E44A882B for ; Thu, 12 Sep 2024 23:18:01 +0000 (UTC) X-FDA: 82557651162.15.C6C8223 Received: from mail-pg1-f178.google.com (mail-pg1-f178.google.com [209.85.215.178]) by imf16.hostedemail.com (Postfix) with ESMTP id BE74B180004 for ; Thu, 12 Sep 2024 23:17:59 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=ZbJXHfO7; spf=pass (imf16.hostedemail.com: domain of debug@rivosinc.com designates 209.85.215.178 as permitted sender) smtp.mailfrom=debug@rivosinc.com; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1726182973; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=KiNSEhiMyi/vclkP3i3QvX4mx663SI7U/pxriPsJ9Y4=; b=ZHFmBhNtLTpqWWUMIy1lgoUTBvJyLR04dgacmiLX9PKaFpTqjXJgcl7greNdwvI3WEhMnN facm+I6dZgeWRCJ+0rZrPwHYsjw0MnzRQ7Jr1VRx3eVw/O3mFt+25icUZegxvSbXZgnPd9 /fxl8+9kJS9cQiDBIPq2sKCjQZPKmdU= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1726182973; a=rsa-sha256; cv=none; b=aR2SNhRwZ051AiXi+HxPM0tv7sYaR0OIVimskWFdDPM3sn5ae/11JNYXDn9cXKGgrsXgaa vhlGrIMe9P5+YBZn0AOJvbNT1+Zz3scOn4eAdEwrt4B8mJM9ilnYVU341GcwtLOW29zd94 6spd8HUhrsr8LTI/KLlUUPN5mkKsF40= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=ZbJXHfO7; spf=pass (imf16.hostedemail.com: domain of debug@rivosinc.com designates 209.85.215.178 as permitted sender) smtp.mailfrom=debug@rivosinc.com; dmarc=none Received: by mail-pg1-f178.google.com with SMTP id 41be03b00d2f7-7c3d9a5e050so82432a12.2 for ; Thu, 12 Sep 2024 16:17:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1726183078; x=1726787878; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=KiNSEhiMyi/vclkP3i3QvX4mx663SI7U/pxriPsJ9Y4=; b=ZbJXHfO7qd7LwcwHzIupNCI44V3gQDiJszzevw/Z/MUhnCvazhVphP1cLm07+K8e/t hN3z0E7SM0fflaU8qMZo+7W6TUf9AQpVQLay/Xn6N59s57uRSiHx5Y6V8ywmNiXjqktO D8+5GGPisylr1sxB1MzJDk0pfrqSsN2uiJxVM1SasYdb0JqX0WL7pcBqrqA6qDoPPk/Y TXxHanvrBDwbUkFDw2dH6RM3CyPRMQA8qCGRV4qoqgndPkTOJMBBY8694xgXq3Auyoyz +5tsSeRLpQSj2yjHeC9Ozv6s43CJnajnkkv1xVu9IiBjGXyMVNmAXkzUfALc5Gbw44hN kzVA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726183078; x=1726787878; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=KiNSEhiMyi/vclkP3i3QvX4mx663SI7U/pxriPsJ9Y4=; b=Vms/IPgifn88CmzXrrA165UOqFz35u3AhRpLmU6OlrtUZVEI1mnlLIh+oclwDXLKAH ek8pQX3ONRKhW4LvqGx7VLZZfmKo3GQa+YlLEdN1WQghTfJNK/wuVj57E0a2C3zgwmpx DEH0iX6KuWmtg/hnYQl6ip20yPo9FI/5LY7gFAXv+nHMahH8LQPFnShOwindRJMjx3vO zZVp6P8fkRHsv0CtzfcF4l+WpIFof/SqJ0uywlZhlGaG8Pw6h84FB4zqM6YqZaU/RwnM xZQdpSfAJLfhD68Fau2tZJ95VmMVg99NTwK7vQ2NHIouG69M+fufCmzNk7JINjYeUaLb x6kQ== X-Forwarded-Encrypted: i=1; AJvYcCXG9hcg9+EQCOINSXXExbbAI/I1abSkCl5wyuxSbkyp/Wycwx8PGWW3fcqRT9+bSRMVudtPCW8ojA==@kvack.org X-Gm-Message-State: AOJu0Yz/iGDI7NgzDWVJTuNJ2XZttNCYFdCuOLn1qe3hUD3Lg+qv8NAo K+hEL1BaCPqlBG1rYkmQax0w5XsBotiwiqxSoibHpRwr4ktYu/BnsTA7fpo9POY= X-Google-Smtp-Source: AGHT+IF4e0NCjicspxUUMmlG4elk65ZCg5cB6xw18ixrBvYAVw02n2WNOur1Dg21kRqmRwms2SEZcA== X-Received: by 2002:a17:90a:fd04:b0:2c9:a3d4:f044 with SMTP id 98e67ed59e1d1-2db9ffbcbd4mr5139066a91.11.1726183078465; Thu, 12 Sep 2024 16:17:58 -0700 (PDT) Received: from debug.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2db6c1ac69asm3157591a91.0.2024.09.12.16.17.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Sep 2024 16:17:58 -0700 (PDT) From: Deepak Gupta To: paul.walmsley@sifive.com, palmer@sifive.com, conor@kernel.org, linux-doc@vger.kernel.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-arch@vger.kernel.org, linux-kselftest@vger.kernel.org Cc: corbet@lwn.net, palmer@dabbelt.com, aou@eecs.berkeley.edu, robh@kernel.org, krzk+dt@kernel.org, oleg@redhat.com, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org, hpa@zytor.com, peterz@infradead.org, akpm@linux-foundation.org, arnd@arndb.de, ebiederm@xmission.com, kees@kernel.org, Liam.Howlett@oracle.com, vbabka@suse.cz, lorenzo.stoakes@oracle.com, shuah@kernel.org, brauner@kernel.org, samuel.holland@sifive.com, debug@rivosinc.com, andy.chiu@sifive.com, jerry.shih@sifive.com, greentime.hu@sifive.com, charlie@rivosinc.com, evan@rivosinc.com, cleger@rivosinc.com, xiao.w.wang@intel.com, ajones@ventanamicro.com, anup@brainfault.org, mchitale@ventanamicro.com, atishp@rivosinc.com, sameo@rivosinc.com, bjorn@rivosinc.com, alexghiti@rivosinc.com, david@redhat.com, libang.li@antgroup.com, jszhang@kernel.org, leobras@redhat.com, guoren@kernel.org, samitolvanen@google.com, songshuaishuai@tinylab.org, costa.shul@redhat.com, bhe@redhat.com, zong.li@sifive.com, puranjay@kernel.org, namcaov@gmail.com, antonb@tenstorrent.com, sorear@fastmail.com, quic_bjorande@quicinc.com, ancientmodern4@gmail.com, ben.dooks@codethink.co.uk, quic_zhonhan@quicinc.com, cuiyunhui@bytedance.com, yang.lee@linux.alibaba.com, ke.zhao@shingroup.cn, sunilvl@ventanamicro.com, tanzhasanwork@gmail.com, schwab@suse.de, dawei.li@shingroup.cn, rppt@kernel.org, willy@infradead.org, usama.anjum@collabora.com, osalvador@suse.de, ryan.roberts@arm.com, andrii@kernel.org, alx@kernel.org, catalin.marinas@arm.com, broonie@kernel.org, revest@chromium.org, bgray@linux.ibm.com, deller@gmx.de, zev@bewilderbeest.net Subject: [PATCH v4 12/30] riscv mm: manufacture shadow stack pte Date: Thu, 12 Sep 2024 16:16:31 -0700 Message-ID: <20240912231650.3740732-13-debug@rivosinc.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240912231650.3740732-1-debug@rivosinc.com> References: <20240912231650.3740732-1-debug@rivosinc.com> MIME-Version: 1.0 X-Stat-Signature: da9cmgdf4kb9o68rcbz5e7crc4ig55hk X-Rspamd-Queue-Id: BE74B180004 X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1726183079-224342 X-HE-Meta: U2FsdGVkX18Aas100Xb9OqTjiqcK65chfvEaOFMtIIQZPCaa6uLBwNRyeBz9HcsueewhQWjUfYQv6+H6cup8NC+ZriGdy+KQACvOWrUAzDhpnrtelCA0JF28JmQrssW4hJf2SsUNRv1F5cidfbFtPk7HN51pvve8vzthpeh2s1TZRuaggUnPAj9o2Kv4eCUcP3sc/B/qkWcVPwKM5mhvkQvpeUgFFzaH+OQfhl+OT2qQwkHrmdUcl5xrU0g2F/bkYOu2ShYXnIlgtv5fIKj/QPwwtMQPcqryfS7VQboXKhJSvrzbQDSsZsZB1+alUrk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ZWrCCGLcY9uEO9o+vxBUmaCYtPLQ= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000002, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: This patch implements creating shadow stack pte (on riscv). Creating shadow stack PTE on riscv means that clearing RWX and then setting W=1. Signed-off-by: Deepak Gupta Reviewed-by: Alexandre Ghiti --- arch/riscv/include/asm/pgtable.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/arch/riscv/include/asm/pgtable.h b/arch/riscv/include/asm/pgtable.h index af4337774fe5..0b6c66fb853a 100644 --- a/arch/riscv/include/asm/pgtable.h +++ b/arch/riscv/include/asm/pgtable.h @@ -425,6 +425,11 @@ static inline pte_t pte_mkwrite_novma(pte_t pte) return __pte(pte_val(pte) | _PAGE_WRITE); } +static inline pte_t pte_mkwrite_shstk(pte_t pte) +{ + return __pte((pte_val(pte) & ~(_PAGE_LEAF)) | _PAGE_WRITE); +} + /* static inline pte_t pte_mkexec(pte_t pte) */ static inline pte_t pte_mkdirty(pte_t pte) @@ -732,6 +737,11 @@ static inline pmd_t pmd_mkwrite_novma(pmd_t pmd) return pte_pmd(pte_mkwrite_novma(pmd_pte(pmd))); } +static inline pmd_t pmd_mkwrite_shstk(pmd_t pte) +{ + return __pmd((pmd_val(pte) & ~(_PAGE_LEAF)) | _PAGE_WRITE); +} + static inline pmd_t pmd_wrprotect(pmd_t pmd) { return pte_pmd(pte_wrprotect(pmd_pte(pmd)));