Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp81752rdg; Wed, 11 Oct 2023 22:16:37 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEq8vI1DDwpIXWFyUMNYJ5YwwBjjgM6DrVm6Z8t1SZfnY6ibZgoaAWxjHVFxmGBM98215X4 X-Received: by 2002:a05:6e02:3201:b0:34f:ef94:c803 with SMTP id cd1-20020a056e02320100b0034fef94c803mr22886733ilb.25.1697087796791; Wed, 11 Oct 2023 22:16:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697087796; cv=none; d=google.com; s=arc-20160816; b=vX7EwzyC1UDxewnzgMxy1xsDUy/x1wuMk0fzI0BZT7lrA9OTUFWRNu13TpLDd1tdqZ 3hm8MKujhHtgo96LB07t9zkLznQL/GNVPTl/zBfEQrh/k0j41792E5wudCwcnKIc9dC4 NOSs2V2VDIVDDprxrixSPgrkTIbz+aJAGCvBfejVtMD5z+/vzJqj6nJlFm6Vu/iipXH6 0WTEuYMEN7ZtEoGhRM13KxEdAiVURGHb01Fj2BV800e6dCIwOIBGjIXA6RopZKRBTF4u ZWRb8c/lJMq0b39ujCIIEMgH6AubqtcW0DZRMRdGuMb+mb+jUn53Tu5XQ8QDC06dnJ7U L2Dg== 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 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 l187-20020a633ec4000000b0057c29fec784si1440584pga.110.2023.10.11.22.16.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Oct 2023 22:16:36 -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=dqE0nNGa; 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 2C6E28083AE5; Wed, 11 Oct 2023 22:16:33 -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 S235373AbjJLFPz (ORCPT + 99 others); Thu, 12 Oct 2023 01:15:55 -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 Content-Transfer-Encoding: 8bit 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:33 -0700 (PDT) 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; + } +} -- 2.34.1