From patchwork Sat Apr 2 17:40:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oliver Upton X-Patchwork-Id: 12799395 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 843CDC433F5 for ; Sat, 2 Apr 2022 17:40:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244279AbiDBRmq (ORCPT ); Sat, 2 Apr 2022 13:42:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59106 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241167AbiDBRmm (ORCPT ); Sat, 2 Apr 2022 13:42:42 -0400 Received: from mail-il1-x14a.google.com (mail-il1-x14a.google.com [IPv6:2607:f8b0:4864:20::14a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1F6F3DFF9 for ; Sat, 2 Apr 2022 10:40:50 -0700 (PDT) Received: by mail-il1-x14a.google.com with SMTP id k5-20020a056e02134500b002c9af0334e2so3732377ilr.11 for ; Sat, 02 Apr 2022 10:40:50 -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=gTC6wbFjulJGpnpdlR2cK65pyxNM9FH8zxgBPKIedMA=; b=IWfMP6PPwTJ7suUb8PtMClWLhu9Q7lmuLZmLxHUiZhB7qG4ONiUnCn55RSteRI6Lj5 WnEriAXO/P4p+M1csdNAB/x8uJiummx6Y0/TAZvBpSRquz7KG9vvI9Z6+/yhFBG80bUu 39n7syXyAT1fsyP29qR+jYISRWRnLync2LwfFqLxLJaprc1qfO6clU6/t+z5WaogkP/5 pF2RgGe/XeZ5vptUf4kb+iPKSZrA25QUiVI1NECCavK79JLnaNP1nDRCJ8PGXkQUIXcp 9MIuPc1dQkdbiiC/Rw1s3I6v/S07jCmPozzTf7mjzKbEIjMM3oXDFA7NbxxInFHCcbGP OarA== 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=gTC6wbFjulJGpnpdlR2cK65pyxNM9FH8zxgBPKIedMA=; b=WJVNkIMlfTlqUrltvXn6y1s/x2qRM1Arv3ks6RTaYDn5K/4PHbpgZbIbE7dBLt+xpU KXme77X9N2uKjSYCnkGheE7CXiIdykEmaMYlMJv/8nhxaB+yDpJuyHbpOLFTxv+g6gZU UFgOgB844l2+zfAYh0HeSK8bMrU4CWjHwz1SX6JhaHpHT1di8egfT0/CWev0YLndar0s GAVUli5jGVLC7FrIucT+EBE8MMzYE439mv9FXgtv/Y/Kw2pWz3LY0dt3fsBjmVNYPclu dSgYVL2VPfHuElCyhsq7jLMZyobzg9z7W17c/BE/ZN6wPahEROiKCzZ9bnxnExNd0VF/ t/MA== X-Gm-Message-State: AOAM533pDUUbjwNhMytBdbqgWXHcZbaNoW2tZphJ1Wrbu/cPs6SgyAwx sBx90h+g7svu8WdnJWP6BLVs6LPel8E= X-Google-Smtp-Source: ABdhPJxh22igukLOyB7xjQIkB7xrRakZ5rtTFEJOHvXCH6QTQaKRf4Vev65C2RCw3Khe1CzIiG7PGVWShMA= X-Received: from oupton.c.googlers.com ([fda3:e722:ac3:cc00:2b:ff92:c0a8:404]) (user=oupton job=sendgmr) by 2002:a92:6810:0:b0:2ca:1ff:e32e with SMTP id d16-20020a926810000000b002ca01ffe32emr2313380ilc.212.1648921249504; Sat, 02 Apr 2022 10:40:49 -0700 (PDT) Date: Sat, 2 Apr 2022 17:40:41 +0000 In-Reply-To: <20220402174044.2263418-1-oupton@google.com> Message-Id: <20220402174044.2263418-2-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 1/4] KVM: arm64: vgic: Don't assume the VM debugfs directory exists 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 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.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. Since 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. Plug the use-after-free by plainly refusing to create vgic-state when KVM fails to create a VM debugfs dir. Cc: stable@kernel.org Fixes: 929f45e32499 ("kvm: no need to check return value of debugfs_create functions") Signed-off-by: Oliver Upton --- arch/arm64/kvm/vgic/vgic-debug.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/arch/arm64/kvm/vgic/vgic-debug.c b/arch/arm64/kvm/vgic/vgic-debug.c index f38c40a76251..cf1364a6fabc 100644 --- a/arch/arm64/kvm/vgic/vgic-debug.c +++ b/arch/arm64/kvm/vgic/vgic-debug.c @@ -271,6 +271,9 @@ DEFINE_SEQ_ATTRIBUTE(vgic_debug); void vgic_debug_init(struct kvm *kvm) { + if (!kvm->debugfs_dentry) + return; + debugfs_create_file("vgic-state", 0444, kvm->debugfs_dentry, kvm, &vgic_debug_fops); } From patchwork Sat Apr 2 17:40:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oliver Upton X-Patchwork-Id: 12799397 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D6196C433FE for ; Sat, 2 Apr 2022 17:40:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244429AbiDBRms (ORCPT ); Sat, 2 Apr 2022 13:42:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59214 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237131AbiDBRmn (ORCPT ); Sat, 2 Apr 2022 13:42:43 -0400 Received: from mail-io1-xd4a.google.com (mail-io1-xd4a.google.com [IPv6:2607:f8b0:4864:20::d4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 398B2DF82 for ; Sat, 2 Apr 2022 10:40:51 -0700 (PDT) Received: by mail-io1-xd4a.google.com with SMTP id b15-20020a05660214cf00b00648a910b964so3599515iow.19 for ; Sat, 02 Apr 2022 10:40:51 -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=EDhTuekQtNdm8MWzZ4rgwl9Zuy6sown5y5t0K60oNeM=; b=B8kXE1B9TLeU0fkKkRjLEwnu0j64XSm51isipBSezaI+aW4AtZHnIwm8TGZj11qhjH fZQIml2v0tbIQEfE+Rdi8YKENmjgZx3JLnbDQpunt+Lhb02W6Vt4aMuEdjjmWuAMIpU/ qpWP9KDaobTe+W3uOxEt+HSwNp7VpmQMyoKm+GSu+CZFLH6hjzjaKFfyU2AcF0kukXvm QDYThdKrd3I540B7S51JbBoxsphYIIH++HAYKwcqXN8Ak3NZOiSQbOk768apsr0G4RTv RVSLI2Pn5gd7HrzXW15CZPCcJCKrOG3MkeCDtxEhDwRuVNo6aCWkbdOKa9xeJ/7BVvad afww== 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=EDhTuekQtNdm8MWzZ4rgwl9Zuy6sown5y5t0K60oNeM=; b=l8/1yluI3PbNXk4EHMUpXiHEahKFa536G1XyTGBK75b0D3fyPHXR1YGbMRAoMJeyae GQorn8pe3wmbwpwqH4j3AudySpq3WwFbDheOlpfN5DoSzBj67hf6wifCLZPGQv2wxSw/ BWMnsKXyl6qhXCaks3+uQ0vOoaeE/2ZRhMUeMerBfMW31ZvhckoteeIPxofwE2/1JvB9 0dmWoJISCdvXeiA1dFxCvc0jV91GM7tqS89ST+VooDOwndh9tTExi0ns717OzReLCanp 2R9Qfw7NJdLe6PZCkPq4fsxDkNVvkllEYXvf4o7OUjT6c5ABp3BfD3YQetpiP+DUfcyZ IPMg== X-Gm-Message-State: AOAM5301fAXtgk8MED6VCymaaEVwivzevJPHwNr1epnqjAExVsY+ruYG tChmKje1481vW0zUE4o33eR/SPORGPQ= X-Google-Smtp-Source: ABdhPJwx6B48zoyhRzOI+UWoY4wiun1eWGRgsGjvJOKksNdUx4f7qTvuv/CNaHpOREGjQo9q8Bk2CyZ29n4= X-Received: from oupton.c.googlers.com ([fda3:e722:ac3:cc00:2b:ff92:c0a8:404]) (user=oupton job=sendgmr) by 2002:a05:6602:2c8b:b0:649:e67c:9202 with SMTP id i11-20020a0566022c8b00b00649e67c9202mr2148843iow.75.1648921250592; Sat, 02 Apr 2022 10:40:50 -0700 (PDT) Date: Sat, 2 Apr 2022 17:40:42 +0000 In-Reply-To: <20220402174044.2263418-1-oupton@google.com> Message-Id: <20220402174044.2263418-3-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 2/4] KVM: Only log about debugfs directory collision once 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 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org In all likelihood, a debugfs directory name collision is the result of a userspace bug. If userspace closes the VM fd without releasing all references to said VM then the debugfs directory is never cleaned. Even a ratelimited print statement can fill up dmesg, making it particularly annoying for the person debugging what exactly went wrong. Furthermore, a userspace that wants to be a nuisance could clog up the logs by deliberately holding a VM reference after closing the VM fd. Dial back logging to print at most once, given that userspace is most likely to blame. Leave the statement in place for the small chance that KVM actually got it wrong. Cc: stable@kernel.org Fixes: 85cd39af14f4 ("KVM: Do not leak memory for duplicate debugfs directories") Signed-off-by: Oliver Upton --- virt/kvm/kvm_main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index 69c318fdff61..38b30bd60f34 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -959,7 +959,7 @@ static int kvm_create_vm_debugfs(struct kvm *kvm, int fd) mutex_lock(&kvm_debugfs_lock); dent = debugfs_lookup(dir_name, kvm_debugfs_dir); if (dent) { - pr_warn_ratelimited("KVM: debugfs: duplicate directory %s\n", dir_name); + pr_warn_once("KVM: debugfs: duplicate directory %s\n", dir_name); dput(dent); mutex_unlock(&kvm_debugfs_lock); return 0; From patchwork Sat Apr 2 17:40:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oliver Upton X-Patchwork-Id: 12799396 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B9077C43219 for ; Sat, 2 Apr 2022 17:40:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244411AbiDBRmq (ORCPT ); Sat, 2 Apr 2022 13:42:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59248 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243941AbiDBRmo (ORCPT ); Sat, 2 Apr 2022 13:42:44 -0400 Received: from mail-il1-x14a.google.com (mail-il1-x14a.google.com [IPv6:2607:f8b0:4864:20::14a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 286F2E095 for ; Sat, 2 Apr 2022 10:40:52 -0700 (PDT) Received: by mail-il1-x14a.google.com with SMTP id o17-20020a92c691000000b002c2c04aebe7so3733615ilg.8 for ; Sat, 02 Apr 2022 10:40:52 -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=LigwUYYC4VhhxtS09KVFjs0sG5saYpBwvbWZHNyydng=; b=NKUIbjH0SKkdci4xkrqxucxb4e10J6YzgfEfrWlPOqo3uYmRUoKeqDouP/VcaTUvyo IBtov8VN/WlMjY1AwlrTF/UlDsXZZhQIup+60SHoXNF+IBnrEq80Jm/xGAPE6FtblLO8 S7FspLtgNxHx0//bc+A+whljvxEEpt6UgvRU4fLs4jyX+w5O1S1NuhIVpg2TKj6f0vB2 vSN32ViMyY0L3YTcACI6hYyldUmccE3BfHkJJoXNav/9Q6QCb7WI7RCLQ1wiPhvL36TZ fM4kSaF2LZOqxDIoXOO1LhhCS324eDYXPaixU4V3ueEMIRLgJBAfcTEA6elYTHEqMW23 f95g== 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=LigwUYYC4VhhxtS09KVFjs0sG5saYpBwvbWZHNyydng=; b=RPDf3qCRfJErNr3pjeMbwFMpFjZD1Rz4ySAaACdEaPLq817WGNRJwwQ/nCjbmpsdJ2 I7ntW6dENn35XMzOf82f03uGkOvxSNdDTeLOSj2IWCVOiuqivydI4ZabYWGgY93D/8UJ VEO03TtCmXtuEpqMaBdQ345a465NGTZ3g2fe2KPS9bluk6kYSDssMOpCqtYOf7ou+ba/ x5zoDy/i1FP4DNgmCQTSxKJEyxCzmSip/hZVEoXLx7R9nQjsw7sQlKOM47obbTxbCasU iMqfVMxHdrdEuS+gLI51qMdFw33/k8+PlwYGZmvVpyRabnwVVI7SMTfO0KZob8rO8EUK cbAA== X-Gm-Message-State: AOAM530DQhezcFF2AtOXCZtSGBgM5hajAme/4UnixeyjmnG7WkSVqUEp inLna2xWztIz1RtPQ5fMowf89BqntlE= X-Google-Smtp-Source: ABdhPJzrUyhT2WOyKdGPJLj7xi4+5aFDvMGMKgqgDavuwSTfoHM1dfGkKHZDJs1ky+LEGuWCsDpRGcVe1NE= X-Received: from oupton.c.googlers.com ([fda3:e722:ac3:cc00:2b:ff92:c0a8:404]) (user=oupton job=sendgmr) by 2002:a05:6e02:d88:b0:2c8:713f:dcff with SMTP id i8-20020a056e020d8800b002c8713fdcffmr2189656ilj.289.1648921251615; Sat, 02 Apr 2022 10:40:51 -0700 (PDT) Date: Sat, 2 Apr 2022 17:40:43 +0000 In-Reply-To: <20220402174044.2263418-1-oupton@google.com> Message-Id: <20220402174044.2263418-4-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 3/4] 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 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.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") Cc: Jing Zhang Signed-off-by: Oliver Upton Reviewed-by: Jing Zhang --- .../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 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: 12799398 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 80539C433EF for ; Sat, 2 Apr 2022 17:40:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244498AbiDBRmt (ORCPT ); Sat, 2 Apr 2022 13:42:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59312 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244141AbiDBRmp (ORCPT ); Sat, 2 Apr 2022 13:42:45 -0400 Received: from mail-io1-xd49.google.com (mail-io1-xd49.google.com [IPv6:2607:f8b0:4864:20::d49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 34115E0B6 for ; Sat, 2 Apr 2022 10:40:53 -0700 (PDT) Received: by mail-io1-xd49.google.com with SMTP id f11-20020a056602070b00b00645d08010fcso3612188iox.15 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=m8EZnZUYIv2E4OcNdiLpBu1U2VPMpBa9gyX1WRpNNUc1dE9d6ZLy/JRKo/JZowrhKX j6y8QJFzCYX/jsqPTQ+iRAgmHZ16NEvDwDylTuOO3x1NCLaPPJo5MzBwMThzw/0PneeT WVKzHzSI4rjZIkeY6NYcTFl5HOzwmRPCWWRAo3KUkprziwI5vxWhwbzVLWJhurfFz0yX KOfhniAvLmSUV9/phs5CvI5L6IF3Ub1BnMHg4dF1e9d8JvfRUGuDLcmedeBr4Bkq6s0E l4oySWOCH8VWed8YDpsnIOSS8WEgALsfnMhPxreH2miD28E94A2g4L/EvOmKvDXg+VBY prAA== X-Gm-Message-State: AOAM530rh+gV8Ogz7NOLAUJL5yIYlx6HRZe9TSc3DlEDmy0kyJaX5PY5 owqy1x7j8hG25uZAIQGqFieecqDCwCc= 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 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.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; }