Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp679918ybl; Wed, 11 Dec 2019 05:58:11 -0800 (PST) X-Google-Smtp-Source: APXvYqwL1ECE7XtiEkTEiyHoLCJg3/8QlULSSpIXz/H3iwu4OKWH49SzCMZMa2vOgiUvstWQfG46 X-Received: by 2002:a9d:175:: with SMTP id 108mr2341443otu.325.1576072691067; Wed, 11 Dec 2019 05:58:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576072691; cv=none; d=google.com; s=arc-20160816; b=BMcyKQ7dAdiaTqvm9kS5WJyzjQk/i1zz0FviLiG96OG9EgW/9Sux3Xzl5oTjnsSbOV 0C0eVY4l3o3QoV14sOuA4nfV1VUI+0F8HOCnlb6z5jxnf+prx/TNP2NRdvxPfO8zHz8V HfxqkDeOV555XP5ogDhLG4YmgbvhwvDWX8IW0crJWgcNEvSbqe1Zd7C/EBgn+MrlDTgL HO33qYBurZH//gPYPWUglGz47fIUqvq4XR8TGJ/Ba1J1V01cHXfJd/wJWDdzqO/7RIO4 unscHQwnae2ParqyzNoVZWDy0FpkoCRkqMS9JieEPVrOqqEwY3SWHgE1HA+wRK25yvpF M1Wg== 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 :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=O3QHlbCbZOD/ApStKoG49S9t9+fyrUjizMznqTA5J8Y=; b=w1mdOJ4a6Lrgyjh9n/aUgzd9TGrww3c5ZfQ6taktW12oNrx7MXx5uBOuzsmTFzBD/l 9q1NmHzkeB4hYxG/X90IsC4Fn7SO7b8uzdmYthWOsF8CztDYZ3/LyIslO+vyHpgj5+n2 xYKXPPC4Sj0E+5no02sSWB+IbMRuyUnWt541OsT+BCFFS1jdxzufzUtXYWn2xMr4va8d IfPSuXeiIJjSg73ijbEuI8Dn6wETrKhmsBImauwKCEi8mQFXzHx48qoGpg7syBrUhkeB UJMyzTU9gjSo+i+Rc8kA+Mqf0knVlWodplS6i1hnaW7cWmFxFOmQx6L5S5b+TssArRmQ Fv4Q== 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 a14si1356221otk.2.2019.12.11.05.57.59; Wed, 11 Dec 2019 05:58:11 -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 S1729724AbfLKN46 (ORCPT + 99 others); Wed, 11 Dec 2019 08:56:58 -0500 Received: from mx2.suse.de ([195.135.220.15]:58636 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728128AbfLKN46 (ORCPT ); Wed, 11 Dec 2019 08:56:58 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 7F388AAB8; Wed, 11 Dec 2019 13:56:56 +0000 (UTC) Subject: Re: [PATCH] xen-blkback: prevent premature module unload To: =?UTF-8?Q?Roger_Pau_Monn=c3=a9?= , "Durrant, Paul" Cc: "xen-devel@lists.xenproject.org" , "linux-block@vger.kernel.org" , "linux-kernel@vger.kernel.org" , Konrad Rzeszutek Wilk , Jens Axboe References: <20191210145305.6605-1-pdurrant@amazon.com> <20191211112754.GM980@Air-de-Roger> <14a01d62046c48ee9b2486917370b5f5@EX13D32EUC003.ant.amazon.com> <20191211135523.GP980@Air-de-Roger> From: =?UTF-8?B?SsO8cmdlbiBHcm/Dnw==?= Message-ID: Date: Wed, 11 Dec 2019 14:56:54 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.2.1 MIME-Version: 1.0 In-Reply-To: <20191211135523.GP980@Air-de-Roger> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 11.12.19 14:55, Roger Pau Monné wrote: > On Wed, Dec 11, 2019 at 01:27:42PM +0000, Durrant, Paul wrote: >>> -----Original Message----- >>> From: Roger Pau Monné >>> Sent: 11 December 2019 11:29 >>> To: Durrant, Paul >>> Cc: xen-devel@lists.xenproject.org; linux-block@vger.kernel.org; linux- >>> kernel@vger.kernel.org; Konrad Rzeszutek Wilk ; >>> Jens Axboe >>> Subject: Re: [PATCH] xen-blkback: prevent premature module unload >>> >>> On Tue, Dec 10, 2019 at 02:53:05PM +0000, Paul Durrant wrote: >>>> 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é >>> >>> One nit below. >>> >>>> --- >>>> Cc: Konrad Rzeszutek Wilk >>>> Cc: "Roger Pau Monné" >>>> Cc: Jens Axboe >>>> --- >>>> 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 e8c5c54e1d26..59d576d27ca7 100644 >>>> --- a/drivers/block/xen-blkback/xenbus.c >>>> +++ b/drivers/block/xen-blkback/xenbus.c >>>> @@ -171,6 +171,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 free back to the cache. >>> ^ freed >> >> Oh yes. Can this be done on commit, or would you like me to send a v2? > > Adjusting on commit would be fine for me, but it's up to Juergen since > he is the one that will pick this up. IIRC the module unload patches > didn't go through the block subsystem. Oh, right. Yes, will fix this when committing. Juergen