From nobody Mon Feb 9 06:25:53 2026 Received: from mail-pl1-f227.google.com (mail-pl1-f227.google.com [209.85.214.227]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4C23722B8AB for ; Sat, 3 Jan 2026 00:45:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.227 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767401136; cv=none; b=IvNVCTDgELLXcu0PGCmz+9Y4lxq8xkFqNvsj0QsdW6KanTwJitpNb0X+FIW4dmMvO1jAQ/79NvGwHiqvCNBS2ZRDI/2yg3P/idKdg061v8tOlds71KVpyunV+R8p3AIfJpzpOfrKGjFX2T0GqT3d4R3ZsoS07Ui2Wh01ySjxKX8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767401136; c=relaxed/simple; bh=RgRQXPGgkBOFh+I3IU1dh10q8VHov+arOD4uOXzU9rg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=p2xuzhueNUYhtTrUkJkmTEOeoOrjo1BhGWq/NBQvS6QoJzCKW2TITSBAbbBBZ9l4aYH/h0x03globAf3SYfeDlTh1PsdWRFCrUdCiKQTWKpi6Z5F/LUnu5uTEX/QIa8qcqqfR6sD+7Xu8hwe5rPoeismr2L4uEK6iGtqKa4hJGA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=purestorage.com; spf=fail smtp.mailfrom=purestorage.com; dkim=pass (2048-bit key) header.d=purestorage.com header.i=@purestorage.com header.b=WpOtjxt4; arc=none smtp.client-ip=209.85.214.227 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=purestorage.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=purestorage.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=purestorage.com header.i=@purestorage.com header.b="WpOtjxt4" Received: by mail-pl1-f227.google.com with SMTP id d9443c01a7336-2a097cc08d5so32621495ad.0 for ; Fri, 02 Jan 2026 16:45:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=purestorage.com; s=google2022; t=1767401133; x=1768005933; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=czj0Xu0INr5Vy2ifFNe60pRb7rtoAzjqp2XCOa9c0II=; b=WpOtjxt4tfrrotLRrvuCFONjo1IQG5bmSH8zbWvvOji5XxHUmTzYDDPE854qVYAb22 hHhE0zcxYOrn1IcuW2TPhUn+p3PMFEN9yqc3J40u4ojecoIj1iwVn2khIVPBxD4s3Aq4 pEHem79pQ+ENPGH5mSwt30RvcFcutwFI52wwxePrIU472inoknlMZKycSW7ZixykkkTv mxlFx0QFmDyMf7wXr2qvp5Vtv0dhwXFVIdTLC9psUTS5qsHNa1ji7YsCF+SQRnmG/GPn nCaNJA3E7+wzrcVBM9pYEGv/Q6pJKQxcfH2BSCQt1fJchb+6ma8aYzCvuH3IyHGxSzT7 tRPg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1767401133; x=1768005933; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=czj0Xu0INr5Vy2ifFNe60pRb7rtoAzjqp2XCOa9c0II=; b=kzej2RD24bv5BtrfsUaIJAWgNVx2peSp/hxL8L/I0Glf87gqV9PC6BSlJEoCW89aKv eSwwY/nHZFEvV9WtWXvmHXom0loT2JZOqGitaEL1klWGwTGjZfkYrpkjmzndZvnGiXsq uqyvbrqL67PCFXVCmBXL7yNkmz3+q7nxTwrrSi+2edDcaPoEnPnq/CkbprLg9Fs8eJjm y1soR5LPEH/cN0ES8T3HV8VJIDPy1ueK6/rpDPgUG57cB3nXk9TGQT7jc9tl05oYGlYx qz4igXyIrwY7EEjn3WwECqhvDNzfibWu7eBsbNg6RigbyP8K/M2/7od7Th9IsNq+ASge 8zSA== X-Forwarded-Encrypted: i=1; AJvYcCVBek9K6rzLPrgZT7jwfFRBn30zIRSEegMmf3l8iS6H9zDX79TM1u613Va5LQz53zDHKuox+bF+dJQ1iGg=@vger.kernel.org X-Gm-Message-State: AOJu0Ywzfyh6fN91W/IGoMD9lFUKzzQOKoyffPwe3YF9LXAJsHFoASQ/ uODS3/F1LV4SLy64IZtw8zLufUCM84CiDTOY+XRo7Cp3hTPcvNborYcjN0PRWwSJDX3B/cgC2M+ xl9VRTi62RSJCl1sD7aFRV8eXOwY0YVL8ImMF X-Gm-Gg: AY/fxX681rxNFm8iQMTwCo4jrkLCAZg66K0i1VZkmL0kbs+TFihlBiy031Iq933V8As aTfPoi2OYuBSEHwdPZ47l7CVJ10R75h1Y/ItfZZJhxhpQKZfxNNSZkP+mtvYKD2a8WYqaQ+y90C RYku5jiaNx420ovGT5nJhGFvb4sbbUBl/NO/wBlsaP62DwfnmAb1iksk1Cdm2emIkFxkqmhxZWJ /ymkGlTJjgkid3diyCISpgvcrghXaE198Xs3KtKJMgKajT37PUOlv18xQj+6TbkwByD36WHz9PK Lzv0cRQmIm5b7pvw9ayiKdl+jScW3QaYq1RMO/cEJH5ZXeHgWvbRZFdZmkCYU3lX0+qSADZT00I XGTSuG/Vol69Busx7Rvn73rX7csfPbrkllluiaCXhTQ== X-Google-Smtp-Source: AGHT+IEzI2YDnQAtUpCUAyA6e8pluyG9Ja7Ny0SdrKIl/+tDZsFmLNITLlBY3bzENXifGoIeFNQS6g468aAz X-Received: by 2002:a05:7022:264a:b0:11b:862d:8031 with SMTP id a92af1059eb24-121721380fcmr16129506c88.0.1767401133187; Fri, 02 Jan 2026 16:45:33 -0800 (PST) Received: from c7-smtp-2023.dev.purestorage.com ([208.88.159.129]) by smtp-relay.gmail.com with ESMTPS id a92af1059eb24-1217253e933sm9026569c88.8.2026.01.02.16.45.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Jan 2026 16:45:33 -0800 (PST) X-Relaying-Domain: purestorage.com Received: from dev-csander.dev.purestorage.com (dev-csander.dev.purestorage.com [10.49.34.222]) by c7-smtp-2023.dev.purestorage.com (Postfix) with ESMTP id B920C3402DF; Fri, 2 Jan 2026 17:45:32 -0700 (MST) Received: by dev-csander.dev.purestorage.com (Postfix, from userid 1557716354) id B47DAE4426F; Fri, 2 Jan 2026 17:45:32 -0700 (MST) From: Caleb Sander Mateos To: Ming Lei , Jens Axboe , Shuah Khan Cc: linux-block@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, Stanley Zhang , Uday Shankar , Caleb Sander Mateos Subject: [PATCH v2 05/19] ublk: add ublk_copy_user_bvec() helper Date: Fri, 2 Jan 2026 17:45:15 -0700 Message-ID: <20260103004529.1582405-6-csander@purestorage.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20260103004529.1582405-1-csander@purestorage.com> References: <20260103004529.1582405-1-csander@purestorage.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Factor a helper function ublk_copy_user_bvec() out of ublk_copy_user_pages(). It will be used for copying integrity data too. Signed-off-by: Caleb Sander Mateos --- drivers/block/ublk_drv.c | 52 +++++++++++++++++++++++----------------- 1 file changed, 30 insertions(+), 22 deletions(-) diff --git a/drivers/block/ublk_drv.c b/drivers/block/ublk_drv.c index 51469e0627ff..811a125a5b04 100644 --- a/drivers/block/ublk_drv.c +++ b/drivers/block/ublk_drv.c @@ -1025,10 +1025,39 @@ static const struct block_device_operations ub_fops= =3D { .open =3D ublk_open, .free_disk =3D ublk_free_disk, .report_zones =3D ublk_report_zones, }; =20 +static bool ublk_copy_user_bvec(const struct bio_vec *bv, unsigned *offset, + struct iov_iter *uiter, int dir, size_t *done) +{ + unsigned len; + void *bv_buf; + size_t copied; + + if (*offset >=3D bv->bv_len) { + *offset -=3D bv->bv_len; + return true; + } + + len =3D bv->bv_len - *offset; + bv_buf =3D kmap_local_page(bv->bv_page) + bv->bv_offset + *offset; + if (dir =3D=3D ITER_DEST) + copied =3D copy_to_iter(bv_buf, len, uiter); + else + copied =3D copy_from_iter(bv_buf, len, uiter); + + kunmap_local(bv_buf); + + *done +=3D copied; + if (copied < len) + return false; + + *offset =3D 0; + return true; +} + /* * Copy data between request pages and io_iter, and 'offset' * is the start point of linear offset of request. */ static size_t ublk_copy_user_pages(const struct request *req, @@ -1037,33 +1066,12 @@ static size_t ublk_copy_user_pages(const struct req= uest *req, struct req_iterator iter; struct bio_vec bv; size_t done =3D 0; =20 rq_for_each_segment(bv, req, iter) { - unsigned len; - void *bv_buf; - size_t copied; - - if (offset >=3D bv.bv_len) { - offset -=3D bv.bv_len; - continue; - } - - len =3D bv.bv_len - offset; - bv_buf =3D kmap_local_page(bv.bv_page) + bv.bv_offset + offset; - if (dir =3D=3D ITER_DEST) - copied =3D copy_to_iter(bv_buf, len, uiter); - else - copied =3D copy_from_iter(bv_buf, len, uiter); - - kunmap_local(bv_buf); - - done +=3D copied; - if (copied < len) + if (!ublk_copy_user_bvec(&bv, &offset, uiter, dir, &done)) break; - - offset =3D 0; } return done; } =20 static inline bool ublk_need_map_req(const struct request *req) --=20 2.45.2