Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp2674850imm; Mon, 16 Jul 2018 12:04:59 -0700 (PDT) X-Google-Smtp-Source: AAOMgpfk1aEfCI/bXBxYEPQu1o9MqowygYHv8dJYLv66FUsMMvQHKxiIstX+70guDfSI2GgmpLwi X-Received: by 2002:a17:902:aa46:: with SMTP id c6-v6mr17519418plr.313.1531767899850; Mon, 16 Jul 2018 12:04:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531767899; cv=none; d=google.com; s=arc-20160816; b=n9EBx3F7aynPAOKw4pkTErcfBnXpnN4/TBeDba4QBjoBMUODH52+pSSn3oa9uSBznT Xh95MkNvDs3wiwFx8txBOl8H4Zoh0gRSw6HtgvzYjW343gA6ShiDv59TrudEIpTsNjNA L6/G/JFUFGjT/1o+vZIlqdypTnPwOKlLtbbGzzoxijfBo0VAKhTzCMDRddeTUPB02qJW zVL3FvuVSbCqghJG/O2t4dq4wF6esx4f2FIaWO0NpjFOMKwMjD+keSD2CQC3sObHOuYh RDPWFiOBpGZuMCpwAy+hcOLyaZEqr4oh4CGhFEJg9BrHVPOdybRRtTqzLPKp/WmiK6RL KEhQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=lo8aXDiiZ3x6Xy3dWrsQO+0wurOFvvAEbOY4FV12H6o=; b=R6w3INwU0aMUwKOm6BpFzCfVKD9fePLKtYhe8DkxKN2wwP3C8CyagFcmU+kXFtLKW1 YjXMLDIeoJ12HOMwA+iVt3l2VXnmXAw3cegQZlIWfIysPMbIGY3MLFvJY4r57aR4kkte thtP1b3vqOLSTioNl0K35TgoQjBvSggrpixXuyXKYYBINsbJEuMxTCJw/agoTrFi0NQf 7BhgB6w9n0M6exsIVYGXNhO7gRoCBv9h+XlTr7iKJnqaJrdnUQyJBolmqHPNhjJGskkZ bUzJEmnIDHl4yMP/ZZYNUgpBFwUfZs87sGCoKhpcdAvLCZCUD4T1wsnortbRQ9b8KVgo 1OXQ== 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 w24-v6si30087307plp.386.2018.07.16.12.04.45; Mon, 16 Jul 2018 12:04:59 -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 S1730310AbeGPTci (ORCPT + 99 others); Mon, 16 Jul 2018 15:32:38 -0400 Received: from shelob.surriel.com ([96.67.55.147]:36168 "EHLO shelob.surriel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730072AbeGPTch (ORCPT ); Mon, 16 Jul 2018 15:32:37 -0400 Received: from imladris.surriel.com ([96.67.55.152]) by shelob.surriel.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ff8ma-0003RH-Hd; Mon, 16 Jul 2018 15:03:40 -0400 From: Rik van Riel To: linux-kernel@vger.kernel.org Cc: x86@kernel.org, luto@kernel.org, efault@gmx.de, kernel-team@fb.com, mingo@kernel.org, dave.hansen@intel.com, Rik van Riel Subject: [PATCH 3/7] x86,mm: restructure switch_mm_irqs_off Date: Mon, 16 Jul 2018 15:03:33 -0400 Message-Id: <20180716190337.26133-4-riel@surriel.com> X-Mailer: git-send-email 2.14.4 In-Reply-To: <20180716190337.26133-1-riel@surriel.com> References: <20180716190337.26133-1-riel@surriel.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. Signed-off-by: Rik van Riel Acked-by: Dave Hansen Suggested-by: Andy Lutomirski --- 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); } -- 2.14.4