Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp1993941rwl; Thu, 30 Mar 2023 04:41:02 -0700 (PDT) X-Google-Smtp-Source: AKy350YoRmIM0QOsRlxVH7dkVZJ1LSLOuO9OHQiY9XvPcvBBtxnJ/mRAupKvINZRoqokwZdT1ZWu X-Received: by 2002:a05:6a20:440c:b0:df:fd8d:a432 with SMTP id ce12-20020a056a20440c00b000dffd8da432mr2651813pzb.5.1680176462346; Thu, 30 Mar 2023 04:41:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680176462; cv=none; d=google.com; s=arc-20160816; b=qe5mnZVXatCq+o6590TvdK+gopCvKE35S3OM/tIBpF/b0n4e5qzQFfrtZvfHS1wMGd rrRYdVCniZeAqP83p9dByVtCRd8mCkgX89vjbEAq1e74yZ8DDijld3KBf8fDXOL+T0Hs EWKgGlEqCzv0j4nFNxQMpgpAvFVUadXQ4YDSG6D1KS8k5SD9claFHA1gdMwTMZnFGfdT gJNlCrkrpLcjH09XS17YUD+Y3Jt1Xa6E4kM+YfIS8PKAyh2A6tbIvY9CcHW78+Nx7HOO F9YJi/p3c+Ta2URTKW3MXtnPQSFzUqv0Djqc5bglTgSg/ODYIrVZOKJVm2gDvvoBO6GI qEBQ== 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=VFZ4HTDXQ9j9mvF7AZrrlFzXBT77MGX93ZTMUgSaoQU=; b=AfoK8CbqvZ7fiIdgVCeJQ0dqG5cD6JAaaowoNowQou2Y2NH6Ygvs+ufZ2BhDyuAlZ0 KN46pAxnYQWJuO2GDE5t5H9oC2c+2G46FtNl+TEnmuR3Ldafar0dPCvinSff6GaHAaCo T8UlzEZZ300C5HDgp/pt0PCanfxfjUMzB4LekFlbEQwU7vIo4Svq9F7jp1kshWrAewem P9YgBRoOXP3KXsjQ3mRYq57x2TgX30OedQqESjXHBdHVjPSynDQoglaiA1sCNYFOdjXX GIKEWkrfv0ioZTjxVACWh64YiXHSxaL24zZGlj5XYFcpM26A5xwg/c15OS2z289nlnlP vPRQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=OnmCVuHG; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v185-20020a6389c2000000b0050f5bfd2546si31417679pgd.731.2023.03.30.04.40.50; Thu, 30 Mar 2023 04:41:02 -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=@redhat.com header.s=mimecast20190719 header.b=OnmCVuHG; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230321AbjC3Li7 (ORCPT + 99 others); Thu, 30 Mar 2023 07:38:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47008 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231699AbjC3Lie (ORCPT ); Thu, 30 Mar 2023 07:38:34 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 826D19EE2 for ; Thu, 30 Mar 2023 04:37:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1680176234; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=VFZ4HTDXQ9j9mvF7AZrrlFzXBT77MGX93ZTMUgSaoQU=; b=OnmCVuHGzvnW9lDMP2RI6rhHQmNxQ6dbN2EqlmHc2HHlltr+y9QUCafQbRei/exswf7ZPL kzXYQmQPWyQBKW242LfwZBNRMAlhv/kTZVpShYUJoFQirSsech82nErOZ94ljl3I843qo9 daui3k2iNTsIJOcPHdyloHzQ2b9EROo= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-137-5dSRH69cN2WxjCzoc7DlOA-1; Thu, 30 Mar 2023 07:37:11 -0400 X-MC-Unique: 5dSRH69cN2WxjCzoc7DlOA-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 532C3101A552; Thu, 30 Mar 2023 11:37:10 +0000 (UTC) Received: from localhost (ovpn-8-19.pek2.redhat.com [10.72.8.19]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5BB562166B33; Thu, 30 Mar 2023 11:37:08 +0000 (UTC) From: Ming Lei To: Jens Axboe , io-uring@vger.kernel.org, linux-block@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Miklos Szeredi , ZiyangZhang , Xiaoguang Wang , Bernd Schubert , Pavel Begunkov , Stefan Hajnoczi , Dan Williams , Ming Lei Subject: [PATCH V6 06/17] io_uring: support OP_SEND_ZC/OP_RECV for fused secondary request Date: Thu, 30 Mar 2023 19:36:19 +0800 Message-Id: <20230330113630.1388860-7-ming.lei@redhat.com> In-Reply-To: <20230330113630.1388860-1-ming.lei@redhat.com> References: <20230330113630.1388860-1-ming.lei@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 X-Spam-Status: No, score=-0.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE 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 Start to allow fused secondary request to support OP_SEND_ZC/OP_RECV, and the buffer can be retrieved from primary request. Once secondary request is completed, the primary command will be done and the associated buffer is returned back. Signed-off-by: Ming Lei --- io_uring/net.c | 30 ++++++++++++++++++++++++++++-- io_uring/opdef.c | 6 ++++++ 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/io_uring/net.c b/io_uring/net.c index 4040cf093318..f0fce1db7596 100644 --- a/io_uring/net.c +++ b/io_uring/net.c @@ -16,6 +16,7 @@ #include "net.h" #include "notif.h" #include "rsrc.h" +#include "fused_cmd.h" #if defined(CONFIG_NET) struct io_shutdown { @@ -69,6 +70,13 @@ struct io_sr_msg { struct io_kiocb *notif; }; +#define user_ptr_to_u64(x) ( \ +{ \ + typecheck(void __user *, (x)); \ + (u64)(unsigned long)(x); \ +} \ +) + static inline bool io_check_multishot(struct io_kiocb *req, unsigned int issue_flags) { @@ -379,7 +387,11 @@ int io_send(struct io_kiocb *req, unsigned int issue_flags) if (unlikely(!sock)) return -ENOTSOCK; - ret = import_ubuf(ITER_SOURCE, sr->buf, sr->len, &msg.msg_iter); + if (!io_req_use_fused_buf(req)) + ret = import_ubuf(ITER_SOURCE, sr->buf, sr->len, &msg.msg_iter); + else + ret = io_import_buf_from_fused(user_ptr_to_u64(sr->buf), + sr->len, ITER_SOURCE, &msg.msg_iter, req); if (unlikely(ret)) return ret; @@ -870,7 +882,11 @@ int io_recv(struct io_kiocb *req, unsigned int issue_flags) sr->buf = buf; } - ret = import_ubuf(ITER_DEST, sr->buf, len, &msg.msg_iter); + if (!io_req_use_fused_buf(req)) + ret = import_ubuf(ITER_DEST, sr->buf, len, &msg.msg_iter); + else + ret = io_import_buf_from_fused(user_ptr_to_u64(sr->buf), + sr->len, ITER_DEST, &msg.msg_iter, req); if (unlikely(ret)) goto out_free; @@ -984,6 +1000,9 @@ int io_send_zc_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe) if (zc->flags & IORING_RECVSEND_FIXED_BUF) { unsigned idx = READ_ONCE(sqe->buf_index); + if (io_req_use_fused_buf(req)) + return -EINVAL; + if (unlikely(idx >= ctx->nr_user_bufs)) return -EFAULT; idx = array_index_nospec(idx, ctx->nr_user_bufs); @@ -1120,8 +1139,15 @@ int io_send_zc(struct io_kiocb *req, unsigned int issue_flags) if (unlikely(ret)) return ret; msg.sg_from_iter = io_sg_from_iter; + } else if (io_req_use_fused_buf(req)) { + ret = io_import_buf_from_fused(user_ptr_to_u64(zc->buf), + zc->len, ITER_SOURCE, &msg.msg_iter, req); + if (unlikely(ret)) + return ret; + msg.sg_from_iter = io_sg_from_iter; } else { io_notif_set_extended(zc->notif); + ret = import_ubuf(ITER_SOURCE, zc->buf, zc->len, &msg.msg_iter); if (unlikely(ret)) return ret; diff --git a/io_uring/opdef.c b/io_uring/opdef.c index d81c9afd65ed..c31badf4fe45 100644 --- a/io_uring/opdef.c +++ b/io_uring/opdef.c @@ -273,6 +273,8 @@ const struct io_issue_def io_issue_defs[] = { .audit_skip = 1, .ioprio = 1, .manual_alloc = 1, + .fused_secondary = 1, + .buf_dir = READ, #if defined(CONFIG_NET) .prep = io_sendmsg_prep, .issue = io_send, @@ -287,6 +289,8 @@ const struct io_issue_def io_issue_defs[] = { .buffer_select = 1, .audit_skip = 1, .ioprio = 1, + .fused_secondary = 1, + .buf_dir = WRITE, #if defined(CONFIG_NET) .prep = io_recvmsg_prep, .issue = io_recv, @@ -413,6 +417,8 @@ const struct io_issue_def io_issue_defs[] = { .audit_skip = 1, .ioprio = 1, .manual_alloc = 1, + .fused_secondary = 1, + .buf_dir = READ, #if defined(CONFIG_NET) .prep = io_send_zc_prep, .issue = io_send_zc, -- 2.39.2