Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp322633rwl; Wed, 29 Mar 2023 02:15:07 -0700 (PDT) X-Google-Smtp-Source: AKy350bbO+RX/MdaPKz4+79iuaXD9PN6LII2ZV4rqhEZqt+Vp+JCCAONZHH2HHGWh5Qf60mRBDRK X-Received: by 2002:a17:903:11d2:b0:1a1:bff4:4a06 with SMTP id q18-20020a17090311d200b001a1bff44a06mr23944507plh.24.1680081307660; Wed, 29 Mar 2023 02:15:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680081307; cv=none; d=google.com; s=arc-20160816; b=mM7NzGsyHQvzXL4u2GVopSJg5GqgBLWLB3vTWAVPxR25lN485t8QmaUbs6hNc01UR5 mNJ2DZb/EaXl8ZikxYQdOZMevIgTt17Xf/zNkyjzq3ocaLA+qU0/A0VWq6KBzGAPZ61s I9Boj40RVzSUIXpQ0YxlFTgESbJNMhVWIX/jMvKkyXb8zd6CXNHOJkV7iCV+XSUjN3Yc w0greYWHanDCK43ywiORrSNHgFTg4pBjkSlzj2SSU/FaNgOTUZDIIvRnW9kC2Eem13xj lmA+y4XgvacoAZjSfeiI86dogiVLDv/CljV3vSIXrCU72OaAseuWsv7BQ7VNLTVlFHpQ aSOA== 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 :organization:from:references:cc:to:content-language:subject :user-agent:mime-version:date:message-id:dkim-signature :wdcironportexception:ironport-sdr:ironport-sdr:dkim-signature; bh=+Kc+tjwYL39inuARMrwWencAkuigRPgOtOeBMjKidPQ=; b=xrXk+x/1Wx+v26d+34p/m/gno5JYzw3qi/hMIFa5oZwVeoKhTPFxR/ttcQYMD+mKSg C6gG2s7OevsfPZkDL2Ei2W3me4WC7OgvXwZLhC94llJZrNeXauSF/7TgXI8BbE1Kmr87 FMLuHD09BA2i4DSE8+JkT2rJXXztX/VvTCyogQCUZbVKSPbeAvjbCawgepgMQIOe2LBN UMAjMFPJ9XAuymz0PGAxzfdVv3BSORlc2zV2IhhhEG6rFijXk/6YeQndqSFU4yIzFLIB U2ILAiUiDTjbUNpCAkyytOSxrjxNSKJOxP1/JzAr45jV2NZ8c+eU70iKqsA+5LIzJjUx xmMw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@wdc.com header.s=dkim.wdc.com header.b=WASFDijd; dkim=pass header.i=@opensource.wdc.com header.s=dkim header.b=ek9+FWZI; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=opensource.wdc.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 37-20020a631665000000b0050239e95d34si30263998pgw.260.2023.03.29.02.14.53; Wed, 29 Mar 2023 02:15:07 -0700 (PDT) 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=fail header.i=@wdc.com header.s=dkim.wdc.com header.b=WASFDijd; dkim=pass header.i=@opensource.wdc.com header.s=dkim header.b=ek9+FWZI; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=opensource.wdc.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231479AbjC2JFo (ORCPT + 99 others); Wed, 29 Mar 2023 05:05:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40270 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231452AbjC2JFV (ORCPT ); Wed, 29 Mar 2023 05:05:21 -0400 Received: from esa3.hgst.iphmx.com (esa3.hgst.iphmx.com [216.71.153.141]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 063933AA6 for ; Wed, 29 Mar 2023 02:05:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1680080706; x=1711616706; h=message-id:date:mime-version:subject:to:cc:references: from:in-reply-to:content-transfer-encoding; bh=ODmg3rPRGn4RIKplIt/ZC9RkflToL9LBuluXecNb92w=; b=WASFDijdsO2B4Ra+aEjGEZSEsKqVRH/eJ44iZ8vPtVkolQHNnSaFbsTf M7XD0eEcuPCYBYSnYj+nxO8KGTnVDj7iwBW8HP/qCGeaZkFu0bp6vLV/2 DcQr3KdZls4/jDkDnGZDl4lqGVsJfIuoZKPI6MNq5+R2qB8Ua8UweUSIz BJRmznuHW4uKXQ6yfrBlfetEdp/bHMAESpC5Z2adesOrfWX1+yldEle0B h253ipSq/28vcKA2aI53/iWSaewFTQ4Ae+ROH0BtEsK4cMfxfgrM+8WOx hmqOlRBsUeQjFfr9qdw+6IMhEdHOwhKGOiXfiNAfe5NRIsgIX7AAjbpWn g==; X-IronPort-AV: E=Sophos;i="5.98,300,1673884800"; d="scan'208";a="231751503" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 29 Mar 2023 17:04:57 +0800 IronPort-SDR: kRdghMhalo4igv6iIvluGTRz7DxutRf9KbelOo+r1j1KC3fhGTnZJiqn/aucJ2La45SQwk3O19 2hwzREUirih6ogblCLxapCY9CNoAZcrd3q82kQuA21M4/bcjNS/WLVzbKjRIGiXTWJgmXQvz+a TIbSTGkJbu/67WirJcEVmt9lLr6MMe6Y9TPaIFotehzDY6siiiiR/p3Vv6wcxcHseKTXsJHfcT 1HBJNolvFsE+EbX+YbM00gxbPXJJ6G0gvSFcfXxP7wk02ytfqIwVf6F3FD4z6mzKvcW2i8IfEV EgU= Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 29 Mar 2023 01:21:07 -0700 IronPort-SDR: lMg56X5sSTNZ7Am4gEAuUW1Zienv/oWgcopUek08ttYG8JrIFe1aMVesHnLHlyRyE3YgnpU7VL GJQSyfQ8X7pHLq2iIOclk/c+5oehvWhDJxmM8hAYkKI4pl4juk8xohGiXB1FncsFF6cDYwAZks 4w+/q3S+XtIO8onDw7awHVkE5h4af/PjLA/uKLyiYMMN59Mjx6y+Qw7GneKrhPPIykuZqyvqFR MzKb9KCQDOc2EM1Fgv8G9ynsLhD+/mDJvwkfve/U270vdyeZ61HBG2dOYbP3Q2YkO1jV2a1gU+ DKI= WDCIronportException: Internal Received: from usg-ed-osssrv.wdc.com ([10.3.10.180]) by uls-op-cesaip01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 29 Mar 2023 02:04:58 -0700 Received: from usg-ed-osssrv.wdc.com (usg-ed-osssrv.wdc.com [127.0.0.1]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTP id 4Pmgc91756z1RtVp for ; Wed, 29 Mar 2023 02:04:56 -0700 (PDT) Authentication-Results: usg-ed-osssrv.wdc.com (amavisd-new); dkim=pass reason="pass (just generated, assumed good)" header.d=opensource.wdc.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d= opensource.wdc.com; h=content-transfer-encoding:content-type :in-reply-to:organization:from:references:to:content-language :subject:user-agent:mime-version:date:message-id; s=dkim; t= 1680080695; x=1682672696; bh=ODmg3rPRGn4RIKplIt/ZC9RkflToL9LBulu XecNb92w=; b=ek9+FWZIOUM0j8FYjqIFGu2FNvtxkIuaUDpxJppjKHuxRxiECWQ XX8+9cY4NJDFc1sTz0Kj8xdgnMbR7ze3HQOPBl8wCwLvm7ooyBQdPxzew5n74aAR jLo/gnamAnUNSM3d1agXwx7i5C6tGt/n1KgIdKm37YAYwrZ6tArpEUHgUo0zSrSm i80nEBbcwNLLSaofPCXt52XW3Y9ZN7jlqRvwG3WXHVUDEmT8mKjWJe8pO5rhaUlc EAsZ97xPJtwtkxCBZnIhNor8FWG8jPPbw1Q0EiMXboC6By/Pf5pF8D7UySUycXFP R6qGXT6WTVd5lBncEbrqSHvqIooKkMzF7bw== X-Virus-Scanned: amavisd-new at usg-ed-osssrv.wdc.com Received: from usg-ed-osssrv.wdc.com ([127.0.0.1]) by usg-ed-osssrv.wdc.com (usg-ed-osssrv.wdc.com [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id BNqzyJhdMPjl for ; Wed, 29 Mar 2023 02:04:55 -0700 (PDT) Received: from [10.225.163.116] (unknown [10.225.163.116]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTPSA id 4Pmgc24vbRz1RtVm; Wed, 29 Mar 2023 02:04:50 -0700 (PDT) Message-ID: <71d9f461-a708-341f-d012-d142086c026e@opensource.wdc.com> Date: Wed, 29 Mar 2023 18:04:49 +0900 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.9.0 Subject: Re: [PATCH v8 9/9] null_blk: add support for copy offload Content-Language: en-US To: Anuj Gupta , Jens Axboe , Alasdair Kergon , Mike Snitzer , dm-devel@redhat.com, Keith Busch , Christoph Hellwig , Sagi Grimberg , James Smart , Chaitanya Kulkarni , Alexander Viro , Christian Brauner Cc: bvanassche@acm.org, hare@suse.de, ming.lei@redhat.com, joshi.k@samsung.com, nitheshshetty@gmail.com, gost.dev@samsung.com, Nitesh Shetty , Vincent Fu , linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-nvme@lists.infradead.org, linux-fsdevel@vger.kernel.org References: <20230327084103.21601-1-anuj20.g@samsung.com> <20230327084103.21601-10-anuj20.g@samsung.com> From: Damien Le Moal Organization: Western Digital Research In-Reply-To: <20230327084103.21601-10-anuj20.g@samsung.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-2.5 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,RCVD_IN_DNSWL_MED, SPF_HELO_PASS,SPF_PASS 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 On 3/27/23 17:40, Anuj Gupta wrote: > From: Nitesh Shetty > > Implementaion is based on existing read and write infrastructure. > > Suggested-by: Damien Le Moal > Signed-off-by: Anuj Gupta > Signed-off-by: Nitesh Shetty > Signed-off-by: Vincent Fu > --- > drivers/block/null_blk/main.c | 94 +++++++++++++++++++++++++++++++ > drivers/block/null_blk/null_blk.h | 7 +++ > 2 files changed, 101 insertions(+) > > diff --git a/drivers/block/null_blk/main.c b/drivers/block/null_blk/main.c > index 9e6b032c8ecc..84c5fbcd67a5 100644 > --- a/drivers/block/null_blk/main.c > +++ b/drivers/block/null_blk/main.c > @@ -1257,6 +1257,81 @@ static int null_transfer(struct nullb *nullb, struct page *page, > return err; > } > > +static inline int nullb_setup_copy_read(struct nullb *nullb, > + struct bio *bio) > +{ > + struct nullb_copy_token *token = bvec_kmap_local(&bio->bi_io_vec[0]); > + > + memcpy(token->subsys, "nullb", 5); > + token->sector_in = bio->bi_iter.bi_sector; > + token->nullb = nullb; > + token->sectors = bio->bi_iter.bi_size >> SECTOR_SHIFT; > + > + return 0; > +} > + > +static inline int nullb_setup_copy_write(struct nullb *nullb, > + struct bio *bio, bool is_fua) > +{ > + struct nullb_copy_token *token = bvec_kmap_local(&bio->bi_io_vec[0]); > + sector_t sector_in, sector_out; > + void *in, *out; > + size_t rem, temp; > + unsigned long offset_in, offset_out; > + struct nullb_page *t_page_in, *t_page_out; > + int ret = -EIO; > + > + if (unlikely(memcmp(token->subsys, "nullb", 5))) > + return -EOPNOTSUPP; > + if (unlikely(token->nullb != nullb)) > + return -EOPNOTSUPP; > + if (WARN_ON(token->sectors != bio->bi_iter.bi_size >> SECTOR_SHIFT)) > + return -EOPNOTSUPP; EOPNOTSUPP is strange. These are EINVAL, no ?. > + > + sector_in = token->sector_in; > + sector_out = bio->bi_iter.bi_sector; > + rem = token->sectors << SECTOR_SHIFT; > + > + spin_lock_irq(&nullb->lock); > + while (rem > 0) { > + temp = min_t(size_t, nullb->dev->blocksize, rem); > + offset_in = (sector_in & SECTOR_MASK) << SECTOR_SHIFT; > + offset_out = (sector_out & SECTOR_MASK) << SECTOR_SHIFT; > + > + if (null_cache_active(nullb) && !is_fua) > + null_make_cache_space(nullb, PAGE_SIZE); > + > + t_page_in = null_lookup_page(nullb, sector_in, false, > + !null_cache_active(nullb)); > + if (!t_page_in) > + goto err; > + t_page_out = null_insert_page(nullb, sector_out, > + !null_cache_active(nullb) || is_fua); > + if (!t_page_out) > + goto err; > + > + in = kmap_local_page(t_page_in->page); > + out = kmap_local_page(t_page_out->page); > + > + memcpy(out + offset_out, in + offset_in, temp); > + kunmap_local(out); > + kunmap_local(in); > + __set_bit(sector_out & SECTOR_MASK, t_page_out->bitmap); > + > + if (is_fua) > + null_free_sector(nullb, sector_out, true); > + > + rem -= temp; > + sector_in += temp >> SECTOR_SHIFT; > + sector_out += temp >> SECTOR_SHIFT; > + } > + > + ret = 0; > +err: > + spin_unlock_irq(&nullb->lock); > + return ret; > +} > + > static int null_handle_rq(struct nullb_cmd *cmd) > { > struct request *rq = cmd->rq; > @@ -1267,6 +1342,14 @@ static int null_handle_rq(struct nullb_cmd *cmd) > struct req_iterator iter; > struct bio_vec bvec; > > + if (rq->cmd_flags & REQ_COPY) { > + if (op_is_write(req_op(rq))) > + return nullb_setup_copy_write(nullb, rq->bio, > + rq->cmd_flags & REQ_FUA); > + else No need for this else. > + return nullb_setup_copy_read(nullb, rq->bio); > + } > + > spin_lock_irq(&nullb->lock); > rq_for_each_segment(bvec, rq, iter) { > len = bvec.bv_len; > @@ -1294,6 +1377,14 @@ static int null_handle_bio(struct nullb_cmd *cmd) > struct bio_vec bvec; > struct bvec_iter iter; > > + if (bio->bi_opf & REQ_COPY) { > + if (op_is_write(bio_op(bio))) > + return nullb_setup_copy_write(nullb, bio, > + bio->bi_opf & REQ_FUA); > + else No need for this else. > + return nullb_setup_copy_read(nullb, bio); > + } > + > spin_lock_irq(&nullb->lock); > bio_for_each_segment(bvec, bio, iter) { > len = bvec.bv_len; > @@ -2146,6 +2237,9 @@ static int null_add_dev(struct nullb_device *dev) > list_add_tail(&nullb->list, &nullb_list); > mutex_unlock(&lock); > > + blk_queue_max_copy_sectors_hw(nullb->disk->queue, 1024); > + blk_queue_flag_set(QUEUE_FLAG_COPY, nullb->disk->queue); This should NOT be unconditionally enabled with a magic value of 1K sectors. The max copy sectors needs to be set with a configfs attribute so that we can enable/disable the copy offload support, to be able to exercise both block layer emulation and native device support. > + > pr_info("disk %s created\n", nullb->disk_name); > > return 0; > diff --git a/drivers/block/null_blk/null_blk.h b/drivers/block/null_blk/null_blk.h > index eb5972c50be8..94e524e7306a 100644 > --- a/drivers/block/null_blk/null_blk.h > +++ b/drivers/block/null_blk/null_blk.h > @@ -67,6 +67,13 @@ enum { > NULL_Q_MQ = 2, > }; > > +struct nullb_copy_token { > + char subsys[5]; > + struct nullb *nullb; > + u64 sector_in; > + u64 sectors; > +}; > + > struct nullb_device { > struct nullb *nullb; > struct config_item item; -- Damien Le Moal Western Digital Research