Received: by 2002:ab2:6a05:0:b0:1f8:1780:a4ed with SMTP id w5csp2587363lqo; Tue, 14 May 2024 03:26:40 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWCV0beI4DQtssghF8Zm+Rj4Mso1691Rz3YgD18jx1jnqWcsgRa5BopJw2LoKzclQCFC/jBtFd3tkAP8n7UE0NFv8LuAPHtB0DyrHydPg== X-Google-Smtp-Source: AGHT+IHH1RnKfyzciYsisZ2yfeeesG6X8+ro/zxgdHa4FNNcLM1aepnnjUZxvX6NwM94GbjBhrDm X-Received: by 2002:a17:906:3a8d:b0:a59:ad2b:ec95 with SMTP id a640c23a62f3a-a5a2d67e2c0mr733315666b.67.1715682400424; Tue, 14 May 2024 03:26:40 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715682400; cv=pass; d=google.com; s=arc-20160816; b=kSWCvvwBb+7vpnuOMoBCA5DDLdZzEfHqyH8gmkbAhUMS8F1485scG4FpQQdik1sKjw iWj1vRMrDTP2Q9DtAcA1izchaDzoaXzVH7fYufenlenPVZefdwwFzyCQxI5HsGWj9mKG 3hDW9U8VRrOroHs5HHHzHbdcTDBygItKA2awPB8ZCn7VWmCf6lxOSEzA6T3tWRC8JwPD BVz8bZOUHBlcRPlh3XK7DnqKszs2JsmFQk3/9kflQbKHVuwk6xhxB94bqoslS0PVsOka D+Z55GAakLajzUMSmi0DbnIYCrCS443xw2mQIW6V1lanQneYw84OgCjWy+xJSgLjDXws Xcgg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id:dkim-signature; bh=HEietWmYD6kKU/pV6wujRo1uhNo/bfHaQjmoZVTM8+A=; fh=a9NmbQgfl/D7NbfmN1bCciWzHtYgnJlgXu0zIP67J0o=; b=BgALhgNEnltvkwoHacHOQNhQg0JeyFhlEz572oed4/ff7bHynfpAh348tR8uAQRr3O El7ealdd/+LFaVp2OFmNZ9RaNXP5gwlkkRoyLPax59e0ZEk4j3l4K7vuZ6ZQM2u+a5VK zawcwYHjRVuc4A/rdHRAAxyze5wyeO6H3prXFr8ciMIXe5HKq6+9CCB+aCggLadFOLC2 T2RuPtpybbfx1GBl74A4ukWXSja/Cixm0lXrenAvE16knEG3UZs+f0hVmHFZxUmV0stJ zW6hxW+JI9HFj+o+2F1lA3IEI1sHFdN6I14zCgLyZgsRHqR/iicNLc7n33ExRW+bq6y+ D+Pg==; 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=iWMQ5of0; 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-178521-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-178521-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id a640c23a62f3a-a5a17c2d129si611151266b.1037.2024.05.14.03.26.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 May 2024 03:26:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-178521-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=iWMQ5of0; 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-178521-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-178521-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 am.mirrors.kernel.org (Postfix) with ESMTPS id 2465E1F212B7 for ; Tue, 14 May 2024 10:26:39 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 083EE130E44; Tue, 14 May 2024 09:43:22 +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="iWMQ5of0" Received: from mail-wr1-f43.google.com (mail-wr1-f43.google.com [209.85.221.43]) (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 2D86284D22 for ; Tue, 14 May 2024 09:43:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.43 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715679801; cv=none; b=Pim7wiDXaCse1oR6YH4hzBATaJ+TIlUMOpJQ1PnRZVdc/VhsSX+WPA4U6i/mGZYqOj9kMlbNskiiLBc23DCQtTAV5apmWTfUwn+1Q6VNqjetRCgY80S/YSEaJg1Wn+jOCOcLrmCfmFxqgRGxpayEeEnpGiUVl9k3n5TCzRxDFBk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715679801; c=relaxed/simple; bh=GNuSE3s2r9EbP9ocQpFNdq2tZtq7uo/Tjsb9ccdwGJY=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=UXnTdxWbwcsgBHx7xArle/wQI1uXzEWK/ZTdakR797qwGxZzqMlQsPGsq1c3xOWRE5UGX6OBFOKZFAZlv/LZbIVgB3F38vbpv3N6N9zHcc1n8y05hO3pBeJoTBbRzIHIbFsUWQCkaiVQlMpKlHpbtCA+nyT+EMFMAUGcZBn6Xts= 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=iWMQ5of0; arc=none smtp.client-ip=209.85.221.43 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-wr1-f43.google.com with SMTP id ffacd0b85a97d-34cb2bf85easo446884f8f.3 for ; Tue, 14 May 2024 02:43:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1715679796; x=1716284596; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=HEietWmYD6kKU/pV6wujRo1uhNo/bfHaQjmoZVTM8+A=; b=iWMQ5of0/ggMHzemNXGUGyT0aEwb8+6FgtXh5FkV01Su/b2T8pycIpxmyLrnpo6ds8 VLiglOgv+TFRb/7+BRusIGNNEaWMXZ5ezwpknsmQ/lMuTkLdXCRiSWo60xVRKm+toslz LTKi83IDni+xqjly7SCgd9ij3Z9FJzNGw/x+ZL+st2uQYWtvfYRYB7o1eFjnQyWJNFFJ T8ZeBybw01vSgI7sDMfLF6uNcZAYnmpCAKCDwWgmNNEq4XFDLQfmsdCFLU0e4mEnuED7 YO/gYBWt0qXdOjS8eVCPDuHJYFgS936FcpCkBUAhUXm0dzJg74swQ/sl4iYEbJ4BFBVk Gsrw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715679796; x=1716284596; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=HEietWmYD6kKU/pV6wujRo1uhNo/bfHaQjmoZVTM8+A=; b=SJ+Dcw6YGeXjhv62UCwZfxXXlLeFTkGjqyLjQFndJjtEoFXndVSmWivIQNDzJhPd0f GNY1J4MXkAIhXOMdzO9xeU7Z8lOZuUVkw9Dnd8zoZ5PZQ3QvYWfX1ood4JvUm6Tcbd4M PhisK9uMGRA/KrxcC1fgv5ubpyXWDnjLs3cH3yu/nATrqjbk5gP+npKi1mSz83aERdCN piDqaaJ8SY+60TjdhNMjBArUny4zx9KKSMhJDqoJjQ2A6Rze+vZNDMP0kX3ubFYXy3bh qNFutkRQXvhqqVEaRO1H80YiafZuXfxVIcTNOdX/ePME+Zqk0z4AxOHGnlpeexs1L7EY QYdQ== X-Forwarded-Encrypted: i=1; AJvYcCWwI7Ff5B4krUZAklyi7qzJE964x/EN6rOWmIn06P0/Yr6XY1wtQAxRCl00zyUweq5oFdnEc26YIveeCstagZ76YvJMJ/pbQL9KWz9b X-Gm-Message-State: AOJu0YyZRff+13iBwXupQVf9CoyiJclOcerxGToY5J/va2z1KJ1867on 3tJJd8emIYwaNFt1PFgHNDXDwEoNPFy7qXtViDVhi+PqdX6PlAWsQqUQC0lCuaU= X-Received: by 2002:a05:600c:1c11:b0:41f:9c43:574f with SMTP id 5b1f17b1804b1-41feac59cffmr88723965e9.3.1715679796443; Tue, 14 May 2024 02:43:16 -0700 (PDT) Received: from ?IPV6:2a01:e0a:999:a3a0:1660:5f6e:2f9c:91b9? ([2a01:e0a:999:a3a0:1660:5f6e:2f9c:91b9]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-41faedf5dcesm76566455e9.0.2024.05.14.02.43.15 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 14 May 2024 02:43:15 -0700 (PDT) Message-ID: Date: Tue, 14 May 2024 11:43:15 +0200 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [RFC PATCH 6/7] riscv: kvm: add SBI FWFT support for SBI_FWFT_DOUBLE_TRAP_ENABLE To: Deepak Gupta Cc: Conor Dooley , Rob Herring , Krzysztof Kozlowski , Paul Walmsley , Palmer Dabbelt , Albert Ou , Anup Patel , Atish Patra , 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 References: <20240418142701.1493091-1-cleger@rivosinc.com> <20240418142701.1493091-7-cleger@rivosinc.com> Content-Language: en-US From: =?UTF-8?B?Q2zDqW1lbnQgTMOpZ2Vy?= In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On 27/04/2024 03:17, Deepak Gupta wrote: > On Thu, Apr 18, 2024 at 04:26:45PM +0200, Clément Léger wrote: >> 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; > > Why its required to check whether host has enabled double trap for itself ? > It's orthogonal to guest asking hypervisor to enable double trap. Hi Deepak, Indeed, as you saw, henvcfg.DTE needs menvcfg.DTE to be enabled in order to be usable. > > Probably you need a check here whether underlying FW supports handling > double > trap. > > Am I missing something here? > >> + >> +    if (value) >> +        csr_set(CSR_HENVCFG_DBLTRP, DBLTRP_DTE); >> +    else >> +        csr_clear(CSR_HENVCFG_DBLTRP, DBLTRP_DTE); > > I think vcpu->arch.cfg has `henvcfg` field. Can we reflect it there as > well so that current > `henvcfg` copy in vcpu arch specifci config is consistent? Otherwise > it'll be lost when vCPU > is scheduled out and later scheduled back in (on vcpu load) henvcfg is restored when loading the vpcu (kvm_arch_vcpu_load()) and saved when the CPU is put (kvm_arch_vcpu_put()). But I just saw that this change is included in the next patch. Should have been this one , I'll fix that. > > Furthermore, lets not do feature specific alias names for CSR. > > Instead let's keep consistent 64bit image of henvcfg in vcpu->arch.cfg. > > And whenever it's time to pick up the setting, pick up logic either > perform the writes in > henvcfg. And if required it'll perform henvcfgh too (as > `kvm_arch_vcpu_load` already does) I don't have a strong opinion on that point so if you think it really is better, I'll switch to that. Thanks, Clément > >> + >> +    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, >>     } >> }; >> >> --  >> 2.43.0 >> >>