From patchwork Thu Apr 18 14:26:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?Q2zDqW1lbnQgTMOpZ2Vy?= X-Patchwork-Id: 13634929 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 70D6CC04FFF for ; Thu, 18 Apr 2024 14:27:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=a14bx2KM5zOOjpNjaJOuSOBJhiWBH60SMOeCH4F9pSc=; b=vMqp6++EkPPEK+ 8cCgPTREVJh5yLbBs4b82dkwo1KomKV59bpAkJ5foZ8OU5W4uzwzNKAMUO3ZtfoNBj0uAX73/SrwO pd4h0XRsPrW3Ml1OmQbKesr6dyaEOi8p9Um9HZqoKCDDmVMd5VPohIvP9+l/IXnIJH6RmaiDURLnw ceGeft64lqI+Rs6SVxB1ZdT1fjZRzTYPJNUGkfZgC0ASg3KgTg5A7vSIeh9c6Hu35TGQ0OjDXmSfd TZXdrNVN/ajCc8zhoZG26WJhnjxv1BSNFUUZ3WDss8317GV9AUJPMO6k4iTbKp1iqkcJMZKEM5jq7 OGy4UEvyXd8OnWlqpVmw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rxSjf-00000002cdD-0aqz; Thu, 18 Apr 2024 14:27:35 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rxSjR-00000002cYz-3yyb for linux-riscv@bombadil.infradead.org; Thu, 18 Apr 2024 14:27:22 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Transfer-Encoding:Content-Type :MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Sender:Reply-To:Content-ID:Content-Description; bh=JY0qCZAt1G9FqrirGdQPEL//dx+I/VeYeDHijBAzwaE=; b=Qro7cHd3fC+Dkn+BgdtiHMkZNx 0nhRdA2wE/tJPQN4fqr5fO2GXqSYW1cjNtVIZ6G40/4uCKJAhEdlGVNnpWTJi4j6L+5KACHi2REmT Fa1k7cGqF6wcXm6yRrigIwz97MMgm/L+UL5rvJKlVZzLswJsFfi9u1UdFJ76nlC4QTfsfFM2FL78d CcAFzPtELlvEjxoZ8Kif51bsfGiaLyvmoAJszCmBSi12w9SpZiHDqMY7/QoyDKzzd+eLxJts8uy/m Epzwb6CUFMcFxusjujaY3sF5FpUCs6y7GRb5pMLnlOzey+cwTLN/Q+Jh2rKazRtrDZOA+OuZ0VMKC f8C7cinQ==; Received: from mail-wr1-x42f.google.com ([2a00:1450:4864:20::42f]) by desiato.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rxSjN-0000000C2Pk-2ovD for linux-riscv@lists.infradead.org; Thu, 18 Apr 2024 14:27:19 +0000 Received: by mail-wr1-x42f.google.com with SMTP id ffacd0b85a97d-349a35aba9dso167616f8f.3 for ; Thu, 18 Apr 2024 07:27:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1713450436; x=1714055236; darn=lists.infradead.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=JY0qCZAt1G9FqrirGdQPEL//dx+I/VeYeDHijBAzwaE=; b=ARG4KZEShLKzSSE9s4vbuISuP7kCYtUb85M/J5mhftVZXIDH9uLn9Da+EqCMZ4yxKI beroNeh8VJaWrKpaYesms4/NVZtodywiZUj4Sx+bMvoBJ6WtSlDc3HODNyyzqdS4lPnG dTBfPNruy9jOr9A5k6tzus/dkZNuMG3MDkpISTcSY9E9w6o1j+rHNYdRhTVBlfxbOf5J xy4HZBBSQxLO5yrw69tCMCk6EmSbPBU8dlroh141wwrhjLO1hh0o35wUCaJkKsFh3Wlq shK/nYTYPJjldrG5hVyUiuUxAz7ScOt2CamY10PJMGro63Q+gS3Qykt5bh21KEHAMheY FpCA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713450436; x=1714055236; 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=JY0qCZAt1G9FqrirGdQPEL//dx+I/VeYeDHijBAzwaE=; b=ddrLVNpQBMS45OHgukLFjCXoedKlPG3H7+WfEVePqdZ3Z/lEX7I9o3c9SZjgvSOICT TouwIORCPSn8d3izLamoLOBsmL56LkWU1YJZHki0MC+coJCtpxmQj32TqHiK4BlJ+7jU UjCxkzMKrnV/5sGwCdtBJ+lL6IouzFqjhojICMMhBERrkA87XbTeNJh5vL944qBwLI+x zUviy4ud4VZB+yImsK72NsJUKwYwyAUxqlJfgWF3dxLYcGyKj9P5lQhtx5pvZ8xVhaI6 zDa8oUBFLTVhcatfBn1hLCe9I38PPLhgn260X4DOIqTRsMvlJS1Yrwa8cuxJQHOtMr2D B2FQ== X-Forwarded-Encrypted: i=1; AJvYcCVu1ji11xQ3LlAuPFBLXddHsuRpHMsVZ1Dx7MHWafp0IVnRBshykPQeqCq/Yj42JuK1m44BOTzNqzpxVxsyXIf15fnYi3EnmS6cEBOyx5Ws X-Gm-Message-State: AOJu0Yz7nr/CI8zWGMomgBztNkyvDlTY+CKojqi7ZDpvPWfdId+535TH F9ZpPm0HErXfcTAkZYGUcDXe1c0Av9fqSfJYYWjM00zypynIAiRbLq0NHTaljMU= X-Google-Smtp-Source: AGHT+IG9QM4RObWosVaHJ2Bu9iGsOImG7zvYuk0PErpgTMOYFhKXz5bCpwhT6ZoBg0yBf1Ld4kG3yA== X-Received: by 2002:a05:600c:3554:b0:416:7b2c:df05 with SMTP id i20-20020a05600c355400b004167b2cdf05mr2101037wmq.1.1713450436400; Thu, 18 Apr 2024 07:27:16 -0700 (PDT) Received: from carbon-x1.. ([2a01:e0a:999:a3a0:7b64:4d1d:16d8:e38b]) by smtp.gmail.com with ESMTPSA id v10-20020a05600c470a00b00418a386c059sm2873645wmo.42.2024.04.18.07.27.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Apr 2024 07:27:15 -0700 (PDT) From: =?utf-8?b?Q2zDqW1lbnQgTMOpZ2Vy?= To: Conor Dooley , Rob Herring , Krzysztof Kozlowski , Paul Walmsley , Palmer Dabbelt , Albert Ou , Anup Patel , Atish Patra Cc: =?utf-8?b?Q2zDqW1lbnQgTMOpZ2Vy?= , linux-riscv@lists.infradead.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, kvm-riscv@lists.infradead.org, Ved Shanbhogue Subject: [RFC PATCH 6/7] riscv: kvm: add SBI FWFT support for SBI_FWFT_DOUBLE_TRAP_ENABLE Date: Thu, 18 Apr 2024 16:26:45 +0200 Message-ID: <20240418142701.1493091-7-cleger@rivosinc.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240418142701.1493091-1-cleger@rivosinc.com> References: <20240418142701.1493091-1-cleger@rivosinc.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240418_152718_108785_4570171D X-CRM114-Status: GOOD ( 15.46 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org Add support in KVM SBI FWFT extension to allow VS-mode to request double trap enabling. Double traps can then be generated by VS-mode, allowing M-mode to redirect them to S-mode. Signed-off-by: Clément Léger --- arch/riscv/include/asm/csr.h | 1 + arch/riscv/include/asm/kvm_vcpu_sbi_fwft.h | 2 +- arch/riscv/kvm/vcpu_sbi_fwft.c | 41 ++++++++++++++++++++++ 3 files changed, 43 insertions(+), 1 deletion(-) diff --git a/arch/riscv/include/asm/csr.h b/arch/riscv/include/asm/csr.h index 905cdf894a57..ee1b73655bec 100644 --- a/arch/riscv/include/asm/csr.h +++ b/arch/riscv/include/asm/csr.h @@ -196,6 +196,7 @@ /* xENVCFG flags */ #define ENVCFG_STCE (_AC(1, ULL) << 63) #define ENVCFG_PBMTE (_AC(1, ULL) << 62) +#define ENVCFG_DTE (_AC(1, ULL) << 59) #define ENVCFG_CBZE (_AC(1, UL) << 7) #define ENVCFG_CBCFE (_AC(1, UL) << 6) #define ENVCFG_CBIE_SHIFT 4 diff --git a/arch/riscv/include/asm/kvm_vcpu_sbi_fwft.h b/arch/riscv/include/asm/kvm_vcpu_sbi_fwft.h index 7dc1b80c7e6c..a9e20d655126 100644 --- a/arch/riscv/include/asm/kvm_vcpu_sbi_fwft.h +++ b/arch/riscv/include/asm/kvm_vcpu_sbi_fwft.h @@ -11,7 +11,7 @@ #include -#define KVM_SBI_FWFT_FEATURE_COUNT 1 +#define KVM_SBI_FWFT_FEATURE_COUNT 2 struct kvm_sbi_fwft_config; struct kvm_vcpu; diff --git a/arch/riscv/kvm/vcpu_sbi_fwft.c b/arch/riscv/kvm/vcpu_sbi_fwft.c index b9b7f8fa6d22..9e8e397eb02f 100644 --- a/arch/riscv/kvm/vcpu_sbi_fwft.c +++ b/arch/riscv/kvm/vcpu_sbi_fwft.c @@ -9,10 +9,19 @@ #include #include #include +#include #include #include #include +#ifdef CONFIG_32BIT +# define CSR_HENVCFG_DBLTRP CSR_HENVCFGH +# define DBLTRP_DTE (ENVCFG_DTE >> 32) +#else +# define CSR_HENVCFG_DBLTRP CSR_HENVCFG +# define DBLTRP_DTE ENVCFG_DTE +#endif + #define MIS_DELEG (1UL << EXC_LOAD_MISALIGNED | 1UL << EXC_STORE_MISALIGNED) static int kvm_sbi_fwft_set_misaligned_delegation(struct kvm_vcpu *vcpu, @@ -36,6 +45,33 @@ static int kvm_sbi_fwft_get_misaligned_delegation(struct kvm_vcpu *vcpu, return SBI_SUCCESS; } +static int kvm_sbi_fwft_set_double_trap(struct kvm_vcpu *vcpu, + struct kvm_sbi_fwft_config *conf, + unsigned long value) +{ + if (!riscv_double_trap_enabled()) + return SBI_ERR_NOT_SUPPORTED; + + if (value) + csr_set(CSR_HENVCFG_DBLTRP, DBLTRP_DTE); + else + csr_clear(CSR_HENVCFG_DBLTRP, DBLTRP_DTE); + + return SBI_SUCCESS; +} + +static int kvm_sbi_fwft_get_double_trap(struct kvm_vcpu *vcpu, + struct kvm_sbi_fwft_config *conf, + unsigned long *value) +{ + if (!riscv_double_trap_enabled()) + return SBI_ERR_NOT_SUPPORTED; + + *value = (csr_read(CSR_HENVCFG_DBLTRP) & DBLTRP_DTE) != 0; + + return SBI_SUCCESS; +} + static struct kvm_sbi_fwft_config * kvm_sbi_fwft_get_config(struct kvm_vcpu *vcpu, enum sbi_fwft_feature_t feature) { @@ -111,6 +147,11 @@ static const struct kvm_sbi_fwft_feature features[] = { .id = SBI_FWFT_MISALIGNED_DELEG, .set = kvm_sbi_fwft_set_misaligned_delegation, .get = kvm_sbi_fwft_get_misaligned_delegation, + }, + { + .id = SBI_FWFT_DOUBLE_TRAP_ENABLE, + .set = kvm_sbi_fwft_set_double_trap, + .get = kvm_sbi_fwft_get_double_trap, } };