From patchwork Fri Aug 4 00:42:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 13341032 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 76B4DC001DB for ; Fri, 4 Aug 2023 00:43:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:Reply-To:List-Subscribe:List-Help: List-Post:List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:Message-ID :References:Mime-Version:In-Reply-To:Date:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=ZehOJb3vPAUHHHMGTyGrt/0b/jbgZIAHnt98QUkJp6I=; b=0TbG6/seTYtM+B 4bMtqvRKBvCdyOu3m4OfYOg0YRmy+W2Bm7KO1Te6f8sFUmtgTaXai31hhU+uDWSnd5QgduRkzRb7o aFlPz35IrY28QK0SeNbo+/jpQkLDV6sS+2ZrS3yoS66pSDd062gofYvWhAEzg8IM5A4a9ODIWsZ3E L+BUY1AGSnCzHMbuDzMHihMNn2xPZmjwQuNk404GtSgEHnDxATWpfnITeHI2z2fWQ7sR273Gg4J+c Qt8PW5qDWkLoNXOxtXUg7EaLxrw5vPYHrhFH4ezRCxrr6D/NDNWBaQdC7rJh3sUmQT/jbdTUYMuq6 QEFSvVB1GK6wuFFzjDSQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qRitq-00BBRy-06; Fri, 04 Aug 2023 00:42:38 +0000 Received: from mail-pl1-x64a.google.com ([2607:f8b0:4864:20::64a]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qRitn-00BBQg-0u for linux-arm-kernel@lists.infradead.org; Fri, 04 Aug 2023 00:42:36 +0000 Received: by mail-pl1-x64a.google.com with SMTP id d9443c01a7336-1bb982d2572so13376045ad.0 for ; Thu, 03 Aug 2023 17:42:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1691109754; x=1691714554; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:from:to:cc:subject:date:message-id:reply-to; bh=J+mxzLyo3KvL1X1/io+X1OzBSufdvdiiGzpaJwRMhFQ=; b=SOX0LmZ7M/i5Xu6IShPkO2I+BxiwZ7/tKfFw/OszRJyMzjeA8srrxfMqCj4Z29VgNn T0538ljVhrlqi2oWqsf8SDO/oV45EgP4x4oPafLtiFcA3cCpGCSnbWPlD7O1UBhgOJNe iWOEAZPpkZuEI+dl8Vup28taKKrYkoe9EEkFDZdVyWlSSumkRefUTDG/veJy2F6RniEr D4CN9ItmtE3GLQpzTfzusmxS7gLu+J3zXqOmaxg3BFTHOgLSHC5+aOpOePxVzXkX7y+j 40aPvclyhw23NLYArpVti1fhnKJ/y5UqJGdMWPnW2w3RzepQtSrazDZXeGyOlRrMC0eG uSAg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691109754; x=1691714554; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=J+mxzLyo3KvL1X1/io+X1OzBSufdvdiiGzpaJwRMhFQ=; b=isNx3g0J44wxraPHvJhI/YDLHPWFI1jfbWOMn0LPDfiYwyVYDbnLHWGo82UdPkQjm0 QzpVv5sb6MB1ovo2jQ5eVecwFM65yIINhaLptqoy1PBFfFzma5o/FbNn8DW3ots9oDF1 3xiTR420r4R+gOP4ZQPxk70tWoXEYX8p04syCqWplgdOYVKzTMF7eu9rxjTmiFv3CO48 qWtjq5vqjMinH/U3vLusAfgVGo4Vuyy2HQkCW4zJLmmWPLAryLKWQekvgM8zESOYn43S vbFUjqoWHlDaos3ReDhO6bEqIhkZH+a5kRa3RU/ZkmQUImeoUNgMqlm3EmC5arK0YYw+ p81w== X-Gm-Message-State: AOJu0YxC//deB9ay64YczxqTLF3ffNV9F3zMwE6M11afxxzPAl9eUbF6 SWXYygktgLhQG7zclRRcZeS5XpQe+Fw= X-Google-Smtp-Source: AGHT+IHgxmGXjdzVwOxMuN7YUlHLd0HAzkRoLNDux7bwtM6itZt1UHKYVf8WxlurAEE0Phc3A5aSSAIz63w= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a17:902:dad1:b0:1b8:a555:385d with SMTP id q17-20020a170902dad100b001b8a555385dmr1165plx.9.1691109754176; Thu, 03 Aug 2023 17:42:34 -0700 (PDT) Date: Thu, 3 Aug 2023 17:42:25 -0700 In-Reply-To: <20230804004226.1984505-1-seanjc@google.com> Mime-Version: 1.0 References: <20230804004226.1984505-1-seanjc@google.com> X-Mailer: git-send-email 2.41.0.585.gd2178a4bd4-goog Message-ID: <20230804004226.1984505-4-seanjc@google.com> Subject: [PATCH 3/4] KVM: selftests: Use asserting kvm_ioctl() macros when getting ARM page sizes From: Sean Christopherson To: Marc Zyngier , Oliver Upton Cc: linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-kernel@vger.kernel.org, Sean Christopherson , Michal Luczaj X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230803_174235_324100_55E364C8 X-CRM114-Status: GOOD ( 14.25 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Sean Christopherson Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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 --- .../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;