From: Neeraj Upadhyay <Neeraj.Upadhyay@amd.com>
To: <kvm@vger.kernel.org>, <seanjc@google.com>, <pbonzini@redhat.com>
Cc: <linux-kernel@vger.kernel.org>, <Thomas.Lendacky@amd.com>,
<nikunj@amd.com>, <Santosh.Shukla@amd.com>,
<Vasant.Hegde@amd.com>, <Suravee.Suthikulpanit@amd.com>,
<bp@alien8.de>, <David.Kaplan@amd.com>, <huibo.wang@amd.com>,
<naveen.rao@amd.com>, <pgonda@google.com>,
<linux-kselftest@vger.kernel.org>, <shuah@kernel.org>
Subject: [RFC PATCH 17/31] KVM: selftests: Add x2apic mode testing in xapic_ipi_test
Date: Fri, 28 Feb 2025 15:00:10 +0530 [thread overview]
Message-ID: <20250228093024.114983-18-Neeraj.Upadhyay@amd.com> (raw)
In-Reply-To: <20250228093024.114983-1-Neeraj.Upadhyay@amd.com>
Add support for testing x2apic mode in xapic_ipi_test. This
allows extending the test in future to support VMs which
only work in x2apic mode such as Secure AVIC enabled VMs.
Signed-off-by: Neeraj Upadhyay <Neeraj.Upadhyay@amd.com>
---
.../selftests/kvm/x86/xapic_ipi_test.c | 65 +++++++++++++++----
1 file changed, 51 insertions(+), 14 deletions(-)
diff --git a/tools/testing/selftests/kvm/x86/xapic_ipi_test.c b/tools/testing/selftests/kvm/x86/xapic_ipi_test.c
index a76078a08ff8..024514089766 100644
--- a/tools/testing/selftests/kvm/x86/xapic_ipi_test.c
+++ b/tools/testing/selftests/kvm/x86/xapic_ipi_test.c
@@ -50,6 +50,29 @@
*/
static volatile uint64_t ipis_rcvd;
+static bool x2apic;
+
+static void apic_enable(void)
+{
+ if (x2apic)
+ x2apic_enable();
+ else
+ xapic_enable();
+}
+
+static uint32_t apic_read_reg(unsigned int reg)
+{
+ return x2apic ? x2apic_read_reg(reg) : xapic_read_reg(reg);
+}
+
+static void apic_write_reg(unsigned int reg, uint64_t val)
+{
+ if (x2apic)
+ x2apic_write_reg(reg, val);
+ else
+ xapic_write_reg(reg, (uint32_t)val);
+}
+
/* Data struct shared between host main thread and vCPUs */
struct test_data_page {
uint32_t halter_apic_id;
@@ -89,10 +112,10 @@ void verify_apic_base_addr(void)
static void halter_guest_code(struct test_data_page *data)
{
verify_apic_base_addr();
- xapic_enable();
+ apic_enable();
- data->halter_apic_id = GET_APIC_ID_FIELD(xapic_read_reg(APIC_ID));
- data->halter_lvr = xapic_read_reg(APIC_LVR);
+ data->halter_apic_id = GET_APIC_ID_FIELD(apic_read_reg(APIC_ID));
+ data->halter_lvr = apic_read_reg(APIC_LVR);
/*
* Loop forever HLTing and recording halts & wakes. Disable interrupts
@@ -103,8 +126,8 @@ static void halter_guest_code(struct test_data_page *data)
* TPR and PPR for diagnostic purposes in case the test fails.
*/
for (;;) {
- data->halter_tpr = xapic_read_reg(APIC_TASKPRI);
- data->halter_ppr = xapic_read_reg(APIC_PROCPRI);
+ data->halter_tpr = apic_read_reg(APIC_TASKPRI);
+ data->halter_ppr = apic_read_reg(APIC_PROCPRI);
data->hlt_count++;
asm volatile("sti; hlt; cli");
data->wake_count++;
@@ -119,7 +142,7 @@ static void halter_guest_code(struct test_data_page *data)
static void guest_ipi_handler(struct ex_regs *regs)
{
ipis_rcvd++;
- xapic_write_reg(APIC_EOI, 77);
+ apic_write_reg(APIC_EOI, 77);
}
static void sender_guest_code(struct test_data_page *data)
@@ -132,7 +155,7 @@ static void sender_guest_code(struct test_data_page *data)
uint64_t tsc_start;
verify_apic_base_addr();
- xapic_enable();
+ apic_enable();
/*
* Init interrupt command register for sending IPIs
@@ -159,8 +182,12 @@ static void sender_guest_code(struct test_data_page *data)
* First IPI can be sent unconditionally because halter vCPU
* starts earlier.
*/
- xapic_write_reg(APIC_ICR2, icr2_val);
- xapic_write_reg(APIC_ICR, icr_val);
+ if (!x2apic) {
+ apic_write_reg(APIC_ICR2, icr2_val);
+ apic_write_reg(APIC_ICR, icr_val);
+ } else {
+ apic_write_reg(APIC_ICR, (uint64_t)icr2_val << 32 | icr_val);
+ }
data->ipis_sent++;
/*
@@ -356,10 +383,10 @@ void do_migrations(struct test_data_page *data, int run_secs, int delay_usecs,
}
void get_cmdline_args(int argc, char *argv[], int *run_secs,
- bool *migrate, int *delay_usecs)
+ bool *migrate, int *delay_usecs, bool *x2apic)
{
for (;;) {
- int opt = getopt(argc, argv, "s:d:m");
+ int opt = getopt(argc, argv, "s:d:v:me:");
if (opt == -1)
break;
@@ -373,13 +400,18 @@ void get_cmdline_args(int argc, char *argv[], int *run_secs,
case 'd':
*delay_usecs = parse_size(optarg);
break;
+ case 'e':
+ *x2apic = parse_size(optarg) == 1;
+ break;
default:
TEST_ASSERT(false,
"Usage: -s <runtime seconds>. Default is %d seconds.\n"
"-m adds calls to migrate_pages while vCPUs are running."
" Default is no migrations.\n"
"-d <delay microseconds> - delay between migrate_pages() calls."
- " Default is %d microseconds.",
+ " Default is %d microseconds.\n"
+ "-e <apic mode> - APIC mode 0 - xapic , 1 - x2apic"
+ " Default is xAPIC.\n",
DEFAULT_RUN_SECS, DEFAULT_DELAY_USECS);
}
}
@@ -400,7 +432,10 @@ int main(int argc, char *argv[])
struct kvm_vm *vm;
uint64_t *pipis_rcvd;
- get_cmdline_args(argc, argv, &run_secs, &migrate, &delay_usecs);
+ get_cmdline_args(argc, argv, &run_secs, &migrate, &delay_usecs, &x2apic);
+ if (x2apic)
+ migrate = 0;
+
if (run_secs <= 0)
run_secs = DEFAULT_RUN_SECS;
if (delay_usecs <= 0)
@@ -410,7 +445,9 @@ int main(int argc, char *argv[])
vm_install_exception_handler(vm, IPI_VECTOR, guest_ipi_handler);
- virt_pg_map(vm, APIC_DEFAULT_GPA, APIC_DEFAULT_GPA);
+ sync_global_to_guest(vm, x2apic);
+ if (!x2apic)
+ virt_pg_map(vm, APIC_DEFAULT_GPA, APIC_DEFAULT_GPA);
params[1].vcpu = vm_vcpu_add(vm, 1, sender_guest_code);
--
2.34.1
next prev parent reply other threads:[~2025-02-28 9:51 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-28 9:29 [RFC PATCH 00/31] AMD: Add Secure AVIC KVM selftests Neeraj Upadhyay
2025-02-28 9:29 ` [RFC PATCH 01/31] Add GHCB with setters and getters Neeraj Upadhyay
2025-02-28 9:29 ` [RFC PATCH 02/31] Add arch specific additional guest pages Neeraj Upadhyay
2025-02-28 9:29 ` [RFC PATCH 03/31] Add vm_vaddr_alloc_pages_shared() Neeraj Upadhyay
2025-02-28 9:29 ` [RFC PATCH 04/31] Add GHCB allocations and helpers Neeraj Upadhyay
2025-02-28 9:29 ` [RFC PATCH 05/31] Add is_sev_enabled() helpers Neeraj Upadhyay
2025-02-28 9:29 ` [RFC PATCH 06/31] Add ability for SEV-ES guests to use ucalls via GHCB Neeraj Upadhyay
2025-02-28 9:30 ` [RFC PATCH 07/31] KVM: selftests: Fix ghcb_entry returned in ghcb_alloc() Neeraj Upadhyay
2025-02-28 9:30 ` [RFC PATCH 08/31] KVM: selftests: Make GHCB entry page size aligned Neeraj Upadhyay
2025-02-28 9:30 ` [RFC PATCH 09/31] KVM: selftests: Add support for #VC in x86 exception handlers Neeraj Upadhyay
2025-02-28 9:30 ` [RFC PATCH 10/31] KVM: selftests: Add MSR VC handling support for SEV-ES VMs Neeraj Upadhyay
2025-02-28 9:30 ` [RFC PATCH 11/31] KVM: selftests: Skip vm_is_gpa_protected() call for APIC MMIO base Neeraj Upadhyay
2025-02-28 9:30 ` [RFC PATCH 12/31] KVM: selftests: Add instruction decoding support Neeraj Upadhyay
2025-02-28 9:30 ` [RFC PATCH 13/31] " Neeraj Upadhyay
2025-02-28 9:30 ` [RFC PATCH 14/31] KVM: selftests: Add MMIO VC exception handling for SEV-ES guests Neeraj Upadhyay
2025-02-28 9:30 ` [RFC PATCH 15/31] KVM: selftests: Add instruction decoding for movabs instructions Neeraj Upadhyay
2025-02-28 9:30 ` [RFC PATCH 16/31] KVM: selftests: Add SEV guests support in xapic_state_test Neeraj Upadhyay
2025-02-28 9:30 ` Neeraj Upadhyay [this message]
2025-02-28 9:30 ` [RFC PATCH 18/31] KVM: selftests: Add SEV VM support in xapic_ipi_test Neeraj Upadhyay
2025-02-28 9:30 ` [RFC PATCH 19/31] KVM: selftests: Add Secure AVIC lib Neeraj Upadhyay
2025-02-28 9:30 ` [RFC PATCH 20/31] KVM: selftests: Add unaccelerated APIC msrs #VC handling Neeraj Upadhyay
2025-02-28 9:30 ` [RFC PATCH 21/31] KVM: selftests: Add IPI handling support for Secure AVIC Neeraj Upadhyay
2025-02-28 9:30 ` [RFC PATCH 22/31] KVM: selftests: Add args param to kvm_arch_vm_post_create() Neeraj Upadhyay
2025-02-28 9:30 ` [RFC PATCH 23/31] KVM: selftests: Add SAVIC GPA notification GHCB call Neeraj Upadhyay
2025-02-28 9:30 ` [RFC PATCH 24/31] KVM: selftests: Add Secure AVIC mode to xapic_ipi_test Neeraj Upadhyay
2025-02-28 9:30 ` [RFC PATCH 25/31] KVM: selftests: Add Secure AVIC APIC regs test Neeraj Upadhyay
2025-02-28 9:30 ` [RFC PATCH 26/31] KVM: selftests: Add test to verify APIC MSR accesses for SAVIC guest Neeraj Upadhyay
2025-02-28 9:30 ` [RFC PATCH 27/31] KVM: selftests: Extend savic test with idle halt testing Neeraj Upadhyay
2025-02-28 9:30 ` [RFC PATCH 28/31] KVM: selftests: Add IOAPIC tests for Secure AVIC Neeraj Upadhyay
2025-02-28 9:30 ` [RFC PATCH 29/31] KVM: selftests: Add cross-vCPU IPI testing for SAVIC guests Neeraj Upadhyay
2025-02-28 9:30 ` [RFC PATCH 30/31] KVM: selftests: Add NMI test " Neeraj Upadhyay
2025-02-28 9:30 ` [RFC PATCH 31/31] KVM: selftests: Add MSI injection test for SAVIC Neeraj Upadhyay
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=20250228093024.114983-18-Neeraj.Upadhyay@amd.com \
--to=neeraj.upadhyay@amd.com \
--cc=David.Kaplan@amd.com \
--cc=Santosh.Shukla@amd.com \
--cc=Suravee.Suthikulpanit@amd.com \
--cc=Thomas.Lendacky@amd.com \
--cc=Vasant.Hegde@amd.com \
--cc=bp@alien8.de \
--cc=huibo.wang@amd.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=naveen.rao@amd.com \
--cc=nikunj@amd.com \
--cc=pbonzini@redhat.com \
--cc=pgonda@google.com \
--cc=seanjc@google.com \
--cc=shuah@kernel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®