From patchwork Sat Apr 2 17:40:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oliver Upton X-Patchwork-Id: 12799393 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 C5216C433F5 for ; Sat, 2 Apr 2022 17:42:29 +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=ns7YNEDDWXhWA+lP/2FVDbB34J TgAs4Jbc26LNdnEz2ykx7Cm163+ExI5mBj6Ii7iCanL8iT0qxMSge96MGKoFS/brI17r8gPbp7H5V sTqW6a1Ob9pIBV5jCYuGeq8LoGVi/RBXHclFQzaztj+lumBWfh7PgrJNYiDk5kzai3WFMwEKhmM3A r39TAak9JI9VqpZmNm/vV7OcgqGCmxPTzb0wmKpUTfWMVJUgFDkF/VHAF8Mgr96VBA8tO0AsTwdBD kib5cPKp5jBvmc0W8MxhgZIpPtUJthH7s9KisiWpKRauo+ezHjzPpzak2BZXiRy/aYnBL6pf6h7NA 6FXTAylA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nahke-009jmF-JH; Sat, 02 Apr 2022 17:41:28 +0000 Received: from mail-io1-xd4a.google.com ([2607:f8b0:4864:20::d4a]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nahk5-009ja0-Qi for linux-arm-kernel@lists.infradead.org; Sat, 02 Apr 2022 17:40:55 +0000 Received: by mail-io1-xd4a.google.com with SMTP id g16-20020a05660226d000b00638d8e1828bso3613713ioo.13 for ; Sat, 02 Apr 2022 10:40:53 -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=pRdr/FNL4DJ4+FDZfYXkJBtQDCsAq7uj4Emtow3IUaukx62QJi2YKu7pn/kogEODph Y+Ut0ZuenWviBdtaf3uK2ywut5KwfSCOLvuj4E4oRTQycEzaxb0DzPh8RMPK+LNVr1U9 BeWnTU5Vzf7eMYH9M9yl+lnM/35IO89F+KiuVVUfxbFmL7DCH09Jixfk7rVjhOmUP+j6 a/towLy19ro+gsEvXWFYQ/JDk+Ch7sQoSUNbTLyRyCqqiA9WSF46VI49YlqOoWC3xzcx XazJkCyLa9KKCF8rswY5B8VWHE3+GnUCNK6RnnP18kj5JH5MFdP1r61Sm0hEYI+A6ayv 064w== 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=eVXU1f9PygqVgByzSXZEBwQ0S5cSuZ4bqXQ7xZB2WKvmeF35txCoEu4E88zPLQM09h VllxrWOG5FdmAFtr66jFQGmCZlyJleSggY2G/A/FPbO130WUO7upozduebsY2d/sF6uk YssoLuVYVdzv4hXDr06C1kysFk/Ida9W1TDAJyF+I6Tm/7bt1PfF2iV9iNm7LESFA8Pg ouXFW0wTywAL0jW5JDSITf3UpRUiBdFKMw31KVxCqlvHns/FZ/yD3xDsSxKrYqpViDYN vsPkFtLD91t0nQFeYxZ2gujTSGZ2CrNSHbpf4kVHAyusgyHcgUCZ/cH4HVwegX2BnKWa OcAA== X-Gm-Message-State: AOAM531n1aj6zd2BrFe12UdgrC9psfHTzmEwg8na2op+z2kX2Co+0u99 ic9/FvAoL/DYh1/7DAYDUwntOGDdcv0= X-Google-Smtp-Source: ABdhPJxfhOuV+H0OWvhKyqVH+yGUG1Gyfq61aVtKlvvdZjUHlwISHe0FlEzqyL1csiERacH6j/kPsSDcnBY= X-Received: from oupton.c.googlers.com ([fda3:e722:ac3:cc00:2b:ff92:c0a8:404]) (user=oupton job=sendgmr) by 2002:a6b:8d8b:0:b0:645:eb9e:6765 with SMTP id p133-20020a6b8d8b000000b00645eb9e6765mr2056322iod.215.1648921252570; Sat, 02 Apr 2022 10:40:52 -0700 (PDT) Date: Sat, 2 Apr 2022 17:40:44 +0000 In-Reply-To: <20220402174044.2263418-1-oupton@google.com> Message-Id: <20220402174044.2263418-5-oupton@google.com> Mime-Version: 1.0 References: <20220402174044.2263418-1-oupton@google.com> X-Mailer: git-send-email 2.35.1.1094.g7c7d902a7c-goog Subject: [PATCH 4/4] 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-20220402_104053_922963_E2E2399F X-CRM114-Status: GOOD ( 11.88 ) 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; }