Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3433432imu; Sun, 11 Nov 2018 15:01:08 -0800 (PST) X-Google-Smtp-Source: AJdET5dqOIqgoSKS+q2Lty3sA8NGQ8B2qUe3Q4oYwG7JE0CyrR4P9DHOh5tPbhJ3q8wBxQjAWZ/z X-Received: by 2002:a63:c942:: with SMTP id y2mr15269181pgg.331.1541977268871; Sun, 11 Nov 2018 15:01:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541977268; cv=none; d=google.com; s=arc-20160816; b=v+Y80EvSpjBKt7EYR6bXsWuMVjBjzrpSxC/Mm7mwqNC3whUmwyWUNqRcc5bLTPsIWd WtHmDyiyd77UKvtKJ2BRrNcjCsfoCoxu4PrmFIR0BhzT30jqxdGsKfOOTD0yRXYMs1KO qQPNUpO/UGabeU6s9q+ZwjaSxbma3IfIv5YaoyKUZ9A/QJRkwb98owk0yNyBHnz2BB8y VXi+dFGlcDvtDOTUrsRg0HLIr2NIcOW6Fd85QhIx5ODP9ATLy30nz5t9Z31su/W/04av Mu5yO3PxJPnmtmpNMNcq3V0dX7Aq+mfhwmWsbTxuYBRId4DX/FhJKCJF10zq1JfZDsov zWJw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=6/C7xgOnTOO2k3M7JAxsB0R12mbUszWXj3XjaGOkSyI=; b=QvhSarnzrFJ8uBDzod/Op1VJPOczUwy75rk+ywAEKNX3cDITZKAQ3U80dl5ORKAYoc eTlwjabF9rfNGoFcG6JI4jYnaSLRUtgWyl7/1RJeHJdMJxFC+U5xlnKB9/X+dnaeK0c9 B30FgjqnbmD4X0abUd8A6llgsNq8xYUrWdgE12Ki77zLElJba+5BslxoVBndRw6pESWh osk9AJar7YOdG4FIkEC/Ff18onJif3A8JY18NG97sUfSk7ECw2E36IWRlC2RQc2MM0bu HNOBvNrF+JbcMn9MZVvPpI7J7qkT5mr6512nviVcHisIqRn6fTaNTroQbBkdLlAO1iqh fpJg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=b47PO4R1; 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 37-v6si16283892ple.389.2018.11.11.15.00.53; Sun, 11 Nov 2018 15:01:08 -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=@kernel.org header.s=default header.b=b47PO4R1; 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 S2390929AbeKLItT (ORCPT + 99 others); Mon, 12 Nov 2018 03:49:19 -0500 Received: from mail.kernel.org ([198.145.29.99]:53628 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390750AbeKLIWi (ORCPT ); Mon, 12 Nov 2018 03:22:38 -0500 Received: from localhost (unknown [206.108.79.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 8CC2D22353; Sun, 11 Nov 2018 22:32:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1541975560; bh=VtV1hfBzQfYRFrVNG7Ujo0YlOf9nbAMpxolRUBwy/oM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=b47PO4R17oTmNZo6niFCLisChySZUsfACZ6JGYFnq2JOQCsBmsHKhDWv+dy/sxLNC ydWglioSk6uGiFmVuHxwh+13FOUmxufm/DxDe3kzlR74JBee2m7TjcmC1MkvjI1RUA 51TE0X1C1YzR48Wq5zrZppK7mibr8vkrxQILOCRY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Waiman.Long@hp.com, peterz@infradead.org, Juergen Gross , Jan Beulich Subject: [PATCH 4.14 121/222] xen: make xen_qlock_wait() nestable Date: Sun, 11 Nov 2018 14:23:38 -0800 Message-Id: <20181111221658.549686523@linuxfoundation.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181111221647.665769131@linuxfoundation.org> References: <20181111221647.665769131@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.14-stable review patch. If anyone has any objections, please let me know. ------------------ From: Juergen Gross commit a856531951dc8094359dfdac21d59cee5969c18e upstream. xen_qlock_wait() isn't safe for nested calls due to interrupts. A call of xen_qlock_kick() might be ignored in case a deeper nesting level was active right before the call of xen_poll_irq(): CPU 1: CPU 2: spin_lock(lock1) spin_lock(lock1) -> xen_qlock_wait() -> xen_clear_irq_pending() Interrupt happens spin_unlock(lock1) -> xen_qlock_kick(CPU 2) spin_lock_irqsave(lock2) spin_lock_irqsave(lock2) -> xen_qlock_wait() -> xen_clear_irq_pending() clears kick for lock1 -> xen_poll_irq() spin_unlock_irq_restore(lock2) -> xen_qlock_kick(CPU 2) wakes up spin_unlock_irq_restore(lock2) IRET resumes in xen_qlock_wait() -> xen_poll_irq() never wakes up The solution is to disable interrupts in xen_qlock_wait() and not to poll for the irq in case xen_qlock_wait() is called in nmi context. Cc: stable@vger.kernel.org Cc: Waiman.Long@hp.com Cc: peterz@infradead.org Signed-off-by: Juergen Gross Reviewed-by: Jan Beulich Signed-off-by: Juergen Gross Signed-off-by: Greg Kroah-Hartman --- arch/x86/xen/spinlock.c | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) --- a/arch/x86/xen/spinlock.c +++ b/arch/x86/xen/spinlock.c @@ -40,29 +40,25 @@ static void xen_qlock_kick(int cpu) */ static void xen_qlock_wait(u8 *byte, u8 val) { + unsigned long flags; int irq = __this_cpu_read(lock_kicker_irq); /* If kicker interrupts not initialized yet, just spin */ - if (irq == -1) + if (irq == -1 || in_nmi()) return; - /* If irq pending already clear it and return. */ + /* Guard against reentry. */ + local_irq_save(flags); + + /* If irq pending already clear it. */ if (xen_test_irq_pending(irq)) { xen_clear_irq_pending(irq); - return; + } else if (READ_ONCE(*byte) == val) { + /* Block until irq becomes pending (or a spurious wakeup) */ + xen_poll_irq(irq); } - if (READ_ONCE(*byte) != val) - return; - - /* - * If an interrupt happens here, it will leave the wakeup irq - * pending, which will cause xen_poll_irq() to return - * immediately. - */ - - /* Block until irq becomes pending (or perhaps a spurious wakeup) */ - xen_poll_irq(irq); + local_irq_restore(flags); } static irqreturn_t dummy_handler(int irq, void *dev_id)