Received: by 2002:ab2:1149:0:b0:1f3:1f8c:d0c6 with SMTP id z9csp3035094lqz; Wed, 3 Apr 2024 16:42:49 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWCd2K1TzxQaVsZpjzbs9TqN3vQssINP8OjPHt44KmHlLK4Nok3KSwTck/w0sWplVVyABUOe+czOsXA/P6zxIHqb2Tqv/IL4s884HLCBQ== X-Google-Smtp-Source: AGHT+IHivvPB6tEGvsg8VkfQl5sUL8SUw1j40ppotLu+X+haw/M+pJs8pu5TgnLtxlF6soQ0Ge8Q X-Received: by 2002:a05:6102:3022:b0:478:799b:a426 with SMTP id v2-20020a056102302200b00478799ba426mr916855vsa.26.1712187768912; Wed, 03 Apr 2024 16:42:48 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712187768; cv=pass; d=google.com; s=arc-20160816; b=YRVDE81+AWyWMsnR0snXh5fn80Ln1RnqnT3wnfi8U7n2xqt3CcIvh9W5TLRqf53wqq mRNY+6EG+ZviRwT+9eGWnUUSTjOIhJrk9Jvzt8p6pna/24BOrlI8kMZ5Kg+OP1t73aMm llq3fl/1E71QpAtaNATK5p7SMZutVAChZY4HCNoktFJSZ/fKoaZVwJSAbr+3plzd19U0 ggbhQ8JYwR5orh1pQYeNv8qQdU7U5V/aheX957XTYsqz5sBU01qf+hHYl3UMDPprX2xs QGBI+2iCBXOSmpnzT+Cahzel7p28j4Kjz7gRZ01siJEgjrACqFfvHRmugFZ2fdhYoNqB vIlQ== 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=B1lL5f6yq9LaiF8GnxAfpEDQQL4kAkav9nCQOWb1C3Y=; fh=UjAuH419kMbvcUfoeF2SEdI8AvMnms2w9Un+Rsd3UF4=; b=b2gpWcnd40ccEILm5Zq4hPiQRF9j/Bx9wCkBAq+SruY4t9kWkySUR05aW+xIgqpxAQ i5O5wp/w9IIMEwIpe9SRcpvOBrhgX48h+dS2hcD/QrAfsPTGMqvZbwL29Ja378x3bAXT QA6uGbIw6KcjeMyGaVGYzOvLiBAPu+fhGmEvxPYXlA/IfB5EbGIhhbsyXn+sNpI00exi D/wXuGCLYdvTN2p2iYek3FGa74XUdB268qp5hNY8cwK+9nWd9upLdwFgnxkvPSn+gb3q 9HyBucCT9z5B62l8v9GJeQPBJJO9pwGLx400xeI9CxHQRYaUVZIu2NC085QeTqHcrv+9 Yk6Q==; 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="VbLmMI/V"; 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-130720-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-130720-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 d13-20020a05621416cd00b006990345af30si9309532qvz.55.2024.04.03.16.42.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Apr 2024 16:42:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-130720-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="VbLmMI/V"; 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-130720-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-130720-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 873491C2669D for ; Wed, 3 Apr 2024 23:42:11 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4D3CE156F5B; Wed, 3 Apr 2024 23:41:36 +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="VbLmMI/V" Received: from mail-pf1-f179.google.com (mail-pf1-f179.google.com [209.85.210.179]) (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 CC099156C55 for ; Wed, 3 Apr 2024 23:41:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.179 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712187695; cv=none; b=AwbGufkBNCxTf35dYjyKENnHUZlwAuWcl4ea+aKIihyDjWnfpolLTxhZw5K9Ejp/DRxRXNmB6SylsSPJM4CNf4ohypiP8x9qLbbivKXw7jK60wlSVgwqyFena4kVM3cCNpGDP7bf8WsEsOk52OigGkpAfYP194qLREza5nZR1Qo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712187695; c=relaxed/simple; bh=DyzxnXYOFHCz6d4trVGJB39+6FjfyRM78o1GLQGA+r0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Ti8fIP8fngzR2aMuvgJfRChtM83Kmwa4kCn4e1XIlysrT53MTihUhX5RyulRT8coTDVA2+os2Ud7uiPMOairfC7cmJbg5JNv7W6NXYohyzEul6pLS1/cnlRszuWrebMwvJhfkS5zJZXOB2Jlta7WLRzjc2kgcruEaH8MpXJi2Rc= 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=VbLmMI/V; arc=none smtp.client-ip=209.85.210.179 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-pf1-f179.google.com with SMTP id d2e1a72fcca58-6e704078860so341069b3a.0 for ; Wed, 03 Apr 2024 16:41:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1712187693; x=1712792493; 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=B1lL5f6yq9LaiF8GnxAfpEDQQL4kAkav9nCQOWb1C3Y=; b=VbLmMI/VIxUJ4bM6wZA4v9O/lS22xRM1g1jl00ifbHN3KyhaC5Z1iO14LjEKjyhBl7 tF/aZfOpg2Jgi6v2XklA5tB9HHSxW5G1Q1khNU0lUGIVrXr0qIU5GMR7bOK3pP9D2/Ap 7ISybqmy4/+aWgC3esEuZ895KLahu2m2gc2Vs3S90OPVEQ0Mc77vT0MgkWU5wlXK9EQN T+2mtVVSFQM8Eb2zyaQKwWzKJJT1kC2qLLU7Sc92nXkquiIQNg8xS+QhesXFgZXPry18 7CjswXpglJ2VYzFKYYnQCI2cdN52XmWC1nlZ2FKZbMVxho5C2xAj/6XVRXRYcnd3Pxkd 92Fw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712187693; x=1712792493; 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=B1lL5f6yq9LaiF8GnxAfpEDQQL4kAkav9nCQOWb1C3Y=; b=MVort/oBKlnALjhSji9VGRlpAOIYDqyeo+3rGy0qY8XNfeSBk8ETzvXev2C3Gpgs0V cjVyh5sjIjjdonu2x4K5enOKuYj8028wPSYmbE43HF2TQVRBZQ9sVFuhpxEv/Em8iH9+ dmLB5qMGxgOi7Ppmf1nc8LdVMxrmdWbio1iJtVxkXQO8ZCwlBrPkWF9bbuf5a7cUu8vu hYrmzvGChpJ3ngMxpvCGyYvf+n1wN5nbBLYWecZuxneFmOXvclyBgXMtFIXChKe53gky Hv6EY3bLjzQWXJKLbwi+Xz6ry8nF6OYVTRiT/aUvyS9yqNBVoPDkbNYjpYNiorfezzAP GHWA== X-Forwarded-Encrypted: i=1; AJvYcCVGRsbLvTdEIq63mORDu3BXeAVF7ikC6Ce/FM3Whzu/5dhC/Tm26Q128cANrpMMHcxkQiyac1eloifdS7xhCJaX8qWo3RzO11LbgqaH X-Gm-Message-State: AOJu0YzLpMJzBBuwT3G9N4cvRo3VQdODAAaOrr/NBIKYqPRQGP1QQZX1 taWu+4SFItf+727axxPWHIKUOyt5IqtSPVJO3a1wE9vH+sJXAJ0ml4oRwMlgn8I= X-Received: by 2002:a05:6a20:de16:b0:1a7:1df5:1699 with SMTP id kz22-20020a056a20de1600b001a71df51699mr975407pzb.27.1712187693134; Wed, 03 Apr 2024 16:41:33 -0700 (PDT) Received: from debug.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id b18-20020a170902d51200b001deeac592absm13899117plg.180.2024.04.03.16.41.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Apr 2024 16:41:32 -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, conor@kernel.org Cc: 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, corbet@lwn.net, 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 v3 01/29] riscv: envcfg save and restore on task switching Date: Wed, 3 Apr 2024 16:34:49 -0700 Message-ID: <20240403234054.2020347-2-debug@rivosinc.com> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240403234054.2020347-1-debug@rivosinc.com> References: <20240403234054.2020347-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 are 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