From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752345AbbBWXO2 (ORCPT ); Mon, 23 Feb 2015 18:14:28 -0500 Received: from terminus.zytor.com ([198.137.202.10]:51441 "EHLO mail.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751591AbbBWXO1 (ORCPT ); Mon, 23 Feb 2015 18:14:27 -0500 Message-ID: <54EBB439.3040303@zytor.com> Date: Mon, 23 Feb 2015 15:14:01 -0800 From: "H. Peter Anvin" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.4.0 MIME-Version: 1.0 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 References: <1424367448-24254-1-git-send-email-ross.zwisler@linux.intel.com> In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.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(); }