Received: by 2002:a05:7412:f690:b0:e2:908c:2ebd with SMTP id ej16csp800486rdb; Thu, 19 Oct 2023 22:26:53 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEjOpNNqMJSOts5Tz5o0DjumaBFyT3uHJuGlQuwlzEUVte4+0IWm8JlYHZ74serSeq3FWbK X-Received: by 2002:a67:ca01:0:b0:457:c46b:8fba with SMTP id z1-20020a67ca01000000b00457c46b8fbamr1096070vsk.5.1697779613382; Thu, 19 Oct 2023 22:26:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697779613; cv=none; d=google.com; s=arc-20160816; b=0U49Dr3ACjA5Oo84tUJlt1vIIXSpGXmF2XhBwRu6MHSvHQM6PyPC3vlrK5yw4GoPT7 jHV9FKZdNb4enCKH3FJgxAwby5quhup31pX1nkikGr8YzGpvr8bYwqXqVKC8Fo7ZGgq/ 8srOem0XVXiLxKMgvzt+d2TPwHVEqs2wqjolXPfuc2OYitD3g0q+gxBOjoM9x9IJkRx9 tk47tLL57Waxe+vOc9obf5gXTrcaSqPjlr+RIH/J2rveqlSaX+JiafmZiDWR1lM/u6JZ qyJ+8oNqOc8+fNIaU6Ly/eFivol71AsJMgBTXK/fymu2mEYuJ1uXBf3+TGyZfrKlleqB OMAA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=IVgRisShFqd7EiamTTw+bWWTirWYsFZ+qCSq/HGAIy0=; fh=rEcG3aLZazhGsCP9wQzjqjyKieVQcGVBRmyXWBeefaM=; b=iNufz6eMc6frCHYwZctriGU2jxjJ45MMJ8dTd2STSEzQ2vW8nRjM6VfW5LRxyv/TlI HBD2zCHLEeLuBbCpIyRa/UY66M7drJjnCWa0Ssf18KQOm/13etW53F/qQSNT+f6s3paP WC2CRE0ITno588rEtQMxVmt+tVZx/iYlEt0uu6+brrrNGYZofM9XCvgySTTH0jdOYLs8 1WFdyyG+/Khx0/sSwF39krVeeE/X9IqBHQMWcVzeymhjwGk22H4QFEtF7BA06i4RzxAu S6N09me6llPM7uv7SJ+rfR+uwRlbj3Yegpi5w+1bvCu9DjUyPoiktUo3+cp8zDjxeHIn /Jnw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ventanamicro.com header.s=google header.b=SZN0+PVo; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id f22-20020a633816000000b005b7dd1d190esi1176842pga.259.2023.10.19.22.26.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Oct 2023 22:26:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; dkim=pass header.i=@ventanamicro.com header.s=google header.b=SZN0+PVo; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id 018E982DC61D; Thu, 19 Oct 2023 22:26:49 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232838AbjJTF01 (ORCPT + 99 others); Fri, 20 Oct 2023 01:26:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43292 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233471AbjJTF0Z (ORCPT ); Fri, 20 Oct 2023 01:26:25 -0400 Received: from mail-ua1-x92f.google.com (mail-ua1-x92f.google.com [IPv6:2607:f8b0:4864:20::92f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9CA57D51 for ; Thu, 19 Oct 2023 22:26:22 -0700 (PDT) Received: by mail-ua1-x92f.google.com with SMTP id a1e0cc1a2514c-7aae07e7ba4so157969241.1 for ; Thu, 19 Oct 2023 22:26:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1697779581; x=1698384381; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=IVgRisShFqd7EiamTTw+bWWTirWYsFZ+qCSq/HGAIy0=; b=SZN0+PVof30n4KVsW5UjKM07VgQ5XRWG8+QdcZJ5WtL3H3NMLqBtHyg705dIKAjnNr w4HclU8zb25S/xDEy+d6UfEyte1vetCzjo+8I8RBkWozQra9JNKqfLqR4dW8MyPEueHw 6JyhxGcG3LJyEsfdKwSc9k97nmKatRM5eGcxLN/qVPm2Oo2cpUGfjtnkXl5aTx84bhWA WTy4mVD64lHjPad9gHlHxTiXJGk6dHagEyVbSsCmRJQuj9yXYuF6s0iSwrBxdv2rgtnH Z+6HqKWrNJPEZUWKLQdrnGa/ksn4eEQH6If+9/RcaoH1HglMW6/oX7FSITfqD1XMeSlb ximw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697779581; x=1698384381; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=IVgRisShFqd7EiamTTw+bWWTirWYsFZ+qCSq/HGAIy0=; b=kcHkwHlz5vMJHfF+Ul9csyqcDPplJxpdiXI/jATZCogtEMlLdBo3YCNOdc4AYieg3i qy2yFnQJPo5K/SU/kNQdFAnAiMxeq0rv8a3zgnI7A0SBaU5wnTHYDrTPh6V1aH30QjJc cgNEvGm8ZzrvoOBYkdQV7C2yVgmLsbrjaW4QNPX3LqciFpSqJ3hST55rrZBtDex0q1QH hv4ophbUPwylXpYa4YHSASuusX8BwG5FigmzZI0VQOu44IpROpkOs+qMf8EICOASjrE5 GpzyJTzA+OeT1/1PVXI+BWOA/4uRDZ4AQRbtgEGe6m7mKg3GdyMU7lNM3bgS15CnynPC EoBg== X-Gm-Message-State: AOJu0YxwrIeYQ0v2eOwzal+LIwdDOmOuM1wrky/Pp8k1RsS3ZPdsJbrd BFfzTg5+htunvZM4gn0An80H7UFryzmLVnXvVdS/xQ== X-Received: by 2002:a67:ef51:0:b0:457:dbe3:ef45 with SMTP id k17-20020a67ef51000000b00457dbe3ef45mr1085001vsr.19.1697779581093; Thu, 19 Oct 2023 22:26:21 -0700 (PDT) MIME-Version: 1.0 References: <20231012051509.738750-1-apatel@ventanamicro.com> <20231012051509.738750-4-apatel@ventanamicro.com> <20231019-1e6f411e1cbc4a3b0fbff3f5@orel> In-Reply-To: <20231019-1e6f411e1cbc4a3b0fbff3f5@orel> From: Anup Patel Date: Fri, 20 Oct 2023 10:56:09 +0530 Message-ID: Subject: Re: [PATCH v2 3/8] RISC-V: KVM: Allow some SBI extensions to be disabled by default To: Andrew Jones Cc: Paolo Bonzini , Atish Patra , Palmer Dabbelt , Paul Walmsley , Greg Kroah-Hartman , Jiri Slaby , Conor Dooley , kvm@vger.kernel.org, kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org, linux-serial@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on howler.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Thu, 19 Oct 2023 22:26:50 -0700 (PDT) On Thu, Oct 19, 2023 at 1:27=E2=80=AFPM Andrew Jones wrote: > > On Thu, Oct 12, 2023 at 10:45:04AM +0530, Anup Patel wrote: > > Currently, all SBI extensions are enabled by default which is > > problematic for SBI extensions (such as DBCN) which are forwarded > > to the KVM user-space because we might have an older KVM user-space > > which is not aware/ready to handle newer SBI extensions. Ideally, > > the SBI extensions forwarded to the KVM user-space must be > > disabled by default. > > > > To address above, we allow certain SBI extensions to be disabled > > by default so that KVM user-space must explicitly enable such > > SBI extensions to receive forwarded calls from Guest VCPU. > > > > Signed-off-by: Anup Patel > > --- > > arch/riscv/include/asm/kvm_vcpu_sbi.h | 4 +++ > > arch/riscv/kvm/vcpu.c | 6 ++++ > > arch/riscv/kvm/vcpu_sbi.c | 45 ++++++++++++++++----------- > > 3 files changed, 36 insertions(+), 19 deletions(-) > > > > diff --git a/arch/riscv/include/asm/kvm_vcpu_sbi.h b/arch/riscv/include= /asm/kvm_vcpu_sbi.h > > index 8d6d4dce8a5e..c02bda5559d7 100644 > > --- a/arch/riscv/include/asm/kvm_vcpu_sbi.h > > +++ b/arch/riscv/include/asm/kvm_vcpu_sbi.h > > @@ -35,6 +35,9 @@ struct kvm_vcpu_sbi_return { > > struct kvm_vcpu_sbi_extension { > > unsigned long extid_start; > > unsigned long extid_end; > > + > > + bool default_unavail; > > + > > /** > > * SBI extension handler. It can be defined for a given extension= or group of > > * extension. But it should always return linux error codes rathe= r than SBI > > @@ -59,6 +62,7 @@ int kvm_riscv_vcpu_get_reg_sbi_ext(struct kvm_vcpu *v= cpu, > > const struct kvm_vcpu_sbi_extension *kvm_vcpu_sbi_find_ext( > > struct kvm_vcpu *vcpu, unsigned long exti= d); > > int kvm_riscv_vcpu_sbi_ecall(struct kvm_vcpu *vcpu, struct kvm_run *ru= n); > > +void kvm_riscv_vcpu_sbi_init(struct kvm_vcpu *vcpu); > > > > #ifdef CONFIG_RISCV_SBI_V01 > > extern const struct kvm_vcpu_sbi_extension vcpu_sbi_ext_v01; > > diff --git a/arch/riscv/kvm/vcpu.c b/arch/riscv/kvm/vcpu.c > > index c061a1c5fe98..e087c809073c 100644 > > --- a/arch/riscv/kvm/vcpu.c > > +++ b/arch/riscv/kvm/vcpu.c > > @@ -141,6 +141,12 @@ int kvm_arch_vcpu_create(struct kvm_vcpu *vcpu) > > if (rc) > > return rc; > > > > + /* > > + * Setup SBI extensions > > + * NOTE: This must be the last thing to be initialized. > > + */ > > + kvm_riscv_vcpu_sbi_init(vcpu); > > With this, we no longer defer probing to the first access (whether that's > by the guest or KVM userspace). With our current small set of SBI > extensions where only a single one has a probe function, then this > simpler approach is good enough. We can always go back to the lazy > approach later if needed. I agree. We can fallback to lazy probing in the future if required. > > > + > > /* Reset VCPU */ > > kvm_riscv_reset_vcpu(vcpu); > > > > diff --git a/arch/riscv/kvm/vcpu_sbi.c b/arch/riscv/kvm/vcpu_sbi.c > > index 9cd97091c723..1b1cee86efda 100644 > > --- a/arch/riscv/kvm/vcpu_sbi.c > > +++ b/arch/riscv/kvm/vcpu_sbi.c > > @@ -155,14 +155,8 @@ static int riscv_vcpu_set_sbi_ext_single(struct kv= m_vcpu *vcpu, > > if (!sext) > > return -ENOENT; > > > > - /* > > - * We can't set the extension status to available here, since it = may > > - * have a probe() function which needs to confirm availability fi= rst, > > - * but it may be too early to call that here. We can set the stat= us to > > - * unavailable, though. > > - */ > > - if (!reg_val) > > - scontext->ext_status[sext->ext_idx] =3D > > + scontext->ext_status[sext->ext_idx] =3D (reg_val) ? > > + KVM_RISCV_SBI_EXT_AVAILABLE : > > KVM_RISCV_SBI_EXT_UNAVAILABLE; > > We're missing the change to riscv_vcpu_get_sbi_ext_single() which should > also drop the comment block explaining the limits to status knowledge > without initial probing (which we now do) and then just check for > available, i.e. > > diff --git a/arch/riscv/kvm/vcpu_sbi.c b/arch/riscv/kvm/vcpu_sbi.c > index bb76c3cf633f..92c42d9aba1c 100644 > --- a/arch/riscv/kvm/vcpu_sbi.c > +++ b/arch/riscv/kvm/vcpu_sbi.c > @@ -186,15 +186,8 @@ static int riscv_vcpu_get_sbi_ext_single(struct kvm_= vcpu *vcpu, > if (!sext) > return -ENOENT; > > - /* > - * If the extension status is still uninitialized, then we should= probe > - * to determine if it's available, but it may be too early to do = that > - * here. The best we can do is report that the extension has not = been > - * disabled, i.e. we return 1 when the extension is available and= also > - * when it only may be available. > - */ > - *reg_val =3D scontext->ext_status[sext->ext_idx] !=3D > - KVM_RISCV_SBI_EXT_UNAVAILABLE; > + *reg_val =3D scontext->ext_status[sext->ext_idx] =3D=3D > + KVM_RISCV_SBI_EXT_AVAILABLE; > > return 0; > } Thanks, I will include this change in the next revision. > > > > > return 0; > > @@ -337,18 +331,8 @@ const struct kvm_vcpu_sbi_extension *kvm_vcpu_sbi_= find_ext( > > scontext->ext_status[entry->ext_idx] =3D=3D > > KVM_RISCV_SBI_EXT_AVAILAB= LE) > > return ext; > > - if (scontext->ext_status[entry->ext_idx] =3D=3D > > - KVM_RISCV_SBI_EXT_UNAVAIL= ABLE) > > - return NULL; > > - if (ext->probe && !ext->probe(vcpu)) { > > - scontext->ext_status[entry->ext_idx] =3D > > - KVM_RISCV_SBI_EXT_UNAVAILABLE; > > - return NULL; > > - } > > > > - scontext->ext_status[entry->ext_idx] =3D > > - KVM_RISCV_SBI_EXT_AVAILABLE; > > - return ext; > > + return NULL; > > } > > } > > > > @@ -419,3 +403,26 @@ int kvm_riscv_vcpu_sbi_ecall(struct kvm_vcpu *vcpu= , struct kvm_run *run) > > > > return ret; > > } > > + > > +void kvm_riscv_vcpu_sbi_init(struct kvm_vcpu *vcpu) > > +{ > > + struct kvm_vcpu_sbi_context *scontext =3D &vcpu->arch.sbi_context= ; > > + const struct kvm_riscv_sbi_extension_entry *entry; > > + const struct kvm_vcpu_sbi_extension *ext; > > + int i; > > + > > + for (i =3D 0; i < ARRAY_SIZE(sbi_ext); i++) { > > + entry =3D &sbi_ext[i]; > > + ext =3D entry->ext_ptr; > > + > > + if (ext->probe && !ext->probe(vcpu)) { > > + scontext->ext_status[entry->ext_idx] =3D > > + KVM_RISCV_SBI_EXT_UNAVAILABLE; > > + continue; > > + } > > + > > + scontext->ext_status[entry->ext_idx] =3D ext->default_una= vail ? > > + KVM_RISCV_SBI_EXT_UNAVAILABLE : > > + KVM_RISCV_SBI_EXT_AVAILABLE; > > + } > > +} > > -- > > 2.34.1 > > > > Thanks, > drew Regards, Anup