All of lore.kernel.org
 help / color / mirror / Atom feed
* [RFC PATCH] mm/highmem: VM_BUG_ON() if offset + len > PAGE_SIZE
@ 2022-04-24 10:48 Fabio M. De Francesco
  2022-04-25  1:47 ` Fabio M. De Francesco
  0 siblings, 1 reply; 4+ messages in thread
From: Fabio M. De Francesco @ 2022-04-24 10:48 UTC (permalink / raw)
  To: Ira Weiny, Andrew Morton, Matthew Wilcox (Oracle),
	Catalin Marinas, Will Deacon, Peter Collingbourne, linux-kernel
  Cc: Fabio M. De Francesco

Call VM_BUG_ON() if offset + len > PAGE_SIZE.

This is an RFC patch because I'm not sure if we actually need to BUG_ON(),
so I'd like to know what Maintainers and other developers think about this
proposal.

Please note that memset_page() uses VM_BUG_ON() to prevent the same issue.

Furthermore, I also cannot understand why memset_page() does not call
flush_dcache_page() after memset() but I suppose that the different
implementations of these two functions should be addressed in another RFC.

Signed-off-by: Fabio M. De Francesco <fmdefrancesco@gmail.com>
---
 include/linux/highmem.h | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/include/linux/highmem.h b/include/linux/highmem.h
index c3d562b5f0c1..bdb16d5f8148 100644
--- a/include/linux/highmem.h
+++ b/include/linux/highmem.h
@@ -349,6 +349,8 @@ static inline void memcpy_to_page(struct page *page, size_t offset,
 static inline void memzero_page(struct page *page, size_t offset, size_t len)
 {
 	char *addr = kmap_local_page(page);
+
+	VM_BUG_ON(offset + len > PAGE_SIZE);
 	memset(addr + offset, 0, len);
 	flush_dcache_page(page);
 	kunmap_local(addr);
-- 
2.34.1


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

* Re: [RFC PATCH] mm/highmem: VM_BUG_ON() if offset + len > PAGE_SIZE
  2022-04-24 10:48 [RFC PATCH] mm/highmem: VM_BUG_ON() if offset + len > PAGE_SIZE Fabio M. De Francesco
@ 2022-04-25  1:47 ` Fabio M. De Francesco
  2022-04-25 16:47   ` Ira Weiny
  0 siblings, 1 reply; 4+ messages in thread
From: Fabio M. De Francesco @ 2022-04-25  1:47 UTC (permalink / raw)
  To: Ira Weiny, Andrew Morton, Matthew Wilcox (Oracle),
	Catalin Marinas, Will Deacon, Peter Collingbourne, linux-kernel

On domenica 24 aprile 2022 12:48:06 CEST Fabio M. De Francesco wrote:
> Call VM_BUG_ON() if offset + len > PAGE_SIZE.
> 
> This is an RFC patch because I'm not sure if we actually need to 
BUG_ON(),

Actually I considered VM_BUG_ON() for consistency with the other functions 
in highmem.h

What about VM_WARN_ON_ONCE() here and also in memset_page?

Thanks,

Fabio

> so I'd like to know what Maintainers and other developers think about 
this
> proposal.
> 
> Please note that memset_page() uses VM_BUG_ON() to prevent the same 
issue.
> 
> Furthermore, I also cannot understand why memset_page() does not call
> flush_dcache_page() after memset() but I suppose that the different
> implementations of these two functions should be addressed in another 
RFC.
> 
> Signed-off-by: Fabio M. De Francesco <fmdefrancesco@gmail.com>
> ---
>  include/linux/highmem.h | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/include/linux/highmem.h b/include/linux/highmem.h
> index c3d562b5f0c1..bdb16d5f8148 100644
> --- a/include/linux/highmem.h
> +++ b/include/linux/highmem.h
> @@ -349,6 +349,8 @@ static inline void memcpy_to_page(struct page *page, 
size_t offset,
>  static inline void memzero_page(struct page *page, size_t offset, size_t 
len)
>  {
>  	char *addr = kmap_local_page(page);
> +
> +	VM_BUG_ON(offset + len > PAGE_SIZE);
>  	memset(addr + offset, 0, len);
>  	flush_dcache_page(page);
>  	kunmap_local(addr);
> -- 
> 2.34.1
> 
> 





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

* Re: [RFC PATCH] mm/highmem: VM_BUG_ON() if offset + len > PAGE_SIZE
  2022-04-25  1:47 ` Fabio M. De Francesco
@ 2022-04-25 16:47   ` Ira Weiny
  2022-04-25 20:05     ` Fabio M. De Francesco
  0 siblings, 1 reply; 4+ messages in thread
From: Ira Weiny @ 2022-04-25 16:47 UTC (permalink / raw)
  To: Fabio M. De Francesco
  Cc: Andrew Morton, Matthew Wilcox (Oracle),
	Catalin Marinas, Will Deacon, Peter Collingbourne, linux-kernel

On Mon, Apr 25, 2022 at 03:47:38AM +0200, Fabio M. De Francesco wrote:
> On domenica 24 aprile 2022 12:48:06 CEST Fabio M. De Francesco wrote:
> > Call VM_BUG_ON() if offset + len > PAGE_SIZE.
> > 
> > This is an RFC patch because I'm not sure if we actually need to 
> BUG_ON(),
> 
> Actually I considered VM_BUG_ON() for consistency with the other functions 
> in highmem.h
> 
> What about VM_WARN_ON_ONCE() here and also in memset_page?

