From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E79003B8BDB for ; Wed, 24 Jun 2026 09:33:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782293601; cv=none; b=P7im8C+AaDVdvYegQeeuI6ht4ZOgtLpzh1r4yiISSeisCvQ5FKgByHXeRLtrSbzCP6mhfahW+61v0h5yZM1r7lw6/mKxLTtHuWyhBy52of7+o/ORCHig5jttATI0bJnz1walE2l3Fsy7K+uVvZNaeogbflbykBIKko8OSVMXFJw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782293601; c=relaxed/simple; bh=zVTzcAhu2sh1noRCqYQ5+3ri+BgXa4QWy0Rkq9VVdAo=; h=From:To:Cc:Subject:In-Reply-To:References:Date:Message-ID: MIME-Version:Content-Type; b=hpHpmt2P5iVCpHF2j+Gho552wr21q4My0NOFRdw6cZP9ZwWgLIM4ua1zwLQKA08wmUdv3QUCzQwhMPIgbhasa/U4fojWt5IFEVIH8Cm0yv5Rmcxxm6akaHXZaJYfeSjljFHYELT1BtRPO1gEYyC7DstMYMxlD1aPuJzf+i38SEs= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=herEhCUE; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=Tmxj8oc9; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="herEhCUE"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="Tmxj8oc9" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1782293591; 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=oScmgVBAZdYqdklOiG9pSCq/MuJ7qIw0aEjZWIJM3Ks=; b=herEhCUEh06HEQHdglDV4z4Or66y4jJQs4daiMggsycfJJG5C3YPJmKTo9ss+7SWHyCG4S gO8vQ6WT+vxcD3LH0oADX1R97utp1gDA1AZrhOG81Ym1URAjivDqiaLM3MglnKGLPuFcgJ 4Pz0iOtclnIq+WmVcYdEUIG6ASAAQMc= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-587-KnwTYOUQNSW3DHwdauGJSQ-1; Wed, 24 Jun 2026 05:33:10 -0400 X-MC-Unique: KnwTYOUQNSW3DHwdauGJSQ-1 X-Mimecast-MFC-AGG-ID: KnwTYOUQNSW3DHwdauGJSQ_1782293589 Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-490ace40f13so3295915e9.3 for ; Wed, 24 Jun 2026 02:33:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1782293589; x=1782898389; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:references :in-reply-to:subject:cc:to:from:from:to:cc:subject:date:message-id :reply-to; bh=oScmgVBAZdYqdklOiG9pSCq/MuJ7qIw0aEjZWIJM3Ks=; b=Tmxj8oc9NORHyMpNMErskFcuZxUMAEqCIINQAgkxpfGql0/tSMyFtbVHcgu1A0KgZv Iq3lZT/ScV5cvkCUHhFB2THarNBpIRoSnaxKO/xX+gwwpetAwMhLkdGPnDs177ml/Xt0 cEX0W5OxMKYRI3oKhGl2cqk5ucw43mX4QeB5kKzIJO8QLmkPgVosRwGN6ek/T2AJgveG uUHHSOQmj8J1YYwaYsjObAchO5usnRNJJK+P/QA2tHqj4kLLy1Cf9h83bNsOdH7WVrrY oUIpWi3THSgmzEeDh91oUz5Bv4J/NwGhyvg+ABdkbYZI1okf+h78HsupjANLLBY9jl/E qLqQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1782293589; x=1782898389; h=content-transfer-encoding:mime-version:message-id:date:references :in-reply-to:subject:cc:to:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=oScmgVBAZdYqdklOiG9pSCq/MuJ7qIw0aEjZWIJM3Ks=; b=TgQXLsAyGoFIxFGX/uxuLKO4PqlrnMNCDxonNc87F73yEGstLnKTHyhx4E70QMH7G6 +K7hTTA6Fnyro76KwjOsM4q/s9F7dlhxNk7Ez4Ku6eAK/+j6YVc8nhfsZ4sKAt+GjLyf Awiz2mxmPMVm0ZbIhGIrixAAPFRC0DhBl9wIcme1fJWPy2/O/M+hiLK4Mq8IJ9mWikCI CNJ12NJpe/fz9vU/cT7mysr3aLof+a+kNOM6A4j8eVXlX/7YUA1e44ELOKpcLh0ISqKv 6hpOdQVn2AfMnIk7h/oAcW76la2/BFumHkkolhFvkF8wdyAurgOR3UzNCX24Imp3yTTA ZwdA== X-Forwarded-Encrypted: i=1; AFNElJ9cnv0AT8mvAQZkUdr8WD8obO/hW4WM2snqXeqyBr04U6mSXHA/WiuUJ8ddG8R8nqD4Uo8JRFinffI5Lbg=@vger.kernel.org X-Gm-Message-State: AOJu0YwOoDvRUjWcm7srn96Pm3UbUSsZsJzsZgZBPeuqqf4PCsX2Lu3t OdCvv8beJAT58K6KClv+BgJPkxfRww4PXroP/GHqRysJLwXGYABiBr2LIqzsqtTDglwQTQZOm4Q 6OO8my9EikSq5brNsgj90+SQ5uSsFfcyPnnnb0tabSUm2Fu2j+AryX5h1edIsFktTV4HsPifKAQ == X-Gm-Gg: AfdE7cnlzNSs0eIDWOGUXPoWp8KCjqs87bAjW2eT5PSvLtp5WSsPKlwuPsmdOGoffly jbxWlK9IqeGwpsHF6ThqTCCq9YSiocyF+B4wOFubSRvZTgzg+DVwvxXpqUkONUCzv+Qkr/Um+99 EABJXMC5qxOMSIGcP02A6A1XX8GIJFu774u9ZSiLJyXKo7kr8++zD6AlsBpPLeeupAKr60Y0PuX FpBqGK+4bwvKE5oLK2ltsW0eQyXrdayvX23OrCgsSue++oo368APus5CVD4guW/S+LN+QPVQ1Cu pnqeJEWJU9NN2bMkpzYU4aI7uK0NkZK9lJK3ch2CeSot93HniIRzt6Cqz+HM+2wQaJm+8o0+HUi PluIb4LvknoKPOx9BdJZJP/skBj5Pu+c/v0U= X-Received: by 2002:a05:600c:a012:b0:492:2e1c:1d19 with SMTP id 5b1f17b1804b1-49260875bbamr34892685e9.31.1782293586965; Wed, 24 Jun 2026 02:33:06 -0700 (PDT) X-Received: by 2002:a05:600c:a012:b0:492:2e1c:1d19 with SMTP id 5b1f17b1804b1-49260875bbamr34892125e9.31.1782293586482; Wed, 24 Jun 2026 02:33:06 -0700 (PDT) Received: from alrua-x1.borgediget.toke.dk ([45.145.92.2]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-49261063d6esm26451795e9.2.2026.06.24.02.33.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Jun 2026 02:33:05 -0700 (PDT) Received: by alrua-x1.borgediget.toke.dk (Postfix, from userid 1000) id 42FAF808FBD; Wed, 24 Jun 2026 11:33:04 +0200 (CEST) From: Toke =?utf-8?Q?H=C3=B8iland-J=C3=B8rgensen?= To: Avinash Duduskar , ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org Cc: eddyz87@gmail.com, memxor@gmail.com, martin.lau@linux.dev, song@kernel.org, yonghong.song@linux.dev, jolsa@kernel.org, emil@etsalapatis.com, john.fastabend@gmail.com, sdf@fomichev.me, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, horms@kernel.org, shuah@kernel.org, hawk@kernel.org, yatsenko@meta.com, leon.hwang@linux.dev, kpsingh@kernel.org, a.s.protopopov@gmail.com, ameryhung@gmail.com, rongtao@cestc.cn, eyal.birger@gmail.com, bpf@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, dsahern@kernel.org Subject: Re: [PATCH bpf-next v5 1/3] bpf: Add BPF_FIB_LOOKUP_VLAN flag to bpf_fib_lookup() helper In-Reply-To: <20260624030530.3342884-2-avinash.duduskar@gmail.com> References: <20260624030530.3342884-1-avinash.duduskar@gmail.com> <20260624030530.3342884-2-avinash.duduskar@gmail.com> X-Clacks-Overhead: GNU Terry Pratchett Date: Wed, 24 Jun 2026 11:33:04 +0200 Message-ID: <87pl1gcmgf.fsf@toke.dk> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Avinash Duduskar writes: > bpf_fib_lookup() returns the FIB-resolved egress ifindex straight > from the fib result. When the egress is a VLAN device, the returned > ifindex is the VLAN netdev's, which has no XDP xmit handler; XDP > programs that want to forward the frame (e.g. xdp-forward) must > instead target the underlying physical device and push the VLAN tag > themselves. Today the program has no way to learn either the > underlying ifindex or the VLAN tag without maintaining its own > VLAN-to-ifindex map in userspace and refreshing it on netlink > events. > > Add BPF_FIB_LOOKUP_VLAN. When the caller sets this flag and the fib > result is a VLAN device whose immediate parent is a real (non-VLAN) > device in the same network namespace, populate the existing output > fields params->h_vlan_proto and params->h_vlan_TCI from the VLAN > device and replace params->ifindex with the parent's ifindex. > params->h_vlan_TCI carries the VID only, with PCP and DEI bits zero; a > consumer wanting to set egress priority writes PCP itself. > params->smac is the VLAN device's own address, which can differ from > the parent's. > > Only the immediate parent is resolved, via vlan_dev_priv(dev)->real_dev > and not vlan_dev_real_dev(), which walks to the bottom of a stack. When > the immediate parent is not a real device in the same namespace, the > lookup returns BPF_FIB_LKUP_RET_VLAN_FAILURE and leaves params->ifindex > at the input. This covers a stacked VLAN (QinQ), where the immediate > parent is itself a VLAN device and one h_vlan_proto/h_vlan_TCI pair > cannot describe two tags, and a parent in another network namespace (a > VLAN device can be moved while its parent stays), whose ifindex would > be meaningless in the caller's namespace. A program that wants the VLAN > device's own ifindex re-issues the lookup without BPF_FIB_LOOKUP_VLAN, > so the unreducible case stays distinct from a physical egress. That > distinction matters for XDP: a program cannot xmit on a VLAN device, so > a success carrying the VLAN ifindex would make it redirect to a device > with no ndo_xdp_xmit and drop the frame at xdp_do_flush(). The swap and > the vlan fields are written only on the reduce path; other output > fields keep their existing behaviour, so a frag-needed result still > reports the route mtu in params->mtu_result. > > BPF_FIB_LOOKUP_VLAN is only useful to XDP, which cannot redirect to a > VLAN device. A tc program can redirect to the VLAN device directly, so > bpf_skb_fib_lookup() rejects the flag with -EINVAL; bpf_xdp_fib_lookup() > accepts it. When the flag is not set, behaviour is unchanged: > h_vlan_proto and h_vlan_TCI are zeroed and ifindex is left at the FIB > result. > > The new block is compiled only under CONFIG_VLAN_8021Q since > vlan_dev_priv() is not defined otherwise; without that config > is_vlan_dev() is constant false and the flag is accepted but never > acts. That is safe because no VLAN device can exist there, so every > egress is already physical. > > This lets an XDP redirect target the physical device and learn the > tag to push in a single lookup, which xdp-forward's optional VLAN > mode (xdp-project/xdp-tools#504) wants from the kernel side. > > The helper's input semantics are unchanged; the reverse direction > (supplying a tag as lookup input) is added in the following patch. > > Suggested-by: Toke H=C3=B8iland-J=C3=B8rgensen > Signed-off-by: Avinash Duduskar Yes, this is way nicer - thanks! One nit below, otherwise LGTM: Reviewed-by: Toke H=C3=B8iland-J=C3=B8rgensen [..] > + if (flags & BPF_FIB_LOOKUP_VLAN) > + return -EINVAL; > + This is fine, but we should probably reject the input flag as well in the next patch (for symmetry). -Toke