From patchwork Wed Apr 6 23:56:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oliver Upton X-Patchwork-Id: 12804258 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 276D1C433FE for ; Wed, 6 Apr 2022 23:57:54 +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=xBXeYePoxgYNItK0oHG5GP3gS8 SRWhvxgb380mrN9bNJPe7CwIsa+hzk6b5yv5KDziiix4HbSD+oQSwYbiQXllURqVp7iTAxbXIVDOV /Isv/V/xZNxre2am4gm0vnYGRJWJSXR6z9Iv5kyam9RjNrmLzsKkzqCT9BDUc4KP1mB/YkMoA6v+Z hfZ7OjPKcBLkYA2FIwDe6pBIg6I/RHZEeNi+rU1SdiafRmsdc9wihnzWmHs1vsJM/xVaGNaKpjR3X gLg/iLU4ds0PCGpRCRy5MzGtQTFXDTzVHS27gQQ+kGDSuCnHzGnVRy+f6MrDmmgS3pRUItBTwwYGn cZNM2A2w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1ncFW8-008L8U-20; Wed, 06 Apr 2022 23:56:52 +0000 Received: from mail-il1-x14a.google.com ([2607:f8b0:4864:20::14a]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1ncFVj-008L1o-Mo for linux-arm-kernel@lists.infradead.org; Wed, 06 Apr 2022 23:56:29 +0000 Received: by mail-il1-x14a.google.com with SMTP id q6-20020a056e0215c600b002c2c4091914so2742156ilu.14 for ; Wed, 06 Apr 2022 16:56:26 -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=SzJkCsZV7iMptbeHI6SunPJiVnXUQJsGsvB3EBMHTQhojiWMdyE3B/pfzOPMhedu0u OmjdVa4Lek6+jecHKQATT9mNii32Oo1kFhrG4QCstEBMVPNiL24y7OBfjRPA9wUhdRbA TAeB+mX1bc+TzRM6ne/WhlZq4XBLaHRKGejrM8I2ujdW/m8+EoB42jAXHLzGSV6cQQ+s riOWVn4yLnlNd/SyoucnJAS05H14Mk9xZheCP9DQVf8ivm5s8/I2K3POTNfZgmfxpJb9 IbOTnSOlGW76Kk118l5vziFY9iX3OH4rZkouN2yrL80iW8lU17cmw4IdwL/McIe4gmIi UcFw== 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=Rbrvw71XW/ozAtYttrdkf0mKuQTMXmNtpmru0oIZbWZoo8ggOP0nAkVgjP9cBnLCPo 4DqsdHHPoKnROT0WLpuYmHn8pOqKC0tELvLgfHNOKfYeWSJfAH6d+JGow3FPQgzXynnU 121/TFkuKQtEuGtyh299nFDO23IO7VkD+sH30ndOcBNBgeeJ/YPXLPKVn5Nu6HrIV9f9 7wNohWYaF6p7FcLpLfC40b9E+ReuJaW6OayBG9l5KaSoM21e7vMJTdtGdLh9BL2aqzHq LOpxzTFzEp6i/7nje+OlRwZZQB3okDzxwDFVMgZxZOPUVIx2f9RLSndox12uXKNHpGKI CFOw== X-Gm-Message-State: AOAM531O2EUlQXSjKt2vktMZnHKJkwJy5XN+BzeZFCaKbib0jR8tmjcz FR2+JoTU9eiucUKdkXROG00Clrmm04c= X-Google-Smtp-Source: ABdhPJzGNrYJp2IFGjhmrFmxuYB89kWWkYo6WwdyQZ1lPeVi+kRKHzYARL8aZVq18I7pX0Q/UZ3gqbn08tg= X-Received: from oupton.c.googlers.com ([fda3:e722:ac3:cc00:2b:ff92:c0a8:404]) (user=oupton job=sendgmr) by 2002:a05:6e02:5af:b0:2ca:396f:9d with SMTP id k15-20020a056e0205af00b002ca396f009dmr5221608ils.216.1649289385863; Wed, 06 Apr 2022 16:56:25 -0700 (PDT) Date: Wed, 6 Apr 2022 23:56:15 +0000 In-Reply-To: <20220406235615.1447180-1-oupton@google.com> Message-Id: <20220406235615.1447180-4-oupton@google.com> Mime-Version: 1.0 References: <20220406235615.1447180-1-oupton@google.com> X-Mailer: git-send-email 2.35.1.1094.g7c7d902a7c-goog Subject: [PATCH v3 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-20220406_165627_781004_A83EEC00 X-CRM114-Status: GOOD ( 12.10 ) 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; }