Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp3826812ybl; Mon, 26 Aug 2019 00:52:26 -0700 (PDT) X-Google-Smtp-Source: APXvYqzQjihAJg0pmJ0H6ydoQGCee2eodczsnS4jaYm3eEqIOKrM0H756n4sltV1ZFILCuMF1CP4 X-Received: by 2002:a17:90a:c08f:: with SMTP id o15mr18890732pjs.31.1566805946122; Mon, 26 Aug 2019 00:52:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1566805946; cv=none; d=google.com; s=arc-20160816; b=tuiws9zQScBJf3xsg/epWZ3P1mhzdEFo9T2aO5deHjVRkmNv1dZTEglER5Ef88EV/4 A6L5Etr1EvqbdfXL6I/MWzmqNm0GzENdqqcEsEVDht8/VXz8xLz0EmkvIeQHjMZJ1WFf zV9hmFB7Klgrsuo5Os7QL/jUQoqjr3C7ldqM9/YAiLKwT5/JAHvbn7NDFT6na14wk9ky MXeArozZfYxw9UvYz6B1JSiktqhhGUeIcKAqV5/dwxjhfxX3WndpAIWCx32GxWgoZu1a mgVxwN/WyPHRD/tAKBvn1XXlyn7oK2wWVsTSes73nF4hLBsQli+g4l/pFM1Bl99IDzec 803w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=EqhzEPG9Ju+yD6G97nMG3Qn5yJMbXdC9ILK2ifQbzt0=; b=vKDhNLUaRngJMAF/GFOIgWZ6WfOcanFKX58nxOZw+VrNx4nzsnrfxebE6UjjS90Ovm b1gecYY1vFg49vmRGo/ShY2Oxz4ES4KsCsMZWnBbQNkD/Uy16cd5QZYi2ICx7eXfxWJf afUwaGsZT7nRq+f0kn/D/ttRxyK9Y6ML0JTJorOsJV4mE2BOmXu2fYyux3B/rh4zJHK0 ilf34GVhpPuru/kOQ9XOcXVqkw+ZJKR1otGuRCrS/x3yfj9+JkkEa+qdZnEIDkHv71x5 aytp5KFgO6n55HvN7SjJ83n/qdPi9dW1VN8yjrjGUGKgrmDlPxuUKEejkmpClYt9ABEi TeWA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i11si8439471pgc.65.2019.08.26.00.52.10; Mon, 26 Aug 2019 00:52:26 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730177AbfHZHvW (ORCPT + 99 others); Mon, 26 Aug 2019 03:51:22 -0400 Received: from mx2.suse.de ([195.135.220.15]:34864 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728198AbfHZHvW (ORCPT ); Mon, 26 Aug 2019 03:51:22 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 77D43AF11; Mon, 26 Aug 2019 07:51:20 +0000 (UTC) Subject: Re: [RFC PATCH v2 1/3] x86/mm/tlb: Change __flush_tlb_one_user interface To: Nadav Amit , Andy Lutomirski , Dave Hansen Cc: Peter Zijlstra , Stefano Stabellini , x86@kernel.org, Thomas Gleixner , xen-devel@lists.xenproject.org, Boris Ostrovsky , Ingo Molnar , linux-kernel@vger.kernel.org References: <20190823225248.15597-1-namit@vmware.com> <20190823225248.15597-2-namit@vmware.com> From: Juergen Gross Message-ID: Date: Mon, 26 Aug 2019 09:51:19 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.8.0 MIME-Version: 1.0 In-Reply-To: <20190823225248.15597-2-namit@vmware.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 24.08.19 00:52, Nadav Amit wrote: > __flush_tlb_one_user() currently flushes a single entry, and flushes it > both in the kernel and user page-tables, when PTI is enabled. > > Change __flush_tlb_one_user() and related interfaces into > __flush_tlb_range() that flushes a range and does not flush the user > page-table. > > This refactoring is needed for the next patch, but regardless makes > sense and has several advantages. First, only Xen-PV, which does not > use PTI, implements the paravirtual interface of flush_tlb_one_user() so > nothing is broken by separating the user and kernel page-table flushes, > and the interface is more intuitive. > > Second, INVLPG can flush unrelated mappings, and it is also a > serializing instruction. It is better to have a tight loop that flushes > the entries. > > Third, currently __flush_tlb_one_kernel() also flushes the user > page-tables, which is not needed. This allows to avoid this redundant > flush. > > Cc: Boris Ostrovsky > Cc: Juergen Gross > Cc: Stefano Stabellini > Cc: xen-devel@lists.xenproject.org > Signed-off-by: Nadav Amit > --- > arch/x86/include/asm/paravirt.h | 5 ++-- > arch/x86/include/asm/paravirt_types.h | 3 ++- > arch/x86/include/asm/tlbflush.h | 24 +++++------------ > arch/x86/kernel/paravirt.c | 7 ++--- > arch/x86/mm/tlb.c | 39 ++++++++++++++++++++++----- > arch/x86/xen/mmu_pv.c | 21 +++++++++------ > 6 files changed, 62 insertions(+), 37 deletions(-) ... > diff --git a/arch/x86/xen/mmu_pv.c b/arch/x86/xen/mmu_pv.c > index 48f7c7eb4dbc..ed68657f5e77 100644 > --- a/arch/x86/xen/mmu_pv.c > +++ b/arch/x86/xen/mmu_pv.c > @@ -1325,22 +1325,27 @@ static noinline void xen_flush_tlb(void) > preempt_enable(); > } > > -static void xen_flush_tlb_one_user(unsigned long addr) > +static void xen_flush_tlb_range(unsigned long start, unsigned long end, > + u8 stride_shift) > { > struct mmuext_op *op; > struct multicall_space mcs; > - > - trace_xen_mmu_flush_tlb_one_user(addr); > + unsigned long addr; > > preempt_disable(); > > mcs = xen_mc_entry(sizeof(*op)); > op = mcs.args; > - op->cmd = MMUEXT_INVLPG_LOCAL; > - op->arg1.linear_addr = addr & PAGE_MASK; > - MULTI_mmuext_op(mcs.mc, op, 1, NULL, DOMID_SELF); > > - xen_mc_issue(PARAVIRT_LAZY_MMU); > + for (addr = start; addr < end; addr += 1ul << stride_shift) { > + trace_xen_mmu_flush_tlb_one_user(addr); > + > + op->cmd = MMUEXT_INVLPG_LOCAL; > + op->arg1.linear_addr = addr & PAGE_MASK; > + MULTI_mmuext_op(mcs.mc, op, 1, NULL, DOMID_SELF); > + > + xen_mc_issue(PARAVIRT_LAZY_MMU); > + } For this kind of usage (a loop) you should: - replace the call of xen_mc_entry() with xen_mc_batch() - use xen_extend_mmuext_op() for each loop iteration - call xen_mc_issue() after the loop Additionally I'd like you to replace trace_xen_mmu_flush_tlb_one_user() with trace_xen_mmu_flush_tlb_range() taking all three parameters and keep it where it was (out of the loop). The paravirt parts seem to be okay. Juergen