public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: "H. Peter Anvin" <hpa@zytor.com>
To: ross.zwisler@linux.intel.com, hpa@linux.intel.com,
	linux-kernel@vger.kernel.org, torvalds@linux-foundation.org,
	bp@suse.de, mingo@kernel.org, tglx@linutronix.de,
	linux-tip-commits@vger.kernel.org
Subject: Re: [tip:x86/asm] x86/asm: Add support for the pcommit instruction
Date: Mon, 23 Feb 2015 15:14:01 -0800	[thread overview]
Message-ID: <54EBB439.3040303@zytor.com> (raw)
In-Reply-To: <tip-719d359dc7b6be3e43d6661f192ceb980b10ee26@git.kernel.org>

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();
}


  reply	other threads:[~2015-02-23 23:14 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-02-19 17:37 [PATCH v4] x86: Add support for the pcommit instruction Ross Zwisler
2015-02-20 10:31 ` [tip:x86/asm] x86/asm: " tip-bot for Ross Zwisler
2015-02-23 23:14   ` H. Peter Anvin [this message]
2015-02-24  9:30     ` Borislav Petkov
2015-02-24 21:40       ` H. Peter Anvin
2015-02-24 21:41         ` H. Peter Anvin
2015-02-24 21:48           ` Ross Zwisler
2015-02-24 21:52             ` H. Peter Anvin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=54EBB439.3040303@zytor.com \
    --to=hpa@zytor.com \
    --cc=bp@suse.de \
    --cc=hpa@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-tip-commits@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=ross.zwisler@linux.intel.com \
    --cc=tglx@linutronix.de \
    --cc=torvalds@linux-foundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox