Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp1751705pxj; Wed, 19 May 2021 13:05:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJygUtQNF0CnSSur7b18flxlA5xbDtstAcfabfDRa0teIcgwdalcf96bNqaz4wxOCYtGKJ08 X-Received: by 2002:a05:6402:944:: with SMTP id h4mr777481edz.319.1621454713666; Wed, 19 May 2021 13:05:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621454713; cv=none; d=google.com; s=arc-20160816; b=qotPOtqejYSkMxRA5vYkrz/p/VXWQd2XGdVzcwGtw5n3p2GsRYl3FiYBazclz1x7x8 kllUfw/IRpJI/8+LA5BypVZ7hbarDxlP3h6/esEq4QRSM/C7gnepxJ9n8v8zzwrC6lpl k+H8pm0MGlqR3BXuHA1y0TZmwz/6rWCBR5311r9R4OPxtorbGtzzz2lH29GRZ495wFWs LRbovlX3QcTi0u3OWs+jIq3J494thUGPQErPPPk1V2eVP30jUJhs27f0dufDoqth6lGD HmFRgA7GT4pI405RZMjzReobzxFQdSFUv6IpTQTZgw5nADPHdOcFXjy/z7Q1BtvUT+3f Rngg== 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=ZrpYaaroywU12UggXTRtJF/Lf0MpETwhcC/rLkqy6po=; b=ZZ1YV2LDWTJ/eFRRfCXq89D0QFVvahzTiEOxm98wZI9nT5B9Tr7ELx72PVyv3eRFpM fvw13K30DaUCaQyTWiVK0q0LNOFznc206SihkdfrHwQ0Ho7FI4pWxg8VOjU9mR15DVnm Xyl1MXGvNUjkqFCz+KPvuE2OcNLy1w54B9HMXWF4jXUW/D3JpRNRMUd+1ZCoRmFMqrGX 5+zzLhevR8jNO8OQUoUyin+fMSSMpGa2736mdG50QUoumuY+aqvuvA4Z85lnJt6alRJO egDwBf/Tb3vxQEh3GeQrOaIQVtMRfZq73F9dtUX+j8mjpHR3aTJeeX89s9g4TxsbiXW2 7OSQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=pAge3JaR; 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 sb9si740712ejb.411.2021.05.19.13.04.49; Wed, 19 May 2021 13:05:13 -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=pAge3JaR; 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 S1354352AbhESORO (ORCPT + 99 others); Wed, 19 May 2021 10:17:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37738 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1354065AbhESOPx (ORCPT ); Wed, 19 May 2021 10:15:53 -0400 Received: from mail-wm1-x32c.google.com (mail-wm1-x32c.google.com [IPv6:2a00:1450:4864:20::32c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D32CBC061351; Wed, 19 May 2021 07:14:15 -0700 (PDT) Received: by mail-wm1-x32c.google.com with SMTP id l11-20020a05600c4f0bb029017a7cd488f5so783549wmq.0; Wed, 19 May 2021 07:14:15 -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=ZrpYaaroywU12UggXTRtJF/Lf0MpETwhcC/rLkqy6po=; b=pAge3JaRar4piwZpSbj0B4ogTM2jlF2q6tuIr1m1iKex512MiGr7a0TTq7MsoEXCl0 9bUUwqGenxeTKtoB+IXRfvCFNJXbGap+lg+wJxDGJndcKMNzSGFeiipvNz0AIGs46JqJ waG3Bs+9Z3BzmP81+Y8jVCS3dbJBKkzWr6txMxelooF0XuMsIejXUUiKVyP3LD/2df9H Oyypm1eqJ00LJEkHz+m5ipNqy+V1rkidx7ODcxtaui7RXpNrvqTIr5nEvqBQlr7Z0y++ NjYHwqAL1DCAs0Gx/eAoFjNWPE+J0BTU6M2P0pD6kKQ/P2bfXmoHdf5ESEnw6nAMEr/J c22g== 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=ZrpYaaroywU12UggXTRtJF/Lf0MpETwhcC/rLkqy6po=; b=SNSAV3cH4W4g2uh/escV7VfKommlsUeZyZLlJavEUWxtUkL/vq10zeu9zetWtIgZoH 6CtXH9wIfyldcHllTU9978AS4UwoohfbhY/IizdBAxO9hqTH57Mf9ER+F6CdFCr/Q18R 1SZHSa7Up5CeyGchJYVAeup5vqKCORP3geBRaK55P3PqKr/gPZ5xViSpDBfrxJEIbJcT KdrAkODd66CKWiZsNJ605AvLIh7V7HOLw0jiVHc/GdEBIqG3oLDq4yE9QUS6E/oZ54Ee DCZ4AdD26e2+cISu1D7yJU5MN+0s0Bb3SQdFgKJL8WXQTVHNwOTh8ChnByxK4prlZrLx th2A== X-Gm-Message-State: AOAM533wEbNks8GXLiCoILtuDsX3U+CbFM0dZzwGdqhA0GhqVbHqBD0j J1lzB1TCDmRvh8NTJV/XHKcOCS8jGqbTGNOG X-Received: by 2002:a1c:7702:: with SMTP id t2mr11730397wmi.115.1621433653562; Wed, 19 May 2021 07:14:13 -0700 (PDT) Received: from localhost.localdomain ([85.255.235.154]) by smtp.gmail.com with ESMTPSA id z3sm6233569wrq.42.2021.05.19.07.14.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 May 2021 07:14:13 -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 19/23] io_uring: pass user_data to bpf executor Date: Wed, 19 May 2021 15:13:30 +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 | 16 ++++++++++++++++ include/uapi/linux/io_uring.h | 4 ++++ 2 files changed, 20 insertions(+) diff --git a/fs/io_uring.c b/fs/io_uring.c index 7c165b2ce8e4..c37846bca863 100644 --- a/fs/io_uring.c +++ b/fs/io_uring.c @@ -882,6 +882,7 @@ struct io_defer_entry { }; struct io_bpf_ctx { + struct io_uring_bpf_ctx u; struct io_ring_ctx *ctx; }; @@ -10482,6 +10483,15 @@ static bool io_bpf_is_valid_access(int off, int size, const struct bpf_prog *prog, struct bpf_insn_access_aux *info) { + if (off < 0 || off >= sizeof(struct io_uring_bpf_ctx)) + return false; + if (off % size != 0) + return false; + + switch (off) { + case offsetof(struct io_uring_bpf_ctx, user_data): + return size == sizeof_field(struct io_uring_bpf_ctx, user_data); + } return false; } @@ -10505,6 +10515,8 @@ static void io_bpf_run(struct io_kiocb *req, unsigned int issue_flags) atomic_read(&req->task->io_uring->in_idle))) goto done; + memset(&bpf_ctx.u, 0, sizeof(bpf_ctx.u)); + bpf_ctx.u.user_data = req->user_data; bpf_ctx.ctx = ctx; prog = req->bpf.prog; @@ -10591,6 +10603,10 @@ static int __init io_uring_init(void) BUILD_BUG_SQE_ELEM(44, __s32, splice_fd_in); BUILD_BUG_SQE_ELEM(48, __u16, cq_idx); + /* should be first, see io_bpf_is_valid_access() */ + __BUILD_BUG_VERIFY_ELEMENT(struct io_bpf_ctx, 0, + struct io_uring_bpf_ctx, u); + BUILD_BUG_ON(sizeof(struct io_uring_files_update) != sizeof(struct io_uring_rsrc_update)); BUILD_BUG_ON(sizeof(struct io_uring_rsrc_update) > diff --git a/include/uapi/linux/io_uring.h b/include/uapi/linux/io_uring.h index 25ab804670e1..d7b1713bcfb0 100644 --- a/include/uapi/linux/io_uring.h +++ b/include/uapi/linux/io_uring.h @@ -403,4 +403,8 @@ struct io_uring_getevents_arg { __u64 ts; }; +struct io_uring_bpf_ctx { + __u64 user_data; +}; + #endif -- 2.31.1