Received: by 10.223.176.5 with SMTP id f5csp2992655wra; Mon, 5 Feb 2018 13:45:30 -0800 (PST) X-Google-Smtp-Source: AH8x225Oh7SRHxiKcvnWyoerCm+mQtH94pRxssOFo8ssg84MAix3FKr62DRYKm5QCetUdazleYoZ X-Received: by 10.101.69.13 with SMTP id n13mr183510pgq.62.1517867130812; Mon, 05 Feb 2018 13:45:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517867130; cv=none; d=google.com; s=arc-20160816; b=CAyvc8HlP0pdG1QUfYDIoPlgknRZ6OpL5XqaIUGDt9GCqwQQRc8wl6np50FL2TOg/C mIxPaiCDdjEZ5XIkjPf8Xym97KsD4HYUSCZJePKAuLcvGjefzAk10oXdkoH+bIM0KDex bFRSEjBamMsmwzb6w3b4KF4JcVQYA6INpNhScSV8fnN7WTfRopTjoItlQQeZxq+P41LH RzFSfxrSV0T/FX3zsQmfHbbNCtYHVS+z+toon4GhcXH0Tfb24zJVs8KUmZukKAvVDJmf AVlVHWAivFNuY+U9PqeRpzeMQfYr8RkUwtZk/kK8dfy555weDxnfSxfnimWwmNPixcnt T2EQ== 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:arc-authentication-results; bh=1u1jBoaSOACpnSYfKBZfBoy+VItQcvA9H+bKChTUdwI=; b=UuBxWjhNH4e05HjjQq2G1x6QxYPtLscR+wUMv3cU47JfHkhkfEK/Ly3Qd9JuR7SO74 zDubacda9ZIllPTkxTuMH7gbn2Vidz1CO4LCe4+6noTe97HYN4Qs05D94jNMrTldApxl WbI+QEpb8lDuwCPFcztjXZQRgTtPgDrcqdT3Ad+o4da5NnDEyjIWwiXOsmxEMqa3WFQ6 5MvNqTycY9wUiAffQUpXhZQqsYJowYrJFxDOzQG4V6ubzJkvqtL1y9th04mpRyoh6ej+ d+RZaBO6GBSgsqpgIKVCyJg0NJu/7ASxAG4Sp57OFXno1AEuyf1AFlTX9bO4swXFS7Yn kk/A== 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 d10-v6si5580472plm.539.2018.02.05.13.45.16; Mon, 05 Feb 2018 13:45:30 -0800 (PST) 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 S1752065AbeBEVnn (ORCPT + 99 others); Mon, 5 Feb 2018 16:43:43 -0500 Received: from terminus.zytor.com ([65.50.211.136]:41731 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752021AbeBEVnh (ORCPT ); Mon, 5 Feb 2018 16:43:37 -0500 Received: from terminus.zytor.com (localhost [127.0.0.1]) by terminus.zytor.com (8.15.2/8.15.2) with ESMTP id w15LTY6g029056; Mon, 5 Feb 2018 13:29:34 -0800 Received: (from tipbot@localhost) by terminus.zytor.com (8.15.2/8.15.2/Submit) id w15LTY6D029050; Mon, 5 Feb 2018 13:29:34 -0800 Date: Mon, 5 Feb 2018 13:29:34 -0800 X-Authentication-Warning: terminus.zytor.com: tipbot set sender to tipbot@zytor.com using -f From: tip-bot for Mathieu Desnoyers Message-ID: Cc: paulmck@linux.vnet.ibm.com, ahh@google.com, paulus@samba.org, sehr@google.com, davejwatson@fb.com, ghackmann@google.com, mathieu.desnoyers@efficios.com, hpa@zytor.com, boqun.feng@gmail.com, linux-kernel@vger.kernel.org, mpe@ellerman.id.au, avi@scylladb.com, tglx@linutronix.de, parri.andrea@gmail.com, luto@kernel.org, benh@kernel.crashing.org, linux@armlinux.org.uk, will.deacon@arm.com, torvalds@linux-foundation.org, mingo@kernel.org, maged.michael@gmail.com, peterz@infradead.org Reply-To: davejwatson@fb.com, ghackmann@google.com, mathieu.desnoyers@efficios.com, hpa@zytor.com, tglx@linutronix.de, avi@scylladb.com, mpe@ellerman.id.au, linux-kernel@vger.kernel.org, boqun.feng@gmail.com, ahh@google.com, paulmck@linux.vnet.ibm.com, paulus@samba.org, sehr@google.com, linux@armlinux.org.uk, benh@kernel.crashing.org, will.deacon@arm.com, mingo@kernel.org, torvalds@linux-foundation.org, maged.michael@gmail.com, peterz@infradead.org, parri.andrea@gmail.com, luto@kernel.org In-Reply-To: <20180129202020.8515-10-mathieu.desnoyers@efficios.com> References: <20180129202020.8515-10-mathieu.desnoyers@efficios.com> To: linux-tip-commits@vger.kernel.org Subject: [tip:sched/urgent] membarrier/x86: Provide core serializing command Git-Commit-ID: 10bcc80e9dbced128e3b4aa86e4737e5486a45d0 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=-2.9 required=5.0 tests=ALL_TRUSTED,BAYES_00 autolearn=ham autolearn_force=no version=3.4.1 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) 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: 10bcc80e9dbced128e3b4aa86e4737e5486a45d0 Gitweb: https://git.kernel.org/tip/10bcc80e9dbced128e3b4aa86e4737e5486a45d0 Author: Mathieu Desnoyers AuthorDate: Mon, 29 Jan 2018 15:20:18 -0500 Committer: Ingo Molnar CommitDate: Mon, 5 Feb 2018 21:35:11 +0100 membarrier/x86: Provide core serializing command There are two places where core serialization is needed by membarrier: 1) When returning from the membarrier IPI, 2) After scheduler updates curr to a thread with a different mm, before going back to user-space, since the curr->mm is used by membarrier to check whether it needs to send an IPI to that CPU. x86-32 uses IRET as return from interrupt, and both IRET and SYSEXIT to go back to user-space. The IRET instruction is core serializing, but not SYSEXIT. x86-64 uses IRET as return from interrupt, which takes care of the IPI. However, it can return to user-space through either SYSRETL (compat code), SYSRETQ, or IRET. Given that SYSRET{L,Q} is not core serializing, we rely instead on write_cr3() performed by switch_mm() to provide core serialization after changing the current mm, and deal with the special case of kthread -> uthread (temporarily keeping current mm into active_mm) by adding a sync_core() in that specific case. Use the new sync_core_before_usermode() to guarantee this. Signed-off-by: Mathieu Desnoyers Acked-by: Thomas Gleixner Acked-by: Peter Zijlstra (Intel) Cc: Andrea Parri Cc: Andrew Hunter Cc: Andy Lutomirski Cc: Avi Kivity Cc: Benjamin Herrenschmidt Cc: Boqun Feng Cc: Dave Watson Cc: David Sehr Cc: Greg Hackmann Cc: H. Peter Anvin Cc: Linus Torvalds Cc: Maged Michael Cc: Michael Ellerman Cc: Paul E. McKenney Cc: Paul Mackerras Cc: Russell King Cc: Will Deacon Cc: linux-api@vger.kernel.org Cc: linux-arch@vger.kernel.org Link: http://lkml.kernel.org/r/20180129202020.8515-10-mathieu.desnoyers@efficios.com Signed-off-by: Ingo Molnar --- arch/x86/Kconfig | 1 + arch/x86/entry/entry_32.S | 5 +++++ arch/x86/entry/entry_64.S | 4 ++++ arch/x86/mm/tlb.c | 7 ++++--- 4 files changed, 14 insertions(+), 3 deletions(-) diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig index 31030ad..e095bdb 100644 --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig @@ -54,6 +54,7 @@ config X86 select ARCH_HAS_FORTIFY_SOURCE select ARCH_HAS_GCOV_PROFILE_ALL select ARCH_HAS_KCOV if X86_64 + select ARCH_HAS_MEMBARRIER_SYNC_CORE select ARCH_HAS_PMEM_API if X86_64 select ARCH_HAS_REFCOUNT select ARCH_HAS_UACCESS_FLUSHCACHE if X86_64 diff --git a/arch/x86/entry/entry_32.S b/arch/x86/entry/entry_32.S index 2a35b1e..abee6d2 100644 --- a/arch/x86/entry/entry_32.S +++ b/arch/x86/entry/entry_32.S @@ -566,6 +566,11 @@ restore_all: .Lrestore_nocheck: RESTORE_REGS 4 # skip orig_eax/error_code .Lirq_return: + /* + * ARCH_HAS_MEMBARRIER_SYNC_CORE rely on IRET core serialization + * when returning from IPI handler and when returning from + * scheduler to user-space. + */ INTERRUPT_RETURN .section .fixup, "ax" diff --git a/arch/x86/entry/entry_64.S b/arch/x86/entry/entry_64.S index a835704..5816858 100644 --- a/arch/x86/entry/entry_64.S +++ b/arch/x86/entry/entry_64.S @@ -804,6 +804,10 @@ GLOBAL(restore_regs_and_return_to_kernel) POP_EXTRA_REGS POP_C_REGS addq $8, %rsp /* skip regs->orig_ax */ + /* + * ARCH_HAS_MEMBARRIER_SYNC_CORE rely on IRET core serialization + * when returning from IPI handler. + */ INTERRUPT_RETURN ENTRY(native_iret) diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c index 9fa7d2e..9b34121 100644 --- a/arch/x86/mm/tlb.c +++ b/arch/x86/mm/tlb.c @@ -229,9 +229,10 @@ void switch_mm_irqs_off(struct mm_struct *prev, struct mm_struct *next, this_cpu_write(cpu_tlbstate.is_lazy, false); /* - * The membarrier system call requires a full memory barrier - * before returning to user-space, after storing to rq->curr. - * Writing to CR3 provides that full memory barrier. + * The membarrier system call requires a full memory barrier and + * core serialization before returning to user-space, after + * storing to rq->curr. Writing to CR3 provides that full + * memory barrier and core serializing instruction. */ if (real_prev == next) { VM_WARN_ON(this_cpu_read(cpu_tlbstate.ctxs[prev_asid].ctx_id) !=