Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp1370306pxj; Fri, 18 Jun 2021 05:51:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz9YTgJclaZMdCOkwh09oUebydPjmwbFYpDMcIsavoWRB6JDfJKkuk0oKhHP5bNTbNIoYgw X-Received: by 2002:a17:906:3485:: with SMTP id g5mr10853490ejb.174.1624020692479; Fri, 18 Jun 2021 05:51:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624020692; cv=none; d=google.com; s=arc-20160816; b=DBbRzSyvVP9UjT6kO2AwdvSQfrcSt4YY/vjTBvYT09UxSyZ1zOveZ1FNPAGlTcWsp2 UkM0fh3cFBVh/+KVGVtcTKXfAU04h2IH0SsA8q1NKTptJttP3gnlGumvAa5ZooWTVd0k XN3SIzTyqcHNPkDk9DPYvfypPNbndjKpsyvPvKfrLbX5O8/Bsxsi+HLbGhGIW52bBUmA hDDGWXG/67dsX2PCaCbGzQny5JuhorPlJ6tdMOXbFeqQJpiEb5n6jE9IJdm7oy3kHTur wGF+tcT7AFqshzOwwUnHF1rotIqXnKZC8l8g4kNtP/GxkkKHSATrZ06LZmEnXnQfs1+f WTZw== 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 :message-id:date:subject:cc:to:dkim-signature:from; bh=fNVRnRf8542INKe/gU6+30e9FBmzmdw4HOsCG1SESDg=; b=sV1245lYfvDUOyvGc6QuZy8ES1Q6Hsf1KFJiSbJkNO1QKASx5i+PcNPRzLixSCAC5m 9E44Lu57g5egVRpPIeCdwhPuSmNEI5vB64tgo/AsCJoT/F++PAV2tvRSrSy31i+TfE0w a/PvIJA96bD/AvTVsU0r4DGEBTgedJwH7lOGg8vRwYBdYmlKasfzQeVqEkoQ3ABLqVoO Hct0Z1JsGmoJgp96KctI45uuNF+W7/6/WbAj0iDGfZTZ5wCwRvP53V9T7mGj0vN1C7t5 5lSefQoP5lbQ+ZtgLPY8kU3lSak4RqXodkQpi2Pg35XV6KZyh0I9QGowbwjyeez5/I6V Cczw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@klausen.dk header.s=dkim header.b=PylWqcdW; 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=REJECT sp=REJECT dis=NONE) header.from=klausen.dk Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id yh1si2587405ejb.508.2021.06.18.05.51.08; Fri, 18 Jun 2021 05:51:32 -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=@klausen.dk header.s=dkim header.b=PylWqcdW; 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=REJECT sp=REJECT dis=NONE) header.from=klausen.dk Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233921AbhFRLyf (ORCPT + 99 others); Fri, 18 Jun 2021 07:54:35 -0400 Received: from mail.klausen.dk ([157.90.24.29]:44588 "EHLO mail.klausen.dk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234342AbhFRLye (ORCPT ); Fri, 18 Jun 2021 07:54:34 -0400 From: Kristian Klausen DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=klausen.dk; s=dkim; t=1624017142; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=fNVRnRf8542INKe/gU6+30e9FBmzmdw4HOsCG1SESDg=; b=PylWqcdWYA5ulggA5WAFN4wVUb53dyb2SbV3C39KTPdkmlbic6heUukQs9O0fr/FqSJsBx SBoOBTrTcq1w1rUnUx9d75/rh8sRMLqLMLqzM/Uwd6L013Zs0QB39ECNGT6sdVarMuCFj/ EmaVwN2RufE2h+rDHJi8GF/Iuab2knk= To: linux-block@vger.kernel.org Cc: Kristian Klausen , stable@vger.kernel.org, Jens Axboe , Martijn Coenen , linux-kernel@vger.kernel.org (open list) Subject: [PATCH v2] loop: Fix missing discard support when using LOOP_CONFIGURE Date: Fri, 18 Jun 2021 13:51:57 +0200 Message-Id: <20210618115157.31452-1-kristian@klausen.dk> X-Mailer: git-send-email 2.32.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Without calling loop_config_discard() the discard flag and parameters aren't set/updated for the loop device and worst-case they could indicate discard support when it isn't the case (ex: if the LOOP_SET_STATUS ioctl was used with a different file prior to LOOP_CONFIGURE). Cc: # 5.8.x- Fixes: 3448914e8cc5 ("loop: Add LOOP_CONFIGURE ioctl") Signed-off-by: Kristian Klausen --- v1 of the patch was tested like so (without the patch): losetup 2.37<= uses LOOP_CONFIGURE instead of LOOP_SET_STATUS64[1] # fallocate -l100M disk.img # rmmod loop # losetup --version losetup from util-linux 2.36.2 # losetup --find --show disk.img /dev/loop0 # grep '' /sys/devices/virtual/block/loop0/queue/*discard* /sys/devices/virtual/block/loop0/queue/discard_granularity:4096 /sys/devices/virtual/block/loop0/queue/discard_max_bytes:4294966784 /sys/devices/virtual/block/loop0/queue/discard_max_hw_bytes:4294966784 /sys/devices/virtual/block/loop0/queue/discard_zeroes_data:0 /sys/devices/virtual/block/loop0/queue/max_discard_segments:1 # losetup -d /dev/loop0 # [update util-linux] # losetup --version losetup from util-linux 2.37 # rmmod loop # losetup --find --show disk.img /dev/loop0 # grep '' /sys/devices/virtual/block/loop0/queue/*discard* /sys/devices/virtual/block/loop0/queue/discard_granularity:0 /sys/devices/virtual/block/loop0/queue/discard_max_bytes:0 /sys/devices/virtual/block/loop0/queue/discard_max_hw_bytes:0 /sys/devices/virtual/block/loop0/queue/discard_zeroes_data:0 /sys/devices/virtual/block/loop0/queue/max_discard_segments:1 With the patch applied: # losetup --version losetup from util-linux 2.37 # rmmod loop # losetup --find --show disk.img /dev/loop0 # grep '' /sys/devices/virtual/block/loop0/queue/*discard* /sys/devices/virtual/block/loop0/queue/discard_granularity:4096 /sys/devices/virtual/block/loop0/queue/discard_max_bytes:4294966784 /sys/devices/virtual/block/loop0/queue/discard_max_hw_bytes:4294966784 /sys/devices/virtual/block/loop0/queue/discard_zeroes_data:0 /sys/devices/virtual/block/loop0/queue/max_discard_segments:1 [1] https://github.com/karelzak/util-linux/pull/1152 v2: Add commit message Move loop_config_discard() before loop_update_rotational() drivers/block/loop.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/block/loop.c b/drivers/block/loop.c index 76e12f3482a9..8271df125153 100644 --- a/drivers/block/loop.c +++ b/drivers/block/loop.c @@ -1154,6 +1154,7 @@ static int loop_configure(struct loop_device *lo, fmode_t mode, blk_queue_physical_block_size(lo->lo_queue, bsize); blk_queue_io_min(lo->lo_queue, bsize); + loop_config_discard(lo); loop_update_rotational(lo); loop_update_dio(lo); loop_sysfs_init(lo); base-commit: 70585216fe7730d9fb5453d3e2804e149d0fe201 -- 2.32.0