From: Sean Christopherson <seanjc@google.com>
To: Marc Zyngier <maz@kernel.org>, Oliver Upton <oliver.upton@linux.dev>
Cc: linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev,
linux-kernel@vger.kernel.org,
Sean Christopherson <seanjc@google.com>,
Michal Luczaj <mhal@rbox.co>
Subject: [PATCH 3/4] KVM: selftests: Use asserting kvm_ioctl() macros when getting ARM page sizes
Date: Thu, 3 Aug 2023 17:42:25 -0700 [thread overview]
Message-ID: <20230804004226.1984505-4-seanjc@google.com> (raw)
In-Reply-To: <20230804004226.1984505-1-seanjc@google.com>
Use kvm_ioctl() instead of open coding equivalent ioctl()+TEST_ASSERT()
calls when getting the support page sizes on ARM. The macro usage is a
little funky since the "kvm_fd" parameter implies an actual /dev/kvm fd,
but on the other hand the code is invoking KVM ioctl()s.
Alternatively, the core utilities could expose a vm_open()+vm_close()
pair so that the ARM code could create a dummy, on-stack VM+vCPU pair and
use {vm,vcpu}_ioctl() as appropriate. But the odds of something breaking
due to oddball, partial usage of kvm_vm and kvm_vcpu structures is much
higher than realizing meaningful benefit from using {vm,vcpu}_ioctl().
Signed-off-by: Sean Christopherson <seanjc@google.com>
---
.../selftests/kvm/lib/aarch64/processor.c | 18 ++++++------------
1 file changed, 6 insertions(+), 12 deletions(-)
diff --git a/tools/testing/selftests/kvm/lib/aarch64/processor.c b/tools/testing/selftests/kvm/lib/aarch64/processor.c
index 3a0259e25335..afec1a30916f 100644
--- a/tools/testing/selftests/kvm/lib/aarch64/processor.c
+++ b/tools/testing/selftests/kvm/lib/aarch64/processor.c
@@ -496,7 +496,7 @@ void aarch64_get_supported_page_sizes(uint32_t ipa,
bool *ps4k, bool *ps16k, bool *ps64k)
{
struct kvm_vcpu_init preferred_init;
- int kvm_fd, vm_fd, vcpu_fd, err;
+ int kvm_fd, vm_fd, vcpu_fd;
uint64_t val;
struct kvm_one_reg reg = {
.id = KVM_ARM64_SYS_REG(SYS_ID_AA64MMFR0_EL1),
@@ -504,19 +504,13 @@ void aarch64_get_supported_page_sizes(uint32_t ipa,
};
kvm_fd = open_kvm_dev_path_or_exit();
- vm_fd = __kvm_ioctl(kvm_fd, KVM_CREATE_VM, (void *)(unsigned long)ipa);
- TEST_ASSERT(vm_fd >= 0, KVM_IOCTL_ERROR(KVM_CREATE_VM, vm_fd));
+ vm_fd = kvm_fd_ioctl(kvm_fd, KVM_CREATE_VM, (void *)(unsigned long)ipa);
+ vcpu_fd = kvm_fd_ioctl(vm_fd, KVM_CREATE_VCPU, (void *)0ul);
- vcpu_fd = ioctl(vm_fd, KVM_CREATE_VCPU, 0);
- TEST_ASSERT(vcpu_fd >= 0, KVM_IOCTL_ERROR(KVM_CREATE_VCPU, vcpu_fd));
+ kvm_ioctl(vm_fd, KVM_ARM_PREFERRED_TARGET, &preferred_init);
+ kvm_ioctl(vcpu_fd, KVM_ARM_VCPU_INIT, &preferred_init);
- err = ioctl(vm_fd, KVM_ARM_PREFERRED_TARGET, &preferred_init);
- TEST_ASSERT(err == 0, KVM_IOCTL_ERROR(KVM_ARM_PREFERRED_TARGET, err));
- err = ioctl(vcpu_fd, KVM_ARM_VCPU_INIT, &preferred_init);
- TEST_ASSERT(err == 0, KVM_IOCTL_ERROR(KVM_ARM_VCPU_INIT, err));
-
- err = ioctl(vcpu_fd, KVM_GET_ONE_REG, ®);
- TEST_ASSERT(err == 0, KVM_IOCTL_ERROR(KVM_GET_ONE_REG, vcpu_fd));
+ kvm_ioctl(vcpu_fd, KVM_GET_ONE_REG, ®);
*ps4k = FIELD_GET(ARM64_FEATURE_MASK(ID_AA64MMFR0_TGRAN4), val) != 0xf;
*ps64k = FIELD_GET(ARM64_FEATURE_MASK(ID_AA64MMFR0_TGRAN64), val) == 0;
--
2.41.0.585.gd2178a4bd4-goog
next prev parent reply other threads:[~2023-08-04 0:43 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-04 0:42 [PATCH 0/4] KVM: selftests: ioctl() macro cleanups Sean Christopherson
2023-08-04 0:42 ` [PATCH 1/4] KVM: selftests: Drop the single-underscore ioctl() helpers Sean Christopherson
2023-08-04 0:42 ` [PATCH 2/4] KVM: selftests: Add helper macros for ioctl()s that return file descriptors Sean Christopherson
2023-08-04 16:46 ` Oliver Upton
2023-08-04 17:27 ` Sean Christopherson
2023-08-14 18:11 ` Sean Christopherson
2023-08-04 17:57 ` Colton Lewis
2023-08-04 18:33 ` Sean Christopherson
2023-08-04 0:42 ` Sean Christopherson [this message]
2023-08-04 14:58 ` [PATCH 3/4] KVM: selftests: Use asserting kvm_ioctl() macros when getting ARM page sizes Michal Luczaj
2023-08-04 15:23 ` Sean Christopherson
2023-08-04 0:42 ` [PATCH 4/4] KVM: selftests: Add logic to detect if ioctl() failed because VM was killed Sean Christopherson
2023-08-04 15:24 ` [PATCH 0/4] KVM: selftests: ioctl() macro cleanups 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=20230804004226.1984505-4-seanjc@google.com \
--to=seanjc@google.com \
--cc=kvmarm@lists.linux.dev \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=maz@kernel.org \
--cc=mhal@rbox.co \
--cc=oliver.upton@linux.dev \
/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®