From patchwork Mon Jul 10 06:46:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Hindborg X-Patchwork-Id: 117658 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9f45:0:b0:3ea:f831:8777 with SMTP id v5csp4833893vqx; Mon, 10 Jul 2023 00:04:06 -0700 (PDT) X-Google-Smtp-Source: APBJJlEXdNPk2Owri+kyFaI3gwo6GPMYZPsgfrHjalFPx2X953XNR449/QILrkTmbTt2gqGg0v3A X-Received: by 2002:a05:6512:159d:b0:4fb:caed:95c3 with SMTP id bp29-20020a056512159d00b004fbcaed95c3mr10335420lfb.53.1688972646052; Mon, 10 Jul 2023 00:04:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688972646; cv=none; d=google.com; s=arc-20160816; b=fuggTqBzwRJlCng41U14rwhBDFAm+YQ6sqKRIru2AdQU1zvzbmtdFcQ8TNF/FWt/mx ndZXSs49mwOAHNNx6gFjrIj+MeRLdH2SP7nj+6HJ1ncmVvRD5Vte5zXJklAjobsfY/nJ Zj6Jkue+3YBV6ckQNTIDc3RqVrFiGhTXgiwvIJ670jiJspB8q7PhCs3XeLqEOuzEkPxn 3zgQ+U10FTojs665liyRCrJyGHAKvRkl/ZSpAHCnxwHZuTQQtEu0CpDT1rWqLb6joSK5 u6lrMpeGEBDJlUGmlNceYHbMI8sABWQ1XDxeD1ryrs9qNdleU4LWUfE7fiHYg+mUPtCm dKUg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=ULsnDQO1R7NyZ+kouszec1NukJNpex1WKOoz+5ctk5g=; fh=Xd8Cfrj0OGz+nWm0hBmxQMVXLsDHU+gPeRIftA0lhqs=; b=XHt0FSibedhC4GNzwz//Oozc9Yghj34XAipi7O7+McXNApRBfV+G+rBtK7rFHMCzVJ rvz2w0I20drFxFH6RFP47iGqOiECo1+dHF2eaYFL/EQBn/KUwJcWYlccGlw1BinGyopL 1NeJq7ERFsVBXrVztpxbU15BAufg2WGIXu6uyrPoGlr62n7FuEY0+y8Jj6zOzf6WHbDp inhJ9OzvNXrcuRbHrhevrs98RhL9z96FohSySpn8+goWUL6H0rlqgG2DUHxtc0vaM+M1 f4Bdtwm/jjd2xYeVKaIIPKC2uPBqfsuzJLT/Uf3gaBxodZjL4QZFhvauyZPQEFiztcFX 6L0Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@metaspace-dk.20221208.gappssmtp.com header.s=20221208 header.b=iN11EwNu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w20-20020a056402129400b0051e4bd3e707si6467983edv.486.2023.07.10.00.03.42; Mon, 10 Jul 2023 00:04:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@metaspace-dk.20221208.gappssmtp.com header.s=20221208 header.b=iN11EwNu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231749AbjGJGqa (ORCPT + 99 others); Mon, 10 Jul 2023 02:46:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48916 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231765AbjGJGqY (ORCPT ); Mon, 10 Jul 2023 02:46:24 -0400 Received: from mail-lf1-x134.google.com (mail-lf1-x134.google.com [IPv6:2a00:1450:4864:20::134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C01AB13D for ; Sun, 9 Jul 2023 23:46:17 -0700 (PDT) Received: by mail-lf1-x134.google.com with SMTP id 2adb3069b0e04-4fb8574a3a1so5945412e87.1 for ; Sun, 09 Jul 2023 23:46:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=metaspace-dk.20221208.gappssmtp.com; s=20221208; t=1688971576; x=1691563576; 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=ULsnDQO1R7NyZ+kouszec1NukJNpex1WKOoz+5ctk5g=; b=iN11EwNuCYJVzKWiNxWAiJm8rJAuhdBLhYn/saKzDSMf6Iea26hmVZxeWxz11kAfrj bzVxBg6FQrgjJKE9pmHccMQ8536A+rzOcHkCc4JTDMkodoYrA5pM3MxEtzqluG6SPuC/ qA5Iq1Yda6HgCr1XKS6kjAeM0hfm+jszEzvEDQnLmTngZB7r3Jd+STnUUGspIV3PbaNU KrePbHuRJyp1uM4lNmbiDrc1lAiIQmVD7X9SlEM89JHnia4ZwWwhAqzvB4yqa80ixF3G 1E4EM6eazl+iQdJwsej084Iyam/8WP8uJ+3NhgJwZALKl81J4c5m73PnxjtxseAmJ8eP h2rg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688971576; x=1691563576; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ULsnDQO1R7NyZ+kouszec1NukJNpex1WKOoz+5ctk5g=; b=eVpr7m29Tk+G+ztzFUP2vzO/NaVFHzsSMRKAP3yRe8yYxbSGXG1eobgo9ovTuaCWld 0HGJteqwJ0pDJJTV3L8lSRmzo9Jv7imZQlP8TSJ0Qsry+2MBqGG3apU33izgRE/ilFys Anh8ceTOuX+8E2zJ8S1OBPkScfloIAv6Q2gSSxdoIIAyhIKT0eeEC0M9ksjJs+SXwq7P Hdu/bGrtnA6wx5A5oXuV2QmaiFpQgIG3VwTD426qZJImXprOKYzJnqlx3UeNKC0myoZK BrGOlzfYOI1XsUfcAoxYHSkvGXbtzjNlwCWDQ7NCa8jwMAyt8ikE0Uwk45QhIc9cSTyu bDvQ== X-Gm-Message-State: ABy/qLbaPMFP0UxrpgHOJiZ5wmYVD8WY56OizCEFzlwOy1omjjJyWg9/ QCXxNaziunY8kG8++fCdzMJrhg== X-Received: by 2002:a05:6512:b8c:b0:4f9:556b:93c2 with SMTP id b12-20020a0565120b8c00b004f9556b93c2mr11304889lfv.1.1688971575928; Sun, 09 Jul 2023 23:46:15 -0700 (PDT) Received: from localhost ([185.108.254.55]) by smtp.gmail.com with ESMTPSA id f15-20020ac251af000000b004fb8668e6cfsm1567079lfk.124.2023.07.09.23.46.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 09 Jul 2023 23:46:15 -0700 (PDT) From: Andreas Hindborg To: Ming Lei Cc: Jens Axboe , Hans Holmberg , Andreas Hindborg , linux-block@vger.kernel.org (open list:BLOCK LAYER), linux-kernel@vger.kernel.org (open list), Johannes Thumshirn , Damien Le Moal , Matias Bjorling , Christoph Hellwig , Minwoo Im , gost.dev@samsung.com, Aravind Ramesh Subject: [PATCH v7 1/3] ublk: add opcode offsets for DRV_IN/DRV_OUT Date: Mon, 10 Jul 2023 08:46:04 +0200 Message-ID: <20230710064607.155155-2-nmi@metaspace.dk> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230710064607.155155-1-nmi@metaspace.dk> References: <20230710064607.155155-1-nmi@metaspace.dk> MIME-Version: 1.0 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1771016181582674058 X-GMAIL-MSGID: 1771016181582674058 From: Andreas Hindborg Ublk zoned storage support relies on DRV_IN handling for zone report. Prepare for this change by adding offsets for the DRV_IN/DRV_OUT commands. Suggested-by: Ming Lei Signed-off-by: Andreas Hindborg --- include/uapi/linux/ublk_cmd.h | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/include/uapi/linux/ublk_cmd.h b/include/uapi/linux/ublk_cmd.h index 4b8558db90e1..521a0d2fbc06 100644 --- a/include/uapi/linux/ublk_cmd.h +++ b/include/uapi/linux/ublk_cmd.h @@ -229,12 +229,23 @@ struct ublksrv_ctrl_dev_info { __u64 reserved2; }; -#define UBLK_IO_OP_READ 0 +#define UBLK_IO_OP_READ 0 #define UBLK_IO_OP_WRITE 1 #define UBLK_IO_OP_FLUSH 2 -#define UBLK_IO_OP_DISCARD 3 -#define UBLK_IO_OP_WRITE_SAME 4 -#define UBLK_IO_OP_WRITE_ZEROES 5 +#define UBLK_IO_OP_DISCARD 3 +#define UBLK_IO_OP_WRITE_SAME 4 +#define UBLK_IO_OP_WRITE_ZEROES 5 +/* + * Ublk passthrough operation code ranges, and each passthrough operation + * provides generic interface between ublk kernel driver and ublk userspace, and + * this interface is usually used for handling generic block layer request, such + * as command of zoned report zones. Passthrough operation is only needed iff + * ublk kernel driver has to be involved for handling this operation. + */ +#define __UBLK_IO_OP_DRV_IN_START 32 +#define __UBLK_IO_OP_DRV_IN_END 96 +#define __UBLK_IO_OP_DRV_OUT_START __UBLK_IO_OP_DRV_IN_END +#define __UBLK_IO_OP_DRV_OUT_END 160 #define UBLK_IO_F_FAILFAST_DEV (1U << 8) #define UBLK_IO_F_FAILFAST_TRANSPORT (1U << 9) From patchwork Mon Jul 10 06:46:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Hindborg X-Patchwork-Id: 117657 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9f45:0:b0:3ea:f831:8777 with SMTP id v5csp4833361vqx; Mon, 10 Jul 2023 00:03:04 -0700 (PDT) X-Google-Smtp-Source: APBJJlEHeISsazizs74vNvGdWbPC0htIWz2oqm/3NZPdjiGZbYg+BC6xCaMpLJVeduR6ElsEJsdI X-Received: by 2002:ac2:5b1d:0:b0:4f7:6976:2070 with SMTP id v29-20020ac25b1d000000b004f769762070mr8765823lfn.40.1688972584268; Mon, 10 Jul 2023 00:03:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688972584; cv=none; d=google.com; s=arc-20160816; b=W4gRakPd9DaLQ1osjGu7fdftT52FjF/OMG7ntoqZJM6Hd2xkwnTNC55DgdY1U2+Lvz 9kEPxVOvuwDuEg3JvnJxEtdmvA7gAdCEQMDBSs0H7WBQg1ZE2/SFuoMz7erezaR7MfBU IDHFdMHELe5pGm3wSrKbpevKwbZsVgWcAF/DlBLSm+d+Yv2WtqzkczvLJS9yTYIkSP9G XmQv1Me8CI4plMNThPyUWmX7jN1/GSSEztXlYHDUgbdtphPwSqWrUeqHZv9iqBTFA7Wr WfLuyBpCuCQykxDk+jrJzpvas3yKc/UgPJpNEbLk0PYsvips/a/rZ9dIg5Ba5WCZm7Or NTXA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=gLXkkNKLC2QFI1E0y4rm62aHVfDJbTTFbFsFl9CT7J4=; fh=Xd8Cfrj0OGz+nWm0hBmxQMVXLsDHU+gPeRIftA0lhqs=; b=qJDSMYiJzNYIWxkw0um5ov5M29F8TjUWVCJd8i5FvSJ/KEGJSLuXCwjh6PeGKUClXa 3JU6QDaIX3fC+sVlUPTsB8JQP3L/Nau9hziUG8Nss5tsVn5LAeIakfqD4D87eXmn48o9 s9GrlPExngBti84wGnk/e67v7rkDljZTK+wYk2YERglX4Gt/EEZ9hpcYd6iy+4E8BaLb us2THot2WymNxFVgEz4yQer+UZBM9ilzXF8eG6hMf0T1ZnKLa+h9HUYvjPUUcwtPsYcI eRDY2ElzFUDjkQ5eNdxfjpUsIkdsVAc1HHHXIIEXoz3mEQX/svgBtuHDKBq21mCBI3FI JDFA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@metaspace-dk.20221208.gappssmtp.com header.s=20221208 header.b=tJlWPqtR; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m7-20020aa7d347000000b0051a2c8c1e4esi8144146edr.418.2023.07.10.00.02.40; Mon, 10 Jul 2023 00:03:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@metaspace-dk.20221208.gappssmtp.com header.s=20221208 header.b=tJlWPqtR; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231991AbjGJGqd (ORCPT + 99 others); Mon, 10 Jul 2023 02:46:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48922 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231774AbjGJGqY (ORCPT ); Mon, 10 Jul 2023 02:46:24 -0400 Received: from mail-lj1-x231.google.com (mail-lj1-x231.google.com [IPv6:2a00:1450:4864:20::231]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BBF00187 for ; Sun, 9 Jul 2023 23:46:18 -0700 (PDT) Received: by mail-lj1-x231.google.com with SMTP id 38308e7fff4ca-2b71ae5fa2fso12736801fa.0 for ; Sun, 09 Jul 2023 23:46:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=metaspace-dk.20221208.gappssmtp.com; s=20221208; t=1688971577; x=1691563577; 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=gLXkkNKLC2QFI1E0y4rm62aHVfDJbTTFbFsFl9CT7J4=; b=tJlWPqtRtUHBDxfXXwiE1c+MIiPPNh4Xf++CCl4xk4XPSvLWCmeiWmx6OrW2ghjDXr RSygzL2dz7sfa9RAatb/Y8qW9Twq5p6NbWIaQmRcmU2TXxl6cEQm5r+wYZNBATisJ8SY S6F5eOO8pCq0Q4MwR6E3c9t7D4YljjSRRytEn0qasj+PD/t+9XPixcFcbJHmzFijyctF YUrOlKm5GuZCJqzURmPMJ7/vWcHyV4pkhWymdtTQ7LFUzggEE1zoZXmaSJ+48i4UEy9X bOje3/v0o2k5KH3HJxeo5I2vdTvLpC4lL4tH9Va81pk+TQSlD//xcSxUfq07xXIoJDzk 5o+w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688971577; x=1691563577; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=gLXkkNKLC2QFI1E0y4rm62aHVfDJbTTFbFsFl9CT7J4=; b=L7PgmwBBAichDa+nwFiuKQiblXwXazdHEFb2uXikBVxkYghz5uU/HnhP8BwF60J+UE DnUblteMLpjQ/+lM+JC4/u+pX/6zMDFN6aaDoWWWnz2D2nSJZRYOvuCzoqxQai16kgdA IbjnUPcY3/tOq1NgHHjshbiSy3svGL2OHNfNyoZ15RQzsumUPVKo2wawF6+Zu/kp0M9l nDCu0pjGTsJGhCzgBM55HZog4mRpY6p2AHlbjkHV8ddaA4+ppPtrfX/lcbOekw4t8Ltm ICP7Qr8b50NbFcTzyu7zBVaBCRAPpcvvDdh3++1l3RhAwM/JguqE2EiqruclIZPBqdHx yKfw== X-Gm-Message-State: ABy/qLYE5ZoDce6igUyKZEl3v62Ka8Yu4HvF5IIq25aaJxiwBYIXrkyl jqATbhzI/UE5Evv9YuDKZUCa/g== X-Received: by 2002:a2e:908f:0:b0:2b6:9ed5:bf15 with SMTP id l15-20020a2e908f000000b002b69ed5bf15mr5758723ljg.23.1688971576905; Sun, 09 Jul 2023 23:46:16 -0700 (PDT) Received: from localhost ([185.108.254.55]) by smtp.gmail.com with ESMTPSA id e24-20020a2e8198000000b002b6ca141b6fsm1875280ljg.87.2023.07.09.23.46.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 09 Jul 2023 23:46:16 -0700 (PDT) From: Andreas Hindborg To: Ming Lei Cc: Jens Axboe , Hans Holmberg , Andreas Hindborg , linux-block@vger.kernel.org (open list:BLOCK LAYER), linux-kernel@vger.kernel.org (open list), Johannes Thumshirn , Damien Le Moal , Matias Bjorling , Christoph Hellwig , Minwoo Im , gost.dev@samsung.com, Aravind Ramesh Subject: [PATCH v7 2/3] ublk: add helper to check if device supports user copy Date: Mon, 10 Jul 2023 08:46:05 +0200 Message-ID: <20230710064607.155155-3-nmi@metaspace.dk> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230710064607.155155-1-nmi@metaspace.dk> References: <20230710064607.155155-1-nmi@metaspace.dk> MIME-Version: 1.0 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1771016116570375816 X-GMAIL-MSGID: 1771016116570375816 From: Andreas Hindborg This will be used by ublk zoned storage support. Signed-off-by: Andreas Hindborg --- drivers/block/ublk_drv.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/drivers/block/ublk_drv.c b/drivers/block/ublk_drv.c index 1c823750c95a..8d271901efac 100644 --- a/drivers/block/ublk_drv.c +++ b/drivers/block/ublk_drv.c @@ -185,6 +185,11 @@ struct ublk_params_header { __u32 types; }; +static inline bool ublk_dev_is_user_copy(const struct ublk_device *ub) +{ + return ub->dev_info.flags & UBLK_F_USER_COPY; +} + static inline void __ublk_complete_rq(struct request *req); static void ublk_complete_rq(struct kref *ref); @@ -2037,7 +2042,7 @@ static int ublk_ctrl_add_dev(struct io_uring_cmd *cmd) UBLK_F_URING_CMD_COMP_IN_TASK; /* GET_DATA isn't needed any more with USER_COPY */ - if (ub->dev_info.flags & UBLK_F_USER_COPY) + if (ublk_dev_is_user_copy(ub)) ub->dev_info.flags &= ~UBLK_F_NEED_GET_DATA; /* We are not ready to support zero copy */ From patchwork Mon Jul 10 06:46:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Hindborg X-Patchwork-Id: 117669 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9f45:0:b0:3ea:f831:8777 with SMTP id v5csp4843071vqx; Mon, 10 Jul 2023 00:24:57 -0700 (PDT) X-Google-Smtp-Source: APBJJlFXkCksNPTPEP7Bi6xA/z5FdkTRbs3ddQ7Vw4lJ5he3kCBUpCrWKQQAdbvRUd2j2Kc6hzAq X-Received: by 2002:a05:6a20:88:b0:12f:7a6a:7f96 with SMTP id 8-20020a056a20008800b0012f7a6a7f96mr8073936pzg.17.1688973896643; Mon, 10 Jul 2023 00:24:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688973896; cv=none; d=google.com; s=arc-20160816; b=MOwPsIWTfb9hv/SmQDrUn6f+//fG4ZMaiAM85M1BFy6/TR1ifD6b129iBzVrU/hiUl MiDMWs9QSiOLZcH1LXKY/QDeTzz13mvXZSf0sGn0MwH+cXOYfLbbdzmRuSCJ5fmyTS3x i+VMEJIyxU2c1juHbagGYYizHY9Uz4hxItMo85bOUV+d3N3qB4kwMPpUzUxJF3pczb9k it3q7S6wt5evGm4+x+74EFSm6lCF1uKNS5NHk8hhQSTJ6vkcA0/LPm1teoZuApmew2Po xQgCyfXaYAvHTB0IGIdviaUYwKzYMEtJwkHnYFvuuOAO2rvZp4LfYSr6aM5a084gsOvi eH7Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=ytWW0UO3oZDW44O3sKuX5IzY5hzPCQrJ/VVDbh3s2Wk=; fh=Xd8Cfrj0OGz+nWm0hBmxQMVXLsDHU+gPeRIftA0lhqs=; b=wXLu/G2Ll5yQTuUWphnnqyPjVk66JNQJmIISQMS8eGHtj1ZRTJnCbp+q8h+ZUvaeVc laajJtj7gXLQR+4nNCzgkMXNNzmnFGUNAFBgDUpm2Fagae3XwydWlc6UYOlATcoca5Yq 4KXZr3rzzo0PdQ2O1qGtK0CbqT2x2NzvnQpHz1alyP2zxA7MXHT7KWuIevMGj/a+F9xw NZZaHCnU/V8RPKsMqTXkqSebI1O0+1d/EK+5jWxs6Y5n/JLiGEUKcAfDT+6sNHnFwVUD LxkI64HPDR86Y/Ws7PxyYk4s/iscGQxI7cZPhKZKlz6bKXyvaYogg2G8n5MeX7wJsx1Y opEQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@metaspace-dk.20221208.gappssmtp.com header.s=20221208 header.b=Ra0EPT4A; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k11-20020a170902d58b00b001a6f0eab385si8667300plh.55.2023.07.10.00.24.44; Mon, 10 Jul 2023 00:24:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@metaspace-dk.20221208.gappssmtp.com header.s=20221208 header.b=Ra0EPT4A; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232063AbjGJGqf (ORCPT + 99 others); Mon, 10 Jul 2023 02:46:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48900 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231826AbjGJGq0 (ORCPT ); Mon, 10 Jul 2023 02:46:26 -0400 Received: from mail-lj1-x22b.google.com (mail-lj1-x22b.google.com [IPv6:2a00:1450:4864:20::22b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 99E3518D for ; Sun, 9 Jul 2023 23:46:19 -0700 (PDT) Received: by mail-lj1-x22b.google.com with SMTP id 38308e7fff4ca-2b5c2433134so51129501fa.0 for ; Sun, 09 Jul 2023 23:46:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=metaspace-dk.20221208.gappssmtp.com; s=20221208; t=1688971578; x=1691563578; 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=ytWW0UO3oZDW44O3sKuX5IzY5hzPCQrJ/VVDbh3s2Wk=; b=Ra0EPT4AMw36U7pjB1fHLIDQXzkxPKzVGy3AUNZNHhImCfqTjm4P0C4uHDYn4r2xaz JZ/Me8iMqSjvoevpvSU0pKGZ+PtrorMEbq67rQAZdhIuajobwO/gkGqi60jtx+S4TZka Esg5Ya8P/iTy/91D0X4iUZo1LCTnSClqMej+nUAnN9OqdS1YIppyWR3a1a414v9e8NLl lM7IqpQCxRjum/1bAlCDbHi3dmnZPg1LNOiEfHxV6WjaY2H7nXZ+yv+iJ/cRxZm+3NDD dTkuQgGbIwxyiimoz1zgYHPjDeCJ+t4YPZiIX7X9OzBJf2OaRvEYXioWowb5JHsIwcHd qYjQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688971578; x=1691563578; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ytWW0UO3oZDW44O3sKuX5IzY5hzPCQrJ/VVDbh3s2Wk=; b=EE0v4yyyiPEKNI26Ut4b7NMd8CdRqYXCfccNHkmsfUfPvHUKBdgY9TPpGJE+n48s3B xiIFyJVVLPJBNC8vkzW+iHmW4otQB/tVxA728azmG021t44O5isZdCHw89Xqc/yjPdNF wmA2yM90n4jW3w1CpAUtrqRItq0AE921PVmIrozeKHqt7DFmp6GR/AgPpUn/XGuSUhUv y+7Rhyx0cgmVpjE+H7NinTutV/LIK941T/U3iqkU7N/eV2iVG9RTEtmUaXx36bNq5MSg WAckhwvi3A8lpm4VNKnO1HTj2Dk+MrJ+ODyT75X0kBXV9fPz7X1aq1844lu3LDhbXBKv yTDQ== X-Gm-Message-State: ABy/qLZk9HkF1waEzC1gPnPVlWfpz04vy6i7BISouaU1dFVVWLumeCxp g33PVYsN4pcQoIOOAuKklosuuQ== X-Received: by 2002:a2e:998a:0:b0:2b4:677e:1433 with SMTP id w10-20020a2e998a000000b002b4677e1433mr4053331lji.5.1688971577939; Sun, 09 Jul 2023 23:46:17 -0700 (PDT) Received: from localhost ([185.108.254.55]) by smtp.gmail.com with ESMTPSA id g7-20020a2eb0c7000000b002b6e15ccf88sm1855779ljl.135.2023.07.09.23.46.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 09 Jul 2023 23:46:17 -0700 (PDT) From: Andreas Hindborg To: Ming Lei Cc: Jens Axboe , Hans Holmberg , Andreas Hindborg , linux-block@vger.kernel.org (open list:BLOCK LAYER), linux-kernel@vger.kernel.org (open list), Johannes Thumshirn , Damien Le Moal , Matias Bjorling , Christoph Hellwig , Minwoo Im , gost.dev@samsung.com, Aravind Ramesh Subject: [PATCH v7 3/3] ublk: enable zoned storage support Date: Mon, 10 Jul 2023 08:46:06 +0200 Message-ID: <20230710064607.155155-4-nmi@metaspace.dk> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230710064607.155155-1-nmi@metaspace.dk> References: <20230710064607.155155-1-nmi@metaspace.dk> MIME-Version: 1.0 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1770677078757862079 X-GMAIL-MSGID: 1771017492231714122 From: Andreas Hindborg Add zoned storage support to ublk: report_zones and operations: - REQ_OP_ZONE_OPEN - REQ_OP_ZONE_CLOSE - REQ_OP_ZONE_FINISH - REQ_OP_ZONE_RESET - REQ_OP_ZONE_APPEND The zone append feature uses the `addr` field of `struct ublksrv_io_cmd` to communicate ALBA back to the kernel. Therefore ublk must be used with the user copy feature (UBLK_F_USER_COPY) for zoned storage support to be available. Without this feature, ublk will not allow zoned storage support. Signed-off-by: Andreas Hindborg --- drivers/block/ublk_drv.c | 314 ++++++++++++++++++++++++++++++++-- include/uapi/linux/ublk_cmd.h | 30 ++++ 2 files changed, 328 insertions(+), 16 deletions(-) diff --git a/drivers/block/ublk_drv.c b/drivers/block/ublk_drv.c index 8d271901efac..a57be961b708 100644 --- a/drivers/block/ublk_drv.c +++ b/drivers/block/ublk_drv.c @@ -56,16 +56,21 @@ | UBLK_F_USER_RECOVERY_REISSUE \ | UBLK_F_UNPRIVILEGED_DEV \ | UBLK_F_CMD_IOCTL_ENCODE \ - | UBLK_F_USER_COPY) + | UBLK_F_USER_COPY \ + | UBLK_F_ZONED) /* 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) +#define UBLK_PARAM_TYPE_ALL \ + (UBLK_PARAM_TYPE_BASIC | UBLK_PARAM_TYPE_DISCARD | \ + UBLK_PARAM_TYPE_DEVT | UBLK_PARAM_TYPE_ZONED) struct ublk_rq_data { struct llist_node node; struct kref ref; + __u64 sector; + __u32 operation; + __u32 nr_sectors; }; struct ublk_uring_cmd_pdu { @@ -110,6 +115,11 @@ struct ublk_uring_cmd_pdu { */ #define UBLK_IO_FLAG_NEED_GET_DATA 0x08 +/* + * Set when IO is Zone Append + */ +#define UBLK_IO_FLAG_ZONE_APPEND 0x10 + struct ublk_io { /* userspace buffer address from io cmd */ __u64 addr; @@ -190,6 +200,198 @@ static inline bool ublk_dev_is_user_copy(const struct ublk_device *ub) return ub->dev_info.flags & UBLK_F_USER_COPY; } +static inline bool ublk_dev_is_zoned(const struct ublk_device *ub) +{ + return ub->dev_info.flags & UBLK_F_ZONED; +} + +static inline bool ublk_queue_is_zoned(struct ublk_queue *ubq) +{ + return ubq->flags & UBLK_F_ZONED; +} + +#ifdef CONFIG_BLK_DEV_ZONED + +static int ublk_get_nr_zones(const struct ublk_device *ub) +{ + const struct ublk_param_basic *p = &ub->params.basic; + + /* Zone size is a power of 2 */ + return p->dev_sectors >> ilog2(p->chunk_sectors); +} + +static int ublk_revalidate_disk_zones(struct ublk_device *ub) +{ + return blk_revalidate_disk_zones(ub->ub_disk, NULL); +} + +static int ublk_dev_param_zoned_validate(const struct ublk_device *ub) +{ + const struct ublk_param_zoned *p = &ub->params.zoned; + int nr_zones; + + if (!ublk_dev_is_zoned(ub)) + return -EINVAL; + + if (!p->max_zone_append_sectors) + return -EINVAL; + + nr_zones = ublk_get_nr_zones(ub); + + if (p->max_active_zones > nr_zones) + return -EINVAL; + + if (p->max_open_zones > nr_zones) + return -EINVAL; + + return 0; +} + +static int ublk_dev_param_zoned_apply(struct ublk_device *ub) +{ + const struct ublk_param_zoned *p = &ub->params.zoned; + + disk_set_zoned(ub->ub_disk, BLK_ZONED_HM); + blk_queue_required_elevator_features(ub->ub_disk->queue, + ELEVATOR_F_ZBD_SEQ_WRITE); + disk_set_max_active_zones(ub->ub_disk, p->max_active_zones); + disk_set_max_open_zones(ub->ub_disk, p->max_open_zones); + blk_queue_max_zone_append_sectors(ub->ub_disk->queue, p->max_zone_append_sectors); + + ub->ub_disk->nr_zones = ublk_get_nr_zones(ub); + + return 0; +} + +/* Based on virtblk_alloc_report_buffer */ +static void *ublk_alloc_report_buffer(struct ublk_device *ublk, + unsigned int nr_zones, size_t *buflen) +{ + struct request_queue *q = ublk->ub_disk->queue; + size_t bufsize; + void *buf; + + nr_zones = min_t(unsigned int, nr_zones, + ublk->ub_disk->nr_zones); + + bufsize = nr_zones * sizeof(struct blk_zone); + bufsize = + min_t(size_t, bufsize, queue_max_hw_sectors(q) << SECTOR_SHIFT); + bufsize = min_t(size_t, bufsize, queue_max_segments(q) << PAGE_SHIFT); + + while (bufsize >= sizeof(struct blk_zone)) { + buf = __vmalloc(bufsize, GFP_KERNEL | __GFP_NORETRY); + if (buf) { + *buflen = bufsize; + return buf; + } + bufsize >>= 1; + } + + *buflen = 0; + return NULL; +} + +static int ublk_report_zones(struct gendisk *disk, sector_t sector, + unsigned int nr_zones, report_zones_cb cb, void *data) +{ + struct ublk_device *ub = disk->private_data; + unsigned int zone_size_sectors = disk->queue->limits.chunk_sectors; + unsigned int first_zone = sector >> ilog2(zone_size_sectors); + unsigned int done_zones = 0; + unsigned int max_zones_per_request; + int ret; + struct blk_zone *buffer; + size_t buffer_length; + + nr_zones = min_t(unsigned int, ub->ub_disk->nr_zones - first_zone, + nr_zones); + + buffer = ublk_alloc_report_buffer(ub, nr_zones, &buffer_length); + if (!buffer) + return -ENOMEM; + + max_zones_per_request = buffer_length / sizeof(struct blk_zone); + + while (done_zones < nr_zones) { + unsigned int remaining_zones = nr_zones - done_zones; + unsigned int zones_in_request = + min_t(unsigned int, remaining_zones, max_zones_per_request); + struct request *req; + struct ublk_rq_data *pdu; + blk_status_t status; + + memset(buffer, 0, buffer_length); + + req = blk_mq_alloc_request(disk->queue, REQ_OP_DRV_IN, 0); + if (IS_ERR(req)) { + ret = PTR_ERR(req); + goto out; + } + + pdu = blk_mq_rq_to_pdu(req); + pdu->operation = UBLK_IO_OP_REPORT_ZONES; + pdu->sector = sector; + pdu->nr_sectors = remaining_zones * zone_size_sectors; + + ret = blk_rq_map_kern(disk->queue, req, buffer, buffer_length, + GFP_KERNEL); + if (ret) { + blk_mq_free_request(req); + goto out; + } + + status = blk_execute_rq(req, 0); + ret = blk_status_to_errno(status); + blk_mq_free_request(req); + if (ret) + goto out; + + for (unsigned int i = 0; i < zones_in_request; i++) { + struct blk_zone *zone = buffer + i; + + /* A zero length zone means no more zones in this response */ + if (!zone->len) + break; + + ret = cb(zone, i, data); + if (ret) + goto out; + + done_zones++; + sector += zone_size_sectors; + + } + } + + ret = done_zones; + +out: + kvfree(buffer); + return ret; +} + +#else + +#define ublk_report_zones (NULL) + +static int ublk_dev_param_zoned_validate(const struct ublk_device *ub) +{ + return -EOPNOTSUPP; +} + +static int ublk_dev_param_zoned_apply(struct ublk_device *ub) +{ + return -EOPNOTSUPP; +} + +static int ublk_revalidate_disk_zones(struct ublk_device *ub) +{ + return 0; +} + +#endif + static inline void __ublk_complete_rq(struct request *req); static void ublk_complete_rq(struct kref *ref); @@ -232,7 +434,7 @@ static inline unsigned ublk_pos_to_tag(loff_t pos) UBLK_TAG_BITS_MASK; } -static void ublk_dev_param_basic_apply(struct ublk_device *ub) +static int ublk_dev_param_basic_apply(struct ublk_device *ub) { struct request_queue *q = ub->ub_disk->queue; const struct ublk_param_basic *p = &ub->params.basic; @@ -257,6 +459,8 @@ static void ublk_dev_param_basic_apply(struct ublk_device *ub) set_disk_ro(ub->ub_disk, true); set_capacity(ub->ub_disk, p->dev_sectors); + + return 0; } static void ublk_dev_param_discard_apply(struct ublk_device *ub) @@ -286,6 +490,9 @@ static int ublk_validate_params(const struct ublk_device *ub) if (p->max_sectors > (ub->dev_info.max_io_buf_bytes >> 9)) return -EINVAL; + + if (ublk_dev_is_zoned(ub) && !p->chunk_sectors) + return -EINVAL; } else return -EINVAL; @@ -304,19 +511,31 @@ static int ublk_validate_params(const struct ublk_device *ub) if (ub->params.types & UBLK_PARAM_TYPE_DEVT) return -EINVAL; + if (ub->params.types & UBLK_PARAM_TYPE_ZONED) + return ublk_dev_param_zoned_validate(ub); + else if (ublk_dev_is_zoned(ub)) + return -EINVAL; + return 0; } static int ublk_apply_params(struct ublk_device *ub) { + int ret; + if (!(ub->params.types & UBLK_PARAM_TYPE_BASIC)) return -EINVAL; - ublk_dev_param_basic_apply(ub); + ret = ublk_dev_param_basic_apply(ub); + if (ret) + return ret; if (ub->params.types & UBLK_PARAM_TYPE_DISCARD) ublk_dev_param_discard_apply(ub); + if (ub->params.types & UBLK_PARAM_TYPE_ZONED) + return ublk_dev_param_zoned_apply(ub); + return 0; } @@ -487,6 +706,7 @@ static const struct block_device_operations ub_fops = { .owner = THIS_MODULE, .open = ublk_open, .free_disk = ublk_free_disk, + .report_zones = ublk_report_zones, }; #define UBLK_MAX_PIN_PAGES 32 @@ -601,7 +821,8 @@ static inline bool ublk_need_map_req(const struct request *req) static inline bool ublk_need_unmap_req(const struct request *req) { - return ublk_rq_has_data(req) && req_op(req) == REQ_OP_READ; + return ublk_rq_has_data(req) && + (req_op(req) == REQ_OP_READ || req_op(req) == REQ_OP_DRV_IN); } static int ublk_map_io(const struct ublk_queue *ubq, const struct request *req, @@ -685,8 +906,14 @@ static blk_status_t ublk_setup_iod(struct ublk_queue *ubq, struct request *req) { struct ublksrv_io_desc *iod = ublk_get_iod(ubq, req->tag); struct ublk_io *io = &ubq->ios[req->tag]; + struct ublk_rq_data *pdu = blk_mq_rq_to_pdu(req); + enum req_op op = req_op(req); u32 ublk_op; + if (!ublk_queue_is_zoned(ubq) && + (op_is_zone_mgmt(op) || op == REQ_OP_ZONE_APPEND)) + return -EIO; + switch (req_op(req)) { case REQ_OP_READ: ublk_op = UBLK_IO_OP_READ; @@ -703,6 +930,37 @@ static blk_status_t ublk_setup_iod(struct ublk_queue *ubq, struct request *req) case REQ_OP_WRITE_ZEROES: ublk_op = UBLK_IO_OP_WRITE_ZEROES; break; + case REQ_OP_ZONE_OPEN: + ublk_op = UBLK_IO_OP_ZONE_OPEN; + break; + case REQ_OP_ZONE_CLOSE: + ublk_op = UBLK_IO_OP_ZONE_CLOSE; + break; + case REQ_OP_ZONE_FINISH: + ublk_op = UBLK_IO_OP_ZONE_FINISH; + break; + case REQ_OP_ZONE_RESET: + ublk_op = UBLK_IO_OP_ZONE_RESET; + break; + case REQ_OP_DRV_IN: + ublk_op = pdu->operation; + switch (ublk_op) { + case UBLK_IO_OP_REPORT_ZONES: + iod->op_flags = ublk_op | ublk_req_build_flags(req); + iod->nr_sectors = pdu->nr_sectors; + iod->start_sector = pdu->sector; + return BLK_STS_OK; + default: + return BLK_STS_IOERR; + } + case REQ_OP_ZONE_APPEND: + ublk_op = UBLK_IO_OP_ZONE_APPEND; + io->flags |= UBLK_IO_FLAG_ZONE_APPEND; + break; + case REQ_OP_ZONE_RESET_ALL: + case REQ_OP_DRV_OUT: + /* We do not support reset_all and drv_out */ + return BLK_STS_NOTSUPP; default: return BLK_STS_IOERR; } @@ -756,7 +1014,8 @@ static inline void __ublk_complete_rq(struct request *req) * * Both the two needn't unmap. */ - if (req_op(req) != REQ_OP_READ && req_op(req) != REQ_OP_WRITE) + if (req_op(req) != REQ_OP_READ && req_op(req) != REQ_OP_WRITE && + req_op(req) != REQ_OP_DRV_IN) goto exit; /* for READ request, writing data in iod->addr to rq buffers */ @@ -1120,6 +1379,11 @@ static void ublk_commit_completion(struct ublk_device *ub, /* find the io request and complete */ req = blk_mq_tag_to_rq(ub->tag_set.tags[qid], tag); + if (io->flags & UBLK_IO_FLAG_ZONE_APPEND) { + req->__sector = ub_cmd->addr; + io->flags &= ~UBLK_IO_FLAG_ZONE_APPEND; + } + if (req && likely(!blk_should_fake_timeout(req->q))) ublk_put_req_ref(ubq, req); } @@ -1419,7 +1683,8 @@ static int __ublk_ch_uring_cmd(struct io_uring_cmd *cmd, ^ (_IOC_NR(cmd_op) == UBLK_IO_NEED_GET_DATA)) goto out; - if (ublk_support_user_copy(ubq) && ub_cmd->addr) { + if (ublk_support_user_copy(ubq) && + !(io->flags & UBLK_IO_FLAG_ZONE_APPEND) && ub_cmd->addr) { ret = -EINVAL; goto out; } @@ -1542,11 +1807,14 @@ static inline bool ublk_check_ubuf_dir(const struct request *req, int ubuf_dir) { /* copy ubuf to request pages */ - if (req_op(req) == REQ_OP_READ && ubuf_dir == ITER_SOURCE) + if ((req_op(req) == REQ_OP_READ || req_op(req) == REQ_OP_DRV_IN) && + ubuf_dir == ITER_SOURCE) return true; /* copy request pages to ubuf */ - if (req_op(req) == REQ_OP_WRITE && ubuf_dir == ITER_DEST) + if ((req_op(req) == REQ_OP_WRITE || + req_op(req) == REQ_OP_ZONE_APPEND) && + ubuf_dir == ITER_DEST) return true; return false; @@ -1885,17 +2153,24 @@ static int ublk_ctrl_start_dev(struct ublk_device *ub, struct io_uring_cmd *cmd) get_device(&ub->cdev_dev); ub->dev_info.state = UBLK_S_DEV_LIVE; + + if (ublk_dev_is_zoned(ub)) { + ret = ublk_revalidate_disk_zones(ub); + if (ret) + goto out_put_cdev; + } + ret = add_disk(disk); + if (ret) + goto out_put_cdev; + + set_bit(UB_STATE_USED, &ub->state); + +out_put_cdev: if (ret) { - /* - * Has to drop the reference since ->free_disk won't be - * called in case of add_disk failure. - */ ub->dev_info.state = UBLK_S_DEV_DEAD; ublk_put_device(ub); - goto out_put_disk; } - set_bit(UB_STATE_USED, &ub->state); out_put_disk: if (ret) put_disk(disk); @@ -2045,6 +2320,13 @@ static int ublk_ctrl_add_dev(struct io_uring_cmd *cmd) if (ublk_dev_is_user_copy(ub)) ub->dev_info.flags &= ~UBLK_F_NEED_GET_DATA; + /* Zoned storage support requires user copy feature */ + if (ublk_dev_is_zoned(ub) && + (!IS_ENABLED(CONFIG_BLK_DEV_ZONED) || !ublk_dev_is_user_copy(ub))) { + ret = -EINVAL; + goto out_free_dev_number; + } + /* We are not ready to support zero copy */ ub->dev_info.flags &= ~UBLK_F_SUPPORT_ZERO_COPY; diff --git a/include/uapi/linux/ublk_cmd.h b/include/uapi/linux/ublk_cmd.h index 521a0d2fbc06..215c596efe3a 100644 --- a/include/uapi/linux/ublk_cmd.h +++ b/include/uapi/linux/ublk_cmd.h @@ -176,6 +176,12 @@ /* Copy between request and user buffer by pread()/pwrite() */ #define UBLK_F_USER_COPY (1UL << 7) +/* + * User space sets this flag when setting up the device to request zoned storage support. Kernel may + * deny the request by returning an error. + */ +#define UBLK_F_ZONED (1ULL << 8) + /* device state */ #define UBLK_S_DEV_DEAD 0 #define UBLK_S_DEV_LIVE 1 @@ -235,6 +241,11 @@ struct ublksrv_ctrl_dev_info { #define UBLK_IO_OP_DISCARD 3 #define UBLK_IO_OP_WRITE_SAME 4 #define UBLK_IO_OP_WRITE_ZEROES 5 +#define UBLK_IO_OP_ZONE_OPEN 10 +#define UBLK_IO_OP_ZONE_CLOSE 11 +#define UBLK_IO_OP_ZONE_FINISH 12 +#define UBLK_IO_OP_ZONE_APPEND 13 +#define UBLK_IO_OP_ZONE_RESET 15 /* * Ublk passthrough operation code ranges, and each passthrough operation * provides generic interface between ublk kernel driver and ublk userspace, and @@ -243,6 +254,16 @@ struct ublksrv_ctrl_dev_info { * ublk kernel driver has to be involved for handling this operation. */ #define __UBLK_IO_OP_DRV_IN_START 32 +/* + * Construct a zone report. The report request is carried in `struct + * ublksrv_io_desc`. The `start_sector` field must be the first sector of a zone + * and shall indicate the first zone of the report. The `nr_sectors` shall + * indicate how many zones should be reported (divide by zone size to get number + * of zones in the report) and must be an integer multiple of the zone size. The + * report shall be delivered as a `struct blk_zone` array. To report fewer zones + * than requested, zero the last entry of the returned array. + */ +#define UBLK_IO_OP_REPORT_ZONES __UBLK_IO_OP_DRV_IN_START #define __UBLK_IO_OP_DRV_IN_END 96 #define __UBLK_IO_OP_DRV_OUT_START __UBLK_IO_OP_DRV_IN_END #define __UBLK_IO_OP_DRV_OUT_END 160 @@ -342,6 +363,13 @@ struct ublk_param_devt { __u32 disk_minor; }; +struct ublk_param_zoned { + __u32 max_open_zones; + __u32 max_active_zones; + __u32 max_zone_append_sectors; + __u8 reserved[20]; +}; + struct ublk_params { /* * Total length of parameters, userspace has to set 'len' for both @@ -353,11 +381,13 @@ struct ublk_params { #define UBLK_PARAM_TYPE_BASIC (1 << 0) #define UBLK_PARAM_TYPE_DISCARD (1 << 1) #define UBLK_PARAM_TYPE_DEVT (1 << 2) +#define UBLK_PARAM_TYPE_ZONED (1 << 3) __u32 types; /* types of parameter included */ struct ublk_param_basic basic; struct ublk_param_discard discard; struct ublk_param_devt devt; + struct ublk_param_zoned zoned; }; #endif