Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp2230844pxb; Mon, 8 Mar 2021 18:57:30 -0800 (PST) X-Google-Smtp-Source: ABdhPJzzlXsthOwqQldC/llUICzn+6SLAkT/Yphxmy1U9UDfkYBdpdcI/nNQJ0wGewhD+8SFo00e X-Received: by 2002:aa7:d94c:: with SMTP id l12mr1539147eds.311.1615258650258; Mon, 08 Mar 2021 18:57:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1615258650; cv=none; d=google.com; s=arc-20160816; b=r+ZEmJZprzmx7rgClGBStKfiTdBnsCuTfK0MsCUh6xylntBD/1cXdhQa4ZTeD4l0xe RFW/vtmj0XANKg1MROHy8ixRPR5Ehaal5BB96xkrsxzcRTNPYS8Mr5PE/t5isHaP5Mdk T7UWbeMo6xQSNPP90RfO8JDF9R0VV/Y/KjAE1MEbzSjWsu09TZ9XzpDSGMD8qJRl3y2I flb10fZzx28nCM6nB3s/MyUC5e5GbopjltKxaOWzOBAL8AfNNrBddFOhj4brc6I5UawX BW5thtcV1I6YXoqJJrqOWJLlydW+rCSjdgGp0Laa6RYQjhg/Hk5AxPWSqs4Cwx6TlvSp Ir5A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:sender:dkim-signature; bh=X1NdEaeznqDG0w3Bd/Nb0MooHdcqj7OMlg+M+dl0jEk=; b=evCY7bFa1gzSPrrbiq8mNClbGJHstTo1RAOUCbzVaRgSJEevp/ckNqK+fTbZo/AE5c CMgEA6Egi5qHQPwNvTWVCgOQz8n9igOlLwcEbG7Fms8/vGHiBkF68hJ5dpNGqv/bK4jq 0uI34psRo+0722WoAySBnGmf82yELSzhSHDvRJayKxOgTwhv72NYpRv3oxqt2Alrlrzw HLa7USVcTtshVXDMdspLCes+IbLid9AkeuEG6ztYHTd/NGJ5v2Y1HbKAxIalSXwAULw1 n6D864LuELJ0qK9+U0j4CDCSJB7Whys59qzquoJ4JancSTgs9kvObL3bLszr9EWC6U1A o/4g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=JcFCVCA1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id de6si8243320ejc.467.2021.03.08.18.57.08; Mon, 08 Mar 2021 18:57:30 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=JcFCVCA1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230214AbhCICzl (ORCPT + 99 others); Mon, 8 Mar 2021 21:55:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49794 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229520AbhCICzd (ORCPT ); Mon, 8 Mar 2021 21:55:33 -0500 Received: from mail-pj1-x102e.google.com (mail-pj1-x102e.google.com [IPv6:2607:f8b0:4864:20::102e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6D7D5C06174A; Mon, 8 Mar 2021 18:55:33 -0800 (PST) Received: by mail-pj1-x102e.google.com with SMTP id jx13so91444pjb.1; Mon, 08 Mar 2021 18:55:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=X1NdEaeznqDG0w3Bd/Nb0MooHdcqj7OMlg+M+dl0jEk=; b=JcFCVCA1vhjhbzEHAoko4Jj6BjMumWdOa097H0rfulPeKTK9V4yxCqgLEu6FODS7/L u6PRVZqB1Bptq58B104MQXpFRMMP+AEoIbDhve75xZtjXamMbW3cOII+4VqLU2YOVmeR PNFCV3L1PlhY+fgeAESTV06Y+XNc+0RK4clhnQ7ugAtiwF9f7IwXgWhkvl4DuPDUCTcC rMdJ5RBn/wB0r520hnbc40j9U1fSiOsyGpoog4MRYNUhnygsDRlKp3kp+cXq7/6od1Vg SRnB0lvStkJBCesGQn09WRo4bQqtKIWWj7/O6EwYRL3BryizpEYSjJCSHIpy9glWnLs1 MvSw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:from:to:cc:subject:message-id :references:mime-version:content-disposition:in-reply-to; bh=X1NdEaeznqDG0w3Bd/Nb0MooHdcqj7OMlg+M+dl0jEk=; b=Eu1ue0FKlOQpbkie+Un9Uj8UQoP1JKs9Y++ruLeR2e8aZGlWpQgGhUr4yhsDLCO8Hh 5Za4qEEcQU9qvnZw1utYuekkl1kmq7xpoLpRH2TAjBd0SLpe2GmOHzBJPQXTTDnY4HH7 ngiqKhTapNj8Zxj//P91zFSMtvz0n6D5Tt0zRY2yN+G4hF8BzZG4sramZBEpaujMIiKv LJtEzG53cZAk0g9dhsygkkmA+gSs7UfxSTXMndISa9k3x8x2Uqw6hFcu4knmauw5k+a0 dsAaAc0aGvmXkUFV3eGP8EmEnfQD8zjhHW3B3anNYBlvZPnZBjT1UwrwWev+H07h/NZ8 eV6A== X-Gm-Message-State: AOAM531o/0RXUx4XalYMefmhTf8NaQRZQk8ySCEBLShWSWU3UJFIhJ31 tXVX6qpVT2rDAUSBl/IG6es= X-Received: by 2002:a17:90a:7e94:: with SMTP id j20mr2343701pjl.8.1615258532930; Mon, 08 Mar 2021 18:55:32 -0800 (PST) Received: from google.com ([2620:15c:211:201:4ccc:acdd:25da:14d1]) by smtp.gmail.com with ESMTPSA id a19sm7825247pfc.65.2021.03.08.18.55.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Mar 2021 18:55:31 -0800 (PST) Sender: Minchan Kim Date: Mon, 8 Mar 2021 18:55:30 -0800 From: Minchan Kim To: Luis Chamberlain Cc: ngupta@vflare.org, sergey.senozhatsky.work@gmail.com, axboe@kernel.dk, mbenes@suse.com, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 1/2] zram: fix crashes due to use of cpu hotplug multistate Message-ID: References: <20210306022035.11266-1-mcgrof@kernel.org> <20210306022035.11266-2-mcgrof@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210306022035.11266-2-mcgrof@kernel.org> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, Mar 06, 2021 at 02:20:34AM +0000, Luis Chamberlain wrote: > The zram driver makes use of cpu hotplug multistate support, > whereby it associates a zram compression stream per CPU. To > support CPU hotplug multistate a callback enabled to allow > the driver to do what it needs when a CPU hotplugs. > > It is however currently possible to end up removing the > zram driver callback prior to removing the zram compression > streams per CPU. This would leave these compression streams > hanging. > > We need to fix ordering for driver load / removal, zram > device additions, in light of the driver's use of cpu > hotplug multistate. Since the zram driver exposes many > sysfs attribute which can also muck with the comrpession > streams this also means we can hit page faults today easily. Hi Luis, First of all, thanks for reporting the ancient bugs. Looks like you found several bugs and I am trying to digest them from your description to understand more clear. I need to ask stupid questions, first. If I understand correctly, bugs you found were related to module unloading race while the zram are still working. If so, couldn't we fix the bug like this(it's not a perfect patch but just wanted to show close module unloading race)? (I might miss other pieces here. Let me know. Thanks!) diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c index a711a2e2a794..646ae9e0b710 100644 --- a/drivers/block/zram/zram_drv.c +++ b/drivers/block/zram/zram_drv.c @@ -1696,6 +1696,8 @@ static void zram_reset_device(struct zram *zram) return; } + module_put(THIS_MODULE); + comp = zram->comp; disksize = zram->disksize; zram->disksize = 0; @@ -1744,13 +1746,19 @@ static ssize_t disksize_store(struct device *dev, goto out_free_meta; } + if (!try_module_get(THIS_MODULE)) + goto out_free_zcomp; + zram->comp = comp; zram->disksize = disksize; + set_capacity_and_notify(zram->disk, zram->disksize >> SECTOR_SHIFT); up_write(&zram->init_lock); return len; +out_free_zcomp: + zcomp_destroy(comp); out_free_meta: zram_meta_free(zram, disksize); out_unlock: