🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: org.kernel.vger.linux-doc
Article #1

Re: [PATCH v6 11/14] RISC-V: KVM: add SBI extension init()/deinit() functions

#1
From: Anup Patel
Date: Fri, 09 May 2025 03:20
122 lines
9725 bytes
Hi Palmer,

On Thu, May 8, 2025 at 10:57 PM Palmer Dabbelt <palmer@dabbelt.com> wrote:
>
> On Thu, 24 Apr 2025 10:31:58 PDT (-0700), cleger@rivosinc.com wrote:
> > The FWFT SBI extension will need to dynamically allocate memory and do
> > init time specific initialization. Add an init/deinit callbacks that
> > allows to do so.
> >
> > Signed-off-by: Clément Léger <cleger@rivosinc.com>
> > Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
> > ---
> >  arch/riscv/include/asm/kvm_vcpu_sbi.h |  9 +++++++++
> >  arch/riscv/kvm/vcpu.c                 |  2 ++
> >  arch/riscv/kvm/vcpu_sbi.c             | 26 ++++++++++++++++++++++++++
> >  3 files changed, 37 insertions(+)
>
> There's 4 KVM patches in here without an Ack from Atish or Anup.
> They're all tied up in the SBIv3 stuff, so just LMK if you want me to
> take them into that staging branch or if you want me to wait.
>
> For now I'm going to go look at other stuff, no rush on my end.

The 4 KVM patches of this series should go through the KVM RISC-V
tree to avoid conflicts when it reaches Linus. I am okay doing a shared
tag for the first 10 patches.

Regards,
Anup

>
> >
> > diff --git a/arch/riscv/include/asm/kvm_vcpu_sbi.h b/arch/riscv/include/asm/kvm_vcpu_sbi.h
> > index 4ed6203cdd30..bcb90757b149 100644
> > --- a/arch/riscv/include/asm/kvm_vcpu_sbi.h
> > +++ b/arch/riscv/include/asm/kvm_vcpu_sbi.h
> > @@ -49,6 +49,14 @@ struct kvm_vcpu_sbi_extension {
> >
> >       /* Extension specific probe function */
> >       unsigned long (*probe)(struct kvm_vcpu *vcpu);
> > +
> > +     /*
> > +      * Init/deinit function called once during VCPU init/destroy. These
> > +      * might be use if the SBI extensions need to allocate or do specific
> > +      * init time only configuration.
> > +      */
> > +     int (*init)(struct kvm_vcpu *vcpu);
> > +     void (*deinit)(struct kvm_vcpu *vcpu);
> >  };
> >
> >  void kvm_riscv_vcpu_sbi_forward(struct kvm_vcpu *vcpu, struct kvm_run *run);
> > @@ -69,6 +77,7 @@ const struct kvm_vcpu_sbi_extension *kvm_vcpu_sbi_find_ext(
> >  bool riscv_vcpu_supports_sbi_ext(struct kvm_vcpu *vcpu, int idx);
> >  int kvm_riscv_vcpu_sbi_ecall(struct kvm_vcpu *vcpu, struct kvm_run *run);
> >  void kvm_riscv_vcpu_sbi_init(struct kvm_vcpu *vcpu);
> > +void kvm_riscv_vcpu_sbi_deinit(struct kvm_vcpu *vcpu);
> >
> >  int kvm_riscv_vcpu_get_reg_sbi_sta(struct kvm_vcpu *vcpu, unsigned long reg_num,
> >                                  unsigned long *reg_val);
> > diff --git a/arch/riscv/kvm/vcpu.c b/arch/riscv/kvm/vcpu.c
> > index 60d684c76c58..877bcc85c067 100644
> > --- a/arch/riscv/kvm/vcpu.c
> > +++ b/arch/riscv/kvm/vcpu.c
> > @@ -185,6 +185,8 @@ void kvm_arch_vcpu_postcreate(struct kvm_vcpu *vcpu)
> >
> >  void kvm_arch_vcpu_destroy(struct kvm_vcpu *vcpu)
> >  {
> > +     kvm_riscv_vcpu_sbi_deinit(vcpu);
> > +
> >       /* Cleanup VCPU AIA context */
> >       kvm_riscv_vcpu_aia_deinit(vcpu);
> >
> > diff --git a/arch/riscv/kvm/vcpu_sbi.c b/arch/riscv/kvm/vcpu_sbi.c
> > index d1c83a77735e..3139f171c20f 100644
> > --- a/arch/riscv/kvm/vcpu_sbi.c
> > +++ b/arch/riscv/kvm/vcpu_sbi.c
> > @@ -508,5 +508,31 @@ void kvm_riscv_vcpu_sbi_init(struct kvm_vcpu *vcpu)
> >               scontext->ext_status[idx] = ext->default_disabled ?
> >                                       KVM_RISCV_SBI_EXT_STATUS_DISABLED :
> >                                       KVM_RISCV_SBI_EXT_STATUS_ENABLED;
> > +
> > +             if (ext->init && ext->init(vcpu) != 0)
> > +                     scontext->ext_status[idx] = KVM_RISCV_SBI_EXT_STATUS_UNAVAILABLE;
> > +     }
> > +}
> > +
> > +void kvm_riscv_vcpu_sbi_deinit(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 idx, i;
> > +
> > +     for (i = 0; i < ARRAY_SIZE(sbi_ext); i++) {
> > +             entry = &sbi_ext[i];
> > +             ext = entry->ext_ptr;
> > +             idx = entry->ext_idx;
> > +
> > +             if (idx < 0 || idx >= ARRAY_SIZE(scontext->ext_status))
> > +                     continue;
> > +
> > +             if (scontext->ext_status[idx] == KVM_RISCV_SBI_EXT_STATUS_UNAVAILABLE ||
> > +                 !ext->deinit)
> > +                     continue;
> > +
> > +             ext->deinit(vcpu);
> >       }
> >  }
Technical Details
Message-ID: <CAAhSdy1JspaC6aYjkMQn_fvjc1eFakdu2JMTQFuCzrh4h4o_3w@mail.gmail.com>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!i2pn2.pugleaf.net!archive.newsdeef.eu!archive!apf9.newsdeef.eu!nntp.lore.kernel.org!not-for-mail
References: <20250424173204.1948385-12-cleger@rivosinc.com> <mhng-0c7b576b-882d-4020-996d-adb1b2bbcc4b@palmer-ri-x1c9a>

