Received: by 10.223.185.116 with SMTP id b49csp3213402wrg; Mon, 5 Mar 2018 16:41:50 -0800 (PST) X-Google-Smtp-Source: AG47ELtf0xqfZLV6O4Qj+TrszXWZzMKQHk2eHnWBmLMnzPuEL47BDxPJvcxM2pUmkE/Yc6Vnqye9 X-Received: by 2002:a17:902:f81:: with SMTP id 1-v6mr14404190plz.265.1520296910015; Mon, 05 Mar 2018 16:41:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520296910; cv=none; d=google.com; s=arc-20160816; b=Wy8a8yN2KxarGnpexq5sma8jVZP7XUdz6pxXqPuFXgX51UcFz2+aLX3TUqbYsgXA2v ikQkWA7Oqthgun5J17nTC43AOpf7gnK5Y47FHDDyCITiBD5tq6ikrZIFCst43lPuNlqq jC6hOAIMEjvC75B/3/+bKAuhGV+YlXcUn+jmI5NTZh3HmEuUMy+pfc284NrAzOOGTkrQ cH/q09JJAra0oMhSWRl34vvVjXxnLH4NJPSDu3mHGO3dUDZHgx0R1SmUQDeAdT5VcUx8 kvwg44t+MhMmjY1CVikpWJOXHRTtD38fcVSzgDOHFaWXfm7cmJkWUAoDPA61OCpWTZ8c YeRw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:to:from:dkim-signature:arc-authentication-results; bh=yiexmfzFJCZaFPVZUdV7YyqgR8uYFnW/1Ktuxgpja4c=; b=vfvf0PVZoX22ZS6IFeyrLtrFrpA4gI1N/csShYl6zCkvJsf1oJ8Z1QEWBAu2MpEkpp Z7MkYeg4OooHoMAOWk1JujKWkcxcmI82NDYJdtY3OoFl9M21O37PEnQUwj/03jv/B8X7 C2pNe0BNGER9XGp37fYhZ8m9YX4qZiYtq6Se101VI9dvXKooeKMRt/qrMOFYZJxjpCb7 UV7r+tmUlYIY0k18EWG3tRk9Fc26G5IPnNU6bzod/dI2i8kwPvdoac/Sl+OTwdHcn7O/ 9M3qDRVdwOytg0PNVYh1pvAj6zDqoDIY8ZH2NZLAoUwZDbGvllP84A1HPYiBNV2EKE4U T3zg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2017-10-26 header.b=SckJ2e1o; 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=oracle.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x22si10924947pfm.321.2018.03.05.16.41.36; Mon, 05 Mar 2018 16:41:49 -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; dkim=pass header.i=@oracle.com header.s=corp-2017-10-26 header.b=SckJ2e1o; 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=oracle.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932972AbeCFA0N (ORCPT + 99 others); Mon, 5 Mar 2018 19:26:13 -0500 Received: from aserp2130.oracle.com ([141.146.126.79]:34758 "EHLO aserp2130.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932926AbeCFA0K (ORCPT ); Mon, 5 Mar 2018 19:26:10 -0500 Received: from pps.filterd (aserp2130.oracle.com [127.0.0.1]) by aserp2130.oracle.com (8.16.0.22/8.16.0.22) with SMTP id w260MD3W115476; Tue, 6 Mar 2018 00:26:06 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : subject : date : message-id : in-reply-to : references; s=corp-2017-10-26; bh=yiexmfzFJCZaFPVZUdV7YyqgR8uYFnW/1Ktuxgpja4c=; b=SckJ2e1osX5z8xY+Hxuf7kVnJ5+PZGkyprQiI4Mvd4AlId+hkx23mdf+w4qJhQliaWLp 4Q2OZT+ZO2OEc8siDk2T0oYki1z1nk8v2w8SVQvtuH8q+9ot1zue0LTgSuwjfz5TPeTo 20RHgHcnz9BRUR8bUk0lmTYzw/Qg6Ex6+aY+uKya15hIMeAM+HHLoCfzWOaamMJNEgDK JCVxrmZ/9brhe58y44T4tdlLQGvhNO7bvBxBMVIP8gYUikzz/fpeFoZBRjmUwDwb3XG/ lkt5V6fdANifzfNcXgXyfDf7Za1vVWMvS9c28pcLxY6/10jGseeDxG7f0hsiab0I70/i 7Q== Received: from userv0021.oracle.com (userv0021.oracle.com [156.151.31.71]) by aserp2130.oracle.com with ESMTP id 2ghdxf8k4b-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 06 Mar 2018 00:26:05 +0000 Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by userv0021.oracle.com (8.14.4/8.14.4) with ESMTP id w260Q4jh024750 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Tue, 6 Mar 2018 00:26:05 GMT Received: from abhmp0008.oracle.com (abhmp0008.oracle.com [141.146.116.14]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id w260Q4lZ032647; Tue, 6 Mar 2018 00:26:04 GMT Received: from localhost.localdomain (/98.216.35.41) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 05 Mar 2018 16:26:04 -0800 From: Pavel Tatashin To: steven.sistare@oracle.com, daniel.m.jordan@oracle.com, linux-kernel@vger.kernel.org, Alexander.Levin@microsoft.com, dan.j.williams@intel.com, sathyanarayanan.kuppuswamy@intel.com, pankaj.laxminarayan.bharadiya@intel.com, akuster@mvista.com, cminyard@mvista.com, pasha.tatashin@oracle.com, gregkh@linuxfoundation.org, stable@vger.kernel.org Subject: [PATCH 4.1 09/65] x86/mm, sched/core: Turn off IRQs in switch_mm() Date: Mon, 5 Mar 2018 19:24:42 -0500 Message-Id: <20180306002538.1761-10-pasha.tatashin@oracle.com> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180306002538.1761-1-pasha.tatashin@oracle.com> References: <20180306002538.1761-1-pasha.tatashin@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=8823 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=930 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1711220000 definitions=main-1803060003 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Andy Lutomirski commit 078194f8e9fe3cf54c8fd8bded48a1db5bd8eb8a upstream. Potential races between switch_mm() and TLB-flush or LDT-flush IPIs could be very messy. AFAICT the code is currently okay, whether by accident or by careful design, but enabling PCID will make it considerably more complicated and will no longer be obviously safe. Fix it with a big hammer: run switch_mm() with IRQs off. To avoid a performance hit in the scheduler, we take advantage of our knowledge that the scheduler already has IRQs disabled when it calls switch_mm(). Signed-off-by: Andy Lutomirski Reviewed-by: Borislav Petkov Cc: Borislav Petkov Cc: Linus Torvalds Cc: Peter Zijlstra Cc: Thomas Gleixner Link: http://lkml.kernel.org/r/f19baf759693c9dcae64bbff76189db77cb13398.1461688545.git.luto@kernel.org Signed-off-by: Ingo Molnar Signed-off-by: Greg Kroah-Hartman (cherry picked from commit 4ead44fd2525ed97e5362a806d312a0e3b0ea445) Signed-off-by: Pavel Tatashin Conflicts: arch/x86/include/asm/mmu_context.h --- arch/x86/include/asm/mmu_context.h | 4 ++++ arch/x86/mm/tlb.c | 10 ++++++++++ 2 files changed, 14 insertions(+) diff --git a/arch/x86/include/asm/mmu_context.h b/arch/x86/include/asm/mmu_context.h index 375fafccb32c..2bf4bae1c65e 100644 --- a/arch/x86/include/asm/mmu_context.h +++ b/arch/x86/include/asm/mmu_context.h @@ -95,6 +95,10 @@ static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk) extern void switch_mm(struct mm_struct *prev, struct mm_struct *next, struct task_struct *tsk); +extern void switch_mm_irqs_off(struct mm_struct *prev, struct mm_struct *next, + struct task_struct *tsk); +#define switch_mm_irqs_off switch_mm_irqs_off + #define activate_mm(prev, next) \ do { \ paravirt_activate_mm((prev), (next)); \ diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c index 40c640980720..4ce6569ad963 100644 --- a/arch/x86/mm/tlb.c +++ b/arch/x86/mm/tlb.c @@ -63,6 +63,16 @@ EXPORT_SYMBOL_GPL(leave_mm); void switch_mm(struct mm_struct *prev, struct mm_struct *next, struct task_struct *tsk) +{ + unsigned long flags; + + local_irq_save(flags); + switch_mm_irqs_off(prev, next, tsk); + local_irq_restore(flags); +} + +void switch_mm_irqs_off(struct mm_struct *prev, struct mm_struct *next, + struct task_struct *tsk) { unsigned cpu = smp_processor_id(); -- 2.16.2