diff options
| author | Sean Christopherson <[email protected]> | 2022-10-06 00:34:03 +0000 |
|---|---|---|
| committer | Sean Christopherson <[email protected]> | 2022-11-16 16:58:51 -0800 |
| commit | 7046638192d52416adbfc273c36950f0e3311191 (patch) | |
| tree | 6483dab78b419e0b8e16b3f8d8547ff811e2be2c /tools/testing/selftests/kvm/lib/ucall_common.c | |
| parent | b3d937722de0e64eebe267451a0e3d5ed5107ef7 (diff) | |
KVM: selftests: Consolidate common code for populating ucall struct
Make ucall() a common helper that populates struct ucall, and only calls
into arch code to make the actually call out to userspace.
Rename all arch-specific helpers to make it clear they're arch-specific,
and to avoid collisions with common helpers (one more on its way...)
Add WRITE_ONCE() to stores in ucall() code (as already done to aarch64
code in commit 9e2f6498efbb ("selftests: KVM: Handle compiler
optimizations in ucall")) to prevent clang optimizations breaking ucalls.
Cc: Colton Lewis <[email protected]>
Reviewed-by: Andrew Jones <[email protected]>
Tested-by: Peter Gonda <[email protected]>
Signed-off-by: Sean Christopherson <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Diffstat (limited to 'tools/testing/selftests/kvm/lib/ucall_common.c')
| -rw-r--r-- | tools/testing/selftests/kvm/lib/ucall_common.c | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/tools/testing/selftests/kvm/lib/ucall_common.c b/tools/testing/selftests/kvm/lib/ucall_common.c new file mode 100644 index 000000000000..2395c7f1d543 --- /dev/null +++ b/tools/testing/selftests/kvm/lib/ucall_common.c @@ -0,0 +1,20 @@ +// SPDX-License-Identifier: GPL-2.0-only +#include "kvm_util.h" + +void ucall(uint64_t cmd, int nargs, ...) +{ + struct ucall uc = {}; + va_list va; + int i; + + WRITE_ONCE(uc.cmd, cmd); + + nargs = min(nargs, UCALL_MAX_ARGS); + + va_start(va, nargs); + for (i = 0; i < nargs; ++i) + WRITE_ONCE(uc.args[i], va_arg(va, uint64_t)); + va_end(va); + + ucall_arch_do_ucall((vm_vaddr_t)&uc); +} |