From patchwork Thu Feb 24 17:25:58 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Raghavendra Rao Ananta X-Patchwork-Id: 12759080 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 BDAB5C433F5 for ; Thu, 24 Feb 2022 17:33:04 +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: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=TM7+T5iYaqet2NwtNxm9A/H3jF9wmW5yF+BOk+zrZS8=; b=kWlFseWAsXvXLxNMCZuXWFQeWz vBl1IDsCGpYkZlR/qPNwUEBhoT9FzvNz+ouW9BRo0CnGmGGeLYHhV40fJJIdytfMQdHZrrLAjzXNC JFsLeDxStiKY31Wr8CDjEWGlMj4Dq4STKvb1ofVFPljtVEmcW80398kdrg2sBtQ0vxbIhQWB6/lWC AcOwUJcCceqMee/o6MicNz8IK9OqiPRyd8S+wCEFoj99ivq2YNhyzC1mex3tJYW6k7HBTJQWXCdYe IDphyHPa6oVj3H8z6a1i2lgL4Do7TDMmRLb0n3rbEBt3WKJJwW+UCBGShwqCdFH4NJQcJJSeLSgCv X38bPJog==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nNHxn-001oYu-72; Thu, 24 Feb 2022 17:31:35 +0000 Received: from mail-pj1-x104a.google.com ([2607:f8b0:4864:20::104a]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nNHsy-001mJe-P3 for linux-arm-kernel@lists.infradead.org; Thu, 24 Feb 2022 17:26:38 +0000 Received: by mail-pj1-x104a.google.com with SMTP id t7-20020a17090a3b4700b001bc366c58faso3924685pjf.4 for ; Thu, 24 Feb 2022 09:26:35 -0800 (PST) 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=jmsF+28/o9uCf/VQ6k2qhkTuRm6SZhX9vjCTItav4Nc=; b=MlN/UYTncICeUsEkBDYqjV04VlUXrjRCma8eYvTC2n4PabVyNlEk1LltoOc1rlbsP5 BHwzTVQ0bQZgdqeFundXtet8O11tqSXdKmPvZbIYLXBL4MIStxKmsZImBmhLDRHyd9iP 1zX0cIBwW73iTjZNiwjKfzYpr54Js+FLQ1vYuNh2gwffgJAyV1xpp2KAPiuOFZlMQ057 X4dRf+jgoWGJTRdUWs7JthKJ9/YyXBuTdzWk6M/WKJw5dbEPLL2aShI6mjqHgWmaraNq RIB/mb6ecYxcpgdPaPcaT0j+eAXnz05OF+R9x5kVVeWEQ7R4G70Yoz6ESki6j1zEtlfP GMOw== 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=jmsF+28/o9uCf/VQ6k2qhkTuRm6SZhX9vjCTItav4Nc=; b=I/LD2f9BEpvF8iMpzs6w64fQAP00z1PO5ZrPP1b2v4scZQvyIh+XlAsEbLhehpJckF MBaYQHwt8CJrBPAzMX2ypENYP5yEXKaX4hn3vvw3alx1pgI+SF3bJ7de2mjQtCcjex2e rjjyzOdJ9Fgybh8EFGmKQBdwuXfOmPDCSsKuWQbBxbNbjCjX31rgAWk0lyKjx9RS6skZ j3mgcfcBGKqlIc8emmg2MeIxUyNSASUIwOXzrPDo+kboUpZCY/M4yGyMlZoTBhT/Nj2l M53JOUvytlWzTHf+UFeajfH4uaAVNJkD2Bb/gLLQ9h9m2o2/QahdQC6fWsvLIQ7A94PA jApA== X-Gm-Message-State: AOAM531c9WzjLjhB2mqLxEvzPieonrhExBLTSAcqejP8M02lhdG1dDjs WfsaVXikVWJL6jsfIppnprboqomiX9l+ X-Google-Smtp-Source: ABdhPJydh3IBl9/WqQAefokxf+CHH33yyX7uFA4vfoZVHfdfqGbdHQgTzulUJSpoukHYPflZqQVnV5VDQyf+ X-Received: from rananta-virt.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:1bcc]) (user=rananta job=sendgmr) by 2002:a17:90b:3ec2:b0:1b9:fbeb:942b with SMTP id rm2-20020a17090b3ec200b001b9fbeb942bmr15311322pjb.55.1645723595262; Thu, 24 Feb 2022 09:26:35 -0800 (PST) Date: Thu, 24 Feb 2022 17:25:58 +0000 In-Reply-To: <20220224172559.4170192-1-rananta@google.com> Message-Id: <20220224172559.4170192-13-rananta@google.com> Mime-Version: 1.0 References: <20220224172559.4170192-1-rananta@google.com> X-Mailer: git-send-email 2.35.1.574.g5d30c73bfb-goog Subject: [PATCH v4 12/13] selftests: KVM: aarch64: hypercalls: Test with KVM_CAP_ARM_REG_SCOPE From: Raghavendra Rao Ananta To: Marc Zyngier , Andrew Jones , James Morse , Alexandru Elisei , Suzuki K Poulose Cc: Paolo Bonzini , Catalin Marinas , Will Deacon , Peter Shier , Ricardo Koller , Oliver Upton , Reiji Watanabe , Jing Zhang , Raghavendra Rao Anata , linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, linux-kernel@vger.kernel.org, kvm@vger.kernel.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220224_092636_872801_F02CFBFE X-CRM114-Status: GOOD ( 17.89 ) 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 Upgrade the aarch64/hypercalls test to also consider the firmware register's scope information. Thus, run the test with the capability KVM_CAP_ARM_REG_SCOPE disabled and enabled. Signed-off-by: Raghavendra Rao Ananta --- .../selftests/kvm/aarch64/hypercalls.c | 83 +++++++++++++++++-- 1 file changed, 75 insertions(+), 8 deletions(-) diff --git a/tools/testing/selftests/kvm/aarch64/hypercalls.c b/tools/testing/selftests/kvm/aarch64/hypercalls.c index e4e3a286ff3e..85818b91b4fb 100644 --- a/tools/testing/selftests/kvm/aarch64/hypercalls.c +++ b/tools/testing/selftests/kvm/aarch64/hypercalls.c @@ -29,7 +29,7 @@ struct kvm_fw_reg_info { .max_feat_bit = bit_max, \ } -static const struct kvm_fw_reg_info fw_reg_info[] = { +static struct kvm_fw_reg_info fw_reg_info[] = { FW_REG_INFO(KVM_REG_ARM_STD_BMAP, KVM_REG_ARM_STD_BMAP_BIT_MAX), FW_REG_INFO(KVM_REG_ARM_STD_HYP_BMAP, KVM_REG_ARM_STD_HYP_BMAP_BIT_MAX), FW_REG_INFO(KVM_REG_ARM_VENDOR_HYP_BMAP, KVM_REG_ARM_VENDOR_HYP_BMAP_BIT_MAX), @@ -294,19 +294,78 @@ static void test_fw_regs_after_vm_start(struct kvm_vm *vm) } } -static struct kvm_vm *test_vm_create(void) +static bool test_reg_is_bmap_fw_reg(uint64_t reg) +{ + if ((reg & KVM_REG_ARM_COPROC_MASK) == KVM_REG_ARM_FW && + (reg & 0xffff) >= 0xff00) /* Bitmap firmware register space */ + return true; + + return false; +} + +static void test_fw_regs_encode_vm_scope(void) +{ + int i; + + /* + * Encode the scope as KVM_REG_ARM_SCOPE_VM for further use + * in KVM_SET_ONE_REG and KVM_GET_ONE_REG operations. + */ + for (i = 0; i < ARRAY_SIZE(fw_reg_info); i++) + fw_reg_info[i].reg |= (KVM_REG_ARM_SCOPE_VM << KVM_REG_ARM_SCOPE_SHIFT); +} + +static void test_validate_fw_regs(struct kvm_vm *vm, int scope) +{ + uint64_t i, reg; + int obtained_scope; + struct kvm_reg_list *reg_list; + + reg_list = vcpu_get_reg_list(vm, 0); + + for (i = 0; i < reg_list->n; i++) { + reg = reg_list->reg[i]; + if (!test_reg_is_bmap_fw_reg(reg)) + continue; + + /* + * Depending on KVM_CAP_ARM_REG_SCOPE, currently all the firmware + * bitmap registers are either completely VM-scoped or vCPU scoped. + */ + obtained_scope = (reg & KVM_REG_ARM_SCOPE_MASK) >> KVM_REG_ARM_SCOPE_SHIFT; + TEST_ASSERT(obtained_scope == scope, + "Incorrect scope detected for reg: %lx. Expected: %d; Obtained: %d\n", + reg, scope, obtained_scope); + } +} + +static struct kvm_vm *test_vm_create(int scope) { struct kvm_vm *vm; + struct kvm_enable_cap reg_scope_cap = { + .cap = KVM_CAP_ARM_REG_SCOPE, + }; + + if (scope == KVM_REG_ARM_SCOPE_VM && !kvm_check_cap(KVM_CAP_ARM_REG_SCOPE)) { + print_skip("Capability KVM_CAP_ARM_REG_SCOPE unavailable\n"); + return NULL; + } vm = vm_create_default(0, 0, guest_code); ucall_init(vm, NULL); steal_time_init(vm); + if (scope == KVM_REG_ARM_SCOPE_VM) { + vm_enable_cap(vm, ®_scope_cap); + test_fw_regs_encode_vm_scope(); + } + return vm; } -static struct kvm_vm *test_guest_stage(struct kvm_vm *vm) +static struct kvm_vm * +test_guest_stage(struct kvm_vm *vm, int scope) { struct kvm_vm *ret_vm = vm; @@ -319,7 +378,7 @@ static struct kvm_vm *test_guest_stage(struct kvm_vm *vm) case TEST_STAGE_HVC_IFACE_FEAT_DISABLED: /* Start a new VM so that all the features are now enabled by default */ kvm_vm_free(vm); - ret_vm = test_vm_create(); + ret_vm = test_vm_create(scope); break; case TEST_STAGE_HVC_IFACE_FEAT_ENABLED: case TEST_STAGE_HVC_IFACE_FALSE_INFO: @@ -334,14 +393,20 @@ static struct kvm_vm *test_guest_stage(struct kvm_vm *vm) return ret_vm; } -static void test_run(void) +static void test_run(int scope) { struct kvm_vm *vm; struct ucall uc; bool guest_done = false; - vm = test_vm_create(); + vm = test_vm_create(scope); + if (!vm) + return; + stage = TEST_STAGE_REG_IFACE; + sync_global_to_guest(vm, stage); + + test_validate_fw_regs(vm, scope); test_fw_regs_before_vm_start(vm); while (!guest_done) { @@ -349,7 +414,7 @@ static void test_run(void) switch (get_ucall(vm, 0, &uc)) { case UCALL_SYNC: - vm = test_guest_stage(vm); + vm = test_guest_stage(vm, scope); break; case UCALL_DONE: guest_done = true; @@ -371,6 +436,8 @@ int main(void) { setbuf(stdout, NULL); - test_run(); + test_run(KVM_REG_ARM_SCOPE_VCPU); + test_run(KVM_REG_ARM_SCOPE_VM); + return 0; }