From nobody Fri Dec 19 07:20:06 2025 Received: from mail-qk1-f230.google.com (mail-qk1-f230.google.com [209.85.222.230]) (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 96F59287276 for ; Wed, 17 Dec 2025 05:35:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.230 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765949721; cv=none; b=U4zspqt2+YiDeSQLxiYp6BE0FgTMKGCgvgO1q50tMK9NEljx038OAyjJhEhoROGKbycsRlcgvrkpKSBK/DKmQ45fNOd5VUwxPF7ShI8YeS6cKA5bbgUgiRKT2P35r0RIDb6WMNmTuAStRhAPAMlSagZN0wytE/RJ6OSQrBb4fLY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765949721; c=relaxed/simple; bh=1m8EvyXDwfnBtO4rKSJxv1p1kVYtxq+BhiSXNiIuIFc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ai2BsOgbmPWfv/hycJbCdyUKccB+xYOpQ+LbjP6cVEps86bDYtOjpmq/btq8ALNbICtMOlSXmv7vRBL14Vjw/4189/YsqrKCfKntHabgMhMLY1JSe9IeSLQ0iepIKKgyuLDP4Vml4pi0mSGVpaHHTDrCQ41buOXREXfFec1V2h4= 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=AjwV1PEY; arc=none smtp.client-ip=209.85.222.230 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="AjwV1PEY" Received: by mail-qk1-f230.google.com with SMTP id af79cd13be357-8b2df1e0c10so109125085a.0 for ; Tue, 16 Dec 2025 21:35:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=purestorage.com; s=google2022; t=1765949713; x=1766554513; 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=hLmTlnuPqHH6b8/uqO7lFBozYXk9kulItImdN914sps=; b=AjwV1PEYCUMrcRrMXXX7CSjXLyq/7Cj2m+OKXHjC7fIObSwcRE2fTS4xCpQ8BuGWZe f0yJ7PgQPrUKTWa62gKHUls9dWJvqFXKXnDizP4GeU0h7xHnXbvKuHI+K7RV8XFfjjWm 2EKnutONnce/D54HoRPLUMc0NqIj3JOqiLnhzl8ww1a5ownoLwmbuys9nfXRBr0dWX1y X1rfdVWrVZ7vB3Bq3keRB7vA6WwXsLhW6+kmS/y5kLCdu3Ciw8ae2OE0sSIzmC7WMS9s ATRh9fI8/rhS6Or07I+6Ne1xcrS1nFvJwCAmr1fusfjKTRYpi/YPjaNhO5yEpwlStKPK AbxA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1765949713; x=1766554513; 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=hLmTlnuPqHH6b8/uqO7lFBozYXk9kulItImdN914sps=; b=jTZZzHUzER1j6Ka7PLM6pZ2cAmJe4zvfny9kyLPYSJkabVxEGLUXYwGW2YuVtchEoQ Pin5vOKu/mf0tPWwbxa9rhlJZBXAJlbpQ0hhhT3JuPVufciqfHcHRPesODCSfEyVlsdW Pe+O+TneF0/RvGiW/oTkd5NpW71IR83ZSLEE2r6xuwv3VhH8Zl5PDUQb1nsIpVnKJPFk /X1im9TAi8UaqrKPO6VK4DUzsGojLLmhEAelHp5dLcXEyyN6RC/ZrtJG5cVLAqDsseVI zYfONI4egQ+LfGE9KygGUoedTQWEzBaTqREQuTXuXs8/dLcyaJjFG2k3/MH/Tg8d19Jg pj9Q== X-Forwarded-Encrypted: i=1; AJvYcCUkZcozDBhWUmd4Ux/aV/FkQwJOyXTPDqbnTFlqVrHshveNxmrG/q3JgcwCmPfEHrR20XW332GLHVDgaXQ=@vger.kernel.org X-Gm-Message-State: AOJu0YyWdCtijxZfLslyLygInbP7wQkFHY5A3aXeBtyCvICyLVNQj65n AXWXKSiujVDQKpKova91CTfdLAkBtC4qgDCUzDlaDjATO/8JZk7wNFnCUag3ZalaRwXz+3MVeHc crwk0mMO4/wWA0kHh8G/JhVoZRyoZccHQRtzPBE1WX9AHqVFyZSbd X-Gm-Gg: AY/fxX5Nxe/w3jWZxKagLZKkD8Zd5s/RPsurK7anDLJwOPfw1HF4tMyLtyayZ8FrwQW i/mX5n1t1zGEvC/n6YHkIoFM3OEQIaKiuF4u5Z/W3y1hkrAWMgjCmmMpB/CctRHolhYvRXPwbVA D4DXPFDJS0qR2fNmyhu2KFkTpPl5nRC1xSWwxEJyUfi6dNMfacoh01MdEV6x4hoBquC5AWXeLp9 H6L/UyTEZ1zHi5gSkO+5+LayvcPXPSaaNbFicZu+BPFx0u2bNdPFxmhlyNq0tETOMXLsiVhBxT9 I2xDcaAdSkuZmJyw0hQjFHIvCQW56zSvOBtSkQc8wWKhYyy269aV+bGiLu4YbSkRujfJexGyHpg j0zXD6EVqg5cpCzqsors6N23GCnc= X-Google-Smtp-Source: AGHT+IEww8Xn6us3eOELOJf2dWwwlAwsZJ+WOpO1sBLgJOCvWnuS6p6k5sw8+fQPVGcQ83L4wdZsBp1KT178 X-Received: by 2002:a05:6214:3009:b0:880:6fa4:f55c with SMTP id 6a1803df08f44-8887e15808fmr208544136d6.6.1765949713446; Tue, 16 Dec 2025 21:35:13 -0800 (PST) Received: from c7-smtp-2023.dev.purestorage.com ([2620:125:9017:12:36:3:5:0]) by smtp-relay.gmail.com with ESMTPS id 6a1803df08f44-88993b13d22sm19235286d6.4.2025.12.16.21.35.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Dec 2025 21:35:13 -0800 (PST) X-Relaying-Domain: purestorage.com Received: from dev-csander.dev.purestorage.com (unknown [IPv6:2620:125:9007:640:ffff::1199]) by c7-smtp-2023.dev.purestorage.com (Postfix) with ESMTP id 486FF3401D2; Tue, 16 Dec 2025 22:35:12 -0700 (MST) Received: by dev-csander.dev.purestorage.com (Postfix, from userid 1557716354) id 45A06E41A08; Tue, 16 Dec 2025 22:35:12 -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 08/20] ublk: add ublk_copy_user_bvec() helper Date: Tue, 16 Dec 2025 22:34:42 -0700 Message-ID: <20251217053455.281509-9-csander@purestorage.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20251217053455.281509-1-csander@purestorage.com> References: <20251217053455.281509-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 d3652ceba96d..0499add560b5 100644 --- a/drivers/block/ublk_drv.c +++ b/drivers/block/ublk_drv.c @@ -987,10 +987,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(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, @@ -999,33 +1028,12 @@ static size_t ublk_copy_user_pages(const struct requ= est *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