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); }