Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp3528063pxf; Mon, 15 Mar 2021 11:33:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxC9FmIYSFZ7iWlFIs84LqNN/7S37ScDBVyk3TvKX+l3CeC0UQ2zAcdxKk4CO2NJr89xEef X-Received: by 2002:aa7:c3c4:: with SMTP id l4mr30912700edr.335.1615833208845; Mon, 15 Mar 2021 11:33:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1615833208; cv=none; d=google.com; s=arc-20160816; b=uOhn4aNAXbAFfBfnl7thWwk+JkFh8f66tWi1UBFnu4DMY/J1rNRs6MQQ7rAYO2RzRq cT+yBGAwGjvOYkgOP2VZhzleRCIZXrPmpE/2ObXq9Qb5ivz4stRTlC0dybTES3Ks/J1E PHXdXsdlKSOI5J6evFR9U6oUKhVpplPm9XpEMIvOve6br+ECO5Tt02i4RfeFkF981P91 p1HqUKrClOWgHIYwF/26yYr8/5FDfNs4HiX4ORYIji1HiX7ZafMqbbGLelIt609XlUt3 c3lJhmaEbPmjyKo3HV1rMQiN8Sh+VHp6PdAie2+hIB4P/pAPFjUGakELnlIcdZ2enYz4 coSQ== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=VNQOjmKBZMlpbnoOcNUQvt8sVgIUZ1OyleqXFbIHnz8=; b=k6Gae7yCRNRl88pf6oe1pK1N4+LBxfgqxIKTp68cMbou32piROY3nViLsdL9zvIAB5 m3MEU9PhqLBowcFq4iqb2Cb4/nUJCx5aYXcqgAemhpL6tXsCgC951kIEbIo470J6Uc/Y 9d+P5dEBCz+cuauXDAt7pLwyvpD8sQzpcibc4eOGiLOwzPdsr5hDwYOQvESVkL3BT/u4 hr+We3xHA6DFMk0iahFh3pgPziLdhk2XlOYHeelJXvPW1kxyn/mleZw/dCalNV9kEhEA N9iVLNw6MCx+goU3e4JMkJVKUR1l/DHgMyjM/pv1nue6UIGF2oFG8rSHRSmr9AFlhBLw Tnqw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=ShRUOaaf; 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=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id mb15si12397494ejb.147.2021.03.15.11.33.06; Mon, 15 Mar 2021 11:33:28 -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=@linuxfoundation.org header.s=korg header.b=ShRUOaaf; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238337AbhCOOoj (ORCPT + 99 others); Mon, 15 Mar 2021 10:44:39 -0400 Received: from mail.kernel.org ([198.145.29.99]:50816 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233001AbhCOOD6 (ORCPT ); Mon, 15 Mar 2021 10:03:58 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 7A26364E83; Mon, 15 Mar 2021 14:03:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1615817037; bh=WwPBGAYBGzs6XzBbiI6mldC2Tgnb08UZi4a5Wx6imh0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ShRUOaaf2wdFZOjgrGJt8QisUa4V+0Aso6OIjElObKfS5SRu1fwpPVGQG+lB3vMus fkfvLtY+pv7bUr6smu/EkOAlQEmkKR4LQyQ/L4KUF8FOnP+rKpxYVnfbCw0NZprc6Y 5pF01Swpzk7Aq26jfwERTri9tN70RJXBJUYyeuYA= From: gregkh@linuxfoundation.org To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Minchan Kim , Amos Bianchi , Sergey Senozhatsky , John Dias , Andrew Morton , Linus Torvalds Subject: [PATCH 5.11 270/306] zram: fix broken page writeback Date: Mon, 15 Mar 2021 14:55:33 +0100 Message-Id: <20210315135516.787087270@linuxfoundation.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210315135507.611436477@linuxfoundation.org> References: <20210315135507.611436477@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Greg Kroah-Hartman From: Minchan Kim commit 2766f1821600cc7562bae2128ad0b163f744c5d9 upstream. commit 0d8359620d9b ("zram: support page writeback") introduced two problems. It overwrites writeback_store's return value as kstrtol's return value, which makes return value zero so user could see zero as return value of write syscall even though it wrote data successfully. It also breaks index value in the loop in that it doesn't increase the index any longer. It means it can write only first starting block index so user couldn't write all idle pages in the zram so lose memory saving chance. This patch fixes those issues. Link: https://lkml.kernel.org/r/20210312173949.2197662-2-minchan@kernel.org Fixes: 0d8359620d9b("zram: support page writeback") Signed-off-by: Minchan Kim Reported-by: Amos Bianchi Cc: Sergey Senozhatsky Cc: John Dias Cc: Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Greg Kroah-Hartman --- drivers/block/zram/zram_drv.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) --- a/drivers/block/zram/zram_drv.c +++ b/drivers/block/zram/zram_drv.c @@ -639,8 +639,8 @@ static ssize_t writeback_store(struct de if (strncmp(buf, PAGE_WB_SIG, sizeof(PAGE_WB_SIG) - 1)) return -EINVAL; - ret = kstrtol(buf + sizeof(PAGE_WB_SIG) - 1, 10, &index); - if (ret || index >= nr_pages) + if (kstrtol(buf + sizeof(PAGE_WB_SIG) - 1, 10, &index) || + index >= nr_pages) return -EINVAL; nr_pages = 1; @@ -664,7 +664,7 @@ static ssize_t writeback_store(struct de goto release_init_lock; } - while (nr_pages--) { + for (; nr_pages != 0; index++, nr_pages--) { struct bio_vec bvec; bvec.bv_page = page;