From patchwork Fri Jul 28 14:53:55 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?SsO8cmdlbiBHcm/Dnw==?= X-Patchwork-Id: 9869043 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 8CC9C60382 for ; Fri, 28 Jul 2017 14:56:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7461C288CB for ; Fri, 28 Jul 2017 14:56:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6965F288CE; Fri, 28 Jul 2017 14:56:11 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id EA996288CB for ; Fri, 28 Jul 2017 14:56:10 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1db6eO-0001X7-UV; Fri, 28 Jul 2017 14:54:00 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1db6eN-0001Wz-FJ for xen-devel@lists.xenproject.org; Fri, 28 Jul 2017 14:53:59 +0000 Received: from [85.158.137.68] by server-9.bemta-3.messagelabs.com id 77/FB-01995-6005B795; Fri, 28 Jul 2017 14:53:58 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrPLMWRWlGSWpSXmKPExsVyuP0Ovy5rQHW kQe8uG4vvWyYzOTB6HP5whSWAMYo1My8pvyKBNePRvV3sBUt5Km7c2sncwDiXq4uRk0NCwEji 7cR/TF2MXBxCAgsZJZo29zCCJNgEVCU2XD/FCmKLCDhKrG5bCmYzCzhIzJp1lBnEFhbQk7i+o IcdxGYBqu/5vwjI5uDgFTCRmHs8GmK+vETHgcksExg5FzAyrGLUKE4tKkst0jW01EsqykzPKM lNzMzRNTQw1stNLS5OTE/NSUwq1kvOz93ECPRWPQMD4w7G38f9DjFKcjApifLeNKuOFOJLyk+ pzEgszogvKs1JLT7EKMPBoSTBa+gHlBMsSk1PrUjLzAGGDUxagoNHSYQ3CiTNW1yQmFucmQ6R OsVozLFh9fovTByvJvz/xiTEkpeflyolzrsPpFQApDSjNA9uECycLzHKSgnzMjIwMAjxFKQW5 WaWoMq/YhTnYFQS5n0PMoUnM68Ebt8roFOYgE6Z2FQJckpJIkJKqoHRUCzF9fK5rRXnP4ox9G xc57mpZevKoAtFxYIRK/0jz5rEPtPuOXyILSx8b/lNhqxV8zmWbw6/9v7zdKX02XYyjWzBrw/ eVP554lzenowdX9ZOTHua55oScfuB/6Yl5yY833h9SU3DzpXPdpqpKvTdFJu4hL9VuejDC6fd Tg+nvnpwgjPgnKhMqxJLcUaioRZzUXEiAAyNTyZiAgAA X-Env-Sender: jgross@suse.com X-Msg-Ref: server-10.tower-31.messagelabs.com!1501253637!106913995!1 X-Originating-IP: [195.135.220.15] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 9.4.25; banners=-,-,- X-VirusChecked: Checked Received: (qmail 43858 invoked from network); 28 Jul 2017 14:53:57 -0000 Received: from mx2.suse.de (HELO mx1.suse.de) (195.135.220.15) by server-10.tower-31.messagelabs.com with DHE-RSA-CAMELLIA256-SHA encrypted SMTP; 28 Jul 2017 14:53:57 -0000 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id A5D9EACA7; Fri, 28 Jul 2017 14:53:57 +0000 (UTC) From: Juergen Gross To: linux-kernel@vger.kernel.org, xen-devel@lists.xenproject.org Date: Fri, 28 Jul 2017 16:53:55 +0200 Message-Id: <20170728145355.17258-1-jgross@suse.com> X-Mailer: git-send-email 2.12.3 Cc: Juergen Gross , boris.ostrovsky@oracle.com Subject: [Xen-devel] [PATCH] xen: avoid deadlock in xenbus X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP When starting the xenwatch thread a theoretical deadlock situation is possible: xs_init() contains: task = kthread_run(xenwatch_thread, NULL, "xenwatch"); if (IS_ERR(task)) return PTR_ERR(task); xenwatch_pid = task->pid; And xenwatch_thread() does: mutex_lock(&xenwatch_mutex); ... event->handle->callback(); ... mutex_unlock(&xenwatch_mutex); The callback could call unregister_xenbus_watch() which does: ... if (current->pid != xenwatch_pid) mutex_lock(&xenwatch_mutex); ... In case a watch is firing before xenwatch_pid could be set and the callback of that watch unregisters a watch, then a self-deadlock would occur. Avoid this by setting xenwatch_pid in xenwatch_thread(). Signed-off-by: Juergen Gross Reviewed-by: Boris Ostrovsky --- drivers/xen/xenbus/xenbus_xs.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/xen/xenbus/xenbus_xs.c b/drivers/xen/xenbus/xenbus_xs.c index e46080214955..3e59590c7254 100644 --- a/drivers/xen/xenbus/xenbus_xs.c +++ b/drivers/xen/xenbus/xenbus_xs.c @@ -857,6 +857,8 @@ static int xenwatch_thread(void *unused) struct list_head *ent; struct xs_watch_event *event; + xenwatch_pid = current->pid; + for (;;) { wait_event_interruptible(watch_events_waitq, !list_empty(&watch_events)); @@ -925,7 +927,6 @@ int xs_init(void) task = kthread_run(xenwatch_thread, NULL, "xenwatch"); if (IS_ERR(task)) return PTR_ERR(task); - xenwatch_pid = task->pid; /* shutdown watches for kexec boot */ xs_reset_watches();