Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp1751369pxj; Wed, 19 May 2021 13:04:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzvX+GGR4wiKgO67f6mIWHMsjBSdh5u7Y190p55wB6YUfBLxdB6pvTDAn78JMHSr4JJVobU X-Received: by 2002:a17:907:98a9:: with SMTP id ju9mr846181ejc.257.1621454687407; Wed, 19 May 2021 13:04:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621454687; cv=none; d=google.com; s=arc-20160816; b=y+m4xSNMEhYB05CKZ36UwUgx3XiJtJv5qoQnpIthgXnlliEsH5XSk8tATznRPxeBL1 6Y8it3HZSo89Qc8caaN7t0RzeliY2mouo7zeECqBBA3vDn+z1kN+NwDIvji9X8UQ/KOT 8RzomR1ZYL1MSgsptx1taVmnYVErLXTROaW32DfF+DpGWQ7fGi55fw54fBBlGBcXueC2 D+4/H3Xslp1lNjmhY0k+7kkl02fGZywYpmoPDw+I0/ko8Ra4xSlveIFD/XmVUxmeb898 K38qJ010Fbznbw23NGec158pefl+afPz9NTFWfys5ZMcEmaBwQlXCwbIr0VkIIKBDER5 BGpg== 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=i3e5Ax3mN/Y6yPJpYOCMTBCrnugW+yH6avkA8+dpTMg=; b=Q0hK5hmUJfceZvqSFLwKSuxZRZyMvdlHZ4hqd2z8hiJnou5qytHUgi1LM548gpllYH XiDNneUDiq8EvsgI5NAUGGwELa2mjhGnHbJKle6UN2oY/NYFnYjweFageETHSGmkCcNk vS3xYFOi5Jq/dJJnJDZUEm1/wmmvtKVa+/VBTkvJoYVtWniO/US738QsgOSjTpUwC+xr KPVeOLl39+ehbFL/3/FKYVELSJg12fH6hun/3WSRMH8ZvpaJcKF4S++Ol6/Knf+28fKi w4eNzabEom4TV8VN95bEu7C6UDfyS1j3DELFEJdeS5DS27/hvOfpxM072diSsV2XhB25 j1Rg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=o0IMFRjU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f10si252550edy.212.2021.05.19.13.04.23; Wed, 19 May 2021 13:04:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=o0IMFRjU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1354297AbhESOQz (ORCPT + 99 others); Wed, 19 May 2021 10:16:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37616 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353994AbhESOPk (ORCPT ); Wed, 19 May 2021 10:15:40 -0400 Received: from mail-wr1-x42a.google.com (mail-wr1-x42a.google.com [IPv6:2a00:1450:4864:20::42a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 37232C061347; Wed, 19 May 2021 07:14:11 -0700 (PDT) Received: by mail-wr1-x42a.google.com with SMTP id v12so14199390wrq.6; Wed, 19 May 2021 07:14:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=i3e5Ax3mN/Y6yPJpYOCMTBCrnugW+yH6avkA8+dpTMg=; b=o0IMFRjUNXwCpOHk3pjSBZPz4dX7RtIs+Nbuov846dsGZ93uGA1REcYDEmAyWquxZx 6uoKNeCUigLeYsDZBvBwOajq6vLKsl57jSaHDitctlNZ6FYeAUdNFU3xUDJZ5uqNlq+9 GbiyxGeTgpyYriKH+0usuyUqnhEAt6nV1HS+hTxUYrCyMzUpzqQYOsHj3oHcV3Ic6TuR rTX/V1sI5kj26beypsIO4+IoSY65UwAJvm14yzNu1ngOcUY058VzCKMVFgpdS1NJHQf7 a/+oax78Nhpdj5SB2+b1BB/JictgIREppkWX+FPSVXinpDEv1FhN84VENlKibbmWh96X TgDw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=i3e5Ax3mN/Y6yPJpYOCMTBCrnugW+yH6avkA8+dpTMg=; b=LNunQli8heNAtCxfkf2C9WVHL08whV4qRgS0UlISEywM1H6w0Ef8KQNonVCcUyttxF dkR+DaEKC7mlUf2z/zD+UGn7Q9WZ9iDCeBbZPdcjR+zBaYb1LlH7TWa/R3p2a06+GXi1 RwUSsNCrsz0Ub3IQPiRUgBaJvGvkCBGCDhGt8TNrOX5qj5Giygr22eeFoieFyHDhGeCk poaPohRO0E6Vs9E74lmBOyMApjIA/flZvN5gj/uqoCeeX2pYSmnuHCfhQLpSX1Nqwpl+ awO5qpdlpEbyAybspDlCOOuEGparvJmr9Rqbdz66xyxbD/6N4f+HGDa0rYomov9wDkCP O/fQ== X-Gm-Message-State: AOAM532PQiTc+yP2KWTEwTsLeyQSdRlwGG+SsHjf0EfkA6hQpkCOYBpb bQByItyuXRd1P7bE64xdkpHbryOFh8PyAOG8 X-Received: by 2002:adf:fe07:: with SMTP id n7mr14908474wrr.388.1621433649552; Wed, 19 May 2021 07:14:09 -0700 (PDT) Received: from localhost.localdomain ([85.255.235.154]) by smtp.gmail.com with ESMTPSA id z3sm6233569wrq.42.2021.05.19.07.14.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 May 2021 07:14:09 -0700 (PDT) From: Pavel Begunkov To: io-uring@vger.kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Jens Axboe , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Horst Schirmeier , "Franz-B . Tuneke" , Christian Dietrich Subject: [PATCH 16/23] io_uring: enable bpf to submit CQEs Date: Wed, 19 May 2021 15:13:27 +0100 Message-Id: X-Mailer: git-send-email 2.31.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Signed-off-by: Pavel Begunkov --- fs/io_uring.c | 36 ++++++++++++++++++++++++++++++++++++ include/uapi/linux/bpf.h | 1 + 2 files changed, 37 insertions(+) diff --git a/fs/io_uring.c b/fs/io_uring.c index aae786291c57..464d630904e2 100644 --- a/fs/io_uring.c +++ b/fs/io_uring.c @@ -10371,6 +10371,29 @@ BPF_CALL_3(io_bpf_queue_sqe, struct io_bpf_ctx *, bpf_ctx, return !io_submit_sqe(ctx, req, sqe); } +BPF_CALL_5(io_bpf_emit_cqe, struct io_bpf_ctx *, bpf_ctx, + u32, cq_idx, + u64, user_data, + s32, res, + u32, flags) +{ + struct io_ring_ctx *ctx = bpf_ctx->ctx; + bool submitted; + + if (unlikely(cq_idx >= ctx->cq_nr)) + return -EINVAL; + + spin_lock_irq(&ctx->completion_lock); + submitted = io_cqring_fill_event(ctx, user_data, res, flags, cq_idx); + io_commit_cqring(ctx); + ctx->cq_extra++; + spin_unlock_irq(&ctx->completion_lock); + if (submitted) + io_cqring_ev_posted(ctx); + + return submitted ? 0 : -ENOMEM; +} + const struct bpf_func_proto io_bpf_queue_sqe_proto = { .func = io_bpf_queue_sqe, .gpl_only = false, @@ -10380,6 +10403,17 @@ const struct bpf_func_proto io_bpf_queue_sqe_proto = { .arg3_type = ARG_CONST_SIZE, }; +const struct bpf_func_proto io_bpf_emit_cqe_proto = { + .func = io_bpf_emit_cqe, + .gpl_only = false, + .ret_type = RET_INTEGER, + .arg1_type = ARG_PTR_TO_CTX, + .arg2_type = ARG_ANYTHING, + .arg3_type = ARG_ANYTHING, + .arg4_type = ARG_ANYTHING, + .arg5_type = ARG_ANYTHING, +}; + static const struct bpf_func_proto * io_bpf_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog) { @@ -10388,6 +10422,8 @@ io_bpf_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog) return prog->aux->sleepable ? &bpf_copy_from_user_proto : NULL; case BPF_FUNC_iouring_queue_sqe: return prog->aux->sleepable ? &io_bpf_queue_sqe_proto : NULL; + case BPF_FUNC_iouring_emit_cqe: + return &io_bpf_emit_cqe_proto; default: return bpf_base_func_proto(func_id); } diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h index cc268f749a7d..c6b023be7848 100644 --- a/include/uapi/linux/bpf.h +++ b/include/uapi/linux/bpf.h @@ -4083,6 +4083,7 @@ union bpf_attr { FN(sock_from_file), \ FN(check_mtu), \ FN(iouring_queue_sqe), \ + FN(iouring_emit_cqe), \ /* */ /* integer value in 'imm' field of BPF_CALL instruction selects which helper -- 2.31.1