lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <Z74nSu3q2b3sy5wY@dread.disaster.area>
Date: Wed, 26 Feb 2025 07:25:46 +1100
From: Dave Chinner <david@...morbit.com>
To: "Raphael S. Carvalho" <raphaelsc@...lladb.com>
Cc: linux-kernel@...r.kernel.org, linux-xfs@...r.kernel.org,
	linux-mm@...ck.org, linux-fsdevel@...r.kernel.org,
	djwong@...nel.org, hch@....de, willy@...radead.org
Subject: Re: [PATCH v3] mm: Fix error handling in __filemap_get_folio() with
 FGP_NOWAIT

On Mon, Feb 24, 2025 at 11:37:00AM -0300, Raphael S. Carvalho wrote:
> original report:
> https://lore.kernel.org/all/CAKhLTr1UL3ePTpYjXOx2AJfNk8Ku2EdcEfu+CH1sf3Asr=B-Dw@mail.gmail.com/T/
> 
> When doing buffered writes with FGP_NOWAIT, under memory pressure, the system
> returned ENOMEM despite there being plenty of available memory, to be reclaimed
> from page cache. The user space used io_uring interface, which in turn submits
> I/O with FGP_NOWAIT (the fast path).
....

> 
> diff --git a/mm/filemap.c b/mm/filemap.c
> index 804d7365680c..3e75dced0fd9 100644
> --- a/mm/filemap.c
> +++ b/mm/filemap.c
> @@ -1986,8 +1986,19 @@ struct folio *__filemap_get_folio(struct address_space *mapping, pgoff_t index,
>  
>  		if (err == -EEXIST)
>  			goto repeat;
> -		if (err)
> +		if (err) {
> +			/*
> +			 * When NOWAIT I/O fails to allocate folios this could
> +			 * be due to a nonblocking memory allocation and not
> +			 * because the system actually is out of memory.
> +			 * Return -EAGAIN so that there caller retries in a
> +			 * blocking fashion instead of propagating -ENOMEM
> +			 * to the application.
> +			 */
> +			if ((fgp_flags & FGP_NOWAIT) && err == -ENOMEM)
> +				err = -EAGAIN;
>  			return ERR_PTR(err);
> +		}
>  		/*
>  		 * filemap_add_folio locks the page, and for mmap
>  		 * we expect an unlocked page.

Looks good to me.

Reviewed-by: Dave Chinner <dchinner@...hat.com>

-- 
Dave Chinner
david@...morbit.com

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