Show Full Headers
Complete Article Headers
Message-ID: <CAAhSdy1JspaC6aYjkMQn_fvjc1eFakdu2JMTQFuCzrh4h4o_3w@mail.gmail.com>
Subject: Re: [PATCH v6 11/14] RISC-V: KVM: add SBI extension init()/deinit() functions
Date: Fri, 9 May 2025 08:50:24 +0530
From: Anup Patel <anup@brainfault.org>
References: <20250424173204.1948385-12-cleger@rivosinc.com> <mhng-0c7b576b-882d-4020-996d-adb1b2bbcc4b@palmer-ri-x1c9a>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!i2pn2.pugleaf.net!archive.newsdeef.eu!archive!apf9.newsdeef.eu!nntp.lore.kernel.org!not-for-mail
Received: from mail-il1-f176.google.com (mail-il1-f176.google.com [209.85.166.176])
 (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
 (No client certificate requested)
 by smtp.subspace.kernel.org (Postfix) with ESMTPS id BDE7B21E094
Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.166.176
ARC-Seal: ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;
 t=1746760838; cv=none; b=tnFefTnQo4EMaxBLOCFFU+0ONTAEjQGbY6dZ0BMEulNCQLimcBx9+eQI+AhmT0P2ttAvDvyuk0rEQLMcNZUPKOJ0x+TD/czC29lS5jx9mJHeu1lj0iF31pLY3ajOMzmwSST23jA80zu3b9GJfW7Hn4wKMij7LadQs3jU4a1SMDI=
ARC-Message-Signature: ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org;
 s=arc-20240116; t=1746760838; c=relaxed/simple;
 bh=QxYt6I37j8Y2FWScFRIV2InQ82omXNQYJHqU/dkoDOQ=;
 h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject:
 To:Cc:Content-Type; b=rL+Lj9GS3fuHJ5LziXzvYAF63+U0cGKjMWPAU9UzMbaBA+O1bd5ZzEP/op/ni4bPW7yYvjAwMUsDaoNjWXARiNGQwKXHAkWR5gUL088mGP7ybE8Q4PWcnLDXb+qNqNk7WUO9PcyijHO8jEPLTEKPc+CFu8XRv905JGNAvJAT+28=
ARC-Authentication-Results: ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=brainfault.org; spf=none smtp.mailfrom=brainfault.org; dkim=pass (2048-bit key) header.d=brainfault-org.20230601.gappssmtp.com header.i=@brainfault-org.20230601.gappssmtp.com header.b=2llTUcHZ; arc=none smtp.client-ip=209.85.166.176
Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=brainfault.org
Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=brainfault.org
Authentication-Results: smtp.subspace.kernel.org;
 dkim=pass (2048-bit key) header.d=brainfault-org.20230601.gappssmtp.com header.i=@brainfault-org.20230601.gappssmtp.com header.b="2llTUcHZ"
Received: by mail-il1-f176.google.com with SMTP id e9e14a558f8ab-3d9189e9a06so7772685ab.2
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
    d=brainfault-org.20230601.gappssmtp.com; s=20230601; t=1746760836; x=1747365636; darn=vger.kernel.org;
    h=content-transfer-encoding:cc:to:subject:message-id:date:from
     :in-reply-to:references:mime-version:from:to:cc:subject:date
     :message-id:reply-to;
    bh=SnqKcVSyirwFx4wEXZIT0zJRplLj4a3hbHksAZ3+SSo=;
    b=2llTUcHZLw6lkdSaA7SZ26rQk0pvWBtXZGqOKYRe+hJw77S5vZ4SUYziUG/BmQFSnH
     iAUW8p5quXkXaUI4KY36MXOxO6lDGF7CL/HUA1EA3WoKIaMc5xP4KUF/BL6BeLQQ29mS
     DjRzLbOIN0Uu0W+NQimB+37BjrZ/p9xeFkSLhEzlQZbwFj5Us6uOYqmOJqITUCn5Cz7t
     t0dzXGWvjO/gNfMK1CLqTXcu7YfppmCE3ryhiyrIqAGmoPszKdQg07Z2FVC3FbOGwuOM
     oKRCDaVz45uuFiK6a6+whegrPpMFa8ajXuNS36JA90h/Z8ojcvw/SL/P7oseeMYUNuCu
     10Mg==
X-Forwarded-Encrypted: i=1; AJvYcCWl7ClT3gL0Nn62CwRAbZ6aKFbCCYsntMmU/S1Gpz8LjLQ6+1Y21RJEQ6nR0T+fpKX9PJFDqeWA0uSZ7ZI=@vger.kernel.org
X-Gm-Message-State: AOJu0Yy88DXGPLLGwTfb/pYB27Rto/MyFlsOrfFgDo8bdZFmyg9w/GHd
 qEFfBPhj28evoyOhSudT4si3L9pXywxMozxCus1sI800GbIJHFgXjAL3ebZWwgQ2L8FFYFTdSR5
 HzMqxqwQqYlJXgx/Bm3xESk2PmGjKVpsD7UA4wA==
X-Gm-Gg: ASbGncv5qV5bB9vYcBcYszdqzy0UbKLtUhPBQ294ROkcwVSun+/8zdA5nVzeB30LLwE
 PRaFgjvmyeY1XLx614KESMrIkjYkrvo62E0esNQ/dgaySwgacrXWVe7zA5FGG6J5q6/jnbViXQr
 +4Rx6zqmShGoYXSaEuAFDOD8k=
X-Received: by 2002:a05:6e02:2292:b0:3d6:cd54:ba53 with SMTP id
 e9e14a558f8ab-3da7e21658cmr27127695ab.22.1746760835694; Thu, 08 May 2025
Precedence: bulk
X-Mailing-List: linux-kernel@vger.kernel.org
List-Id: <linux-kernel.vger.kernel.org>
List-Subscribe: <mailto:linux-kernel+subscribe@vger.kernel.org>
List-Unsubscribe: <mailto:linux-kernel+unsubscribe@vger.kernel.org>
MIME-Version: 1.0
In-Reply-To: <mhng-0c7b576b-882d-4020-996d-adb1b2bbcc4b@palmer-ri-x1c9a>
X-Gm-Features: ATxdqUHBve2EeFlPYflmLTkAF_hrOfFokX5MPn_gLZXF6fdS6VEfyoAB6lvQ_MY
To: Palmer Dabbelt <palmer@dabbelt.com>
Cc: Atish Patra <atishp@rivosinc.com>, cleger@rivosinc.com,
 Paul Walmsley <paul.walmsley@sifive.com>, atishp@atishpatra.org, shuah@kernel.org, 
 corbet@lwn.net, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, 
 linux-doc@vger.kernel.org, kvm@vger.kernel.org, kvm-riscv@lists.infradead.org, 
 linux-kselftest@vger.kernel.org, samuel.holland@sifive.com, 
 ajones@ventanamicro.com, debug@rivosinc.com
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Newsgroups: org.kernel.vger.linux-kernel,org.kernel.vger.kvm,org.kernel.vger.linux-doc,org.kernel.vger.linux-kselftest