From nobody Sun Feb 8 21:28:14 2026 Received: from mail-ot1-f100.google.com (mail-ot1-f100.google.com [209.85.210.100]) (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 BCD6D245014 for ; Sat, 3 Jan 2026 00:45:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.100 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767401143; cv=none; b=m16/SaiQjpcpflsZaby7WTsVz0B35PJOtq74iBLEVyR4RqbqPC2NtqJWtA97EE8s88DHZ43mZVh3sHNhxPmQjx3hdcd43Pe1PSN/Xr/cW7pfUK8tkgZU/v4wbot0CiFefJ+95vZiqwwS2AYzyIAwzkTLlQObOXARYfaLon6ui3A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767401143; c=relaxed/simple; bh=QxssRt2K7/arHhwAENIHPr/xs0l3C9sgNhJ+s1tkF+w=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hH34kwQpdWWMumCvjVu28oe/VsJxXVZjsgKE80yoH26pQm5Oceo4CiC0GHyiWFI8D2jYATC+CVVibsNhmxjMI6W8NVEje5ULJTAW+bF0aYKQjjdoV7m96Dvw9jdVrDl0IkcSZH/VYX0xPg9RqzZMAori8cdP/89306nQkzhM6Yo= 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=Zj1owq0b; arc=none smtp.client-ip=209.85.210.100 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="Zj1owq0b" Received: by mail-ot1-f100.google.com with SMTP id 46e09a7af769-7c7589281e9so2331516a34.1 for ; Fri, 02 Jan 2026 16:45:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=purestorage.com; s=google2022; t=1767401135; x=1768005935; 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=Zj1owq0bGskrbnSH51RVWb32S+ABTrOb9crYmb1Me//37C0M6PN06YUWz02qQl8UcE zom0vpXsQvj2ID+mloWR8xBIrH0ETzxePwKgrZkrbPSyX+9I2nFM/F7QDiK26gJOwUw5 kuAM7en9rlJGa3HeA2uHKDS2BUru48ugUiuAf8bx8qmFaN81M3duW1i5h4TianGAPpT+ +D2IZGM0YbwwwIe3zpSwG6ag9gktVIaGbB5RscICD3l4vU+yrp2Tmst9iYaK94RcKmoT owe1MC7Kn/MKGkjhCKR+iXsjoQSk1UbKkui25KGr5WUzHUO8S5g2Rs/LEUhMRlwxjEWM iCWQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1767401135; x=1768005935; 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=XoQL90MRi+ZKx4vGfQX8pnFZs7+Q+FbCfohNpCRywY+b/KkryTUxetPXrOjc4udYpR w6Y4vs4XkAnCvsqD8VlzkCwMSiCX83e5HfJpbCC1TaBV8Z3FCIfjFNDN//0cIzrGVQrM LidK23T4p73XVWZ+WxA0hWmTqUxbVq8wb76lbTOuMNOvORbjt1jdrxGO/N3atZ6HieI3 sdfzLW+ecbgxFWIYCb3rWtFG0JJY99aWeD++KcJXhHPn6aBHSFkhTEmj83Cm23IOaefS w4QguK0D/bYsHVxcp3S2T9WzyYPHQd7LhNWNh6i7sBTOqDn13ZHvldD6vR4mh7YjDyYQ 09ow== X-Forwarded-Encrypted: i=1; AJvYcCWTkQDwP1x5MdNQkNth43VfYhhWYXeyXAeCEa4TYO9cV3Pgc3eXrSRNGOOEvpwPUTqFyKg4lPvaJEvlAJ8=@vger.kernel.org X-Gm-Message-State: AOJu0YxpZKkr+TTguXTcSqQjZcHD7qIjyyn6VaWDRSjao28Kwychoyhe EMeg7LnKIwNZgh5ev+1kTzNhsSIGyJZ1dFOS0jLG70uKkmt+/Lwa882m1wkucnTGeFauWCoKl5M tgmh1sfyIsi5JjPyc+Hx4yf90iBXV218Z+8FXt/i6J9mdDjvTgbJh X-Gm-Gg: AY/fxX46Pdde4tDt06iTYuy3WpciLNRIzAEsiI2GexBOhRJILARB6QH1Uh2JDNkFeBI CpWQxKcb6nKc9wvn3Q1DDlTUsW5qd2mXgN/mI2A1CkpRiVqO+zdZezunz1h+kNR7XmNVL8IPsb1 bTegAEi8fkVUrOtpYWS0139iYjqGzcsrphud5Xl4k+i1tGBhkC41Fb531b+j1CorRHZCpbLe4Jq qqM2uBCmWLYONoYX0HdLPkjhZB9+lGmMwPwYmnV7r/Z5YDQs9tivAFfSg/99/4i2oSJ2VLD74Eo ROoSyp7e/3O7j2sTCuTqvOdwoG0sXeXbE/QDQcA4cNn5Ho4Ki2XooSFjpCZaCkdFcv93ASAk7RV IHlBmLR3oVpa4UhBR4BO0PODFqYQ= X-Google-Smtp-Source: AGHT+IFLwalgPrUnK/JshmelFKcHKKaza9UIJzmapQ5N39F9GOnFHGs1qG2AEw88mtSWG1HLbWTZUbhSO7Jr X-Received: by 2002:a05:6830:314f:b0:7c7:66df:54df with SMTP id 46e09a7af769-7cc66a0b3b8mr17419979a34.5.1767401135279; Fri, 02 Jan 2026 16:45:35 -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 46e09a7af769-7cc667ba104sm5572651a34.3.2026.01.02.16.45.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Jan 2026 16:45:35 -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 756C2341FB6; Fri, 2 Jan 2026 17:45:34 -0700 (MST) Received: by dev-csander.dev.purestorage.com (Postfix, from userid 1557716354) id 734E8E4426F; Fri, 2 Jan 2026 17:45:34 -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 15/19] selftests: ublk: implement integrity user copy in kublk Date: Fri, 2 Jan 2026 17:45:25 -0700 Message-ID: <20260103004529.1582405-16-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" 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