Received: by 2002:a05:7412:f690:b0:e2:908c:2ebd with SMTP id ej16csp186362rdb; Thu, 19 Oct 2023 00:58:22 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHsy7Sac2Eb6/SfVO0tGTCT3MwmIsR9JTxQfUgQ9pIoEwdq98dPYpptzn4Stb83lNYcweKZ X-Received: by 2002:a17:902:ea8c:b0:1ca:8e79:53c1 with SMTP id x12-20020a170902ea8c00b001ca8e7953c1mr1366108plb.13.1697702302302; Thu, 19 Oct 2023 00:58:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697702302; cv=none; d=google.com; s=arc-20160816; b=p9npejsxd+qZ4+pKmTT8/2uNAAEMDuNbAAS5TENZr7kZJPDxPcQZCF+na6sjs4Xi6W nWn9H7vn7h9jF+tVSWi1SCgAVcdiQV/uzq9ZQz32SAH+KqF0cmjzw1yv47xGr1ocyqMn g5LyFo+eVvKSPKzQp8YbNAAV1wN14shjvhZkPxfg/HKGqnznsiq9DaMmbU8A8/YDr55R a1RUM4N8LsP7BSuYDqrQ1JoTQLrU6Bp+OXdV+YUGtUi4YWG1LtNd9n9vFdvuV0YScMgP P0Pe/0aEX88o/f+BM75KKuIUsBngQ15Qb+q82ZPfRPKT6IcpkCCCuQPp095OhLTMNyZo G9+A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=BaT0UAyyKtssFxQND155cWxNkiluUWACURFJFcXVWDk=; fh=HphsaL+YRSr8xSEjXKGEGNHhmBU1p3niIw2svRX7Lek=; b=JCI+uRBsuocvlq7Twupw3WO/QKD/NDUub5s1WbGEjbYD8IjM5WbngofNzAepGAnrtJ neZHwhYtVvqJomu9FAqBRrgFDS7pH8HmtvjHA4rSuaZHWz/NC5xQW5ErQMlbbDMHk8zk 71CWYc0Xn0so0bMnQEhCl5emtgdOswBkvL5z7u2QUcn5I87e46+EcvAfphylrIDLDNNs teQFCya8rYUffLkqMnALMJ9XMOMFuYoVVY8cd5g6bnXx4/fYakO6ehDaXnMlMibCDPg3 Bx9GkVqI7ormPyQfY6oeHowycy4jnlzedepuZlZLB48dOLoZZQwsKX+01u9lpXe7dMi6 VTwA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ventanamicro.com header.s=google header.b=OTQwklIt; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from pete.vger.email (pete.vger.email. [23.128.96.36]) by mx.google.com with ESMTPS id z7-20020a1709028f8700b001bbcddd6e82si1613544plo.91.2023.10.19.00.58.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Oct 2023 00:58:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) client-ip=23.128.96.36; Authentication-Results: mx.google.com; dkim=pass header.i=@ventanamicro.com header.s=google header.b=OTQwklIt; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 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 pete.vger.email (Postfix) with ESMTP id 81DA88186532; Thu, 19 Oct 2023 00:58:18 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232791AbjJSH6C (ORCPT + 99 others); Thu, 19 Oct 2023 03:58:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58612 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231948AbjJSH6B (ORCPT ); Thu, 19 Oct 2023 03:58:01 -0400 Received: from mail-wr1-x431.google.com (mail-wr1-x431.google.com [IPv6:2a00:1450:4864:20::431]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B497512E for ; Thu, 19 Oct 2023 00:57:58 -0700 (PDT) Received: by mail-wr1-x431.google.com with SMTP id ffacd0b85a97d-31fa15f4cc6so6529684f8f.2 for ; Thu, 19 Oct 2023 00:57:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1697702277; x=1698307077; 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=BaT0UAyyKtssFxQND155cWxNkiluUWACURFJFcXVWDk=; b=OTQwklItlLRD3WcaPTmvA6bmBJJWVn+ObaccYbMF7ORoUMkWYRsnIWQvtTij5QRjtO l6Op/ZOlu+qTMpm+oxpcw3DO7xabclvPURK+gHyUFd050a1mwc2C5aQ+2mEuBtYoV+tW FoSeaRxJ/SDK8byHs5BC5vH44wCeQQrSQ+qEv/I1z3nt8/qPru7FRFe8FDHVuINUjAQE R1EGRUl8aw3Eiy7bPQKNc0l1nC1SIffvRoZKp2wj8TmOrOYz5cXT311q4xCki1Pecp70 qx6g2aHoTX+YFH5m44wMQTSLDyOvCVJTFxcM/n9A5IaWvZERG8WtoI9ZidhLlw1Qfobo gnOg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697702277; x=1698307077; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=BaT0UAyyKtssFxQND155cWxNkiluUWACURFJFcXVWDk=; b=ce9wQNlSAXe9BAItk3Igto3Z6071N7So5r2Tz8X2rvoMYI3CF+lHwqM2HG72HPXZpQ dfuQL4ZsutWzNI7b12gpiwtU2YvZg8m+C1qVXXuDjRknURZGWEBJUapoUTwXom/m9jTf OLurmHOWbQLnfJrwKfv1Jlf21QJF83QiEcAcR6aGGJtm2NxhRe8dyBsHQpm5GXGhMr6X KDMeFUNUHV2nVjEKQ/yzqJGJgAYcqk14K7ZtaoMzViKxBQk6SzMfr0ILs4OPcuitBA5Z 8yUiIppmm3ZTVBCaFqSraBozlGZRiynl/H6QS7WylFOrIbZxQPhDTl0dm8MJ9zpmNIsU HSlg== X-Gm-Message-State: AOJu0YyLaiKC3r9vHBciXA+jpR6F37XO9l2IFKv20I3PY0Kmuq8Jtsp7 gkr/K36eQAuPI2/XVLA2NHH6cg== X-Received: by 2002:adf:f9cd:0:b0:32d:a335:e33d with SMTP id w13-20020adff9cd000000b0032da335e33dmr887824wrr.58.1697702277126; Thu, 19 Oct 2023 00:57:57 -0700 (PDT) Received: from localhost (cst2-173-16.cust.vodafone.cz. [31.30.173.16]) by smtp.gmail.com with ESMTPSA id i3-20020a5d6303000000b0032db4e660d9sm3831000wru.56.2023.10.19.00.57.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Oct 2023 00:57:56 -0700 (PDT) Date: Thu, 19 Oct 2023 09:57:55 +0200 From: Andrew Jones To: Anup Patel 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 Subject: Re: [PATCH v2 3/8] RISC-V: KVM: Allow some SBI extensions to be disabled by default Message-ID: <20231019-1e6f411e1cbc4a3b0fbff3f5@orel> References: <20231012051509.738750-1-apatel@ventanamicro.com> <20231012051509.738750-4-apatel@ventanamicro.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20231012051509.738750-4-apatel@ventanamicro.com> 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 pete.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 (pete.vger.email [0.0.0.0]); Thu, 19 Oct 2023 00:58:18 -0700 (PDT) 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 rather than SBI > @@ -59,6 +62,7 @@ int kvm_riscv_vcpu_get_reg_sbi_ext(struct kvm_vcpu *vcpu, > const struct kvm_vcpu_sbi_extension *kvm_vcpu_sbi_find_ext( > struct kvm_vcpu *vcpu, unsigned long extid); > int kvm_riscv_vcpu_sbi_ecall(struct kvm_vcpu *vcpu, struct kvm_run *run); > +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. > + > /* 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 kvm_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 first, > - * but it may be too early to call that here. We can set the status to > - * unavailable, though. > - */ > - if (!reg_val) > - scontext->ext_status[sext->ext_idx] = > + scontext->ext_status[sext->ext_idx] = (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 = scontext->ext_status[sext->ext_idx] != - KVM_RISCV_SBI_EXT_UNAVAILABLE; + *reg_val = scontext->ext_status[sext->ext_idx] == + KVM_RISCV_SBI_EXT_AVAILABLE; return 0; } > > return 0; > @@ -337,18 +331,8 @@ const struct kvm_vcpu_sbi_extension *kvm_vcpu_sbi_find_ext( > scontext->ext_status[entry->ext_idx] == > KVM_RISCV_SBI_EXT_AVAILABLE) > return ext; > - if (scontext->ext_status[entry->ext_idx] == > - KVM_RISCV_SBI_EXT_UNAVAILABLE) > - return NULL; > - if (ext->probe && !ext->probe(vcpu)) { > - scontext->ext_status[entry->ext_idx] = > - KVM_RISCV_SBI_EXT_UNAVAILABLE; > - return NULL; > - } > > - scontext->ext_status[entry->ext_idx] = > - 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 = &vcpu->arch.sbi_context; > + const struct kvm_riscv_sbi_extension_entry *entry; > + const struct kvm_vcpu_sbi_extension *ext; > + int i; > + > + for (i = 0; i < ARRAY_SIZE(sbi_ext); i++) { > + entry = &sbi_ext[i]; > + ext = entry->ext_ptr; > + > + if (ext->probe && !ext->probe(vcpu)) { > + scontext->ext_status[entry->ext_idx] = > + KVM_RISCV_SBI_EXT_UNAVAILABLE; > + continue; > + } > + > + scontext->ext_status[entry->ext_idx] = ext->default_unavail ? > + KVM_RISCV_SBI_EXT_UNAVAILABLE : > + KVM_RISCV_SBI_EXT_AVAILABLE; > + } > +} > -- > 2.34.1 > Thanks, drew