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] [thread-next>] [day] [month] [year] [list]
Date:	Mon, 23 Feb 2015 15:14:01 -0800
From:	"H. Peter Anvin" <hpa@...or.com>
To:	ross.zwisler@...ux.intel.com, hpa@...ux.intel.com,
	linux-kernel@...r.kernel.org, torvalds@...ux-foundation.org,
	bp@...e.de, mingo@...nel.org, tglx@...utronix.de,
	linux-tip-commits@...r.kernel.org
Subject: Re: [tip:x86/asm] x86/asm: Add support for the pcommit instruction

On 02/20/2015 02:31 AM, tip-bot for Ross Zwisler wrote:
> 
> This function shows how to properly use clwb/clflushopt/clflush
> and pcommit with appropriate fencing:
> 
> void flush_and_commit_buffer(void *vaddr, unsigned int size)
> {
> 	void *vend = vaddr + size - 1;
> 
> 	for (; vaddr < vend; vaddr += boot_cpu_data.x86_clflush_size)
> 		clwb(vaddr);
> 
> 	/* Flush any possible final partial cacheline */
> 	clwb(vend);
> 
> 	/*
> 	 * sfence to order clwb/clflushopt/clflush cache flushes
> 	 * mfence via mb() also works
> 	 */
> 	wmb();
> 
> 	/* pcommit and the required sfence for ordering */
> 	pcommit_sfence();
> }
> 

That may cause the same line to be flushed twice.  I would suggest,
instead, also removing the arithmetic on void *:

Totally untested, yadda yadda...

void flush_and_commit_buffer(void *vaddr, unsigned int size)
{
	unsigned long clflush_mask = boot_cpu_data.x86_clflush_size - 1;
 	char *vend = (char *)vaddr + size;
	char *p;

 	for (p = (char *)((unsigned long)vaddr & ~clflush_mask);
	     p < vend; p += boot_cpu_data.x86_clflush_size)
 		clwb(vaddr);

 	/*
 	 * sfence to order clwb/clflushopt/clflush cache flushes
 	 * mfence via mb() also works
 	 */
 	wmb();

 	/* pcommit and the required sfence for ordering */
 	pcommit_sfence();
}

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

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