Message ID | 20240125062739.1339782-3-debug@rivosinc.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel+bounces-38005-ouuuleilei=gmail.com@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2553:b0:103:945f:af90 with SMTP id p19csp1452490dyi; Wed, 24 Jan 2024 22:28:59 -0800 (PST) X-Google-Smtp-Source: AGHT+IE9UJ32bjOQAcC7Jv6KQu54LgFqZQE7VVaNavJmhRmpShob4sYX8N/YSFjePazTB3uLqdDM X-Received: by 2002:a17:906:3152:b0:a31:2f87:d367 with SMTP id e18-20020a170906315200b00a312f87d367mr727830eje.29.1706164139219; Wed, 24 Jan 2024 22:28:59 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706164139; cv=pass; d=google.com; s=arc-20160816; b=E+naoAVfaAZo3PpC3cL0/7/Dxp3ub3M+YlzQgU9f8wQRBLSFvU7uj1fia54x6UZ1qd kwk+YaRpbQNeTfl1IrhIUNcpIwuCeqGyD3bR06oouQFX4KM9DYGKVqrc1WDIcr0BWRB3 tPU7nZwtWbvFOK2dzHk+FVQFyC1MHyzWQOJ9Qia0e+9PCbGtUYZTe6dy1bbM8fezmMUs 4mXUqDkM3C+BHmwwVhJ4bo9Mm4fnKvWrcNSUokSulkNCTunScQeD9OBAx0e2rZM8rxLg BzuEHCJlqDcleRX3urH2VvHQ7Rot9c0sF78ZsK0UowoPSVwOeQ1OXBHp1iMW1EegrRWe aTmA== 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=UpWYX6cXeb3EwmSmbUmLWJ8fZpndT9qVanP1zDkk0zs=; fh=oy7V1wWqiaug32hsWRXm98kKNp5NFPTWbY7PiGr4deM=; b=mokZwlYYE2Sbzcg6sG+vKJnOiumMUtQfYc99jNUuckuxy0iqtspBmUpzlxKIBEFaM6 9DVk27trS37Pbt6dYJDGS0Gpy9uLCodg/AIfu20Cdbcb6VPTm1f7iV9kKvsWOKJWXedL R8cISDPRbDL2w4y/ay3UgeoNz3W43aeKoPagASh+jkW9aqhO5cqIsQxFzdDg53aj9crT QEYsxBa+8lNn/QTNzmcvtNYBXFILEZ9U1/JMcbX5koKVJ9eA01Rxp3P+shYNcN6yA7N3 rwbc2Z5CyZgnKNnavJS+uV5Whuijy2aLmu5XYIqwQVm0AyQ/3oPdm99cNMLm0YcgILTQ ComA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=WGeuz059; 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-38005-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-38005-ouuuleilei=gmail.com@vger.kernel.org" Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id i13-20020a1709064ecd00b00a2cebb4ad80si648063ejv.322.2024.01.24.22.28.59 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Jan 2024 22:28:59 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-38005-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=WGeuz059; 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-38005-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-38005-ouuuleilei=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 am.mirrors.kernel.org (Postfix) with ESMTPS id A67061F23AFA for <ouuuleilei@gmail.com>; Thu, 25 Jan 2024 06:28:58 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 91627111BA; Thu, 25 Jan 2024 06:28:26 +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="WGeuz059" 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 3D40811183 for <linux-kernel@vger.kernel.org>; Thu, 25 Jan 2024 06:28:22 +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=1706164103; cv=none; b=VQGt8cnR+MU3P9E1d3Od8szNIREPd5KxMY0KJo2FQ7P79mJCHCZVp7dMYOoQPrs0yliVlWEAP/HLIXdWO6/7nWFYcnwnmxQpqkbte4gSCm4lkRUZUwFe9V8oxf0Uwy7moc1P+i7Eakoo2CKFO4D1PHHosLMneu4EtvKtnLIT9II= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706164103; c=relaxed/simple; bh=9+H+30KMPyCh1YcAoThxCuB9d80x0zddDEJVZVZUZoo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=k+fO6bg1eABJyCUvCoVNOYpbSBwYEGhf4W6jSItsTzokB1t3dafPaYBhfozc1DQUtckMtmML5uNsUl1RJlvFQlkBf+mdOYRtmxgO80HyaxxDFnQtz3o50zynuVENFwyq71cjdbYJ9PI9NDO8jjzNj219gO6lKgj9DogZrt1wmmU= 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=WGeuz059; 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-3bd7c15a745so4544387b6e.2 for <linux-kernel@vger.kernel.org>; Wed, 24 Jan 2024 22:28:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1706164101; x=1706768901; 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=UpWYX6cXeb3EwmSmbUmLWJ8fZpndT9qVanP1zDkk0zs=; b=WGeuz059B9Z7CNUInY/nBtaR+3tAYT7gRCwrfKaJIOcr3lGpa/M2ZxrOj23Cg8vfSN vGPHxxHrHzvQIMrh/VL+qkVSP7shRow2asqcbFfz8lWSF7SXpRb038vAEuSG+68NocGG 3QwFxC4K+qC7VsUdSForvULS9Ir6jtpqJIUaBmyGLe9ta4tbHeodNbZ6JtYxpCLaHWa5 X1yWDq04KFmpqjMA5I5bGhmAK1BCljJsqkL8ZlN79hBYPDck6iR+UMmHYogY4pDpbgpq /uY+aIJP+EhcTZXx6TqtIeVEbqOOoNXuGqOidNk0NGFxGJvwPkIkG8RLuqOaH8xt80uw 3F8w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706164101; x=1706768901; 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=UpWYX6cXeb3EwmSmbUmLWJ8fZpndT9qVanP1zDkk0zs=; b=dRiVqPMZGAi0coruv6QSHiuln4dIKuKTwKnzswK2PG1CEzTNwHxFbhlF+SoW+ZAgrW qsdoPYQmq3GWUCD//0JlQaZ+XSUoqvK+yzhRy3Un7obSEw6ZfLIgx9UIdR9AQhoLxFMW cniX4PwPikeRFX1xMo/PuJpmX/o2h3QUEpytvW1izcID37JctPBGSjAHj9efdHI3xU0z hgw1GdU4z8UyWPeuYarLn6/qLFEwI3w4sg11ymGuQSuok2hdIylP0MX4LhnHWst7UzcA nKWjp2kRYwphLxwyPWjhDcbw1yP9bAKOdWW64ouN/7nGA8jrx+i9vFu+wwEWNqVok9hB TCJg== X-Gm-Message-State: AOJu0YyiZoy9FvKBa4iA22N5xfENhpPnZzR7WlPzEp33juruRmMAFHKC nKWu6CyRpRlJ2hgvwXPKWpEkBROLVjuCRoU86BfOaJazhElLNCo4fbYUZG8TGpM= X-Received: by 2002:a05:6808:3197:b0:3bd:a590:8a00 with SMTP id cd23-20020a056808319700b003bda5908a00mr578367oib.85.1706164101404; Wed, 24 Jan 2024 22:28:21 -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.28.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Jan 2024 22:28:21 -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 02/28] riscv: envcfg save and restore on trap entry/exit Date: Wed, 24 Jan 2024 22:21:27 -0800 Message-ID: <20240125062739.1339782-3-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> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: <linux-kernel.vger.kernel.org> List-Subscribe: <mailto:linux-kernel+subscribe@vger.kernel.org> List-Unsubscribe: <mailto:linux-kernel+unsubscribe@vger.kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789042768578928043 X-GMAIL-MSGID: 1789042768578928043 |
Series |
riscv control-flow integrity for usermode
|
|
Commit Message
Deepak Gupta
Jan. 25, 2024, 6:21 a.m. UTC
From: Deepak Gupta <debug@rivosinc.com> 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. Signed-off-by: Deepak Gupta <debug@rivosinc.com> --- 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(+)
Comments
On Thu, Jan 25, 2024, at 1:21 AM, debug@rivosinc.com wrote: > From: Deepak Gupta <debug@rivosinc.com> > > 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. > > Signed-off-by: Deepak Gupta <debug@rivosinc.com> > --- > 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. -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
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 <debug@rivosinc.com> >> >> 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 <debug@rivosinc.com> >> --- >> 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
On Thu, Jan 25, 2024 at 09:09:14AM -0800, Deepak Gupta wrote: >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 <debug@rivosinc.com> >>> >>>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. Also I'll fix the commit message. I think that's what you were pointing out. > >> >>> >>>Signed-off-by: Deepak Gupta <debug@rivosinc.com> >>>--- >>> 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
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 + /* Save the kernel shadow call stack pointer */ scs_save_current