For consistency leave this as a VM_BUG_ON[1]

I've been down a similar path[2] and there was a long discussion about it.[3]

In the end we settled on VM_BUG_ON.[4]

As to the addition of flush_dcache_page().  There was a discussion here.

https://lore.kernel.org/lkml/CAHk-=wiKac4t-fOP_3fAf7nETfFLhT3ShmRmBq2J96y6jAr56Q@mail.gmail.com/

Ira

[1] https://lore.kernel.org/lkml/20210209205249.GB2975576@iweiny-DESK2.sc.intel.com/

[2] https://lore.kernel.org/lkml/20201209022250.GP1563847@iweiny-DESK2.sc.intel.com/

[3] https://lore.kernel.org/lkml/20201208213255.GO1563847@iweiny-DESK2.sc.intel.com/

[4] https://lore.kernel.org/lkml/20210210174928.3156073-1-ira.weiny@intel.com/

> 
> Thanks,
> 
> Fabio
> 
> > so I'd like to know what Maintainers and other developers think about 
> this
> > proposal.
> > 
> > Please note that memset_page() uses VM_BUG_ON() to prevent the same 
> issue.
> > 
> > Furthermore, I also cannot understand why memset_page() does not call
> > flush_dcache_page() after memset() but I suppose that the different
> > implementations of these two functions should be addressed in another 
> RFC.
> > 
> > Signed-off-by: Fabio M. De Francesco <fmdefrancesco@gmail.com>
> > ---
> >  include/linux/highmem.h | 2 ++
> >  1 file changed, 2 insertions(+)
> > 
> > diff --git a/include/linux/highmem.h b/include/linux/highmem.h
> > index c3d562b5f0c1..bdb16d5f8148 100644
> > --- a/include/linux/highmem.h
> > +++ b/include/linux/highmem.h
> > @@ -349,6 +349,8 @@ static inline void memcpy_to_page(struct page *page, 
> size_t offset,
> >  static inline void memzero_page(struct page *page, size_t offset, size_t 
> len)
> >  {
> >  	char *addr = kmap_local_page(page);
> > +
> > +	VM_BUG_ON(offset + len > PAGE_SIZE);
> >  	memset(addr + offset, 0, len);
> >  	flush_dcache_page(page);
> >  	kunmap_local(addr);
> > -- 
> > 2.34.1
> > 
> > 
> 
> 
> 
> 

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

* Re: [RFC PATCH] mm/highmem: VM_BUG_ON() if offset + len > PAGE_SIZE
  2022-04-25 16:47   ` Ira Weiny
@ 2022-04-25 20:05     ` Fabio M. De Francesco
  0 siblings, 0 replies; 4+ messages in thread
From: Fabio M. De Francesco @ 2022-04-25 20:05 UTC (permalink / raw)
  To: Ira Weiny
  Cc: Andrew Morton, Matthew Wilcox (Oracle),
	Catalin Marinas, Will Deacon, Peter Collingbourne, linux-kernel

On lunedì 25 aprile 2022 18:47:18 CEST Ira Weiny wrote:
> On Mon, Apr 25, 2022 at 03:47:38AM +0200, Fabio M. De Francesco wrote:
> > On domenica 24 aprile 2022 12:48:06 CEST Fabio M. De Francesco wrote:
> > > Call VM_BUG_ON() if offset + len > PAGE_SIZE.
> > > 
> > > This is an RFC patch because I'm not sure if we actually need to 
> > BUG_ON(),
> > 
> > Actually I considered VM_BUG_ON() for consistency with the other 
functions 
> > in highmem.h
> > 
> > What about VM_WARN_ON_ONCE() here and also in memset_page?
> 
> For consistency leave this as a VM_BUG_ON[1]
> 
> I've been down a similar path[2] and there was a long discussion about 
it.[3]
> 
> In the end we settled on VM_BUG_ON.[4]

Thanks for your reply and for providing so many helpful links :)

I just read the ones related to VM_BUG_ON() (I don't have time for 
flush_dcache_page() today). Since the consensus for these kinds of issues 
is in favor of using VM_BUG_ON(), that's OK for me.

I will send a "real" patch by tomorrow.

Again, thanks,

Fabio

> As to the addition of flush_dcache_page().  There was a discussion here.
> 
> https://lore.kernel.org/lkml/CAHk-=wiKac4t-fOP_3fAf7nETfFLhT3ShmRmBq2J96y6jAr56Q@mail.gmail.com/
> 
> Ira
> 
> [1] https://lore.kernel.org/lkml/20210209205249.GB2975576@iweiny-DESK2.sc.intel.com/
> 
> [2] https://lore.kernel.org/lkml/20201209022250.GP1563847@iweiny-DESK2.sc.intel.com/
> 
> [3] https://lore.kernel.org/lkml/20201208213255.GO1563847@iweiny-DESK2.sc.intel.com/
> 
> [4] https://lore.kernel.org/lkml/20210210174928.3156073-1-ira.weiny@intel.com/




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

end of thread, other threads:[~2022-04-25 20:05 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-24 10:48 [RFC PATCH] mm/highmem: VM_BUG_ON() if offset + len > PAGE_SIZE Fabio M. De Francesco
2022-04-25  1:47 ` Fabio M. De Francesco
2022-04-25 16:47   ` Ira Weiny
2022-04-25 20:05     ` Fabio M. De Francesco

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.