Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3477934imu; Sun, 11 Nov 2018 16:01:41 -0800 (PST) X-Google-Smtp-Source: AJdET5fqe3mWUJk3FyF3VpsVHnfLLWDe0xOIF2Y1Ms57TfSB+tlZbnKYUKDBUxvpVHNoJcBjJ4VI X-Received: by 2002:a17:902:1124:: with SMTP id d33-v6mr18441106pla.125.1541980901348; Sun, 11 Nov 2018 16:01:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541980901; cv=none; d=google.com; s=arc-20160816; b=pyOTrNZuzCKU6ULh9LkoxBou2TxmzLopJSlWuOqE8k0elWgJqKdclM22GM0iOA8k5K hpxEYTegzFTejntorZpJAggSsZne5jrA0GJLSnFJW80qh0mtVYHTHPYYkNT+6KmkVgsF 6n+rRVgDi/TzytPgsxo8PV2Vb/N75p1xAk0NXRWUCHpsVnBcmdkA2PRMkFb/ea5EJpWt tXroTdPWsqyF9t+fBrzhhyONPVjvmmqeWwlPlyaKSq5G/BSIMFTi4jVShoZDgyjS3Yiy 9RKXtfc1mWsAHZWCPdJxzG9JPnismZ2QvsjcvPvw/IkTLARpq4X574YX3WbCXSo57npt 1O9g== 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=A5fvFsVGCpR1XfnVaRtljzgWgcBfOBJfDpGm+msGjhg=; b=QnUbV9Qa10ETfHh0qmW6KYPMQrdxRh3ll6o3dKv71UDs0rD7v9vwyCf9aWbUj99lBQ jHX0DQxOD1+WjiueCVzwP7T6+q5RBespNBzccWO0/Y76qWHcwfFnyYwxRAzS1pvgqI9V bvvkPjGPUV9qfrtHRdhaYg0iLE+OD66ZPEil08eyn3O63SdgtXM/J0xogfo3eDcOkLTN zII4t6mdVkXn35K1SGVT/umH8N/yMQ+aW6QoVgKJDXiHyUqqQ6jdFr5YwTMPtZKLXUQ+ 9d7cA8LX4lH9cndO4OMyEp4BeiOG6LCAgAPGnNx9OrBTfuA+KIi3eKP+W9Ft0cIIfqQF TBzQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=0x52pa19; 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 h3si15152663pgi.391.2018.11.11.16.01.26; Sun, 11 Nov 2018 16:01:41 -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=0x52pa19; 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 S1732279AbeKLIR6 (ORCPT + 99 others); Mon, 12 Nov 2018 03:17:58 -0500 Received: from mail.kernel.org ([198.145.29.99]:35336 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732235AbeKLIR6 (ORCPT ); Mon, 12 Nov 2018 03:17:58 -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 0FA9221582; Sun, 11 Nov 2018 22:28:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1541975282; bh=y00m3A7/LE5OjuwRCbgr5AUXszvVkQeN3QVX6Mqd9dU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=0x52pa19nOtr5QFN2wLuyZE8wCT0D9p8JTgw1JE4WACorOSsLFVyrysGKu3z2PTfB cL7U+xLiXKxNJg174LljqxdTEaE5Fzoj56ekmaOriXYogaxmC+oMscaa8eg/xl+4Qj AeoJ9GIE5uN50QdKBf9/yhB68qaqcnUIZl450wgY= 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.19 203/361] xen: fix race in xen_qlock_wait() Date: Sun, 11 Nov 2018 14:19:10 -0800 Message-Id: <20181111221648.793194743@linuxfoundation.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181111221619.915519183@linuxfoundation.org> References: <20181111221619.915519183@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.19-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 @@ -45,17 +45,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;