From patchwork Mon Apr 4 18:21:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oliver Upton X-Patchwork-Id: 12800595 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 5F0B9C433F5 for ; Mon, 4 Apr 2022 18:22:39 +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=24lmrx7P5JCYjfKZzb4wcLnOrgl1ORkD4VmlQs34iLo=; b=e+p7pSmVPGr3vT+7PXiJwafM7e 0eb849z3y4Y7pe2Lp8mXGyE9jt8HHoZZmd9XGMyTU4aACiQxPXiVN0bi31fMHHGZsfbqNDuDeJfu0 WwZeyPoxGtPBoqvN1LFdy1eKSRDh+3Z/E2FhNHW5YTgszxtCq2U1zaNvKmet/dmGzOqrHhAOgrBd2 MtosTB9at53k0a0BJ8CcJ18nsispZs1OVEm9xmZgbU5VPKi4G2ylkxilBZgkhxrPvKKoNcmlY7p+z dTpYDT4GOly7vJIAQSvMZEyDqCluAJtSd/RSJxD4RfphExX6kIjg9RMWRZHj9a+/8x0+dE+eIQeug M6GJcNVA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nbRKe-00G7CO-TB; Mon, 04 Apr 2022 18:21:41 +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 1nbRKU-00G7AS-GV for linux-arm-kernel@lists.infradead.org; Mon, 04 Apr 2022 18:21:31 +0000 Received: by mail-il1-x14a.google.com with SMTP id x6-20020a923006000000b002bea39c3974so6617031ile.12 for ; Mon, 04 Apr 2022 11:21:29 -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=9C6w1rezdQTRbXbtrJY1SOnX+wuE5x8FHrvORNXkiH4=; b=ntCvfuIdi9xMnMJP+WEKYAhtFIzNV0vgJkusexYCHVXmFsHxjRL0ss7NhSk+fRH55U IOVUf2f/dRvRvNUW8QStwvlNrurraZnMphm1VQ5851zbUGzrqT8d4cFxbhOP8vn/G+8w fYDJB9Rxyhu+dtkt733HYqDqzN0cNBBuG/RDzaBHjtz1lf8He19cAQunaA+tgo0ZkWqj nHmF5lg/twg67wMwdeQKzJW2OZCiSL+/Gp9K+7ik47gg7kTJlOLrCUwmO42RVRKax3/6 WKnNSA2mnNTHeyQVF4+axB8WRxkGTfeRQFfs7yonAUtqLzbwxah4SnDga35oAG2BGmbE 8fKQ== 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=9C6w1rezdQTRbXbtrJY1SOnX+wuE5x8FHrvORNXkiH4=; b=IdmjMBQVBKRCvyPCWtPcsd3koSHlBn5zR4jWmg7FnJpS6kaLZ0VTn+DaUcZRcIHX6C zhIbiPAIpV4tVfcpkHj83EXMnU1CQQRwCLJYf1XJY5Qvgcz6Lu9SHf4u4xoT0+GMudbv if2FqnIcKBFRrvb8z/98c9JcUJSOC45/O1Q6RYkoRbH65mwgEfbuIE910FmzADAC0KWr Xt1vAGqRg5VyR/YOowU99VsY3F66ieC1ZU/fKsxCvNnOp1pJuXdTCW3e43BUy+PfAEsU I9diYTQmC/g6xVGsx6MwO94gE9ABxXQmkcUUzeaxv9DwBPUg1ymJf4sIJSNy9caha/4c lq2A== X-Gm-Message-State: AOAM530kZQaxzQUDgE+rOQnb5qziYS57t1qNMxvLbcRQc9AmYpcZzag9 bnlX0Rjg1OxtffxyzdILk8LQC4RqMe0= X-Google-Smtp-Source: ABdhPJw742AYzEqFaE6euki5t9MMfZCGGI9PjjeQy1BTQ6eXyn3wAYraEjyHb6JW9iO7D2ml2hNsob2+TpA= X-Received: from oupton.c.googlers.com ([fda3:e722:ac3:cc00:2b:ff92:c0a8:404]) (user=oupton job=sendgmr) by 2002:a05:6e02:17ca:b0:2ca:42d8:81d with SMTP id z10-20020a056e0217ca00b002ca42d8081dmr510403ilu.249.1649096488828; Mon, 04 Apr 2022 11:21:28 -0700 (PDT) Date: Mon, 4 Apr 2022 18:21:17 +0000 In-Reply-To: <20220404182119.3561025-1-oupton@google.com> Message-Id: <20220404182119.3561025-2-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 1/3] KVM: Don't create VM debugfs files outside of the VM directory 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 , stable@kernel.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220404_112130_584217_10EE53E6 X-CRM114-Status: GOOD ( 18.65 ) 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 Unfortunately, there is no guarantee that KVM was able to instantiate a debugfs directory for a particular VM. To that end, KVM shouldn't even attempt to create new debugfs files in this case. If the specified parent dentry is NULL, debugfs_create_file() will instantiate files at the root of debugfs. For arm64, it is possible to create the vgic-state file outside of a VM directory, the file is not cleaned up when a VM is destroyed. Nonetheless, the corresponding struct kvm is freed when the VM is destroyed. Nip the problem in the bud for all possible errant debugfs file creations by initializing kvm->debugfs_dentry to -ENOENT. In so doing, debugfs_create_file() will fail instead of creating the file in the root directory. Cc: stable@kernel.org Fixes: 929f45e32499 ("kvm: no need to check return value of debugfs_create functions") Signed-off-by: Oliver Upton --- virt/kvm/kvm_main.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index 70e05af5ebea..04a426e65cb8 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -932,7 +932,7 @@ static void kvm_destroy_vm_debugfs(struct kvm *kvm) int kvm_debugfs_num_entries = kvm_vm_stats_header.num_desc + kvm_vcpu_stats_header.num_desc; - if (!kvm->debugfs_dentry) + if (!IS_ERR(kvm->debugfs_dentry)) return; debugfs_remove_recursive(kvm->debugfs_dentry); @@ -955,6 +955,12 @@ static int kvm_create_vm_debugfs(struct kvm *kvm, int fd) int kvm_debugfs_num_entries = kvm_vm_stats_header.num_desc + kvm_vcpu_stats_header.num_desc; + /* + * Force subsequent debugfs file creations to fail if the VM directory + * is not created. + */ + kvm->debugfs_dentry = ERR_PTR(-ENOENT); + if (!debugfs_initialized()) return 0; @@ -5479,7 +5485,7 @@ static void kvm_uevent_notify_change(unsigned int type, struct kvm *kvm) } add_uevent_var(env, "PID=%d", kvm->userspace_pid); - if (kvm->debugfs_dentry) { + if (!IS_ERR(kvm->debugfs_dentry)) { char *tmp, *p = kmalloc(PATH_MAX, GFP_KERNEL_ACCOUNT); if (p) { From patchwork Mon Apr 4 18:21:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oliver Upton X-Patchwork-Id: 12800597 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 6EBF8C433F5 for ; Mon, 4 Apr 2022 18:22:51 +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=Tsm9oAJRfTGhObb0p70txFJxKDxvDm5/yFyJSRHwihk=; b=3W7FjqhlxkHkP1jyz3IZhMZHxW LkFM2+wt5ZZMJU8O4Lu5k1MQSzoHfvGx4/ojGh8Oj6+jU+Js5/NOu/O0ywuaSGRuv7hyLYkIcf1U+ 8kk++hmGK00UW2YcAMo1r67PxmBBkvFU6urYmnlUdQC7u5Bmc1ry2a1WZ7xjp2fmITd2s6FJ8AEla +95ji7dyvi1IDh4ZPcT/H+eAhOEke6XbLkbx+dz5fUl0Id9GhCxanBQVW8OrrUJ3V3ikbLvSdvTD9 bZ6Jqx2Pa3qVCK9VcTTbRMgp73uXdTztJKN/YV1pCo4C4Ld5jvrq1R0ZpW6Y0XoJs6Al90qTTNh6H 1KuqWOBA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nbRKn-00G7DR-DK; Mon, 04 Apr 2022 18:21:49 +0000 Received: from mail-io1-xd49.google.com ([2607:f8b0:4864:20::d49]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nbRKV-00G7Am-Od for linux-arm-kernel@lists.infradead.org; Mon, 04 Apr 2022 18:21:33 +0000 Received: by mail-io1-xd49.google.com with SMTP id h14-20020a05660208ce00b00645c339411bso6837824ioz.8 for ; Mon, 04 Apr 2022 11:21:30 -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=UF2I2mHbDVASrG05DEItZfczKpOZthJZ1m0MB3YjXVY=; b=tcxC71n8qRIQtoplY54rvL/t1PM0vquhFBE/lAZhF7XYLojblaLlklu7pRZ9UPnz2y 1DCwD3eahwdyYR2x+Ew8gFONkQgrmXFyMrYjaAedHmdyKQpBNUDi7wvucA2nf0RRP4yj 8OjE3G6p/9MKRMB/fxfL3GKqq53KeK6h/oL30r8siKj45GroFMnBACt2kw/jhcfQdX1P 974RrKtOT0HPojjuNUxVR1SbbTgex41Y1OzCalE1p4ke0cTnIXpM+TDnXprsmKu77tq2 TagfXw6GPklrVI7x9HWxjeG8KMzXtBHH0KsZRB90fzH0AifnWI5EC/CBe2S2gKzQjerQ GO9A== 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=UF2I2mHbDVASrG05DEItZfczKpOZthJZ1m0MB3YjXVY=; b=Tm/8ar6trSK43BQfdR4HpQfl5V8UCBaSGQcaN6Q8oNh4wuhfPTLiY2iPSvNZOjYOPe xIsmIWDUHJoyFX8+V64m54qb94glnIMB72/kDTY8yTlQPVrP5+ZR4Pn9OFpCtL1oIjEZ 8VWTSdGm34An94GMjLB8o/In+0/qx3yf9rGthDn09ZjpOo/0ZQUy5njhoSZ02vq3vEjd TW4dTP0j1tmm3C9WuurSPlYEo2ZbdA/KMFl9YcbwiuxW43ZbVklMxuThQ9YKnDE3pHT8 uiwmfjzm7RvwB5L8KzKTsFIzJF2SXiUgLcOmSIDg727TVmOFgAt0ozdyrQeQIfQr/m+n CKHg== X-Gm-Message-State: AOAM531orI6u21KPAGTxnxWd3AiZF4yKyh3JuBye5y875wbmlkZZ2V8G poT3MKw2U6D8d5B7hLG+ybGWY3f39yA= X-Google-Smtp-Source: ABdhPJxMtg0K6INoCkIU+22+KIhOsbvZj/wp5fDFQBYNYjykIapUx1/xqAWiebo8OINm+4A3zMI6PtlF6Z0= X-Received: from oupton.c.googlers.com ([fda3:e722:ac3:cc00:2b:ff92:c0a8:404]) (user=oupton job=sendgmr) by 2002:a5d:81d4:0:b0:649:ac07:27b with SMTP id t20-20020a5d81d4000000b00649ac07027bmr688893iol.216.1649096490046; Mon, 04 Apr 2022 11:21:30 -0700 (PDT) Date: Mon, 4 Apr 2022 18:21:18 +0000 In-Reply-To: <20220404182119.3561025-1-oupton@google.com> Message-Id: <20220404182119.3561025-3-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 2/3] selftests: KVM: Don't leak GIC FD across dirty log test iterations 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 , Jing Zhang X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220404_112131_879076_28A7AD48 X-CRM114-Status: GOOD ( 16.40 ) 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 dirty_log_perf_test instantiates a VGICv3 for the guest (if supported by hardware) to reduce the overhead of guest exits. However, the test does not actually close the GIC fd when cleaning up the VM between test iterations, meaning that the VM is never actually destroyed in the kernel. While this is generally a bad idea, the bug was detected from the kernel spewing about duplicate debugfs entries as subsequent VMs happen to reuse the same FD even though the debugfs directory is still present. Abstract away the notion of setup/cleanup of the GIC FD from the test by creating arch-specific helpers for test setup/cleanup. Close the GIC FD on VM cleanup and do nothing for the other architectures. Fixes: c340f7899af6 ("KVM: selftests: Add vgic initialization for dirty log perf test for ARM") Reviewed-by: Jing Zhang Signed-off-by: Oliver Upton --- .../selftests/kvm/dirty_log_perf_test.c | 34 +++++++++++++++++-- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/tools/testing/selftests/kvm/dirty_log_perf_test.c b/tools/testing/selftests/kvm/dirty_log_perf_test.c index c9d9e513ca04..7b47ae4f952e 100644 --- a/tools/testing/selftests/kvm/dirty_log_perf_test.c +++ b/tools/testing/selftests/kvm/dirty_log_perf_test.c @@ -18,11 +18,40 @@ #include "test_util.h" #include "perf_test_util.h" #include "guest_modes.h" + #ifdef __aarch64__ #include "aarch64/vgic.h" #define GICD_BASE_GPA 0x8000000ULL #define GICR_BASE_GPA 0x80A0000ULL + +static int gic_fd; + +static void arch_setup_vm(struct kvm_vm *vm, unsigned int nr_vcpus) +{ + /* + * The test can still run even if hardware does not support GICv3, as it + * is only an optimization to reduce guest exits. + */ + gic_fd = vgic_v3_setup(vm, nr_vcpus, 64, GICD_BASE_GPA, GICR_BASE_GPA); +} + +static void arch_cleanup_vm(struct kvm_vm *vm) +{ + if (gic_fd > 0) + close(gic_fd); +} + +#else /* __aarch64__ */ + +static void arch_setup_vm(struct kvm_vm *vm, unsigned int nr_vcpus) +{ +} + +static void arch_cleanup_vm(struct kvm_vm *vm) +{ +} + #endif /* How many host loops to run by default (one KVM_GET_DIRTY_LOG for each loop)*/ @@ -206,9 +235,7 @@ static void run_test(enum vm_guest_mode mode, void *arg) vm_enable_cap(vm, &cap); } -#ifdef __aarch64__ - vgic_v3_setup(vm, nr_vcpus, 64, GICD_BASE_GPA, GICR_BASE_GPA); -#endif + arch_setup_vm(vm, nr_vcpus); /* Start the iterations */ iteration = 0; @@ -302,6 +329,7 @@ static void run_test(enum vm_guest_mode mode, void *arg) } free_bitmaps(bitmaps, p->slots); + arch_cleanup_vm(vm); perf_test_destroy_vm(vm); } 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; }