[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250923050942.206116-8-Neeraj.Upadhyay@amd.com>
Date: Tue, 23 Sep 2025 10:39:14 +0530
From: Neeraj Upadhyay <Neeraj.Upadhyay@....com>
To: <kvm@...r.kernel.org>, <seanjc@...gle.com>, <pbonzini@...hat.com>
CC: <linux-kernel@...r.kernel.org>, <Thomas.Lendacky@....com>,
<nikunj@....com>, <Santosh.Shukla@....com>, <Vasant.Hegde@....com>,
<Suravee.Suthikulpanit@....com>, <bp@...en8.de>, <David.Kaplan@....com>,
<huibo.wang@....com>, <naveen.rao@....com>, <pgonda@...gle.com>,
<linux-kselftest@...r.kernel.org>, <shuah@...nel.org>, <tiala@...rosoft.com>
Subject: [RFC PATCH v2 07/35] KVM: selftests: Return an unused GHCB from the pool
The ghcb_alloc() function in the SEV selftest library always returned
the first GHCB from the pool, regardless of whether it was already in
use. In a multi-vCPU test, this causes all vCPUs to share and corrupt
the same GHCB, leading to unpredictable test failures.
Modify ghcb_alloc() to iterate through the pool and return the first
entry that is not currently marked as in_use. Mark the selected entry
as in use before returning it to prevent other vCPUs from allocating it.
Additionally, correct a minor bug in the memset call which was
incorrectly taking the address of the ghcb pointer instead of using
the pointer value itself.
This ensures that each vCPU in a test gets its own unique GHCB, allowing
multi-threaded SEV-ES tests to run correctly.
Signed-off-by: Neeraj Upadhyay <Neeraj.Upadhyay@....com>
---
tools/testing/selftests/kvm/lib/x86/sev.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/tools/testing/selftests/kvm/lib/x86/sev.c b/tools/testing/selftests/kvm/lib/x86/sev.c
index de36a6c93839..3090a6518066 100644
--- a/tools/testing/selftests/kvm/lib/x86/sev.c
+++ b/tools/testing/selftests/kvm/lib/x86/sev.c
@@ -68,7 +68,6 @@ static void sev_es_terminate(void)
static struct ghcb_entry *ghcb_alloc(void)
{
- return &ghcb_pool->ghcbs[0];
struct ghcb_entry *entry;
struct ghcb *ghcb;
int i;
@@ -81,7 +80,7 @@ static struct ghcb_entry *ghcb_alloc(void)
entry = &ghcb_pool->ghcbs[i];
ghcb = &entry->ghcb;
- memset(&ghcb, 0, sizeof(*ghcb));
+ memset(ghcb, 0, sizeof(*ghcb));
ghcb->ghcb_usage = 0;
ghcb->protocol_version = 1;
--
2.34.1
Powered by blists - more mailing lists