Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3477681imu; Sun, 11 Nov 2018 16:01:26 -0800 (PST) X-Google-Smtp-Source: AJdET5c/KOZ5k/rsWpAmSAg/BgcWAefcgZy0+I6Q2LjmWiwtyTMzn5qB5LiZ1IxN9P3kwsXGV0Nu X-Received: by 2002:a62:8749:: with SMTP id i70-v6mr18346138pfe.41.1541980886610; Sun, 11 Nov 2018 16:01:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541980886; cv=none; d=google.com; s=arc-20160816; b=mDSsp+xx5zDtsWqV3P+KyHp6RTBz1+rAcQ5++84BJ6z41fMuCuXy6CGe+1DXJ4sUnT KRIyR8CQ2MXJCQmmq8TPC0/9iFMcjO/Zk02J31a51XUxiXfS90fhqlm7tYTQRi7livzi B7pSbWJjYbKKGRfBcJPhzx76FhEOyA9DTa+I281JfqUbTrf8G9wiT3hAllAC7VZabPgC eYgdXxLh+HAw1U3mBZGPfvL49dL3+wDi3VGDuf0RRvUgLGWiNDyN7yDVDtXeMe6EI1T2 SQsCeu4jfM83iiIijbLP+wPW/OUcYTFIgl425Qflqs4E4AtkxUE//OYlTFY8s7DBdapv jwDg== 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=m52kTP5B/dJeE+Hlsa3hVkOcPfCPKfLe/1QBJCuCt+4=; b=G4qBA0QuGgTHJ6XRlw8EzHUnisv8XKBx45+eelc8tfZzUyLUsnj1zKd1TOQ1EGGlCh QyPkPlM/rIkgGyjPxgBJFR7S6ruM5l/8R6Psi89BlLubNZX/XlCHWXnAAwUSc7ZOy2W/ lSTKSPkD+TrNV+ULGF0/TiksQAEnZNQmhjCLOFhgdnI+h5zKmF/DuKWaWlT9VVfCYJ9S +g+raItu1tnDWODrzifNJmO2OUMLtUHxSyEHKhMiiirERjeDoTCg8GSyyqfa3tnTHoRL bd5ESEnoppLf+hHf1Wkx3las0hZzFwXPUbS8CLYDAG4/JxM6TLijGpq/qH1JUDIteMKm LnCQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=gL84WsoD; 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 s4si14258450pga.377.2018.11.11.16.01.11; Sun, 11 Nov 2018 16:01:26 -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=gL84WsoD; 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 S1732292AbeKLIR7 (ORCPT + 99 others); Mon, 12 Nov 2018 03:17:59 -0500 Received: from mail.kernel.org ([198.145.29.99]:34210 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732255AbeKLIR6 (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 596F321508; 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=hv3yzZtipGVF9UMrmsjzQfpfl0aGS3fhkzmpSoAyCYE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gL84WsoD57zh5FxngyMNRprrVxG4JNtUrJxZbnVYTXTz7ljvEYQu+Iy93mRt7YBbG LYRVun2m3DW9wGi+pgHrwdFn5PfIUa5J0S7FS/KilCvVNY7u09JrvwhsGh9yGjlEd2 4NOt27ePUDdsrD6DQpYJaOXt4LOKy9ucUKqibyaQ= 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 204/361] xen: make xen_qlock_wait() nestable Date: Sun, 11 Nov 2018 14:19:11 -0800 Message-Id: <20181111221648.885899244@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 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 @@ -39,29 +39,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)