From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-yx1-f41.google.com (mail-yx1-f41.google.com [74.125.224.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4DC2C37CD45 for ; Mon, 4 May 2026 23:01:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.224.41 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777935662; cv=none; b=Ln5RfdimoJxz/sxSaq5yNib2dL0w8jee91h/VP3nBEidnvVNeoZJr2/psrTayYv2HOPcM41fiUKaARH3mE0fM9ZVNV2oUbgNNGpD98aKgKLGR2z7E/YvElGObYdba36Ym29V7LTtF4Ib177OpieIkt5FSAmuIQOrWtiPTwirNPE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777935662; c=relaxed/simple; bh=GS3tWmFYf8Q7lVBDml+EYCl+olkE2mAbu7X9hjWwiNA=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version:Content-Type; b=G+fK3VsqTCBqZp6x17PJKXT9Kb6hCClRoUkARsWZfjm8kC26CUrn9oF78R8tZdo7X/1CgXeCc+qX+YbUY1PH5xB/TID/y6BRJVrm1Bit7loO7o4T/HOSnKoJgC8k+bw1aVM70i7hPwgwe4QYyzF2bj8lwytZb1SIZ3PiDl/48sc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=JbXWLKJv; arc=none smtp.client-ip=74.125.224.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="JbXWLKJv" Received: by mail-yx1-f41.google.com with SMTP id 956f58d0204a3-651c36a7ee9so525113d50.0 for ; Mon, 04 May 2026 16:01:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1777935660; x=1778540460; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=4TZfqdfxjhy0c/VGVumHu/CLAzrRRaEgVoP7aBB7kv8=; b=JbXWLKJvAN4nXkygJ3slUfGsy3czoOfGCO2A5QXPf+8WDeyvxjtIrLMyB8E/3ad9+r qpksmfFRnOqMpY2BYMkonlaKhtGXI2CaO8zGjwv275MIHcf50S/jqYmuiCTsn+EtRYUP 6nM0ufMcy0fkp/R7jRs9723pxkpRFHYzUvt4CDwqTw9JyW+9uEzQLcpvC4gMsV+TuJO5 MnNf9/HjiECgX7jH9rdFPgnQNk3G7w2Qv1ravXI5GUAQ0olWLOOU81wnteZj/zzgWu6F 9wJeLfc4qU6RrppaH0xPPLzamFVUJ8qAxLT2LfyAmBS/5Pf2xtfWUvm0qsWaPiTNG/Aw 3Xsw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777935660; x=1778540460; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=4TZfqdfxjhy0c/VGVumHu/CLAzrRRaEgVoP7aBB7kv8=; b=CszSYoZGZwRRplE2byPNziR8+oWEIs7tq6j8vqn35UT3oxhdDTn2isnj1tV9jri0R0 M9YYBiKbwY6CDx4EXbvLstfJolAKeJeTUwI6fU05nS4WiMrbi4+wOxuvtZrImZqFrQlE ns9y7GerhVWGgVYL2TzKpSitnGGX9mm74E1gUrkYpkgCx+zCMneiPBLx86aA4LEKfA4V xXgnQE/6ZtnPFS/gM771t5UETpM3D6XOV0HTSY6V67sEotvKnqkgWI7qpJVwXtl8BkN5 eaJoZTIF03lqmtyVwiAaZ+vhHsaDm/5qJMKxBHxvArOcaLYjAJPc+ZYh/xob5EjyDHwh 0kJQ== X-Gm-Message-State: AOJu0YxmzKWe9Y7Iz5MDQa3HtAPWOJ/IXtNqEZv6V24HZ5IHRE+nlrse 8MLTOjlB6lLcq433Pqjz/CQ+S9dpnaPB0+D3GZBzmxNss9l3GYWwY7H554UoTw== X-Gm-Gg: AeBDietWAEulDoue5JsAJT9uZv6fKCGr8g8YgNiWUtDU5FR2mEV4gb45+9nwTKugJ5c d2vSIsajUaUT79ryDIjR2P7k4HtNkuDV6egn6F7lAgwswDfRpDCB8HVktHDHtTN5bhupdnD7E26 F73tpkId0THjcvMQydpnhzEpAFE30L4nIrlRYGXe8jqroSV+pQIZVytaWiHWolkzSP6tuiMhu7A SsAvdpliCPOW5j8Ods/TQ4zaeEGS0CmRhdX0lwtDLbcybyxuxzWF8i8sir7uvVV/KDEqBnK8ZxH U80sTS5ER4kESYFWMPKqGQTxceTwy+MO3lavdIfm1dnREymEZQVNqbfedV/N55ZGwOBBqGJMeKO hA/yVmnLtMUbwLL6frKv9gg6r2qpkYcpuDyQ1g2l/dhAzx+v4iK9aIC79flFapDGfJ970SWS6e4 gcibMK7/ZCDyCWRI4NvOQ+HnWO5EKILCY= X-Received: by 2002:a05:690e:d4a:b0:651:e0cd:587a with SMTP id 956f58d0204a3-65c6aecce29mr279076d50.7.1777935659676; Mon, 04 May 2026 16:00:59 -0700 (PDT) Received: from localhost ([2a03:2880:21ff::]) by smtp.gmail.com with ESMTPSA id 956f58d0204a3-65c2e85f390sm6134563d50.15.2026.05.04.16.00.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 May 2026 16:00:59 -0700 (PDT) From: Wei Wang To: netdev@vger.kernel.org, Jakub Kicinski , Daniel Zahka , Willem de Bruijn , David Wei , Andrew Lunn , "David S . Miller" , Eric Dumazet , Simon Horman , Paolo Abeni Cc: Wei Wang Subject: [PATCH v13 net-next 0/5] psp: Add support for dev-assoc/disassoc Date: Mon, 4 May 2026 16:00:50 -0700 Message-ID: <20260504230056.917415-1-weibunny.kernel@gmail.com> X-Mailer: git-send-email 2.52.0 Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From: Wei Wang The main purpose of this feature is to associate virtual devices like veth or netkit with a real PSP device, so we could provide PSP functionality to the application running with virtual devices. A typical deployment that works with this feature is as follows: Host Namespace: psp_dev_local ←──physically linked──→ psp_dev_peer (PSP device) │ │ BPF on psp_dev_local ingress: bpf_redirect_peer() to nk_guest │ nk_host / veth_host │ │ BPF on nk_host ingress: bpf_redirect_neigh() to psp_dev_local │ Guest Namespace (netns): │ nk_guest / veth_guest ★ PSP application run here Remote Namespace (_netns): psp_dev_peer ★ PSP server application runs here Note: The general requirement for this feature to work: For PSP to work correctly, the egress device at validate_xmit_skb() time must have psp_dev matching the association's psd. Any device stacking or traffic redirection that changes the egress device will cause either: 1. TX validation failure (SKB_DROP_REASON_PSP_OUTPUT) - fail-safe 2. RX policy failure after tx-assoc - packets without PSP extension are rejected by receiver expecting encrypted traffic Here are a few examples that this feature would not work: - Bonding with load balancing in round-robin, XOR, 802.3ad mode across multiple PSP devices, or mixed PSP and non-PSP devices - Bonding with active-backup mode might work without PSP migration for failover case. - ipvlan/macvlan in bridge mode would not work given packets are loopbacked locally without going through the PSP device. Changes since v12: - Rebase Changes since v11: - Cap max number of associated devs per psd to 128 to avoid overflowing GENLMSG_DEFAULT_SIZE for netlink msg in patch 2 - Make common function for getting net in psp_nl_dev_assoc_doit() and psp_nl_dev_disassoc_doit() in patch 2 - Only allow NSID to be passed in when user is in dev_net(psd->main_netdev) to avoid manipulation of dev-assoc/dev-disassoc from netns other than its own in patch 2 - Fixed the race between netdev_unregister() and psp_nl_dev_assoc_doit() by adding devreg status check in psp_nl_dev_assoc_doit(). Changes since v10: - Corrected typo on patch 1 - Removed the kdoc style comments, Use goto style in psp_nl_dev_assoc_doit() clean up code, Resolved "TOCTOU" issue in psp_assoc_device_get_locked() in patch 2 - Replaced psp_devs_lock with a new mutex in psp_attach_netdev_notifier(), Fixed kdoc style comments in patch 3 Changes since v9: - Added comments for psp_device_get_locked(), fixed lint issue, fixed rcu warning in patch 2 - Return error if register_netdevice_notifier() fails in psp_device_get_locked_dev_assoc() in patch 3 - Removed psp version and ip version for unnecessary tests cases in patch 5 Changes since v8: - Rebase Changes since v7: - Refactor in patch 1 to have a common helper for psp_device_get_locked_admin() and psp_device_get_locked() - Take psd->lock in psp_assoc_device_get_locked() before psp_dev_check_access() in patch 2 - Use cmpxchg() for assoc_dev->psp_dev assignment when doing dev-assoc in patch 2 - Check for err for register_netdevice_notifier() in patch 3 - Call psp_attach_netdev_notifier() in pre_doit handler for dev-assoc to avoid releasing of psd->lock in patch 3 Changes since v6: - Remove the unused remote_addr, nk_guest_addr and import cmd in patch 5 Changes since v5: - Remove module_exit() in patch 3 Changes since v4: - Address compilation warning in patch 3 - Removed the call to psp_nl_has_listeners_any_ns() and check listeners when looping through netns in psp_nl_notify_dev() in patch 2. This makes sure we only send notification to netns that has listeners. Changes since v3: - Make nsid optional for dev-assoc/dev-disassoc operation, and use the ns user is in when it's not specified. Also added a test for this. - Fix psp_nl_notify_dev() to compute the correct nsid relative to the listener's netns. - Only register the new netdev event for psp dev cleanup upon the first successful dev-assoc operation. - Change the following in selftest: - Add CONFIG_NETKIT to driver/net's config - Fall back to NetDrvEpEnv and run basic test cases if NetDrvContEnv does not load - Use ksft_variants instead of psp_ip_ver_test_builder Changes since v2: - Change the newly added parameter to psp_device_get_and_lock() to admin in patch 1. Introduce 2 device check functions: - psp_device_get_locked_admin() for dev-set and key-rotate - psp_device_get_locked() for all other operations Flip the logic for checking the dev_assoc_list accordingly in patch 2. - Move psp_nl_notify_dev() before removing the dev from assoc_dev_list in psp_nl_dev_disassoc_doit() and correct the typo in commit msg in patch 2. - Remove the threading and subprocess and some comment updates in patch 5. Changes since v1: - Update the first 4 patches to reflect the latest changes in https://lore.kernel.org/netdev/20260302053315.1919859-1-dw@davidwei.uk/ - Update patch 9 to add a param to NetDrvContEnv to control the loading of the tx forwarding bpf program Wei Wang (5): psp: add admin/non-admin version of psp_device_get_locked psp: add new netlink cmd for dev-assoc and dev-disassoc psp: add a new netdev event for dev unregister selftests/net: Add bpf skb forwarding program selftests/net: psp: Add test for dev-assoc/disassoc Documentation/netlink/specs/psp.yaml | 71 ++- include/net/psp/types.h | 23 + include/uapi/linux/psp.h | 13 + net/psp/psp-nl-gen.c | 36 +- net/psp/psp-nl-gen.h | 7 + net/psp/psp.h | 3 +- net/psp/psp_main.c | 104 +++- net/psp/psp_nl.c | 398 ++++++++++++++- tools/testing/selftests/drivers/net/config | 1 + .../drivers/net/hw/nk_redirect.bpf.c | 60 +++ .../selftests/drivers/net/lib/py/env.py | 54 ++- tools/testing/selftests/drivers/net/psp.py | 457 ++++++++++++++++-- 12 files changed, 1167 insertions(+), 60 deletions(-) create mode 100644 tools/testing/selftests/drivers/net/hw/nk_redirect.bpf.c -- 2.52.0