From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f175.google.com (mail-pl1-f175.google.com [209.85.214.175]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BEA0219E992 for ; Tue, 11 Aug 2026 05:00:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.175 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786424442; cv=none; b=NM6Iuyi3TFhZyfPx1r/50oRLg8uhw658Sr0SIWMxz1GbjvwlTu4kbGb1ilDS/HvgUDTBE0UNaph6ujVc3nrSSRITf3DRHGiD4z4M9qwHDfWnOJuO5fX4+yi3BNM6663nOOzfjD0ZyjxTF76Wj/dWqn0iIB/ZZ5wLdhmnyZMINLE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786424442; c=relaxed/simple; bh=96uq6DR7meULD6e0vhzPQPh15pvpeq+zRFpv9E5X/6o=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=Dxute5FGw27czuIZYO1wyTYB3bYgwnvLlW2Mo9rRevgCfmF+jE66u5gZZKaxXaLdT5Cg7x5Z1/l8/Y/k6HN0/u1vkzvxMKfxjdA2ddrfOCgb9rKzwIv553W14/0WB46cvoGItZAsxchCP0qgif5eQgMYlYaZqzMwqjpwBSf0GfI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=P1TslVV8; arc=none smtp.client-ip=209.85.214.175 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.b="P1TslVV8" Received: by mail-pl1-f175.google.com with SMTP id d9443c01a7336-2ce98cb8165so6502415ad.1 for ; Mon, 10 Aug 2026 22:00:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1786424441; x=1787029241; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=FBt9KUApkZajktq9wAzF4z4ZyRD+OJ573CFHiv7VWA0=; b=P1TslVV8WwqReD1Dvmm+ncpmiF7Aqiuxy3gW2fsiHuUdaCDpPy8TDd6dvz6/5vh50f SwK4fSXyPWPWG5VywVUFxLuM4LAefqJO4BSabuUTCc01/XgazeqzM6ESQWm0PxsyRhbG GAfPdb0cEy/b1fKo0U6BSbO5U3cqCRN/Fa0RO3yr8Tk2P4OSlaf00HAOdoIm7F0MP1r1 J9DDJ1pc5C6C8N4ejuiFbHxrz+HXLZi4xrcmCpc2vbHojKn1pfYjsggUghtJp3YmDvr4 UAXRcEx4p8wt5J7eTvzPqsW0lBS++LVh0og8ByoEaYDNyvhZRfHgN+dFZPLaDos/cA2y dttQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1786424441; x=1787029241; h=content-transfer-encoding:mime-version: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=FBt9KUApkZajktq9wAzF4z4ZyRD+OJ573CFHiv7VWA0=; b=sZOPvewy4OY4xAD+lKgMt4SykmiDi17MHpSj2UbUG9PFju4pIcnpkXJCg0uGuaTKdA bDNU0erFR3QmVh2fzWDrQDXW8MQsqd4ciACTgimjdM3YSZo4sz3M7FtHFyLK6vCI15aV BGyT9L5YP9T/V9Kaot1IFd73hIgPTO/BS0CH48yy1/9e5x1bhfxHSlJg2PNdeD+18B4G /TC+Ow29COlQ1HjUrZ77FrmDfWGpGHQiUjHa1tlDJpQTtRw7jF3nnQQDnHPDKwbv736x qUWQCUzCjXQR2udpxe1SQAD4jTzW4NHwjHeBrT5/Y/DZKctmjWkFySL5MEpm+bhwXoI6 6bOA== X-Forwarded-Encrypted: i=1; AHgh+Rqj2AX3glyBkDyORP+oBflc1Pn+jHrDV1ionNJR4gNsZ51bdrj4BLttxusna1YI9sCdfTHJosY+6i63aRE=@vger.kernel.org X-Gm-Message-State: AOJu0YxMBqspxwPrIdTotg0umy2yszLFmdwbOMgeMGO2LdseOx4bo/qk 4hD8IWgJRXlJkot0oUTjJXuBpClWLuidUsvjGm+z4m9ei1j8iuVn22DP X-Gm-Gg: AR+sD13yDgEGzCEJX8lgeQx2OkiSdATNnIjbev7aj59QEHwzxIJHgfqVDhoEpiHXYXB K55R1cqIHi3xBwlA3P4xN8eleiwz3uPNruCCE8bjWFYEOSdk7SgF8YESlp7ulIqMB5lXBH+WRpR wvNK4cZFcYmNggR375m6OPWhWNX+76ZVoErpD1cm9393ug1LqBgIuvYZVcVQLwEcZEh6LfAgdcR r4S1ZCmZrTRffjMtnz9Xecg6KFS0JJzeQ6tdbCSaaluWebsVuuntfuFRrm5M4QCJPlSsDOIRExA ZsR0sOYB6HKacl7cNa4d0VCoZsEfCO1A84/HUzWditnQGrkefwfK29Txpk4/tdW287DMFLaxGIU iBZAe5eJs1ZGL2EXB4G/7I2/zXhqIEJeZ/bOsYcjpZlIPJ2UOp67VqHEi0FWY6n8mkdDl4/KaBN o+0lup5z00qyhdPK56tQh26SXU6knTBiA12DMYjNAfGMbWwKRsT0rq8Mcba/IZWz7VIqz/kpMC5 rM= X-Received: by 2002:a17:902:f64c:b0:2c0:d94f:50c7 with SMTP id d9443c01a7336-2d3187e903bmr5964185ad.7.1786424438583; Mon, 10 Aug 2026 22:00:38 -0700 (PDT) Received: from 10-86-27-207.ban-spse ([165.204.217.251]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-31c64e10011sm535444eec.28.2026.08.10.22.00.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Aug 2026 22:00:37 -0700 (PDT) From: Gokul K To: Sean Christopherson , Paolo Bonzini Cc: Shuah Khan , kvm@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 0/2] KVM: selftests: Fix two VMs leaked on early returns Date: Tue, 11 Aug 2026 10:30:27 +0530 Message-ID: <20260811050029.530698-1-gokul02k@gmail.com> X-Mailer: git-send-email 2.54.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Two x86 selftests create a VM and then take an early return that skips the kvm_vm_free() at the end of the function. Both now jump to that existing cleanup instead. Patch 1 is the plain-SEV path of sev_smoke_test(), which returns straight out of the UCALL_DONE case instead of leaving the loop. The SEV-ES path next to it breaks out and frees correctly. Patch 2 is nx_huge_pages_test, which returns as soon as it has confirmed that disabling NX huge pages is denied without CAP_SYS_BOOT. The two patches are independent and either can be applied on its own. Found by auditing every function under tools/testing/selftests/kvm/ that creates a VM and later calls kvm_vm_free(), looking for returns in between. Seven other hits were false positives, mostly returns after REPORT_GUEST_ASSERT() or TEST_FAIL(), which abort the process and make the return unreachable. Two more that do look real, in get-reg-list.c and arm64/external_aborts.c, are left out because they belong to different maintainers. Compile-tested only. This host has neither SEV (kvm_amd sev=N) nor hugetlb configured, so both tests SKIP rather than run. Note patch 1 touches sev_smoke_test.c, which an unrelated patch I sent earlier also touches [1]. They modify different functions and do not conflict in either order. v2: - nx_huge_pages_test: goto the existing cleanup instead of open-coding kvm_vm_free() before the return, matching patch 1 (Sean) - Drop the claims that these paths never exercise VM teardown, and that the nx_huge_pages path is not obscure. Neither justification holds up: teardown still happens, just at process exit, and how often a leaking path runs does not change whether it should be fixed (Sean) - Rebase onto current kvm-x86/next [1] https://lore.kernel.org/all/20260807071026.195503-1-gokul02k@gmail.com/ v1: https://lore.kernel.org/all/20260808081050.408657-1-gokul02k@gmail.com/ Gokul K (2): KVM: selftests: Free the VM when the SEV smoke test's guest completes KVM: selftests: Free the VM when NX hugepage disabling is denied tools/testing/selftests/kvm/x86/nx_huge_pages_test.c | 3 ++- tools/testing/selftests/kvm/x86/sev_smoke_test.c | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) -- 2.54.0