From patchwork Thu Jan 25 06:21:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Deepak Gupta X-Patchwork-Id: 13530078 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 3A4FBC47DDF for ; Thu, 25 Jan 2024 06:29:13 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BDF1C6B0095; Thu, 25 Jan 2024 01:29:12 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id B66876B0096; Thu, 25 Jan 2024 01:29:12 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 996CB6B0098; Thu, 25 Jan 2024 01:29:12 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 7E4C86B0095 for ; Thu, 25 Jan 2024 01:29:12 -0500 (EST) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 4AEDE8058F for ; Thu, 25 Jan 2024 06:29:12 +0000 (UTC) X-FDA: 81716856144.16.04BC42E Received: from mail-pf1-f180.google.com (mail-pf1-f180.google.com [209.85.210.180]) by imf21.hostedemail.com (Postfix) with ESMTP id 80C1A1C000D for ; Thu, 25 Jan 2024 06:29:10 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=R7DNYqJw; spf=pass (imf21.hostedemail.com: domain of debug@rivosinc.com designates 209.85.210.180 as permitted sender) smtp.mailfrom=debug@rivosinc.com; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1706164150; a=rsa-sha256; cv=none; b=3Q5Dn+vTSpzN3ObiIhLdUERj2sCTNB+RNpl1QShxRQwVxgpAS4C0D/iBIolaOhPRaGFGOK wIVh2yI8DzO4iMe6bbDOf3Ko+mLLYFkZ0Tk1AnHe7jtU9nvEs12zHlKXaRm6tIW+DqpbUj VOotmZzTqAwsusIC80y2rvghGjE2g6E= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=R7DNYqJw; spf=pass (imf21.hostedemail.com: domain of debug@rivosinc.com designates 209.85.210.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=1706164150; 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=uqhJyw4qKw6ttxWAjpEt4kkwqgUPwpH+MlNDa4SEbVQ=; b=wfq071xJ2XptcjYRTw87OT+AVvjNqiod9ey+HpVE4V5Tu/2xw3EjzCaGzOklLjnyj7HTN6 z9StXxayxCO5Vs1C5EUkujR5Hhkl7E8I8jQ/mnlZNuiWdJMQX9jN6bDnRHJb/MrA3sZytq OP4Hiy9m3glMMS0q3UzV3ZAoj6K5r8s= Received: by mail-pf1-f180.google.com with SMTP id d2e1a72fcca58-6ddd19552e6so80346b3a.1 for ; Wed, 24 Jan 2024 22:29:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1706164149; x=1706768949; 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=uqhJyw4qKw6ttxWAjpEt4kkwqgUPwpH+MlNDa4SEbVQ=; b=R7DNYqJwZvOygbLEwvhTmxw3iO+bMMAWmwYSCSo1du123iDm0Nl8GHv0QrdQT1ldDz swoUJ+MrbPvVfWQVOMi3lrADtl8bM96AoEE+1e6UiWPk6rzsJPHP0QrtrdFce9asiymI sDUXjgwI9Li3xgQRJhObYIKONZQd/d3GXtJBDvCEzkXUBdOM8ghmpwBfLJnGvUiVQECi cEoIljglXxyUELWZwhIx9lVjY/lJtjs0BvK2g5PKThVPqy/UkW2MEt33JoDXRHS3TGfe egQrymvEv0moQclfr6fbDo3r50G1DfJYnFcR3tWi3IipkA6Cqz4wSa+tXWz5GmvO2EzN GsMg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706164149; x=1706768949; 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=uqhJyw4qKw6ttxWAjpEt4kkwqgUPwpH+MlNDa4SEbVQ=; b=TeDkVp3r7Vx4Mkd7GwIQtd3q1LS03FXREgO6iCHsafy3DBsEdn6duEms7Lk1uqxKiS XLkVKfm6AjsYRKYrTTp+mxkVbSkCjPcjdApBgqa/dqB9ldDqweMpuRVT275n0jBiIoJb xfZ03g0kRnxFauB4UKZi/6QIjppXXZXwL607xInz4QJK3ZPn79e+8uByb+4aOXJn3B/A 9Ejk/YvzsZpCwU+SmYp0xIiAyooV0M9j+9haRaNa2JvWC3cP18tW6U6JA+za236s/Qh1 Otx6KMyFF3lmE7nz5Kgu9cmMQ+2eVWt942YscD53vcCvPxX4OyODKzvqd9E9yWYJwRTe vJzA== X-Gm-Message-State: AOJu0YyNz5NeAlPCLFu5oxxlhr9J+l0mNMRWT58XpeZWtKEdd8VMUhDQ iNE3hRi8m4wi8R8P+1t4zRxPS4W5oJ9XxrtlC3q4bVeN+Oj/w8KrAIai/1oXrZc= X-Google-Smtp-Source: AGHT+IEl63VLMXT2mHqAciM7L/Xopf+jIyT34V6he9kHeUuUlxwxwREqJzJ6MMes7H6nQTQcNzI7AA== X-Received: by 2002:a05:6a00:2194:b0:6dd:c69f:1e31 with SMTP id h20-20020a056a00219400b006ddc69f1e31mr202939pfi.51.1706164147768; Wed, 24 Jan 2024 22:29:07 -0800 (PST) Received: from debug.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id t19-20020a056a00139300b006dd870b51b8sm3201139pfg.126.2024.01.24.22.29.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Jan 2024 22:29:07 -0800 (PST) From: debug@rivosinc.com To: rick.p.edgecombe@intel.com, broonie@kernel.org, Szabolcs.Nagy@arm.com, kito.cheng@sifive.com, keescook@chromium.org, ajones@ventanamicro.com, paul.walmsley@sifive.com, palmer@dabbelt.com, conor.dooley@microchip.com, cleger@rivosinc.com, atishp@atishpatra.org, alex@ghiti.fr, bjorn@rivosinc.com, alexghiti@rivosinc.com Cc: corbet@lwn.net, aou@eecs.berkeley.edu, oleg@redhat.com, akpm@linux-foundation.org, arnd@arndb.de, ebiederm@xmission.com, shuah@kernel.org, brauner@kernel.org, debug@rivosinc.com, guoren@kernel.org, samitolvanen@google.com, evan@rivosinc.com, xiao.w.wang@intel.com, apatel@ventanamicro.com, mchitale@ventanamicro.com, waylingii@gmail.com, greentime.hu@sifive.com, heiko@sntech.de, jszhang@kernel.org, shikemeng@huaweicloud.com, david@redhat.com, charlie@rivosinc.com, panqinglin2020@iscas.ac.cn, willy@infradead.org, vincent.chen@sifive.com, andy.chiu@sifive.com, gerg@kernel.org, jeeheng.sia@starfivetech.com, mason.huo@starfivetech.com, ancientmodern4@gmail.com, mathis.salmen@matsal.de, cuiyunhui@bytedance.com, bhe@redhat.com, chenjiahao16@huawei.com, ruscur@russell.cc, bgray@linux.ibm.com, alx@kernel.org, baruch@tkos.co.il, zhangqing@loongson.cn, catalin.marinas@arm.com, revest@chromium.org, josh@joshtriplett.org, joey.gouly@arm.com, shr@devkernel.io, omosnace@redhat.com, ojeda@kernel.org, jhubbard@nvidia.com, linux-doc@vger.kernel.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-arch@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: [RFC PATCH v1 08/28] mm: Define VM_SHADOW_STACK for RISC-V Date: Wed, 24 Jan 2024 22:21:33 -0800 Message-ID: <20240125062739.1339782-9-debug@rivosinc.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240125062739.1339782-1-debug@rivosinc.com> References: <20240125062739.1339782-1-debug@rivosinc.com> MIME-Version: 1.0 X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 80C1A1C000D X-Stat-Signature: nazmympwwgnxqtjnkdpnhcju9rduyfbo X-Rspam-User: X-HE-Tag: 1706164150-523253 X-HE-Meta: U2FsdGVkX1+XSM1pyFmvv6BvHC6NvvQyMhTF7BAhan0pOsxqyigm6YuSFsULro9RkIrBIMCXZpuigKoWhFJybSBp8Sqm7CEBw5+SdO8oV6zS+XIuc/LpMjaaOuku+kGutO5x0OoLkILu0+plDjRg3SBRE1yyHzQtFgPIHpcVR3AAlD+jG00iGtGvoRfe3/wIHrht2kabR5VQZuEBmiRGJk/pYbiC+BL9j7pUOwBQD2osqmEm7/Ky2OXFnUJfTYqXBSO1FMljC4lv5PA7xMXQdq9V2228mksk6b6xugTOs6vaYy78L4IXlBDKzdp4H4duKqQ/gh249nbPqoePJgtltqswRa1HdfGV167ujeiov9s3N4I7gAcZDpyIG9UJRs/HwI5AAxo1iXvDiR7rR/Z/JBRBagkMISqWRTizItyjngQHK3jTvDy/cQKDVVfydif8ZqykWpjjWm90ZvbZsuj9C6AeNU1VFO1fGh4yd6AhsRhxFyIV3hckrXxWo4v7e/wVTV22yObQk4wKkWMXfu4r5XCWkuJ1hzNWa0ePZggetShp6Pqht9hU4ICGzNExBlwIKmOy6v+mi87bakmrcNLiCcYYjpkoBOWx316GxHTb4VD6jXqvIx+kLpeDpiT9r46r0bsDI3mjPkSuhdx4QTWJEar0kaDO2PIkzgIjNPPXZWO/mgXr9pHEQj6w8hRYsuW506KBv4xaeCWtT/482aNTRAPD7e/IYA9aGE7F1/mQsJ2wuWw6DgsXouD3lYY7Tgk1dxrCr/MgSR9C+Bz5gKHyXaL2iBaWimYBKWe+4kLc6lZe0Go8WnKlLW94dFeg5S4WTIslPdOY6gGZLXJHoZkslbN9uT6dxXnTl2Aypx99MjxjWvjfLCrpJIOxOEv0oVZZgGQrG/2tllvu06GAUXW0PDSVfNRoSRN/1826vsci8c7JLygbPIYd9gCG8J0A5I82B2LkU3ZN51u/hTZVWz0 ZuIAnPrX wL0gwwtqFLuVtGiU4o/vdownF1uO0kDcVGGx5GC3x5PAF/RRplO3R8d7Ro5GKX+mbhcnTE4/IvsSmwrJj3rxgESaPLK4SkOh6j+LAKGFqKpQ0Br6H5Lzor8Ky0Qot/DJRbmzuwIbfSfOJkXY0jj1A5oDieMsNEATv4v/8Ew1/T5EceaoANzdcGfDkxxkNmaaydXME9TuDt18mnof7BokMYbfqeppPQplZ/mJTcogPgb6m0iYwwnt8cGeTNNB4Pac+qyg0wblEe9BX6/WioEnrlMb6dSR2F8fMP69jqwjxfz9S3nFvybgtvmf0Yfh4tE4h5SEb4X+bC54aLRVjJLldAeB3zSieCIILGxQoqTfCDKQmraY1xzZN4zOGr33tOtHVNpQGjXEl6NpizN/xBDWMrWYHnBZ/aG/UVc0nidd73xkuYBUEhcGPvSK9p3Oeop6B3/oPpkj6W90G0ooVKA/ZgTDK6kcj3Wm8mVAL8o/ybEZvKnLyX6GLsmr3SrLqo+FeM0HbGRibxhgK4GdafjmUPnNb1Dat+e8NbroVT2fXo9bB/54= 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: From: Deepak Gupta VM_SHADOW_STACK is defined by x86 as vm flag to mark a shadow stack vma. x86 uses VM_HIGH_ARCH_5 bit but that limits shadow stack vma to 64bit only. arm64 follows same path https://lore.kernel.org/lkml/20231009-arm64-gcs-v6-12-78e55deaa4dd@kernel.org/#r On RISC-V, write-only page table encodings are shadow stack pages. This patch re-defines VM_WRITE only to be VM_SHADOW_STACK. Next set of patches will set guard rail that no other mm flow can set VM_WRITE only in vma except when specifically creating shadow stack. Signed-off-by: Deepak Gupta --- include/linux/mm.h | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/include/linux/mm.h b/include/linux/mm.h index 418d26608ece..dfe0e8118669 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -352,7 +352,19 @@ extern unsigned int kobjsize(const void *objp); * for more details on the guard size. */ # define VM_SHADOW_STACK VM_HIGH_ARCH_5 -#else +#endif + +#ifdef CONFIG_RISCV_USER_CFI +/* + * On RISC-V pte encodings for shadow stack is R=0, W=1, X=0 and thus RISCV + * choosing to use similar mechanism on vm_flags where VM_WRITE only means + * VM_SHADOW_STACK. RISCV as well doesn't support VM_SHADOW_STACK to be set + * with VM_SHARED. + */ +#define VM_SHADOW_STACK VM_WRITE +#endif + +#ifndef VM_SHADOW_STACK # define VM_SHADOW_STACK VM_NONE #endif