All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] mm/filemap: Fix readahead return types
@ 2021-05-10 20:12 Matthew Wilcox (Oracle)
  2021-05-10 22:27 ` Darrick J. Wong
  0 siblings, 1 reply; 3+ messages in thread
From: Matthew Wilcox (Oracle) @ 2021-05-10 20:12 UTC (permalink / raw)
  To: akpm
  Cc: Matthew Wilcox (Oracle), linux-mm, linux-fsdevel, linux-btrfs, linux-xfs

A readahead request will not allocate more memory than can be represented
by a size_t, even on systems that have HIGHMEM available.  Change the
length functions from returning an loff_t to a size_t.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
---
 fs/iomap/buffered-io.c  | 4 ++--
 include/linux/pagemap.h | 6 +++---
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/fs/iomap/buffered-io.c b/fs/iomap/buffered-io.c
index f2cd2034a87b..9023717c5188 100644
--- a/fs/iomap/buffered-io.c
+++ b/fs/iomap/buffered-io.c
@@ -394,7 +394,7 @@ void iomap_readahead(struct readahead_control *rac, const struct iomap_ops *ops)
 {
 	struct inode *inode = rac->mapping->host;
 	loff_t pos = readahead_pos(rac);
-	loff_t length = readahead_length(rac);
+	size_t length = readahead_length(rac);
 	struct iomap_readpage_ctx ctx = {
 		.rac	= rac,
 	};
@@ -402,7 +402,7 @@ void iomap_readahead(struct readahead_control *rac, const struct iomap_ops *ops)
 	trace_iomap_readahead(inode, readahead_count(rac));
 
 	while (length > 0) {
-		loff_t ret = iomap_apply(inode, pos, length, 0, ops,
+		ssize_t ret = iomap_apply(inode, pos, length, 0, ops,
 				&ctx, iomap_readahead_actor);
 		if (ret <= 0) {
 			WARN_ON_ONCE(ret == 0);
diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h
index a4bd41128bf3..e89df447fae3 100644
--- a/include/linux/pagemap.h
+++ b/include/linux/pagemap.h
@@ -997,9 +997,9 @@ static inline loff_t readahead_pos(struct readahead_control *rac)
  * readahead_length - The number of bytes in this readahead request.
  * @rac: The readahead request.
  */
-static inline loff_t readahead_length(struct readahead_control *rac)
+static inline size_t readahead_length(struct readahead_control *rac)
 {
-	return (loff_t)rac->_nr_pages * PAGE_SIZE;
+	return rac->_nr_pages * PAGE_SIZE;
 }
 
 /**
@@ -1024,7 +1024,7 @@ static inline unsigned int readahead_count(struct readahead_control *rac)
  * readahead_batch_length - The number of bytes in the current batch.
  * @rac: The readahead request.
  */
-static inline loff_t readahead_batch_length(struct readahead_control *rac)
+static inline size_t readahead_batch_length(struct readahead_control *rac)
 {
 	return rac->_batch_count * PAGE_SIZE;
 }
-- 
2.30.2


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] mm/filemap: Fix readahead return types
  2021-05-10 20:12 [PATCH] mm/filemap: Fix readahead return types Matthew Wilcox (Oracle)
@ 2021-05-10 22:27 ` Darrick J. Wong
  2021-05-10 23:17   ` Matthew Wilcox
  0 siblings, 1 reply; 3+ messages in thread
From: Darrick J. Wong @ 2021-05-10 22:27 UTC (permalink / raw)
  To: Matthew Wilcox (Oracle)
  Cc: akpm, linux-mm, linux-fsdevel, linux-btrfs, linux-xfs

On Mon, May 10, 2021 at 09:12:01PM +0100, Matthew Wilcox (Oracle) wrote:
> A readahead request will not allocate more memory than can be represented
> by a size_t, even on systems that have HIGHMEM available.  Change the
> length functions from returning an loff_t to a size_t.
> 
> Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>

Looks reasonable to me; is this a 5.13 bugfix or just something that
doesn't look right (i.e. save it for 5.14)?

Reviewed-by: Darrick J. Wong <djwong@kernel.org>

--D

> ---
>  fs/iomap/buffered-io.c  | 4 ++--
>  include/linux/pagemap.h | 6 +++---
>  2 files changed, 5 insertions(+), 5 deletions(-)
> 
> diff --git a/fs/iomap/buffered-io.c b/fs/iomap/buffered-io.c
> index f2cd2034a87b..9023717c5188 100644
> --- a/fs/iomap/buffered-io.c
> +++ b/fs/iomap/buffered-io.c
> @@ -394,7 +394,7 @@ void iomap_readahead(struct readahead_control *rac, const struct iomap_ops *ops)
>  {
>  	struct inode *inode = rac->mapping->host;
>  	loff_t pos = readahead_pos(rac);
> -	loff_t length = readahead_length(rac);
> +	size_t length = readahead_length(rac);
>  	struct iomap_readpage_ctx ctx = {
>  		.rac	= rac,
>  	};
> @@ -402,7 +402,7 @@ void iomap_readahead(struct readahead_control *rac, const struct iomap_ops *ops)
>  	trace_iomap_readahead(inode, readahead_count(rac));
>  
>  	while (length > 0) {
> -		loff_t ret = iomap_apply(inode, pos, length, 0, ops,
> +		ssize_t ret = iomap_apply(inode, pos, length, 0, ops,
>  				&ctx, iomap_readahead_actor);
>  		if (ret <= 0) {
>  			WARN_ON_ONCE(ret == 0);
> diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h
> index a4bd41128bf3..e89df447fae3 100644
> --- a/include/linux/pagemap.h
> +++ b/include/linux/pagemap.h
> @@ -997,9 +997,9 @@ static inline loff_t readahead_pos(struct readahead_control *rac)
>   * readahead_length - The number of bytes in this readahead request.
>   * @rac: The readahead request.
>   */
> -static inline loff_t readahead_length(struct readahead_control *rac)
> +static inline size_t readahead_length(struct readahead_control *rac)
>  {
> -	return (loff_t)rac->_nr_pages * PAGE_SIZE;
> +	return rac->_nr_pages * PAGE_SIZE;
>  }
>  
>  /**
> @@ -1024,7 +1024,7 @@ static inline unsigned int readahead_count(struct readahead_control *rac)
>   * readahead_batch_length - The number of bytes in the current batch.
>   * @rac: The readahead request.
>   */
> -static inline loff_t readahead_batch_length(struct readahead_control *rac)
> +static inline size_t readahead_batch_length(struct readahead_control *rac)
>  {
>  	return rac->_batch_count * PAGE_SIZE;
>  }
> -- 
> 2.30.2
> 

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] mm/filemap: Fix readahead return types
  2021-05-10 22:27 ` Darrick J. Wong
