Received: by 2002:a25:c205:0:0:0:0:0 with SMTP id s5csp5515644ybf; Thu, 5 Mar 2020 02:05:00 -0800 (PST) X-Google-Smtp-Source: ADFU+vuGuaxpXiiQuILNCgSXDIKp65ZFF2i6vSUBj+KcU+xMgtaoC68QNbhKxChQAc0OAaUsmv7X X-Received: by 2002:a9d:6a9a:: with SMTP id l26mr6278803otq.104.1583402700291; Thu, 05 Mar 2020 02:05:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1583402700; cv=none; d=google.com; s=arc-20160816; b=Q33VW9ibBdNCr6jI3hesDu5/Wj9oILmNjj3rYxZHvikr5ZBsNb6DJvzlB9O2cLg3+2 lhyqhn0OagI8qmFazHXaB0HnxqwjflhmTpHfPFTIoodLNt4sJuXF6LsrbO+vakq4PiY3 eXHV5dCn5dJlmlXFFJ82C9pd4aUTak6l/bkap+scZwg4ENek8ZDtKTuBPAwPJq98HYSW sm3qlbl36yBI5ZD/xYzTv6epyWSkidlne8mMlQrzTAJCqojS8wq8zqVYjGzJZWl5k/qg onpCnMV+Hqt8HJM4d4jNsDB6AgFp+eUuhntzBQaR+Ogk59ymtBUDydd80TzYENWE5ttP MTQA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from; bh=mxXjEvjsrpRrjc/2uBSklQTrQApJOoJLz0qwJOuLn2s=; b=sit0d6ouGmK+le5HVCP/Tk3KjHLjOShnvJE46bxzrVJ//5yT7GaJQX8BwVHe5MEAXR R2lsPhA0WJ9IoSEaMhO+mB9se5SQM+dZnrwvdLzQfU7+EJfUBqSC7xteSfQLXatwoxGI Vp/n/4OMLj73J4Mw4Z6nJd6/JAeGMle8jkNJNVxUGHqYIS7e82RYcvsYVf7lJZmxe0Vs j3zFHFZ8CGFapRRnnFhHHdpeoSbsNl5507GlzaUWh3/KZunogAuXt6sMbNa4P9eYr3DZ nZuU/IuAuxnJjef/ixmBBDPp4ClGd2t/0Y4oIVZXKtqzcrrOY5RwLelvhNMgo4ez7T+P 6HaQ== ARC-Authentication-Results: i=1; mx.google.com; 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 r23si3223966otd.203.2020.03.05.02.04.48; Thu, 05 Mar 2020 02:05:00 -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; 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 S1726874AbgCEKD1 (ORCPT + 99 others); Thu, 5 Mar 2020 05:03:27 -0500 Received: from mx2.suse.de ([195.135.220.15]:44900 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725937AbgCEKD1 (ORCPT ); Thu, 5 Mar 2020 05:03:27 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 8D629B23A; Thu, 5 Mar 2020 10:03:25 +0000 (UTC) From: Juergen Gross To: xen-devel@lists.xenproject.org, linux-kernel@vger.kernel.org Cc: Juergen Gross , Boris Ostrovsky , Stefano Stabellini Subject: [PATCH] xen/xenbus: fix locking Date: Thu, 5 Mar 2020 11:03:23 +0100 Message-Id: <20200305100323.16736-1-jgross@suse.com> X-Mailer: git-send-email 2.16.4 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit 060eabe8fbe726 ("xenbus/backend: Protect xenbus callback with lock") introduced a bug by holding a lock while calling a function which might schedule. Fix that by using a semaphore instead. Fixes: 060eabe8fbe726 ("xenbus/backend: Protect xenbus callback with lock") Signed-off-by: Juergen Gross --- drivers/xen/xenbus/xenbus_probe.c | 10 +++++----- drivers/xen/xenbus/xenbus_probe_backend.c | 5 +++-- include/xen/xenbus.h | 3 ++- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/drivers/xen/xenbus/xenbus_probe.c b/drivers/xen/xenbus/xenbus_probe.c index 66975da4f3b6..8c4d05b687b7 100644 --- a/drivers/xen/xenbus/xenbus_probe.c +++ b/drivers/xen/xenbus/xenbus_probe.c @@ -239,9 +239,9 @@ int xenbus_dev_probe(struct device *_dev) goto fail; } - spin_lock(&dev->reclaim_lock); + down(&dev->reclaim_sem); err = drv->probe(dev, id); - spin_unlock(&dev->reclaim_lock); + up(&dev->reclaim_sem); if (err) goto fail_put; @@ -271,9 +271,9 @@ int xenbus_dev_remove(struct device *_dev) free_otherend_watch(dev); if (drv->remove) { - spin_lock(&dev->reclaim_lock); + down(&dev->reclaim_sem); drv->remove(dev); - spin_unlock(&dev->reclaim_lock); + up(&dev->reclaim_sem); } module_put(drv->driver.owner); @@ -473,7 +473,7 @@ int xenbus_probe_node(struct xen_bus_type *bus, goto fail; dev_set_name(&xendev->dev, "%s", devname); - spin_lock_init(&xendev->reclaim_lock); + sema_init(&xendev->reclaim_sem, 1); /* Register with generic device framework. */ err = device_register(&xendev->dev); diff --git a/drivers/xen/xenbus/xenbus_probe_backend.c b/drivers/xen/xenbus/xenbus_probe_backend.c index 791f6fe01e91..9b2fbe69bccc 100644 --- a/drivers/xen/xenbus/xenbus_probe_backend.c +++ b/drivers/xen/xenbus/xenbus_probe_backend.c @@ -45,6 +45,7 @@ #include #include #include +#include #include #include @@ -257,10 +258,10 @@ static int backend_reclaim_memory(struct device *dev, void *data) drv = to_xenbus_driver(dev->driver); if (drv && drv->reclaim_memory) { xdev = to_xenbus_device(dev); - if (!spin_trylock(&xdev->reclaim_lock)) + if (down_trylock(&xdev->reclaim_sem)) return 0; drv->reclaim_memory(xdev); - spin_unlock(&xdev->reclaim_lock); + up(&xdev->reclaim_sem); } return 0; } diff --git a/include/xen/xenbus.h b/include/xen/xenbus.h index 89a889585ba0..850a43bd69d3 100644 --- a/include/xen/xenbus.h +++ b/include/xen/xenbus.h @@ -42,6 +42,7 @@ #include #include #include +#include #include #include #include @@ -76,7 +77,7 @@ struct xenbus_device { enum xenbus_state state; struct completion down; struct work_struct work; - spinlock_t reclaim_lock; + struct semaphore reclaim_sem; }; static inline struct xenbus_device *to_xenbus_device(struct device *dev) -- 2.16.4