2022-06-18 00:33:44

by Sean Christopherson

[permalink] [raw]
Subject: [PATCH 0/3] KVM: selftests: Consolidate ucall code

Consolidate the code for making and getting ucalls. All architectures pass
the ucall struct via memory, so filling and copying the struct is 100%
generic. The only per-arch code is sending and receiving the address of
said struct.

Tested on x86 and arm, compile tested on s390 and RISC-V.

Sean Christopherson (3):
KVM: selftests: Consolidate common code for popuplating ucall struct
KVM: selftests: Consolidate boilerplate code in get_ucall()
KVM: selftest: Add __weak stubs for ucall_arch_(un)init()

tools/testing/selftests/kvm/Makefile | 1 +
.../selftests/kvm/include/ucall_common.h | 17 ++++++-
.../testing/selftests/kvm/lib/aarch64/ucall.c | 36 +++-----------
tools/testing/selftests/kvm/lib/riscv/ucall.c | 44 ++---------------
tools/testing/selftests/kvm/lib/s390x/ucall.c | 41 ++--------------
.../testing/selftests/kvm/lib/ucall_common.c | 49 +++++++++++++++++++
.../testing/selftests/kvm/lib/x86_64/ucall.c | 41 ++--------------
7 files changed, 87 insertions(+), 142 deletions(-)
create mode 100644 tools/testing/selftests/kvm/lib/ucall_common.c


base-commit: 8baacf67c76c560fed954ac972b63e6e59a6fba0
--
2.37.0.rc0.104.g0611611a94-goog


2022-06-18 00:39:10

by Sean Christopherson

[permalink] [raw]
Subject: [PATCH 3/3] KVM: selftest: Add __weak stubs for ucall_arch_(un)init()

Provide __weak stubs for (un)initializing ucall, aarch64 is the only
architecture that actually needs to do work.

No functional change intended.

Signed-off-by: Sean Christopherson <[email protected]>
---
tools/testing/selftests/kvm/lib/riscv/ucall.c | 8 --------
tools/testing/selftests/kvm/lib/s390x/ucall.c | 8 --------
tools/testing/selftests/kvm/lib/ucall_common.c | 10 ++++++++++
tools/testing/selftests/kvm/lib/x86_64/ucall.c | 8 --------
4 files changed, 10 insertions(+), 24 deletions(-)

diff --git a/tools/testing/selftests/kvm/lib/riscv/ucall.c b/tools/testing/selftests/kvm/lib/riscv/ucall.c
index 37e091d4366e..1c6c0432bdd7 100644
--- a/tools/testing/selftests/kvm/lib/riscv/ucall.c
+++ b/tools/testing/selftests/kvm/lib/riscv/ucall.c
@@ -10,14 +10,6 @@
#include "kvm_util.h"
#include "processor.h"

