All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andrew Jones <ajones@ventanamicro.com>
To: kvm-riscv@lists.infradead.org
Subject: [PATCH 1/3] RISC-V: KVM: Disable SBI extension when its probe fails
Date: Wed, 26 Apr 2023 19:13:26 +0200	[thread overview]
Message-ID: <20230426171328.69663-2-ajones@ventanamicro.com> (raw)
In-Reply-To: <20230426171328.69663-1-ajones@ventanamicro.com>

When an SBI extension specific probe function exists and fails, then
use the extension_disabled context to disable the extension. This
ensures the extension's functions cannot be invoked. Doing the
disabling in kvm_vcpu_sbi_find_ext() allows it to be done lazily
on its first use. Checking extension_disabled prior to probing
ensures the probe is only executed once for disabled extensions.
Later patches ensure we only execute probe once for enabled
extensions as well.

Signed-off-by: Andrew Jones <ajones@ventanamicro.com>
---
 arch/riscv/kvm/vcpu_sbi.c | 23 +++++++++++++++--------
 1 file changed, 15 insertions(+), 8 deletions(-)

diff --git a/arch/riscv/kvm/vcpu_sbi.c b/arch/riscv/kvm/vcpu_sbi.c
index e52fde504433..aa3c126d2e3c 100644
--- a/arch/riscv/kvm/vcpu_sbi.c
+++ b/arch/riscv/kvm/vcpu_sbi.c
@@ -307,18 +307,25 @@ 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 i;
-	const struct kvm_riscv_sbi_extension_entry *sext;
 	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++) {
-		sext = &sbi_ext[i];
-		if (sext->ext_ptr->extid_start <= extid &&
-		    sext->ext_ptr->extid_end >= extid) {
-			if (sext->dis_idx < KVM_RISCV_SBI_EXT_MAX &&
-			    scontext->extension_disabled[sext->dis_idx])
+		entry = &sbi_ext[i];
+		ext = entry->ext_ptr;
+
+		if (ext->extid_start <= extid && ext->extid_end >= extid) {
+			if (entry->dis_idx >= KVM_RISCV_SBI_EXT_MAX)
+				return ext;
+			if (scontext->extension_disabled[entry->dis_idx])
+				return NULL;
+			if (ext->probe && !ext->probe(vcpu)) {
+				scontext->extension_disabled[entry->dis_idx] = true;
 				return NULL;
-			return sbi_ext[i].ext_ptr;
+			}
+			return ext;
 		}
 	}
 
-- 
2.39.2



WARNING: multiple messages have this Message-ID (diff)
From: Andrew Jones <ajones@ventanamicro.com>
To: kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org
Cc: 'Palmer Dabbelt ' <palmer@dabbelt.com>,
	'Anup Patel ' <anup@brainfault.org>,
	'Atish Patra ' <atishp@atishpatra.org>,
	'Albert Ou ' <aou@eecs.berkeley.edu>,
	'Paul Walmsley ' <paul.walmsley@sifive.com>
Subject: [PATCH 1/3] RISC-V: KVM: Disable SBI extension when its probe fails
Date: Wed, 26 Apr 2023 19:13:26 +0200	[thread overview]
Message-ID: <20230426171328.69663-2-ajones@ventanamicro.com> (raw)
In-Reply-To: <20230426171328.69663-1-ajones@ventanamicro.com>

When an SBI extension specific probe function exists and fails, then
use the extension_disabled context to disable the extension. This
ensures the extension's functions cannot be invoked. Doing the
disabling in kvm_vcpu_sbi_find_ext() allows it to be done lazily
on its first use. Checking extension_disabled prior to probing
ensures the probe is only executed once for disabled extensions.
Later patches ensure we only execute probe once for enabled
extensions as well.

Signed-off-by: Andrew Jones <ajones@ventanamicro.com>
---
 arch/riscv/kvm/vcpu_sbi.c | 23 +++++++++++++++--------
 1 file changed, 15 insertions(+), 8 deletions(-)

diff --git a/arch/riscv/kvm/vcpu_sbi.c b/arch/riscv/kvm/vcpu_sbi.c
index e52fde504433..aa3c126d2e3c 100644
--- a/arch/riscv/kvm/vcpu_sbi.c
+++ b/arch/riscv/kvm/vcpu_sbi.c
@@ -307,18 +307,25 @@ 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 i;
-	const struct kvm_riscv_sbi_extension_entry *sext;
 	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++) {
-		sext = &sbi_ext[i];
-		if (sext->ext_ptr->extid_start <= extid &&
-		    sext->ext_ptr->extid_end >= extid) {
-			if (sext->dis_idx < KVM_RISCV_SBI_EXT_MAX &&
-			    scontext->extension_disabled[sext->dis_idx])
+		entry = &sbi_ext[i];
+		ext = entry->ext_ptr;
+
+		if (ext->extid_start <= extid && ext->extid_end >= extid) {
+			if (entry->dis_idx >= KVM_RISCV_SBI_EXT_MAX)
+				return ext;
+			if (scontext->extension_disabled[entry->dis_idx])
+				return NULL;
+			if (ext->probe && !ext->probe(vcpu)) {
+				scontext->extension_disabled[entry->dis_idx] = true;
 				return NULL;
-			return sbi_ext[i].ext_ptr;
+			}
+			return ext;
 		}
 	}
 
-- 
2.39.2


_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

  reply	other threads:[~2023-04-26 17:13 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-26 17:13 [PATCH 0/3] RISC-V: KVM: Ensure SBI extension is enabled Andrew Jones
2023-04-26 17:13 ` Andrew Jones
2023-04-26 17:13 ` Andrew Jones [this message]
2023-04-26 17:13   ` [PATCH 1/3] RISC-V: KVM: Disable SBI extension when its probe fails Andrew Jones
2023-05-19 14:57   ` Anup Patel
2023-05-19 14:57     ` Anup Patel
2023-05-19 15:02     ` Anup Patel
2023-05-19 15:02       ` Anup Patel
2023-04-26 17:13 ` [PATCH 2/3] RISC-V: KVM: Rename dis_idx to ext_idx Andrew Jones
2023-04-26 17:13   ` Andrew Jones
2023-05-19 14:58   ` Anup Patel
2023-05-19 14:58     ` Anup Patel
2023-04-26 17:13 ` [PATCH 3/3] RISC-V: KVM: Introduce extension_enabled Andrew Jones
2023-04-26 17:13   ` Andrew Jones
2023-05-19 15:05   ` Anup Patel
2023-05-19 15:05     ` Anup Patel
2023-05-22  9:28     ` Andrew Jones
2023-05-22  9:28       ` Andrew Jones
2023-05-25 15:58       ` Anup Patel
2023-05-25 15:58         ` Anup Patel

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230426171328.69663-2-ajones@ventanamicro.com \
    --to=ajones@ventanamicro.com \
    --cc=kvm-riscv@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.