From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f53.google.com (mail-wm1-f53.google.com [209.85.128.53]) (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 CDE2B1C5789 for ; Tue, 1 Oct 2024 14:06:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.53 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727791585; cv=none; b=HpD4CkLxgVlXNBqSybFQzOkQMcWJJrT+wKWhYZHyOQAnqIBSfUHijHW68MifSLn4R9hC7fI3++Mko6EHlcQbpCHIUDoVpX/12rjyGlQKKaaSXp4PoISTU+6sz3dXj9UOAsc1F+N9C989+4FHkPUMqPPTu9JUPqPuoN5TH65m6BE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727791585; c=relaxed/simple; bh=k+HGpSm5hZTXbX2q38o3UsWdiRJiQ5DUA4WSCzHUkGc=; h=Mime-Version:Content-Type:Date:Message-Id:To:Cc:Subject:From: References:In-Reply-To; b=bkDtPcJi/nbxMcHoPLHNHUmLImZZRY5xUE210wfpBEVpttbLvKXHTq7JI0FZItqERKSztzdFprcODNmr8W74KrHSJ07CuYJ+R37plu9r47eTuhDf3jmIMD8lkpdDZOKAPdRFOp6OheRhVKKBZ5GY8WOeEhbaWTiYNvDH3A3oOx0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=cloudflare.com; spf=pass smtp.mailfrom=cloudflare.com; dkim=pass (2048-bit key) header.d=cloudflare.com header.i=@cloudflare.com header.b=B4ZrFsBB; arc=none smtp.client-ip=209.85.128.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=cloudflare.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=cloudflare.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=cloudflare.com header.i=@cloudflare.com header.b="B4ZrFsBB" Received: by mail-wm1-f53.google.com with SMTP id 5b1f17b1804b1-42cae4eb026so53766995e9.0 for ; Tue, 01 Oct 2024 07:06:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloudflare.com; s=google09082023; t=1727791582; x=1728396382; darn=vger.kernel.org; h=in-reply-to:references:from:subject:cc:to:message-id:date :content-transfer-encoding:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=k+HGpSm5hZTXbX2q38o3UsWdiRJiQ5DUA4WSCzHUkGc=; b=B4ZrFsBBFlpJngRrIdgwC8hJMZCOTZfODjux5TBa0c0YakUoSQisGE9SqaF8v9KYKE mfCWNT5M6JoSjvCk4hQXsc7pAt93eGVJVr0H0mP5apRvfmGTtlhhO9HVhp7v2LxXknjM T3YkAIuF9s0UBDcb0msqgO2c5d7g5YX1oGXXD4/oCtVA202WnnlQwl99YBfRya6ZxVX6 jlHZqKgQrsZiop+gRs1DPHhyXbgx0F4H8EJMAOrwl1p0eBo1H4YHkzljLaYJf/vBStpg nxWlzMPv1P+i1oA9w376Sj9pYGo+HekIUSx7jIDroixnGyFyq0XCFdgvLn1PZ3vlCYP5 5A+w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727791582; x=1728396382; h=in-reply-to:references:from:subject:cc:to:message-id:date :content-transfer-encoding:mime-version:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=k+HGpSm5hZTXbX2q38o3UsWdiRJiQ5DUA4WSCzHUkGc=; b=AmbH1FFNzhZO13j+DmbQuXW340xXT26kgHD4dzidO6PCykwADrU1Mt8K2F3dYHBt07 RXCHl7EmSpJMRutyvX5KU7vV+Ht6nlx4gcXxByLb2EnYojV110WhV+rjUpA6dtAgzoim TQC6sctFQ9aA97xu2F07C4gvGabp2fB5RyFU0+fodspSa+x11Pvz79q274AmmTFA/Q9J b/NzpAofF9mP5h8kuXCTYNo5wfABZnxBd6aiV0GLM91peJ32zDr98HmPOiCLKsRhP/Q8 SBXN0Cv6/bkber2bsJ8EnX56z+ytt+/HzhwFD0YYpdvP17oCTupIVYYFO+6tbm0INik1 40jA== X-Forwarded-Encrypted: i=1; AJvYcCXWCt9pnPUY134U15sFHlu8Ki1RdUrI7i6SBzlZb7Ees2QdYDwidR/4J6VAiVWqCahqTZyd2Jo=@vger.kernel.org X-Gm-Message-State: AOJu0YyTVyxkg+594A8NCs6UUZ1HyS33dfnInPhw/BbQUwsrbSpLcefZ sWTRJH9gsVECesn1npK5DvMqFn8bK8UhCE5Hc9fER9+0RR/5JRSmB4Y4picV2DU= X-Google-Smtp-Source: AGHT+IFbKmOHQzYH6RU5RJ695hEsh3LWNKXU2AyvEHj2fyjWXajYvlxmm7C65l5t2tAIDZnqYBHP2Q== X-Received: by 2002:a05:6000:1141:b0:374:b9a7:5ed6 with SMTP id ffacd0b85a97d-37cd5ab7652mr9443619f8f.22.1727791581955; Tue, 01 Oct 2024 07:06:21 -0700 (PDT) Received: from localhost ([2a09:bac1:27c0:58::241:6e]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-37cd5742499sm11766826f8f.93.2024.10.01.07.06.20 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 01 Oct 2024 07:06:21 -0700 (PDT) Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 Date: Tue, 01 Oct 2024 16:06:20 +0200 Message-Id: To: =?utf-8?q?Toke_H=C3=B8iland-J=C3=B8rgensen?= Cc: "Lorenzo Bianconi" , "Jesper Dangaard Brouer" , "Jakub Sitnicki" , "Alexander Lobakin" , "Lorenzo Bianconi" , , , , , , , , , , , , , , , , , , , , "kernel-team" , "Yan Zhai" Subject: Re: [RFC bpf-next 0/4] Add XDP rx hw hints support performing XDP_REDIRECT From: "Arthur Fabre" X-Mailer: aerc 0.8.2 References: <1f53cd74-6c1e-4a1c-838b-4acc8c5e22c1@intel.com> <09657be6-b5e2-4b5a-96b6-d34174aadd0a@kernel.org> <87ldzkndqk.fsf@toke.dk> <87wmiysi37.fsf@toke.dk> <87ldzds8bp.fsf@toke.dk> <874j5xs9b1.fsf@toke.dk> In-Reply-To: <874j5xs9b1.fsf@toke.dk> On Mon Sep 30, 2024 at 12:52 PM CEST, Toke H=C3=B8iland-J=C3=B8rgensen wrot= e: > > Thinking about it more, my only relectance for a registration API is ho= w > > to communicate the ID back to other consumers (our discussion below). > > > >> > >> > Dynamically registering fields means you have to share the returned = ID > >> > with whoever is interested, which sounds tricky. > >> > If an XDP program sets a field like packet_id, every tracing > >> > program that looks at it, and userspace service, would need to know = what > >> > the ID of that field is. > >> > Is there a way to easily share that ID with all of them? > >> > >> Right, so I'll admit this was one of the handwavy bits of my original > >> proposal, but I don't think it's unsolvable. You could do something li= ke > >> (once, on application initialisation): > >> > >> __u64 my_key =3D bpf_register_metadata_field(my_size); /* maybe add a = name for introspection? */ > >> bpf_map_update(&shared_application_config, &my_key_index, &my_key); > >> > >> and then just get the key out of that map from all programs that want = to > >> use it? > > > > Passing it out of band works (whether it's via a pinned map like you > > described, or through other means like a unix socket or some other > > API), it's just more complicated. > > > > Every consumer also needs to know about that API. That won't work with > > standard tools. For example if we set a PACKET_ID KV, maybe we could > > give it to pwru so it could track packets using it? > > Without registering keys, we could pass it as a cli flag. With > > registration, we'd have to have some helper to get the KV ID. > > > > It also introduces ordering dependencies between the services on > > startup, eg packet tracing hooks could only be attached once our XDP > > service has registered a PACKET_ID KV, and they could query it's API. > > Yeah, we definitely need a way to make that accessible and not too > cumbersome. > > I suppose what we really need is a way to map an application-specific > identifier to an ID. And, well, those identifiers could just be (string) > names? That's what we do for CO-RE, after all. So you'd get something > like: > > id =3D bpf_register_metadata_field("packet_id", 8, BPF_CREATE); /* regist= er */ > > id =3D bpf_register_metadata_field("packet_id", 8, BPF_NO_CREATE); /* res= olve */ > > and we make that idempotent, so that two callers using the same name and > size will just get the same id back; and if called with BPF_NO_CREATE, > you'll get -ENOENT if it hasn't already been registered by someone else? > > We could even make this a sub-command of the bpf() syscall if we want it > to be UAPI, but that's not strictly necessary, applications can also > just call the registration from a syscall program at startup... That's a nice API, it makes sharing the IDs much easier. We still have to worry about collisions (what if two different things want to add their own "packet_id" field?). But at least: * "Any string" has many more possibilities than 0-64 keys. * bpf_register_metadata() could return an error if a field is already registered, instead of silently letting an application overwrite metadata (although arguably we could have add a BPF_NOEXIST style flag to the KV set() to kind of do the same). At least internally, it still feels like we'd maintain a registry of these string fields and make them configurable for each service to avoid collisions. > >> We could combine such a registration API with your header format, so > >> that the registration just becomes a way of allocating one of the keys > >> from 0-63 (and the registry just becomes a global copy of the header). > >> This would basically amount to moving the "service config file" into t= he > >> kernel, since that seems to be the only common denominator we can rely > >> on between BPF applications (as all attempts to write a common daemon > >> for BPF management have shown). > > > > That sounds reasonable. And I guess we'd have set() check the global > > registry to enforce that the key has been registered beforehand? > > Yes, exactly. And maybe check that the size matches as well just to > remove the obvious footgun of accidentally stepping on each other's > toes? > > > Thanks for all the feedback! > > You're welcome! Thanks for working on this :) > > -Toke