Received: by 2002:a05:7412:b10a:b0:f3:1519:9f41 with SMTP id az10csp1066842rdb; Fri, 1 Dec 2023 06:19:32 -0800 (PST) X-Google-Smtp-Source: AGHT+IEytnZFEwmhpufkEsVylfqEGaXiyBBxyg4pJ0f444gNokdoCAZOLggKR1ov6HnzWrVXLgdt X-Received: by 2002:a17:903:428a:b0:1d0:5531:ef8 with SMTP id ju10-20020a170903428a00b001d055310ef8mr1778876plb.22.1701440372518; Fri, 01 Dec 2023 06:19:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701440372; cv=none; d=google.com; s=arc-20160816; b=UQyJ4r+OsbWku7l/f0WJLq9xoF7/zSonklvY6+Gs29cee6QmfQ2brU7+LyTkSTofGG jKo5xU/8VtHq5f/QMVN/cYH81YOlOlhBan/sOwwc0Qf5Nkyy8ocdksZ4IkmY/k5P9cL8 dwNftNUk6MxBN1EUGTc3zBprdTU73KleiadEgbOscj/CbLWu0vKi250b3/rmPxhT6j1J p/oN/kINnkUz4ZHreqoFRgIzzolBejz7tz8Jknky/h+QlYfseMeioae58aXcyXjqgP13 t4oyxz5j1z3aEJLftgFJ8ycnMjwUH1Jz+kx89UZ/GCLCKsX6HKMEA+PzUV9JJp1tEDT1 gUrg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=wEpn1rN0H9J4J1lp44h9DQD1Iq6/aR8RtLbVaUkH44I=; fh=xtlSLC6pLGO25+mqOTDUZijSVk9BLWPhz+/mMDxN8DM=; b=pHyHWhHIrRGl1BMoILqe6LSJblcIv22XM/9SYZ0JEdU5KW86Eud1SPynT1ZOXM8D1v eRG7tDAnlN92LsnlXozSBTLXy15gIzMmKr5oszLkgTcdT8R2brHeYDgsb9clpE/0OeT4 1UWdbqS9wNoCMYe6B3gbe9owKjVcEX6gc2Wwq7YYzy0yiMb7peS9vxVgm/y+Xwkd3uBJ exW8r5hI4fM/e5VMyBANIya9uhWjdINzk/P9AizdwASq3L6BT3gGReMVx4BlgClymyC2 D2PrVlMxfNLkQ4Wh28sQkIeHAOMPem6SG+pfDzgKkSZYyKaRce96bythryGZBdndupYB OyDQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel-dk.20230601.gappssmtp.com header.s=20230601 header.b=VOJIvOVe; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id cp12-20020a170902e78c00b001cff62f4c75si3285636plb.53.2023.12.01.06.19.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Dec 2023 06:19:32 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel-dk.20230601.gappssmtp.com header.s=20230601 header.b=VOJIvOVe; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id D143181C3D6E; Fri, 1 Dec 2023 06:19:16 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1379124AbjLAOTB (ORCPT + 99 others); Fri, 1 Dec 2023 09:19:01 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39276 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1379137AbjLAOTA (ORCPT ); Fri, 1 Dec 2023 09:19:00 -0500 Received: from mail-pl1-x62b.google.com (mail-pl1-x62b.google.com [IPv6:2607:f8b0:4864:20::62b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C2CF310DB for ; Fri, 1 Dec 2023 06:19:05 -0800 (PST) Received: by mail-pl1-x62b.google.com with SMTP id d9443c01a7336-1d03f90b0cbso2869705ad.1 for ; Fri, 01 Dec 2023 06:19:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20230601.gappssmtp.com; s=20230601; t=1701440345; x=1702045145; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=wEpn1rN0H9J4J1lp44h9DQD1Iq6/aR8RtLbVaUkH44I=; b=VOJIvOVeW57Y/YzXd2zMRTpU8jkRLXWB289x2SwezAkb0SFJMPZvSOKaZhgz0sh/Jq IQKeeR7V+mwxhq5kP+ZXZzISZbAbRCSFRMQlIXdD0CXTDG17c/Lwxv+y1qbj2Bfk8HRi HycRzBUJRnUGEHrsBSAEi9RIrg8tXDiNOD0qU1Yv8zpIGln50Njp8i+1e4G5FVa66lJh FZluKVqx+Z42g1dqzivsMvYT+2UW/+//uj0ICYR3nrIATqY+I34c6kLAJRjnaRpyavOf yMilEwxodwCE95j3ysf7H2EFl+a1GjSUjr2K1scanBdd0dKQCrxRYmXUoFtobqGoD5x8 SmPw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701440345; x=1702045145; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=wEpn1rN0H9J4J1lp44h9DQD1Iq6/aR8RtLbVaUkH44I=; b=KNHfh2XHnXkoXw4tjj4pfB5yS2DRkB253CnOFADA6Kn3YASbuM/sSqHmO+eajDM0bG Itlm+7lcKbyMHXJ0v5OG02nww2MA3hfOD1i3Wq+q/egdK8Bb24YdaWdX0sPe7kxUdoDB ZHk8zpoK273TOAWhr6lo96tmBW4yEvAHriYgOqlWESSTXxAsJ8FC8ozoKL4AT/Y6oIuo dz7PmSXx1GZ14m2cKmujMZAxA1+/fpV2CGv9cBSfFy9dvKjmaB8obafjM+bGMZ1dcCDB nY8wsiFftv0pVGjiKXPF4mw3umrrIZMExKytFrc4JceUhX/oKV5w8Nc3O/qoZauU/agX hvYQ== X-Gm-Message-State: AOJu0Yx6Sk56yaJoPEO0VzTfeHQ1PgaD60lEq2ZGhuph48rDTvmEZRnK wSEBrLYBphO+OLPYpbMo4+kGn5VNOaw3y0XbLNryaQ== X-Received: by 2002:a17:902:d501:b0:1cf:7962:656d with SMTP id b1-20020a170902d50100b001cf7962656dmr5467856plg.3.1701440345138; Fri, 01 Dec 2023 06:19:05 -0800 (PST) Received: from [192.168.1.150] ([198.8.77.194]) by smtp.gmail.com with ESMTPSA id u23-20020a170902a61700b001cf6d5a034dsm3370360plq.209.2023.12.01.06.19.03 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 01 Dec 2023 06:19:04 -0800 (PST) Message-ID: Date: Fri, 1 Dec 2023 07:19:03 -0700 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] zram: Using GFP_ATOMIC instead of GFP_KERNEL to allocate bitmap memory in backing_dev_store Content-Language: en-US To: Dongyun Liu , minchan@kernel.org, senozhatsky@chromium.org Cc: linux-kernel@vger.kernel.org, linux-block@vger.kernel.org, lincheng.yang@transsion.com, jiajun.ling@transsion.com, ldys2014@foxmail.com, Dongyun Liu References: <20231130152047.200169-1-dongyun.liu@transsion.com> <3af0752f-0534-43c4-913f-4d4df8c8501b@gmail.com> From: Jens Axboe In-Reply-To: <3af0752f-0534-43c4-913f-4d4df8c8501b@gmail.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (fry.vger.email [0.0.0.0]); Fri, 01 Dec 2023 06:19:17 -0800 (PST) On 11/30/23 11:51 PM, Dongyun Liu wrote: > > > On 2023/11/30 23:37, Jens Axboe wrote: >> On 11/30/23 8:20 AM, Dongyun Liu wrote: >>> diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c >>> index d77d3664ca08..ee6c22c50e09 100644 >>> --- a/drivers/block/zram/zram_drv.c >>> +++ b/drivers/block/zram/zram_drv.c >>> @@ -514,7 +514,7 @@ static ssize_t backing_dev_store(struct device *dev, >>> nr_pages = i_size_read(inode) >> PAGE_SHIFT; >>> bitmap_sz = BITS_TO_LONGS(nr_pages) * sizeof(long); >>> - bitmap = kvzalloc(bitmap_sz, GFP_KERNEL); >>> + bitmap = kmalloc(bitmap_sz, GFP_ATOMIC); >>> if (!bitmap) { >>> err = -ENOMEM; >>> goto out; >> >> Outside of this moving from a zeroed alloc to one that does not, the >> change looks woefully incomplete. Why does this allocation need to be >> GFP_ATOMIC, and: > > By using GFP_ATOMIC, it indicates that the caller cannot reclaim or > sleep, although we can prevent the risk of deadlock when acquiring > the zram->lock again in zram_bvec_write. Yes, I am very much aware of how gfp allocation flags work and how why it's broken. It was a rhetorical question as to why you think you could get away with just fixing one of them. >> 1) file_name = kmalloc(PATH_MAX, GFP_KERNEL); does not > > There is no zram->init_lock held here, so there is no need to use > GFP_ATOMIC. True >> 2) filp_open() -> getname_kernel() -> __getname() does not >> 3) filp_open() -> getname_kernel() does not >> 4) bdev_open_by_dev() does not > > Missing the use of GFP_ATOMIC. Indeed! >> IOW, you have a slew of GFP_KERNEL allocations in there, and you >> probably just patched the largest one. But the core issue remains. >> >> The whole handling of backing_dev_store() looks pretty broken. >> > > Indeed, this patch only solves the biggest problem and does not > fundamentally solve it, because there are many processes for holding > zram->init_lock before allocation memory in backing_dev_store that > need to be fully modified, and I did not consider it thoroughly. > Obviously, a larger and better patch is needed to eliminate this risk, > but it is currently not necessary. You agree that it doesn't fix the issue, it just happens to fix the one that you hit. And then you jump to the conclusion that this is all that's needed to fix it. Ehm, confused? -- Jens Axboe