From patchwork Wed Dec 4 18:02:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kairui Song X-Patchwork-Id: 13894153 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 45891E7716D for ; Wed, 4 Dec 2024 18:02:42 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B5B3A6B0088; Wed, 4 Dec 2024 13:02:41 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id B0B026B0089; Wed, 4 Dec 2024 13:02:41 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 983836B008A; Wed, 4 Dec 2024 13:02:41 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 75FD06B0088 for ; Wed, 4 Dec 2024 13:02:41 -0500 (EST) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id EA522C1042 for ; Wed, 4 Dec 2024 18:02:40 +0000 (UTC) X-FDA: 82858046250.27.7119D68 Received: from mail-pf1-f176.google.com (mail-pf1-f176.google.com [209.85.210.176]) by imf26.hostedemail.com (Postfix) with ESMTP id C510D140020 for ; Wed, 4 Dec 2024 18:02:27 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=luj4egeU; spf=pass (imf26.hostedemail.com: domain of ryncsn@gmail.com designates 209.85.210.176 as permitted sender) smtp.mailfrom=ryncsn@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1733335345; a=rsa-sha256; cv=none; b=oMgsIV0pL+ExKnnQoxXCN38vbOmNxG7XggDL92JMvZnxigiK+vsmqWK53X77ycjgpi8g3f KUogthTEQNZ+fWPrjqsJpezzQ/F7aRYb+K7KrueW8dPE5DbyNgbgbCze0VV/7pL5FZs8+L kXVCkMVGDBshNmCxZOxYEJmueJELCu0= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=luj4egeU; spf=pass (imf26.hostedemail.com: domain of ryncsn@gmail.com designates 209.85.210.176 as permitted sender) smtp.mailfrom=ryncsn@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1733335345; h=from:from:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=bAlGt/tiVuSRFhJS9Rkw9mOuskNJthnKTcKF5ulNOvw=; b=EEpRT16BevAV+95EiHfMy0glI3ebtKIhhHfcHPpP5iZMl1pC4hxPe7GdPGi3dgALCnsO/H 8Q4Q6dM/tStA++l9tNmgPH72v/2GSE1DedIBTuMTzLKgKjjWbkWViregU/wHeV0M0cfybr XgpeBFyFa6ClVtV15Dr/3+3L2VnabcA= Received: by mail-pf1-f176.google.com with SMTP id d2e1a72fcca58-724d57a9f7cso78386b3a.3 for ; Wed, 04 Dec 2024 10:02:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1733335357; x=1733940157; darn=kvack.org; h=content-transfer-encoding:mime-version:reply-to:references :in-reply-to:message-id:date:subject:cc:to:from:from:to:cc:subject :date:message-id:reply-to; bh=bAlGt/tiVuSRFhJS9Rkw9mOuskNJthnKTcKF5ulNOvw=; b=luj4egeUjK8TIatlBK3SrmMV3Fslr5Dds6szqoBo5Nb9pN+uzUErycibMXWOf/fq1U YIgOGHnovieEZLhqMa9lO/1wv/kVy+Dj/XMCEK3aIQAkqHT6mirg6ORDn8+x/Ke3x3qz cAOv0he2Yflvw5+MVrfxe4XhrqDrsLKIOB+m6HSgYyk6vWNN90jvjG2SXrTlGXiCkRen HtDBROZ8+sI5XLpxP1GY+pcFY6YPEZuhFntzlxmy5AeODvbGay46M5Y/fpPfcu7GvgjG mjzvcnDD/OU25yCBVpZaDJOGckvuZIX+cHFLtQU+/WkzmjtVe57z0RLQCGfWZVO873Qm 0pbg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733335357; x=1733940157; h=content-transfer-encoding:mime-version:reply-to:references :in-reply-to:message-id:date:subject:cc:to:from:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=bAlGt/tiVuSRFhJS9Rkw9mOuskNJthnKTcKF5ulNOvw=; b=AbtxT3UvbFyXeqe80xH8xKw9wPzHoK2UmeRiqlWh6LMogAu2uErej5aYPjRt0yCzVm CA6qeF5KmCr1xB2TbwNSFHEaxdtn3+n9XprTm6q9fisuApePzwYBTBfcKyrYLOHv7IXW 71CvC7bnwAreKoVd/HbvJa+Oj3xgNvpP3AbwfzSka74vMkbYDn9qtCAH9VrFouUSaEeI DXkLUjq3mBw/YqipppTZ26FRIq0ZI218wCQljcLJFuSZsm+Y7b5EN3+DapvGLKepbnie veoe9foZanXV1nN5y0REOOGwB9oe8UZy19VoQBFRcBfhsN2psL/vMfWt6tJJ2VyApsCV PPgQ== X-Gm-Message-State: AOJu0YwQqylSTGWu1yeAu5VFU3r8jGzAchT0rDGQg5k+3SdTEBubjX2B 6oje54CZjAfuzkQkYpjVWl3EZeOJgiOuJzokCoByOjj9IOEquhvG/RQSeGYpVTU= X-Gm-Gg: ASbGncu6G6zHqrjffjHDfB0B30Y02MCuyf/cJY3j8Eym08VhZ1Klkj3IV42XpM7zpvK MYtztv30TlDxRY0g2iSFR8iGTlVEC3sKYJureJbTTkMOkFW8UMl4Fuc00aaEwwYl4i3F3+jg99m /z1KDIA0+qDcFB5bMqDMY54/h26Y0+l21ClgcnOVrBt5XHDbd0YLxNWDM3FvIZl48VGHq8aiMb6 JLE+WjLf/nWYLx8FwFKeDTy31FrleevSHxxA1n6CbwZykb7iM6sk4c+D+ZG/Fq0qF2pi/0= X-Google-Smtp-Source: AGHT+IHeql1iWXSfpkc9alhz3TOTPqPIWd0paC+yeqbkwcITYB2dvWkcwBYhP1UiZzR3SpjSJkLP+g== X-Received: by 2002:a05:6a00:3c8c:b0:71e:f4:dbc with SMTP id d2e1a72fcca58-7257fcced2cmr9725349b3a.25.1733335357173; Wed, 04 Dec 2024 10:02:37 -0800 (PST) Received: from KASONG-MC4.tencent.com ([101.32.222.185]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7258947b48fsm2064736b3a.47.2024.12.04.10.02.34 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Wed, 04 Dec 2024 10:02:36 -0800 (PST) From: Kairui Song To: linux-mm@kvack.org Cc: Minchan Kim , Sergey Senozhatsky , Andrew Morton , linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, Kairui Song , Desheng Wu , stable@vger.kernel.org Subject: [PATCH 2/2] zram: fix uninitialized ZRAM not releasing backing device Date: Thu, 5 Dec 2024 02:02:24 +0800 Message-ID: <20241204180224.31069-3-ryncsn@gmail.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241204180224.31069-1-ryncsn@gmail.com> References: <20241204180224.31069-1-ryncsn@gmail.com> Reply-To: Kairui Song MIME-Version: 1.0 X-Rspamd-Queue-Id: C510D140020 X-Stat-Signature: 8eiarhmfi1w9xzarb9fye9e4k1zmt85h X-Rspam-User: X-Rspamd-Server: rspam09 X-HE-Tag: 1733335347-18455 X-HE-Meta: U2FsdGVkX1+tX9IRPYgLc1yRmOTfv5J8Fd15AN5PV9yrJkTLRobXgCDyAzBZI8SfMSPZ5GzqHtkXEkJkym6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y23AvzwMJp5bVQF8lVGFEExGzyfa2rlY68crVXPeyDt/go97PPYU2eEfhupHl3zDQAVakYFJFbW4rSthN9pX3of+vRaR072qJkIDMzVZWOX5ozP3Xs4j9OnBSyi21/fgZyHNMCQ9QbGyjsrSnwC91zR8tOyTZJ/ytPR3GHjfQ615cesUJ1ZJ77UZhRexqs4rdOEjvOTP35qq7Ix+hgkB74J1KSBNq3Hmg9Yz0QTT83LVzu4m1WBCHfstrlMQpDr0patWMu9DC+/fogsNUeS/muwoHVxM2OyCl8mQp97u5Nw0AZ1MSXXAK2mYOpy33HSQJlrG5ldBrB8T55OaiWT0TX7Tsamdg5/i2M+yIDbb2A2d9mAH4ks4fcMLLHOrnBZ76sJTowVzvnLSqUfx+kUSlAmOi4SRyRR//JFoIqiLSO99rCl3GGbp9zXmNQ= X-Bogosity: Ham, tests=bogofilter, spamicity=0.006955, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: Kairui Song Setting backing device is done before ZRAM initialization. If we set the backing device, then remove the ZRAM module without initializing the device, the backing device reference will be leaked and the device will be hold forever. Fix this by always check and release the backing device when resetting or removing ZRAM. Fixes: 013bf95a83ec ("zram: add interface to specif backing device") Reported-by: Desheng Wu Signed-off-by: Kairui Song Cc: stable@vger.kernel.org --- drivers/block/zram/zram_drv.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c index dd48df5b97c8..dfe9a994e437 100644 --- a/drivers/block/zram/zram_drv.c +++ b/drivers/block/zram/zram_drv.c @@ -2335,6 +2335,9 @@ static void zram_reset_device(struct zram *zram) zram->limit_pages = 0; if (!init_done(zram)) { + /* Backing device could be set before ZRAM initialization. */ + reset_bdev(zram); + up_write(&zram->init_lock); return; }