Message ID | 20240329044459.3990638-2-debug@rivosinc.com (mailing list archive) |
---|---|
State | New |
Headers | show
Return-Path: <owner-linux-mm@kvack.org> 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 49E57CD1283 for <linux-mm@archiver.kernel.org>; Fri, 29 Mar 2024 04:45:17 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BC1846B0088; Fri, 29 Mar 2024 00:45:16 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B70696B0089; Fri, 29 Mar 2024 00:45:16 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9F3A96B008A; Fri, 29 Mar 2024 00:45:16 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 7FF696B0088 for <linux-mm@kvack.org>; Fri, 29 Mar 2024 00:45:16 -0400 (EDT) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 38E37160F62 for <linux-mm@kvack.org>; Fri, 29 Mar 2024 04:45:16 +0000 (UTC) X-FDA: 81948837432.27.06B0E02 Received: from mail-oi1-f175.google.com (mail-oi1-f175.google.com [209.85.167.175]) by imf20.hostedemail.com (Postfix) with ESMTP id 6BA671C0015 for <linux-mm@kvack.org>; Fri, 29 Mar 2024 04:45:14 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=tIBu7NHx; dmarc=none; spf=pass (imf20.hostedemail.com: domain of debug@rivosinc.com designates 209.85.167.175 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=1711687514; 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=txT/LccY8POETQDQkXcfynUkPCv6cjOV6zf46WX/Pcw=; b=biBaVajOHzpPCJAp156ZRAnaJ9PlZH4cysbhyKv2hk9X8cg6KgCZ++UZfuDBkgbuodbXAM kmYEUGcN2TGasdLy0ggWZRLfxkQOJ6XBGJ1ESTbN6Hz1DV75PcZKaf65KWYjrODEd3V82Z Mzt9zNQQ3ZwmQbHHEgP0+f2AczrH0Zw= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=tIBu7NHx; dmarc=none; spf=pass (imf20.hostedemail.com: domain of debug@rivosinc.com designates 209.85.167.175 as permitted sender) smtp.mailfrom=debug@rivosinc.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1711687514; a=rsa-sha256; cv=none; b=aQf92QBuvOQsupPtuRgbrI8amPHuDiPLmkpOm8uXc7C4cTRgy+7jHO0TGxe8otWyYa80wn YDfVxoRELP6j2HdYsyp9xhTAdc8YIPFkmmROf6ImM4+4otx2PAtcB1DG38TL3trtU54Jbb kb06+yf7Lp9+i7Ya1F53mipe5e9s2Ds= Received: by mail-oi1-f175.google.com with SMTP id 5614622812f47-3c3df13fe31so1005496b6e.0 for <linux-mm@kvack.org>; Thu, 28 Mar 2024 21:45:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1711687513; x=1712292313; 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=txT/LccY8POETQDQkXcfynUkPCv6cjOV6zf46WX/Pcw=; b=tIBu7NHx5g8viX1waTh8TArkMedsLhf2dVrugpuXC4gVrgYmnMvNlKC9SR/v++0RlF 6ODQ9PJSbXVEQXYcjL3H8rekfABk+3rxqS8L2mZNs+FIhEm5QxZb7zydY8MY8G1Lu7S4 qkLG4+TELla19S//nNQnZT15Qrs7JriEIZa9qFvzJHoRHTkfit+y6ZZvZLsx/rZFU1Nv sh+hnS5zKbC0cZMiMLv2UGaecbwHoYLLbNidofCkNePJhBM6KxQjPGs8KtjdYKDZoIwB qz45vbZ7e1Rzyq55p4G/QR1aZhaHe4U8KRFLMYPFR3FH74aTEZAGXwGCPwjwbE3URB5V eb6g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711687513; x=1712292313; 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=txT/LccY8POETQDQkXcfynUkPCv6cjOV6zf46WX/Pcw=; b=l4babBDv4cfxsID7mq+crc2qTXWTZX0BxXNguEJEQ0wcUtQY3vn0G5dYpkB3CJ5drl c9V6RB8Lubgfz3GV7O8bIGws9hckRUmX8xA5o+uNoutjMgzXnwkEHndLSjTw3TvHrKoR lLmp3foIqiVb1W0Y5BAKDBnBYHU6IJgHBD6xOQwoMDp19TqaxI2vlKeHhL/9swQ6AqN8 NbH7/NkBvwNdjkA6SNkx/swebHO6wUryLjAolNZh1OhgqVlNiRtRwHroycVifeQe4mvi +Be8g5KOtwAJdAs7Ps6DyPXVBeycvtWApuAoWpHrrpyOnGFjAo3BUAnECS02Tdr1iWNX mWng== X-Forwarded-Encrypted: i=1; AJvYcCXDeCEa7il+ETMOVPED2ef6eYJDKAU75tkucUpcuq90v1xXXzkKNT6OGbDK4687ThjZSG9QSnX3p/LT/Et/587MX3A= X-Gm-Message-State: AOJu0Yy1sOdvfDHiszGL8NKx/zbAbyRGzTayHVpC9Ur6vEg55FFphGx6 rL4wrX6D9qaERcGMaoMeNQIgBCPfBBFyk3ixIPucdeaK25yjDp3VoDI/SYgREus= X-Google-Smtp-Source: AGHT+IEg1KTq7jE0OLYYVBAFrVsprg4r4Srip8vRVS899kAu1nJanfI5DM3TwMhj/+BfX0hVCMH91w== X-Received: by 2002:a05:6808:1584:b0:3c3:e05c:f499 with SMTP id t4-20020a056808158400b003c3e05cf499mr1508075oiw.39.1711687513312; Thu, 28 Mar 2024 21:45:13 -0700 (PDT) Received: from debug.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id i18-20020aa78b52000000b006ea7e972947sm2217120pfd.130.2024.03.28.21.45.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Mar 2024 21:45:12 -0700 (PDT) From: Deepak Gupta <debug@rivosinc.com> To: paul.walmsley@sifive.com, rick.p.edgecombe@intel.com, broonie@kernel.org, Szabolcs.Nagy@arm.com, kito.cheng@sifive.com, keescook@chromium.org, ajones@ventanamicro.com, conor.dooley@microchip.com, cleger@rivosinc.com, atishp@atishpatra.org, alex@ghiti.fr, bjorn@rivosinc.com, alexghiti@rivosinc.com, samuel.holland@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-mm@kvack.org, linux-arch@vger.kernel.org, linux-kselftest@vger.kernel.org Cc: corbet@lwn.net, tech-j-ext@lists.risc-v.org, palmer@dabbelt.com, aou@eecs.berkeley.edu, robh+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org, oleg@redhat.com, akpm@linux-foundation.org, arnd@arndb.de, ebiederm@xmission.com, Liam.Howlett@oracle.com, vbabka@suse.cz, lstoakes@gmail.com, shuah@kernel.org, brauner@kernel.org, debug@rivosinc.com, andy.chiu@sifive.com, jerry.shih@sifive.com, hankuan.chen@sifive.com, greentime.hu@sifive.com, evan@rivosinc.com, xiao.w.wang@intel.com, charlie@rivosinc.com, apatel@ventanamicro.com, mchitale@ventanamicro.com, dbarboza@ventanamicro.com, sameo@rivosinc.com, shikemeng@huaweicloud.com, willy@infradead.org, vincent.chen@sifive.com, guoren@kernel.org, samitolvanen@google.com, songshuaishuai@tinylab.org, gerg@kernel.org, heiko@sntech.de, bhe@redhat.com, jeeheng.sia@starfivetech.com, cyy@cyyself.name, maskray@google.com, ancientmodern4@gmail.com, mathis.salmen@matsal.de, cuiyunhui@bytedance.com, bgray@linux.ibm.com, mpe@ellerman.id.au, baruch@tkos.co.il, alx@kernel.org, david@redhat.com, catalin.marinas@arm.com, revest@chromium.org, josh@joshtriplett.org, shr@devkernel.io, deller@gmx.de, omosnace@redhat.com, ojeda@kernel.org, jhubbard@nvidia.com Subject: [PATCH v2 01/27] riscv: envcfg save and restore on task switching Date: Thu, 28 Mar 2024 21:44:33 -0700 Message-Id: <20240329044459.3990638-2-debug@rivosinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240329044459.3990638-1-debug@rivosinc.com> References: <20240329044459.3990638-1-debug@rivosinc.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: 6BA671C0015 X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: 3r89uu6cumhzg3qpybf85ayyttz6pt8a X-HE-Tag: 1711687514-334722 X-HE-Meta: U2FsdGVkX1+ygXBtRr8toDOwbis/e9cnT0Kx1ArvDr/HjZmrzpVlbi2B/R8EUrWqDEXndHmLHtyU/tA59v0JRtr6Ocn3Xv9Jf395L/MwBJhDV2X1tT9RcJ0zsDW7ktDRIIvMdFjyxy40PVp0B0gom3rGkl+CmKAgi9imJFQfM4mjtUcZQAaqHw5lX2RkShzOPgEbPiDnuZMi3UbajI1TK0F5cnm3x6vTt+Cv1eo01+4mYECTpBOCjOEvxMkTVnGAgqJ5ZlDu4Rvv+wwEBAJsCjb0epVkD7V1IkZnv9QVL71u7Jwwy7Xr7rlEeYq6JpUg0dalb9zOxWmXjnQmz7RB5eshR+SUb1hAXsTza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Zy2BLok0HcIsiBvfZZMHAyMZfBO4/XHU5uZuLdPJB+L+5A/7rhjnPxR739R+BPCE+vsRpEw= 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: <linux-mm.kvack.org> List-Subscribe: <mailto:majordomo@kvack.org> List-Unsubscribe: <mailto:majordomo@kvack.org> |
Series |
riscv control-flow integrity for usermode
|
expand
|
diff --git a/arch/riscv/include/asm/switch_to.h b/arch/riscv/include/asm/switch_to.h index 7efdb0584d47..2d9a00a30394 100644 --- a/arch/riscv/include/asm/switch_to.h +++ b/arch/riscv/include/asm/switch_to.h @@ -69,6 +69,15 @@ static __always_inline bool has_fpu(void) { return false; } #define __switch_to_fpu(__prev, __next) do { } while (0) #endif +static inline void __switch_to_envcfg(struct task_struct *next) +{ + register unsigned long envcfg = next->thread_info.envcfg; + + asm volatile (ALTERNATIVE("nop", "csrw " __stringify(CSR_ENVCFG) ", %0", 0, + RISCV_ISA_EXT_XLINUXENVCFG, 1) + :: "r" (envcfg) : "memory"); +} + extern struct task_struct *__switch_to(struct task_struct *, struct task_struct *); @@ -80,6 +89,7 @@ do { \ __switch_to_fpu(__prev, __next); \ if (has_vector()) \ __switch_to_vector(__prev, __next); \ + __switch_to_envcfg(__next); \ ((last) = __switch_to(__prev, __next)); \ } while (0) diff --git a/arch/riscv/include/asm/thread_info.h b/arch/riscv/include/asm/thread_info.h index 5d473343634b..a503bdc2f6dd 100644 --- a/arch/riscv/include/asm/thread_info.h +++ b/arch/riscv/include/asm/thread_info.h @@ -56,6 +56,7 @@ struct thread_info { long user_sp; /* User stack pointer */ int cpu; unsigned long syscall_work; /* SYSCALL_WORK_ flags */ + unsigned long envcfg; #ifdef CONFIG_SHADOW_CALL_STACK void *scs_base; void *scs_sp;
envcfg CSR defines enabling bits for cache management instructions and soon will control enabling for control flow integrity and pointer masking features. Control flow integrity enabling for forward cfi and backward cfi is controlled via envcfg and thus need to be enabled on per thread basis. This patch creates a place holder for envcfg CSR in `thread_info` and adds logic to save and restore on task switching. Signed-off-by: Deepak Gupta <debug@rivosinc.com> --- arch/riscv/include/asm/switch_to.h | 10 ++++++++++ arch/riscv/include/asm/thread_info.h | 1 + 2 files changed, 11 insertions(+)