-void ucall_arch_init(struct kvm_vm *vm, void *arg)
-{
-}
-
-void ucall_arch_uninit(struct kvm_vm *vm)
-{
-}
-
struct sbiret sbi_ecall(int ext, int fid, unsigned long arg0,
unsigned long arg1, unsigned long arg2,
unsigned long arg3, unsigned long arg4,
diff --git a/tools/testing/selftests/kvm/lib/s390x/ucall.c b/tools/testing/selftests/kvm/lib/s390x/ucall.c
index 0f695a031d35..3e8d4275c9e4 100644
--- a/tools/testing/selftests/kvm/lib/s390x/ucall.c
+++ b/tools/testing/selftests/kvm/lib/s390x/ucall.c
@@ -6,14 +6,6 @@
*/
#include "kvm_util.h"

-void ucall_arch_init(struct kvm_vm *vm, void *arg)
-{
-}
-
-void ucall_arch_uninit(struct kvm_vm *vm)
-{
-}
-
void ucall_arch_do_ucall(vm_vaddr_t uc)
{
/* Exit via DIAGNOSE 0x501 (normally used for breakpoints) */
diff --git a/tools/testing/selftests/kvm/lib/ucall_common.c b/tools/testing/selftests/kvm/lib/ucall_common.c
index c488ed23d0dd..a1e563fd8fcc 100644
--- a/tools/testing/selftests/kvm/lib/ucall_common.c
+++ b/tools/testing/selftests/kvm/lib/ucall_common.c
@@ -1,6 +1,16 @@
// SPDX-License-Identifier: GPL-2.0-only
#include "kvm_util.h"

+void __weak ucall_arch_init(struct kvm_vm *vm, void *arg)
+{
+
+}
+
+void __weak ucall_arch_uninit(struct kvm_vm *vm)
+{
+
+}
+
void ucall(uint64_t cmd, int nargs, ...)
{
struct ucall uc = {
diff --git a/tools/testing/selftests/kvm/lib/x86_64/ucall.c b/tools/testing/selftests/kvm/lib/x86_64/ucall.c
index ec53a406f689..2f724f0bed32 100644
--- a/tools/testing/selftests/kvm/lib/x86_64/ucall.c
+++ b/tools/testing/selftests/kvm/lib/x86_64/ucall.c
@@ -8,14 +8,6 @@

#define UCALL_PIO_PORT ((uint16_t)0x1000)

-void ucall_arch_init(struct kvm_vm *vm, void *arg)
-{
-}
-
-void ucall_arch_uninit(struct kvm_vm *vm)
-{
-}
-
void ucall_arch_do_ucall(vm_vaddr_t uc)
{
asm volatile("in %[port], %%al"
--
2.37.0.rc0.104.g0611611a94-goog

2022-06-20 08:21:15

by Andrew Jones

[permalink] [raw]
Subject: Re: [PATCH 0/3] KVM: selftests: Consolidate ucall code

On Sat, Jun 18, 2022 at 12:16:15AM +0000, Sean Christopherson wrote:
> Consolidate the code for making and getting ucalls. All architectures pass
> the ucall struct via memory, so filling and copying the struct is 100%
> generic. The only per-arch code is sending and receiving the address of
> said struct.
>
> Tested on x86 and arm, compile tested on s390 and RISC-V.

For the series

Reviewed-by: Andrew Jones <[email protected]>

Thanks,
drew

2022-06-20 12:45:41

by Paolo Bonzini

[permalink] [raw]
Subject: Re: [PATCH 0/3] KVM: selftests: Consolidate ucall code

On 6/18/22 02:16, Sean Christopherson wrote:
> Consolidate the code for making and getting ucalls. All architectures pass
> the ucall struct via memory, so filling and copying the struct is 100%
> generic. The only per-arch code is sending and receiving the address of
> said struct.
>
> Tested on x86 and arm, compile tested on s390 and RISC-V.

I'm not sure about doing this yet. The SEV tests added multiple
implementations of the ucalls in one architecture. I have rebased those
recently (not the SEV part) to get more familiar with the new kvm_vcpu
API for selftests, and was going to look at your old review next...

Paolo

2022-06-21 15:12:57

by Sean Christopherson

[permalink] [raw]
Subject: Re: [PATCH 0/3] KVM: selftests: Consolidate ucall code

On Mon, Jun 20, 2022, Paolo Bonzini wrote:
> On 6/18/22 02:16, Sean Christopherson wrote:
> > Consolidate the code for making and getting ucalls. All architectures pass
> > the ucall struct via memory, so filling and copying the struct is 100%
> > generic. The only per-arch code is sending and receiving the address of
> > said struct.
> >
> > Tested on x86 and arm, compile tested on s390 and RISC-V.
>
> I'm not sure about doing this yet. The SEV tests added multiple
> implementations of the ucalls in one architecture. I have rebased those
> recently (not the SEV part) to get more familiar with the new kvm_vcpu API
> for selftests, and was going to look at your old review next...

I had forgotten about that code. My idea of a per-VM list[*] would fit nicely on
top, though maybe drop the last patch from this series.

[*] https://lore.kernel.org/all/[email protected]

2022-07-15 19:42:58

by Peter Gonda

[permalink] [raw]
Subject: Re: [PATCH 0/3] KVM: selftests: Consolidate ucall code

On Tue, Jun 21, 2022 at 8:55 AM Sean Christopherson <[email protected]> wrote:
>
> On Mon, Jun 20, 2022, Paolo Bonzini wrote:
> > On 6/18/22 02:16, Sean Christopherson wrote:
> > > Consolidate the code for making and getting ucalls. All architectures pass
> > > the ucall struct via memory, so filling and copying the struct is 100%
> > > generic. The only per-arch code is sending and receiving the address of
> > > said struct.
> > >
> > > Tested on x86 and arm, compile tested on s390 and RISC-V.
> >
> > I'm not sure about doing this yet. The SEV tests added multiple
> > implementations of the ucalls in one architecture. I have rebased those
> > recently (not the SEV part) to get more familiar with the new kvm_vcpu API
> > for selftests, and was going to look at your old review next...
>
> I had forgotten about that code. My idea of a per-VM list[*] would fit nicely on
> top, though maybe drop the last patch from this series.
>
> [*] https://lore.kernel.org/all/[email protected]

I just sent an RFC of SEV selftesting using Sean's suggestion built on
the first 2 patches in this series. I think they work well with the
encrypted VMs ucalling.

https://lore.kernel.org/all/[email protected]/