From patchwork Wed Apr 6 23:56:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oliver Upton X-Patchwork-Id: 12804255 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 67525C433EF for ; Wed, 6 Apr 2022 23:57:47 +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=ND9X1LUz4xOikhC2QQlmlfERH8PPrd17FwD9iAx2FDw=; b=pJboXeGmMVT4d/hQOW8K83nm7u KRHwMy8RRiUz89sNGFjB3eRx9QbaqfIN04FXSUtOAHfjRqioubghDbBfpSo1q5+sqlXWljV8k3EDi z87BBqXrUIbvCL5eZ2zfigQXEsOXVDwaIxpNDKLs30vtzbMWGu9Vgu27aCSpTtCvPprSXkAlMvNS4 PFHqM/YdA6Gwz/5BT6R2GXLX2gmiMHsroeHUjiLbgajDxS78X6bb0QJYL/va3orCiPumygUkL5gBE 7qAMJFfgeAPrbx5pSiInNCfy0YU9dr80JOkxAsFva5/ABchXa6wOs6MgCUe45WohR6dk2gD9GXsok 7TIShNKA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1ncFVq-008L4I-Ty; Wed, 06 Apr 2022 23:56:35 +0000 Received: from mail-yb1-xb4a.google.com ([2607:f8b0:4864:20::b4a]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1ncFVh-008L1J-P7 for linux-arm-kernel@lists.infradead.org; Wed, 06 Apr 2022 23:56:27 +0000 Received: by mail-yb1-xb4a.google.com with SMTP id r134-20020a25768c000000b0063d13119f84so2937144ybc.16 for ; Wed, 06 Apr 2022 16:56:24 -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=UE8U10PWA5ODRXn2/uykVggaoFMEeuBNkjbyKzrUnCc=; b=StweytVoVyZbt90ESUuB2VGZmpz69UiQywLFR+/3fhQYHNUTdQZloEgP4cirg0Kkhd ureLULbzCXKzEuVeyccV7zNNedLEQpO4ayhcybXsVmgxDbgKCBrnsMt4KcoGFXliCiDL p0yS3x603eqH2cuF0Jfgeumy6ZZXE4/Odao00WPCwWYzuYVheUOvU/y7PhYbkklz5J8P spP+ZBEnX4drhVit+1wCy6T9N9UoRJEFMu/pj0F3D0FqfNpLHeAMKkavfelwlloXm8Ki mtOpj9fHSSXtZbEZUujQ5kBOBV5TtTSNk278FllAny6hV6Rytjamf7Z1WSwRNnqUdxFb gBaA== 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=UE8U10PWA5ODRXn2/uykVggaoFMEeuBNkjbyKzrUnCc=; b=drg7ey/6xgqU1KxE3acTknjdqZRh1pWgJ3IF7nN99Wr/GoI8w4NrRviAvk0ur8tYIz +r/0EPzgAfi8hFtg8qK5uXk4AXqzw5AME0W91D15vaF9mFjlMTqWjgQpi7uitpCFF1WX g2ryBAQbok4eGivcn1ualzCFuBdsYlUwzjAQSHfWpJtjpuJixOgQ0BDQ2rSQGpHtM6r4 s+bY75D7x5Jo/ET8tBLY+naoS0iOQkBpiyjqWnwE4QZ8esP0rQBPr3mXl4FnAmoBF6XI rAuMM9dB16aFGosZCnNwZz+GFaVPFmcOLKvKC19CpFQnS6AAZSX03jvv0/hbmF2w21kJ y8/w== X-Gm-Message-State: AOAM532LulNlk4m2e9v/7lmClHICyRAriixsGzKqYepx+uWGlaBNqAjc Qzokn1obFyQzwo6Tx9jc08n6XtNKBJM= X-Google-Smtp-Source: ABdhPJydvJQ9YWsazIPz0K7K9LDxhja6MJh+d1QgvhsxpSx1I3YpvuashAMC5XHLhA33/FRzcSzrmPBE1A8= X-Received: from oupton.c.googlers.com ([fda3:e722:ac3:cc00:2b:ff92:c0a8:404]) (user=oupton job=sendgmr) by 2002:a05:6902:100e:b0:637:7536:6582 with SMTP id w14-20020a056902100e00b0063775366582mr8357978ybt.355.1649289383593; Wed, 06 Apr 2022 16:56:23 -0700 (PDT) Date: Wed, 6 Apr 2022 23:56:13 +0000 In-Reply-To: <20220406235615.1447180-1-oupton@google.com> Message-Id: <20220406235615.1447180-2-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 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-20220406_165625_853944_505A7919 X-CRM114-Status: GOOD ( 18.22 ) 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..e39a6f56fc47 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 Wed Apr 6 23:56:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oliver Upton X-Patchwork-Id: 12804257 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 20153C433EF 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=Tsm9oAJRfTGhObb0p70txFJxKDxvDm5/yFyJSRHwihk=; b=CAttldFf+yelARb1xtwJh/QR0v DJGi33k/Kb+JgVca1OqK+Mrle6SY7SvUeRZU435fPQAMmcoV2uS4HV96qcLd1h2g65ZYgO6oI3H1p ka/YfJ/AbyAcrW14OI8QcWSIHmVi6CkBRhf+0MQa35iaCk/zAiNyAWty2SZHLSBZ4kAWWuKkflF6d ewNDlHJF18ZTPG4Ek9vGXsBoboiVfv+wzptGOHWLyNZITH5DyCcTZOkIVXXB912bMMo8gGurWNAQQ arcqCfyR5tPWpoW1sK3BudAdUE/PV12c0w1/8UDCDquNWUewCuCKMmo0mwJJdIP6+Fxi969pQDccW TlnaV29Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1ncFVz-008L7K-O0; Wed, 06 Apr 2022 23:56:43 +0000 Received: from mail-il1-x149.google.com ([2607:f8b0:4864:20::149]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1ncFVi-008L1W-Nn for linux-arm-kernel@lists.infradead.org; Wed, 06 Apr 2022 23:56:28 +0000 Received: by mail-il1-x149.google.com with SMTP id l8-20020a056e020dc800b002ca4c433357so2711762ilj.23 for ; Wed, 06 Apr 2022 16:56:25 -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=CxQm71obckQx1ot8ttP2ziACqWcKGK4akKG1COLV+bQWzBRg9Azn3q2fUw6u0mZ4La mlTSehKe88RUN3Cqari2K1UKweOzh7gRY7rvke0Sxra/LR5yabTeWR3pb6gABgpAiFbh 3LDUmHjknj3TOpwWLKKUTTr8xa2BRA6ZKHLZWppjCqiXKxKE/+315ZNXsiA0KQ1Himyk YBv93Eof/Lgya4aIH5+cvdaqrqFkT48ZnEXupNIiuuliGu6MX1nMotBFktHb532z7a6I 14qW8I7whAReD61AEBQsI04P7UtTOM97tMAbHs6qs1AgQwe85gA4jCx8P8vj1JGqCJWd 63PQ== 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=2zJAx5R+434HqOh4PdkdYizq/FV9JAweaZo4CHbnqIBIi5fUK/zhDFCFam3Tjywsqn off6t2i2mwyE9ZyT7xkI1r8fhllTchgz8JDH41AYhyQw2VB/rAB9voZ3dJCXbBCBuUNU LDzqt7j0ZbxJG781HZ/HimmlxwFW3X7WtHFyV0RZ3TnEe4NocGi4OmfI/AKQqAuI1qyh 6w5YgzuvmyPptoCYawca9PJ7Knz+nR0baegYW7YLuBWR1QODY891x0mqi02Dk9c4yskw 2xnpiWNHLAGt1BljJt9WLdq0iacm1wzKUZ9EwOTynBRd+0RQybDw4vltgBq9rN69qVav ewOQ== X-Gm-Message-State: AOAM533oPavSz/kb3gEXcOISXS22N4jthVN9H1QUW7YtKZrUkxeblpFx eNbrNJG4cXn+//TRyj/i1jEUHWr+xro= X-Google-Smtp-Source: ABdhPJxZYhapYayA71PbkdV1563SUH1JsWUENhomJcQekruoJ8CSaLV4CpWvvqb90+EKwQyAk2ignByhlAY= X-Received: from oupton.c.googlers.com ([fda3:e722:ac3:cc00:2b:ff92:c0a8:404]) (user=oupton job=sendgmr) by 2002:a92:7513:0:b0:2b9:5b61:e376 with SMTP id q19-20020a927513000000b002b95b61e376mr5694259ilc.193.1649289384698; Wed, 06 Apr 2022 16:56:24 -0700 (PDT) Date: Wed, 6 Apr 2022 23:56:14 +0000 In-Reply-To: <20220406235615.1447180-1-oupton@google.com> Message-Id: <20220406235615.1447180-3-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 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-20220406_165626_819774_CD47C266 X-CRM114-Status: GOOD ( 15.97 ) 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 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; }