From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.172 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796116016; b=hjW6CAyYR9P6iR2kQXY22RyqqYUzUx6Tud8EDebqwpVz+/kVpZnly25AU6mb32/Q8HKF kVoRbCrMeGENhC38rtP3allqlETYrM7mTfUXCQoHKQLxHcb4XoQC/x4nxBOEUuqUYAMTp cwvAILWHYIyA8i6455tkLhIEhwW2nPEdUOY9A+7v8+AJdmn3KaflhhM9rWZvNsihzDuey B2Q5qyZ3GK9rSCEMggXilQODJpHCWL1EcU1n5ksMN0VFK1l4u3xnF60h7rwZc9xWZIC5U zBxhaW30zaLO7DTJ+0YXZfUv7OP31+gy1wVag/xpeXnA1DNiGIjhBI4DvUIR13OY2JA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796116016; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:To:Cc:Subject:Date:Message-ID:X-Mailer:In-Reply-To:References: MIME-Version:Content-Transfer-Encoding; bh=yYIjyygIY/QwpAXQkMexRPNEZ+UwuDW/92GJAz+Vno0=; b=UBC4jdd2cbW1QnRhP0HXJshTMKB8Z0qzBznmjiqQHaMATd48DdFtJO+3ANXa1PzvfVuH 6vO+T50DtaQgfKhDN+Hd4PelSFa22/WEnK3GCMxWuQGrX9AqjfjH3S0UxIn/aNL+8O2bM AWhHW9rLKGKLg7cnxellihkuCuoGY9ahQTYBQGn/IdAgIq8JI0e+8Rkv8T1QoBI0FSB2i WGQVlMA4M6pAY2w75sGkZm+GTJbs3JnW4hnuYYLNswrTEC+3uJTrsUT5GIC5/GC+MSazg qiuvZ/XeaGLwDjczVkV0wOAFGYmy1h0wFybYWPCDAcGxekEVihEEJHG43xhD1StqVSQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=iNkHefkM; arc=none smtp.remote-ip=74.125.82.172 Received: from mail-dy1-f172.google.com (mail-dy1-f172.google.com [74.125.82.172]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9FB98606A32E for ; Tue, 1 Dec 2026 09:06:55 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 9FB98606A32E Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=iNkHefkM Received: by mail-dy1-f172.google.com with SMTP id 5a478bee46e88-385d8a00598so19968064eec.1 for ; Tue, 01 Dec 2026 01:06:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796116015; x=1796720815; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=yYIjyygIY/QwpAXQkMexRPNEZ+UwuDW/92GJAz+Vno0=; b=iNkHefkMYpqqXXjsKRqXz0hVDzsRwR9fzpZZuK/SYGtiva7rWPdJV4EKkgu8y9uc91 C7ZhFRbrVhw0b1j3U0VmI9MvzUMP4Z+3N5YtX8mnfOPnUKol5B2ITFXYIqIWcUFrq4Bx yOBJqKECkb+xxHK144eX3xT2rZmrHYj92RxbdlDwxdkSnMlJQvJhDZTwiWchCvbdLRIV ZyLss24M5GmX4MvtmmicWX5xJxdSgSdpeI0Iyn+oEtlcu90q3iXKqQt2D/U08OsVfuhc MMdRYawGMha/REeWsgYVxehQLyIzj32RVQsb7p3oVPw03mogsYtZ+pD8r9ULiAi5wsCE Calg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796116015; x=1796720815; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=yYIjyygIY/QwpAXQkMexRPNEZ+UwuDW/92GJAz+Vno0=; b=EwBtFSDZ5YIhX+1uF7RfSDsh1uO/cNB1+izmtCPSsYC0w6aSVw/J4ebkwnCSPlL9h3 C2wp890dc2aQjazrobuy9Vh5tLObW+aYsy7nz3JbTARhiPe1/AXGCFuiSQ8bLefTN7b1 /ix7JEL/ykNo4gL8vLSYs28tcMclmVII65KYDdOiO/irk98jlclT+7v8SylgnK/vReei 1+5SHuVKzLFKzY1gJRgxqkFUJLtD1OOo6Yyn2dHMXYnP3FZ20w8AqXq72T7LZJ0Y/BLO rvIgHVQwhDzSY/5fHSPFgFqKlxGRHLBPJm1LcJL2fAzL2ttp8pCy3iOmXXj2szgAzTAj A4fg== X-Forwarded-Encrypted: i=1; AL+hErHaVIyyvuRUSA/jkgufNxQcB8aB0YxlaQPwkur1kefyReskVapj+3fQS7mKA9AmTQSZPpAeuPB5ZY7hV2I=@vger.kernel.org X-Gm-Message-State: APuU4Z9s/KzuACPj7ayNoQDWIH/e24GAoCH+KJ1GcV/7/chiqXut61yQ I8lcLQOcB8p7vNzeW2e7eKhb2RKrDlobfCs6Cw2wYS79pIrFa8yknEYx X-Gm-Gg: AZFdTZcKBVBYvQIJ6kO/0xBAx5xnKRcvyYSTERKE5G07QuOSBtkxoXx2PkzRXI3yqV6 l9gI/TwLz+weQyYAfVlgLCMMma1HNPHTpWQN9vDbN6HXMwJSSyBF/iTGaZFx2+QjdzhYuAuMe1h Ah98BQLz2p8NLvU2WYLVk8p2mqPAIrBwhEwPbqhAutV7ix09f85k3cyBu/3h5XiznwyupTHB5qW hsg9O4KNtH1CqVM80XzkxN7ultaARohvqaoGIvDl5u/qQ2uiLKJpuhCeNVn/+cNlsEalrnJlIfW W7g6B9+6EX3A4CFPQM7VfoNu/fVJocF6RuQ6ZU9qIE8b75x4EzS6yVOubELh/QRlxhVVILTaLhQ GRCDZ62Qd2+F3T6dAdSDul8OCpj2XQVJrQw+ng4FMbqDnyrNLhm15tVRYuea6mbRVYHFdFxoANm MatmRYoZ9AnQKJT1pj10aHimDSTFhGuby7nFeYOOvGHvfCtKKJ+CuBUOBHvi1B8F2X4FHjdLKRO YYQ5rWaFkoM5Jw7lczvMVv/Ty8qKIRaJKqTM7aglr+8+MA1S9i2vP1jORuIjVFnaezbXb8/7n6Z BDy7y00eiVq/2Jg/PXajgIz3gsmTUVmNIfOPF9lngQ== X-Received: by 2002:a05:7022:3f07:b0:19a:8e3e:530e with SMTP id a92af1059eb24-1b5568650c0mr38551217c88.8.1796116014499; Tue, 01 Dec 2026 01:06:54 -0800 (PST) Received: from 10-86-27-207.ban-spse ([165.204.217.251]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-1b562a82b3fsm103317755c88.5.2026.12.01.01.06.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Dec 2026 01:06:53 -0800 (PST) From: Gokul K To: Sean Christopherson , Paolo Bonzini , kvm@vger.kernel.org Cc: Shuah Khan , linux-kselftest@vger.kernel.org, Peter Gonda , Jing Zhang , linux-kernel@vger.kernel.org Subject: [PATCH 2/3] KVM: selftests: Close the SEV fd opened for each KVM_SEV_INIT2 ioctl Date: Tue, 1 Dec 2026 14:36:31 +0530 Message-ID: <20261201090632.2482795-3-gokul02k@gmail.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20261201090632.2482795-1-gokul02k@gmail.com> References: <20261201090632.2482795-1-gokul02k@gmail.com> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit __sev_ioctl() opens /dev/sev to fill in kvm_sev_cmd.sev_fd and then drops the descriptor on the floor. open_sev_dev_path_or_exit() opens the device afresh on every call, so the leak is one descriptor per ioctl, not one for the test. The test issues a lot of them. test_flags() runs 32 iterations and test_features() runs 64, each for up to three VM types, so a machine that supports SEV, SEV-ES and SEV-SNP gets through nearly three hundred calls. Hold the descriptor in a local and close it once the ioctl is done. Every other caller of open_sev_dev_path_or_exit() stores the fd in vm->arch.sev_fd, which the previous patch makes kvm_vm_release() close; this is the only caller that owns the fd itself. Fixes: dfc083a181ba ("selftests: kvm: add tests for KVM_SEV_INIT2") Signed-off-by: Gokul K --- tools/testing/selftests/kvm/x86/sev_init2_tests.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/kvm/x86/sev_init2_tests.c b/tools/testing/selftests/kvm/x86/sev_init2_tests.c index 87bff4fbb7ed..09c8d9620bd1 100644 --- a/tools/testing/selftests/kvm/x86/sev_init2_tests.c +++ b/tools/testing/selftests/kvm/x86/sev_init2_tests.c @@ -32,10 +32,11 @@ bool have_snp; static int __sev_ioctl(int vm_fd, int cmd_id, void *data) { + int sev_fd = open_sev_dev_path_or_exit(); struct kvm_sev_cmd cmd = { .id = cmd_id, .data = (u64)data, - .sev_fd = open_sev_dev_path_or_exit(), + .sev_fd = sev_fd, }; int ret; @@ -44,6 +45,8 @@ static int __sev_ioctl(int vm_fd, int cmd_id, void *data) "%d failed: fw error: %d\n", cmd_id, cmd.error); + kvm_free_fd(sev_fd); + return ret; } -- 2.54.0