From patchwork Thu Oct 12 05:15:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 151741 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp994482vqb; Wed, 11 Oct 2023 22:16:28 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFjiGrxU1s5R20B3Dg1BTnK6YyZWLh0dPQ/5s2xlhxSBBu1pwhfhLriTY5hTVxyB+QrvYWt X-Received: by 2002:a05:6808:1a27:b0:3a9:e40c:683c with SMTP id bk39-20020a0568081a2700b003a9e40c683cmr28360315oib.1.1697087787985; Wed, 11 Oct 2023 22:16:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697087787; cv=none; d=google.com; s=arc-20160816; b=I38BOCRROmL12udKLuj5puVPnM753M0+bhpejNUZVl+2kyaicMvYtgqlpJntv+PrDr ISugr3/EFWsiMxCLgkWtj63EhPBnB65jEStijxBn+spz8PmQU11AlxSd44L77MQGyaub Laf3hcQid8nEonNZZYuMOz5HCdJKTGPZRWxabNDUHy2vdtTsP/vhi6iGCXvsvJMY0qD1 8qzDwYHZ+woBw1D1azL33R9xk9nF415X+XtqTCwaRpNVuaJiAtDz7fXJXBFkTa70fwvs fSMrtw616IWNcJq2nFI28H6K4wM2CHjYOQrNlMvLtUD2bRbmoR8vpMDUntMT4xrFQ7gO bsuA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=UnnUYFylMM7osLHu6Gv9hbGwiUDTuyMbxo3uWzdsMQU=; fh=7GYORjoWw1oF4BCDuq40hd+MOEKRwzNqXwnZ/K2vS9Q=; b=dxsjWqtMrAa7IA8L/zVj/bAeWaEUPBx76yPj7f8xEF0kk1pf+ZLcZa+B33TFV3u/5e 27ItArcqdkeOUXTF/n2RscJev/Bkz9btqr125s1ks+V6EEAe00yF03YZFyifArIBSs5E rC8yu/KjkNGN2txcOVKIOqiz2hhq6neqksjY+rcOKRSZghTf2vMt4dwnSGUMGJM8nfym qS2LLH//YyBFx4sQwpdqW9NhQxDeTkNaeBUH6fYa0hD1A25+HF99zgqbtnuZXLts+KKl yjuXFrsK9NkBsLlDW3UxezLoy/rJqx9I7boIxuSB4XMy3o+7YKKffiLRyK5HyIjQjxCK lkWw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ventanamicro.com header.s=google header.b=dqE0nNGa; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id r20-20020a6560d4000000b0055391572218si1314746pgv.26.2023.10.11.22.16.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Oct 2023 22:16:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; dkim=pass header.i=@ventanamicro.com header.s=google header.b=dqE0nNGa; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 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 3D74C806FB78; Wed, 11 Oct 2023 22:16:21 -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 S235384AbjJLFP4 (ORCPT + 18 others); Thu, 12 Oct 2023 01:15:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44194 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235304AbjJLFPu (ORCPT ); Thu, 12 Oct 2023 01:15:50 -0400 Received: from mail-pj1-x1035.google.com (mail-pj1-x1035.google.com [IPv6:2607:f8b0:4864:20::1035]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5BD0FE4 for ; Wed, 11 Oct 2023 22:15:33 -0700 (PDT) Received: by mail-pj1-x1035.google.com with SMTP id 98e67ed59e1d1-27d1f57bda7so325221a91.0 for ; Wed, 11 Oct 2023 22:15:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1697087732; x=1697692532; darn=vger.kernel.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=UnnUYFylMM7osLHu6Gv9hbGwiUDTuyMbxo3uWzdsMQU=; b=dqE0nNGaOHUpekPXSfgZl7ELDKFozCRnkUzlU0U79v0qa1HjKV6VKTn94IdJwbs7Dx WBV/TEw69VackiL3io9W+O9SJwsvcYvVtefCIgaZoqRtZnERLNvu65TF/AgODJigZ47c 280MMqvMu3EwXueYABWHYwTTE0vrpmw64V4PpYZ1mNhJCDxHoF9732oki6ogsw79wnMI cKAWequtAgEVA1UaAM8ryMEpuhk5DmWBr0U2XsK9sObQRyqiLxJuS72bVkcVKKe2bbsK V5Tn47JSKahVP3WomCV1qh0HsGySjZ9K9NFL40HoxkmMuhTLhikGx3gjT/2t9ahU4scX jQJg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697087732; x=1697692532; 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=UnnUYFylMM7osLHu6Gv9hbGwiUDTuyMbxo3uWzdsMQU=; b=ftnDzXBf+dJob9T8iwHu/gqxh3GNPV81LOQ6JWWKSuaFQT+xMicdGvD/NhUgaFUnkc RBkwM1PdwJI5RcSCFBOypbXkUYHSTAb1rLfaYtv0kQSS63PztQeDg74rMXPBm4hExRRm ohzb+4D61Ons9RHELbeaqeenWKb/gAuDLzinCir0cp8ttXhAfNbjfnF+UWQ6SDs3HlOg IJzHWh4gh3NgT0zj1R0OCt7n4ejEZXClXCLkZ6c8hUH6OmVTaeEr3PzR/HeruwxmK4hs XoaJlMpEbjSYVGxu2RsDnOpLddC9BDLeyqW3EM71Y8pG7axR3wjgZHYTdIAb9DmIby9c 5New== X-Gm-Message-State: AOJu0Yx3LwmDbbZkmGWwI0N0U3lYWvQtxxoqFcE+3QpGy5JBOgs/4K8v wYz4BnrJz9owepwXqdBThOCVG9u853QM9P4gSSo= X-Received: by 2002:a17:90a:c254:b0:27d:1f9f:a57f with SMTP id d20-20020a17090ac25400b0027d1f9fa57fmr918230pjx.32.1697087732343; Wed, 11 Oct 2023 22:15:32 -0700 (PDT) Received: from anup-ubuntu-vm.localdomain ([106.51.83.242]) by smtp.gmail.com with ESMTPSA id s18-20020a17090330d200b001b9d95945afsm851309plc.155.2023.10.11.22.15.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Oct 2023 22:15:31 -0700 (PDT) From: Anup Patel To: Paolo Bonzini , Atish Patra , Palmer Dabbelt , Paul Walmsley , Greg Kroah-Hartman , Jiri Slaby Cc: Conor Dooley , Andrew Jones , 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, Anup Patel Subject: [PATCH v2 3/8] RISC-V: KVM: Allow some SBI extensions to be disabled by default Date: Thu, 12 Oct 2023 10:45:04 +0530 Message-Id: <20231012051509.738750-4-apatel@ventanamicro.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231012051509.738750-1-apatel@ventanamicro.com> References: <20231012051509.738750-1-apatel@ventanamicro.com> MIME-Version: 1.0 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]); Wed, 11 Oct 2023 22:16:21 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1779525524015138543 X-GMAIL-MSGID: 1779525524015138543 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); + /* 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; 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; + } +}