Received: by 2002:a05:7412:b10a:b0:f3:1519:9f41 with SMTP id az10csp1688713rdb; Sat, 2 Dec 2023 05:54:58 -0800 (PST) X-Google-Smtp-Source: AGHT+IGj3cY7sLu6MH3AyTogm0ar+dRGsQA9cLa+bql99bU64nLGUlxLijmQaWHck9cdNFzBd6tO X-Received: by 2002:a05:6a20:914e:b0:18b:9287:eab9 with SMTP id x14-20020a056a20914e00b0018b9287eab9mr573922pzc.52.1701525297864; Sat, 02 Dec 2023 05:54:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701525297; cv=none; d=google.com; s=arc-20160816; b=jMKoD4CgsQAjx+8Ku3qmFS0iEbbASWgMjR1GpPx38cHo4tK2p/H8JMMje4y1vUyZvB rv8QJdOuHkW4slyECs4/X0K3Qr6Eza+Yo/xjdizjgGY1CTRvJZzaInySNlCk/cZqgsrK njosFY95F3JeXiagAihV+UllijhjZd8Fnu9zmyLZx7C2uli/8+LPWBX2FY8h8SE9DlMd lSY9Bbkp5JVEom+ripuCAhohs2Q1EleSfBFeup0Sh8iz6dhLzyTwiWjXC4QIUcRZZYln nZRnMjTHlFvcsOvQlKapBIAfvrZhcf38HeU71bLYoI6RGYE27kWyilKK0+VCVm/iywNR /fKA== 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:subject:user-agent:mime-version:date:message-id :dkim-signature; bh=VQOH7+u4hLSIClzOMDwlaWGqqeGohEqTdqEdf5joqgg=; fh=4hK/Mrc3KTq95gC1u6IQkCF+lZR2X5onSRmIRajTIoc=; b=y1jRhp3tmLFA4Orx0D8pRZa4dPTyh6scOnfKQef8EmrHIZ6tWebvbU+UPxOUOvM7Og 6AwXLfry17mJMLL0Ycas+e5BJSZ7f7f4W7ma+10DyM0JQDfPQLAqZ93Y9Dm+QYuaTUZq On55NUETNUaKX7QGltMTeHRg670H72/93FETq4+DKbNEJZZRoBAOD5fKZGFJ9sYE2UF3 i2HPC6CF7gg/dtql4vmXzhc2bzTtVmrnkZKoEU5WiFpok/nP1pK1hWS+oEMfxG9VHhao UBgk30i9Bi5/d5CumIfftb2J78F6sM3DeiCVJxy0XzVoplMnLQiaWoAu6h7M+QCxnSjj kE3A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=bnX4pcZL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id g5-20020a63fa45000000b005adba954597si5085658pgk.504.2023.12.02.05.54.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 02 Dec 2023 05:54:57 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=bnX4pcZL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id B13108058B72; Sat, 2 Dec 2023 05:54:54 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230181AbjLBNyi (ORCPT + 99 others); Sat, 2 Dec 2023 08:54:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59362 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229451AbjLBNyh (ORCPT ); Sat, 2 Dec 2023 08:54:37 -0500 Received: from mail-pg1-x544.google.com (mail-pg1-x544.google.com [IPv6:2607:f8b0:4864:20::544]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E0FF7116; Sat, 2 Dec 2023 05:54:43 -0800 (PST) Received: by mail-pg1-x544.google.com with SMTP id 41be03b00d2f7-5c239897895so1003914a12.2; Sat, 02 Dec 2023 05:54:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1701525283; x=1702130083; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:from:references:cc:to:subject :user-agent:mime-version:date:message-id:from:to:cc:subject:date :message-id:reply-to; bh=VQOH7+u4hLSIClzOMDwlaWGqqeGohEqTdqEdf5joqgg=; b=bnX4pcZLjH0c/vRWKJau3lqSEGyCaig0Q3hfN3nagg/8kjjtVFm+RIN8uOmc7Y3efA WbUne0nGsYsiwB6an7sWaegHhLTPosGdihsdENYlU1UzFSWW7W8UCcciQx5KPWVKjYan U5VEeAPoFOICKvhjqbfnN1ywfsA1wbHODhnFTooYirsvZZ0MiveaAqtjkh3djzEYLFBe bs6Pcy1qTPhl7VcUrYK1ECwc12IdOmOb7sPOJKSEY1GOltvD5DVjmsc9QqBx3X2nTTUY 1axWxuFa581oImCEl49FSeSzKaYyH7jbnHIWVm0mxVMHXVL5Yvi7UDclxeUxqdTuY0MT MF4A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701525283; x=1702130083; h=content-transfer-encoding:in-reply-to:from:references:cc:to:subject :user-agent:mime-version:date:message-id:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=VQOH7+u4hLSIClzOMDwlaWGqqeGohEqTdqEdf5joqgg=; b=B0qlJbnkHNSbPhlJLx/0ojMNTdgVOCegcA16D8NEuuKliyNAI89UFclxfLTfws4+vA pHizNAXQYRZBYcpWJ++PL2lOS8armR5rmmKK5EBZUhYlZpgl6ARgT0dgdd9cv/r5ui0m /og+HXH7Sa1IghL6JlDlw6q/sX6eQETh7ySEhVYFg6/GoUhUZ6FIoyJwD6XG/ohZ1M5t XdeHTdZgIX/ZQCngiCcjikrVXNBFPplgbyf5bgzLYbHl5ICKXIabuFntzYR2O8qkqOjg iHEq1n/X9wX3cYkI3/yX9kTCmPhs2ivOTICXy+VnWxWH7LgmmoZieDEnDm8QXMy0fR9A 1K6g== X-Gm-Message-State: AOJu0YzRMnYAeh5TfeMBxrmJIGw24oCnqvHbI6AgNBF4T76LOjYkWnr4 N7YYaQyTCWiqelbIaHDFOWc= X-Received: by 2002:a17:90a:8a87:b0:285:b67b:f435 with SMTP id x7-20020a17090a8a8700b00285b67bf435mr349463pjn.41.1701525283332; Sat, 02 Dec 2023 05:54:43 -0800 (PST) Received: from [10.164.172.236] ([182.255.33.153]) by smtp.gmail.com with ESMTPSA id gd10-20020a17090b0fca00b0028066f3c373sm6628990pjb.17.2023.12.02.05.54.40 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 02 Dec 2023 05:54:43 -0800 (PST) Message-ID: <4b43d22d-f50c-4cb1-85a1-6eab468304f4@gmail.com> Date: Sat, 2 Dec 2023 21:54:38 +0800 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 To: Jens Axboe , 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: Dongyun Liu In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, 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 agentk.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 (agentk.vger.email [0.0.0.0]); Sat, 02 Dec 2023 05:54:55 -0800 (PST) On 2023/12/1 22:19, Jens Axboe wrote: > 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? > Hi, Jens, Maybe there's something wrong with my expression. You can think of it this way: I agree with you that it doesn't fix the issue.