Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp1028369pxb; Tue, 19 Oct 2021 18:57:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyLw3JgA7fwoNJ7c9qMaAohq6j7hq6BT7ie3Gvehg7q9Nbm+8/dKebKBc9naIXpFoO4s0Lc X-Received: by 2002:a63:8f4c:: with SMTP id r12mr30829546pgn.0.1634695068114; Tue, 19 Oct 2021 18:57:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634695068; cv=none; d=google.com; s=arc-20160816; b=QxIaNwlNs3m56jiGsEtdKGYHCupT1MmhD8X4AEdu23z4Hwr9iZaqmUPsg06jDWlxtX BxiQzLKICgB0+CC4mPODeWjghAiQYiZ/Q0LKfUgr/baK9eCjkxeRTX5A7zshqA1FnsJ5 ecWzDmMeJjPtGw/Pl6Nst/33iJvmTAf6ISJlKRNqf80BrOC3p8aFkmhJGHwdJ0SISAo9 f1D+56+3Rfi/U6cIqyAFi2iaT44Cnteu6OhF7D9D9s9mswOcpeodbtJOq6N0GURyjKNf PkXeub7pUnDs8cxAJrwryO7je6Ku0AaIPPYZlOoEYbmfTTb6CFKITXOONi4oS+YTGqS5 +99g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=F1oEtaJKDPh3Y7ob5t2269utmHBPdM5EX8o/2XMz544=; b=KkeqxaPQyKwIWU8VKJsMbFUd3Tts4MaHzEirN/b6ibvX1DYwGpWuFfAoiwV/vNCqAp 79MY6WvKhFJdI+uXYjhwdRWjQaj3J10eDrBS4ihBptPymjOQ3a6Xr2vPZWtf3cQWSPss +BGkoLUVaNp4gJpAz3ZcoUY1+u19EmtdpBLeZEJ2iH2N6frjUv3ymWbHdKJ0h5bahF9+ F73eaVwU1/jQRMIN4SB3obe1FMZDnTx8/LWP+F2OiQQBLjNEJy2hAr1O3MD/+dqaF1kC HSw4Dpuf/6UNtnHmu2L8yDzJ9yc+k/rBXY5D1PAqNGIOp6bLsulEUvS893v0VfQv8zhP 8Pmg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=XFngEllW; 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=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f6si1058040pln.47.2021.10.19.18.57.35; Tue, 19 Oct 2021 18:57:48 -0700 (PDT) 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=@redhat.com header.s=mimecast20190719 header.b=XFngEllW; 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=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229952AbhJTB6c (ORCPT + 99 others); Tue, 19 Oct 2021 21:58:32 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:39464 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229943AbhJTB6b (ORCPT ); Tue, 19 Oct 2021 21:58:31 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1634694977; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=F1oEtaJKDPh3Y7ob5t2269utmHBPdM5EX8o/2XMz544=; b=XFngEllWU5Mp45iMYmm8r0UO6iGT+GlY499obFvX+sRKdsb3XeDTOXb94qdKdZBQb8zyGV aVXfTGQV/YmssQuWRUGdr4tFHhqBTcqsC7svFZK0Buao44SzQr1Hec7DgluYgT2DvAQ+zB +/ej6oWC8oMpZSrprog20YAGKMckt4I= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-232-owE6K1epNZKoiNujNgVuhQ-1; Tue, 19 Oct 2021 21:56:14 -0400 X-MC-Unique: owE6K1epNZKoiNujNgVuhQ-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 427EA362F8; Wed, 20 Oct 2021 01:56:13 +0000 (UTC) Received: from localhost (ovpn-8-20.pek2.redhat.com [10.72.8.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id A578A60657; Wed, 20 Oct 2021 01:56:04 +0000 (UTC) From: Ming Lei To: Jens Axboe Cc: linux-block@vger.kernel.org, Luis Chamberlain , Minchan Kim , Greg Kroah-Hartman , linux-kernel@vger.kernel.org, Ming Lei Subject: [PATCH V2 1/4] zram: fix race between zram_reset_device() and disksize_store() Date: Wed, 20 Oct 2021 09:55:45 +0800 Message-Id: <20211020015548.2374568-2-ming.lei@redhat.com> In-Reply-To: <20211020015548.2374568-1-ming.lei@redhat.com> References: <20211020015548.2374568-1-ming.lei@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When the ->init_lock is released in zram_reset_device(), disksize_store() can come in and try to allocate meta, but zram_reset_device() is freeing free meta, so cause races. Link: https://lore.kernel.org/linux-block/20210927163805.808907-1-mcgrof@kernel.org/T/#mc617f865a3fa2778e40f317ddf48f6447c20c073 Reported-by: Luis Chamberlain Signed-off-by: Ming Lei --- drivers/block/zram/zram_drv.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c index a68297fb51a2..25d781dc5fef 100644 --- a/drivers/block/zram/zram_drv.c +++ b/drivers/block/zram/zram_drv.c @@ -1704,12 +1704,13 @@ static void zram_reset_device(struct zram *zram) set_capacity_and_notify(zram->disk, 0); part_stat_set_all(zram->disk->part0, 0); - up_write(&zram->init_lock); /* I/O operation under all of CPU are done so let's free */ zram_meta_free(zram, disksize); memset(&zram->stats, 0, sizeof(zram->stats)); zcomp_destroy(comp); reset_bdev(zram); + + up_write(&zram->init_lock); } static ssize_t disksize_store(struct device *dev, -- 2.31.1