Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp2339748imm; Sat, 28 Jul 2018 14:58:50 -0700 (PDT) X-Google-Smtp-Source: AAOMgpdQ14QpJEqUrrCDc0vHem99alO4NY+CLzWmnmkNb4vmVrMa6WkddrxHelLWsfH3By3JDE6e X-Received: by 2002:a17:902:7488:: with SMTP id h8-v6mr11018443pll.41.1532815130898; Sat, 28 Jul 2018 14:58:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532815130; cv=none; d=google.com; s=arc-20160816; b=ZjZUC28I2CY2vOOYzLYCeQ4wrezB3F2oRfo3cjXJP29sNrTdSfrHCcHwvB6PlKEZcB jmg433DoUDhWnXPacQ2CCgxLj5NEjB99qmcoMFktLltDFyZmDwwgyEBLqWhzT7bFnBMw lRCKiNGZh2wZZa1GKUA5WeXt92f1+tvuk0Zum2VLkCT8c8BiZ8LPFRRDqg28B8Mn/0Ak N9eY4gL0fRRCcoJwcxOi7wk+7fqsOHAxSJqcCX3qbVaoW6aFyWNjqOEHpYDZ70aIRu5e AXpwZoXXXhokwN+7eqNEMCNedGnCDvQW+hQpsU68aTyEPjs+/j2LqhctUIeNR6T6AYwa qX8A== 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=Lj3BSEfU/rHgxkEr6Oe3wqloK9FMLsMnJskMBSc0TSg=; b=UkO6RKWdlRabCFx5J2oE+3Elj73gRjan8y0vcN48/1/tOvwO3y67vxTjnfZIJ4wh6l ssm63ijgembjB5WHK+nd19HKvR0bIZWDCGGGKz2AMKB9lx0Ml9fL2Gn3YG/ZSVjlEB7C W0+/IduhYSKxWoHgX3WufTTGTsAxU1d367832poqlgMQR0Mn7iJijfjghSzL/rJXBnsC D/z3Z270gnX9VddyGB/bsNvBEmqDzo1DT8/QrCJ939A5b0Dw32uKPr3utdZJ7/nCS3Xx +2kvdLaL+w0KHKs6nxUe4iXy5enR9/E4p+6cvnds3IhPv2d/PdVhf7WnwpC3Ait3p4li kGXA== 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 p77-v6si7597100pfj.294.2018.07.28.14.58.36; Sat, 28 Jul 2018 14:58:50 -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 S1731379AbeG1XWU (ORCPT + 99 others); Sat, 28 Jul 2018 19:22:20 -0400 Received: from shelob.surriel.com ([96.67.55.147]:44102 "EHLO shelob.surriel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731347AbeG1XWU (ORCPT ); Sat, 28 Jul 2018 19:22:20 -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 1fjXA0-0000QZ-PG; Sat, 28 Jul 2018 17:54:00 -0400 From: Rik van Riel To: linux-kernel@vger.kernel.org Cc: kernel-team@fb.com, peterz@infradead.org, luto@kernel.org, x86@kernel.org, vkuznets@redhat.com, mingo@kernel.org, efault@gmx.de, dave.hansen@intel.com, will.daecon@arm.com, catalin.marinas@arm.com, benh@kernel.crashing.org, Rik van Riel Subject: [PATCH 06/10] mm,x86: skip cr4 and ldt reload when mm stays the same Date: Sat, 28 Jul 2018 17:53:53 -0400 Message-Id: <20180728215357.3249-7-riel@surriel.com> X-Mailer: git-send-email 2.14.4 In-Reply-To: <20180728215357.3249-1-riel@surriel.com> References: <20180728215357.3249-1-riel@surriel.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When switching back from lazy TLB mode to a thread of the same process that switched into lazy TLB mode, we still have the cr4 (and sometimes LDT) of that process loaded, and there is no need to reload it. When there was no TLB flush while the CPU was in lazy TLB mode, the current code in switch_mm_irqs_off already avoids the reload, by returning early. However, when the TLB contents on the CPU are out of date, and we flush the TLB for the task, we fall through to the regular context switching code. This patch teaches that code to skip the cr4 and LDT flushes when switching back to the same mm after a flush. Suggested-by: Andy Lutomirski Signed-off-by: Rik van Riel --- arch/x86/mm/tlb.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c index 671cc66df801..149fb64e4bf4 100644 --- a/arch/x86/mm/tlb.c +++ b/arch/x86/mm/tlb.c @@ -367,8 +367,10 @@ void switch_mm_irqs_off(struct mm_struct *prev, struct mm_struct *next, 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); + if (next != real_prev) { + load_mm_cr4(next); + switch_ldt(real_prev, next); + } } /* -- 2.14.4