From patchwork Thu Feb 17 03:49:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Reiji Watanabe X-Patchwork-Id: 12749291 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 0C3F1C433EF for ; Thu, 17 Feb 2022 03:51:44 +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:Mime-Version: Message-Id:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Owner; bh=DPkPJSOCFF8ljRkE5IAoFhvokMQQbvgD2mDkIY1Ql00=; b=cAk ZAj4Re5UOPhiZqHapIGhqhTd14XRw9L604kbsv3LQUxmj0t5Vkf6WdLnYmok1HhlTtkEcvKVS+TIu YuhUkJruvjiMw5geIPfe6V4WzfoSu2MfTXZeNHLAcr8eEyv7gxce48B+RTsicI8UPo9NJH7h+VcQe vTR0swe1Vaf+4DyyDDk1Dpu4OfeqdXa6w2YfuWdRiyhwUO263oavTcEdN50ZWvohcDk/pBNMHGVCn Lpldsgi+9+mz2UXUIEtjfbpZMgbr3tRogvVJmREeVeWWUSf0J2wbJbX+di8MCLJNPmbqB0v+3uQvu MSxPPix+QD6X540zcSbKwaPNuo8kULg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nKXo7-008r6B-Jy; Thu, 17 Feb 2022 03:50:15 +0000 Received: from mail-pl1-x64a.google.com ([2607:f8b0:4864:20::64a]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nKXo4-008r59-Tp for linux-arm-kernel@lists.infradead.org; Thu, 17 Feb 2022 03:50:14 +0000 Received: by mail-pl1-x64a.google.com with SMTP id c22-20020a170902849600b0014eff3fd4bcso1970958plo.7 for ; Wed, 16 Feb 2022 19:50:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:message-id:mime-version:subject:from:to:cc; bh=vRtM/cROOx5FsqNMttv0pPiPYqWySn+ox7xCpR/R9pQ=; b=VXI/EO5uA+etW0dY+bDcMbof9vcOt9SX4c8MIwKYL2KjJK778sgRC4ONa+S96Tq0kC 2DNAkeg32L87pidTLjIxaGqseJc+3T5vMuB+w+93GZkI2D2TVXTTsK9tLKdq55IVduJd HY6Yt6e7ITaZd1JWGm6SAif/ms7rSjFues9sLIJCzp12Jt5VwgzXhnRJusVMPVi7fx7K EGLTgjyoji9r7qxZ7uhq821QmUs0eEGMKzsvl5mW4BzjI4gNlfYLd+rvssbuo7pt2BsP pXyzTyGwbqarreY8cymIKeiUQtmMLmNlCpb2jOchN184vkaWtt52ENyHw4o+hy9Vex4V c4Xw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:message-id:mime-version:subject:from:to:cc; bh=vRtM/cROOx5FsqNMttv0pPiPYqWySn+ox7xCpR/R9pQ=; b=CjbyShPuJd0us1Dict/6iWqtYsGVJ6uETDmoY819jBeUjI2LQrU2TWKyWHqx33phK3 LhbmqTSFeZafnE642h8xAV0fv7lKBp0ZvLvlT5jL5fnqDIdUAI5AoqA7Lb+vUkEeE+sv rDO5wNuUdahMIv1qhgrOay23fMt0nx4or9xWsBviLdjkfOWrJM2On+LmT21XJ0qdiCLk kReqVTQnSkC+MHLbYebHasFfzNBg3NEqllScY8QEELxYXQipA+KHZZ8WgeKk3Enhn1gQ chy749KP6H3iEOiCQ0JqSN+cKyAUr/hHtc8o5mLKwb0k8l0WnRw9LCFKByhhrIKnjIJ4 Zq6g== X-Gm-Message-State: AOAM53314qU3fZrc04chTvQNs/eZCBXMCeJWXntIHJ7B/J4lcltGTx8J ANkpBAqp/e96CxOPS0tcgXgSp+vY2IA= X-Google-Smtp-Source: ABdhPJz43oeS5F0siXWsZh061o21n+qfPtthgPIgTIT8DyUX6v2rSoMU2ZNvcsVNXhRZGwvcQO+2wDnOY7E= X-Received: from reiji-vws-sp.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:3d59]) (user=reijiw job=sendgmr) by 2002:a17:90a:1f4d:b0:1bb:a657:ace5 with SMTP id y13-20020a17090a1f4d00b001bba657ace5mr2283133pjy.39.1645069811410; Wed, 16 Feb 2022 19:50:11 -0800 (PST) Date: Wed, 16 Feb 2022 19:49:46 -0800 Message-Id: <20220217034947.180935-1-reijiw@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.35.1.473.g83b2b277ed-goog Subject: [PATCH 1/2] KVM: selftests: kvm_vm_elf_load() and elfhdr_get() should close fd From: Reiji Watanabe To: Marc Zyngier , kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org Cc: linux-arm-kernel@lists.infradead.org, James Morse , Alexandru Elisei , Suzuki K Poulose , Andrew Jones , Paolo Bonzini , Will Deacon , Peter Shier , Ricardo Koller , Oliver Upton , Jing Zhang , Raghavendra Rao Anata , Reiji Watanabe X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220216_195013_006327_237A08BE X-CRM114-Status: GOOD ( 10.42 ) 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 kvm_vm_elf_load() and elfhdr_get() open one file each, but they never close the opened file descriptor. If a test repeatedly creates and destroys a VM with vm_create_with_vcpus(), which (directly or indirectly) calls those two functions, the test might end up getting a open failure with EMFILE. Fix those two functions to close the file descriptor. Signed-off-by: Reiji Watanabe Reviewed-by: Oliver Upton Reviewed-by: Andrew Jones --- tools/testing/selftests/kvm/lib/elf.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tools/testing/selftests/kvm/lib/elf.c b/tools/testing/selftests/kvm/lib/elf.c index 13e8e3dcf984..9b23537a3caa 100644 --- a/tools/testing/selftests/kvm/lib/elf.c +++ b/tools/testing/selftests/kvm/lib/elf.c @@ -91,6 +91,7 @@ static void elfhdr_get(const char *filename, Elf64_Ehdr *hdrp) " hdrp->e_shentsize: %x\n" " expected: %zx", hdrp->e_shentsize, sizeof(Elf64_Shdr)); + close(fd); } /* VM ELF Load @@ -190,4 +191,5 @@ void kvm_vm_elf_load(struct kvm_vm *vm, const char *filename) phdr.p_filesz); } } + close(fd); }