Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp5769847imm; Mon, 23 Jul 2018 05:54:07 -0700 (PDT) X-Google-Smtp-Source: AAOMgpfchUJ3EPrAF1FVyFI0eKisgI7AzWkQtpF6L7d2VqQ0VboMRKAEK68dOQmttQ8gIShv+ywK X-Received: by 2002:a62:4add:: with SMTP id c90-v6mr13219888pfj.23.1532350447001; Mon, 23 Jul 2018 05:54:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532350446; cv=none; d=google.com; s=arc-20160816; b=XrDhTUeH6AVUGkznwd34dPYq9i1TdidZKdtqeKQudgrEBltcWkr3N4IJ31TpScfG/C 6m/hcvwJuTtJ11sH1zJ4qvxYomqA01OqP8kHu1xqaibp6YUJmApFa8fxxUWNC9I7P/jP JORnsxTViaRkqzTx9K0AZDb7lULY0nRxDXNRssB3Ar57K4tGn10mXunFi/BidQmxSqnr vGd8kc/Y/yhfx2+Fa3vSkz5uDqG4lGbFKJeAsRD+TY/Tfj3FqMXcDElBR+cyKXQfKSRt D3TW8t2pdgxW8UUq5VapuL6xfpyRt2MIuFgqz/48WT+Q2SuwFIDTux+B7NUn9D5Hd9K8 3e4A== 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=QTnhTr/lI94Kwuhb2igOVQJdvIa8WI7bN/VwhtvxkF4=; b=dIQVB392+8H3WYwV4byW3SsUbssNydQCFCZVvK8ZDEBNzuhunFHJuSM104hpGz7cD2 pIJlvOSst4T0dsAD/T4TC0kW8N2ySL33/AQK23yujAZjrtSbmOJACnvX27In8NY2Y5hJ r/xh9Sdj/PCe0/MmtgaQQbbFNXn6yb9szElmsEvPwkAOkFpu9UbSJDNe3Z9z+CnXOwmP uUBi6PdVEpOWkgQOouN2WhW0URYjGaAFW4xfRY6fiqjZCW9VusgQC+Oi8sXftC6mCcgy 1oPvGWnEW1T48mJty3O8TJ+Rlw2ueSOv7brMsner57BEUwQ+WzWBFDM6sBBSVGW5L9+J /RlQ== 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 s126-v6si9366239pfc.222.2018.07.23.05.53.51; Mon, 23 Jul 2018 05:54:06 -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 S2389446AbeGWNrx (ORCPT + 99 others); Mon, 23 Jul 2018 09:47:53 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:51386 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388197AbeGWNrv (ORCPT ); Mon, 23 Jul 2018 09:47:51 -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 0F10CCB5; Mon, 23 Jul 2018 12:45:41 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Kyle Huey , Peter Zijlstra , Andy Lutomirski , Thomas Gleixner , David Woodhouse , "Srivatsa S. Bhat" , "Matt Helsley (VMware)" , Alexey Makhalov , Bo Gan Subject: [PATCH 4.4 063/107] x86/process: Optimize TIF checks in __switch_to_xtra() Date: Mon, 23 Jul 2018 14:41:57 +0200 Message-Id: <20180723122416.251142387@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: Kyle Huey commit af8b3cd3934ec60f4c2a420d19a9d416554f140b upstream Help the compiler to avoid reevaluating the thread flags for each checked bit by reordering the bit checks and providing an explicit xor for evaluation. With default defconfigs for each arch, x86_64: arch/x86/kernel/process.o text data bss dec hex 3056 8577 16 11649 2d81 Before 3024 8577 16 11617 2d61 After i386: arch/x86/kernel/process.o text data bss dec hex 2957 8673 8 11638 2d76 Before 2925 8673 8 11606 2d56 After Originally-by: Thomas Gleixner Signed-off-by: Kyle Huey Cc: Peter Zijlstra Cc: Andy Lutomirski Link: http://lkml.kernel.org/r/20170214081104.9244-2-khuey@kylehuey.com Signed-off-by: Thomas Gleixner [dwmw2: backported to make TIF_RDS handling simpler. No deferred TR reload.] 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/kernel/process.c | 54 ++++++++++++++++++++++++++-------------------- 1 file changed, 31 insertions(+), 23 deletions(-) --- a/arch/x86/kernel/process.c +++ b/arch/x86/kernel/process.c @@ -188,48 +188,56 @@ int set_tsc_mode(unsigned int val) return 0; } +static inline void switch_to_bitmap(struct tss_struct *tss, + struct thread_struct *prev, + struct thread_struct *next, + unsigned long tifp, unsigned long tifn) +{ + if (tifn & _TIF_IO_BITMAP) { + /* + * Copy the relevant range of the IO bitmap. + * Normally this is 128 bytes or less: + */ + memcpy(tss->io_bitmap, next->io_bitmap_ptr, + max(prev->io_bitmap_max, next->io_bitmap_max)); + } else if (tifp & _TIF_IO_BITMAP) { + /* + * Clear any possible leftover bits: + */ + memset(tss->io_bitmap, 0xff, prev->io_bitmap_max); + } +} + void __switch_to_xtra(struct task_struct *prev_p, struct task_struct *next_p, struct tss_struct *tss) { struct thread_struct *prev, *next; + unsigned long tifp, tifn; prev = &prev_p->thread; next = &next_p->thread; - if (test_tsk_thread_flag(prev_p, TIF_BLOCKSTEP) ^ - test_tsk_thread_flag(next_p, TIF_BLOCKSTEP)) { + tifn = READ_ONCE(task_thread_info(next_p)->flags); + tifp = READ_ONCE(task_thread_info(prev_p)->flags); + switch_to_bitmap(tss, prev, next, tifp, tifn); + + propagate_user_return_notify(prev_p, next_p); + + if ((tifp ^ tifn) & _TIF_BLOCKSTEP) { unsigned long debugctl = get_debugctlmsr(); debugctl &= ~DEBUGCTLMSR_BTF; - if (test_tsk_thread_flag(next_p, TIF_BLOCKSTEP)) + if (tifn & _TIF_BLOCKSTEP) debugctl |= DEBUGCTLMSR_BTF; - update_debugctlmsr(debugctl); } - if (test_tsk_thread_flag(prev_p, TIF_NOTSC) ^ - test_tsk_thread_flag(next_p, TIF_NOTSC)) { - /* prev and next are different */ - if (test_tsk_thread_flag(next_p, TIF_NOTSC)) + if ((tifp ^ tifn) & _TIF_NOTSC) { + if (tifn & _TIF_NOTSC) hard_disable_TSC(); else hard_enable_TSC(); } - - if (test_tsk_thread_flag(next_p, TIF_IO_BITMAP)) { - /* - * Copy the relevant range of the IO bitmap. - * Normally this is 128 bytes or less: - */ - memcpy(tss->io_bitmap, next->io_bitmap_ptr, - max(prev->io_bitmap_max, next->io_bitmap_max)); - } else if (test_tsk_thread_flag(prev_p, TIF_IO_BITMAP)) { - /* - * Clear any possible leftover bits: - */ - memset(tss->io_bitmap, 0xff, prev->io_bitmap_max); - } - propagate_user_return_notify(prev_p, next_p); } /*