From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.8 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_PASS, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C7C11C04EB9 for ; Mon, 3 Dec 2018 17:15:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 8FB282087F for ; Mon, 3 Dec 2018 17:15:02 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="ys8dXP2j" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8FB282087F Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727011AbeLCROr (ORCPT ); Mon, 3 Dec 2018 12:14:47 -0500 Received: from merlin.infradead.org ([205.233.59.134]:36688 "EHLO merlin.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726997AbeLCROr (ORCPT ); Mon, 3 Dec 2018 12:14:47 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=Content-Type:MIME-Version:References: Subject:Cc:To:From:Date:Message-Id:Sender:Reply-To:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=htZ08rlxgS2BEec6pWnM6IPnKncVCK07MaVOAwK8DCU=; b=ys8dXP2jF6pNUrWZGLgUD6+8mK vXmEIJFGUaTHENum4RAfeGYXRcXKTPdVV6pKTU5BO+wiafIUy+aVlHmZvCJgxAIG5irdD1SQ88oDA 0I3GCN2JyiRM27geRlj3rw2hXyidQJkrorKANmJJlJr+ULMA3sXBbGjibGj28T4brvZ8kMXvysDGo B8NJqIbbVhibPrbAkIE6yegfePd/ikVKuAPjet7cMylLWJ69PfE/Z7cjGQ9vaQH0DWtZgaJQuH888 JqEEugA59M+ftHVEiVjl05sCGzMz+qN52chPQeJxjKCD0sx96aTczwxh0xlhxh1Ck1XHGpoDZ8xse 5Sezr5FA==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=hirez.programming.kicks-ass.net) by merlin.infradead.org with esmtpsa (Exim 4.90_1 #2 (Red Hat Linux)) id 1gTrni-0001H9-1s; Mon, 03 Dec 2018 17:14:39 +0000 Received: by hirez.programming.kicks-ass.net (Postfix, from userid 0) id 3460C2029F4CD; Mon, 3 Dec 2018 18:14:26 +0100 (CET) Message-Id: <20181203171043.626999883@infradead.org> User-Agent: quilt/0.65 Date: Mon, 03 Dec 2018 18:03:52 +0100 From: Peter Zijlstra To: dave.hansen@intel.com, luto@kernel.org, peterz@infradead.org Cc: x86@kernel.org, Tom.StDenis@amd.com, linux-kernel@vger.kernel.org Subject: [RFC][PATCH 09/10] x86/mm/cpa: Better use clflushopt References: <20181203170343.054618965@infradead.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Currently we issue an MFENCE before and after flushing a range. This means that if we flush a bunch of single page ranges -- like with the cpa array, we issue a whole bunch of superfluous MFENCEs. Reorgainze the code a little to avoid this. Signed-off-by: Peter Zijlstra (Intel) --- arch/x86/mm/pageattr.c | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) --- a/arch/x86/mm/pageattr.c +++ b/arch/x86/mm/pageattr.c @@ -251,15 +251,7 @@ static unsigned long __cpa_addr(struct c * Flushing functions */ -/** - * clflush_cache_range - flush a cache range with clflush - * @vaddr: virtual start address - * @size: number of bytes to flush - * - * 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) +static void clflush_cache_range_opt(void *vaddr, unsigned int size) { const unsigned long clflush_size = boot_cpu_data.x86_clflush_size; void *p = (void *)((unsigned long)vaddr & ~(clflush_size - 1)); @@ -268,11 +260,22 @@ void clflush_cache_range(void *vaddr, un if (p >= vend) return; - mb(); - for (; p < vend; p += clflush_size) clflushopt(p); +} +/** + * clflush_cache_range - flush a cache range with clflush + * @vaddr: virtual start address + * @size: number of bytes to flush + * + * 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) +{ + mb(); + clflush_cache_range_opt(vaddr, size); mb(); } EXPORT_SYMBOL_GPL(clflush_cache_range); @@ -339,6 +342,7 @@ static void cpa_flush(struct cpa_data *d if (!cache) return; + mb(); for (i = 0; i < cpa->numpages; i++) { unsigned long addr = __cpa_addr(cpa, i); unsigned int level; @@ -349,8 +353,9 @@ static void cpa_flush(struct cpa_data *d * Only flush present addresses: */ if (pte && (pte_val(*pte) & _PAGE_PRESENT)) - clflush_cache_range((void *)addr, PAGE_SIZE); + clflush_cache_range_opt((void *)addr, PAGE_SIZE); } + mb(); } static bool overlaps(unsigned long r1_start, unsigned long r1_end,