From nobody Sun May 5 10:31:43 2024 Delivered-To: importer2@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+importer2=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1623233255; cv=none; d=zohomail.com; s=zohoarc; b=NzPurahulKDd4CQJYcoyLucmqtGb7XvUfGKmSzxvqDoFDhzQS0kV4g2a1LyukSmeWcNFtjqQKD10bFj55jkNpc+sfdpMlCb9lrCBvSP1xBHpgceZ2zhmG5TI3D5WKz+te5Pk/ipoWJJOxJ33q+17YQGxwVxzy563hQ4WMg90Zds= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1623233255; 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=N2qoJhkd1ibV/+npAxGgSwFH+b6GVorDK3xOm9OUY74IkHS2L7PmyT492abF/UaRUjWQEsoR+8qLtH3pgwkZ2ETN24siiTf8MBoZccMJXnZtKhksj3oZoLGRlkVWmJZs5VLN1BZCCd1ucspXWQJpMUjef5B/506EXm+Vde5ytq4= 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+importer2=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 16232332558915.804009529826544; Wed, 9 Jun 2021 03:07:35 -0700 (PDT) Received: from localhost ([::1]:51312 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lqv7W-0003Cj-Pq for importer2@patchew.org; Wed, 09 Jun 2021 06:07:34 -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+importer2=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+importer2=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 From nobody Sun May 5 10:31:43 2024 Delivered-To: importer2@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+importer2=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1623233254; cv=none; d=zohomail.com; s=zohoarc; b=K/bDc87YXqDcZqn02AsbC5VhgsXFeqNTTmwzccQ+/CIzmAFpRkyC7ptC7mqADUrIkzX5t8FloezIflk6N3EdInw5MK1KYHA1s9nUmpFnVfvF6I26y4D0pieFoQ6DWnR9oOlpfU4Z0dXeDB2+fpKBTqVGRTjC13L5Eb2Z7YpJRfc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1623233254; 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=VZcva1w0YsTCDAr5AsPAqXS01llpV02/KrLMUdw59do=; b=Z1P5/vH0O6tIxRwlhJGiajJJ/6EaJd2Dtl/EDbOm2S4qODPdsuA6pmPeS6mY036EbPxvMJrOGs+khCD8Tq869MhlUMfiM317c9UM1tORWWHyl0WkhDG38xkdxJ3quM1PUxJo7VU1HuZQPEagQWqBIQ6trCri8Lv+rkUyN+lRZKI= 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+importer2=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 1623233254848753.6259848572055; Wed, 9 Jun 2021 03:07:34 -0700 (PDT) Received: from localhost ([::1]:51250 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lqv7V-0003AU-Ls for importer2@patchew.org; Wed, 09 Jun 2021 06:07:33 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40902) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lqv5E-0000JE-CC for qemu-devel@nongnu.org; Wed, 09 Jun 2021 06:05:12 -0400 Received: from mail-lf1-x12d.google.com ([2a00:1450:4864:20::12d]:34582) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lqv5B-0006si-Jj for qemu-devel@nongnu.org; Wed, 09 Jun 2021 06:05:12 -0400 Received: by mail-lf1-x12d.google.com with SMTP id f30so37161412lfj.1 for ; Wed, 09 Jun 2021 03:05:09 -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.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Jun 2021 03:05:07 -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=VZcva1w0YsTCDAr5AsPAqXS01llpV02/KrLMUdw59do=; b=CRAWMytEarY4Q2Uc+mb1jp3lAQIbFP060ceWuOp8ZM8O1zUjglgjDBF9BXNRvqQTme X4JuawgxfXxTkcj00RSL+vgor9lGvqAQpSs3ORMadec+YgKH8wX5bQyrQSPzY/zafIsr tMvwF92vRXMacT7vPDr3FstuK+uaj2TgJOyecoKX0ANapQQm8EEMyRiLmjuakZjlJAPC JK06bOjuJyyNaqgiH+wWa8cIpqixa+l+Kh8ERNgtgF0AvgF0ZhGIA0tyvGNF1Q1SdNSr oG6ZTpl5OQnI6aqy8qq5i6IfI0DE75ZVou7lF6ZuMn9nqyuV2wIre7SC7ShQs+KbpTFt fAiQ== 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=VZcva1w0YsTCDAr5AsPAqXS01llpV02/KrLMUdw59do=; b=RKopUoBYpWBXjfR/uTV1EOMV7/1N+jI753bLsisd8E+DpcL1DxqrPBV/7R/vhahShi 0GLYxfZY/5S0lkHzth8oRotCEFt9XecJBKyJVMcfubhQR/4aHaXQjOXmSK3BX2jn1jkZ AmPShPowZfF5mMYIQ4MfXp3TEUPAYY+nhShOD2vepRDOg59VDR7cjaaDDtTY7MLaUlpk R7KUnToZofuf3/11x8DhHsJI+KXCr1Q9FccS0T0xqLxDNLA/Su68EsnD67yOL1wbpjYk 7l1OV83Op3G/rPeu97kXP2wMc1DkzQXizfbL+g11V4woj3gDs+b7+SBu4Hw7xiUTItX1 POqw== X-Gm-Message-State: AOAM530UUpbKLFvfiac2l9iiazbqy/d28HU2M2Z0n2UfAKDnZSgM3EtW f6252Qf5ekyR4zrIkMpAg9wjcQ== X-Google-Smtp-Source: ABdhPJyr1w5wog8cFfH4Bcc1ngwHRw019apf4s7yuhDwmx/ximlRsEemsXASGeoa69aVICso27sHlQ== X-Received: by 2002:a19:4096:: with SMTP id n144mr9013465lfa.433.1623233108091; Wed, 09 Jun 2021 03:05:08 -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 2/5] virtio-net: Added property to load eBPF RSS with fds. Date: Wed, 9 Jun 2021 13:04:54 +0300 Message-Id: <20210609100457.142570-3-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+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: none client-ip=2a00:1450:4864:20::12d; envelope-from=andrew@daynix.com; helo=mail-lf1-x12d.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+importer2=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 program and maps now may be passed during initialization. Initially was implemented for libvirt to launch qemu without permissions. Signed-off-by: Andrew Melnychenko --- hw/net/virtio-net.c | 77 ++++++++++++++++++++++++++++++++-- include/hw/virtio/virtio-net.h | 1 + 2 files changed, 74 insertions(+), 4 deletions(-) diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c index bd7958b9f0..0602b1772e 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -41,6 +41,7 @@ #include "sysemu/sysemu.h" #include "trace.h" #include "monitor/qdev.h" +#include "monitor/monitor.h" #include "hw/pci/pci.h" #include "net_rx_pkt.h" #include "hw/virtio/vhost.h" @@ -1223,14 +1224,81 @@ static void virtio_net_detach_epbf_rss(VirtIONet *n) virtio_net_attach_ebpf_to_backend(n->nic, -1); } =20 -static bool virtio_net_load_ebpf(VirtIONet *n) +static int virtio_net_get_ebpf_rss_fds(char *str, char *fds[], int nfds) { - if (!virtio_net_attach_ebpf_to_backend(n->nic, -1)) { - /* backend does't support steering ebpf */ + char *ptr =3D str; + char *cur =3D NULL; + size_t len =3D strlen(str); + int i =3D 0; + + for (; i < nfds && ptr < str + len;) { + cur =3D strchr(ptr, ':'); + + if (cur =3D=3D NULL) { + fds[i] =3D g_strdup(ptr); + } else { + fds[i] =3D g_strndup(ptr, cur - ptr); + } + + i++; + if (cur =3D=3D NULL) { + break; + } else { + ptr =3D cur + 1; + } + } + + return i; +} + +static bool virtio_net_load_ebpf_fds(VirtIONet *n) +{ + char *fds_strs[EBPF_RSS_MAX_FDS]; + int fds[EBPF_RSS_MAX_FDS]; + int nfds; + int ret =3D false; + Error *errp; + int i =3D 0; + + if (n =3D=3D NULL || !n->ebpf_rss_fds) { return false; } =20 - return ebpf_rss_load(&n->ebpf_rss); + nfds =3D virtio_net_get_ebpf_rss_fds(n->ebpf_rss_fds, + fds_strs, EBPF_RSS_MAX_FDS); + for (i =3D 0; i < nfds; i++) { + fds[i] =3D monitor_fd_param(monitor_cur(), fds_strs[i], &errp); + } + + if (nfds =3D=3D EBPF_RSS_MAX_FDS) { + ret =3D ebpf_rss_load_fds(&n->ebpf_rss, fds[0], fds[1], fds[2], fd= s[3]); + } + + if (!ret) { + for (i =3D 0; i < nfds; i++) { + close(fds[i]); + } + } + + for (i =3D 0; i < nfds; i++) { + g_free(fds_strs[i]); + } + + return ret; +} + +static bool virtio_net_load_ebpf(VirtIONet *n) +{ + bool ret =3D true; + + if (virtio_net_attach_ebpf_to_backend(n->nic, -1)) { + if (!(n->ebpf_rss_fds + && virtio_net_load_ebpf_fds(n))) { + ret =3D ebpf_rss_load(&n->ebpf_rss); + } + } + + return ret; } =20 static void virtio_net_unload_ebpf(VirtIONet *n) @@ -3605,6 +3673,7 @@ static Property virtio_net_properties[] =3D { VIRTIO_NET_F_RSS, false), DEFINE_PROP_BIT64("hash", VirtIONet, host_features, VIRTIO_NET_F_HASH_REPORT, false), + DEFINE_PROP_STRING("ebpf_rss_fds", VirtIONet, ebpf_rss_fds), DEFINE_PROP_BIT64("guest_rsc_ext", VirtIONet, host_features, VIRTIO_NET_F_RSC_EXT, false), DEFINE_PROP_UINT32("rsc_interval", VirtIONet, rsc_timeout, diff --git a/include/hw/virtio/virtio-net.h b/include/hw/virtio/virtio-net.h index 824a69c23f..993f2f3036 100644 --- a/include/hw/virtio/virtio-net.h +++ b/include/hw/virtio/virtio-net.h @@ -213,6 +213,7 @@ struct VirtIONet { VirtioNetRssData rss_data; struct NetRxPkt *rx_pkt; struct EBPFRSSContext ebpf_rss; + char *ebpf_rss_fds; }; =20 void virtio_net_set_netclient_name(VirtIONet *n, const char *name, --=20 2.31.1 From nobody Sun May 5 10:31:43 2024 Delivered-To: importer2@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+importer2=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1623233256; cv=none; d=zohomail.com; s=zohoarc; b=msZlcotH16m8ZkQYcVshXS/WpOU45ulHDuHGp/C6UFvYR36obGln1tAHkJej69aMxHKH7ITjA+3iaqAV9+9fqXbRmfBnVprxCfTh3vCgyCyy6Nzia2MZT3bc4kHc0Mz2ujPD61iux09Fsp+We+BfkDqsVbJc4OWB5EBaQOxF+Rc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1623233256; 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=zDjdmfF5W2tPz/BdMjDQWwRdeLRUFtNW7LLUnye9n/s=; b=T3t2wVuGGJtHN9vs7bgOazFjbioWFCs4LGinIewtIB6dbLlv80OPSI39BoVBBabImj9cpVm5G2D30U+Hg9UbHKVEwguQq4YgmwDo4tKtlarTW+5dZygGHa9Bxc5hUbnW7kc+B31zNyCdi+UsBktIU0/DVeUJGVh6oSnZhtxSi6A= 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+importer2=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 1623233256626408.8394718228526; Wed, 9 Jun 2021 03:07:36 -0700 (PDT) Received: from localhost ([::1]:51374 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lqv7X-0003FX-JY for importer2@patchew.org; Wed, 09 Jun 2021 06:07:35 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40916) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lqv5G-0000Lw-FV for qemu-devel@nongnu.org; Wed, 09 Jun 2021 06:05:14 -0400 Received: from mail-lf1-x12c.google.com ([2a00:1450:4864:20::12c]:41746) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lqv5D-0006tM-8L for qemu-devel@nongnu.org; Wed, 09 Jun 2021 06:05:14 -0400 Received: by mail-lf1-x12c.google.com with SMTP id j20so7812097lfe.8 for ; Wed, 09 Jun 2021 03:05:10 -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.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Jun 2021 03:05:08 -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=zDjdmfF5W2tPz/BdMjDQWwRdeLRUFtNW7LLUnye9n/s=; b=SU1sSngvAC17c6KusTyJXkfrccBkxleILzVV7lds4iDftKbTpCkQohTtsMqjS0ZHlP 5cyVwWBKCeRK73yjb63uJGPhaOzIeiqLDnH+ojc+hN1vFZHMC2lBKMObBPHxpITrW0uE lubpCvTYhf4ZSBa3v345cqrqcbu+cCpnrVdbnJIyBTzqrtmqxXDRoXYWpUjFjVSMHGQ+ TUXmAFk0FjsGN+5MEQFuRn4/I5c0TeYaghRpUYYEryNNsK1HgSYuOPcwObUgm/Q2dNTN JymX9X9OV+00Ux5vSX9y4OlQHRhY2Ef9BhhkVANH8eL7/tP4qWu2RNIoixFObrCMIjp9 BqNQ== 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=zDjdmfF5W2tPz/BdMjDQWwRdeLRUFtNW7LLUnye9n/s=; b=YokJZwKOwpqSjM1aM/IrRJLrb+Tcp3lO2OgXLKCjbKlYxVLHzEOQifCI4wcAMUi1mB p7FdA1AwWuZcVwJeehRf0BwFCT1Jb5C+3j8kHP36WwpoRfdPVGC/5a6erfbttrenRxHI YbFcRdwhRvOe4gGEgqhhh0GylAlLdUXY/ExmSV+S1LK8IPkxFbGC7dNluLWvERRcTggW KPLpBM9lcn4ZllaUN/WfSSnHhXCJwIn44HQudYjUJ6sKj/ZK9YSdekLQ20zNx8V+M31E BHeUWqdM8t+BOyKAedo8Rs4aASyWabPDVRmtQcHZ1IKQpvSmGUf6KRs1AKMpIlaP0zuO okYA== X-Gm-Message-State: AOAM531AGUJ+MOcCrPVDgbM1V63LE8J+JM/ehg6nwNJKL1Og53r4x3PO 15J2MtjHwe6FlNHB7tHsRPnefA== X-Google-Smtp-Source: ABdhPJyxSBJPJ5B8vgm/AHMlKszteU+SP8CJUtec49W/iWGjA89DP/et5rhXDOQJmnvZgQV7I9bZtg== X-Received: by 2002:a05:6512:507:: with SMTP id o7mr2795921lfb.453.1623233109030; Wed, 09 Jun 2021 03:05:09 -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 3/5] ebpf_rss_helper: Added helper for eBPF RSS. Date: Wed, 9 Jun 2021 13:04:55 +0300 Message-Id: <20210609100457.142570-4-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+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: none client-ip=2a00:1450:4864:20::12c; envelope-from=andrew@daynix.com; helo=mail-lf1-x12c.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+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Helper program. Loads eBPF RSS program and maps and passes them through uni= x socket. Libvirt may launch this helper and pass eBPF fds to qemu virtio-net. Signed-off-by: Andrew Melnychenko --- ebpf/qemu-ebpf-rss-helper.c | 130 ++++++++++++++++++++++++++++++++++++ meson.build | 8 +++ 2 files changed, 138 insertions(+) create mode 100644 ebpf/qemu-ebpf-rss-helper.c diff --git a/ebpf/qemu-ebpf-rss-helper.c b/ebpf/qemu-ebpf-rss-helper.c new file mode 100644 index 0000000000..f0379dddf2 --- /dev/null +++ b/ebpf/qemu-ebpf-rss-helper.c @@ -0,0 +1,130 @@ +/* + * eBPF RSS Helper + * + * Developed by Daynix Computing LTD (http://www.daynix.com) + * + * Authors: + * Andrew Melnychenko + * + * This work is licensed under the terms of the GNU GPL, version 2. See + * the COPYING file in the top-level directory. + * + * Description: This is helper program for libvirtd. + * It loads eBPF RSS program and passes fds through unix sock= et. + * Built by meson, target - 'qemu-ebpf-rss-helper'. + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "ebpf_rss.h" + +static int send_fds(int socket, int *fds, int n) +{ + struct msghdr msg =3D {}; + struct cmsghdr *cmsg =3D NULL; + char buf[CMSG_SPACE(n * sizeof(int))]; + char dummy_buffer =3D 0; + struct iovec io =3D { .iov_base =3D &dummy_buffer, + .iov_len =3D sizeof(dummy_buffer) }; + + memset(buf, 0, sizeof(buf)); + + msg.msg_iov =3D &io; + msg.msg_iovlen =3D 1; + msg.msg_control =3D buf; + msg.msg_controllen =3D sizeof(buf); + + cmsg =3D CMSG_FIRSTHDR(&msg); + cmsg->cmsg_level =3D SOL_SOCKET; + cmsg->cmsg_type =3D SCM_RIGHTS; + cmsg->cmsg_len =3D CMSG_LEN(n * sizeof(int)); + + memcpy(CMSG_DATA(cmsg), fds, n * sizeof(int)); + + return sendmsg(socket, &msg, 0); +} + +static void print_help_and_exit(const char *prog, int exitcode) +{ + fprintf(stderr, "%s - load eBPF RSS program for qemu and pass eBPF fds" + " through unix socket.\n", prog); + fprintf(stderr, "\t--fd , -f - unix socket file descriptor" + " used to pass eBPF fds.\n"); + fprintf(stderr, "\t--help, -h - this help.\n"); + exit(exitcode); +} + +int main(int argc, char **argv) +{ + char *fd_string =3D NULL; + int unix_fd =3D 0; + struct EBPFRSSContext ctx =3D {}; + int fds[EBPF_RSS_MAX_FDS] =3D {}; + int ret =3D -1; + + for (;;) { + int c; + static struct option long_options[] =3D { + {"help", no_argument, 0, 'h'}, + {"fd", required_argument, 0, 'f'}, + {0, 0, 0, 0} + }; + c =3D getopt_long(argc, argv, "hf:", + long_options, NULL); + + if (c =3D=3D -1) { + break; + } + + switch (c) { + case 'f': + fd_string =3D optarg; + break; + case 'h': + default: + print_help_and_exit(argv[0], + c =3D=3D 'h' ? EXIT_SUCCESS : EXIT_FAILURE); + } + } + + if (!fd_string) { + fprintf(stderr, "Unix file descriptor not present.\n"); + print_help_and_exit(argv[0], EXIT_FAILURE); + } + + fprintf(stderr, "FD %s\n", fd_string); + + unix_fd =3D atoi(fd_string); + + if (!unix_fd) { + fprintf(stderr, "Unix file descriptor is invalid.\n"); + return EXIT_FAILURE; + } + + ebpf_rss_init(&ctx); + if (!ebpf_rss_load(&ctx)) { + fprintf(stderr, "Can't load ebpf.\n"); + return EXIT_FAILURE; + } + fds[0] =3D ctx.program_fd; + fds[1] =3D ctx.map_configuration; + fds[2] =3D ctx.map_toeplitz_key; + fds[3] =3D ctx.map_indirections_table; + + ret =3D send_fds(unix_fd, fds, EBPF_RSS_MAX_FDS); + if (ret < 0) { + fprintf(stderr, "Issue while sending fds: %s.\n", strerror(errno)); + } + + ebpf_rss_unload(&ctx); + + return ret < 0 ? EXIT_FAILURE : EXIT_SUCCESS; +} + diff --git a/meson.build b/meson.build index 626cf932c1..ce26bddead 100644 --- a/meson.build +++ b/meson.build @@ -2413,6 +2413,14 @@ if have_tools dependencies: [authz, crypto, io, qom, qemuutil, libcap_ng, mpathpersist], install: true) + + if libbpf.found() + executable('qemu-ebpf-rss-helper', files( + 'ebpf/qemu-ebpf-rss-helper.c', 'ebpf/ebpf_rss.c'), + dependencies: [qemuutil, libbpf, glib], + install: true, + install_dir: get_option('libexecdir')) + endif endif =20 if 'CONFIG_IVSHMEM' in config_host --=20 2.31.1 From nobody Sun May 5 10:31:43 2024 Delivered-To: importer2@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+importer2=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1623233357; cv=none; d=zohomail.com; s=zohoarc; b=PHjoAEY+SfXdc8TaHpKB7uSme8YTkUKMCI/1b4AQedfA7VU3P4V/474vakGniWCYbjFI7Si0jKcenBhNRDRIF17CWuo/66CfHbIRzwfZKfh+Nfb/pWlyXOx4BSYGeChYN6mhbYTOz7rfbmOjbLu/3xF183dlNNNJzmbULsgseDk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1623233357; 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=LJT8VRcYS9KQvYEHyPuMGZ6CdJ8/1KVNk860uBev24k=; b=F/E+4+h62EJCgUjdzgqrCYdJebrtCGwgIhkai4/e3Hnw6G8HP2dUKFv22yNQdzTFmak7BHdlR2F2aTyO8Q+vkTW8PRVmFlLSTcdNLzSe0EmxWAe2n1aGvixOB2UJvzVrxvHUpUzpCtvB0mgqnZuqlPrN95NUZVKj5OsU/+fSiSA= 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+importer2=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 1623233357696439.98352192420316; Wed, 9 Jun 2021 03:09:17 -0700 (PDT) Received: from localhost ([::1]:58876 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lqv9A-0008CC-Ky for importer2@patchew.org; Wed, 09 Jun 2021 06:09:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40914) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lqv5F-0000Ld-VN for qemu-devel@nongnu.org; Wed, 09 Jun 2021 06:05:14 -0400 Received: from mail-lf1-x136.google.com ([2a00:1450:4864:20::136]:42516) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lqv5D-0006u1-D1 for qemu-devel@nongnu.org; Wed, 09 Jun 2021 06:05:13 -0400 Received: by mail-lf1-x136.google.com with SMTP id j2so9514817lfg.9 for ; Wed, 09 Jun 2021 03:05:11 -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.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Jun 2021 03:05:09 -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=LJT8VRcYS9KQvYEHyPuMGZ6CdJ8/1KVNk860uBev24k=; b=aYM4U0G9T8mAIk0wN0tft19NRcvVqAseUYSetFcbdzwjVLlSBz+IOLTGwQfdLYMEpR V/3RVeS6iMu8ltBCRRKW1D8cUXWPwQKMPnLfKn6Y4AvR5KZF79/EbfXm0g9FgGBiV8n4 Hu0u//ifNVk1UQzW1RLuQEd6n2dn391s8aL70KaEgbsLiM/yg15wf7JdxJ+4F1o4FInB SvEg+1hm4EtlxXa4hLWwPyGRbhweGvMcI6vnjhcTgzkJ9YTZTkWfr72Nlkhn9IGcnl/5 QItxDzAM6XVH/6Wu3IQDnSBRQZKCJNyfKL3n4sHHbjBz1QTlumw01NOhWR9Q13D2/sbS 6aGg== 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=LJT8VRcYS9KQvYEHyPuMGZ6CdJ8/1KVNk860uBev24k=; b=eG65HnCds00kGuo5lAIxqbmtS1YFNmIsEA2m2BP+PB5jgL2vjmaFLyl8T2AbrF2TOL st4iJA8QfjLPxWopLcAkZNFuuWv7SdD/9aGgZkEClAOyLX084O2tYefg/FatbmjL33wX EA3VatDuLcJ3e5zoDrP7jasu0Zj/egWY+ZQO/1p0BtWwAA2jKjG36bHBhnsFkxg57qT8 BaljObynrPFWo473JVjWNiJXkUwRDEIGopHI1h4ctlY8IGChOUFrfp4GHY83cfezzzbW Dvh59ARD4uqj81Pr/s4QZSb6TkZD+0iEBJI6ByCdUWJ/CSqwm+/EBRJfGjr9a6YT0TGA bNZQ== X-Gm-Message-State: AOAM530h8Z/a1eygWoPVJqqRAbaxOBfWxoW2elU1kgZXpL4lOFpK9M4k VdFDOj/jZ0xkdamWK68K7OA2Ag== X-Google-Smtp-Source: ABdhPJx2BRtcSTGZY6L1/smatg5BqZal0KzSb9ev84fZ3LlwVwUo88wXxmyVL6tZPDLgKH14OjXApQ== X-Received: by 2002:a05:6512:1c3:: with SMTP id f3mr18747601lfp.79.1623233109971; Wed, 09 Jun 2021 03:05:09 -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 4/5] qmp: Added qemu-ebpf-rss-path command. Date: Wed, 9 Jun 2021 13:04:56 +0300 Message-Id: <20210609100457.142570-5-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+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: none client-ip=2a00:1450:4864:20::136; envelope-from=andrew@daynix.com; helo=mail-lf1-x136.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+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" New qmp command to query ebpf helper. It's crucial that qemu and helper are in sync and in touch. Technically helper should pass eBPF fds that qemu may accept. And different qemu's builds may have different eBPF programs and helpers. Qemu returns helper that should "fit" to virtio-net. Signed-off-by: Andrew Melnychenko --- monitor/qmp-cmds.c | 78 ++++++++++++++++++++++++++++++++++++++++++++++ qapi/misc.json | 29 +++++++++++++++++ 2 files changed, 107 insertions(+) diff --git a/monitor/qmp-cmds.c b/monitor/qmp-cmds.c index f7d64a6457..5dd2a58ea2 100644 --- a/monitor/qmp-cmds.c +++ b/monitor/qmp-cmds.c @@ -351,3 +351,81 @@ void qmp_display_reload(DisplayReloadOptions *arg, Err= or **errp) abort(); } } + +#ifdef CONFIG_LINUX + +static const char *get_dirname(char *path) +{ + char *sep; + + sep =3D strrchr(path, '/'); + if (sep =3D=3D path) { + return "/"; + } else if (sep) { + *sep =3D 0; + return path; + } + return "."; +} + +static char *find_helper(const char *name) +{ + char qemu_exec[PATH_MAX]; + const char *qemu_dir =3D NULL; + char *helper =3D NULL; + + if (name =3D=3D NULL) { + return NULL; + } + + if (readlink("/proc/self/exe", qemu_exec, PATH_MAX) > 0) { + qemu_dir =3D get_dirname(qemu_exec); + + helper =3D g_strdup_printf("%s/%s", qemu_dir, name); + if (access(helper, F_OK) =3D=3D 0) { + return helper; + } + g_free(helper); + } + + helper =3D g_strdup_printf("%s/%s", CONFIG_QEMU_HELPERDIR, name); + if (access(helper, F_OK) =3D=3D 0) { + return helper; + } + g_free(helper); + + return NULL; +} + +HelperPathList *qmp_query_helper_paths(Error **errp) +{ + HelperPathList *ret =3D NULL; + const char *helpers_list[] =3D { +#ifdef CONFIG_EBPF + "qemu-ebpf-rss-helper", +#endif + NULL + }; + const char **helper_iter =3D helpers_list; + + for (; *helper_iter !=3D NULL; ++helper_iter) { + char *path =3D find_helper(*helper_iter); + if (path) { + HelperPath *helper =3D g_new0(HelperPath, 1); + helper->name =3D g_strdup(*helper_iter); + helper->path =3D path; + + QAPI_LIST_PREPEND(ret, helper); + } + } + + return ret; +} +#else + +HelperPathList *qmp_query_helper_paths(Error **errp) +{ + return NULL; +} + +#endif diff --git a/qapi/misc.json b/qapi/misc.json index 156f98203e..023bd2120d 100644 --- a/qapi/misc.json +++ b/qapi/misc.json @@ -519,3 +519,32 @@ 'data': { '*option': 'str' }, 'returns': ['CommandLineOptionInfo'], 'allow-preconfig': true } + +## +# @HelperPath: +# +# Name of the helper and binary location. +## +{ 'struct': 'HelperPath', + 'data': {'name': 'str', 'path': 'str'} } + +## +# @query-helper-paths: +# +# Query specific eBPF RSS helper for current qemu binary. +# +# Returns: list of object that contains name and path for helper. +# +# Example: +# +# -> { "execute": "query-helper-paths" } +# <- { "return": [ +# { +# "name": "qemu-ebpf-rss-helper", +# "path": "/usr/local/libexec/qemu-ebpf-rss-helper" +# } +# ] +# } +# +## +{ 'command': 'query-helper-paths', 'returns': ['HelperPath'] } --=20 2.31.1 From nobody Sun May 5 10:31:43 2024 Delivered-To: importer2@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+importer2=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1623233359; cv=none; d=zohomail.com; s=zohoarc; b=IAf9TXuyCDMyQGDXO5XTD4ad7J2p1K5hKyYrcjDST/0xC0X2Q6YGhS/xcFU4eEwaSQOVsUytvJDaKnNKHdg5RCdRNj/oTJ/2T5TjGfcquCagcFImsg6fUJ7Qmz2TpAFaUqMGfJi62q6x27v8SEzhx8ORKPTvsN90P4HteHO+Z0w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1623233359; 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=9MSBl1qwvm6PBKVcWEziC8/TNLeqsJud3KoYE2xPGRI=; b=RhMKZi9H5zur8S0kQqk6UvbK6qar6uCtjgGoeAqwpn+GANbQzKqCmlyDC2c+tWzUIg+XrzU6wLzUVaQUdSTyfwqJsNCjsNLcK8QqMa0QqgEKcRVUocjAGAD6YIpRoIf3Q2HmdfLgx6NMGlFhETU3Nj0IP04w3zZB1q7sxX+V2EA= 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+importer2=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 162323335911761.865142747341224; Wed, 9 Jun 2021 03:09:19 -0700 (PDT) Received: from localhost ([::1]:58968 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lqv9B-0008G9-SO for importer2@patchew.org; Wed, 09 Jun 2021 06:09:17 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40918) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lqv5H-0000O8-By for qemu-devel@nongnu.org; Wed, 09 Jun 2021 06:05:15 -0400 Received: from mail-lf1-x133.google.com ([2a00:1450:4864:20::133]:44746) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lqv5E-0006u9-A1 for qemu-devel@nongnu.org; Wed, 09 Jun 2021 06:05:15 -0400 Received: by mail-lf1-x133.google.com with SMTP id r198so33785666lff.11 for ; Wed, 09 Jun 2021 03:05:11 -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.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Jun 2021 03:05:10 -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=9MSBl1qwvm6PBKVcWEziC8/TNLeqsJud3KoYE2xPGRI=; b=dsGPg8nwx1fpwwj+0nX5kZPn3GNDqlmnqrar8rbYjEHycTT/IpOQSZGHkCTCk/OyLR rWeQcOiIl5Fwaw8rwKxXF89uLUBrpWmuuETw/4m2m5wVVWp3xpXUTjl86uCWiIRGFZ0H uulUyLbafEbjkkdIT+LLDkn22rGY+dF5BOOMkR74vc1WIJNDVfLF+Nc9rkkOGU6UuCTr Urb1ehvAGATlSoj2Got6Rf2uqwjMR9vdKsaTImFXIxZQQBevI2AnbrjyzFFyCKJGY2Qq e3vGVRG4PG+Ffr3OlaY8o6zrJMTInqASqHsVyM+FUIAcqyvGBhf/igiOz2XIYafxwhDj H76w== 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=9MSBl1qwvm6PBKVcWEziC8/TNLeqsJud3KoYE2xPGRI=; b=ZeQqhD5C8Ee1oHa3iXmsMh656ncWU0H/HIZaRa6pV4SgjXgrQwcHYc6UCH5Zf/Q+nd O/06QSK8ATQnADranDYZsILixmyZEmpSDI1wMDewdNA1QdOLHccbVUtULqQLmaTXJQoQ nN9HBjQmQyrrDUGfdyMZc61y26d4eXlIWZaOV1vfEYNjhGauLU92LvxkraBkXo8mwjOQ ydKj6LyVCCLPfaFNPqMOsDOZnTXU3U5SUCbDaX9l/8xpjPzjS66zonvaStthyhmUdgyc bafzhlY7MFq1T+7+gv/iY4Na5tlUiBdUJFD2SdFyicyuNfsw2FfHobDXe6uTu3F1+iyV QBUA== X-Gm-Message-State: AOAM530zAFOapwHYrtQqZat830DwOw82smqeReL3N0RRUonkTnPG0EnS oMOnYaHbASc5/g//a/uRJZ3TJA== X-Google-Smtp-Source: ABdhPJxzGbPwC2xqcBYPR1uqHvrZ4nsSZXPQvoQ+UczkJJ3J/gMuuepqv6mlc+v9AzCV8kCY1csiug== X-Received: by 2002:a05:6512:3c9f:: with SMTP id h31mr1877617lfv.51.1623233110914; Wed, 09 Jun 2021 03:05:10 -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 5/5] meson: libbpf dependency now exclusively for Linux. Date: Wed, 9 Jun 2021 13:04:57 +0300 Message-Id: <20210609100457.142570-6-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+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: none client-ip=2a00:1450:4864:20::133; envelope-from=andrew@daynix.com; helo=mail-lf1-x133.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+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Libbpf is used for eBPF RSS steering, which is supported only by Linux TAP. There is no reason yet to build eBPF loader and helper for non Linux systems, even if libbpf is present. Signed-off-by: Andrew Melnychenko --- meson.build | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/meson.build b/meson.build index ce26bddead..fa6c48fb86 100644 --- a/meson.build +++ b/meson.build @@ -1033,19 +1033,22 @@ if not get_option('fuse_lseek').disabled() endif =20 # libbpf -libbpf =3D dependency('libbpf', required: get_option('bpf'), method: 'pkg-= config') -if libbpf.found() and not cc.links(''' - #include - int main(void) - { - bpf_object__destroy_skeleton(NULL); - return 0; - }''', dependencies: libbpf) - libbpf =3D not_found - if get_option('bpf').enabled() - error('libbpf skeleton test failed') - else - warning('libbpf skeleton test failed, disabling') +libbpf =3D not_found +if targetos =3D=3D 'linux' + libbpf =3D dependency('libbpf', required: get_option('bpf'), method: 'pk= g-config') + if libbpf.found() and not cc.links(''' + #include + int main(void) + { + bpf_object__destroy_skeleton(NULL); + return 0; + }''', dependencies: libbpf) + libbpf =3D not_found + if get_option('bpf').enabled() + error('libbpf skeleton test failed') + else + warning('libbpf skeleton test failed, disabling') + endif endif endif =20 --=20 2.31.1