patches and low-level development discussion
 help / color / mirror / code / Atom feed
From: Alyssa Ross <hi@alyssa.is>
To: Yureka Lilian <yureka@cyberchaos.dev>
Cc: Demi Marie Obenour <demiobenour@gmail.com>, devel@spectrum-os.org
Subject: Re: [PATCH v6 1/4] tools: add xdp-forwarder
Date: Sat, 27 Sep 2025 10:00:53 +0200	[thread overview]
Message-ID: <87wm5kb9ze.fsf@alyssa.is> (raw)
In-Reply-To: <20250924114300.100541-2-yureka@cyberchaos.dev>

[-- Attachment #1: Type: text/plain, Size: 4636 bytes --]

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.

Yureka Lilian <yureka@cyberchaos.dev> 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 <demiobenour@gmail.com>
> Signed-off-by: Yureka Lilian <yureka@cyberchaos.dev>
> Signed-off-by: Demi Marie Obenour <demiobenour@gmail.com>
> ---
>  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.

>  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 <yureka@cyberchaos.dev>
> +# SPDX-FileCopyrightText: 2025 Demi Marie Obenour <demiobenour@gmail.com>
> +
> +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?

> +
> +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.)

> +  '-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')
> +

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 227 bytes --]

  parent reply	other threads:[~2025-09-27  8:01 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-24 11:42 [PATCH v6 0/4] xdp-forwarder Yureka Lilian
2025-09-24 11:42 ` [PATCH v6 1/4] tools: add xdp-forwarder Yureka Lilian
2025-09-25  9:55   ` Alyssa Ross
2025-09-26 23:47     ` Demi Marie Obenour
2025-09-25  9:58   ` Alyssa Ross
2025-09-25 10:00     ` Alyssa Ross
2025-09-27  8:00   ` Alyssa Ross [this message]
2025-09-27  9:14     ` Yureka
2025-09-27 11:34   ` Alyssa Ross
2025-09-24 11:42 ` [PATCH v6 2/4] docs/architecture: add paragraph about networking Yureka Lilian
2025-09-27 11:39   ` Alyssa Ross
2025-09-24 11:42 ` [PATCH v6 3/4] vm/sys/net: build against pkgsMusl Yureka Lilian
2025-09-27 11:44   ` Alyssa Ross
2025-09-24 11:42 ` [PATCH RFC v6 4/4] vm/sys/net: integrate xdp-forwarder Yureka Lilian
2025-09-25  9:33 ` [PATCH v6 0/4] xdp-forwarder Alyssa Ross

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87wm5kb9ze.fsf@alyssa.is \
    --to=hi@alyssa.is \
    --cc=demiobenour@gmail.com \
    --cc=devel@spectrum-os.org \
    --cc=yureka@cyberchaos.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://spectrum-os.org/git/crosvm
	https://spectrum-os.org/git/doc
	https://spectrum-os.org/git/mktuntap
	https://spectrum-os.org/git/nixpkgs
	https://spectrum-os.org/git/spectrum
	https://spectrum-os.org/git/ucspi-vsock
	https://spectrum-os.org/git/www

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).