From patchwork Tue Oct 29 23:44:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Deepak Gupta X-Patchwork-Id: 13855727 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 890FCD7494D for ; Tue, 29 Oct 2024 23:44:50 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E508A6B00A4; Tue, 29 Oct 2024 19:44:47 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id DFF796B00A6; Tue, 29 Oct 2024 19:44:47 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C53116B00A7; Tue, 29 Oct 2024 19:44:47 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id A09A16B00A4 for ; Tue, 29 Oct 2024 19:44:47 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 56B91AC1DB for ; Tue, 29 Oct 2024 23:44:47 +0000 (UTC) X-FDA: 82728271416.10.2482C98 Received: from mail-pg1-f180.google.com (mail-pg1-f180.google.com [209.85.215.180]) by imf24.hostedemail.com (Postfix) with ESMTP id CC438180015 for ; Tue, 29 Oct 2024 23:44:41 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=hAWGannz; spf=pass (imf24.hostedemail.com: domain of debug@rivosinc.com designates 209.85.215.180 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=1730245273; 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=CzIJ0ckbf1GHBD2tYvzNgj5PuC5n3mvmNJyw5lLXOXo=; b=A+cX6Q3stG35TgEKUjMCgDKeMZ27sxAgo7c7KRpqkBjgqUSlagTfL2iLhmM92eys+e6zjN hHqxAC9nPhu+DilszgdJlIAgQFfBw9pNHAWYpM3HNBNutlJCNRimwWPp2Nc6RzXiMqagbo qxxvSAyF7vL7zsRov97/BDV145ykwRg= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=hAWGannz; spf=pass (imf24.hostedemail.com: domain of debug@rivosinc.com designates 209.85.215.180 as permitted sender) smtp.mailfrom=debug@rivosinc.com; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1730245273; a=rsa-sha256; cv=none; b=ggQBr3R5AW3Sj1LGRULisdYjA2ce9nC9wKW1NEl+nWmAIFLr56UvFHNi+j8eu5+fQT9Gor gTYnxF3qKVxtVKMeD1vKfw9Bmto3kHBt6XzTL4qiSg4WEZEO5eXSrku6TUFN5HE61NyKO0 YfeGKit5AuqyLbcWEU8bNMSHeCuWyag= Received: by mail-pg1-f180.google.com with SMTP id 41be03b00d2f7-7ea7e2ff5ceso4444678a12.2 for ; Tue, 29 Oct 2024 16:44:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1730245484; x=1730850284; 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=CzIJ0ckbf1GHBD2tYvzNgj5PuC5n3mvmNJyw5lLXOXo=; b=hAWGannzMOiQiBdFeZqkZ8+aKvJHPFfLgPojPnSD0RkNhVJS2mxw+uMyQhnQloh+ZP kLTHZFaSE+bAxDw6/3eLwVho0a9AiNg5WsGGVtkwyV9R5UG3Yomuiv3z4awY6zqqwh4R RsUU+zjyVbiKZcN72eB8+lvp9X1NuAaW6C0q5LjHKhW1pEeUKUBdiQGasz1EP0xr8oxi BLtsmbzHWraD5zYswJYkGFZu5Xuf/Dn775WudM2ma9hhTz+nJ+GzpaEQRguD3YDQ21PN rijCfWrIEcaivg9TfHzbqgYDkUvjDUEE9MthDCsfZOj8zrB9nTFgogZWqNMzBEgLEFAd l/8Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730245484; x=1730850284; 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=CzIJ0ckbf1GHBD2tYvzNgj5PuC5n3mvmNJyw5lLXOXo=; b=YMHa+6lB8/85klaggwNPz86gAk88Mep0nP/AT5Z7xuS4go6NGL+wzehmULY1WMVbRY OL99ddUHfbtQiOSOzm9YNuH2MvEsEVjkp3EeQ3LEqCobilrCdIRYeUksQbwsTXT3yfuy cI0mWDGVZ6I4V4RHypv1PSGbzxfZnlgmZikCN3QamsJEGCKmkVlhzT0eV+xWSgAQWQTD YPqSbQoSTruz2o01BTLvxtLzt0qEHtNujArjV7GrldkaufpjeCUms8YSXQk9iRP5euD6 RPOm+OJzZwBG43F+hMps/qEBCHcC4ZFMb9J0nFsUan/srJZ/0OZZ5A5GNbhE353dZPmV muOQ== X-Forwarded-Encrypted: i=1; AJvYcCVS88Cf+prBHCqaOsLy8cVhg/tAK4C/o/HylItLStiIZSGTG+zNWQZGtlizy2C7Y+QdHIbbDoAjuw==@kvack.org X-Gm-Message-State: AOJu0YyP64kU29IAWG+Ntv5LIX6NpW4o/awk+hxpmlW9++MwHDpdsfm8 Bxmnk3SFcF3dqfzRyZW2Z0UrLApFkBDMcW9u8TF6mWTJ6SxZreqaLeu8ACOtyDM= X-Google-Smtp-Source: AGHT+IHO9NpgsFfUG2/uawtteNyrFufrWe38CJ3nbx9BvyIZZlCpghacJ/qvTmf6Sjhfn55Wj0xhbA== X-Received: by 2002:a05:6a21:920b:b0:1cf:573a:bb58 with SMTP id adf61e73a8af0-1d9eee1e178mr2067308637.40.1730245484368; Tue, 29 Oct 2024 16:44:44 -0700 (PDT) Received: from debug.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-72057921863sm8157643b3a.33.2024.10.29.16.44.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Oct 2024 16:44:43 -0700 (PDT) From: Deepak Gupta Date: Tue, 29 Oct 2024 16:44:11 -0700 Subject: [PATCH v7 11/32] riscv mm: manufacture shadow stack pte MIME-Version: 1.0 Message-Id: <20241029-v5_user_cfi_series-v7-11-2727ce9936cb@rivosinc.com> References: <20241029-v5_user_cfi_series-v7-0-2727ce9936cb@rivosinc.com> In-Reply-To: <20241029-v5_user_cfi_series-v7-0-2727ce9936cb@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: rspam06 X-Rspamd-Queue-Id: CC438180015 X-Stat-Signature: okpkeip8x17pbcgbjw4zwcsahh8u8gbh X-Rspam-User: X-HE-Tag: 1730245481-277797 X-HE-Meta: U2FsdGVkX19TZbQEacLaj1E6fEBstZT97IfbHh5jjXwb9GBVQwna/8WAAipg800kEMwHDj0BNVSuzfSGJuQwLh4crh99HHyHWbRgCVjMExGP+IhfQFRd7+0LhJN/xxHBSsJfQ7XrkVteYh5ihFuzW49NCiaktLE/DbV/ScJlcS/YL4UUzD7scca6UVbPB30pj5nxBtlji+Y14fhD2vht7pwKFKQOWZ0bOwoVd02dPOGlv0twUza0KoCz4ukBxwDCCBr2bqJMXj3vDnRPDa/z6ojS1irtcbiBrVEaFg1neh3SqkqRT9fdyy9N8gshtIiBPPSs5GzFygPNhVu3D5nIuJ1e6iMsYr4GlfLK2u/1MXiHf2b6hZr1uMRV+DgXkzu5ngz3WqmpqR1BcWMIlE4/13tdSeouWcf7K/TYCMolPj9pPoy1CcKyzHnh5gvDz8iKGlzr7sWUMHPxtD5L+zvLb6b5R/40gxiircuAX4Wu5QdkU43m+oyPY+XNonrUXKjftLxB63iChiiihGVB4zkIkD+2KbP4Vt1ka+pKbu5wrLJVweehS6zrLmgHTDn7GVz7qgYpXG13FqjVhH6fR4hLnk2ChfeCTUSCxVKtwC25T/v8tEk08rgkq6CoU6hvQS8Pq2CrE0mLFMnOyPdIeny/2nb9lFNqCnjAQijjdtevsa7w5rLntARxTS8okOozBhNet4W6Mt6nk8f4qabx4wPZazuNYeFX1AlQLGOwZ51VM6NWEroIQ4fdKtldsNumcieaVuNwJ6zPTSM8ePZ70UOyVNzFNVTmuZVLxMKUiGZNjKMaD6SzW9+QnG9bmB7U+og3cFqf97fpQBDBlFFPSrY0s52PNUvzzaSV0EaXbHnQLLqC4e1bRevpL1FDi27HaxbwABoBHpUrksG8ZVdo1fOcKHGThJ7ATgIqNeY+eMb4KnX68XSOoYSnzP8/XVV+HYBmcDOI1YXMxZQhNKOiyz/ fBZphEeV qe2BzYHUxp6NQEMDpEcMBSa6+etnoayU5LO7hCiqDHy0QTIplsQAb5jOHeAtk5iHvaFzvtzjtN617w85X33J+T846D38YuEIPH+WvneylDAfeUOCPFUidEQ5Ez6c/7TE4jN8HJUPKyTGEgWlHFw2OScCZld4JtF+VkTPGJiFs5pi4VRA6hSMdo8vK7dPDyK/BbnDwBKSwYKdvRY5ZG2XhNtboudE73SLwxH/nKeYB5geS9Ya2S3GCoXl/99hKxrpzeWKdu6OPpBK4HRoqKD5GzakBBW5WsAea8xi6tQTQb1HSLFRXkg0V1Su/CcIcsPsD9mDcEUTH3MU6wxvHigJz0erNTJYXhJKNlc7M4lw09J2brxcKXuDr6gfGmnFYGiHeSePZ7QzN42w5A8ZqYlzqcktEOf0un96z6FD2DhG0q5/WDsRaLrf63nVhufkM8feHq5InoQUBf6Z0PeY= 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)));