@ 2021-05-10 23:17   ` Matthew Wilcox
  0 siblings, 0 replies; 3+ messages in thread
From: Matthew Wilcox @ 2021-05-10 23:17 UTC (permalink / raw)
  To: Darrick J. Wong; +Cc: akpm, linux-mm, linux-fsdevel, linux-btrfs, linux-xfs

On Mon, May 10, 2021 at 03:27:56PM -0700, Darrick J. Wong wrote:
> On Mon, May 10, 2021 at 09:12:01PM +0100, Matthew Wilcox (Oracle) wrote:
> > A readahead request will not allocate more memory than can be represented
> > by a size_t, even on systems that have HIGHMEM available.  Change the
> > length functions from returning an loff_t to a size_t.
> > 
> > Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
> 
> Looks reasonable to me; is this a 5.13 bugfix or just something that
> doesn't look right (i.e. save it for 5.14)?
> 
> Reviewed-by: Darrick J. Wong <djwong@kernel.org>

Thanks!  Linus was unhappy about it, and I promised to fix it.  I leave
it up to Andrew whether he wants to see this in 5.13 or 5.14.

https://lore.kernel.org/linux-btrfs/CAHk-=wj1KRvb=hie1VUTGo1D_ckD+Suo0-M2Nh5Kek1Wu=2Ppw@mail.gmail.com/

(I went a little beyond what he was directly unhappy with and reviewed
all the readahead.*length users for unnecessary loff_t usage)

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-05-10 23:17 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-10 20:12 [PATCH] mm/filemap: Fix readahead return types Matthew Wilcox (Oracle)
2021-05-10 22:27 ` Darrick J. Wong
2021-05-10 23:17   ` Matthew Wilcox

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.