From patchwork Mon Nov 11 20:53:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Deepak Gupta X-Patchwork-Id: 13871345 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 2A612D3ABF5 for ; Mon, 11 Nov 2024 20:54:25 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A5BC96B00AE; Mon, 11 Nov 2024 15:54:19 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 9E5DB6B00B0; Mon, 11 Nov 2024 15:54:19 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 835606B00B1; Mon, 11 Nov 2024 15:54:19 -0500 (EST) 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 634DB6B00AE for ; Mon, 11 Nov 2024 15:54:19 -0500 (EST) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 1F4411C7781 for ; Mon, 11 Nov 2024 20:54:19 +0000 (UTC) X-FDA: 82775016618.29.C0BA735 Received: from mail-pg1-f182.google.com (mail-pg1-f182.google.com [209.85.215.182]) by imf14.hostedemail.com (Postfix) with ESMTP id C2098100004 for ; Mon, 11 Nov 2024 20:53:31 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=PDGDYEn0; spf=pass (imf14.hostedemail.com: domain of debug@rivosinc.com designates 209.85.215.182 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=1731358369; 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-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=HvFaRabdOYgj/FaUxHA5lpjBxuSoaWHPSkkVGjDU8NY=; b=ZjKnr+WeWcB+MbC/JyrGPA/Gzf64lZh8XHGKCrdssr95sdlAtxAKAFoWXHNsJAIXXNNAsb wuWzntVPzqQ3eWHIbft3f/C4BumpdfWrwZBnqQqKuI0WXrT2EC/QEvuyqGMGJ2WTyl+w/D 0rb2ffcSL455ocs50uZ2gtZZ67ih5eQ= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1731358369; a=rsa-sha256; cv=none; b=Gc0Uvxy6enBh/cGBFU048g4Wc2t83kW+Csi3mIpkwRiH1k35nBaukePXHql7wdmRw4o845 RsMSAUj75XXb7z5cNpumG4EITNv4Jb8XI163CYgW158tcGC7tbQkvhQnw/JG4q6l2/VBq/ WfzUQ8UDQ8thfKgkuXSDYeqamXOe/P4= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=PDGDYEn0; spf=pass (imf14.hostedemail.com: domain of debug@rivosinc.com designates 209.85.215.182 as permitted sender) smtp.mailfrom=debug@rivosinc.com; dmarc=none Received: by mail-pg1-f182.google.com with SMTP id 41be03b00d2f7-7f4324503d7so2291775a12.3 for ; Mon, 11 Nov 2024 12:54:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1731358456; x=1731963256; darn=kvack.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=HvFaRabdOYgj/FaUxHA5lpjBxuSoaWHPSkkVGjDU8NY=; b=PDGDYEn0/hbnPINHNwv6v69Msjg1eJh9Y9d9aTDUMkGH8utGiQX5WUw4ktEWzeLMd/ dpxsPab2ft6qRWEA8Olb/Vf3qd+RqAN2/+/yeEWn5jklNBugo45dxB1wVjXYLtqaR6R5 dJo1c9Ki4lax5ggxtJaRNIMxRDxLKYSi8UBpOxsFIO/YROmfCGiHJZyrV6T/CpJ9wyWJ v3363c2rb5YJYFKL41NR7HukZqad6Gplv7NrtTFZf8UEVVNBxaER0GrBYaOIM0+a6tRK phCG3gTm9/sjYlPPRrnQNKOFzZmQYZZaIYo7WrRd6oTzoY6j7QakE5hXjeAGiINPf1Kp JyJg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731358456; x=1731963256; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=HvFaRabdOYgj/FaUxHA5lpjBxuSoaWHPSkkVGjDU8NY=; b=e8+z86ZRucBUtIURUBVo1JYE/L+MgORXmTMjpjpoNw+BWmtPlY4J/K5eu2lgMi6WJf LcwbMCbnAw+irO9kpuUTbiht2II2E2YZ5xYRUHwVOlUu35tnHEWDys+1tc0qlVcVYQSu ZoTXdJhqpxGXeeE2zuCUd4E9jKi4CZ8TmU8lfznZiQWaXOPFCw6Fy7J81cJ66+XVjGSx 35JSb3OsKgQ8SoKm4QGQFAtbmv337NdQguVMZrP1U0DDWFYRh97ltFdpYcgr9iJCXY4k K2zRdoaor1KBHFEtBnMpCSH57gcBhcJ0EBimiuwQRTujKoWWg60+mQ0CefRmXi2735ch Xgjw== X-Forwarded-Encrypted: i=1; AJvYcCW6/GTQgVwKjLg7TUh626apDWKgwOfEMb0DbuxOU58KqiDgU76eBy3Bg1qNswtCVDneIOhBshQnpA==@kvack.org X-Gm-Message-State: AOJu0Yy8jU8ht+NaEh5aLTpA7NXJXz/VIJxw5+2BxRf2GJ9NZiz9WEJw ykMWQm09UQWNWgzVCoEkPD83Uk3yEODZ0uqND0nrlLtQ4JUV1Qa3y4x7jj74NRI= X-Google-Smtp-Source: AGHT+IHkeWur3sgROxcRoGTFfP+xBQFc9m8RxiHforXzu5iQMPat3nHq0j8ICMSCMJgsQveJpQW4TA== X-Received: by 2002:a17:90b:4acb:b0:2e2:af53:9326 with SMTP id 98e67ed59e1d1-2e9b177fc76mr19427178a91.30.1731358455997; Mon, 11 Nov 2024 12:54:15 -0800 (PST) Received: from debug.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2e9a5fd1534sm9059974a91.42.2024.11.11.12.54.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Nov 2024 12:54:15 -0800 (PST) From: Deepak Gupta Date: Mon, 11 Nov 2024 12:53:53 -0800 Subject: [PATCH v8 08/29] riscv mm: manufacture shadow stack pte MIME-Version: 1.0 Message-Id: <20241111-v5_user_cfi_series-v8-8-dce14aa30207@rivosinc.com> References: <20241111-v5_user_cfi_series-v8-0-dce14aa30207@rivosinc.com> In-Reply-To: <20241111-v5_user_cfi_series-v8-0-dce14aa30207@rivosinc.com> To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , Andrew Morton , "Liam R. Howlett" , Vlastimil Babka , Lorenzo Stoakes , Paul Walmsley , Palmer Dabbelt , Albert Ou , Conor Dooley , Rob Herring , Krzysztof Kozlowski , Arnd Bergmann , Christian Brauner , Peter Zijlstra , Oleg Nesterov , Eric Biederman , Kees Cook , Jonathan Corbet , Shuah Khan Cc: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-riscv@lists.infradead.org, devicetree@vger.kernel.org, linux-arch@vger.kernel.org, linux-doc@vger.kernel.org, linux-kselftest@vger.kernel.org, alistair.francis@wdc.com, richard.henderson@linaro.org, jim.shu@sifive.com, andybnac@gmail.com, kito.cheng@sifive.com, charlie@rivosinc.com, atishp@rivosinc.com, evan@rivosinc.com, cleger@rivosinc.com, alexghiti@rivosinc.com, samitolvanen@google.com, broonie@kernel.org, rick.p.edgecombe@intel.com, Deepak Gupta X-Mailer: b4 0.14.0 X-Rspamd-Server: rspam10 X-Stat-Signature: epuxxn9u57r1ms4stpm3xay37qnur91b X-Rspamd-Queue-Id: C2098100004 X-Rspam-User: X-HE-Tag: 1731358411-130214 X-HE-Meta: U2FsdGVkX1/CUOU/6CzJPH95/5vfyZJIRC6jKKtv4vsGJWe0FFgZnyTCvgLG1NzlSSJqqw6AtRFmzbWAuAweA2wuXK347Z/s14PPyzNiWOM0ZPILCJQYGicdXeQryn376QbGn/3uVSSUahf/P6V6aa60N+QtlDt6RocepSmMjSWSlJ5jLWDGjoTGq4USeUkfpDX0zRASBCVB5yCrCSzZL4lK8WRMjs+Gq5U2f2vZzkpcZgCjhxXnVSN95o+rycv1icekg/OiSz5gmG8j3s1YztkBdvEhsCqj7qr5XLtLgXJzl3CZImbvdBICPp9eMvlIgBwuPkXY2vLj4nKunD8a/xxGse12J4DNNF+FijW2n4eFToZM5NRtKQ5/q3wdSnwCQ3bFLXjozzsW8N1LfB0AiLm+0QyeYCr/xvyW6aT++BGJdFdqAVMKTy6Y7I9eegpAhUxkRGRgG+ZKhnYDbTPzNU7u7L5o1TBxO91OIM7klQ3gOeOVEv+0q3Xo2haX4MHvK6RfPTqd/9VHce+EP1cNuvlqzBo/UkjKmZVzrUX7xiPikjHMs+ZD4nUHkuLg9AvshoDXKbwgJobtr/Ky9tSVKtn4k74O9pD9It50RK21jIZyN/tjieTp3W6iZlHIWGl81NaOZPnRMp9WD6GQmy0h0KPvWYbQrJbCO1uhRZewIH5hNhqirKIoKAganZi8+XPhJDr2ar66xmZy0vUC+JbzL5rfR/LULNrLAUDqyAd0CnNCSCFebbWIEcp2T/igWIZAnUQkxBJl+UkbctvtqFC2NyhuQZyfhb8A3iV5wmdmuH8/G458/NVXLV3V2LQ29wENEJ+h6+aVHnr/gT/aAaAkbwpdZdx5UBYc4Wib9L1+orbAGIXJlLvjY1D0+Dls6JtKFo/atFzcGcIwgNH7W5MPKOBWw98JUQrUEKAQXuYuk+jBSOnTKbQKy0GCq9RYGYIx03WlaaqJYnclpoU9oDG BMXdciTY WDEogRafZFCNSK2VJVJp/RFZ5mzPCzFGI+XdzPsBGzmbcbEF96NWX69iZpRQVuL31duXcHK92/MU2pkIGw/IhouK9g2nIesJQYWXWyBj0rNwuTVzOtQj/r9R54fuPmaVFqv1PpMzi2KdNsHrFdY5H2C6TkdWkEoE+Pw22Jp+2dDCprlj/Zi/rRizsJC0GqLqjOLZUEOd/xkRa31PIOiOH+Nd1aZVrGvygSAxMppWjj7NfpWi3gfcJxRM3NpO3sR/5kTl6AnQxFc5YttQ2FXyUP44uVpV2yUIo9E+D46DpnSxM2myzRduix0YFqSknWaexBOiNJ+FSHn8J43HPTDWKMdekDYCXcto8hclzoof0hUekIlmduI4r3JPo4vaZLRP8ZoFmq7r0wh4nj/GoqzKlH5E3vtNC0fdu4lqxlDg97h1rHY99NRACmTsNyltlFVBLxNBKpR/G6Vow12y7bSMTt5jRfA== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, 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 4948a1f18ae8..2c6edc8d04a3 100644 --- a/arch/riscv/include/asm/pgtable.h +++ b/arch/riscv/include/asm/pgtable.h @@ -421,6 +421,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) @@ -738,6 +743,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)));