From: Sean Christopherson <seanjc@google.com>
To: Yosry Ahmed <yosry@kernel.org>
Cc: Paolo Bonzini <pbonzini@redhat.com>,
kvm@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v3 03/10] KVM: selftests: Use an array for guest_regs (and fix offsets)
Date: Fri, 24 Jul 2026 10:03:38 -0700 [thread overview]
Message-ID: <amOa6qCKvyFWc6z4@google.com> (raw)
In-Reply-To: <CAO9r8zMZmGEmkwu7ixZE+5izZEwsAdoq3fiypiDO0fHowp7_1g@mail.gmail.com>
On Fri, Jul 24, 2026, Yosry Ahmed wrote:
> On Fri, Jul 24, 2026 at 8:33 AM Sean Christopherson <seanjc@google.com> wrote:
> Oh I wanted to, but the compiler wouldn't let me use enum values
> directly in the preprocessor, see:
> https://lore.kernel.org/kvm/CAO9r8zPz8WbijVN6mgLb8OaU6=tNSSz1NgNBjZCsC36D4+TO+w@mail.gmail.com/.
>
> I can do an enum *and* macros using enum values if you prefer so, like:
>
> #define __GUEST_REGS_RAX 0
> ...
>
> enum guest_regs {
> GUEST_REGS_RAX = __GUEST_REGS_RAX,
> ...
> NR_GUEST_REGS,
> };
I would much rather follow KUT's lib/x86/virt.h, and provide asm constraints for
the offsets. Actually, my vote is to copy+paste KUT's entire approach, and provide:
struct guest_regs {
u64 rax;
u64 rcx;
u64 rdx;
u64 rbx;
/*
* Use RSP's index to hold CR2, as RSP isn't manually context switched
* by software in any relevant flows.
*
* FIXME: Actually context switch CR2 on Intel.
*/
u64 cr2;
u64 rbp;
u64 rsi;
u64 rdi;
u64 r8;
u64 r9;
u64 r10;
u64 r11;
u64 r12;
u64 r13;
u64 r14;
u64 r15;
u64 rflags;
};
Using an array for the GPRs is only valuable when the code *needs* to index the
GPRs based on their index, e.g. like KVM needs to do when emulating instructions.
But for "normal" software, using an array just makes the code kludgy.
E.g. this
vmcb->save.rip = (u64)guest_rip;
vmcb->save.rsp = (u64)svm->stack;
guest_regs.rdi = (u64)svm;
versus
vmcb->save.rip = (u64)guest_rip;
vmcb->save.rsp = (u64)svm->stack;
guest_regs[X86_REGS_RDI] = (u64)svm;
next prev parent reply other threads:[~2026-07-24 17:03 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-29 18:37 [PATCH v3 00/10] KVM: selftests: Stress save+restore and #PF (ft. nested) Yosry Ahmed
2026-06-29 18:37 ` [PATCH v3 01/10] KVM: selftests: Move STR() and XSTR() definitions to test_util.h Yosry Ahmed
2026-07-24 15:26 ` Sean Christopherson
2026-06-29 18:37 ` [PATCH v3 02/10] KVM: selftests: Fix RAX and RFLAGS VMCB offsets when running L2 Yosry Ahmed
2026-06-29 18:37 ` [PATCH v3 03/10] KVM: selftests: Use an array for guest_regs (and fix offsets) Yosry Ahmed
2026-07-24 15:33 ` Sean Christopherson
2026-07-24 16:18 ` Yosry Ahmed
2026-07-24 17:03 ` Sean Christopherson [this message]
2026-07-24 17:44 ` Yosry Ahmed
2026-06-29 18:37 ` [PATCH v3 04/10] KVM: selftests: Move GPR load/save definitions outside of nSVM code Yosry Ahmed
2026-06-29 18:37 ` [PATCH v3 05/10] KVM: selftests: Reuse GPR switching logic for nVMX Yosry Ahmed
2026-06-29 18:37 ` [PATCH v3 06/10] KVM: selftests: Drop HORRIFIC_L2_UCALL_CLOBBER_HACK Yosry Ahmed
2026-07-24 15:37 ` Sean Christopherson
2026-07-24 16:20 ` Yosry Ahmed
2026-06-29 18:37 ` [PATCH v3 07/10] KVM: selftests: Add basic stress test for save+restore and #PF handling Yosry Ahmed
2026-07-24 16:45 ` Sean Christopherson
2026-07-24 17:38 ` Yosry Ahmed
2026-07-24 18:12 ` Sean Christopherson
2026-07-24 18:25 ` Yosry Ahmed
2026-06-29 18:37 ` [PATCH v3 08/10] KVM: selftests: Trigger save+restore randomly in the #PF stress test Yosry Ahmed
2026-06-29 18:37 ` [PATCH v3 09/10] KVM: selftests: Support running stress save+restore and #PF test in L2 Yosry Ahmed
2026-07-24 17:37 ` Sean Christopherson
2026-07-24 17:40 ` Yosry Ahmed
2026-06-29 18:37 ` [PATCH v3 10/10] KVM: selftests: Trigger L2->L1 exits stress save+restore and #PF test Yosry Ahmed
2026-07-24 17:50 ` Sean Christopherson
2026-07-24 18:15 ` Yosry Ahmed
2026-07-24 18:25 ` Sean Christopherson
2026-07-24 18:35 ` Yosry Ahmed
2026-07-24 20:32 ` Sean Christopherson
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=amOa6qCKvyFWc6z4@google.com \
--to=seanjc@google.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=pbonzini@redhat.com \
--cc=yosry@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
Powered by JetHome