From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=103.168.172.159 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796159965; b=n9XpZzuJkYvuKWwGkzflTvBhhAnx9YmzFJBlPjao6LJ4XnB0ppyc56WtI8qH/E0bH3Wh nAeZ8TNy33h+FvwesVs0PL6u7PpG4UtWA61co34Y8AEgpMxwjJwVMmEgviL5Y+b9j0dXT DDJY1yZH4wlyyTEWJP9Z8DrAKxP7MK6u/StHZAw8oapG0SxbVV9+55W1xnsyqlQYxmcWp D/h0YcMZnfCYnJj3+YMqW9EUGCxGeJeXatsUXgFvaVUqFgHuqXcrnfyR4auNyD/3bSsmd irenqtLI/2OjOb0kTnuRySosiUm5NMEI1YsYptrxW89Y51E5UXbtNHfvpeHdqlxnIDA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796159965; h=DMARC-Filter:Received:Received:DKIM-Signature:DKIM-Signature: X-DKIM2-Info:DKIM2-Signature:X-DKIM2-Info:Message-Instance: X-ME-Sender:X-ME-Received:X-ME-Proxy-Cause:X-ME-Proxy:Feedback-ID: Received:Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: X-Mailer:MIME-Version:Content-Type:Content-Transfer-Encoding; bh=vISOndXrxNN9SRIJ/mGR/lEfv6FHBaUI7LRUZmhTELc=; b=hEyxBCqiu1Q9jzUHuURHCnPaqb4IvLeswO9Wy/juLnaep8HP6kyKOJea5Ch7W2b5NTzw kBBJNrD2ge7RKf2aBviS7NAWQoP4P+8AQvIUjJVmy+59p0so9VRMCG0muOf/oMNAMFCtM acsjiQ97PK1iOhKrvxPox5RgdHpOjhh0nzBj0hVDCml39PHFW/D+tRNh2kZNkp2l+KsXA YLIUDiZAr9AX6vZpLlXH6h02OcJsoNHLFiZM4f+yQpE77nEFYCCHydJr6wPP+PFt3OBz/ kYixTNc+OIGCqsuR2JQStrIa1jdTcmPnNbc80i6Rtp8FeEF6OQjKfQyP1b4pkK5jVGA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=shazbot.org; spf=pass smtp.mailfrom=shazbot.org; dkim=pass header.d=shazbot.org header.i=@shazbot.org header.a=rsa-sha256 header.s=fm3 header.b=gbgvwxtY; dkim=pass header.d=messagingengine.com header.i=@messagingengine.com header.a=rsa-sha256 header.s=fm3 header.b=vWE3D5hy; arc=none smtp.remote-ip=103.168.172.159 Received: from fhigh-a8-smtp.messagingengine.com (fhigh-a8-smtp.messagingengine.com [103.168.172.159]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 48BD0606A31A for ; Tue, 1 Dec 2026 21:19:24 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 48BD0606A31A Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=shazbot.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=shazbot.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=shazbot.org header.i=@shazbot.org header.a=rsa-sha256 header.s=fm3 header.b=gbgvwxtY; dkim=pass (2048-bit key, unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.a=rsa-sha256 header.s=fm3 header.b=vWE3D5hy Received: from phl-compute-01.internal (phl-compute-01.internal [10.202.2.41]) by mailfhigh.phl.internal (Postfix) with ESMTP id 5D98D14003C8 for ; Tue, 1 Dec 2026 16:19:23 -0500 (EST) Received: from phl-frontend-03 ([10.202.2.162]) by phl-compute-01.internal (MEProxy); Tue, 01 Dec 2026 16:19:23 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=shazbot.org; h= cc:cc:content-transfer-encoding:content-type:content-type:date :date:from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm3; t=1796159963; x=1796246363; bh=vISOndXrxNN9SRIJ/mGR/lEfv6FHBaUI7LRUZmhTELc=; b= gbgvwxtYuVhueCPYKUp6TwraDnX/CIyAMg+e1qus1f7uo3/xkUU4teNsyt9FEBPE GxTAeaBPQSOu3UqqFj7BnEdwDvN/zC5+2gC9w2DjwY9j93RWLbY5dfsk92zDlFFU 6dz8DVXU2kE8hY2kBLJ72VvkST/rx5nR/x8yUOKu8JZzjSsMo7AMj9aGtYigsSW1 9xGrgwC4HEkMDp94Xi0qXO3TVMiNLWUP0Sw15MhfyM5uqHvCyDZrGmbu4ye84EMH buLMbaJhyzH3pth3+B3bMfRakJSrs4heII2LXlmMSMcm2t+TxBgvRU0WxaRXiehV qUnL87dQdclMRlYQ6EsBlw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm3; t=1796159963; x= 1796246363; bh=vISOndXrxNN9SRIJ/mGR/lEfv6FHBaUI7LRUZmhTELc=; b=v WE3D5hyH8kT7gQ2h1MwMQwoZdItxJtUXooPrBnAho1IRG2VKloXYZPudoLanKH8P E05g+AYBHdL6BPHaCu5SY/ozuCH2nZCAnjgTLnVZ/pQYoG9M1tT/vO86n+bFj6PJ vMlaPBCEh0AJGeJvZhL6S8qRgfWDMcOE4Ta7JvUSRkmIxqouDKgAOMhd/A4ggkwb bcEMi1td/+SXx4M+ui4Pvzb/Dkp0efezpi+jv5DW1FND1cOvCNupCBo2yMsom3cH Vl5xI1yeD4yH5fACFBC5wFmlaZ+5qMb/I5yj/t8o7LXt7KgmyYCy7UDMJwguVhBW EgEgEZ1Es5HSD6eBkXCWg== X-DKIM2-Info: draft=ietf-dkim-dkim2-spec-09; repo=github.com/dkim2wg/interop; date=2026-11-03; sw=lmtpprox; action=sign d=shazbot.org a=rsa-sha256; DKIM2-Signature: i=1; m=1; t=1796159963; d=shazbot.org; mf=PGFsZXhAc2hhemJvdC5vcmc+; rt=PGt2bUB2Z2VyLmtlcm5lbC5vcmc+; s=fm3:rsa-sha256:TWwJ+AD/taCwtGaq5iioncoeMK9qIFIP7I8NnbCKuIPpued uEY2MQ0VrpNRjqpEhmz5wEqhGi2PswZcG9nIriA6DF326schA6UWXAVRFrq47bxg kNeSiZiS//9hHzcowBW2FJWL87cQ/X3zhUcya7MgjqDA7HILH8Qn7YJXv59DJHZg Av1xVdFuSfEY7XURB+oJh8g+sF/5BHN8C8CfE/JnZj5Iyt9Z/8O2CGDuRq0Nz9mc NuV/35lxSdd3DXUHRUZUtRuQNx0SiEBxEovUJUGg54v3SR4Gu+DOH+ysYRV8nyfM gDPx5UKvG1vyhJxcp9I4/bNiybZasb4T5JBbl4g==; X-DKIM2-Info: draft=ietf-dkim-dkim2-spec-09; repo=github.com/dkim2wg/interop; date=2026-11-03; sw=lmtpprox; action=mi-m=1; hc=12; hn=cc,content-transfer-encoding,content-type,date,feedback-id, from,in-reply-to,message-id,mime-version,references,subject,to; Message-Instance: m=1; h=sha256:AeRJ9FaasbHyPhr1Pz4+I+p/f1xBGi/XuU5v2hwONjM=:XW38nFzpWXvs2oxhu0yVP3A+NbVq8N4F5Dtqqbsf+J4=; X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: dmFkZTGxu8J4NCLReWF2oXWXM8cGNrQkUvRq5nVnT6vnyOED5bDE9/aXY3fGPthxyOPVpi BxmIwFCwf0jQpKc9ItkyDWQ3Ph7D57EZto1awUS/5l3wgLIn9sKzQ8Bw/SiP8K+1ZOcXtR pSTVnvbXLKVdSwjoHWRmGXH7XKtfKvbI93MJ84a2q9btfWbpfXAmMvnfyE28EmMNZEZgDM e3qdipreH2bJKrdHZwQTaoMQWfKOhEJ7fki4d44uPrpg/Ufkgl90W8L51qcc+cnAY/xzg/ CEOYM+IkigJ0CaIxoYbwqXUhbZMeqxOWzr+gfjOkPqNn9AW1BU0KSnKpJSpKxMPO9z4jRs urDxmO8taWPcKXrfZzoqz3IIs5Pvo/GgpWjHlC+BJsB+gItYI39JB0seMTaNdQKJ4Gg8wu AD+QSyZ0zvKPt4qAC5v9Wogz+fNvfgDKu2Xn7yTh1JAthxgak9LzlIZ7org4PUiNa0R/X5 BzfeUQAtcKyv8pUjpa6hTPUIEbiZWDLL9YM4GP+OGiQ5x9AJigPW4041tmoCbT+oPPzOYB 2Z0LxauY3a5Djr6bKFlzvOSlaJ3K1BB48l0f0rdHrJhyRwVj0qMKGOcgYab08PQrHmZzpg Q8oWHfvvhyTr0IPrfJ+vgPUGu8EUP1MyZm7o1OSrPEO+l0v5zRHlENH7kjWw X-ME-Proxy: Feedback-ID: i03f14258:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 1 Dec 2026 16:19:21 -0500 (EST) Date: Tue, 1 Dec 2026 14:19:19 -0700 From: Alex Williamson To: Zhu Jun Cc: brett.creeley@amd.com, jgg@ziepe.ca, yishaih@nvidia.com, skolothumtho@nvidia.com, kevin.tian@intel.com, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, alex@shazbot.org Subject: Re: [PATCH] vfio/pds: Release migration files on allocation failure Message-ID: <20261201141919.0ea34e1b@shazbot.org> In-Reply-To: <20261112023101.118174-1-zhujun2@cmss.chinamobile.com> References: <20261112023101.118174-1-zhujun2@cmss.chinamobile.com> X-Mailer: Claws Mail 4.4.0 (GTK 3.24.52; x86_64-pc-linux-gnu) X-Mailing-List: kvm@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Thu, 12 Nov 2026 10:31:01 +0800 Zhu Jun wrote: > pds_vfio_get_lm_file() takes an extra file reference before allocating its > backing storage. If an allocation fails, the error path drops only one > reference and frees the private data, leaving the anonymous file leaked. > > Take the extra reference only after all allocations succeed. On failure, > drop the initial reference and let the file's release callback destroy the > mutex and free the private data. > > OpenAI Codex assisted with analysis and patch preparation. > > Fixes: bb500dbe2ac6 ("vfio/pds: Add VFIO live migration support") > Signed-off-by: Zhu Jun > --- > drivers/vfio/pci/pds/lm.c | 9 +++++---- > 1 file changed, 5 insertions(+), 4 deletions(-) > > diff --git a/drivers/vfio/pci/pds/lm.c b/drivers/vfio/pci/pds/lm.c > index 08487eab11b0..d96ec77402c0 100644 > --- a/drivers/vfio/pci/pds/lm.c > +++ b/drivers/vfio/pci/pds/lm.c > @@ -37,9 +37,6 @@ pds_vfio_get_lm_file(const struct file_operations *fops, int flags, u64 size) > stream_open(lm_file->filep->f_inode, lm_file->filep); > mutex_init(&lm_file->lock); > > - /* prevent file from being released before we are done with it */ > - get_file(lm_file->filep); > - > /* Allocate memory for file pages */ > npages = DIV_ROUND_UP_ULL(size, PAGE_SIZE); > pages = kmalloc_objs(*pages, npages); > @@ -73,6 +70,9 @@ pds_vfio_get_lm_file(const struct file_operations *fops, int flags, u64 size) > lm_file->page_mem = page_mem; > lm_file->alloc_size = npages * PAGE_SIZE; > > + /* prevent file from being released before we are done with it */ > + get_file(lm_file->filep); > + > return lm_file; > > out_free_page_mem: > @@ -81,7 +81,8 @@ pds_vfio_get_lm_file(const struct file_operations *fops, int flags, u64 size) > kfree(pages); > out_put_file: > fput(lm_file->filep); > - mutex_destroy(&lm_file->lock); > + return NULL; > + > out_free_file: > kfree(lm_file); > I might opt to do the lm_file free+return in the anon_inode_getfile() error branch, rather than create this split unwind chain. There's a natural inflection after that where we rely on the release callback for the final cleanup anyway. The change itself looks correct as is to me otherwise. Brett? Thanks, Alex