From patchwork Tue Nov 8 05:05:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Lemon X-Patchwork-Id: 13035894 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A8C76C43217 for ; Tue, 8 Nov 2022 05:05:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232654AbiKHFFq convert rfc822-to-8bit (ORCPT ); Tue, 8 Nov 2022 00:05:46 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39018 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233103AbiKHFFl (ORCPT ); Tue, 8 Nov 2022 00:05:41 -0500 Received: from mx0b-00082601.pphosted.com (mx0b-00082601.pphosted.com [67.231.153.30]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6B9CF17AB9 for ; Mon, 7 Nov 2022 21:05:39 -0800 (PST) Received: from pps.filterd (m0109332.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 2A7LKmUo022482 for ; Mon, 7 Nov 2022 21:05:38 -0800 Received: from maileast.thefacebook.com ([163.114.130.3]) by mx0a-00082601.pphosted.com (PPS) with ESMTPS id 3kq6kk4yf3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Mon, 07 Nov 2022 21:05:38 -0800 Received: from twshared2001.03.ash8.facebook.com (2620:10d:c0a8:1b::d) by mail.thefacebook.com (2620:10d:c0a8:83::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Mon, 7 Nov 2022 21:05:37 -0800 Received: by devvm2494.atn0.facebook.com (Postfix, from userid 172786) id F335A23B26011; Mon, 7 Nov 2022 21:05:21 -0800 (PST) From: Jonathan Lemon To: CC: Subject: [PATCH v1 05/15] io_uring: mark pages in ifq region with zctap information. Date: Mon, 7 Nov 2022 21:05:11 -0800 Message-ID: <20221108050521.3198458-6-jonathan.lemon@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20221108050521.3198458-1-jonathan.lemon@gmail.com> References: <20221108050521.3198458-1-jonathan.lemon@gmail.com> MIME-Version: 1.0 X-FB-Internal: Safe X-Proofpoint-ORIG-GUID: Ct5t0uyShckbSY0wYhvTP4p0n6ROSynx X-Proofpoint-GUID: Ct5t0uyShckbSY0wYhvTP4p0n6ROSynx X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.219,Aquarius:18.0.895,Hydra:6.0.545,FMLib:17.11.122.1 definitions=2022-11-07_11,2022-11-07_02,2022-06-22_01 Precedence: bulk List-ID: X-Mailing-List: io-uring@vger.kernel.org The network stack passes up pages, which must be mapped to zctap device buffers in order to get the reference count and other items. Mark the page as private, and use the page_private field to record the lookup and ownership information. Signed-off-by: Jonathan Lemon --- io_uring/zctap.c | 61 ++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 56 insertions(+), 5 deletions(-) diff --git a/io_uring/zctap.c b/io_uring/zctap.c index 0705f5056d07..7426feee1e04 100644 --- a/io_uring/zctap.c +++ b/io_uring/zctap.c @@ -27,18 +27,68 @@ struct ifq_region { typedef int (*bpf_op_t)(struct net_device *dev, struct netdev_bpf *bpf); +static void zctap_set_page_info(struct page *page, u64 info) +{ + set_page_private(page, info); +} + +static u64 zctap_mk_page_info(u16 region_id, u16 pgid) +{ + return (u64)0xface << 48 | (u64)region_id << 16 | (u64)pgid; +} + static void io_remove_ifq_region(struct ifq_region *ifr) { + struct io_mapped_ubuf *imu; + struct page *page; + int i; + + imu = ifr->imu; + for (i = 0; i < ifr->nr_pages; i++) { + page = imu->bvec[i].bv_page; + + ClearPagePrivate(page); + set_page_private(page, 0); + } + kvfree(ifr); } +static int io_zctap_map_region(struct ifq_region *ifr) +{ + struct io_mapped_ubuf *imu; + struct page *page; + u64 info; + int i; + + imu = ifr->imu; + for (i = 0; i < ifr->nr_pages; i++) { + page = imu->bvec[i].bv_page; + if (PagePrivate(page)) + goto out; + SetPagePrivate(page); + info = zctap_mk_page_info(ifr->id, i); + zctap_set_page_info(page, info); + ifr->freelist[i] = page; + } + return 0; + +out: + while (i--) { + page = imu->bvec[i].bv_page; + ClearPagePrivate(page); + set_page_private(page, 0); + } + return -EEXIST; +} + int io_provide_ifq_region(struct io_zctap_ifq *ifq, u16 id) { struct io_ring_ctx *ctx = ifq->ctx; struct io_mapped_ubuf *imu; struct ifq_region *ifr; - int i, nr_pages; - struct page *page; + int nr_pages; + int err; /* XXX for now, only allow one region per ifq. */ if (ifq->region) @@ -63,9 +113,10 @@ int io_provide_ifq_region(struct io_zctap_ifq *ifq, u16 id) ifr->free_count = nr_pages; ifr->id = id; - for (i = 0; i < nr_pages; i++) { - page = imu->bvec[i].bv_page; - ifr->freelist[i] = page; + err = io_zctap_map_region(ifr); + if (err) { + kvfree(ifr); + return err; } ifq->region = ifr;