From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=13.77.154.182 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796027602; b=HJlCBA0hxj35r7VjLu4H2d43JS4vLNwQ3HNQ68acLAhPBM/u/y0QxFqjUEqwlBtQj/vY 767nf0sA15wNC5BqVRCudExj5ZIbr0YvSuVJzsRly0HB1ymWZxDMVaLfdYvJ4++IHMFhJ PWUS8IMM7VTcfYAfdkwF0DGfDHu+MfkLgHo9YGST9maf9a0m+Gy6zXtqx4K4bpBIz2HGz oFXXvboaBmh+gLcAx0+DW79GqpTEIAdkGBz0yX0lf/Cd07IYS6I2OK+FVcApCFp1VsK6u R6iYnkvMctJrZBVS+cp6eugpglVV5KT3bTl1DlF6GEFu2BWbBElNWJWAA3QE91bOi5g== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796027602; h=DMARC-Filter:Received:DKIM-Filter:DKIM-Signature:Message-ID:Date: MIME-Version:User-Agent:Subject:To:Cc:References:Content-Language: From:In-Reply-To:Content-Type:Content-Transfer-Encoding:X-Spam-Status: X-Spam-Checker-Version; bh=yAZYSBlFWnMGdL4jX5IkWw64uvkdDWx3jPt63qy4RyI=; b=rXD3hXEV0RP2YKwAP1q+oSscz46xMVLa3plLBiQazPIxF2u6xPP0bQk9P+uTXrijSutC nvlpcqGcKzN2E4KeF6bhNil5gQ8eGa0v9DfPNJtKEnD4FKTiOn2YUijLCCYf7cLsaOD7m KYmhuHrgXKoY2XrRroZMkkBWigvAR3jaFAYfZqN5kcePmUBcOXHNVw6fW/BZFHRzvTDpf CFxtJIjaHySeE95ZzKU+Dvo1mGF8P9Bf6PfHiqpHzeHSxQFjrG1uULK1GM1YZ7oXT2Q3X q9+JWe1yxjTtv52LqvxqwAt/VdZAeyGJQEgespKUQujgpyOXhw9Z6lFmLMkqOwgizLA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=linux.microsoft.com; spf=pass smtp.mailfrom=linux.microsoft.com; dkim=pass header.d=linux.microsoft.com header.i=@linux.microsoft.com header.a=rsa-sha256 header.s=default header.b=dtPoETln; arc=none smtp.remote-ip=13.77.154.182 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9B4F0606A68F; Mon, 30 Nov 2026 08:33:20 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 9B4F0606A68F Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.microsoft.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.microsoft.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=linux.microsoft.com header.i=@linux.microsoft.com header.a=rsa-sha256 header.s=default header.b=dtPoETln Received: from [10.95.64.116] (unknown [52.172.102.219]) by linux.microsoft.com (Postfix) with ESMTPSA id 6EC1A20B7166; Mon, 30 Nov 2026 00:33:10 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 6EC1A20B7166 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1796027592; bh=yAZYSBlFWnMGdL4jX5IkWw64uvkdDWx3jPt63qy4RyI=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=dtPoETlnr1lQNRY1byhkXDO428fNm7+yav+JMBwywC+WN9CeaN2HfOAqCTNnxHnQw S/FJsmRsjStJnh20w6SoquSwblZHAOTFWLnCdZhbB09rqBkvaVtlVG7bXpBhsUQtRn Gk/UpXeyrExJprLkwBfAEOhM8KgGYJCRjFcmFPVw= Message-ID: <5bb09f89-0301-45a6-80c2-7f04e787cb74@linux.microsoft.com> Date: Mon, 30 Nov 2026 14:03:15 +0530 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 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] uio_hv_generic: Close the channel on remove if it is still open To: Yuho Choi , Haiyang Zhang , Wei Liu , Dexuan Cui , Greg Kroah-Hartman Cc: Michael Kelley , Emerson Busson , linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org References: <20261129184024.1092604-2-oss.patchbox@gmail.com> Content-Language: en-US From: Naman Jain In-Reply-To: <20261129184024.1092604-2-oss.patchbox@gmail.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 11/30/2026 12:08 AM, Yuho Choi wrote: > hv_uio_release() closes the VMBus channel when the last file is closed, > and hv_uio_remove() then frees the ring buffer. But once > uio_unregister_device() has run, the uio core no longer calls > ->release() for files that are still open. If the device is unbound > while a process has /dev/uioX open, the channel is never closed: > > - the host keeps the channel open and the ring GPADL established; > - hv_uio_channel_cb() stays installed, and dereferences a NULL drvdata > the next time the host signals the channel; > - after the driver is bound again, opening the device fails, since > vmbus_connect_ring() finds the channel still open. > > hv_uio_remove() also frees the ring in that case. In most VMs the pages > happen to be leaked instead, because ringbuffer_gpadlhandle.decrypted is > still set. A channel with a confidential ring buffer never sets it, so > there the pages go back to the allocator while the GPADL still covers > them. The same happens when vmbus_disconnect_ring() fails in > hv_uio_release(). > > Close the channel in hv_uio_remove() if it is still open, and hold a > reference to the uio device until then, as hv_uio_channel_cb() uses it. > A process may still have the ring mapped, and uio maps it with > remap_pfn_range(), which takes no page references, so keep the ring > memory in that case. Keep it too when closing the channel failed in > hv_uio_release(), as vmbus_close() does, and warn when the ring is > leaked. > > Fixes: cdfa835c6e5e ("uio_hv_generic: defer opening vmbus until first use") > Signed-off-by: Yuho Choi > } > @@ -385,15 +389,35 @@ static void > hv_uio_remove(struct hv_device *dev) > { > struct hv_uio_private_data *pdata = hv_get_drvdata(dev); > + struct device *uio_dev; > > if (!pdata) > return; > > hv_remove_ring_sysfs(dev->channel); > + > + /* hv_uio_channel_cb() may use it until the channel is closed */ > + uio_dev = get_device(&pdata->info.uio_dev->dev); > uio_unregister_device(&pdata->info); > + > + /* > + * The uio core does not call hv_uio_release() for files that are > + * still open after the device is unregistered, so close the channel > + * here. A process may still have the ring mapped, so keep it. > + */ > + if (atomic_read(&pdata->refcnt)) { > + vmbus_disconnect_ring(dev->channel); This can free a subchannel's ring pages while an application still has them mapped. The sysfs removal above only unmaps the primary ring. The application can still access the subchannel pages after they've been freed, even if the kernel has allocated them for something else. Can we remove each subchannel's ring file before freeing its pages? You may also want to check Sashiko's comments on this patch. Regards, Naman