Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp9604251ybi; Wed, 24 Jul 2019 06:59:16 -0700 (PDT) X-Google-Smtp-Source: APXvYqxHx7EaQYBAREfuW1O8kgU4c9j9AYpui4p2bQP1Nc3QREdYwAOYZ/xrLHy30UjfIHw42sID X-Received: by 2002:a17:90a:ad93:: with SMTP id s19mr87617867pjq.36.1563976756674; Wed, 24 Jul 2019 06:59:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563976756; cv=none; d=google.com; s=arc-20160816; b=Q3wBuSsZQjdvYTxqOdk9WyqD4j6MJiQMgYeoqc6hw7ALyexpjZrKyi2gnOQ42RNObz UyJ9UTLamdX/HPKFk6UR25a6cr6sDBxyfHLJ4U/TlDV4Vs325rBcXeS5Cu+z+i7xIodG JHJV9gOQfcVUttBY2/9zxUTPLFWOAEH0A0vqUEOXp5rr2U/agqAOpQo6xZ9OlxBck7LE w8+xNsrslYsE9eVsuzXqjH9R7pq9XU9mzlBAcQmNXooos+i0urOUr+Xt90M7jCTqeikx fFLVnHW4rfV5rqzt9nJdGOoQPK6OJde7MQiVCDlRJZZg6i5kOKDz1bd1yUoPTn+HeSWq 8dPQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-disposition :content-transfer-encoding:mime-version:robot-unsubscribe:robot-id :git-commit-id:subject:to:references:in-reply-to:reply-to:cc :message-id:from:date:dkim-signature:dkim-filter; bh=HTvdMoYmj62/nIKk37CBNQtbiGBHSzDh/WTcWcvePQU=; b=dAriX52TxJ2NYknzwVBAKn6WdTOQtlunKobm35yiePgdoVXh7yzr+uDogHlt9EDoq9 XDiPi9ho73uvnuulFHbhYZGuQFLomzzHLtnkV23cceY5to9Kq8Q2Zo8vu4DARlNtL+y+ bjRyKkV5vNPT6c1fk0YmYV57zdGnv4/0huvBR97sFo4CZI9dT3TT26lqXW/oq4xmezwr RowCvECCYsOeHYmor2shTQgTKLCfvBYQ6z9aKsiPQkxL1gFovXK4CQjme8xu4JS8SMUY tPXjCT8HZj097DMaprVSMq/XdVFlppWMgX7+mM64PrV5+e+HFML1fV1PXGblTBZ7rYfB 6nTg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@zytor.com header.s=2019071901 header.b=eBuUYksT; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=zytor.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q67si27930601pgq.83.2019.07.24.06.59.01; Wed, 24 Jul 2019 06:59: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; dkim=pass header.i=@zytor.com header.s=2019071901 header.b=eBuUYksT; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=zytor.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727888AbfGXNWw (ORCPT + 99 others); Wed, 24 Jul 2019 09:22:52 -0400 Received: from terminus.zytor.com ([198.137.202.136]:48611 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727722AbfGXNWw (ORCPT ); Wed, 24 Jul 2019 09:22:52 -0400 Received: from terminus.zytor.com (localhost [127.0.0.1]) by terminus.zytor.com (8.15.2/8.15.2) with ESMTPS id x6ODMJ1T548860 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NO); Wed, 24 Jul 2019 06:22:20 -0700 DKIM-Filter: OpenDKIM Filter v2.11.0 terminus.zytor.com x6ODMJ1T548860 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zytor.com; s=2019071901; t=1563974540; bh=HTvdMoYmj62/nIKk37CBNQtbiGBHSzDh/WTcWcvePQU=; h=Date:From:Cc:Reply-To:In-Reply-To:References:To:Subject:From; b=eBuUYksTYbY/iFc+rOHdZrrCCnU+5DZYhvlJ+LOLAqQMA8HAIlIJmZTbNuURD57pn xoLdX6G+b3hnFLWvnPze/YNyPTl+i9toQDFjHYiJhXW6LU2mB09dw/XXCeLYiRqdA/ Gki1QDVhT8Cw42xy0fbMewq5206uwoA6aG99rAggOlBpRAvShOd4A3/+3FstjlsdWM 2CGQzUyJO1uLPitJBoCy2O43cTG5qkOwF1W9WljwW5JvFFZEfQEYJCGePeavPrIO36 t1o0sE9XoF6SjXKCsZxtx9+wbYkqs7d2OCEojEcuFbCa4oKAiXHf4uqGaWL5TBPjjv BwOHEQQCX0BzQ== Received: (from tipbot@localhost) by terminus.zytor.com (8.15.2/8.15.2/Submit) id x6ODMJXs548857; Wed, 24 Jul 2019 06:22:19 -0700 Date: Wed, 24 Jul 2019 06:22:19 -0700 X-Authentication-Warning: terminus.zytor.com: tipbot set sender to tipbot@zytor.com using -f From: tip-bot for Jan Kiszka Message-ID: Cc: tglx@linutronix.de, hpa@zytor.com, linux-kernel@vger.kernel.org, jan.kiszka@siemens.com, mingo@kernel.org Reply-To: mingo@kernel.org, jan.kiszka@siemens.com, hpa@zytor.com, tglx@linutronix.de, linux-kernel@vger.kernel.org In-Reply-To: <0fbbcb64-5f26-4ffb-1bb9-4f5f48426893@siemens.com> References: <0fbbcb64-5f26-4ffb-1bb9-4f5f48426893@siemens.com> To: linux-tip-commits@vger.kernel.org Subject: [tip:x86/mm] x86/mm: Avoid redundant interrupt disable in load_mm_cr4() Git-Commit-ID: 21e450d21ccad4cb7c7984c29ff145012b47736d X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline X-Spam-Status: No, score=-0.3 required=5.0 tests=ALL_TRUSTED,BAYES_00, DATE_IN_FUTURE_96_Q,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF autolearn=no autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on terminus.zytor.com Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: 21e450d21ccad4cb7c7984c29ff145012b47736d Gitweb: https://git.kernel.org/tip/21e450d21ccad4cb7c7984c29ff145012b47736d Author: Jan Kiszka AuthorDate: Tue, 18 Jun 2019 09:32:11 +0200 Committer: Thomas Gleixner CommitDate: Wed, 24 Jul 2019 14:43:37 +0200 x86/mm: Avoid redundant interrupt disable in load_mm_cr4() load_mm_cr4() is always called with interrupts disabled from: - switch_mm_irqs_off() - refresh_pce(), which is a on_each_cpu() callback Thus, disabling interrupts in cr4_set/clear_bits() is redundant. Implement cr4_set/clear_bits_irqsoff() helpers, rename load_mm_cr4() to load_mm_cr4_irqsoff() and use the new helpers. The new helpers do not need a lockdep assert as __cr4_set() has one already. The renaming in combination with the checks in __cr4_set() ensure that any changes in the boundary conditions at the call sites will be detected. [ tglx: Massaged change log ] Signed-off-by: Jan Kiszka Signed-off-by: Thomas Gleixner Link: https://lkml.kernel.org/r/0fbbcb64-5f26-4ffb-1bb9-4f5f48426893@siemens.com --- arch/x86/events/core.c | 2 +- arch/x86/include/asm/mmu_context.h | 8 ++++---- arch/x86/include/asm/tlbflush.h | 30 +++++++++++++++++++++++------- arch/x86/mm/tlb.c | 2 +- 4 files changed, 29 insertions(+), 13 deletions(-) diff --git a/arch/x86/events/core.c b/arch/x86/events/core.c index 81b005e4c7d9..cfe256ca76df 100644 --- a/arch/x86/events/core.c +++ b/arch/x86/events/core.c @@ -2087,7 +2087,7 @@ static int x86_pmu_event_init(struct perf_event *event) static void refresh_pce(void *ignored) { - load_mm_cr4(this_cpu_read(cpu_tlbstate.loaded_mm)); + load_mm_cr4_irqsoff(this_cpu_read(cpu_tlbstate.loaded_mm)); } static void x86_pmu_event_mapped(struct perf_event *event, struct mm_struct *mm) diff --git a/arch/x86/include/asm/mmu_context.h b/arch/x86/include/asm/mmu_context.h index 9024236693d2..16ae821483c8 100644 --- a/arch/x86/include/asm/mmu_context.h +++ b/arch/x86/include/asm/mmu_context.h @@ -28,16 +28,16 @@ static inline void paravirt_activate_mm(struct mm_struct *prev, DECLARE_STATIC_KEY_FALSE(rdpmc_always_available_key); -static inline void load_mm_cr4(struct mm_struct *mm) +static inline void load_mm_cr4_irqsoff(struct mm_struct *mm) { if (static_branch_unlikely(&rdpmc_always_available_key) || atomic_read(&mm->context.perf_rdpmc_allowed)) - cr4_set_bits(X86_CR4_PCE); + cr4_set_bits_irqsoff(X86_CR4_PCE); else - cr4_clear_bits(X86_CR4_PCE); + cr4_clear_bits_irqsoff(X86_CR4_PCE); } #else -static inline void load_mm_cr4(struct mm_struct *mm) {} +static inline void load_mm_cr4_irqsoff(struct mm_struct *mm) {} #endif #ifdef CONFIG_MODIFY_LDT_SYSCALL diff --git a/arch/x86/include/asm/tlbflush.h b/arch/x86/include/asm/tlbflush.h index dee375831962..6f66d841262d 100644 --- a/arch/x86/include/asm/tlbflush.h +++ b/arch/x86/include/asm/tlbflush.h @@ -290,26 +290,42 @@ static inline void __cr4_set(unsigned long cr4) } /* Set in this cpu's CR4. */ -static inline void cr4_set_bits(unsigned long mask) +static inline void cr4_set_bits_irqsoff(unsigned long mask) { - unsigned long cr4, flags; + unsigned long cr4; - local_irq_save(flags); cr4 = this_cpu_read(cpu_tlbstate.cr4); if ((cr4 | mask) != cr4) __cr4_set(cr4 | mask); - local_irq_restore(flags); } /* Clear in this cpu's CR4. */ -static inline void cr4_clear_bits(unsigned long mask) +static inline void cr4_clear_bits_irqsoff(unsigned long mask) { - unsigned long cr4, flags; + unsigned long cr4; - local_irq_save(flags); cr4 = this_cpu_read(cpu_tlbstate.cr4); if ((cr4 & ~mask) != cr4) __cr4_set(cr4 & ~mask); +} + +/* Set in this cpu's CR4. */ +static inline void cr4_set_bits(unsigned long mask) +{ + unsigned long flags; + + local_irq_save(flags); + cr4_set_bits_irqsoff(mask); + local_irq_restore(flags); +} + +/* Clear in this cpu's CR4. */ +static inline void cr4_clear_bits(unsigned long mask) +{ + unsigned long flags; + + local_irq_save(flags); + cr4_clear_bits_irqsoff(mask); local_irq_restore(flags); } diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c index 4de9704c4aaf..e6a9edc5baaf 100644 --- a/arch/x86/mm/tlb.c +++ b/arch/x86/mm/tlb.c @@ -440,7 +440,7 @@ void switch_mm_irqs_off(struct mm_struct *prev, struct mm_struct *next, this_cpu_write(cpu_tlbstate.loaded_mm_asid, new_asid); if (next != real_prev) { - load_mm_cr4(next); + load_mm_cr4_irqsoff(next); switch_ldt(real_prev, next); } }