From nobody Fri Dec 19 07:20:13 2025 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 2C735258ECC for ; Wed, 17 Dec 2025 05:35:13 +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=1765949718; cv=none; b=WKOiNhiM0KMBpGJlDcGYGOCdC7WxHJQ5FzIgSsrenwKKj9XwORt2OvSeqVVV6w/yDDQbtxewDaq6t10YVZuUjRd6blAf9eTxhKUnJEH8HzppuYk8N+AEs1F5tsGkCJavONrbEgqGgSm5vpLlUP2kvbPvRlyDIaWeFK0qRNLwgzo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765949718; c=relaxed/simple; bh=OOXWaan+k6PBqwTEL0czF4iDFHJndZaTqnCQr/uI6ZM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=EwTYyE6W7tgA6WRGXzqtBNWMb7/ZjwN1HajsaQbE73BKKnh8SEHhhfmLeZ/KAxGmdkm85OXH9Zs+TDy8m4vONEbQYFX6qBR+3puCuedFwL050jJ8dPhUiIOtNjQEYMVj4B1t8ejac/1BnIWZQvwmwzzX8A9qIl4w1vDplUlYLy8= 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=Er87W86U; 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="Er87W86U" Received: by mail-pl1-f227.google.com with SMTP id d9443c01a7336-2a097cc08d5so7935665ad.0 for ; Tue, 16 Dec 2025 21:35:13 -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=Zznngbs4m93+ngp43rYp7bEDz3TrzVx/RV2H/1Phn2Q=; b=Er87W86UM8z/X9zbNW7fYHRB+B2bN4VCWKFhHAqLHrDcYU00NbhkixN+n0nFJ9oXNh 2ZiMEXDTi6/L8ileOqOOD1yyltgTdoRtHkJbI7K9Yse/YrYATUcy1Og8ODu68AkTPV0H A3/LZegmaPeUUIiNSVKHR4l7wxM/yZ5xbHGvQoWFqyM39lRAeydP2wczlEAM/m3zDygz 13oCx3b0uH26EtPU6+81lSaDOuJoeP1rH3O5gWXeZnC9doYqFdAEnElQUd4SXz2SojEL QL6Y7jk+c3xqvAJPK3GYbGIEv+NwQod8LP4rUBXL7PMS2yC8esKNbufHjseFZ601alPo tDqQ== 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=Zznngbs4m93+ngp43rYp7bEDz3TrzVx/RV2H/1Phn2Q=; b=FyhzmGfFd/PL/7bRsSQmOJrNO9Iw12U5HuIESTGn1WKEZUxL7RwyQaCsohEF6xK/xh L0rIvJwaNTewb6DShigT5HtphTwCahF+ND/Fjl1B3zXmaDGFiX7QJZ/d06250mpZdtng XuududcncaA8iI7rTZavz+eYBDXsuB98NDXPbpf6zWC2LnJVuen0u7+BVvJHEvvqoQEi b/x+7hT0DpDBWWKW01lMgW97qFYbiUPRMi3UZfun4UB+BwhJ1EiAQyBKC64fnGq5H8fl 9Lyun5S2fCmT/CGqLUR1C3I+zuLCUAMjdzwIsJZFl2hqm4wJ90Io4yz0qrfhifHNee2m Q72Q== X-Forwarded-Encrypted: i=1; AJvYcCUQ1DuKM+poXBnjbc76A1bv1RgUqiuvOPKEryNmhxpydSSdJl8pqOK6rg896KWmoXsMmS1TqiSKK3N/h+Y=@vger.kernel.org X-Gm-Message-State: AOJu0YwUm9/5nuzoekM1idw3Dc2tdU6Jq2TBJl6ibZwmXF/HVcnJ9CmZ CQ2LPqUzOY7yzTqJPjUnmfjom7Zqyb+0vKkgQt+/Z/psLhZe8KwtYyMArtZicY7mD3Z6vzwc9hl SdVUeekNGfnymDTGp5UwKxN4nRFF2cTOOdGGA X-Gm-Gg: AY/fxX6hk0Z66D6wUctXgIYhMtYDG5XEh+Qb6DIpoxqJOupQBcMfwDjf0g8ianmSpWr N3MkKUJ7BR9l/CnnZQgDElwsnWMyNAKJQX/OxR65NEEBIaOKadlH5ce7DsPGhkM897xYrnljJYH 6pKQKFR+jiaYhnA8VYxMyixe/Z65jgk/vU09q/DNRjSPlEpc+4K8Ngrcn40bDqwMqm5GUxjXski rKwdu4OdZ1i1iY+rLY3ZV7LbiVdOehSsN6n6lzoKaD3eN+X9N9xBGinlO9zhgyewln3ILDklkiw rbna5oryC1tQjxU3t9r2FXdldTGMHs6fkbSSTiF1ni7FGura/q7AH6h+h6FkEdHJSPXSfK5KcCU qgepN3YQIwOg2K6sEpzn3ujdHuD18T2eoe2A4haWPqw== X-Google-Smtp-Source: AGHT+IFIoOpuRg1q9EuTG0Nc8t8lYQNrZq3x8IAXv8KiSuUg/NK/XNf2ZmAO0r6Gx/3SMpY6lnMAk35MnOeS X-Received: by 2002:a05:7301:d0a:b0:2ae:5b8c:324a with SMTP id 5a478bee46e88-2ae5b8c395emr709246eec.4.1765949712622; Tue, 16 Dec 2025 21:35:12 -0800 (PST) Received: from c7-smtp-2023.dev.purestorage.com ([208.88.159.128]) by smtp-relay.gmail.com with ESMTPS id 5a478bee46e88-2ac3c13d622sm2020103eec.0.2025.12.16.21.35.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Dec 2025 21:35:12 -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 0EC2A342237; Tue, 16 Dec 2025 22:35:12 -0700 (MST) Received: by dev-csander.dev.purestorage.com (Postfix, from userid 1557716354) id 0CA87E41A08; 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 06/20] ublk: support UBLK_PARAM_TYPE_INTEGRITY in device creation Date: Tue, 16 Dec 2025 22:34:40 -0700 Message-ID: <20251217053455.281509-7-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" From: Stanley Zhang If the UBLK_PARAM_TYPE_INTEGRITY flag is set, validate the integrity parameters and apply them to the blk_integrity limits. UBLK_PARAM_TYPE_INTEGRITY requires CONFIG_BLK_DEV_INTEGRITY=3Dy, UBLK_F_USER_COPY, and metadata_size > 0. Reuse the block metadata ioctl LBMD_PI_CAP_* and LBMD_PI_CSUM_* constants from the linux/fs.h UAPI header for the flags and csum_type field values. The struct ublk_param_integrity validations are based on the checks in blk_validate_integrity_limits(). Any invalid parameters should be rejected before being applied to struct blk_integrity. Signed-off-by: Stanley Zhang [csander: add param validation] Signed-off-by: Caleb Sander Mateos --- drivers/block/ublk_drv.c | 92 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 91 insertions(+), 1 deletion(-) diff --git a/drivers/block/ublk_drv.c b/drivers/block/ublk_drv.c index 4da5d8ff1e1d..2893a9172220 100644 --- a/drivers/block/ublk_drv.c +++ b/drivers/block/ublk_drv.c @@ -42,10 +42,12 @@ #include #include #include #include #include +#include +#include #include =20 #define UBLK_MINORS (1U << MINORBITS) =20 #define UBLK_INVALID_BUF_IDX ((u16)-1) @@ -81,11 +83,12 @@ =20 /* All UBLK_PARAM_TYPE_* should be included here */ #define UBLK_PARAM_TYPE_ALL \ (UBLK_PARAM_TYPE_BASIC | UBLK_PARAM_TYPE_DISCARD | \ UBLK_PARAM_TYPE_DEVT | UBLK_PARAM_TYPE_ZONED | \ - UBLK_PARAM_TYPE_DMA_ALIGN | UBLK_PARAM_TYPE_SEGMENT) + UBLK_PARAM_TYPE_DMA_ALIGN | UBLK_PARAM_TYPE_SEGMENT | \ + UBLK_PARAM_TYPE_INTEGRITY) =20 struct ublk_uring_cmd_pdu { /* * Store requests in same batch temporarily for queuing them to * daemon context. @@ -613,10 +616,57 @@ static void ublk_dev_param_basic_apply(struct ublk_de= vice *ub) set_disk_ro(ub->ub_disk, true); =20 set_capacity(ub->ub_disk, p->dev_sectors); } =20 +static int ublk_integrity_flags(u32 flags) +{ + int ret_flags =3D 0; + + if (flags & LBMD_PI_CAP_INTEGRITY) { + flags &=3D ~LBMD_PI_CAP_INTEGRITY; + ret_flags |=3D BLK_INTEGRITY_DEVICE_CAPABLE; + } + if (flags & LBMD_PI_CAP_REFTAG) { + flags &=3D ~LBMD_PI_CAP_REFTAG; + ret_flags |=3D BLK_INTEGRITY_REF_TAG; + } + return flags ? -EINVAL : ret_flags; +} + +static int ublk_integrity_pi_tuple_size(u8 csum_type) +{ + switch (csum_type) { + case LBMD_PI_CSUM_NONE: + return 0; + case LBMD_PI_CSUM_IP: + case LBMD_PI_CSUM_CRC16_T10DIF: + return 8; + case LBMD_PI_CSUM_CRC64_NVME: + return 16; + default: + return -EINVAL; + } +} + +static enum blk_integrity_checksum ublk_integrity_csum_type(u8 csum_type) +{ + switch (csum_type) { + case LBMD_PI_CSUM_NONE: + return BLK_INTEGRITY_CSUM_NONE; + case LBMD_PI_CSUM_IP: + return BLK_INTEGRITY_CSUM_IP; + case LBMD_PI_CSUM_CRC16_T10DIF: + return BLK_INTEGRITY_CSUM_CRC; + case LBMD_PI_CSUM_CRC64_NVME: + return BLK_INTEGRITY_CSUM_CRC64; + default: + WARN_ON_ONCE(1); + return BLK_INTEGRITY_CSUM_NONE; + } +} + static int ublk_validate_params(const struct ublk_device *ub) { /* basic param is the only one which must be set */ if (ub->params.types & UBLK_PARAM_TYPE_BASIC) { const struct ublk_param_basic *p =3D &ub->params.basic; @@ -675,10 +725,35 @@ static int ublk_validate_params(const struct ublk_dev= ice *ub) return -EINVAL; if (p->max_segment_size < UBLK_MIN_SEGMENT_SIZE) return -EINVAL; } =20 + if (ub->params.types & UBLK_PARAM_TYPE_INTEGRITY) { + const struct ublk_param_integrity *p =3D &ub->params.integrity; + int pi_tuple_size =3D ublk_integrity_pi_tuple_size(p->csum_type); + int flags =3D ublk_integrity_flags(p->flags); + + if (!IS_ENABLED(CONFIG_BLK_DEV_INTEGRITY)) + return -EINVAL; + if (!ublk_dev_support_user_copy(ub)) + return -EINVAL; + if (flags < 0) + return flags; + if (pi_tuple_size < 0) + return pi_tuple_size; + if (!p->metadata_size) + return -EINVAL; + if (p->csum_type =3D=3D LBMD_PI_CSUM_NONE && + (p->flags & LBMD_PI_CAP_REFTAG)) + return -EINVAL; + if (p->pi_offset + pi_tuple_size > p->metadata_size) + return -EINVAL; + if (p->interval_exp < SECTOR_SHIFT || + p->interval_exp > ub->params.basic.logical_bs_shift) + return -EINVAL; + } + return 0; } =20 static void ublk_apply_params(struct ublk_device *ub) { @@ -2901,10 +2976,25 @@ static int ublk_ctrl_start_dev(struct ublk_device *= ub, lim.seg_boundary_mask =3D ub->params.seg.seg_boundary_mask; lim.max_segment_size =3D ub->params.seg.max_segment_size; lim.max_segments =3D ub->params.seg.max_segments; } =20 + if (ub->params.types & UBLK_PARAM_TYPE_INTEGRITY) { + const struct ublk_param_integrity *p =3D &ub->params.integrity; + int pi_tuple_size =3D ublk_integrity_pi_tuple_size(p->csum_type); + + lim.integrity =3D (struct blk_integrity) { + .flags =3D ublk_integrity_flags(p->flags), + .csum_type =3D ublk_integrity_csum_type(p->csum_type), + .metadata_size =3D p->metadata_size, + .pi_offset =3D p->pi_offset, + .interval_exp =3D p->interval_exp, + .tag_size =3D p->tag_size, + .pi_tuple_size =3D pi_tuple_size, + }; + } + if (wait_for_completion_interruptible(&ub->completion) !=3D 0) return -EINTR; =20 if (ub->ublksrv_tgid !=3D ublksrv_pid) return -EINVAL; --=20 2.45.2