Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp5767341imm; Mon, 23 Jul 2018 05:51:17 -0700 (PDT) X-Google-Smtp-Source: AAOMgpeuVY1i03dMUr3LYk4+EdSZIbeMCuXUvGBKFb0QX7eC4MGGHDqBBUPodzmFd4DTpEaoXGdv X-Received: by 2002:a63:e116:: with SMTP id z22-v6mr6998755pgh.89.1532350276999; Mon, 23 Jul 2018 05:51:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532350276; cv=none; d=google.com; s=arc-20160816; b=U0woecVS4NJUioT8080o/X7s6A9qLVJPGj8SuagcwZf+hLEE4jS7hDaqAoijymI1/M rmkeJ+erH8+4qH2bHc9jJ2DwOOIUK5GXwrWc8tp+S60XbbRxrfC4JTozwwwLzdRQ3VTU SG+YUL3zAMMn0Z2djEJwxI5eJhGAXAJE+cB/41f86yw+zBdpxlfwpVYgbZqPndHYfNWD Cr13SJf49BM4GcJ08dpLrYrCGYGpFcScPFfcFQSU93x2vo0Fa90icfjhbFzbKS92s0un fKd5Lwv1IXuftlVhNQ5c6kcE7FUStz1tPaku4+BmEgNWuOJjtzm//J3i08Tk0C2cXGNk d5HQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=OaQ4M/YoTGi+pbnSNg1yQ+AE0jTDGvHMBumOtlNYDoo=; b=jbEIaiG/kCwJjXvl4Q6HeoCrNSgyAuF5HufmkXgbJ3T/JNSg/iRm7nqrwT3ffrMOtU MYqpFFtmHwMyLc3tACgtIPGftWj4xKIHFRwf/iSGEWxwYOtcAOSieTTLSHkimoGt0txR M3D7jgoPM8IuOL25UN2amJT5ulGWKlMWlAex4drKkVhkfYRR7oHnFo+dNOOC1Fjd1ftQ vx9np5GHUL9GX7plPCGufI/VOMLpmcNClchKgr12+kN98Gl23nkBfLxJAQ0yrd/KYKn5 3RlGUJcy6GeHUB3b3Ypu1PQnmvmhMtrnVC0UazZVECqor40StpeAoWi6skVZgmInVBfj JYsg== 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 r24-v6si8147821pgo.295.2018.07.23.05.51.02; Mon, 23 Jul 2018 05:51:16 -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 S2389654AbeGWNsG (ORCPT + 99 others); Mon, 23 Jul 2018 09:48:06 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:51200 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388574AbeGWNsF (ORCPT ); Mon, 23 Jul 2018 09:48:05 -0400 Received: from localhost (LFbn-1-12238-233.w90-92.abo.wanadoo.fr [90.92.53.233]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 23D38C37; Mon, 23 Jul 2018 12:46:44 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Thomas Gleixner , Peter Zijlstra , Andy Lutomirski , David Woodhouse , "Srivatsa S. Bhat" , "Matt Helsley (VMware)" , Alexey Makhalov , Bo Gan Subject: [PATCH 4.4 065/107] x86/process: Optimize TIF_NOTSC switch Date: Mon, 23 Jul 2018 14:41:59 +0200 Message-Id: <20180723122416.407490961@linuxfoundation.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180723122413.003644357@linuxfoundation.org> References: <20180723122413.003644357@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.4-stable review patch. If anyone has any objections, please let me know. ------------------ From: Thomas Gleixner commit 5a920155e388ec22a22e0532fb695b9215c9b34d upstream Provide and use a toggle helper instead of doing it with a branch. x86_64: arch/x86/kernel/process.o text data bss dec hex 3008 8577 16 11601 2d51 Before 2976 8577 16 11569 2d31 After i386: arch/x86/kernel/process.o text data bss dec hex 2925 8673 8 11606 2d56 Before 2893 8673 8 11574 2d36 After Signed-off-by: Thomas Gleixner Cc: Peter Zijlstra Cc: Andy Lutomirski Link: http://lkml.kernel.org/r/20170214081104.9244-4-khuey@kylehuey.com Signed-off-by: Thomas Gleixner Signed-off-by: David Woodhouse Signed-off-by: Greg Kroah-Hartman Signed-off-by: Srivatsa S. Bhat Reviewed-by: Matt Helsley (VMware) Reviewed-by: Alexey Makhalov Reviewed-by: Bo Gan Signed-off-by: Greg Kroah-Hartman --- arch/x86/include/asm/tlbflush.h | 10 ++++++++++ arch/x86/kernel/process.c | 22 ++++------------------ 2 files changed, 14 insertions(+), 18 deletions(-) --- a/arch/x86/include/asm/tlbflush.h +++ b/arch/x86/include/asm/tlbflush.h @@ -111,6 +111,16 @@ static inline void cr4_clear_bits(unsign } } +static inline void cr4_toggle_bits(unsigned long mask) +{ + unsigned long cr4; + + cr4 = this_cpu_read(cpu_tlbstate.cr4); + cr4 ^= mask; + this_cpu_write(cpu_tlbstate.cr4, cr4); + __write_cr4(cr4); +} + /* Read the CR4 shadow. */ static inline unsigned long cr4_read_shadow(void) { --- a/arch/x86/kernel/process.c +++ b/arch/x86/kernel/process.c @@ -130,11 +130,6 @@ void flush_thread(void) fpu__clear(&tsk->thread.fpu); } -static void hard_disable_TSC(void) -{ - cr4_set_bits(X86_CR4_TSD); -} - void disable_TSC(void) { preempt_disable(); @@ -143,15 +138,10 @@ void disable_TSC(void) * Must flip the CPU state synchronously with * TIF_NOTSC in the current running context. */ - hard_disable_TSC(); + cr4_set_bits(X86_CR4_TSD); preempt_enable(); } -static void hard_enable_TSC(void) -{ - cr4_clear_bits(X86_CR4_TSD); -} - static void enable_TSC(void) { preempt_disable(); @@ -160,7 +150,7 @@ static void enable_TSC(void) * Must flip the CPU state synchronously with * TIF_NOTSC in the current running context. */ - hard_enable_TSC(); + cr4_clear_bits(X86_CR4_TSD); preempt_enable(); } @@ -234,12 +224,8 @@ void __switch_to_xtra(struct task_struct wrmsrl(MSR_IA32_DEBUGCTLMSR, debugctl); } - if ((tifp ^ tifn) & _TIF_NOTSC) { - if (tifn & _TIF_NOTSC) - hard_disable_TSC(); - else - hard_enable_TSC(); - } + if ((tifp ^ tifn) & _TIF_NOTSC) + cr4_toggle_bits(X86_CR4_TSD); } /*