Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp1574810yba; Sun, 14 Apr 2019 14:12:18 -0700 (PDT) X-Google-Smtp-Source: APXvYqzcGc0gBkiWtFRk+fuxbUqIy1ndT8BAxX/ZBMHqc8x/0QyiOL3xk3MUITROQEECgW/L+TIc X-Received: by 2002:a63:4241:: with SMTP id p62mr66474302pga.379.1555276338304; Sun, 14 Apr 2019 14:12:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555276338; cv=none; d=google.com; s=arc-20160816; b=sHNpoatp5qunW/w2AAW25spNrIL9htnTKvUIldCSXdptsFqmaKSPjNHTtQc+/aVQAj KvM3BEKrmUkWu/+wKy7fymsMbKF8sj3NEuV0+/gihEPERCRnuN9xUVdSPgDFWpAH6kN3 jBNbOmXcyAtwISr5DSEZarlPohi4c/jIpXOoNXC7mgPW2NKEnTvvXQb1GkmuyrQaTAbx +qDTipbBm0sQFqvtSEIRNIAYC1yss7MbL3qj2TuQJMVmfhOXzvZ9WYjZst3yyfyH2U5k drh7p6Q2E5NCczD7wBkjiUPDrSq/znrJczgbNdO8iKVKcG12ZoU2b2ls58EjDrSTRKN1 F+UQ== 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; bh=c0g3ahCqez/wVBYPsVpM6HQNbLt8UsCFBKzOPd9bmNQ=; b=zbo1IBnTeOy3te89B5ljPTk5vOMxZlGBFzGPcDeu5wVe+cXqQiYh1rsE5R/b+SVCKR 8HR/l+NF/Y9613ItdfRwkuhJe7TaS2fDHH6VqwJRCtEbX7Ph4eQo78ILBDng1QHLfsgW eShnaHAh6Ztmh5LHnqSzeW99oHaug7S/I07orYIJUQSFth778ter8MzxxesxHnuVB7xx kAYLb7dsgZhPkC7WdHClo39cIAqy1dDUuBfAMsq1Mvn5mu6SW+oO/EcoSuJc4lnLj4Qn jfP/i2EkRE+IXaTiVR07SSarFofr7v1Bzso8rnXxiQnhPaWLx16ja54DRDlwcimcPWJX bZoQ== 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 t194si41088285pgb.316.2019.04.14.14.11.59; Sun, 14 Apr 2019 14:12:18 -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 S1726810AbfDNVKP (ORCPT + 99 others); Sun, 14 Apr 2019 17:10:15 -0400 Received: from terminus.zytor.com ([198.137.202.136]:51127 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725797AbfDNVKP (ORCPT ); Sun, 14 Apr 2019 17:10:15 -0400 Received: from terminus.zytor.com (localhost [127.0.0.1]) by terminus.zytor.com (8.15.2/8.15.2) with ESMTPS id x3ELA7mj2699346 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NO); Sun, 14 Apr 2019 14:10:07 -0700 Received: (from tipbot@localhost) by terminus.zytor.com (8.15.2/8.15.2/Submit) id x3ELA6PN2699341; Sun, 14 Apr 2019 14:10:06 -0700 Date: Sun, 14 Apr 2019 14:10:06 -0700 X-Authentication-Warning: terminus.zytor.com: tipbot set sender to tipbot@zytor.com using -f From: tip-bot for Thomas Gleixner Message-ID: Cc: tglx@linutronix.de, mingo@kernel.org, mikhail.v.gavrilov@gmail.com, thomas.lendacky@amd.com, hpa@zytor.com, linux-kernel@vger.kernel.org Reply-To: thomas.lendacky@amd.com, hpa@zytor.com, linux-kernel@vger.kernel.org, mikhail.v.gavrilov@gmail.com, mingo@kernel.org, tglx@linutronix.de In-Reply-To: References: To: linux-tip-commits@vger.kernel.org Subject: [tip:x86/urgent] x86/speculation: Prevent deadlock on ssb_state::lock Git-Commit-ID: 2f5fb19341883bb6e37da351bc3700489d8506a7 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=1.1 required=5.0 tests=ALL_TRUSTED,BAYES_00, DATE_IN_FUTURE_06_12,FREEMAIL_FORGED_REPLYTO autolearn=no autolearn_force=no version=3.4.2 X-Spam-Level: * 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: 2f5fb19341883bb6e37da351bc3700489d8506a7 Gitweb: https://git.kernel.org/tip/2f5fb19341883bb6e37da351bc3700489d8506a7 Author: Thomas Gleixner AuthorDate: Sun, 14 Apr 2019 19:51:06 +0200 Committer: Thomas Gleixner CommitDate: Sun, 14 Apr 2019 23:05:52 +0200 x86/speculation: Prevent deadlock on ssb_state::lock Mikhail reported a lockdep splat related to the AMD specific ssb_state lock: CPU0 CPU1 lock(&st->lock); local_irq_disable(); lock(&(&sighand->siglock)->rlock); lock(&st->lock); lock(&(&sighand->siglock)->rlock); *** DEADLOCK *** The connection between sighand->siglock and st->lock comes through seccomp, which takes st->lock while holding sighand->siglock. Make sure interrupts are disabled when __speculation_ctrl_update() is invoked via prctl() -> speculation_ctrl_update(). Add a lockdep assert to catch future offenders. Fixes: 1f50ddb4f418 ("x86/speculation: Handle HT correctly on AMD") Reported-by: Mikhail Gavrilov Signed-off-by: Thomas Gleixner Tested-by: Mikhail Gavrilov Cc: Thomas Lendacky Cc: stable@vger.kernel.org Link: https://lkml.kernel.org/r/alpine.DEB.2.21.1904141948200.4917@nanos.tec.linutronix.de --- arch/x86/kernel/process.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c index 58ac7be52c7a..957eae13b370 100644 --- a/arch/x86/kernel/process.c +++ b/arch/x86/kernel/process.c @@ -426,6 +426,8 @@ static __always_inline void __speculation_ctrl_update(unsigned long tifp, u64 msr = x86_spec_ctrl_base; bool updmsr = false; + lockdep_assert_irqs_disabled(); + /* * If TIF_SSBD is different, select the proper mitigation * method. Note that if SSBD mitigation is disabled or permanentely @@ -477,10 +479,12 @@ static unsigned long speculation_ctrl_update_tif(struct task_struct *tsk) void speculation_ctrl_update(unsigned long tif) { + unsigned long flags; + /* Forced update. Make sure all relevant TIF flags are different */ - preempt_disable(); + local_irq_save(flags); __speculation_ctrl_update(~tif, tif); - preempt_enable(); + local_irq_restore(flags); } /* Called from seccomp/prctl update */