From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.0 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0A69BC46463 for ; Wed, 1 Aug 2018 10:03:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C6158208AC for ; Wed, 1 Aug 2018 10:03:13 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C6158208AC Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=surriel.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389203AbeHALsK (ORCPT ); Wed, 1 Aug 2018 07:48:10 -0400 Received: from shelob.surriel.com ([96.67.55.147]:55904 "EHLO shelob.surriel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389005AbeHALsJ (ORCPT ); Wed, 1 Aug 2018 07:48:09 -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 1fkny6-00010M-Em; Wed, 01 Aug 2018 06:02:58 -0400 From: Rik van Riel To: linux-kernel@vger.kernel.org Cc: kernel-team@fb.com, mingo@kernel.org, peterz@infradead.org, luto@kernel.org, x86@kernel.org, efault@gmx.de, dave.hansen@intel.com, Rik van Riel Subject: [PATCH 06/11] mm,x86: skip cr4 and ldt reload when mm stays the same Date: Wed, 1 Aug 2018 06:02:50 -0400 Message-Id: <20180801100255.4278-7-riel@surriel.com> X-Mailer: git-send-email 2.14.4 In-Reply-To: <20180801100255.4278-1-riel@surriel.com> References: <20180801100255.4278-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 Acked-by: Andy Lutomirski --- 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