Received: by 2002:ab2:b82:0:b0:1f3:401:3cfb with SMTP id 2csp867494lqh; Thu, 28 Mar 2024 21:45:38 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUKwn+IPOE0VUGPtpd2FXZ5COQ14BqWhUhQAHaxw/DFyYMkUYpwmtYFFVajCJpDQuzncQKqEAXOrZzvyWpGMNPKWTKu39LgfXcV5A2B4g== X-Google-Smtp-Source: AGHT+IHFGwHyrJieYbBYJBbE7L6XPpjGMigBQBgTeJs+i6UXngqsX1Nd1J2vE37xrZmYUeCn2iKm X-Received: by 2002:a05:6122:2f0:b0:4d3:362f:f9c1 with SMTP id b16-20020a05612202f000b004d3362ff9c1mr1367519vko.13.1711687538092; Thu, 28 Mar 2024 21:45:38 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711687538; cv=pass; d=google.com; s=arc-20160816; b=XaLCs6KsxXV+7d7n45iKmpXNAWNAym3Ce01kpvNKm3VbgNUKw1Ky2zikyAeUD35MRe 04ZKYFbAgKhv4yKSajEmQmQ8lpqLBkWBgYzNQ8kRT7K4vMyhCMZkaWKdJPFuYTcA4tPh oreKf9d/C+HYZHcWqh9fpnCUWEWTd/RvDxEkmlyZZFcrBjXZICvRN5HVA8glC7OOXzFJ CjGJqapFVPGId3ZgP9AsRrX529L597ZK5HwT04+Djnu7YeinbX1K7UHiPZc9FD0xf3by hTN2nDd3G5WHiRTJW3XMeswuwiCBKAKPozBXurAzVNJIjj075dS9fMGuJARHHNE2DH6p VAVw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=txT/LccY8POETQDQkXcfynUkPCv6cjOV6zf46WX/Pcw=; fh=7LMA1BofhtxEVSfs9MvfQ5k7Dd0CzvaNPwpyl39kyD8=; b=AdmZq1pUXkEz5r07Dc/RZ+agS0/OGRMt8gdOqAJIbj1i7VbMrn3nLE9RlRS4R3VbZT EazA0GfOO1sq1loM9kynJ2cHC5PETBZifS4c6i5jI7bJ7HR7ZXKAQxriQ4Nhzwjqb67A l27nju95N7MGzJ6LeylfO+rUmhql/Fjoyp1ObSeDmv957NPgAVZ64UhYh6XkMcVXIp6q ol4JpA3gFgQDxfqTfOCcQ3xmTUrrsq1y9qJxPhqFBTX5LW4c+0f2x6/Eyr+SBaJyBrPV w6g7MB63ETsZTfbF6rTUK5w+w775QQx2HjMcksrnwtgIFhlqmvkczknUuSKQ0rexEjQa eg3A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=dTb5TpmU; arc=pass (i=1 spf=pass spfdomain=rivosinc.com dkim=pass dkdomain=rivosinc-com.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-124118-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-124118-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id m9-20020ad45049000000b0069681bbfd9csi3002409qvq.481.2024.03.28.21.45.37 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Mar 2024 21:45:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-124118-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=dTb5TpmU; arc=pass (i=1 spf=pass spfdomain=rivosinc.com dkim=pass dkdomain=rivosinc-com.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-124118-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-124118-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 797CB1C23A2A for ; Fri, 29 Mar 2024 04:45:37 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id AED503BBCE; Fri, 29 Mar 2024 04:45:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.b="dTb5TpmU" Received: from mail-oi1-f172.google.com (mail-oi1-f172.google.com [209.85.167.172]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 39AA93B79F for ; Fri, 29 Mar 2024 04:45:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711687515; cv=none; b=YZ3nb4sPlmhzGySmjpNV9ewEzJFYfXLNZH0fBMabAp9XDliv4wBtM1blr7IavuQLXhhGz/2yIxLDZwWoTnI3GKWTXWSBfOpOmNR6dWauhod7P27lnD99cfBxVmt5qm6wgWNpscrSOIDnAKkyNffkysDCpd/MDk5sXs5Rz70HjDM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711687515; c=relaxed/simple; bh=zG0tEeBP+zvlyz5cnQr5MClbjEm8rVN8C4s+1xfpDqQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=D1FpnD4eOrF/TR7kdShZbjtT33eXZWDGQRnhBUPNUULYARxXzyvA8Wo888wqx1BrdNrkEb0QmCXAx7QpVDkLaDq4cbHXmBjqp2a3nVxu5N3cXhijWaviL+OyUrYEIB+TAs/5bmnrBJ4T1fA8zUZG4yu9o3Tfp4xx4fsmwpSOHZU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rivosinc.com; spf=pass smtp.mailfrom=rivosinc.com; dkim=pass (2048-bit key) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.b=dTb5TpmU; arc=none smtp.client-ip=209.85.167.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rivosinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=rivosinc.com Received: by mail-oi1-f172.google.com with SMTP id 5614622812f47-3c38eced701so1017798b6e.1 for ; 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=vger.kernel.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=dTb5TpmUPw7ef/9qYzYpDdie7SYJme4gr3jRsPvSkzT4PmfBFG95GBons5rIe8N3Hq 2caUTED1gHdCKxfrfGiT5xiE3WaIJCTSwzhjXFreo6E5blO+BQCxiMqyxh6FW1c5O2B6 luw8GRlioxxTSLmA0KFWVJ/p997w9Nzafs7h4rmY9NNRr/cWE0IPWaFdk1Kadgu6RbZt L4yz2L7Ld0fceVtMB3hSUyISo1lXE+ZDN6pPmfcWEERqasct2J+x6scnLXaLKP+fDnnV v0SkR39pDdaZYoT+lJeGO4apudmmc9haVKmR5rNdJvHvb3+s/opzSWJnw3qYlartL/dH Pctw== 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=ItuNKEI5EsKOSNrwDL1JrLEhVJurbnWkOOabM4TCqrM4U8tFOyIQPRpoez5T72b+R0 bTOEieIgnBjiL4eUD99dFn9K233oFzc0JrxpTF8kGH0Wd69OsCb8ClYj+9OX25JLowp7 NGJXOwlSzrz1i3AmGh2OvcMZ/1JWH9AZPdyNO50Icr0tAqPXzeS8Zrbsror1JmB5W9Vm tThngDYECcHjz2FJmdF8bHpTaU+qILzmfaTZN1ojS0WpP8S7UynREE1b8cPAjcl5H4V2 uRqGZOVodgChVdZzQGRcoSTaJ0Xo5cMXwS30nAVALEZ+ZVnnaS2ozJ9vw0kbIvs+dPy5 EyzQ== X-Forwarded-Encrypted: i=1; AJvYcCX9W3RDXCjabMthyJClA70OXfG6tKacc8vmtAcKnPJv64qaJmHoq4Enxu23W0uCuHBysWu2Va9BeC+jpJGs1gLnfG+6oTQtuyqtqwbo X-Gm-Message-State: AOJu0YxKPh0diak5HLVZIoSj1JZbyv2FJq//37fpI1P3qux0IjIE4Ymb 5gvoSq33VHwQIZg7aAfRLAXJA16niBvoZe89zgn1WAY2qUG9XuKJvtGLKnxoS0Y= 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 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> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 --- arch/riscv/include/asm/switch_to.h | 10 ++++++++++ arch/riscv/include/asm/thread_info.h | 1 + 2 files changed, 11 insertions(+) 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; -- 2.43.2