Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

[PATCH] x86: improve algorithm in clflush_cache_range

67 views
Skip to first unread message

Ross Zwisler

unread,
Apr 28, 2015, 6:13:37 PM4/28/15
to linux-...@vger.kernel.org, Ross Zwisler, H. Peter Anvin, Thomas Gleixner, Ingo Molnar, x...@kernel.org, Borislav Petkov
The current algorithm used in clflush_cache_range() can cause the last
cache line of the buffer to be flushed twice. Fix that algorithm so
that each cache line will only be flushed once.

Signed-off-by: Ross Zwisler <ross.z...@linux.intel.com>
Reported-by: H. Peter Anvin <h...@zytor.com>
Cc: H. Peter Anvin <h...@zytor.com>
Cc: Thomas Gleixner <tg...@linutronix.de>
Cc: Ingo Molnar <mi...@redhat.com>
Cc: x...@kernel.org
Cc: Borislav Petkov <b...@suse.de>
---
arch/x86/mm/pageattr.c | 13 ++++++-------
1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
index 89af288ec674..338e507f95b8 100644
--- a/arch/x86/mm/pageattr.c
+++ b/arch/x86/mm/pageattr.c
@@ -129,16 +129,15 @@ within(unsigned long addr, unsigned long start, unsigned long end)
*/
void clflush_cache_range(void *vaddr, unsigned int size)
{
- void *vend = vaddr + size - 1;
+ unsigned long clflush_mask = boot_cpu_data.x86_clflush_size - 1;
+ char *vend = (char *)vaddr + size;
+ char *p;

mb();

- for (; vaddr < vend; vaddr += boot_cpu_data.x86_clflush_size)
- clflushopt(vaddr);
- /*
- * Flush any possible final partial cacheline:
- */
- clflushopt(vend);
+ for (p = (char *)((unsigned long)vaddr & ~clflush_mask);
+ p < vend; p += boot_cpu_data.x86_clflush_size)
+ clflushopt(p);

mb();
}
--
1.9.3

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majo...@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

Borislav Petkov

unread,
Apr 29, 2015, 6:29:12 AM4/29/15
to Ross Zwisler, linux-...@vger.kernel.org, H. Peter Anvin, Thomas Gleixner, Ingo Molnar, x...@kernel.org
On Tue, Apr 28, 2015 at 04:13:12PM -0600, Ross Zwisler wrote:
> The current algorithm used in clflush_cache_range() can cause the last
> cache line of the buffer to be flushed twice. Fix that algorithm so
> that each cache line will only be flushed once.
>
> Signed-off-by: Ross Zwisler <ross.z...@linux.intel.com>
> Reported-by: H. Peter Anvin <h...@zytor.com>
> Cc: H. Peter Anvin <h...@zytor.com>
> Cc: Thomas Gleixner <tg...@linutronix.de>
> Cc: Ingo Molnar <mi...@redhat.com>
> Cc: x...@kernel.org
> Cc: Borislav Petkov <b...@suse.de>
> ---
> arch/x86/mm/pageattr.c | 13 ++++++-------
> 1 file changed, 6 insertions(+), 7 deletions(-)

Applied, thanks.

--
Regards/Gruss,
Boris.

ECO tip #101: Trim your mails when you reply.
--
0 new messages