Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp3413651imm; Tue, 17 Jul 2018 04:34:57 -0700 (PDT) X-Google-Smtp-Source: AAOMgpfI37OJeosOSN3anfC+G20YDzQHk5t1hMY16242OrMY1U6TCkUpOeUy2ypKffAClyh1ytiJ X-Received: by 2002:a17:902:292b:: with SMTP id g40-v6mr1271389plb.273.1531827297614; Tue, 17 Jul 2018 04:34:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531827297; cv=none; d=google.com; s=arc-20160816; b=VnGeoVco7n//W2Gba4BNrvkgKRbynu96yonfsaMCiUQmtC6EgiaVBfXj9AiGFPQlEy Eg+zrLPpTFICUWdxG/O1kqgQVZ9P25wHe/pcd3Ef+d3BhK0c/ig6R2Y03tPIa+BO/fwK w82PGffoz5Z+tT+Ma8i6/dBbYDj1pqsxXxRAUK9tAXkWbir6p764bgcf6xhZ/C428vHT +CAnBI2QV9MIfQjkj31eqMSbq1qWefpwNSJTlYr+pahJd6pCe9MGDGYZvsIfnGPakJhl IRNFFslAGnYSgeYFXr2O1GGAs15lMFz/6D8QR14I1pmeQHg0jG54mW/NYxfHydU1NTBw ldkA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature:arc-authentication-results; bh=XtYwwGdPdl8VxPkgMROVyS53GDTk1qvByNuaXHUdN9I=; b=sa8QzSXI1tWliEZp4we/bQTTNF4K9I6clHZmAr4AhJfKrJ0uk6thGWYe+VP+DGMwyN Y+ky/PxF0itHQ3OSa4bFA5LHT6cxdk2fvmLtrbtUozPGrHSCjcUQ+EdB9isXQqWwsxyb 3cveRnxpiaFDAGlU9Q6zWNsDLmKU3S/eJDmsi40Kj7eKr0R96ZL9LsSqygNSviSYSegT 31t5/nCB2pRtyKMeWbqvWWynjRGaFmKo2ZveW6wr4DjXU+B8i4UlakYkEh3uK+6Er9Ka yBreftArL/ciswUaRJDRaYezgBEiNRr0Z5oK2SCyfmSTAPW4S6z7BcloF9K3jK9HJxls G07g== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=merlin.20170209 header.b=mASrF2Yz; 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 a12-v6si638591pgv.296.2018.07.17.04.34.42; Tue, 17 Jul 2018 04:34:57 -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; dkim=fail header.i=@infradead.org header.s=merlin.20170209 header.b=mASrF2Yz; 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 S1731093AbeGQMF6 (ORCPT + 99 others); Tue, 17 Jul 2018 08:05:58 -0400 Received: from merlin.infradead.org ([205.233.59.134]:40020 "EHLO merlin.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730131AbeGQMF5 (ORCPT ); Tue, 17 Jul 2018 08:05:57 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=XtYwwGdPdl8VxPkgMROVyS53GDTk1qvByNuaXHUdN9I=; b=mASrF2YzZfekND4zd+NseKhuP dzJjhnG7zC1zXVfZTKngCrjVQliAjzVQtoYAkUQjfKc+iAnBHYbELDYcgvyl/sWb1PvMkHrRGCYkf 512lQ8/edMG6iKzK+3yJibSCYm3mqAL65KL1I92BjKbksD/8QwX4Q1N2vFOvcAHtfHv7IZbBtqTsC u7NiaReEMTJvz+y9NoLtuW1DwTjc/46XKdh3SLpXs/LdQcd6XCxxzqp3H1wvtIEZKOAvsGkFjSMPy 0bI/lF2jCoSdUWcoAW9OBL6IyAquXLKCdDw9YCQ563xwJPIF7mPFJC4G/CjMmPFa9QePPumwfc0lr 4AV/xs1Fg==; 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 1ffOEV-0008Oi-GH; Tue, 17 Jul 2018 11:33:31 +0000 Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 2190C20275F3B; Tue, 17 Jul 2018 13:33:30 +0200 (CEST) Date: Tue, 17 Jul 2018 13:33:30 +0200 From: Peter Zijlstra To: songliubraving@fb.com, linux-kernel@vger.kernel.org, dave.hansen@intel.com, hpa@zytor.com, riel@surriel.com, tglx@linutronix.de, mingo@kernel.org, torvalds@linux-foundation.org Cc: linux-tip-commits@vger.kernel.org Subject: Re: [tip:x86/mm] x86/mm/tlb: Make lazy TLB mode lazier Message-ID: <20180717113330.GU2476@hirez.programming.kicks-ass.net> References: <20180716190337.26133-5-riel@surriel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.0 (2018-05-17) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jul 17, 2018 at 02:35:08AM -0700, tip-bot for Rik van Riel wrote: > @@ -242,17 +244,40 @@ void switch_mm_irqs_off(struct mm_struct *prev, struct mm_struct *next, > next->context.ctx_id); > > /* > + * Even in lazy TLB mode, the CPU should stay set in the > + * mm_cpumask. The TLB shootdown code can figure out from > + * from cpu_tlbstate.is_lazy whether or not to send an IPI. > */ > if (WARN_ON_ONCE(real_prev != &init_mm && > !cpumask_test_cpu(cpu, mm_cpumask(next)))) > cpumask_set_cpu(cpu, mm_cpumask(next)); > > + /* > + * If the CPU is not in lazy TLB mode, we are just switching > + * from one thread in a process to another thread in the same > + * process. No TLB flush required. > + */ > + if (!was_lazy) > + return; > + > + /* > + * Read the tlb_gen to check whether a flush is needed. > + * If the TLB is up to date, just use it. > + * The barrier synchronizes with the tlb_gen increment in > + * the TLB shootdown code. > + */ > + smp_mb(); What exactly is this smp_mb() ordering? The above comment is insufficient. Is it the cpumask_set_cpu() vs the atomic64_read() ? If so, should this not be smp_mb__after_atomic() (iow a NO-OP on x86) If it is not so, please fix the comment to explain things. > + next_tlb_gen = atomic64_read(&next->context.tlb_gen); > + if (this_cpu_read(cpu_tlbstate.ctxs[prev_asid].tlb_gen) == > + next_tlb_gen) > + return; > + > + /* > + * TLB contents went out of date while we were in lazy > + * mode. Fall through to the TLB switching code below. > + */ > + new_asid = prev_asid; > + need_flush = true;