Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp3310215imm; Tue, 17 Jul 2018 02:36:25 -0700 (PDT) X-Google-Smtp-Source: AAOMgpel8d30aKvvOfAa0r9WZL4E0sRLkynhwH0PPljSHz+hiusu4lf6xKdLWNLiyrdHbbRPpK4z X-Received: by 2002:a63:8648:: with SMTP id x69-v6mr890403pgd.172.1531820185917; Tue, 17 Jul 2018 02:36:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531820185; cv=none; d=google.com; s=arc-20160816; b=LawXpJUrkaHuMFo9Mf9KxALbUQclglHdLksSObG58H5zVX7KMVRXOMr6EWQcADW7Cm LIAMO/FKkc6EXcEn87h61aajmG6E17M43tGBLgG/Oq4GZiOcW8rr8SnlisRpPRxXHLSy fsbWAAJQv6YOGqa8/B+yI3XiowjiPpkW7G/XwySHDerlBT3NJ9ohAQC4G0GhUTqlzRE8 aHVV4y819guBV5FDNwCDA5LfAvorNJnxguqfhYZh8JXnzTNFIUeeR1ar6oEF8JfCCvV2 ysJPX8GT6buv/I2OIZ2G3do3ThE++Jo+z3X1TvBCoyifc+8IBzBS5va59RmYEWBDs/tQ D2zA== 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:arc-authentication-results; bh=sXfx+5rBdHOSKtdVl7DZJtWwpeYTr4ny0Wd5I9D9/YU=; b=GWJE6mqtUFhj0UO+0wR0tsi/rUXuQZ+p/az8ChS146ZWoAzlaSSO8bLuXv8Wjczj6s IuzmUZj8hJwpQ/HD9mlgkZeS+OKDYXCc0XS0NtWIIObG1jHHwwlG/zWlGjuXPZXne9KO JWnkLAwwuW7PZjMGIa2RHonySguh/NaRnGQAg2qRcf9HicRj8Zemjyxgexe0/Q4WnQwR QSj0PtctTipsyPvoljf71XjK/Kj7vZglQba9YT+20jczy3iFIi56vBHjJzd7FDdLpIQk BdiKxvH/uVTu6SkRArulKoHZp50SGKW2i2IMYteQMhk7QS0iEromoKopDUutpZQ2TBiz 6e1g== 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 o184-v6si492071pga.520.2018.07.17.02.36.10; Tue, 17 Jul 2018 02:36:25 -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 S1730229AbeGQKGl (ORCPT + 99 others); Tue, 17 Jul 2018 06:06:41 -0400 Received: from terminus.zytor.com ([198.137.202.136]:54287 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729602AbeGQKGl (ORCPT ); Tue, 17 Jul 2018 06:06:41 -0400 Received: from terminus.zytor.com (localhost [127.0.0.1]) by terminus.zytor.com (8.15.2/8.15.2) with ESMTPS id w6H9Yc3Y1463383 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Tue, 17 Jul 2018 02:34:38 -0700 Received: (from tipbot@localhost) by terminus.zytor.com (8.15.2/8.15.2/Submit) id w6H9YcNj1463379; Tue, 17 Jul 2018 02:34:38 -0700 Date: Tue, 17 Jul 2018 02:34:38 -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: luto@kernel.org, peterz@infradead.org, torvalds@linux-foundation.org, dave.hansen@intel.com, hpa@zytor.com, linux-kernel@vger.kernel.org, mingo@kernel.org, tglx@linutronix.de, riel@surriel.com Reply-To: riel@surriel.com, tglx@linutronix.de, hpa@zytor.com, linux-kernel@vger.kernel.org, mingo@kernel.org, dave.hansen@intel.com, peterz@infradead.org, torvalds@linux-foundation.org, luto@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: 61d0beb5796ab11f7f3bf38cb2eccc6579aaa70b 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=-2.9 required=5.0 tests=ALL_TRUSTED,BAYES_00, DATE_IN_FUTURE_96_Q autolearn=ham autolearn_force=no version=3.4.1 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) 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: 61d0beb5796ab11f7f3bf38cb2eccc6579aaa70b Gitweb: https://git.kernel.org/tip/61d0beb5796ab11f7f3bf38cb2eccc6579aaa70b Author: Rik van Riel AuthorDate: Mon, 16 Jul 2018 15:03:33 -0400 Committer: Ingo Molnar CommitDate: Tue, 17 Jul 2018 09:35:32 +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. Suggested-by: Andy Lutomirski Signed-off-by: Rik van Riel Acked-by: Dave Hansen Cc: Linus Torvalds Cc: Peter Zijlstra Cc: Thomas Gleixner Cc: efault@gmx.de Cc: kernel-team@fb.com Link: http://lkml.kernel.org/r/20180716190337.26133-4-riel@surriel.com Signed-off-by: Ingo Molnar --- arch/x86/mm/tlb.c | 60 +++++++++++++++++++++++++++---------------------------- 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c index 9a893673c56b..4b73fe835c95 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); /* @@ -297,41 +297,41 @@ void switch_mm_irqs_off(struct mm_struct *prev, struct mm_struct *next, next_tlb_gen = atomic64_read(&next->context.tlb_gen); choose_new_asid(next, next_tlb_gen, &new_asid, &need_flush); + } - 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); + 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); + + 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); }