From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from atuin.qyliss.net (localhost [IPv6:::1]) by atuin.qyliss.net (Postfix) with ESMTP id DFF0124004; Sat, 27 Sep 2025 09:14:18 +0000 (UTC) Received: by atuin.qyliss.net (Postfix, from userid 993) id 2214123FD8; Sat, 27 Sep 2025 09:14:16 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on atuin.qyliss.net X-Spam-Level: X-Spam-Status: No, score=-0.1 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DMARC_PASS,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE autolearn=unavailable autolearn_force=no version=4.0.1 Received: from mail.cyberchaos.dev (mail.cyberchaos.dev [195.39.247.168]) by atuin.qyliss.net (Postfix) with ESMTPS id 5FD8823FD6 for ; Sat, 27 Sep 2025 09:14:15 +0000 (UTC) Message-ID: DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yuka.dev; s=mail; t=1758964454; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=taZwB3rQ1U7bXOCmsyoBiXX87xBHrbWzu7wBOktmZ8Y=; b=rT8uQdC4BAusiQKNbd/dJMhCCjmuQw5hetdMqheWiB8mTWhch7E13wcqU4bmqs1hQcbo8G asp8F55wNuhlzUvf50bVQzLwwG8qdDBUu3CY1neX1g74KR1oYhFewv/6rlmLB9bprIN4Fa Y/Vm0jC0WVRjRINZSGNj2tfaBYoJ7PA= Date: Sat, 27 Sep 2025 11:14:08 +0200 MIME-Version: 1.0 Subject: Re: [PATCH v6 1/4] tools: add xdp-forwarder To: Alyssa Ross References: <20250924114300.100541-1-yureka@cyberchaos.dev> <20250924114300.100541-2-yureka@cyberchaos.dev> <87wm5kb9ze.fsf@alyssa.is> Content-Language: en-US From: Yureka In-Reply-To: <87wm5kb9ze.fsf@alyssa.is> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Message-ID-Hash: FV7ITKE34MANGK2RZNBZ5WUET7PJAHP6 X-Message-ID-Hash: FV7ITKE34MANGK2RZNBZ5WUET7PJAHP6 X-MailFrom: yuka@yuka.dev X-Mailman-Rule-Hits: member-moderation X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address CC: devel@spectrum-os.org X-Mailman-Version: 3.3.9 Precedence: list List-Id: Patches and low-level development discussion Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: On 9/27/25 10:00, Alyssa Ross wrote: > A few more things I just found. Happy to just make the fixes myself > when I apply the patch if you prefer — just let me know what you think. Yes, please do the fixups when you apply the patch. Thank you! > > Yureka Lilian writes: > >> The xdp-forwarder's purpose is implementing the functionality needed >> within the net-vm (a VM running the Linux drivers for any physical >> interfaces on the spectrum system). >> >> In the future, the net-vm will load the included XDP programs on the >> passed-through physical interfaces as well as the downstream virtio >> interface going into the router (recognized by its special MAC address). >> >> The net-vm needs to multiplex between the physical interfaces, as there >> might be several interfaces in the same IOMMU-group. >> >> For this, the XDP program loaded on the physical interfaces >> (`prog_physical.o`) applies a VLAN tag corresponding to the interface id >> and redirects the packets to the router interface (identified by the >> `router_iface` bpf map). In the other direction the XDP program loaded on >> the router interface (`prog_router.o`) removes one layer of VLAN tagging >> and redirects the packets to the interface read from the VLAN tag. >> >> The helper program `set_router_iface` is used to update the `router_iface` >> bpf map to point to the interface passed as argument to the program. >> >> Co-authored-by: Demi Marie Obenour >> Signed-off-by: Yureka Lilian >> Signed-off-by: Demi Marie Obenour >> --- >> pkgs/default.nix | 4 + >> release/checks/pkg-tests.nix | 1 + >> tools/default.nix | 21 +- > tools/shell.nix should also set driverSupport = true so libbpf is > available in the development shell. Ack > >> tools/meson.build | 4 + >> tools/meson_options.txt | 3 + >> tools/xdp-forwarder/meson.build | 48 +++++ >> tools/xdp-forwarder/parsing_helpers.h | 274 +++++++++++++++++++++++++ >> tools/xdp-forwarder/prog_physical.c | 39 ++++ >> tools/xdp-forwarder/prog_router.c | 42 ++++ >> tools/xdp-forwarder/rewrite_helpers.h | 146 +++++++++++++ >> tools/xdp-forwarder/set_router_iface.c | 30 +++ >> 11 files changed, 608 insertions(+), 4 deletions(-) >> create mode 100644 tools/xdp-forwarder/meson.build >> create mode 100644 tools/xdp-forwarder/parsing_helpers.h >> create mode 100644 tools/xdp-forwarder/prog_physical.c >> create mode 100644 tools/xdp-forwarder/prog_router.c >> create mode 100644 tools/xdp-forwarder/rewrite_helpers.h >> create mode 100644 tools/xdp-forwarder/set_router_iface.c >> diff --git a/tools/xdp-forwarder/meson.build b/tools/xdp-forwarder/meson.build >> new file mode 100644 >> index 0000000..9b70ce3 >> --- /dev/null >> +++ b/tools/xdp-forwarder/meson.build >> @@ -0,0 +1,48 @@ >> +# SPDX-License-Identifier: EUPL-1.2+ >> +# SPDX-FileCopyrightText: 2025 Yureka Lilian >> +# SPDX-FileCopyrightText: 2025 Demi Marie Obenour >> + >> +libbpf = dependency('libbpf', version : '1.6.2') > This is an exact version match, which means we'll have to change it > every time libbpf updates in Nixpkgs. Do you know what a more > appropriate version constraint would be? We can change it to >=1.6.3. > >> + >> +executable('set-router-iface', 'set_router_iface.c', >> + dependencies : libbpf, >> + install : true) >> + >> +clang = find_program('clang', native: true) >> + >> +bpf_o_cmd = [ >> + clang.full_path(), >> + '-fno-stack-protector', >> + '-fno-strict-aliasing', >> + '-fwrapv', '-fwrapv-pointer', >> + '-Wall', >> + '-Wextra', > When I built in a Nix shell I got warnings from > -Wcompare-distinct-pointer-types and -Wsign-compare, coming from the > vendored headers. Should I just silence those? (A quick look at the > kernel suggests the distinct pointer type comparison is probably fine, > but that the sign comparison issue should probably be fixed upstream.) I agree about the severity of the warnings, and I think we can silence them since the -Wsign-compare warnings are all in functions which we never use. >> + '-O2', >> + '-target', 'bpf', >> + '-I', meson.current_source_dir() + '/include', >> + '-g', >> + '-c', >> + '-o', '@OUTPUT@', >> + '-MD', >> + '-MP', >> + '-MF', '@DEPFILE@', >> + '--', >> + '@INPUT@', >> +] >> + >> +prog_router_o = custom_target( >> + input : 'prog_router.c', >> + output : 'prog_router.o', >> + depfile : 'prog_router.o.dep', >> + command : bpf_o_cmd, >> + install: true, >> + install_dir: 'lib/xdp') >> + >> +prog_physical_o = custom_target( >> + input : 'prog_physical.c', >> + output : 'prog_physical.o', >> + depfile : 'prog_physical.o.dep', >> + command : bpf_o_cmd, >> + install: true, >> + install_dir: 'lib/xdp') >> +