Received: by 2002:a05:6a10:9afc:0:0:0:0 with SMTP id t28csp3517227pxm; Mon, 28 Feb 2022 23:06:15 -0800 (PST) X-Google-Smtp-Source: ABdhPJxkz7p4DEmvbwbl9jNHGb0K6wT0lOP5VYLXvcDyzrN0w4XV1zrNjeDYKQRPUZEDv9kiQiVz X-Received: by 2002:a05:6402:2074:b0:410:81bf:ff3b with SMTP id bd20-20020a056402207400b0041081bfff3bmr23401072edb.326.1646118375435; Mon, 28 Feb 2022 23:06:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646118375; cv=none; d=google.com; s=arc-20160816; b=iLkLGpq9WB6Qh1QascotSefVNSdT9+5mOfV758D4r0mUqxsjGVI3Ymz3aWl44f96px ZgREWVnXO4pa9n5vCpXo8xvgTbG58ZRRpYpjVJTHwBnrbnllvGbN9yGAMoawl4KK0Ir5 +N2RHOTwUEXru2/QMleq/TiElxne9pJT7sbpPQ6n4xBIaLZk+IRIhs76TZPvELc/samz SCb2PIQ1forqOPUDhzZced2/11WE3xVQOjY6yhoYR9bBc1ZHslFJaY+FIhL1gVeDqAlB XuavwvZ75YWuTH7M3d0YB928N9xJBtpc9an0zolTcsaxNh8bqcyvz3up17fMcfiRFAxs SX+Q== 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=LwvwEzrp1xIn/jiiFpp6P3SyFgnwZ8pdXfzOU/9VimM=; b=S4HyL9Pmir4twu18SE+G0BFos8Z8VguM/z5pUcSbl7L6n9iWZfMAvuN7yW7eMQM3LZ e7uOU0mzX2vS+W+WB0FQ7dvDzDdtRfu1WPLHe5125kvpDq2QIe1X5K3dxoahTa6bdWbm iECKel8CoiCs7U8FEfwa4xCo6vW2cfcTIo1MsDiAYRooz71A+KsjlGM/dzU/MgGgCcW0 0HHkfeS1vaQaWKpekhaOHPJ577qAL+ZPx0KOd6bi2qBPKUndvxxq7dOenSFvPBwgFAAA +/3T1tVHajQeh4EKHZwoEHRsgTrFUBnWpwANPlkI/e/N9noR/Y8bsNlASH6tngLrVKwp /lVg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b="ET/mFAPh"; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w9-20020a056402070900b00410d469d75esi8566650edx.619.2022.02.28.23.05.52; Mon, 28 Feb 2022 23:06:15 -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=@gmail.com header.s=20210112 header.b="ET/mFAPh"; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230180AbiCAFol (ORCPT + 99 others); Tue, 1 Mar 2022 00:44:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53612 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229572AbiCAFoj (ORCPT ); Tue, 1 Mar 2022 00:44:39 -0500 Received: from mail-pf1-x42f.google.com (mail-pf1-x42f.google.com [IPv6:2607:f8b0:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C67FA3C726; Mon, 28 Feb 2022 21:43:59 -0800 (PST) Received: by mail-pf1-x42f.google.com with SMTP id y11so13207107pfa.6; Mon, 28 Feb 2022 21:43:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:date:mime-version:user-agent:subject:content-language:to :cc:references:from:in-reply-to:content-transfer-encoding; bh=LwvwEzrp1xIn/jiiFpp6P3SyFgnwZ8pdXfzOU/9VimM=; b=ET/mFAPhigISowfoXYA20OpHqk3b9a377bJHQAx/qiZNGD/rCjrHZIID+csiK8jxjw csAgrclrCMAp3lafFbwBkY1TMlrh2B335k7jWtctCtNZb3vne87S95RBhOSy1pDqnV/8 j8gfCKCjHHrSLNZi9QW045rbK1MOOUD1eGhAUKx9fZkqtiC7mCV1D0azocajXFOhLhqa Mh+yu10gYbKl0F60BnGwmMLZRKNIKwva12PFiREuNWNmfx1u/nAVoeAWGexFmoOzQYeM wFcyQ0rnCo+MXgzicTl97V7dqClDSjQaCG/nmNmXmu9IIDLbvCRIb6nKEp5m0RgjuQZH BKig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:cc:references:from:in-reply-to :content-transfer-encoding; bh=LwvwEzrp1xIn/jiiFpp6P3SyFgnwZ8pdXfzOU/9VimM=; b=fCIJsfRbR8iPqKM8dlUiXBm0PWm9fjRvVeG4sfIn1t/R9IGbkoELw+kH85VX3GuTYV LkjFVHeM0FlaCayoyeVJCjHSCHWPIEH1WJSAGlfSuao1kluuN8RKghXbFTWdE9V0hvAk vJMfNAFoxwaP/5BqCoDetqMM7p6alw8AxQgSym7MDYW0x5mEeA0lVOGKBkII5yn5trMK AC3qljaeovGiXZqWLXO65+WOjy2I92DOWfJ6dyJzrC9xKgi+BxwK+Z9DUH4/0tT7XloA fm/r3n0Q1BUnC0UzRO1Otj+m8IYL3r3DlXH8rPA3H6gKztL+FzJRKZQOkCiuOgFK410P FvnA== X-Gm-Message-State: AOAM532ZrVvhgvvKLRf9jf8xxvIm3PgAWX2P+4K5zrTe13EYeBjm2dyk /MRvNPextZA9KowlSVO+A4Y= X-Received: by 2002:a63:1350:0:b0:378:7fb4:63eb with SMTP id 16-20020a631350000000b003787fb463ebmr10043971pgt.457.1646113439190; Mon, 28 Feb 2022 21:43:59 -0800 (PST) Received: from [192.168.66.3] (p912131-ipoe.ipoe.ocn.ne.jp. [153.243.13.130]) by smtp.gmail.com with ESMTPSA id l13-20020a056a00140d00b004e13da93eaasm16233690pfu.62.2022.02.28.21.43.57 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 28 Feb 2022 21:43:58 -0800 (PST) Message-ID: Date: Tue, 1 Mar 2022 14:43:55 +0900 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux aarch64; rv:91.0) Gecko/20100101 Thunderbird/91.5.0 Subject: Re: [PATCH] virtio-blk: Assign discard_granularity Content-Language: en-US To: Stefan Hajnoczi Cc: linux-kernel@vger.kernel.org, linux-block@vger.kernel.org, virtualization@lists.linux-foundation.org, Jens Axboe , Paolo Bonzini , Christoph Hellwig References: <20220224093802.11348-1-akihiko.odaki@gmail.com> From: Akihiko Odaki In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,NICE_REPLY_A, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham 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 On 2022/02/28 19:51, Stefan Hajnoczi wrote: > On Thu, Feb 24, 2022 at 06:38:02PM +0900, Akihiko Odaki wrote: >> Virtual I/O Device (VIRTIO) Version 1.1 >> https://docs.oasis-open.org/virtio/virtio/v1.1/csprd01/virtio-v1.1-csprd01.html >>> discard_sector_alignment can be used by OS when splitting a request >>> based on alignment. >> >> According to Documentation/ABI/stable/sysfs-block, the corresponding >> field in the kernel is, confusingly, discard_granularity, not >> discard_alignment. > > Good catch, struct virtio_blk_config->discard_sector_alignment is Linux > q->limits.discard_granularity. > >> >> Signed-off-by: Akihiko Odaki >> --- >> drivers/block/virtio_blk.c | 4 +--- >> 1 file changed, 1 insertion(+), 3 deletions(-) >> >> diff --git a/drivers/block/virtio_blk.c b/drivers/block/virtio_blk.c >> index c443cd64fc9b..1fb3c89900e3 100644 >> --- a/drivers/block/virtio_blk.c >> +++ b/drivers/block/virtio_blk.c >> @@ -913,11 +913,9 @@ static int virtblk_probe(struct virtio_device *vdev) >> blk_queue_io_opt(q, blk_size * opt_io_size); >> >> if (virtio_has_feature(vdev, VIRTIO_BLK_F_DISCARD)) { >> - q->limits.discard_granularity = blk_size; >> - >> virtio_cread(vdev, struct virtio_blk_config, >> discard_sector_alignment, &v); >> - q->limits.discard_alignment = v ? v << SECTOR_SHIFT : 0; > > Should we use struct virtio_blk_config->topology.alignment_offset > ("offset of first aligned logical block" and used for Linux > blk_queue_alignment_offset()) for q->limits.discard_alignment? Maybe but I'm not sure. I had looked at the code of QEMU (commit 5c1ee569660d4a205dced9cb4d0306b907fb7599) but it apparently always sets 0 for virtio_blk_config->topology.alignment_offset. I don't have a hardware which requires discard_alignment either so I cannot test it. I'd like to leave this patch as is since I cannot deny the possibility that the host has a different alignment offset for discarding and other operations.