From nobody Tue Feb 10 04:17:25 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1623233245; cv=none; d=zohomail.com; s=zohoarc; b=Bvf7Pl6QGSo2TebM35zNIzagK4XwYZWefWvN0Mz581zuH3OCObZHsTUKhH459g+oG7p5ZhtinQnfK6P1Jc/fvGoMdSv0dqtIvL0GZ8V4v3Olhye9LwWBaY75roCmphaWccy4n26ND1H3EQh1cFjO14zTU3J7bzChtowk+7JHjno= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1623233245; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=n9qgRrfzY+Rmwjm0+r7ctkec2j7NmFWBk64rftF+Ejk=; b=RrF0a6rCpnM/52TcGiXiLneTZ7bzwZb6eLHLukTPiI2sqwHqezviNQ5tCTJdGWSIA93x28qgjY9eXEEz04ASWAnyqWNgZb5btrLJCb3vFDuN9GiWfR2pxByy4brUysYb9dAMVnlZoXCk+ReKkiV3cy6Y2Eaj/sjTecO84kAoLdE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1623233245595722.6986002984545; Wed, 9 Jun 2021 03:07:25 -0700 (PDT) Received: from localhost ([::1]:51312 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lqv7M-0003Cj-F8 for importer@patchew.org; Wed, 09 Jun 2021 06:07:24 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40880) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lqv5D-0000Iy-Dk for qemu-devel@nongnu.org; Wed, 09 Jun 2021 06:05:12 -0400 Received: from mail-lf1-x12f.google.com ([2a00:1450:4864:20::12f]:43753) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lqv5A-0006s3-Nb for qemu-devel@nongnu.org; Wed, 09 Jun 2021 06:05:10 -0400 Received: by mail-lf1-x12f.google.com with SMTP id n12so30116337lft.10 for ; Wed, 09 Jun 2021 03:05:08 -0700 (PDT) Received: from navi.cosmonova.net.ua ([95.67.24.131]) by smtp.gmail.com with ESMTPSA id l12sm333590lfk.10.2021.06.09.03.05.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Jun 2021 03:05:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=n9qgRrfzY+Rmwjm0+r7ctkec2j7NmFWBk64rftF+Ejk=; b=u7yxdxKOmFxiNG9ETcM/9VqPwj6JzXxUJYXOUuPtcni13S6n4gLaLZZEOjkoKZKh31 5ncefg5+ONTT5aC+x9Ixc3nmVnVlG0fBprUQllJsAm9IAVcCqLY4GNGPk+U+iIhYz0Xt FFcGCsbFaXSfV2qU1YMFaQ4yzIJ0bpmMmrDYi5WXeq5I7lUnSKFv97rK+HH/N0Qx2GOf TZv+htwBYJFHW6ghMvNVeC1D9e4iN6YXWexVi0lMaULVRlvD7f5PTvUG7YSnKn6U2lWP Ns2pjVn4MTbE5KaDTn+QW7uathGc5D9Nnw+HUge5K0JiuD8XnTIyTf5kkOjhFpAiw1qS prdA== 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=n9qgRrfzY+Rmwjm0+r7ctkec2j7NmFWBk64rftF+Ejk=; b=mcnPJUzmVyBW16aR0u/168p+Zvku/Wfp7401V8aX3WHYQZIe4pxnyISlWhN/wOQhj5 caLaJeQEfkGs0PfQSN97ERBeLdgYOnuZUzLdXLeFU7b4U6dhFmAQ6XvwPpcFkKJ0rCYJ v1Px7/ZK65Kq+sX2iZ9EOw5k020IF5O9Wh/8/SVlIjHZebncaaE6INNJFpoSZHlY13uk 0ZDK4D2qQmKI2melC1h7VnVhpLf5/h6E2P+7tMH3FLVOia1NUKHGZQ4Rt1DJcpMlWuVJ N8piDnu2KMzB9DTUREmop4kieFkxMPpT1WprvzMSRYCFYUJTAV+uBN90yG0nL2d5vs7C Y9uw== X-Gm-Message-State: AOAM532PLy5RPGfTz0L+jzeYhhQWpVhWdwPj7yFa9SKHnkvXTa6tpD+H WdW0gG/rnbU9F4oWLjBHjeC0aw== X-Google-Smtp-Source: ABdhPJxaHGHZ+W6R1Kr8MBAhj9hAx6YG79blEQUIzF1fPWA5zyHtcY4bR5Pn2qbo1DQPZTQGzv34dg== X-Received: by 2002:ac2:443b:: with SMTP id w27mr19768054lfl.295.1623233107143; Wed, 09 Jun 2021 03:05:07 -0700 (PDT) From: Andrew Melnychenko To: mst@redhat.com, yuri.benditovich@daynix.com, jasowang@redhat.com, armbru@redhat.com, eblake@redhat.com, berrange@redhat.com Subject: [RFC PATCH 1/5] ebpf: Added eBPF initialization by fds. Date: Wed, 9 Jun 2021 13:04:53 +0300 Message-Id: <20210609100457.142570-2-andrew@daynix.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210609100457.142570-1-andrew@daynix.com> References: <20210609100457.142570-1-andrew@daynix.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: none client-ip=2a00:1450:4864:20::12f; envelope-from=andrew@daynix.com; helo=mail-lf1-x12f.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: yan@daynix.com, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" eBPF RSS context may be initialized by program fd and map fds. virtio-net may provide fds passed by libvirt. Signed-off-by: Andrew Melnychenko --- ebpf/ebpf_rss-stub.c | 6 ++++++ ebpf/ebpf_rss.c | 31 ++++++++++++++++++++++++++++--- ebpf/ebpf_rss.h | 5 +++++ 3 files changed, 39 insertions(+), 3 deletions(-) diff --git a/ebpf/ebpf_rss-stub.c b/ebpf/ebpf_rss-stub.c index e71e229190..8d7fae2ad9 100644 --- a/ebpf/ebpf_rss-stub.c +++ b/ebpf/ebpf_rss-stub.c @@ -28,6 +28,12 @@ bool ebpf_rss_load(struct EBPFRSSContext *ctx) return false; } =20 +bool ebpf_rss_load_fds(struct EBPFRSSContext *ctx, int program_fd, + int config_fd, int toeplitz_fd, int table_fd) +{ + return false; +} + bool ebpf_rss_set_all(struct EBPFRSSContext *ctx, struct EBPFRSSConfig *co= nfig, uint16_t *indirections_table, uint8_t *toeplitz_key) { diff --git a/ebpf/ebpf_rss.c b/ebpf/ebpf_rss.c index 118c68da83..6e9b88efed 100644 --- a/ebpf/ebpf_rss.c +++ b/ebpf/ebpf_rss.c @@ -27,19 +27,20 @@ void ebpf_rss_init(struct EBPFRSSContext *ctx) { if (ctx !=3D NULL) { ctx->obj =3D NULL; + ctx->program_fd =3D -1; } } =20 bool ebpf_rss_is_loaded(struct EBPFRSSContext *ctx) { - return ctx !=3D NULL && ctx->obj !=3D NULL; + return ctx !=3D NULL && (ctx->obj !=3D NULL || ctx->program_fd !=3D -1= ); } =20 bool ebpf_rss_load(struct EBPFRSSContext *ctx) { struct rss_bpf *rss_bpf_ctx; =20 - if (ctx =3D=3D NULL) { + if (ctx =3D=3D NULL || ebpf_rss_is_loaded(ctx)) { return false; } =20 @@ -70,10 +71,26 @@ bool ebpf_rss_load(struct EBPFRSSContext *ctx) error: rss_bpf__destroy(rss_bpf_ctx); ctx->obj =3D NULL; + ctx->program_fd =3D -1; =20 return false; } =20 +bool ebpf_rss_load_fds(struct EBPFRSSContext *ctx, int program_fd, + int config_fd, int toeplitz_fd, int table_fd) +{ + if (ctx =3D=3D NULL || ebpf_rss_is_loaded(ctx)) { + return false; + } + + ctx->program_fd =3D program_fd; + ctx->map_configuration =3D config_fd; + ctx->map_toeplitz_key =3D toeplitz_fd; + ctx->map_indirections_table =3D table_fd; + + return true; +} + static bool ebpf_rss_set_config(struct EBPFRSSContext *ctx, struct EBPFRSSConfig *config) { @@ -160,6 +177,14 @@ void ebpf_rss_unload(struct EBPFRSSContext *ctx) return; } =20 - rss_bpf__destroy(ctx->obj); + if (ctx->obj !=3D NULL) { + rss_bpf__destroy(ctx->obj); + } else { + close(ctx->program_fd); + close(ctx->map_configuration); + close(ctx->map_toeplitz_key); + close(ctx->map_indirections_table); + } ctx->obj =3D NULL; + ctx->program_fd =3D -1; } diff --git a/ebpf/ebpf_rss.h b/ebpf/ebpf_rss.h index bf3f2572c7..363859c8bb 100644 --- a/ebpf/ebpf_rss.h +++ b/ebpf/ebpf_rss.h @@ -14,6 +14,8 @@ #ifndef QEMU_EBPF_RSS_H #define QEMU_EBPF_RSS_H =20 +#define EBPF_RSS_MAX_FDS 4 + struct EBPFRSSContext { void *obj; int program_fd; @@ -36,6 +38,9 @@ bool ebpf_rss_is_loaded(struct EBPFRSSContext *ctx); =20 bool ebpf_rss_load(struct EBPFRSSContext *ctx); =20 +bool ebpf_rss_load_fds(struct EBPFRSSContext *ctx, int program_fd, + int config_fd, int toeplitz_fd, int table_fd); + bool ebpf_rss_set_all(struct EBPFRSSContext *ctx, struct EBPFRSSConfig *co= nfig, uint16_t *indirections_table, uint8_t *toeplitz_key); =20 --=20 2.31.1