Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp2091658ybp; Thu, 10 Oct 2019 02:02:52 -0700 (PDT) X-Google-Smtp-Source: APXvYqyZ0fTD9nQtb/S+uzo1bD4kd6Rbl/tNr9Y2XPj19PF2bOoFrPnuRWzUy5Ij0nti8QsUSyyJ X-Received: by 2002:a17:906:4d50:: with SMTP id b16mr6980588ejv.245.1570698172828; Thu, 10 Oct 2019 02:02:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570698172; cv=none; d=google.com; s=arc-20160816; b=a53CmAUAlQvYtvFvihWyCCKraX5kpKe4tBqI2dBvN1nrT9Iv+HgwhsCSR1qStiqQN8 Z0b7ZtxPhmcdrtgX7yOYBUrh+gCE5a7fcmUcd3WU8N5cTUEZW/9psptBK8h+BqYA/MzV kSWsYkrEw9pAISxOvxhAbfAq8AdblSg5EtJhBDcuxX9REp0n4F2jSTuQxoQW6htSbYrO XZAirOpu4l6L+yn905kRK7V+3i0hwOfOC85f1EBmkRbebNqGqTUNz1O0DSLFuM2VmqU3 hBYe9dtoLHfZ8QHesBCaYhCdL7XLkREoKlmMZVXiCFmYXzeB4Q4HtoglANAqPGHU5fJE cUgA== 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=oFiSBm+OImVqc60x5yIBK8xSHx4O6zJ7xBuZ2fwXXPw=; b=NfMbd/If1TL5XRCKNAa7nOk5LGbSdz1yInCmDtRMdY4psJ7DiOPXKQeiy5osOqrDhj UvMoRXOHdqIwziuePowZDrkFDSgteHRpiAmVKOW5JlHHIUzsbVf0b2qhJlvRK8s6llTr 772EZq9naGtOVYh28utkXF60m/EGScp8Lirxfe/+fX5U/q+46KnwOllsGL9Cq2ZcWlUm sbgUC7IaRjgCA/G5PJUa2onmjwphHbd4m7Kgqd2eQ6NviWvghvdqTEvqBiVyN9DLt1V2 G8Q2qFKgUB2XKN4DUVzkPEczNsZAQNWsgIKhNg7qyWb0iV3fpHZ83B76/Xl6sqRcwfIS 63HQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=PG6+aaGs; 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 ca9si2825130edb.79.2019.10.10.02.02.29; Thu, 10 Oct 2019 02:02:52 -0700 (PDT) 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=PG6+aaGs; 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 S2387992AbfJJJA0 (ORCPT + 99 others); Thu, 10 Oct 2019 05:00:26 -0400 Received: from mail.kernel.org ([198.145.29.99]:47536 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388614AbfJJImw (ORCPT ); Thu, 10 Oct 2019 04:42:52 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (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 7C47722492; Thu, 10 Oct 2019 08:42:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1570696972; bh=ctkmw1M+BK4/k/ZFVsn6InxKW70lswMcW/BIGGD3PCA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PG6+aaGssTXbGrY+iRCAsYZUOm3eArZzkph2m0mPlYiFilye/ot+V6xZIJk81ZBOF qgWD77YuN+/z5M2uy/ESkI0WPbIrKn7mKFO5jHDOcdzvJK5zeMWCFquwhoPZx2AOw5 vw3bxxI1M5lb81ayuAJja5NPtEBO85/SuXnLxo/A= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, James Dingwall , Juergen Gross , Boris Ostrovsky Subject: [PATCH 5.3 083/148] xen/xenbus: fix self-deadlock after killing user process Date: Thu, 10 Oct 2019 10:35:44 +0200 Message-Id: <20191010083616.377380735@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191010083609.660878383@linuxfoundation.org> References: <20191010083609.660878383@linuxfoundation.org> User-Agent: quilt/0.66 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 From: Juergen Gross commit a8fabb38525c51a094607768bac3ba46b3f4a9d5 upstream. In case a user process using xenbus has open transactions and is killed e.g. via ctrl-C the following cleanup of the allocated resources might result in a deadlock due to trying to end a transaction in the xenbus worker thread: [ 2551.474706] INFO: task xenbus:37 blocked for more than 120 seconds. [ 2551.492215] Tainted: P OE 5.0.0-29-generic #5 [ 2551.510263] "echo 0 > /proc/sys/kernel/hung_task_timeout_secs" disables this message. [ 2551.528585] xenbus D 0 37 2 0x80000080 [ 2551.528590] Call Trace: [ 2551.528603] __schedule+0x2c0/0x870 [ 2551.528606] ? _cond_resched+0x19/0x40 [ 2551.528632] schedule+0x2c/0x70 [ 2551.528637] xs_talkv+0x1ec/0x2b0 [ 2551.528642] ? wait_woken+0x80/0x80 [ 2551.528645] xs_single+0x53/0x80 [ 2551.528648] xenbus_transaction_end+0x3b/0x70 [ 2551.528651] xenbus_file_free+0x5a/0x160 [ 2551.528654] xenbus_dev_queue_reply+0xc4/0x220 [ 2551.528657] xenbus_thread+0x7de/0x880 [ 2551.528660] ? wait_woken+0x80/0x80 [ 2551.528665] kthread+0x121/0x140 [ 2551.528667] ? xb_read+0x1d0/0x1d0 [ 2551.528670] ? kthread_park+0x90/0x90 [ 2551.528673] ret_from_fork+0x35/0x40 Fix this by doing the cleanup via a workqueue instead. Reported-by: James Dingwall Fixes: fd8aa9095a95c ("xen: optimize xenbus driver for multiple concurrent xenstore accesses") Cc: # 4.11 Signed-off-by: Juergen Gross Reviewed-by: Boris Ostrovsky Signed-off-by: Boris Ostrovsky Signed-off-by: Greg Kroah-Hartman --- drivers/xen/xenbus/xenbus_dev_frontend.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) --- a/drivers/xen/xenbus/xenbus_dev_frontend.c +++ b/drivers/xen/xenbus/xenbus_dev_frontend.c @@ -55,6 +55,7 @@ #include #include #include +#include #include #include @@ -116,6 +117,8 @@ struct xenbus_file_priv { wait_queue_head_t read_waitq; struct kref kref; + + struct work_struct wq; }; /* Read out any raw xenbus messages queued up. */ @@ -300,14 +303,14 @@ static void watch_fired(struct xenbus_wa mutex_unlock(&adap->dev_data->reply_mutex); } -static void xenbus_file_free(struct kref *kref) +static void xenbus_worker(struct work_struct *wq) { struct xenbus_file_priv *u; struct xenbus_transaction_holder *trans, *tmp; struct watch_adapter *watch, *tmp_watch; struct read_buffer *rb, *tmp_rb; - u = container_of(kref, struct xenbus_file_priv, kref); + u = container_of(wq, struct xenbus_file_priv, wq); /* * No need for locking here because there are no other users, @@ -333,6 +336,18 @@ static void xenbus_file_free(struct kref kfree(u); } +static void xenbus_file_free(struct kref *kref) +{ + struct xenbus_file_priv *u; + + /* + * We might be called in xenbus_thread(). + * Use workqueue to avoid deadlock. + */ + u = container_of(kref, struct xenbus_file_priv, kref); + schedule_work(&u->wq); +} + static struct xenbus_transaction_holder *xenbus_get_transaction( struct xenbus_file_priv *u, uint32_t tx_id) { @@ -650,6 +665,7 @@ static int xenbus_file_open(struct inode INIT_LIST_HEAD(&u->watches); INIT_LIST_HEAD(&u->read_buffers); init_waitqueue_head(&u->read_waitq); + INIT_WORK(&u->wq, xenbus_worker); mutex_init(&u->reply_mutex); mutex_init(&u->msgbuffer_mutex);