From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f175.google.com (mail-pl1-f175.google.com [209.85.214.175]) (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 68F272EDD7A for ; Wed, 3 Dec 2025 17:19:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.175 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764782376; cv=none; b=QPaPpnYaO1xGm1iz7s8TaONoScMfpMrsxOmZ2T66d8Hfk/b4RS1V5Kci4MrxGOSMK2saL55edOEIEMCJkD8C/9jzx4UzC0QTAzyarf+6E5zgkFlXyabWUsG5VmQMXteGh/Xxcm7NQ9luGqNvdOani9VeLgcAZwa4gA1k+Ozz2Uo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764782376; c=relaxed/simple; bh=CwA9Ys5uCmBjSmMP2RcG9FxDi2vRp38nNCScDl7Ne4w=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=GJac4ElnFAKOB+yAptujQArystJfe/xKjeN6zD8JdXTb/36Mqcy0DuzskI26IPoFNA99xhUYpElMo4yMB0SBxmUv1oFAYLBHPhCW0WeTbT7Er/0sP4B3M0l2zHMBWJS2gzV3ZMySGrtwyFZNlfPXdmXgy6DQk8mQNmYBIIe0/og= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=rivosinc.com; spf=pass smtp.mailfrom=rivosinc.com; dkim=pass (2048-bit key) header.d=rivosinc.com header.i=@rivosinc.com header.b=Hjgg+62H; arc=none smtp.client-ip=209.85.214.175 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=rivosinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=rivosinc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=rivosinc.com header.i=@rivosinc.com header.b="Hjgg+62H" Received: by mail-pl1-f175.google.com with SMTP id d9443c01a7336-29853ec5b8cso84712375ad.3 for ; Wed, 03 Dec 2025 09:19:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc.com; s=google; t=1764782374; x=1765387174; 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=ntk4xZMcJdx9GyxuuhaDbNEO4dKaRG4g/4/eVizjmMk=; b=Hjgg+62HKTnyEzu5kmSlofkEsioAgC0rAc0wXBtDMFckRRzbLlJxkTEN1phMy14VVU JgF6tGBxauZZLfJe43QCqkuFbavS4MqSAo5AthVF9H2T9BNW1wmlY3WYq99ZJ5idA9f9 FKHSCpdICyCjoDjXBTpnNXS/d0CcGfNpseDV48PUJnJ+cJo/2uX4IbADyYvFS87gWYNz TN28JBFiO85Wm15B7vQRpmdnbEY2+++Ch8kLvf1Li+TMsVQJ0nCOdyWLF9T/cf6VHmVV PDIREze8ZBjhT7C2o+5+8SQZ8xhFsiKYyCSefn4m9kusRc2NShwYg8bZKiAVlDT3/2/T eI5g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1764782374; x=1765387174; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ntk4xZMcJdx9GyxuuhaDbNEO4dKaRG4g/4/eVizjmMk=; b=ksox6ult8XpKbSOmjTcla24HPWKA0VqTR7lh0SCahHJuySRFn+sxDi7HdiOTZDokde RcuxtPPbVdVKe905RLe64QTgDoAM/WH3cN/54LhE50wY0YM8cS8IeHxmqnlNS3eGYlV3 0P+k+OR5mb/dCxcybSZJa3btRmjuO5sVKYh8QREmL3wbH+DGGhOtq8MqzJ1O5lg/ICb1 jaUBa69zMfB0dCXOZKfWuyfPrdBs9/dpU6v8gUoc308NHfIz7Bxet33vhikXXEXxmWaP Ws7B1g/eKwszEN1bPTRFenIP3ih4VtZXw39sMqS6hKprfCOtvokHQcvEjn839JLdCQC6 i8Uw== X-Forwarded-Encrypted: i=1; AJvYcCVR+QeasVdndhJQMzwinOsX1tsjeKQJRc15634SQFF59oxPvnsMj0SfwQMG19FXUBWeG9I3SZLsWME9NbI=@vger.kernel.org X-Gm-Message-State: AOJu0YxyyquuAf4S4JG5fB8xh7/ytyXFbGp4uzaftfDIVokuGXYQVSKo uza6FNttLFNnGFqLrv1GRM9s8jPNWhA9QHhsUYxTKgpQlqGI1t8+6yy8+w//R950jPvQhM+RhMX R0i/1 X-Gm-Gg: ASbGncvB1QrKvj2oasrSJUZI1rgRM4RQb+O0xSleqnFJljd+UhFOcFmK4zSSjqXHwBM p3tMMNc5rywSRHV0tuxwc19mMGLqSAQDvwjaTK0shRVXhcDCs1y04gzY94eSG+vddrIYqMvVRIk wOvkCX8TwJOiTl6MEAsVTwPufuK6Jh/f1LFZUwFVWzvnH9I2IBijBtID6x3XcJWCuWXnQgzkHtU wg8EXtyY6+AX6kTfoj13VAsg2yr36bLyl2CrKy50qyCmmiOVDWz/RUoaitoQOGwwANEWXSkP1G3 f8NBsKt/AX8W3P8BHJGQ6pYFIhoImQwCNqh+SVqKmRBljdKdQ2y8ssZhNhESHv7PyehyBUhtnkP PzTc7qvOYK4aSg9HtJJivQ1XmYFh+I8oxviv9ohfBDY0x9QfRxl/H6r1Qc/SYCIfWJuU+h6y3SO 2Q/hhD4Ld+nb53ucpKgwL3 X-Google-Smtp-Source: AGHT+IEJ2Iti/5YvIxdDWKb+Z7naCD/zlmjgrBAtvofU3TTuAmsOEg1X1az1RgMcBWVQzA1qII+ZbQ== X-Received: by 2002:a17:903:40cf:b0:29d:65ed:f481 with SMTP id d9443c01a7336-29d681418femr39682905ad.0.1764782373529; Wed, 03 Dec 2025 09:19:33 -0800 (PST) Received: from debug.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-29bce442691sm188814395ad.28.2025.12.03.09.19.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Dec 2025 09:19:33 -0800 (PST) Date: Wed, 3 Dec 2025 09:19:28 -0800 From: Deepak Gupta To: zhouquan@iscas.ac.cn Cc: anup@brainfault.org, ajones@ventanamicro.com, atishp@atishpatra.org, paul.walmsley@sifive.com, palmer@dabbelt.com, linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org, kvm@vger.kernel.org, kvm-riscv@lists.infradead.org Subject: Re: [PATCH 1/4] RISC-V: KVM: Allow zicfiss/zicfilp exts for Guest/VM Message-ID: References: <103e156ea1f2201db52034e370a907f46edafb83.1764509485.git.zhouquan@iscas.ac.cn> 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: <103e156ea1f2201db52034e370a907f46edafb83.1764509485.git.zhouquan@iscas.ac.cn> On Mon, Dec 01, 2025 at 09:28:25AM +0800, zhouquan@iscas.ac.cn wrote: >From: Quan Zhou > >Extend the KVM ISA extension ONE_REG interface to allow KVM user >space to detect and enable zicfiss/zicfilp exts for Guest/VM, >the rules defined in the spec [1] are as follows: >--- >1) Zicfiss extension introduces the SSE field (bit 3) in henvcfg. >If the SSE field is set to 1, the Zicfiss extension is activated >in VS-mode. When the SSE field is 0, the Zicfiss extension remains >inactive in VS-mode. > >2) Zicfilp extension introduces the LPE field (bit 2) in henvcfg. >When the LPE field is set to 1, the Zicfilp extension is enabled >in VS-mode. When the LPE field is 0, the Zicfilp extension is not >enabled in VS-mode. > >[1] - https://github.com/riscv/riscv-cfi > >Signed-off-by: Quan Zhou >--- > arch/riscv/include/uapi/asm/kvm.h | 2 ++ > arch/riscv/kvm/vcpu.c | 6 ++++++ > arch/riscv/kvm/vcpu_onereg.c | 2 ++ > 3 files changed, 10 insertions(+) > >diff --git a/arch/riscv/include/uapi/asm/kvm.h b/arch/riscv/include/uapi/asm/kvm.h >index 759a4852c09a..7ca087848a43 100644 >--- a/arch/riscv/include/uapi/asm/kvm.h >+++ b/arch/riscv/include/uapi/asm/kvm.h >@@ -190,6 +190,8 @@ enum KVM_RISCV_ISA_EXT_ID { > KVM_RISCV_ISA_EXT_ZFBFMIN, > KVM_RISCV_ISA_EXT_ZVFBFMIN, > KVM_RISCV_ISA_EXT_ZVFBFWMA, >+ KVM_RISCV_ISA_EXT_ZICFILP, >+ KVM_RISCV_ISA_EXT_ZICFISS, > KVM_RISCV_ISA_EXT_MAX, > }; > >diff --git a/arch/riscv/kvm/vcpu.c b/arch/riscv/kvm/vcpu.c >index 5ce35aba6069..098d77f9a886 100644 >--- a/arch/riscv/kvm/vcpu.c >+++ b/arch/riscv/kvm/vcpu.c >@@ -557,6 +557,12 @@ static void kvm_riscv_vcpu_setup_config(struct kvm_vcpu *vcpu) > if (riscv_isa_extension_available(isa, ZICBOZ)) > cfg->henvcfg |= ENVCFG_CBZE; > >+ if (riscv_isa_extension_available(isa, ZICFILP)) >+ cfg->henvcfg |= ENVCFG_LPE; Blindly enabling landing pad enforcement on guest kernel will lead to issues (a guest kernel might not be ready and compiled with landing pad enforcement). It must be done via a SSE interface where enable is requested by guest kernel. >+ >+ if (riscv_isa_extension_available(isa, ZICFISS)) >+ cfg->henvcfg |= ENVCFG_SSE; Same comment on shadow stack enable. While usually shadow stack usage is optin where explicityl sspush/sspopchk/ssamoswap has to be part of codegen to use the extension and not modifying existing instruction behavior (like zicfilp does on `jalr`) There is a situaion during early boot of kernel where shadow stack permissions for init shadow stack might not have been configured (or satp == BARE at that time), in those cases `sspush/sspopchk` in guest kernel will start faulting. So enabling shadow stack should also be done via SSE interface. That's how user cfi patchsets also do. >+ > if (riscv_isa_extension_available(isa, SVADU) && > !riscv_isa_extension_available(isa, SVADE)) > cfg->henvcfg |= ENVCFG_ADUE; >diff --git a/arch/riscv/kvm/vcpu_onereg.c b/arch/riscv/kvm/vcpu_onereg.c >index 865dae903aa0..3d05a4bafd9b 100644 >--- a/arch/riscv/kvm/vcpu_onereg.c >+++ b/arch/riscv/kvm/vcpu_onereg.c >@@ -72,6 +72,8 @@ static const unsigned long kvm_isa_ext_arr[] = { > KVM_ISA_EXT_ARR(ZICBOP), > KVM_ISA_EXT_ARR(ZICBOZ), > KVM_ISA_EXT_ARR(ZICCRSE), >+ KVM_ISA_EXT_ARR(ZICFILP), >+ KVM_ISA_EXT_ARR(ZICFISS), > KVM_ISA_EXT_ARR(ZICNTR), > KVM_ISA_EXT_ARR(ZICOND), > KVM_ISA_EXT_ARR(ZICSR), >-- >2.34.1 > >