From patchwork Tue Oct 8 22:36:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Deepak Gupta X-Patchwork-Id: 13827095 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 A5084CF0429 for ; Tue, 8 Oct 2024 22:38:38 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B11FD6B0082; Tue, 8 Oct 2024 18:38:24 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id AC4476B00A8; Tue, 8 Oct 2024 18:38:24 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8797A6B00A9; Tue, 8 Oct 2024 18:38:24 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 637AA6B0082 for ; Tue, 8 Oct 2024 18:38:24 -0400 (EDT) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id C0F6D80CAB for ; Tue, 8 Oct 2024 22:38:22 +0000 (UTC) X-FDA: 82651900128.30.5C95ABB Received: from mail-pg1-f182.google.com (mail-pg1-f182.google.com [209.85.215.182]) by imf19.hostedemail.com (Postfix) with ESMTP id 4BB801A0005 for ; Tue, 8 Oct 2024 22:38:22 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=GPZjRKp4; dmarc=none; spf=pass (imf19.hostedemail.com: domain of debug@rivosinc.com designates 209.85.215.182 as permitted sender) smtp.mailfrom=debug@rivosinc.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1728427075; a=rsa-sha256; cv=none; b=xfpiIdbkSHNgFelfCJgQbhSEeHdXdooOhTfc1PymKhTVpz1eSUTsOnTfNKyvVFa5nAanpD X64qS+gCcmEdPmn6SuMHyUvH7dDdpDGZ2WT7K4FW398U0KYZPLgKlaDOO9aFlfdOII/1b0 LR7J2eg3IL7ENA6DViD0bRaoNGzN8HQ= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=GPZjRKp4; dmarc=none; spf=pass (imf19.hostedemail.com: domain of debug@rivosinc.com designates 209.85.215.182 as permitted sender) smtp.mailfrom=debug@rivosinc.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1728427075; 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=2C90J9RYuhUspTM29RNlFy9KZ9EfD49VXDsueXaYW9WoaSwodyuYvuGjj3lpVGfTPdpXHm s1ggsM3vDR/82MISCjT2MvLZxRhHWoZLr+1rV7oMj7PEEJSr2ZiZtCgwOMOBhpGvesR6C7 Y2SikwpJ9hqmpJOZoQx/S6ClXB2xGYk= Received: by mail-pg1-f182.google.com with SMTP id 41be03b00d2f7-7e9ff6fb4c6so4606853a12.3 for ; Tue, 08 Oct 2024 15:38:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1728427101; x=1729031901; 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=GPZjRKp4IPX6OoAUerp5MlE/VIwR/Y56IZ+W0m0oV9MtSW2Ayui3l0PTHx1qrRCqHy qkUKcnyYf4oXXV/KNp6kE7Ce3l+Jwea/U2W5TrAflMF07l55y0DC2/nOog4yEJvexnpY HYA28o/8hc1fX8NQuZWrqS/QRr4iDsqdvW2ftkefLlTyoXHVKOMsHV6ccaDeLCzpnyII 4XKw1CVrFSBcYLdtOCEBkH8JeerF/nK4XIl+pO7dezHr9gJpmCfwkzXbpL3AUYK9mshX VUQg0HB2X86YInL5PEcVxiiuN0ODrJU+CtFzZX3oYCkm/Ig7DcQn38ObKaFHhCGJn/rL XMuw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728427101; x=1729031901; 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=LPuQYfjLTSif7q74qPZAcs43AljO3YhJMgvqAAWed4klIATHyKdY+TZmiOySZrN3Eq C8+FJGan3WTz8uzgyZtwLFI8a79BBVmVONeQ+0thZejeT4lhRJFHwufI/8SRPSo6O17x V+unJGzdgEqY74DYgF4yAeqUPHwihBKNMVzpN4tGEMmT6ZJ1wDo2L0bPbt8bfpIoeAEX r77ei5HJlfvM0AHNhvxGcEwbM9Vt2e8g7J7550RlkbcY3BtQdX7SA6pnJv67bC488jS6 8EXP5dXLlv0mxWmdrUT69IUYiw1UQJ8xloRrk24XLE6hGo38hGx2tgoR6Ka1saBAPcGb YkuQ== X-Forwarded-Encrypted: i=1; AJvYcCWhCP8waNsicc/U7z8Cd0Z4jbU/yWZi4cUcDFQ2fYjHOr8O8C1c4sAuVwn3s8gb2o7fLvM2O6UZxQ==@kvack.org X-Gm-Message-State: AOJu0YwxxBFVY4ozKbzJoaplvLJqF8uHkG4qz4WxSTR5agSFrjEwXt2d jh1QxeL2KHTd4OocDf3wktv3/kT0QbDlYwWyqEq2Te+yZeOksfI7x1EkYgTGXDc= X-Google-Smtp-Source: AGHT+IHvesfHqSkO6ZkkqxS8iUZFbPtASty24Hzhh3e/eaCzge7K6ZuvofdLUxv7u/b5HvamsjHRPQ== X-Received: by 2002:a05:6a21:6f83:b0:1d0:7df8:2484 with SMTP id adf61e73a8af0-1d8a3cd928amr676575637.43.1728427101109; Tue, 08 Oct 2024 15:38:21 -0700 (PDT) Received: from debug.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71df0ccc4b2sm6591270b3a.45.2024.10.08.15.38.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Oct 2024 15:38:20 -0700 (PDT) From: Deepak Gupta Date: Tue, 08 Oct 2024 15:36:54 -0700 Subject: [PATCH v6 12/33] riscv mm: manufacture shadow stack pte MIME-Version: 1.0 Message-Id: <20241008-v5_user_cfi_series-v6-12-60d9fe073f37@rivosinc.com> References: <20241008-v5_user_cfi_series-v6-0-60d9fe073f37@rivosinc.com> In-Reply-To: <20241008-v5_user_cfi_series-v6-0-60d9fe073f37@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-Rspam-User: X-Stat-Signature: b8myp8y1fsi14yw881dhnuesn1zzm8kg X-Rspamd-Queue-Id: 4BB801A0005 X-Rspamd-Server: rspam02 X-HE-Tag: 1728427102-219914 X-HE-Meta: U2FsdGVkX1/Pc4Lwf9ln4Ux/Tw9zXIJ4rNGAJGyG5J/mGGddNFAjHOhQYgBftWZk74HmERdkLyVJcHYIIhRPS+K8ngno0yuAn2Iqmm2DsxP/R+mUKVj6qMvgixzo/gm+vBCuzanuLZ+xlXNG/oN06YcbbF14kpxkiFB1MONsBUIEhsjHO3KOnzgV39ggU/Bv6f1+KHAm0WRUSaxtnbcM691Hk2VVzhN3XCykhnmG70AnF3cy8AQ6WsyzqEiPrkiMEQywyj297XDvxTGjk05uzm5ve7lONZst+yxVXjWwSs2CV/ChLAgxJeAYVCBvBtcPKPLaOSAilxhjli107Fvbj6glA0hc4FhnNgTQrAtDt8C6BcjaMNFzc4eHRvODJceuN8nPXQkgfWwNfGk/am/YNZ3jG/HNHwL1em3efrLy4LFikHjay6icTQI9KeJffx5ACTgc81hVjCiRWRDlRugmc2BcR+Gm+OX9ehVkuh0JbuiBB09PaV1BRiWj8HKxx3Iz4lFG3JRcWYfJE/mTsUkRQe/HOCgMVDALCJYzlYMBUlEFSf6SFUdQYnnOYNaRUYlfB4tc5xd9ejQ5XSekIReqtRVyWW20XCBfJ/PjRNtz3MZ3N+jbbxVDyvO112tnhOzPX9DGUvoa4zvk3XD0ThsXggrwGR7Syxe8/tzmobsDD7Xj4wt1Gpf7wL72tF/fis6s+M2QCFAReXNGthZ54qV7sB+3wtvhCi7TBQn5nnqFlhnuFMxvFE0xEP8mgIWF3xyakTf0tVDHiKKxXEdTdZ4oG9azvtctDC1ZX1hICGYQLg5AUsC8WNuxrxjUvTjxzMX682nf2TxkramzFputGYAl7fgKc0Fq0IVHesOMPMRefCpCCbCRjUXhgf8uSCmT5bOh5TRdY8FpC2RmEu3ekBtlKD+A7158d/4znTyjYxE/RLR4aZme2GsYm4DhHc6R20bdVqrJzKK0lS8c2bBk5Gq /Ge8DYkC X+mnP4mtOgINqF1bvKsalLw59sRb818gjIkBy33TdDtRWhXTfqplMc07vTip8bQF4fItlrJFGflb41bfD+kMOJ0S6B1AZ/NWB9+D4gknyIIN8vBCLXf9uvlwqeUnKGqMbXCALoaexBvq19w76hlH91kg7N3AxNUFvUg5ys3YLWXyXI7O53MEAtCz0CO3oMVL5GyAQr1qDEeRcE+olOqGQDMnYFU+oCQ8tLisIZTzq7W/lnMWLweyHqO9XVNbiYe/pQ+/CjB6F2TtUuZpU4ALfgnHzZdZ/8hXRe8nAexZQ62yda473UDWwC30TYdEJxgPqNNmcIAy5y7TArBH4sHMiMeUcUKy1sBKV3Rcukg5ly3xRh9SzWjBvm7bfty/5XCr635wkYgAJ30NkhCIveW6Bb0yL1toVg7o3Aky02vAKDOeM7uu0iHbbCOovvaepRzYx74NX6bzFT8KJEte/mZpo8q9KkoV3vVUItr3BSaXoraJg0qf65d8Tkms8WvF+oiQXr+TkM+48k+OxpFJiKRSTbtjYtN4qaefYzpz7pS1qVWbUkpSz6Z1HH858sL/rKQeBs60ZVzAiPNuSDDI= 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)));