Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3432574imu; Sun, 11 Nov 2018 15:00:16 -0800 (PST) X-Google-Smtp-Source: AJdET5dTyx+7VL7DNuzYBLUFcT2oqnReNtNFIUVso4mRmVXBBO2h86rO130AkSdkMHSh0X3GmQRB X-Received: by 2002:a63:4745:: with SMTP id w5mr15737678pgk.377.1541977215974; Sun, 11 Nov 2018 15:00:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541977215; cv=none; d=google.com; s=arc-20160816; b=d6ioLDrWv2YtTTlidoZ//JyGArOkYwB8aTmgUi5KZfWXHs00ThA9YfLX5TmPJxjM8t n4AnHdLlyynafYf28Td2ZfkMYGjvVEMtkCcYEAOdKxrOUW5Blj5wsBEEP+oY8F0P4v60 M2Hf1QZFVcZ5rRAlt80Fn9HSJ0WMP3AuqQiJrQjwvVN9j3uL8a4a+f9IWPuMZ7Avl0/N hmmc8Oq7u+ANA7xv1CEWqei7HwzZUjG/P2KJrjh5qPoFyvJ0fsQirMC91N4H+6YNnmL1 0zgJQTJ5w+hPrdIiDDlr4NhULMHmes/pVahDzwezu+o7i8auocfJLwWpJx6+I6H7Mtk0 hfjA== 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=4j4BhTUTUDjEjPXV+xt0szIPX4Z87MqtM2SMC9lieWY=; b=xrZ0pp8f3sLzO5BvVglk5O4xRXEuC7MSwkBF0oeLjGPfNkcJUneFbv2zhfT66H+SJs uGmglvh9tvKBVFNxQBfFSo3UJAAIuZfMXwR5VA/KKuAlMP4ENLIeTjFz171ieGuM2pPa CraADtkYp0PWQ5YLIjruUMdiAJiBj5Ajm2/tcCHF0DbAzq37U9YkiPb/l3JDJGLfE881 ev8BlRFL5LAAYKBjU6linoA4PrjOJnGKHBIIqNHJDxO+TiIAcPMzu0pK+agM4dShq6uz 3WgvogHoe74bJ0MUBq3E0sj/2y7EDqypcfLG7WktQyIkjd5h2IMU1X6heG8pKoKoOUNV /1FQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=xKOjgrxV; 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 h6-v6si17992544plk.373.2018.11.11.15.00.01; Sun, 11 Nov 2018 15:00:15 -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=xKOjgrxV; 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 S2390840AbeKLIto (ORCPT + 99 others); Mon, 12 Nov 2018 03:49:44 -0500 Received: from mail.kernel.org ([198.145.29.99]:52752 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390764AbeKLIWh (ORCPT ); Mon, 12 Nov 2018 03:22:37 -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 426B422419; 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=J6ZHLU3ComOF3mIL5ZRfMEbEhVzQYI1i6gkSfKfElvU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=xKOjgrxVWmM8blzRIj9/jcowVbEJMkaKMDPCHMQBhntI8bdJURI1UNivAjSa897nf vTbR/kLxFTpqwq83tM4z1QTm4FyKw11b2tqELSixCwkA37zesuKRk1++lSGrdDHR7G phWfQxW0NP30ASWNU6Q0EPgmPIAXE+cYVmt77Up8= 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 120/222] xen: fix race in xen_qlock_wait() Date: Sun, 11 Nov 2018 14:23:37 -0800 Message-Id: <20181111221658.451137611@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 2ac2a7d4d9ff4e01e36f9c3d116582f6f655ab47 upstream. In the following situation a vcpu waiting for a lock might not be woken up from xen_poll_irq(): CPU 1: CPU 2: CPU 3: takes a spinlock tries to get lock -> xen_qlock_wait() frees the lock -> xen_qlock_kick(cpu2) -> xen_clear_irq_pending() takes lock again tries to get lock -> *lock = _Q_SLOW_VAL -> *lock == _Q_SLOW_VAL ? -> xen_poll_irq() frees the lock -> xen_qlock_kick(cpu3) And cpu 2 will sleep forever. This can be avoided easily by modifying xen_qlock_wait() to call xen_poll_irq() only if the related irq was not pending and to call xen_clear_irq_pending() only if it was pending. 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 | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) --- a/arch/x86/xen/spinlock.c +++ b/arch/x86/xen/spinlock.c @@ -46,17 +46,12 @@ static void xen_qlock_wait(u8 *byte, u8 if (irq == -1) return; - /* clear pending */ - xen_clear_irq_pending(irq); - barrier(); + /* If irq pending already clear it and return. */ + if (xen_test_irq_pending(irq)) { + xen_clear_irq_pending(irq); + return; + } - /* - * We check the byte value after clearing pending IRQ to make sure - * that we won't miss a wakeup event because of the clearing. - * - * The sync_clear_bit() call in xen_clear_irq_pending() is atomic. - * So it is effectively a memory barrier for x86. - */ if (READ_ONCE(*byte) != val) return;