From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mta1.formilux.org (mta1.formilux.org [51.159.59.229]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C18DF625 for ; Sun, 17 May 2026 08:10:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=51.159.59.229 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779005452; cv=none; b=drHWXZhz/4CTst0Fs8Dma3PWJWQmKPjo9+XkhSxSfNEQ1ezVjeXVAue4iTfj3AHvGo4UW6O/dDtL4125O75pA4T16OdlQ78clgVd4YVAUJW/33dauqHNqBi1jMIbX2bx/brwTkh7LyBypM11zzh+bYq6NBarWGio2wxWcAD7KlM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779005452; c=relaxed/simple; bh=Tp9EBPyQye0plkW+JjPSaNRG0trHxw5lx8gPK1VmUII=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=MlXjkt7GUBo0hdCjsotPMF7gOYNplqGPjVviQC+B+HKfj0OKVEUaAC85PTWg4jGmFWLi1yt69G+g7GYxpInV83JS8di2ryIDtTO+hYUWByZHfjN2b935sTe4pNAiHZ21PXfGFLP5tYcowTD9gtSGvykBa+zJ01LKvyQw9XRWdzk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=1wt.eu; spf=pass smtp.mailfrom=1wt.eu; dkim=pass (1024-bit key) header.d=1wt.eu header.i=@1wt.eu header.b=LOP9AFZv; arc=none smtp.client-ip=51.159.59.229 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=1wt.eu Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=1wt.eu Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=1wt.eu header.i=@1wt.eu header.b="LOP9AFZv" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1wt.eu; s=mail; t=1779005442; bh=XgBqwimChJY5f7lsXtKeVFkWbgAWxzp9r+TB1X/uypE=; h=From:Message-ID:From; b=LOP9AFZvztfA4toZ50xyBKgz78JKAFlVqZzXILw6eL5nj4pGV+kZAxhiNSAisAjEi xiGTIoYr4RGJ3pHEocwCQEr5TisTFA2oGgfiEQNwqSoiuBfj9asygsTupoXbFCEJNS /SYiIdTktyS5YxGNBKmPvsZ3hPPFhCbN+5fYp/6M= Received: from 1wt.eu (ded1.1wt.eu [163.172.96.212]) by mta1.formilux.org (Postfix) with ESMTP id 18319C0975; Sun, 17 May 2026 10:10:42 +0200 (CEST) Date: Sun, 17 May 2026 10:10:41 +0200 From: Willy Tarreau To: Afi0 Cc: hch@lst.de, linux-kernel@vger.kernel.org, robin.murphy@arm.com Subject: Re: [PATCH] dma: pool: fix racy refill check in dma_alloc_from_pool() Message-ID: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: On Sun, May 17, 2026 at 07:43:03AM +0000, Afi0 wrote: > > From d5e6f7a8b9c0d5e6f7a8b9c0d5e6f7a8b9c0d5e6 Mon Sep 17 00:00:00 2001 > From: Andrii Kuchmenko > Date: Sat, 16 May 2026 12:56:00 +0000 > Subject: [PATCH] dma: pool: fix racy refill check in dma_alloc_from_pool() > > The availability check after gen_pool_alloc() is not synchronized with > concurrent allocations on other CPUs: > > addr = gen_pool_alloc(pool, size); /* (A) alloc succeeds */ > if (!addr) > return NULL; > ... > if (gen_pool_avail(pool) < atomic_pool_size) /* (B) racy read */ > schedule_work(&atomic_pool_work); /* (C) may not fire */ > > Between (A) and (B), concurrent CPUs can drain the pool completely. > CPU0 reads gen_pool_avail() at (B) and sees a stale non-zero value, > decides not to schedule the refill worker. The pool remains at zero > until an unrelated event triggers the worker. During this window all > GFP_ATOMIC and GFP_NOWAIT callers receive NULL from dma_alloc_coherent() > with no indication of the root cause. > > Drivers that do not check the return value of dma_alloc_coherent() in > atomic context will NULL-deref (kernel oops/panic). Drivers that do > check it will silently drop operations: packet loss in network drivers, > I/O failure in storage drivers, device hangs in GPU/media drivers. > > Confirmed present in v6.14-rc3 (mainline). The pattern is unchanged > since its introduction in commit d3f1d56c2e0e. > > Untrusted user trigger: indirect, via drivers that call dma_alloc_coherent() > in atomic context on behalf of user operations (virtio-net MSG_ZEROCOPY, > USB bulk transfers from plugdev group). Direct kernel-internal trigger > requires driving alloc/free pressure on a DMA-capable device. > > Fix: remove the racy conditional check and call schedule_work() > unconditionally on every successful allocation. schedule_work() is > idempotent -- if the work item is already pending or running, the call > is a no-op. The workqueue deduplicates concurrent schedule_work() calls > naturally, so overhead is bounded to one work item per alloc burst. > The worker itself checks whether expansion is actually needed, so > spurious calls are harmless. > > Fixes: d3f1d56c2e0e ("dma-pool: add additional atomic pools") > Cc: Christoph Hellwig > Cc: Robin Murphy > Cc: stable@vger.kernel.org > Signed-off-by: Afi0 ^^^^^ still not working here. willy