From nobody Sat Feb 7 09:59:14 2026 Received: from mail-qt1-f227.google.com (mail-qt1-f227.google.com [209.85.160.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 0A8C1202C5C for ; Tue, 6 Jan 2026 00:58:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.227 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767661101; cv=none; b=e5Y74elpo8xYSZbYMK7E/Sd+hdtyE5B4iH5buvjg/OasXWBX/WLCWterz4TeTAL5BoHO8jzidOUXA+6T4OrxiC/yYt/i1pH38hI3zWgvvG3nQa/4hyaAQqC3A1wH2JDWbXOcdFt5DnfjxQJ3lie1BRyUZoKbKozFZnBYZ6BBEQY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767661101; c=relaxed/simple; bh=QxssRt2K7/arHhwAENIHPr/xs0l3C9sgNhJ+s1tkF+w=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=isAhfZM094ei/OLFGYaMTo8g7qC9qr6OZbLmUl2uENIvN/+MPmcyKjUQ7nkrUWqhcouhy8w7svSSMgbvyK/cmrpy2vp5AUZnYbCDUFZg1wmx/2S/aa59pF13ZQh++ofQ4HEXZXDLlq9NSDFvNePRYsh8fspPlX7yiLqJ7Nw3CNc= 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=MjI/Ujfr; arc=none smtp.client-ip=209.85.160.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="MjI/Ujfr" Received: by mail-qt1-f227.google.com with SMTP id d75a77b69052e-4ee0633c9afso151551cf.0 for ; Mon, 05 Jan 2026 16:58:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=purestorage.com; s=google2022; t=1767661092; x=1768265892; 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=tY6pKUQ5Qn3DxRwxGDGPj6r/MLXemuiieYvUhI1zlzM=; b=MjI/UjfrUlbaELqYEmKXoImGQYp8AmKATB26fT2jP+kRJK1SvgNdsMvfIMDrp6IOA3 IA5OjW4mGiVIK+/IBXzx+rrAIvoeAlHeVGhvi8xcD2oEqdRLgx90/m+UlkH4aYQ080sp SjeWArG0OUgk3VK+lbp1a9QE2A+QFsPqoqa+jgdYpbDyaImlso5wigNHtpUMyzqPwPrF cn09AoGfhE4g4mcJ21Ad+J2e6XpbP6X2x2UsVdZN7cnkQHSuYgQLmWWS7q5tEG/OFYSw ulJCasY7c9wqP07zuqhZ0c9l7X9godFYCQsQqa7RC/DK98mwYoWX1AColgThv35jtakf BdVA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1767661092; x=1768265892; 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=tY6pKUQ5Qn3DxRwxGDGPj6r/MLXemuiieYvUhI1zlzM=; b=DhfFJJBj0GsD04STw8G02ksAClFidVfWK8+ueSyEFOmXTCcdxGIOmjqnuIJxAczwRe cMcnwmdm8IjhZEuQnqmeLiuyKwBSvzDKCD+0vrD7gGVGZBg/2vRGWwJBgwavHAp3M5r/ jDFtZyMODjOgvCv/t+ZtYaH6NDY+LBWgwghgIeACmNrK6waeqKzGb2FrOSazMupIhBPX tycbFfqMEQsaeJl3B2gDMjpYmcjg+TQWGaBqtJelj503okAOZAhawMr5MV9fTmkSycwf fKmfmkPrPrJwYxUrWN2CsVtEkmB2407wJhQsU+l7tWZBp+xPUArqgO+/3G7rI7i1s+rG 23pA== X-Forwarded-Encrypted: i=1; AJvYcCVhGXx+lSUkCeBsKWm0WLb0kUJW91/pyWuFEGnhVIcVDPfj5j4QDgIXiKLEIiUfmbY/KUeX3D2TwzfPKmc=@vger.kernel.org X-Gm-Message-State: AOJu0YwxdZDC5xoLNRetEsuSJuvrKvp8GvodQGXWUKgtvi5dlxna00Jl DO/FeIZyUzMVzHeNSOQj35vSrPE6+WQ8aPra3CFvT8TailtMd8RTTibFQh83AZkhupOabdYkoeP /guj/Nvf/XoLD/wxwSh68WihuTLP1VDnpTujgzipGPyYf1H0vPOdM X-Gm-Gg: AY/fxX4KI6OGHsMXiNHtPzD1JBqoRUSJ548rbSMZDa0wT/6yp9XzDM0Beq1kMxSJzJH pzbtB3PFucuM/UK9fbtKQlReEthYQSC77tzSHjw7JRpq957//j3nUj/Mkb4s7fMXdXFQEt2PHzL qkKOl9dkr1g2/e9evcJAA9/y9uHN0B6aZ9da7ztcitk59QABOO+eKFLgrVfS27cAVbFhgwqAHxG 8V9UaRcwjZlFbAuDaiFxDojmyFlYB5fAA1+Kj/17HnEklCwg3g+SHhPv0pSC7o/DlRBOr5DYq+V SnLo6V5sbcBV/TuKW99aJ7TTKa6ivEQ+7KRXRkRWriprojiZZlvVs2+9f2OLbxug7LYBCGmMnnl eaz3eCTRR2KIzl4/kxDS1OY7oh4I= X-Google-Smtp-Source: AGHT+IE3+qV6lMsdT+LdWxtRiwsIoi9qcTbvHyfusqkNl2ZgxSujSJyFfgl/w7QZTFvWDx8SUOCfZjNlVnWi X-Received: by 2002:a05:622a:1344:b0:4f3:616f:150 with SMTP id d75a77b69052e-4ffa759af60mr16305621cf.0.1767661091737; Mon, 05 Jan 2026 16:58:11 -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 d75a77b69052e-4ffa8d7f1adsm268321cf.2.2026.01.05.16.58.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Jan 2026 16:58:11 -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 CA1CF34084D; Mon, 5 Jan 2026 17:58:10 -0700 (MST) Received: by dev-csander.dev.purestorage.com (Postfix, from userid 1557716354) id BC8ADE44554; Mon, 5 Jan 2026 17:58:10 -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 , "Martin K . Petersen" , Caleb Sander Mateos Subject: [PATCH v3 15/19] selftests: ublk: implement integrity user copy in kublk Date: Mon, 5 Jan 2026 17:57:47 -0700 Message-ID: <20260106005752.3784925-16-csander@purestorage.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20260106005752.3784925-1-csander@purestorage.com> References: <20260106005752.3784925-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" If integrity data is enabled for kublk, allocate an integrity buffer for each I/O. Extend ublk_user_copy() to copy the integrity data between the ublk request and the integrity buffer if the ublksrv_io_desc indicates that the request has integrity data. Signed-off-by: Caleb Sander Mateos --- tools/testing/selftests/ublk/kublk.c | 41 ++++++++++++++++++++++++---- tools/testing/selftests/ublk/kublk.h | 14 ++++++++++ 2 files changed, 50 insertions(+), 5 deletions(-) diff --git a/tools/testing/selftests/ublk/kublk.c b/tools/testing/selftests= /ublk/kublk.c index 6ff110d0dcae..dfba808657b1 100644 --- a/tools/testing/selftests/ublk/kublk.c +++ b/tools/testing/selftests/ublk/kublk.c @@ -415,12 +415,14 @@ static void ublk_queue_deinit(struct ublk_queue *q) int nr_ios =3D q->q_depth; =20 if (q->io_cmd_buf) munmap(q->io_cmd_buf, ublk_queue_cmd_buf_sz(q)); =20 - for (i =3D 0; i < nr_ios; i++) + for (i =3D 0; i < nr_ios; i++) { free(q->ios[i].buf_addr); + free(q->ios[i].integrity_buf); + } } =20 static void ublk_thread_deinit(struct ublk_thread *t) { io_uring_unregister_buffers(&t->ring); @@ -432,23 +434,25 @@ static void ublk_thread_deinit(struct ublk_thread *t) close(t->ring.ring_fd); t->ring.ring_fd =3D -1; } } =20 -static int ublk_queue_init(struct ublk_queue *q, unsigned long long extra_= flags) +static int ublk_queue_init(struct ublk_queue *q, unsigned long long extra_= flags, + __u8 metadata_size) { struct ublk_dev *dev =3D q->dev; int depth =3D dev->dev_info.queue_depth; int i; - int cmd_buf_size, io_buf_size; + int cmd_buf_size, io_buf_size, integrity_size; unsigned long off; =20 q->tgt_ops =3D dev->tgt.ops; q->flags =3D 0; q->q_depth =3D depth; q->flags =3D dev->dev_info.flags; q->flags |=3D extra_flags; + q->metadata_size =3D metadata_size; =20 /* Cache fd in queue for fast path access */ q->ublk_fd =3D dev->fds[0]; =20 cmd_buf_size =3D ublk_queue_cmd_buf_sz(q); @@ -460,15 +464,27 @@ static int ublk_queue_init(struct ublk_queue *q, unsi= gned long long extra_flags) q->dev->dev_info.dev_id, q->q_id); goto fail; } =20 io_buf_size =3D dev->dev_info.max_io_buf_bytes; + integrity_size =3D ublk_integrity_len(q, io_buf_size); for (i =3D 0; i < q->q_depth; i++) { q->ios[i].buf_addr =3D NULL; q->ios[i].flags =3D UBLKS_IO_NEED_FETCH_RQ | UBLKS_IO_FREE; q->ios[i].tag =3D i; =20 + if (integrity_size) { + q->ios[i].integrity_buf =3D malloc(integrity_size); + if (!q->ios[i].integrity_buf) { + ublk_err("ublk dev %d queue %d io %d malloc(%d) failed: %m\n", + dev->dev_info.dev_id, q->q_id, i, + integrity_size); + goto fail; + } + } + + if (ublk_queue_no_buf(q)) continue; =20 if (posix_memalign((void **)&q->ios[i].buf_addr, getpagesize(), io_buf_size)) { @@ -607,17 +623,17 @@ static void ublk_user_copy(const struct ublk_io *io, = __u8 match_ublk_op) const struct ublksrv_io_desc *iod =3D ublk_get_iod(q, io->tag); __u64 off =3D ublk_user_copy_offset(q->q_id, io->tag); __u8 ublk_op =3D ublksrv_get_op(iod); __u32 len =3D iod->nr_sectors << 9; void *addr =3D io->buf_addr; + ssize_t copied; =20 if (ublk_op !=3D match_ublk_op) return; =20 while (len) { __u32 copy_len =3D min(len, UBLK_USER_COPY_LEN); - ssize_t copied; =20 if (ublk_op =3D=3D UBLK_IO_OP_WRITE) copied =3D pread(q->ublk_fd, addr, copy_len, off); else if (ublk_op =3D=3D UBLK_IO_OP_READ) copied =3D pwrite(q->ublk_fd, addr, copy_len, off); @@ -626,10 +642,24 @@ static void ublk_user_copy(const struct ublk_io *io, = __u8 match_ublk_op) assert(copied =3D=3D (ssize_t)copy_len); addr +=3D copy_len; off +=3D copy_len; len -=3D copy_len; } + + if (!(iod->op_flags & UBLK_IO_F_INTEGRITY)) + return; + + len =3D ublk_integrity_len(q, iod->nr_sectors << 9); + off =3D ublk_user_copy_offset(q->q_id, io->tag); + off +=3D UBLKSRV_IO_INTEGRITY_FLAG; + if (ublk_op =3D=3D UBLK_IO_OP_WRITE) + copied =3D pread(q->ublk_fd, io->integrity_buf, len, off); + else if (ublk_op =3D=3D UBLK_IO_OP_READ) + copied =3D pwrite(q->ublk_fd, io->integrity_buf, len, off); + else + assert(0); + assert(copied =3D=3D (ssize_t)len); } =20 int ublk_queue_io_cmd(struct ublk_thread *t, struct ublk_io *io) { struct ublk_queue *q =3D ublk_io_to_queue(io); @@ -1012,11 +1042,12 @@ static int ublk_start_daemon(const struct dev_ctx *= ctx, struct ublk_dev *dev) =20 for (i =3D 0; i < dinfo->nr_hw_queues; i++) { dev->q[i].dev =3D dev; dev->q[i].q_id =3D i; =20 - ret =3D ublk_queue_init(&dev->q[i], extra_flags); + ret =3D ublk_queue_init(&dev->q[i], extra_flags, + ctx->metadata_size); if (ret) { ublk_err("ublk dev %d queue %d init queue failed\n", dinfo->dev_id, i); goto fail; } diff --git a/tools/testing/selftests/ublk/kublk.h b/tools/testing/selftests= /ublk/kublk.h index d00f2b465cdf..830b49a7716a 100644 --- a/tools/testing/selftests/ublk/kublk.h +++ b/tools/testing/selftests/ublk/kublk.h @@ -110,10 +110,11 @@ struct ublk_ctrl_cmd_data { __u32 len; }; =20 struct ublk_io { char *buf_addr; + void *integrity_buf; =20 #define UBLKS_IO_NEED_FETCH_RQ (1UL << 0) #define UBLKS_IO_NEED_COMMIT_RQ_COMP (1UL << 1) #define UBLKS_IO_FREE (1UL << 2) #define UBLKS_IO_NEED_GET_DATA (1UL << 3) @@ -173,10 +174,11 @@ struct ublk_queue { /* borrow one bit of ublk uapi flags, which may never be used */ #define UBLKS_Q_AUTO_BUF_REG_FALLBACK (1ULL << 63) #define UBLKS_Q_NO_UBLK_FIXED_FD (1ULL << 62) __u64 flags; int ublk_fd; /* cached ublk char device fd */ + __u8 metadata_size; struct ublk_io ios[UBLK_QUEUE_DEPTH]; }; =20 struct ublk_thread { struct ublk_dev *dev; @@ -222,10 +224,22 @@ static inline void ublk_set_integrity_params(const st= ruct dev_ctx *ctx, .csum_type =3D ctx->csum_type, .tag_size =3D ctx->tag_size, }; } =20 +static inline size_t ublk_integrity_len(const struct ublk_queue *q, size_t= len) +{ + /* All targets currently use interval_exp =3D logical_bs_shift =3D 9 */ + return (len >> 9) * q->metadata_size; +} + +static inline size_t +ublk_integrity_data_len(const struct ublk_queue *q, size_t integrity_len) +{ + return (integrity_len / q->metadata_size) << 9; +} + static inline int ublk_io_auto_zc_fallback(const struct ublksrv_io_desc *i= od) { return !!(iod->op_flags & UBLK_IO_F_NEED_REG_BUF); } =20 --=20 2.45.2