Received: by 2002:a05:7412:3290:b0:fa:6e18:a558 with SMTP id ev16csp99624rdb; Thu, 25 Jan 2024 09:16:30 -0800 (PST) X-Google-Smtp-Source: AGHT+IHQRGYMoUCnIzVQjCyWTNWu3I1RjLiW+dJXA1bkMyaAsaBfxadXwNAJ9yFidn4C+433ldsg X-Received: by 2002:a05:6a20:2988:b0:19c:61d4:2b9a with SMTP id f8-20020a056a20298800b0019c61d42b9amr118440pzh.31.1706202990245; Thu, 25 Jan 2024 09:16:30 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706202990; cv=pass; d=google.com; s=arc-20160816; b=qifTNlXk17IelJyVFVtkYrLWKZsWl9pIlme7TtKJM+eS+jRU3koB1+iUKVKKSznVYU vlXoQNURxYpCuR3wPNLgX58N9SQVYIDPd8RGT+eqOfVbQbHgsKn7/hoCI5Yiu9RurQSm HBR8I2U+WWEu7rGtaqQAFpau40QfHynsdzGpRTiFRyG5kjUxN0gjVfxrQ1+2E3Ju5MBG sJbBZmYELu8O6L8meq+Iq7Kyk3iZgoxHHmbjIw0qotD+ncWqxATAwAru/sC6nJBICSNO 2VS+1SxO/x6jtwdB9sn5SAFh2RwSOOQQEr5pEsGqszntCwu62pBHfzfU8/6GVPbgCzI8 eIZw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=EemHHEVJxCejDW2IGmWybsIfYtaSynaTSK4azEaq/DU=; fh=/E+QEIL1pZn07Lmld4kCACqnP0PRaPlefIDHM+sXSM8=; b=tlrvVrjwxaF1Oxzj1FQzMEE3Zza6nY3vn/+h9Ws/ts6yvCHSp3BW6Z/byrca1SYOsv N4xMt6U60ic6MS0vI6NMcvalUXoR27jjifAsT46k/RHr3bX4rbnjEzwm9cv3qZ2AXbmg D14yefOiHR6nZCof8tSLXvTcuJg8tpU4ZdHXnrRJF4rfoTGn7Ubi6Lvhw/OWlqyXN8pM QkSmJvGtcjFVQLuKleE7WKhpILjZoyTNBeQjzAcIbWH6qOJIr6muwFJzLr5rjCBf7G0x BQKZVYP0yk9gOwS69FkO8wPmzq+avxHr/3a9mVggs6PRHmuPL5T+g9YO52FEoJvMNpJ6 Uxjw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=wWxB6UTz; 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-39010-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-39010-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id x29-20020a056a000bdd00b006ddc61d9b9csi1689866pfu.35.2024.01.25.09.16.30 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Jan 2024 09:16:30 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-39010-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=wWxB6UTz; 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-39010-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-39010-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 96C17299034 for ; Thu, 25 Jan 2024 17:15:24 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3EDD712FF9F; Thu, 25 Jan 2024 17:09:23 +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="wWxB6UTz" Received: from mail-pf1-f177.google.com (mail-pf1-f177.google.com [209.85.210.177]) (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 BC821131735 for ; Thu, 25 Jan 2024 17:09:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.177 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706202562; cv=none; b=jPfEWxQJjFitXOVdX47PoTcKQ5thBZjO0eXGfxgREXE7MI/KAYIJVEqYWA95L6yBQCCivq1sw7rT2TeqLChu2UTPnbAcrKwmo93mWB/tIxX2TNzQ+vyT8QUgXEjsej3fZE5fXh4gqQfZ28sQQxeN44Be68uA5SY9FChTnni2Gtw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706202562; c=relaxed/simple; bh=SYP5SuCzecJg/AbMI+aiTjZqTA04WqjPusKcUYsXjXM=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=nNOCnJCOzpXxE7DGKj9RfmwYQU7fCV9M/cua/sncMxrOJTHksTq5gc7cOApgZP5OWRaKbuHWiTmIfd95VzoCYeOzbCza3mBRIh/u3NJtfW8zZVfbFwqc2gFwb9a649Po6av/w2rz8leqWqTgFYwHtuMJrE7FZW55KAG1bdLKqz4= 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=wWxB6UTz; arc=none smtp.client-ip=209.85.210.177 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-f177.google.com with SMTP id d2e1a72fcca58-6dd853c1f80so688708b3a.1 for ; Thu, 25 Jan 2024 09:09:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1706202560; x=1706807360; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=EemHHEVJxCejDW2IGmWybsIfYtaSynaTSK4azEaq/DU=; b=wWxB6UTzC752chpv9Ex6QtzPlDcXZCYcUzrQ39rHeCXZCx0ugi59QuQ5HcMpjSm2fS 6lAivpF8m4CyLmGbvvFo9dr6Ve6NuXhKeRS5/kxBJ24Rf9QTbnzvCpUgAZ1K8xSfi3o+ 9dAaOzASZoMzm2tnA5qQoUdKon0uPc042Zor/AJTthSQMkg1DWUGrbDkjjc++8V3imHl +RlWnYje6UplVxu8RdlbYeY8EoNa/qaZPjylUEDaxLEQq4r5Bj5mNfrenqAepVh+P1EU qAO8x9NbM4c5eGD4CvKZ+MC2e6FupknCCBBthBiBpn6rfcINTVglRhcmFkzmHSTWn2cr FI1Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706202560; x=1706807360; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=EemHHEVJxCejDW2IGmWybsIfYtaSynaTSK4azEaq/DU=; b=tLS/trEJ43X1ZapXRL6Ad27rr6zf2FYTg54qNRuMWWeX1sFCg2rdzxptJxG+ZuY0L4 c4oCLp9fhVboofX739g0uiSp0sJx6WOOyr9P9r/lSFdQdOKWmjogrgl6uhJlbbaRYIrs vMPVsBbl2U+O7+KvEnyeh0mJEkKQHHfqmjgw/B+EiqOuRHjWSd5gl9GR3HcnR+aa85qQ PQ5Us2og3TINlVYVW/3mEaqxrINBCpgy6el9AALgurgwcHoNDfszC/Ot8lHew960QFGE 8vHtRac3YzX6YKlz3hpSKjaS+9xLeFyd6r+guSIFYoUZPAqLOBRIlBmPtkaWDZ8x/jVT 9B0g== X-Gm-Message-State: AOJu0Yxd9BH6BIF4ZXfxylMAhGxwhZRn19E9rmFCEOCJry+EkKwAHoOB Vc++zELsi2CR3GNnzbU7cTxN/cuiZ2QX0ANb2hJ5uy22cVxkeTU9MRUUBtBEHVc= X-Received: by 2002:a05:6a00:b4f:b0:6db:ac96:f530 with SMTP id p15-20020a056a000b4f00b006dbac96f530mr221939pfo.24.1706202559878; Thu, 25 Jan 2024 09:09:19 -0800 (PST) Received: from debug.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id w128-20020a626286000000b006dde0724247sm180477pfb.149.2024.01.25.09.09.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Jan 2024 09:09:19 -0800 (PST) Date: Thu, 25 Jan 2024 09:09:14 -0800 From: Deepak Gupta To: Stefan O'Rear Cc: rick.p.edgecombe@intel.com, broonie@kernel.org, Szabolcs.Nagy@arm.com, "kito.cheng@sifive.com" , Kees Cook , Andrew Jones , paul.walmsley@sifive.com, Palmer Dabbelt , Conor Dooley , cleger@rivosinc.com, Atish Patra , Alexandre Ghiti , =?iso-8859-1?Q?Bj=F6rn_T=F6pel?= , Alexandre Ghiti , Jonathan Corbet , Albert Ou , oleg@redhat.com, akpm@linux-foundation.org, arnd@arndb.de, "Eric W. Biederman" , shuah@kernel.org, Christian Brauner , guoren , samitolvanen@google.com, Evan Green , xiao.w.wang@intel.com, Anup Patel , mchitale@ventanamicro.com, waylingii@gmail.com, greentime.hu@sifive.com, Heiko Stuebner , Jisheng Zhang , shikemeng@huaweicloud.com, david@redhat.com, Charlie Jenkins , panqinglin2020@iscas.ac.cn, willy@infradead.org, Vincent Chen , Andy Chiu , Greg Ungerer , jeeheng.sia@starfivetech.com, mason.huo@starfivetech.com, ancientmodern4@gmail.com, mathis.salmen@matsal.de, cuiyunhui@bytedance.com, bhe@redhat.com, ruscur@russell.cc, bgray@linux.ibm.com, alx@kernel.org, baruch@tkos.co.il, zhangqing@loongson.cn, Catalin Marinas , 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: Re: [RFC PATCH v1 02/28] riscv: envcfg save and restore on trap entry/exit Message-ID: References: <20240125062739.1339782-1-debug@rivosinc.com> <20240125062739.1339782-3-debug@rivosinc.com> <23d023c0-27cf-44fa-be0a-000d1534ef86@app.fastmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: <23d023c0-27cf-44fa-be0a-000d1534ef86@app.fastmail.com> On Thu, Jan 25, 2024 at 02:19:29AM -0500, Stefan O'Rear wrote: >On Thu, Jan 25, 2024, at 1:21 AM, debug@rivosinc.com wrote: >> From: Deepak Gupta >> >> 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 trap entry and exits. > >Should only be "restore"? I don't see saving. It's always saved in `thread_info` and user mode can't change it. So no point saving it. > >> >> Signed-off-by: Deepak Gupta >> --- >> arch/riscv/include/asm/thread_info.h | 1 + >> arch/riscv/kernel/asm-offsets.c | 1 + >> arch/riscv/kernel/entry.S | 4 ++++ >> 3 files changed, 6 insertions(+) >> >> diff --git a/arch/riscv/include/asm/thread_info.h >> b/arch/riscv/include/asm/thread_info.h >> index 574779900bfb..320bc899a63b 100644 >> --- a/arch/riscv/include/asm/thread_info.h >> +++ b/arch/riscv/include/asm/thread_info.h >> @@ -57,6 +57,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; >> diff --git a/arch/riscv/kernel/asm-offsets.c >> b/arch/riscv/kernel/asm-offsets.c >> index a03129f40c46..cdd8f095c30c 100644 >> --- a/arch/riscv/kernel/asm-offsets.c >> +++ b/arch/riscv/kernel/asm-offsets.c >> @@ -39,6 +39,7 @@ void asm_offsets(void) >> OFFSET(TASK_TI_PREEMPT_COUNT, task_struct, thread_info.preempt_count); >> OFFSET(TASK_TI_KERNEL_SP, task_struct, thread_info.kernel_sp); >> OFFSET(TASK_TI_USER_SP, task_struct, thread_info.user_sp); >> + OFFSET(TASK_TI_ENVCFG, task_struct, thread_info.envcfg); >> #ifdef CONFIG_SHADOW_CALL_STACK >> OFFSET(TASK_TI_SCS_SP, task_struct, thread_info.scs_sp); >> #endif >> diff --git a/arch/riscv/kernel/entry.S b/arch/riscv/kernel/entry.S >> index 54ca4564a926..63c3855ba80d 100644 >> --- a/arch/riscv/kernel/entry.S >> +++ b/arch/riscv/kernel/entry.S >> @@ -129,6 +129,10 @@ SYM_CODE_START_NOALIGN(ret_from_exception) >> addi s0, sp, PT_SIZE_ON_STACK >> REG_S s0, TASK_TI_KERNEL_SP(tp) >> >> + /* restore envcfg bits for current thread */ >> + REG_L s0, TASK_TI_ENVCFG(tp) >> + csrw CSR_ENVCFG, s0 >> + > >This is redundant if we're repeatedly processing interrupts or exceptions >within a single task. We should only be writing envcfg when switching >between tasks or as part of the prctl. > >We need to use an ALTERNATIVE for this since the oldest supported hardware >does not have envcfg csrs. Yeah fixing that in next series. Thanks > >-s > >> /* Save the kernel shadow call stack pointer */ >> scs_save_current >> >> -- >> 2.43.0 >> >> >> _______________________________________________ >> linux-riscv mailing list >> linux-riscv@lists.infradead.org >> http://lists.infradead.org/mailman/listinfo/linux-riscv