Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp4980262imm; Tue, 9 Oct 2018 08:01:41 -0700 (PDT) X-Google-Smtp-Source: ACcGV61OWl9frS9XPVdwpAITo8cRH+Xb6sOk1sX7DwrIdfxCaqsvaFxZ1eIAzSm2nrgHebtGwu28 X-Received: by 2002:a63:a362:: with SMTP id v34-v6mr26462409pgn.261.1539097301171; Tue, 09 Oct 2018 08:01:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539097301; cv=none; d=google.com; s=arc-20160816; b=S8XCpaSoEwzRYFsl8pkpCDI9hhb0ueFyTHeHbBsSBcslJqI2E/HNDAb+L35SKry6SA S6S16lmkGpK4QiOwRBGYeP1CEH//PFobRIKEHw+6alMjZE00gN8V0cEh2A0YSsmkDrgc uGeWy6e16UcCaTREumjtsiWAWiesnlo2eUsgH1pVJoL/21Gq4+vWSr84RQ9hzK7jQulr FjMGN6T0fSLVCniNxx0m6ZrJ4e5xRXG1RzxXMSU1lZopnYMyrjbXv7dQtm+G8Ci9bnlr 7O3sLcssvsrTWTIAWc2yWQEu4guvDBSogPxmrTg7HWqlSHMuwdgNC+0H5FLeQi2ZsDJu 5mNA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-disposition :content-transfer-encoding:mime-version:robot-unsubscribe:robot-id :git-commit-id:subject:to:references:in-reply-to:reply-to:cc :message-id:from:date; bh=IMpQX+3++ePm1VjfToYPJn+8HAMaE6SdxVu64hng6xU=; b=eeiOAelf38qz13ZbtC8b8vuzNj4DgneZRbFu3ndPYpGIZrACxCzeTWatR42vvm8c8N tYOXNTdBl12FpYlk8AbPlpvQJlYUnea9G48FhcnB9KIu126s7lTgPsPdzpa/U+4ospFj caNOUPzcD4CVkrX4bPdODLJQMwhsFRO7iEuQo610f7b/unRPZlXvJTKEufPX1yNR40b0 PsjcFSzOVAFGehgT2w/xL/rZyyl8ZrT48z4zZaPY3tlgWeivpTvkAyKaNJXcXwil8q93 4BFeSzhP5t2D+2c3NuWLvI3JlUVG/DErla7ymb6+ikmzF2eQaWRpjejvOKm2TOpWJimw Aptw== 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 r29-v6si15512075pff.262.2018.10.09.08.01.18; Tue, 09 Oct 2018 08:01:41 -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 S1727233AbeJIWQY (ORCPT + 99 others); Tue, 9 Oct 2018 18:16:24 -0400 Received: from terminus.zytor.com ([198.137.202.136]:35787 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726418AbeJIWQY (ORCPT ); Tue, 9 Oct 2018 18:16:24 -0400 Received: from terminus.zytor.com (localhost [127.0.0.1]) by terminus.zytor.com (8.15.2/8.15.2) with ESMTPS id w99EwgoA1080935 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Tue, 9 Oct 2018 07:58:42 -0700 Received: (from tipbot@localhost) by terminus.zytor.com (8.15.2/8.15.2/Submit) id w99EwgtY1080931; Tue, 9 Oct 2018 07:58:42 -0700 Date: Tue, 9 Oct 2018 07:58:42 -0700 X-Authentication-Warning: terminus.zytor.com: tipbot set sender to tipbot@zytor.com using -f From: tip-bot for Rik van Riel Message-ID: Cc: linux-kernel@vger.kernel.org, mingo@kernel.org, tglx@linutronix.de, torvalds@linux-foundation.org, luto@kernel.org, peterz@infradead.org, hpa@zytor.com, riel@surriel.com, dave.hansen@intel.com Reply-To: torvalds@linux-foundation.org, peterz@infradead.org, luto@kernel.org, hpa@zytor.com, riel@surriel.com, dave.hansen@intel.com, mingo@kernel.org, tglx@linutronix.de, linux-kernel@vger.kernel.org In-Reply-To: <20180716190337.26133-4-riel@surriel.com> References: <20180716190337.26133-4-riel@surriel.com> To: linux-tip-commits@vger.kernel.org Subject: [tip:x86/mm] x86/mm/tlb: Restructure switch_mm_irqs_off() Git-Commit-ID: 12c4d978fd170ccdd7260ec11f93b11e46904228 X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline X-Spam-Status: No, score=-0.7 required=5.0 tests=ALL_TRUSTED,BAYES_00, DATE_IN_FUTURE_48_96 autolearn=no autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on terminus.zytor.com Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: 12c4d978fd170ccdd7260ec11f93b11e46904228 Gitweb: https://git.kernel.org/tip/12c4d978fd170ccdd7260ec11f93b11e46904228 Author: Rik van Riel AuthorDate: Tue, 25 Sep 2018 23:58:39 -0400 Committer: Peter Zijlstra CommitDate: Tue, 9 Oct 2018 16:51:11 +0200 x86/mm/tlb: Restructure switch_mm_irqs_off() Move some code that will be needed for the lazy -> !lazy state transition when a lazy TLB CPU has gotten out of date. No functional changes, since the if (real_prev == next) branch always returns. (cherry picked from commit 61d0beb5796ab11f7f3bf38cb2eccc6579aaa70b) Cc: npiggin@gmail.com Cc: efault@gmx.de Cc: will.deacon@arm.com Cc: Linus Torvalds Cc: Thomas Gleixner Cc: songliubraving@fb.com Cc: kernel-team@fb.com Cc: hpa@zytor.com Suggested-by: Andy Lutomirski Signed-off-by: Rik van Riel Acked-by: Dave Hansen Signed-off-by: Ingo Molnar Signed-off-by: Peter Zijlstra (Intel) Link: http://lkml.kernel.org/r/20180716190337.26133-4-riel@surriel.com --- arch/x86/mm/tlb.c | 66 +++++++++++++++++++++++++++---------------------------- 1 file changed, 33 insertions(+), 33 deletions(-) diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c index 54a5870190a6..9fb30d27854b 100644 --- a/arch/x86/mm/tlb.c +++ b/arch/x86/mm/tlb.c @@ -187,6 +187,8 @@ void switch_mm_irqs_off(struct mm_struct *prev, struct mm_struct *next, u16 prev_asid = this_cpu_read(cpu_tlbstate.loaded_mm_asid); unsigned cpu = smp_processor_id(); u64 next_tlb_gen; + bool need_flush; + u16 new_asid; /* * NB: The scheduler will call us with prev == next when switching @@ -252,8 +254,6 @@ void switch_mm_irqs_off(struct mm_struct *prev, struct mm_struct *next, return; } else { - u16 new_asid; - bool need_flush; u64 last_ctx_id = this_cpu_read(cpu_tlbstate.last_ctx_id); /* @@ -308,44 +308,44 @@ void switch_mm_irqs_off(struct mm_struct *prev, struct mm_struct *next, /* Let nmi_uaccess_okay() know that we're changing CR3. */ this_cpu_write(cpu_tlbstate.loaded_mm, LOADED_MM_SWITCHING); barrier(); + } - if (need_flush) { - this_cpu_write(cpu_tlbstate.ctxs[new_asid].ctx_id, next->context.ctx_id); - this_cpu_write(cpu_tlbstate.ctxs[new_asid].tlb_gen, next_tlb_gen); - load_new_mm_cr3(next->pgd, new_asid, true); - - /* - * NB: This gets called via leave_mm() in the idle path - * where RCU functions differently. Tracing normally - * uses RCU, so we need to use the _rcuidle variant. - * - * (There is no good reason for this. The idle code should - * be rearranged to call this before rcu_idle_enter().) - */ - trace_tlb_flush_rcuidle(TLB_FLUSH_ON_TASK_SWITCH, TLB_FLUSH_ALL); - } else { - /* The new ASID is already up to date. */ - load_new_mm_cr3(next->pgd, new_asid, false); - - /* See above wrt _rcuidle. */ - trace_tlb_flush_rcuidle(TLB_FLUSH_ON_TASK_SWITCH, 0); - } + if (need_flush) { + this_cpu_write(cpu_tlbstate.ctxs[new_asid].ctx_id, next->context.ctx_id); + this_cpu_write(cpu_tlbstate.ctxs[new_asid].tlb_gen, next_tlb_gen); + load_new_mm_cr3(next->pgd, new_asid, true); /* - * Record last user mm's context id, so we can avoid - * flushing branch buffer with IBPB if we switch back - * to the same user. + * NB: This gets called via leave_mm() in the idle path + * where RCU functions differently. Tracing normally + * uses RCU, so we need to use the _rcuidle variant. + * + * (There is no good reason for this. The idle code should + * be rearranged to call this before rcu_idle_enter().) */ - if (next != &init_mm) - this_cpu_write(cpu_tlbstate.last_ctx_id, next->context.ctx_id); - - /* Make sure we write CR3 before loaded_mm. */ - barrier(); + trace_tlb_flush_rcuidle(TLB_FLUSH_ON_TASK_SWITCH, TLB_FLUSH_ALL); + } else { + /* The new ASID is already up to date. */ + load_new_mm_cr3(next->pgd, new_asid, false); - this_cpu_write(cpu_tlbstate.loaded_mm, next); - this_cpu_write(cpu_tlbstate.loaded_mm_asid, new_asid); + /* See above wrt _rcuidle. */ + trace_tlb_flush_rcuidle(TLB_FLUSH_ON_TASK_SWITCH, 0); } + /* + * Record last user mm's context id, so we can avoid + * flushing branch buffer with IBPB if we switch back + * to the same user. + */ + if (next != &init_mm) + this_cpu_write(cpu_tlbstate.last_ctx_id, next->context.ctx_id); + + /* Make sure we write CR3 before loaded_mm. */ + barrier(); + + this_cpu_write(cpu_tlbstate.loaded_mm, next); + this_cpu_write(cpu_tlbstate.loaded_mm_asid, new_asid); + load_mm_cr4(next); switch_ldt(real_prev, next); }