From patchwork Wed Feb 1 23:12:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Patra X-Patchwork-Id: 51595 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp562016wrn; Wed, 1 Feb 2023 15:13:53 -0800 (PST) X-Google-Smtp-Source: AK7set/F+dGEmupN3C/D59OTq9GKacR1vzfWRyCtqE9ZnTgkH/PL++3czKfxREPuaPxP8/uBPFN4 X-Received: by 2002:a17:90b:1e50:b0:229:649a:9a05 with SMTP id pi16-20020a17090b1e5000b00229649a9a05mr4257660pjb.11.1675293233501; Wed, 01 Feb 2023 15:13:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675293233; cv=none; d=google.com; s=arc-20160816; b=dHQT4QqnLg4J7aSw54K014ugUu179RD0JNsHsqDphbt7oK0H8idY4s9AezfVlN+N9O KaLzE+17scqWblmCY79oPDCkzJrEVhHiawER+5J6dqet9dYL26dGD0ThZjq4uLXceXkf kwMD49WGOw/dOxgWi2e4eXs2UxjvBkZKQfoDByq35f0kA/OrLO/aL+gBOcCTfTkectMq IjuiBDgSsQ6Db/f/fYjlUozyAArJd6VkZPx4/XRzFLCIFp9aeDkuOt8uI+yrDhURUEm9 zQFXJaPERArA3QasXAb8TAu3noiy8ByFyIP2iyW56nky0NMzVU+2Ub0soI8/WWR9gkkn J/aw== 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=kCMwx+bNWqE6Uw0wVFvOC8mb8JgaxncZy1aDemdVBjk=; b=MVC5WNHfPFeGqxPfeIU7yQQCbc9WV7iNsigmC9bJzUHAr54gBet74jyXzjT3UAeH5W k1HOS6Sm1g/sdwvjpmAIbLt2VRIz8/WJoH5bgGXfqI1c3XAxezIhIoYJoODQ9SJX51DN brX9ZlowmGY6BW3h/fKTyHsFmj55z9Gjsu5yBczYU4qVM2QnoCVT3xlqE6IFfC8h2wFG Mvb8tJX6U6P65a1WgnEw045utjaAVY8VZlutPV7e2ezWR58fpbp5vzAAw9YGOV2yGLZB IdlBZHTDR9Vtn667ZS77Vd3nXj/H2vbbac4/cZwd/+LO6S9YAY32yPprEPEu7YnE98/7 Pvxw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rivosinc-com.20210112.gappssmtp.com header.s=20210112 header.b=mdNqkzYU; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id il4-20020a17090b164400b00229c7de0072si3580761pjb.147.2023.02.01.15.13.40; Wed, 01 Feb 2023 15:13:53 -0800 (PST) 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=mdNqkzYU; 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 S231382AbjBAXNH (ORCPT + 99 others); Wed, 1 Feb 2023 18:13:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38112 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230526AbjBAXNC (ORCPT ); Wed, 1 Feb 2023 18:13:02 -0500 Received: from mail-pj1-x102a.google.com (mail-pj1-x102a.google.com [IPv6:2607:f8b0:4864:20::102a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CF4D7EFB2 for ; Wed, 1 Feb 2023 15:12:57 -0800 (PST) Received: by mail-pj1-x102a.google.com with SMTP id cl23-20020a17090af69700b0022c745bfdc3so133307pjb.3 for ; Wed, 01 Feb 2023 15:12:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20210112.gappssmtp.com; s=20210112; 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=kCMwx+bNWqE6Uw0wVFvOC8mb8JgaxncZy1aDemdVBjk=; b=mdNqkzYUs2zpA4DU4VEmsE/uQMZGivSWSfYeFb6rmpfasEsLsAcZPkheNKsoOFTjd/ vq9cpIn8un8CiRxkgXJuDEjVEYrtJ32FDY0W7HHlquY0qlzqPXTcULeK+8fOMeeOu4q2 KFCm+0LEilFqCX77NN1juCn9Vsy8dCUzU+XMU+VY4HOD7MUu/P4iJlmI9p2JWXUxJMek PFCms9ed2SH/2qADoAi9aUd56mwgsDRaJ8qXSYWlqAfPFPqBzVuVn5/izTeKikNZjBbu uLGwwhc5JtW06s+X/OhthIZeYKsfpk7/u4oZ+Kf3xMlvFwzbWXO9KAYnvfWKrspcZmap vTUA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=kCMwx+bNWqE6Uw0wVFvOC8mb8JgaxncZy1aDemdVBjk=; b=MTYSFGBKFZ+xEU+1dCiPLEFjJPHeWsnRmWgOiKC8yQewTLGLwouJUS0ro5CfErOyYc lMhkmx+/J9b1zZk5yljyx6aGNll88/o1SsFITC3lbgpYFOXET5QRgAh2w3ySFgDXH9/9 IckGsujjRzgNVG80WVQf7ibYybgNnGqOiNXu/dZgdSGM0VE3y5ptS1oJoisO6rWRwN7F cOuvCCP4lLFh18f7VBF74jYhZ91zeSFJUpV2vKmS+Wp1iEJQieNZka09AtGmRcLPcFtY 0FtvImDjpWjESCvDSy49XaeQTY9iZEOQXmTdUmtEj8jPdIgQxXaHembsES6YVLnUiG2K x29A== X-Gm-Message-State: AO0yUKVHSLeu/kIsZqJK761M0gr3K7LiQtxvgbfqYYTwzJGGt/dRxnLG 9b0eKTFdt1qmBgDFoAoiRrCO4qbC1BKPtm4Z X-Received: by 2002:a17:90b:1c05:b0:22b:b5c7:4fc with SMTP id oc5-20020a17090b1c0500b0022bb5c704fcmr4086441pjb.46.1675293176534; Wed, 01 Feb 2023 15:12:56 -0800 (PST) Received: from atishp.ba.rivosinc.com ([66.220.2.162]) by smtp.gmail.com with ESMTPSA id t3-20020a17090a510300b0022bf0b0e1b7sm1861774pjh.10.2023.02.01.15.12.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Feb 2023 15:12:56 -0800 (PST) From: Atish Patra To: linux-kernel@vger.kernel.org Cc: Atish Patra , Anup Patel , Albert Ou , Andrew Jones , Atish Patra , Eric Lin , Guo Ren , Heiko Stuebner , kvm-riscv@lists.infradead.org, kvm@vger.kernel.org, linux-riscv@lists.infradead.org, Mark Rutland , Palmer Dabbelt , Paul Walmsley , Will Deacon Subject: [PATCH v4 04/14] RISC-V: KVM: Define a probe function for SBI extension data structures Date: Wed, 1 Feb 2023 15:12:40 -0800 Message-Id: <20230201231250.3806412-5-atishp@rivosinc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230201231250.3806412-1-atishp@rivosinc.com> References: <20230201231250.3806412-1-atishp@rivosinc.com> MIME-Version: 1.0 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1756672277416819034?= X-GMAIL-MSGID: =?utf-8?q?1756672277416819034?= Currently the probe function just checks 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 does not require additional dependency checks can avoid implementing this function. Reviewed-by: Anup Patel Signed-off-by: Atish Patra Reviewed-by: Andrew Jones --- 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 f79478a..45ba341 100644 --- a/arch/riscv/include/asm/kvm_vcpu_sbi.h +++ b/arch/riscv/include/asm/kvm_vcpu_sbi.h @@ -29,6 +29,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)(struct kvm_vcpu *vcpu); }; 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 5d65c63..846d518 100644 --- a/arch/riscv/kvm/vcpu_sbi_base.c +++ b/arch/riscv/kvm/vcpu_sbi_base.c @@ -19,6 +19,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; + const struct kvm_vcpu_sbi_extension *sbi_ext; switch (cp->a6) { case SBI_EXT_BASE_GET_SPEC_VERSION: @@ -43,8 +44,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(vcpu); + else + *out_val = 1; + } else + *out_val = 0; + } break; case SBI_EXT_BASE_GET_MVENDORID: *out_val = vcpu->arch.mvendorid;