Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp3559657imw; Mon, 18 Jul 2022 10:12:37 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uPfpbgWe2g1dHki679/+J4yZrH/FtCr+xBtmuTzBkxB2lsXwfczawt/ym7Uk7VbO1j28RR X-Received: by 2002:a17:907:2c44:b0:72b:6160:c64c with SMTP id hf4-20020a1709072c4400b0072b6160c64cmr26820132ejc.55.1658164357172; Mon, 18 Jul 2022 10:12:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658164357; cv=none; d=google.com; s=arc-20160816; b=I9tQs6xwvL6XBBmeYhDGjGHowD+Iwzi9a8sxopYvs9DCRM3mFW8gnSl2U9mLR3++CO PDkz8z0s/MgoUDU7JlLkLO3Kg3HBKOrK9Fh3tc7HISq5s32Qpu9GVHL2U2qIgKPM9drf wWvuzD+RmafRdtvPv03MRE+jOKIwW/KKkGpps3CzVBmabGL3D5sR0GBXIvhEBuAZwBFa v0P4EYquuqJ8pSj8fkFGm0vVwsVmrCbKgZg27ZHsqxB0EFoEcK4KTo2ZhmKBKgDprwz5 tsYrbiatplIRYRsWbvT4E0Y0+rSz40dRrq/rfdHPw48qkEQTdWdJfTcJrsi2Uf7Ir8Kl KkMw== 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=yTc6DPtRL3G/t0xkTGIGozwG47F+csFvT/B18Fnd6bA=; b=eOZP70lXGQ0G1ccJNsEItH3qAbu40belIkIad72vTYvnfgPqooZT58YDjxm1gtlrxt GyoYPKkZYZBxtcxGyWAj4p4PyeykespvZkjvwRJlew++mDNk08j5aU/rFPYyYOxp2PsE aIAoF2jiDnE5rEQJq8X3/LDLIFCgGSqi9sKaPhyqvWmIGW5UTt9O55tD19I+TkbL3Su3 55ItAjIdqh738aDaw9QdW8lbDfPRnFDTX1XlgSs1IG367L4x23e0uFLW7DspeZtOM7c4 uUMG8v80IrboJvYjjvxCtUDw4dk5KBK0R0lp9wlXjHSLEf4u8Hpv3AjUh43MalOhZZI+ WGNw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rivosinc-com.20210112.gappssmtp.com header.s=20210112 header.b=FzhoHCa1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k20-20020a05640212d400b0043aa8412569si14829440edx.315.2022.07.18.10.12.12; Mon, 18 Jul 2022 10:12:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@rivosinc-com.20210112.gappssmtp.com header.s=20210112 header.b=FzhoHCa1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235414AbiGRRF6 (ORCPT + 99 others); Mon, 18 Jul 2022 13:05:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57368 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235719AbiGRRFt (ORCPT ); Mon, 18 Jul 2022 13:05:49 -0400 Received: from mail-pj1-x102e.google.com (mail-pj1-x102e.google.com [IPv6:2607:f8b0:4864:20::102e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D41652BB07 for ; Mon, 18 Jul 2022 10:05:47 -0700 (PDT) Received: by mail-pj1-x102e.google.com with SMTP id u7-20020a17090a3fc700b001f1efc76be2so67818pjm.1 for ; Mon, 18 Jul 2022 10:05:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=yTc6DPtRL3G/t0xkTGIGozwG47F+csFvT/B18Fnd6bA=; b=FzhoHCa1YsaXYQ8x7nWgTmqf0KgVR4ynTwb6sSm5eIdHHC8iMhZW6RP3czhrR5n8g/ X2JKnvYBb1H58qTMZKXWi9CM1ZQO1mXLe07lVJd/+LwRh8tfBcmzbSFcotIZJhPLOUWu aehAPylHZQU7yz4IYfdL02Wz2JwbZBANg72NQqo5gHm2pA6TKHd81Ze1FoShkQs4WMAt J+F55ANKBQ+2NGW0+hnosnafLochQp/Rt3MrI+yMQtV7Uur5M1fuFzysZl9w/7EcuczN G2ZkIM824pXrYATCqnGXtVd4QVts+VWdN9ZLCDXaCjhqlcydUTORkG9xZukPNK7yHSzu CVBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=yTc6DPtRL3G/t0xkTGIGozwG47F+csFvT/B18Fnd6bA=; b=cKqHIoADxIZad6lJQL/b8zRHgNMKo+q+1b9WTYf/fnguRFk9JJ4XRRiBut622xAjQ3 a7hZ06ZKHlF4YBZK2+K9YFMp/BK79p9RxuZbEYGw25KljklYNjP5AxLH9pn8prxkpGya 0N5PUyv3n2aFia0YcFXWVWTj1ZrO753j7Zx+4UxVbKHSL8mbGfNQ02DSM0CvMmDZ3iRO aUOC+FBn4jD/TQxOBi2uDSI63PfDKfpHoAA5Tp08ltNRIQ1ebJBp72dpMb+b44BHYk6N vqckNcROJalLtonFd4AvuZG9+7VBf21Eh/rs9p3bZRmieYR0wV2QtJ1iAEQ7p5vhhkuV A6FA== X-Gm-Message-State: AJIora9nFlr7OAseBpeOpUMJl6iFN9NzODq0oNS1ex3sz2A/XdNEmfMi xEvK1XNKl3s4CjwpDqEwQkzOcDqRFBwjVA== X-Received: by 2002:a17:90a:ca14:b0:1f1:664a:241 with SMTP id x20-20020a17090aca1400b001f1664a0241mr17356543pjt.184.1658163947139; Mon, 18 Jul 2022 10:05:47 -0700 (PDT) Received: from atishp.ba.rivosinc.com ([66.220.2.162]) by smtp.gmail.com with ESMTPSA id r10-20020a170902be0a00b0016bc947c5b7sm9733402pls.38.2022.07.18.10.05.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Jul 2022 10:05:46 -0700 (PDT) From: Atish Patra To: linux-kernel@vger.kernel.org Cc: Atish Patra , Albert Ou , Anup Patel , Atish Patra , Guo Ren , kvm-riscv@lists.infradead.org, kvm@vger.kernel.org, linux-riscv@lists.infradead.org, Mark Rutland , Palmer Dabbelt , Paul Walmsley , Will Deacon Subject: [RFC 3/9] RISC-V: KVM: Define a probe function for SBI extension data structures Date: Mon, 18 Jul 2022 10:01:59 -0700 Message-Id: <20220718170205.2972215-4-atishp@rivosinc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220718170205.2972215-1-atishp@rivosinc.com> References: <20220718170205.2972215-1-atishp@rivosinc.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,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 lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org c,urrently the probe function just check if an SBI extension is registered or not. However, the extension may not want to advertise itself depending on some other condition. An additional extension specific probe function will allow extensions to decide if they want to be advertised to the caller or not. Any extension that do not require additional dependency check does not required to implement this function. Signed-off-by: Atish Patra --- arch/riscv/include/asm/kvm_vcpu_sbi.h | 3 +++ arch/riscv/kvm/vcpu_sbi_base.c | 13 +++++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/arch/riscv/include/asm/kvm_vcpu_sbi.h b/arch/riscv/include/asm/kvm_vcpu_sbi.h index 83d6d4d2b1df..5853a1ef71ea 100644 --- a/arch/riscv/include/asm/kvm_vcpu_sbi.h +++ b/arch/riscv/include/asm/kvm_vcpu_sbi.h @@ -25,6 +25,9 @@ struct kvm_vcpu_sbi_extension { int (*handler)(struct kvm_vcpu *vcpu, struct kvm_run *run, unsigned long *out_val, struct kvm_cpu_trap *utrap, bool *exit); + + /* Extension specific probe function */ + unsigned long (*probe)(unsigned long extid); }; void kvm_riscv_vcpu_sbi_forward(struct kvm_vcpu *vcpu, struct kvm_run *run); diff --git a/arch/riscv/kvm/vcpu_sbi_base.c b/arch/riscv/kvm/vcpu_sbi_base.c index 48f431091cdb..14be1a819588 100644 --- a/arch/riscv/kvm/vcpu_sbi_base.c +++ b/arch/riscv/kvm/vcpu_sbi_base.c @@ -22,6 +22,7 @@ static int kvm_sbi_ext_base_handler(struct kvm_vcpu *vcpu, struct kvm_run *run, int ret = 0; struct kvm_cpu_context *cp = &vcpu->arch.guest_context; struct sbiret ecall_ret; + const struct kvm_vcpu_sbi_extension *sbi_ext; switch (cp->a6) { case SBI_EXT_BASE_GET_SPEC_VERSION: @@ -46,8 +47,16 @@ static int kvm_sbi_ext_base_handler(struct kvm_vcpu *vcpu, struct kvm_run *run, */ kvm_riscv_vcpu_sbi_forward(vcpu, run); *exit = true; - } else - *out_val = kvm_vcpu_sbi_find_ext(cp->a0) ? 1 : 0; + } else { + sbi_ext = kvm_vcpu_sbi_find_ext(cp->a0); + if (sbi_ext) { + if (sbi_ext->probe) + *out_val = sbi_ext->probe(cp->a0); + else + *out_val = 1; + } else + *out_val = 0; + } break; case SBI_EXT_BASE_GET_MVENDORID: case SBI_EXT_BASE_GET_MARCHID: -- 2.25.1