From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.1 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D4D24C43603 for ; Fri, 20 Dec 2019 14:47:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A5F3E218AC for ; Fri, 20 Dec 2019 14:47:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1576853238; bh=zpryMmh7r1ZdKjkQ4fS6T5Gjlv9Z7AzzCKc75EjCr44=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=ndG3ATcwUsCvT8mvMeNUWtmdWa89Npy57Ee8Qyx7zRCSRO5OC2OKA2D85kBQbLaah oZciO/sQ99Il4Q4BJwTpRvVUcdMna4i/+iVEKOBSyYLxq2Bo8qkU0TSDEPfpaAMGHy aQKyaEYB18+4RLylG94b9PrXsz539ato9zHMseKo= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727779AbfLTOrR (ORCPT ); Fri, 20 Dec 2019 09:47:17 -0500 Received: from mail.kernel.org ([198.145.29.99]:45442 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727667AbfLTOrO (ORCPT ); Fri, 20 Dec 2019 09:47:14 -0500 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 6AE3B24680; Fri, 20 Dec 2019 14:47:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1576853234; bh=zpryMmh7r1ZdKjkQ4fS6T5Gjlv9Z7AzzCKc75EjCr44=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hI+sSIBzQ0lvNZZsOjF0Y6CmVJcf9Y3ey4CEPskzLwp55veR8sT15d1W2TIUwC0W5 B6RF5KEfLnHh+jDMSpIsRNLoqUZ3eW7pGN+vG83fD/0U89x8I6p7mypSbphIvJOo4A Z/w3ghCF57pg+nNl5TF3EXpiEQIhCMo52OI4nJVA= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Paul Durrant , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Juergen Gross , Sasha Levin , xen-devel@lists.xenproject.org, linux-block@vger.kernel.org Subject: [PATCH AUTOSEL 4.9 12/14] xen-blkback: prevent premature module unload Date: Fri, 20 Dec 2019 09:46:56 -0500 Message-Id: <20191220144658.10414-12-sashal@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191220144658.10414-1-sashal@kernel.org> References: <20191220144658.10414-1-sashal@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Paul Durrant [ Upstream commit fa2ac657f9783f0891b2935490afe9a7fd29d3fa ] Objects allocated by xen_blkif_alloc come from the 'blkif_cache' kmem cache. This cache is destoyed when xen-blkif is unloaded so it is necessary to wait for the deferred free routine used for such objects to complete. This necessity was missed in commit 14855954f636 "xen-blkback: allow module to be cleanly unloaded". This patch fixes the problem by taking/releasing extra module references in xen_blkif_alloc/free() respectively. Signed-off-by: Paul Durrant Reviewed-by: Roger Pau Monné Signed-off-by: Juergen Gross Signed-off-by: Sasha Levin --- drivers/block/xen-blkback/xenbus.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/drivers/block/xen-blkback/xenbus.c b/drivers/block/xen-blkback/xenbus.c index ad736d7de8383..1d1f866579679 100644 --- a/drivers/block/xen-blkback/xenbus.c +++ b/drivers/block/xen-blkback/xenbus.c @@ -178,6 +178,15 @@ static struct xen_blkif *xen_blkif_alloc(domid_t domid) blkif->domid = domid; atomic_set(&blkif->refcnt, 1); init_completion(&blkif->drain_complete); + + /* + * Because freeing back to the cache may be deferred, it is not + * safe to unload the module (and hence destroy the cache) until + * this has completed. To prevent premature unloading, take an + * extra module reference here and release only when the object + * has been freed back to the cache. + */ + __module_get(THIS_MODULE); INIT_WORK(&blkif->free_work, xen_blkif_deferred_free); return blkif; @@ -322,6 +331,7 @@ static void xen_blkif_free(struct xen_blkif *blkif) /* Make sure everything is drained before shutting down */ kmem_cache_free(xen_blkif_cachep, blkif); + module_put(THIS_MODULE); } int __init xen_blkif_interface_init(void) -- 2.20.1