From patchwork Thu Sep 16 18:15:50 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oliver Upton X-Patchwork-Id: 12499941 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 294C7C433EF for ; Thu, 16 Sep 2021 18:31:33 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id E77F061139 for ; Thu, 16 Sep 2021 18:31:32 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org E77F061139 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.infradead.org 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:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:References: Mime-Version:Message-Id:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=VhOZ0iTdHTDwGlZaQDeCPGkLNz+jUCdlEciXw2zrHmg=; b=JOXKI6p11MYX2VLxa2hoMlScJc yoyVIIvkNzjT7QRJ1tYby+cMo/7TxaYdLo5IB0u6TfL6AA/a7pl8bE1vbYb5/Rm62toXhnAZKQuca 6lpmv50YxZcC7Qqd6EzxZMyUZbDE10ZHcTkr+oI8pSztrYV5U+4T6cunXKJaPmeu0zcWylrIErStm VTagvmUh3MjDViRtdkP176di4ds4w3xIM+EtbWDDpUS5m9btpW+u3VYPGFEROMfuYNPNFoTOCY8kK PUQfx8oOsgQKRBXfMZSLa1/d8Akz4eGIWN6Qa39FEeUXJqrW6oYfJpZiUINRIzRvHf7RyFfI06ip0 7GQQKo/Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mQw8o-00C7u7-PL; Thu, 16 Sep 2021 18:29:47 +0000 Received: from mail-qt1-x849.google.com ([2607:f8b0:4864:20::849]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mQvvY-00C23p-6i for linux-arm-kernel@lists.infradead.org; Thu, 16 Sep 2021 18:16:05 +0000 Received: by mail-qt1-x849.google.com with SMTP id p21-20020ac846150000b02902982d999bfbso63058162qtn.7 for ; Thu, 16 Sep 2021 11:16:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=Lf2+OEFIK0DZ90wJh7r/ap0DRDUXtW/FHZQIxM7aCWs=; b=OITDpvH3x47XxN6kO7/uIZZCcH87kVGWV1zze6CTqPoC0xc4xzgliRMfE64m3NEX80 GyZZzBRKHNvNwBUtA3psK6dCbAuZ1BPrC9Wl2EWblOPhm668jYBsUxNbsVUsjiClpMeZ +WrBoG3O8UkRRbPERQzyEgpYKao6TIIMlfW0ZGJ6+BM90PftlP56VjGG9pKDpLOKQQJd Z2VxMBz+6AgHeLgz02agykPsLNoqzY10MBYH3VaJMvVjlhRDnGu0MeAkDbiPZtbf3XJa +eaCwjBjdsslhdJdRm5WurKJGa0hwRKdBFY6f2bdC0scVg+Suflb4TP7jvFPzQD3DFys ssew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=Lf2+OEFIK0DZ90wJh7r/ap0DRDUXtW/FHZQIxM7aCWs=; b=BAcCqRnBia4MYPruGIpiUXtGB838zJ5LLy760j7aWc8BispiI+ixze8VzX3Gvo5Fgz KJJx/ZnctmyX4U5wXkjxGgQnRlILuIrdTDd6R902+lsb13J4sXTkhxKKiaaahY57PvB4 pEVk0gJHDsFGMGPrhVNRUWE3AV8N8KBs3ER0aAVj3SbKcAnXCL2B5eZhUkkzb1FBB448 SbhmHU0nyWaGI6K/CwI320ABQTPnHLUezIsGqhN+/yYgo9+JPFwC3lAaGTPMPZHveFY6 VAhZTRO25Q8LeUCPagX28PTZk2hGooCKxH+3zu2drE1cTAT5+AMqwtDdo9wTW2Om7qUU 4hvA== X-Gm-Message-State: AOAM533VmNDiT9xRTFzEHmIelqqolOQolbrEuW1F0qBJf4nPjaq9064K ZvXE8XgtLvyAS/DZqYABpO/Jxzssz78= X-Google-Smtp-Source: ABdhPJwYPmdbsJ31AQtWH9mTug2gOZOVdIfRujXipfU/0mTRAqDcQpmUVVXp1iBNavHQTcnnUliFBYKJ7Mc= X-Received: from oupton.c.googlers.com ([fda3:e722:ac3:cc00:2b:ff92:c0a8:404]) (user=oupton job=sendgmr) by 2002:a05:6214:1444:: with SMTP id b4mr6740209qvy.33.1631816162488; Thu, 16 Sep 2021 11:16:02 -0700 (PDT) Date: Thu, 16 Sep 2021 18:15:50 +0000 In-Reply-To: <20210916181555.973085-1-oupton@google.com> Message-Id: <20210916181555.973085-5-oupton@google.com> Mime-Version: 1.0 References: <20210916181555.973085-1-oupton@google.com> X-Mailer: git-send-email 2.33.0.464.g1972c5931b-goog Subject: [PATCH v8 4/9] selftests: KVM: Add helpers for vCPU device attributes From: Oliver Upton To: kvm@vger.kernel.org, kvmarm@lists.cs.columbia.edu Cc: Paolo Bonzini , Sean Christopherson , Marc Zyngier , Peter Shier , Jim Mattson , David Matlack , Ricardo Koller , Jing Zhang , Raghavendra Rao Anata , James Morse , Alexandru Elisei , Suzuki K Poulose , linux-arm-kernel@lists.infradead.org, Andrew Jones , Will Deacon , Catalin Marinas , Oliver Upton X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210916_111604_307956_6F8F9856 X-CRM114-Status: UNSURE ( 9.59 ) X-CRM114-Notice: Please train this message. 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: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org vCPU file descriptors are abstracted away from test code in KVM selftests, meaning that tests cannot directly access a vCPU's device attributes. Add helpers that tests can use to get at vCPU device attributes. Reviewed-by: Andrew Jones Signed-off-by: Oliver Upton --- .../testing/selftests/kvm/include/kvm_util.h | 9 +++++ tools/testing/selftests/kvm/lib/kvm_util.c | 38 +++++++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/tools/testing/selftests/kvm/include/kvm_util.h b/tools/testing/selftests/kvm/include/kvm_util.h index a8ac5d52e17b..1b3ef5757819 100644 --- a/tools/testing/selftests/kvm/include/kvm_util.h +++ b/tools/testing/selftests/kvm/include/kvm_util.h @@ -240,6 +240,15 @@ int _kvm_device_access(int dev_fd, uint32_t group, uint64_t attr, int kvm_device_access(int dev_fd, uint32_t group, uint64_t attr, void *val, bool write); +int _vcpu_has_device_attr(struct kvm_vm *vm, uint32_t vcpuid, uint32_t group, + uint64_t attr); +int vcpu_has_device_attr(struct kvm_vm *vm, uint32_t vcpuid, uint32_t group, + uint64_t attr); +int _vcpu_access_device_attr(struct kvm_vm *vm, uint32_t vcpuid, uint32_t group, + uint64_t attr, void *val, bool write); +int vcpu_access_device_attr(struct kvm_vm *vm, uint32_t vcpuid, uint32_t group, + uint64_t attr, void *val, bool write); + const char *exit_reason_str(unsigned int exit_reason); void virt_pgd_alloc(struct kvm_vm *vm); diff --git a/tools/testing/selftests/kvm/lib/kvm_util.c b/tools/testing/selftests/kvm/lib/kvm_util.c index 0ffc2d39c80d..0fe66ca6139a 100644 --- a/tools/testing/selftests/kvm/lib/kvm_util.c +++ b/tools/testing/selftests/kvm/lib/kvm_util.c @@ -2040,6 +2040,44 @@ int kvm_device_access(int dev_fd, uint32_t group, uint64_t attr, return ret; } +int _vcpu_has_device_attr(struct kvm_vm *vm, uint32_t vcpuid, uint32_t group, + uint64_t attr) +{ + struct vcpu *vcpu = vcpu_find(vm, vcpuid); + + TEST_ASSERT(vcpu, "nonexistent vcpu id: %d", vcpuid); + + return _kvm_device_check_attr(vcpu->fd, group, attr); +} + +int vcpu_has_device_attr(struct kvm_vm *vm, uint32_t vcpuid, uint32_t group, + uint64_t attr) +{ + int ret = _vcpu_has_device_attr(vm, vcpuid, group, attr); + + TEST_ASSERT(!ret, "KVM_HAS_DEVICE_ATTR IOCTL failed, rc: %i errno: %i", ret, errno); + return ret; +} + +int _vcpu_access_device_attr(struct kvm_vm *vm, uint32_t vcpuid, uint32_t group, + uint64_t attr, void *val, bool write) +{ + struct vcpu *vcpu = vcpu_find(vm, vcpuid); + + TEST_ASSERT(vcpu, "nonexistent vcpu id: %d", vcpuid); + + return _kvm_device_access(vcpu->fd, group, attr, val, write); +} + +int vcpu_access_device_attr(struct kvm_vm *vm, uint32_t vcpuid, uint32_t group, + uint64_t attr, void *val, bool write) +{ + int ret = _vcpu_access_device_attr(vm, vcpuid, group, attr, val, write); + + TEST_ASSERT(!ret, "KVM_SET|GET_DEVICE_ATTR IOCTL failed, rc: %i errno: %i", ret, errno); + return ret; +} + /* * VM Dump *