From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.9 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BC342C41621 for ; Tue, 24 Mar 2020 10:16:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 9642E2080C for ; Tue, 24 Mar 2020 10:16:14 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="OEvILK6v" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727152AbgCXKQO (ORCPT ); Tue, 24 Mar 2020 06:16:14 -0400 Received: from us-smtp-delivery-74.mimecast.com ([63.128.21.74]:22524 "EHLO us-smtp-delivery-74.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727145AbgCXKQN (ORCPT ); Tue, 24 Mar 2020 06:16:13 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1585044971; 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=/1wY4En0yDB+cGvUu+J0YQ/O0nGvtOSgxUaiPAKKcj4=; b=OEvILK6vglIlkeFk2jW8z+5SeqPqXG5Ipe/NVtyH3H+ZO2jNytwWkGKpYi6KWIUluFQDdz qpXv8uEnLlGlISdGHG00HQ16dj7YLYqZuq4Eh+JuVKmWxohm7dMLqo9QKy7AnMuETeD3jC aFbAjf512cwYe/TzT4Ni//4du64DZcg= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-76-rN0z_7ozMsK7SouQcBElFQ-1; Tue, 24 Mar 2020 06:16:10 -0400 X-MC-Unique: rN0z_7ozMsK7SouQcBElFQ-1 Received: by mail-wm1-f71.google.com with SMTP id g9so1120251wmh.1 for ; Tue, 24 Mar 2020 03:16:10 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:in-reply-to:references:date :message-id:mime-version:content-transfer-encoding; bh=/1wY4En0yDB+cGvUu+J0YQ/O0nGvtOSgxUaiPAKKcj4=; b=qGohNLn5xEwp5JlS6S3om5Rt19QaAzg6pwpnQ3EpOcwtowm4nxZnzswhHRud+123X3 NQaxiijOIpdZS4cLOotyIBfDwtH4/9l6KAdJCEhH4yuQVzRQ5rcMFMDxmHFdV8Q5PMVt rbyykJPsEOGZLheRvdi8LC0jA5e+9ieP2eCtRViqOf76oaKdB0iKRomJxYIXLnMowQMX lVzVocUSrNQF/KqfVPcb7LDAnPXeR6tgR/qPVb3PtDmWkU8CiqCsiQxBDlVKGL5j4jtg qJQV8j1smxaFSfTx1PAY9VzXqCjBKIm0imwlOBg7PIPIK42u0zSRbl8BoG7y/4R01FM+ CNGg== X-Gm-Message-State: ANhLgQ2sCVl+vb6MANRM1zPI6mx7xkfKRiG9hhB7bZRXypREc1kTJhhC cY+pz58+iihohettb50qC5UO9EbnPSaS5w+QH3oPFOeIgRNFzVTErV1OdGV7IelLFbA6Iban2iC e/XAAfF2byGIL X-Received: by 2002:a5d:6045:: with SMTP id j5mr34114912wrt.401.1585044969083; Tue, 24 Mar 2020 03:16:09 -0700 (PDT) X-Google-Smtp-Source: ADFU+vt4fxw3WQlcrSpfYVY6EUzmKWp+2/hFVX/ZlQ7yZFHspc85MIgrLtEPxWoN8Rr5x79q54R6OQ== X-Received: by 2002:a5d:6045:: with SMTP id j5mr34114878wrt.401.1585044968861; Tue, 24 Mar 2020 03:16:08 -0700 (PDT) Received: from alrua-x1.borgediget.toke.dk ([45.145.92.2]) by smtp.gmail.com with ESMTPSA id u13sm11839118wru.88.2020.03.24.03.16.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Mar 2020 03:16:07 -0700 (PDT) Received: by alrua-x1.borgediget.toke.dk (Postfix, from userid 1000) id 29A13180371; Tue, 24 Mar 2020 11:16:06 +0100 (CET) From: Toke =?utf-8?Q?H=C3=B8iland-J=C3=B8rgensen?= To: Andrey Ignatov Cc: Andrii Nakryiko , Jakub Kicinski , Alexei Starovoitov , Daniel Borkmann , Martin KaFai Lau , Song Liu , Yonghong Song , Andrii Nakryiko , "David S. Miller" , Jesper Dangaard Brouer , John Fastabend , Lorenz Bauer , Networking , bpf Subject: Re: [PATCH bpf-next 1/4] xdp: Support specifying expected existing program when attaching XDP In-Reply-To: <20200323235441.GA33093@rdna-mbp> References: <158462359206.164779.15902346296781033076.stgit@toke.dk> <158462359315.164779.13931660750493121404.stgit@toke.dk> <20200319155236.3d8537c5@kicinski-fedora-PC1C0HJN> <875zez76ph.fsf@toke.dk> <87r1xj48ko.fsf@toke.dk> <20200323235441.GA33093@rdna-mbp> X-Clacks-Overhead: GNU Terry Pratchett Date: Tue, 24 Mar 2020 11:16:06 +0100 Message-ID: <87369y2h3t.fsf@toke.dk> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Sender: bpf-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org Andrey Ignatov writes: > Toke H=C3=B8iland-J=C3=B8rgensen [Mon, 2020-03-23 04:25= -0700]: >> Andrii Nakryiko writes: >>=20 >> > On Fri, Mar 20, 2020 at 1:48 AM Toke H=C3=B8iland-J=C3=B8rgensen wrote: >> >> >> >> Jakub Kicinski writes: >> >> >> >> > On Thu, 19 Mar 2020 14:13:13 +0100 Toke H=C3=B8iland-J=C3=B8rgensen= wrote: >> >> >> From: Toke H=C3=B8iland-J=C3=B8rgensen >> >> >> >> >> >> While it is currently possible for userspace to specify that an ex= isting >> >> >> XDP program should not be replaced when attaching to an interface,= there is >> >> >> no mechanism to safely replace a specific XDP program with another. >> >> >> >> >> >> This patch adds a new netlink attribute, IFLA_XDP_EXPECTED_FD, whi= ch can be >> >> >> set along with IFLA_XDP_FD. If set, the kernel will check that the= program >> >> >> currently loaded on the interface matches the expected one, and fa= il the >> >> >> operation if it does not. This corresponds to a 'cmpxchg' memory o= peration. >> >> >> >> >> >> A new companion flag, XDP_FLAGS_EXPECT_FD, is also added to explic= itly >> >> >> request checking of the EXPECTED_FD attribute. This is needed for = userspace >> >> >> to discover whether the kernel supports the new attribute. >> >> >> >> >> >> Signed-off-by: Toke H=C3=B8iland-J=C3=B8rgensen >> >> > >> >> > I didn't know we wanted to go ahead with this... >> >> >> >> Well, I'm aware of the bpf_link discussion, obviously. Not sure what's >> >> happening with that, though. So since this is a straight-forward >> >> extension of the existing API, that doesn't carry a high implementati= on >> >> cost, I figured I'd just go ahead with this. Doesn't mean we can't ha= ve >> >> something similar in bpf_link as well, of course. >> >> >> >> > If we do please run this thru checkpatch, set .strict_start_type, >> >> >> >> Will do. >> >> >> >> > and make the expected fd unsigned. A negative expected fd makes no >> >> > sense. >> >> >> >> A negative expected_fd corresponds to setting the UPDATE_IF_NOEXIST >> >> flag. I guess you could argue that since we have that flag, setting a >> >> negative expected_fd is not strictly needed. However, I thought it was >> >> weird to have a "this is what I expect" API that did not support >> >> expressing "I expect no program to be attached". >> > >> > For BPF syscall it seems the typical approach when optional FD is >> > needed is to have extra flag (e.g., BPF_F_REPLACE for cgroups) and if >> > it's not specified - enforce zero for that optional fd. That handles >> > backwards compatibility cases well as well. >>=20 >> Never did understand how that is supposed to square with 0 being a valid >> fd number? > > In BPF_F_REPLACE case (since it was used as an example in this thread) > it's all pretty clear: > > * if the flag is set, use fd from attr.replace_bpf_fd that can be anything > (incl. zero, since indeed it's valid fd) no problem with that; > * if flag is not set, ignore replace_bpf_fd completely. > > It's descirbed in commit log in 7dd68b3279f1: > > ... > > BPF_F_REPLACE is introduced to make the user intent clear, since > replace_bpf_fd alone can't be used for this (its default value, 0, is= a > valid fd). BPF_F_REPLACE also makes it possible to extend the API in = the > future (e.g. add BPF_F_BEFORE and BPF_F_AFTER if needed). > > ... > > , i.e. flag presense is important, not the fd attribute being zero. > > Hope it clarifies. Yup, it does, thanks! My confusion stemmed from having seen '!=3D 0' tests for FDs in various places and wondered how that was supposed to work. Didn't realise this was handled by way of an accompanying flag, that does make sense :) -Toke