From patchwork Mon Apr 4 18:21:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oliver Upton X-Patchwork-Id: 12800598 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 7399EC433FE for ; Mon, 4 Apr 2022 18:22:53 +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=ssHatV6mExTlE70diwGNZLg7Pkz4zWwPhaO9GcOilro=; b=eK8EN+Zy9BlcsaH46qOdOfexh/ GUC3rcpjU9BvqczQaKjfFHZXW5buN7YPVuzswpzF/rkOidwazlS5Uqxv3QRQmvg/x42RZQkSl2B6Z y44qJcdLQaN7LOtJH94+VCY8+z1Ulsp0qV02ojaVznUgUkErKkUpckECDkqqGuNmbOYz+uQYAyn86 DfaI3mG2q/WD/+tm8VrRmkT/jFELF51sNMk2bXpD2w58ZHPLx65R/7pEpy9Z9M8kjVALDsCf8PAWs 6wbP9w/lF9I36hvjlmK0UACkc71RHKzyD79qubZ8W7sIHiDHmL9iQSQ1MEmKkSL4uShQz8j9BFZPw bpt9PELA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nbRKv-00G7Fd-T1; Mon, 04 Apr 2022 18:21:58 +0000 Received: from mail-yw1-x1149.google.com ([2607:f8b0:4864:20::1149]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nbRKX-00G7B5-4B for linux-arm-kernel@lists.infradead.org; Mon, 04 Apr 2022 18:21:34 +0000 Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-2eb7d137101so18678637b3.12 for ; Mon, 04 Apr 2022 11:21:31 -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=uRmXUJJ9UlZ6s6G2CwiIknxpFh1oZyxCOBIJvLxa8r4=; b=pD4+208dXd+MuHbyfJYWyePRJiEoaz4qSgQF8/hxMsKV0Z77tFRwC9sUU2JZ74zbJN Nlx5Axiw++PDyBNl2HV3VZvug6drX2xzxJfLCeMbpi2IVdhGJTyKXQYDIlOUkOJDaG/U iepheGb2k8zTo54D5xJ4g1d40r92qSQZajd6inFsq2CyMqBwM0sBRQghFW0OCXgcjDEC SR3U2crly/QNYAVdd/EEvyop1nywh9D3m92nz/i8+U1+woMZ9ZvSk5oMGmsLxa/V1Udx TxlfQuZhwK3T9hIAV4TsTqwqva87iJ2lYmlpt23OOpbQJY2u9rHr3uEOleyMUM1aY8I5 5Fsg== 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=uRmXUJJ9UlZ6s6G2CwiIknxpFh1oZyxCOBIJvLxa8r4=; b=GSn9Ro08EHD4yZQ0JH4bX8SoSqF9ed4L4hPMw2qz8wjLR6Ghlp1FNXL2GboJAoHcQn ZcRfNqpdLRulBIRmd6/RJoprRGsQDnSQ4ME+GG5uhZ3pLn7J2wbBNckYfb4h58y0kSsj 81Hzr6ey794m07cVvZhrcZDp0NZzxkoM8Q+qxZO09d++bSjMy2jAJPBfCo+1mUeaXL83 gMWj8WKPIdNZp8CrULsfiUxBXdQ4Ac2qiViohxwGB1vG5xaxBOjdsXg+2UFHXiJe4kCh gQCT3FZenJANlFeyWd7qLfAIXSmppvRx5w/XFqIaTAI73WJF3xaxjnskK6edlnIgb8vS wQqw== X-Gm-Message-State: AOAM532ssl12E6dvRHVTyDgXbSixbeiMN7ZD4cCA2LCA9o+r8ZbHUt+1 WLD6vh3EakqXzSGrD2k8tulAhsu4kvY= X-Google-Smtp-Source: ABdhPJyae0iAnZ5vVEgpMLzFzDK8g3K2mXaBfdK4hiobTFKYWjRk2EN5sWj512nGNHMjsWgcvI/z556o6Kc= X-Received: from oupton.c.googlers.com ([fda3:e722:ac3:cc00:2b:ff92:c0a8:404]) (user=oupton job=sendgmr) by 2002:a05:6902:1082:b0:63e:145c:dc55 with SMTP id v2-20020a056902108200b0063e145cdc55mr805811ybu.283.1649096491105; Mon, 04 Apr 2022 11:21:31 -0700 (PDT) Date: Mon, 4 Apr 2022 18:21:19 +0000 In-Reply-To: <20220404182119.3561025-1-oupton@google.com> Message-Id: <20220404182119.3561025-4-oupton@google.com> Mime-Version: 1.0 References: <20220404182119.3561025-1-oupton@google.com> X-Mailer: git-send-email 2.35.1.1094.g7c7d902a7c-goog Subject: [PATCH v2 3/3] selftests: KVM: Free the GIC FD when cleaning up in arch_timer From: Oliver Upton To: kvmarm@lists.cs.columbia.edu Cc: kvm@vger.kernel.org, Marc Zyngier , James Morse , Alexandru Elisei , Suzuki K Poulose , linux-arm-kernel@lists.infradead.org, Peter Shier , Ricardo Koller , Reiji Watanabe , Paolo Bonzini , Sean Christopherson , Oliver Upton X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220404_112133_216935_2EA70FA9 X-CRM114-Status: GOOD ( 12.63 ) 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 In order to correctly destroy a VM, all references to the VM must be freed. The arch_timer selftest creates a VGIC for the guest, which itself holds a reference to the VM. Close the GIC FD when cleaning up a VM. Signed-off-by: Oliver Upton --- tools/testing/selftests/kvm/aarch64/arch_timer.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/tools/testing/selftests/kvm/aarch64/arch_timer.c b/tools/testing/selftests/kvm/aarch64/arch_timer.c index b08d30bf71c5..3b940a101bc0 100644 --- a/tools/testing/selftests/kvm/aarch64/arch_timer.c +++ b/tools/testing/selftests/kvm/aarch64/arch_timer.c @@ -362,11 +362,12 @@ static void test_init_timer_irq(struct kvm_vm *vm) pr_debug("ptimer_irq: %d; vtimer_irq: %d\n", ptimer_irq, vtimer_irq); } +static int gic_fd; + static struct kvm_vm *test_vm_create(void) { struct kvm_vm *vm; unsigned int i; - int ret; int nr_vcpus = test_args.nr_vcpus; vm = vm_create_default_with_vcpus(nr_vcpus, 0, 0, guest_code, NULL); @@ -383,8 +384,8 @@ static struct kvm_vm *test_vm_create(void) ucall_init(vm, NULL); test_init_timer_irq(vm); - ret = vgic_v3_setup(vm, nr_vcpus, 64, GICD_BASE_GPA, GICR_BASE_GPA); - if (ret < 0) { + gic_fd = vgic_v3_setup(vm, nr_vcpus, 64, GICD_BASE_GPA, GICR_BASE_GPA); + if (gic_fd < 0) { print_skip("Failed to create vgic-v3"); exit(KSFT_SKIP); } @@ -395,6 +396,12 @@ static struct kvm_vm *test_vm_create(void) return vm; } +static void test_vm_cleanup(struct kvm_vm *vm) +{ + close(gic_fd); + kvm_vm_free(vm); +} + static void test_print_help(char *name) { pr_info("Usage: %s [-h] [-n nr_vcpus] [-i iterations] [-p timer_period_ms]\n", @@ -478,7 +485,7 @@ int main(int argc, char *argv[]) vm = test_vm_create(); test_run(vm); - kvm_vm_free(vm); + test_vm_cleanup(vm); return 0; }