Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp1659061rwb; Thu, 8 Dec 2022 13:36:26 -0800 (PST) X-Google-Smtp-Source: AA0mqf4WXXZZJnxX/uFSkEsl1fY1r2zYJ9C+wvHUaGD2JMoqqwwxkJRpp8HpNJxxi53FSONkZpIO X-Received: by 2002:a17:906:f05:b0:7b2:c575:2ee8 with SMTP id z5-20020a1709060f0500b007b2c5752ee8mr64298756eji.136.1670535386377; Thu, 08 Dec 2022 13:36:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670535386; cv=none; d=google.com; s=arc-20160816; b=xNursdyktWLqNUXwRJH4/Ri+rChuLx2qC4lidJiLnSxkoVF+IzwTfzBY9a0tucfV38 wEFEe/1Suh69qgnVEhpnN9U3OfJ8w35DJMzQBDnwJFLNiUWo1rNgWHuULqPsTlMTcf1c utEEk3kEK/EX1G3scZx3R9rsiCuXH1ASb7T00Fb1RlSNVnm8WLwtePYucRInCVQcxGsK sJBLppQUXJsC4ayS/JqpIk2k8l8Ftmhthiebjik5GP5IHY6lha8X7B9bjcJbNikll02G nTlES8eQlIdIl0zI/DfxA0CWe77LvE2ENgnalZEzVqF92QFwWEnuZMbFCa1O7kUNtcf8 ZIpw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:mime-version:date :dkim-signature; bh=1/7SmmzO1fjUhk6gqNU1IGSXCaBrn6wr7PS0uHHL0Y4=; b=B98cdDUNNSe1XSyCREr7ryOYpmlioxShJW6uOCQg5UFK1wmhAFsAg11fDlbybYkXaa c2WbPsEh6MO+4d7WdrJp7BCYvVtmkFPxdqU85ZhmIJXkMQlbPEBBLSYv4OWAck+gI9rV LFmWsBEcekFZ61KQdODSCq3nk+HrQZgzl7X6np0/Q1a3pZLwHlZNzuwlQosSFlVNeOq6 F0d1x/GJaTMovFt19PZk/LjGZleTj+1pKaFUoi8drFf938dh4i6VxFEO7N7JKHNqZxfP UHVfBt2LvlRdypsU/tjFwbJTNaACDAZbPHzuTXGrhZkmU+kTkiaAHwuyCv2lNf4pHWp0 2lKw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=LqiYpvie; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id gs8-20020a1709072d0800b007ad4a555cb6si22021714ejc.878.2022.12.08.13.36.09; Thu, 08 Dec 2022 13:36:26 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=LqiYpvie; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229761AbiLHV3J (ORCPT + 73 others); Thu, 8 Dec 2022 16:29:09 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40662 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229809AbiLHV3H (ORCPT ); Thu, 8 Dec 2022 16:29:07 -0500 Received: from mail-yw1-x1149.google.com (mail-yw1-x1149.google.com [IPv6:2607:f8b0:4864:20::1149]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 40FF88426B for ; Thu, 8 Dec 2022 13:29:06 -0800 (PST) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-3fe3bedbb16so27814027b3.15 for ; Thu, 08 Dec 2022 13:29:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=1/7SmmzO1fjUhk6gqNU1IGSXCaBrn6wr7PS0uHHL0Y4=; b=LqiYpvieBDCbLQwkb+CSQO3e5kvlO9YkgEAx+uj4dvnOMSYSbFp+eB6H7weFJnTz89 8MDyvy5lu8E6NOlVICNsMMIWd2RXsQrhEHP/T+ym9fr0388elXolqAQVV5XMtGyPc7hB mh47hi5HEFtu4bMGkuw7sLC+CgMhhQDK3rFxEm+R8vsaFvB3a8j6j2zQv0P+wJGMQLDy 6qYqDgN4YpiZmvCgZNbe6NfpIeJGuTrFf6M+9a2bJ+nkDnbJl61wH4k79YmSG333Qxbj 9U7xGHcetB4fBU33IHmW5ZSKzsib8LREKjD5mpb4io1ayunr/o9VMJFRteWlgb2E3MvY WTSg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=1/7SmmzO1fjUhk6gqNU1IGSXCaBrn6wr7PS0uHHL0Y4=; b=ZJsi8B3DmdV+7c+76Oa5NGZ/x/UMGH++wfmlpgzMEZKUk4makQZhstEPZhBxrQX/S6 6eVZTkxE60Xgss7noz6e9AlLbIDSkUeU71UOx6PC65uQ5ZEYvqsIwroti8j8i7rTs0JD 21t78Shtx1UtUn532Q+WC/+3hJrDrvst5Oug73LQgcflrfEG39F/bq8nMPfgXHHB0Xz/ 0g8jwubP4JpeB1yFc5+FestbxTGPxh67M2zBuIRlYeaBmnTTmzyRfZZm6q6zRDAMdVMN 3DHR6pK3rPEZtHFwj45YUS0t+jSxHzfX9qlTVsu/QEwm/DRPx/zf2lePcu+8rBIHKF4q 6RHg== X-Gm-Message-State: ANoB5pkKYmU9SsWu5LhjU78lk/xjHDQt73UwDgmjuHmZX/npqiPB3cpE tvEHudsLipOWv8wnRdl3JY1VUlGrTgtbAi/p46RW8w== X-Received: from isaacmanjarres.irv.corp.google.com ([2620:15c:2d:3:c924:bf6:54d9:20e9]) (user=isaacmanjarres job=sendgmr) by 2002:a05:690c:902:b0:3f6:489a:a06f with SMTP id cb2-20020a05690c090200b003f6489aa06fmr10039866ywb.470.1670534945529; Thu, 08 Dec 2022 13:29:05 -0800 (PST) Date: Thu, 8 Dec 2022 13:29:01 -0800 Mime-Version: 1.0 X-Mailer: git-send-email 2.39.0.rc1.256.g54fd8350bd-goog Message-ID: <20221208212902.765781-1-isaacmanjarres@google.com> Subject: [PATCH RESEND v1] loop: Fix the max_loop commandline argument treatment when it is set to 0 From: "Isaac J. Manjarres" To: Jens Axboe , Andrew Morton , Ken Chen Cc: Saravana Kannan , "Isaac J. Manjarres" , stable@vger.kernel.org, kernel-team@android.com, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Currently, the max_loop commandline argument can be used to specify how many loop block devices are created at init time. If it is not specified on the commandline, CONFIG_BLK_DEV_LOOP_MIN_COUNT loop block devices will be created. The max_loop commandline argument can be used to override the value of CONFIG_BLK_DEV_LOOP_MIN_COUNT. However, when max_loop is set to 0 through the commandline, the current logic treats it as if it had not been set, and creates CONFIG_BLK_DEV_LOOP_MIN_COUNT devices anyway. Fix this by starting max_loop off as set to CONFIG_BLK_DEV_LOOP_MIN_COUNT. This preserves the intended behavior of creating CONFIG_BLK_DEV_LOOP_MIN_COUNT loop block devices if the max_loop commandline parameter is not specified, and allowing max_loop to be respected for all values, including 0. This allows environments that can create all of their required loop block devices on demand to not have to unnecessarily preallocate loop block devices. Fixes: 732850827450 ("remove artificial software max_loop limit") Cc: stable@vger.kernel.org Cc: Ken Chen Signed-off-by: Isaac J. Manjarres --- drivers/block/loop.c | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) This is a resend because I misspelled the address for stable@vger.kernel.org the first time. --Isaac diff --git a/drivers/block/loop.c b/drivers/block/loop.c index ad92192c7d61..d12d3d171ec4 100644 --- a/drivers/block/loop.c +++ b/drivers/block/loop.c @@ -1773,7 +1773,16 @@ static const struct block_device_operations lo_fops = { /* * And now the modules code and kernel interface. */ -static int max_loop; + +/* + * If max_loop is specified, create that many devices upfront. + * This also becomes a hard limit. If max_loop is not specified, + * create CONFIG_BLK_DEV_LOOP_MIN_COUNT loop devices at module + * init time. Loop devices can be requested on-demand with the + * /dev/loop-control interface, or be instantiated by accessing + * a 'dead' device node. + */ +static int max_loop = CONFIG_BLK_DEV_LOOP_MIN_COUNT; module_param(max_loop, int, 0444); MODULE_PARM_DESC(max_loop, "Maximum number of loop devices"); module_param(max_part, int, 0444); @@ -2181,7 +2190,7 @@ MODULE_ALIAS("devname:loop-control"); static int __init loop_init(void) { - int i, nr; + int i; int err; part_shift = 0; @@ -2209,19 +2218,6 @@ static int __init loop_init(void) goto err_out; } - /* - * If max_loop is specified, create that many devices upfront. - * This also becomes a hard limit. If max_loop is not specified, - * create CONFIG_BLK_DEV_LOOP_MIN_COUNT loop devices at module - * init time. Loop devices can be requested on-demand with the - * /dev/loop-control interface, or be instantiated by accessing - * a 'dead' device node. - */ - if (max_loop) - nr = max_loop; - else - nr = CONFIG_BLK_DEV_LOOP_MIN_COUNT; - err = misc_register(&loop_misc); if (err < 0) goto err_out; @@ -2233,7 +2229,7 @@ static int __init loop_init(void) } /* pre-create number of devices given by config or max_loop */ - for (i = 0; i < nr; i++) + for (i = 0; i < max_loop; i++) loop_add(i); printk(KERN_INFO "loop: module loaded\n"); -- 2.39.0.rc1.256.g54fd8350bd-goog