* [PATCH] x86/mm: Allow clflush_cache_range() to flush large ranges
@ 2026-11-30 6:57 Yang Wencheng
2026-11-30 15:02 ` Dave Hansen
0 siblings, 1 reply; 4+ messages in thread
From: Yang Wencheng @ 2026-11-30 6:57 UTC (permalink / raw)
To: x86
Cc: Yang Wencheng, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
Dave Hansen, H. Peter Anvin, Andy Lutomirski, Peter Zijlstra,
Mike Rapoport (Microsoft), Vishal Moola, Lorenzo Stoakes (ARM),
Coiby Xu, Arjan van de Ven, linux-kernel
clflush_cache_range() accepts an unsigned int size even though several
callers naturally pass size_t values. Ranges larger than UINT_MAX are
therefore truncated and only partially flushed.
Use size_t for the public interface and its internal helper so the
complete range is preserved.
Fixes: d7c8f21a8cad ("x86: cpa: move flush to cpa")
Signed-off-by: Yang Wencheng <east.moutain.yang@gmail.com>
---
arch/x86/include/asm/cacheflush.h | 2 +-
arch/x86/mm/pat/set_memory.c | 4 ++--
2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/arch/x86/include/asm/cacheflush.h b/arch/x86/include/asm/cacheflush.h
index b192d917a6d0..b3a2b5f1bef1 100644
--- a/arch/x86/include/asm/cacheflush.h
+++ b/arch/x86/include/asm/cacheflush.h
@@ -8,6 +8,6 @@
#include <asm-generic/cacheflush.h>
#include <asm/special_insns.h>
-void clflush_cache_range(void *addr, unsigned int size);
+void clflush_cache_range(void *addr, size_t size);
#endif /* _ASM_X86_CACHEFLUSH_H */
diff --git a/arch/x86/mm/pat/set_memory.c b/arch/x86/mm/pat/set_memory.c
index b1d5c5a0ffb4..d115a9afef47 100644
--- a/arch/x86/mm/pat/set_memory.c
+++ b/arch/x86/mm/pat/set_memory.c
@@ -325,7 +325,7 @@ static unsigned long __cpa_addr(struct cpa_data *cpa, unsigned long idx)
* Flushing functions
*/
-static void clflush_cache_range_opt(void *vaddr, unsigned int size)
+static void clflush_cache_range_opt(void *vaddr, size_t size)
{
const unsigned long clflush_size = boot_cpu_data.x86_clflush_size;
void *p = (void *)((unsigned long)vaddr & ~(clflush_size - 1));
@@ -346,7 +346,7 @@ static void clflush_cache_range_opt(void *vaddr, unsigned int size)
* CLFLUSHOPT is an unordered instruction which needs fencing with MFENCE or
* SFENCE to avoid ordering issues.
*/
-void clflush_cache_range(void *vaddr, unsigned int size)
+void clflush_cache_range(void *vaddr, size_t size)
{
mb();
clflush_cache_range_opt(vaddr, size);
base-commit: fe6ff8d5d675c01793b9f051d16055dd4aa75244
--
2.43.0
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] x86/mm: Allow clflush_cache_range() to flush large ranges
2026-11-30 6:57 [PATCH] x86/mm: Allow clflush_cache_range() to flush large ranges Yang Wencheng
@ 2026-11-30 15:02 ` Dave Hansen
2026-12-01 13:40 ` Wencheng Yang
0 siblings, 1 reply; 4+ messages in thread
From: Dave Hansen @ 2026-11-30 15:02 UTC (permalink / raw)
To: Yang Wencheng, x86
Cc: Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen,
H. Peter Anvin, Andy Lutomirski, Peter Zijlstra,
Mike Rapoport (Microsoft), Vishal Moola, Lorenzo Stoakes (ARM),
Coiby Xu, Arjan van de Ven, linux-kernel
On 11/29/26 22:57, Yang Wencheng wrote:
> clflush_cache_range() accepts an unsigned int size even though several
> callers naturally pass size_t values. Ranges larger than UINT_MAX are
> therefore truncated and only partially flushed.
>
> Use size_t for the public interface and its internal helper so the
> complete range is preserved.
Does this cause any practical problems?
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] x86/mm: Allow clflush_cache_range() to flush large ranges
2026-11-30 15:02 ` Dave Hansen
@ 2026-12-01 13:40 ` Wencheng Yang
2026-12-01 15:24 ` Arjan van de Ven
0 siblings, 1 reply; 4+ messages in thread
From: Wencheng Yang @ 2026-12-01 13:40 UTC (permalink / raw)
To: Dave Hansen
Cc: x86, Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen,
H. Peter Anvin, Andy Lutomirski, Peter Zijlstra,
Mike Rapoport (Microsoft), Vishal Moola, Lorenzo Stoakes (ARM),
Coiby Xu, Arjan van de Ven, linux-kernel
Yes. In my driver, I call clflush_cache_range() with a size greater than 4 GiB,
which causes the size argument to be truncated and only part of the intended
range to be flushed.
I don't see a reason why this API should limit the size to less than 4 GiB,
as flushing a memory range larger than 4 GiB is also a valid use case.
Thanks.
On Mon, Nov 30, 2026 at 11:02 PM Dave Hansen <dave.hansen@intel.com> wrote:
>
> On 11/29/26 22:57, Yang Wencheng wrote:
> > clflush_cache_range() accepts an unsigned int size even though several
> > callers naturally pass size_t values. Ranges larger than UINT_MAX are
> > therefore truncated and only partially flushed.
> >
> > Use size_t for the public interface and its internal helper so the
> > complete range is preserved.
>
> Does this cause any practical problems?
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] x86/mm: Allow clflush_cache_range() to flush large ranges
2026-12-01 13:40 ` Wencheng Yang
@ 2026-12-01 15:24 ` Arjan van de Ven
0 siblings, 0 replies; 4+ messages in thread
From: Arjan van de Ven @ 2026-12-01 15:24 UTC (permalink / raw)
To: Wencheng Yang, Dave Hansen
Cc: x86, Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen,
H. Peter Anvin, Andy Lutomirski, Peter Zijlstra,
Mike Rapoport (Microsoft), Vishal Moola, Lorenzo Stoakes (ARM),
Coiby Xu, linux-kernel
On 12/1/2026 5:40 AM, Wencheng Yang wrote:
> Yes. In my driver, I call clflush_cache_range() with a size greater than 4 GiB,
> which causes the size argument to be truncated and only part of the intended
> range to be flushed.
>
> I don't see a reason why this API should limit the size to less than 4 GiB,
> as flushing a memory range larger than 4 GiB is also a valid use case.
do you happen to have a public reference to the (GPL of course) source
code to this driver?
it's common to show both sides of the issue for API changes
> ms?
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-12-01 15:24 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-30 6:57 [PATCH] x86/mm: Allow clflush_cache_range() to flush large ranges Yang Wencheng
2026-11-30 15:02 ` Dave Hansen
2026-12-01 13:40 ` Wencheng Yang
2026-12-01 15:24 ` Arjan van de Ven
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®