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 Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CB854C433FE for ; Thu, 5 May 2022 14:27:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232839AbiEEObU (ORCPT ); Thu, 5 May 2022 10:31:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56114 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229570AbiEEObR (ORCPT ); Thu, 5 May 2022 10:31:17 -0400 Received: from us-smtp-delivery-74.mimecast.com (us-smtp-delivery-74.mimecast.com [170.10.129.74]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 06941AE46 for ; Thu, 5 May 2022 07:27:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1651760857; 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: in-reply-to:in-reply-to:references:references; bh=hz8cN3gu7AH5J5jQIlr6+13kmwxut9ycO89aQGaXRjo=; b=gGm/eOSLp7Gr5275ZDi6X+l0di8QO+vvX9DFTdCCoTMe8dqlt0SpB6BCoyaBNmc4JZLU2G YgYm0EiLUSHLx4m63XqWTuKN0rx6O//xuWZxIcCI2ENjvMEiy0Ny6wYv/DvKUQd96KEuxU 0rtDIICTfh7cdY0BCobNsgqbb08vilQ= Received: from mail-ed1-f70.google.com (mail-ed1-f70.google.com [209.85.208.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-111-Y_1Qq3JJMj6nqwpw2ohXEA-1; Thu, 05 May 2022 10:27:36 -0400 X-MC-Unique: Y_1Qq3JJMj6nqwpw2ohXEA-1 Received: by mail-ed1-f70.google.com with SMTP id s24-20020a05640217d800b00425e19e7deaso2414321edy.3 for ; Thu, 05 May 2022 07:27:35 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:in-reply-to:references:date :message-id:mime-version; bh=hz8cN3gu7AH5J5jQIlr6+13kmwxut9ycO89aQGaXRjo=; b=Z7G05LmAXd9mP8AKtVLOJQ9/mlE3pg9UrIZOyWvred+aPbTAQHoT9XbdHofNBkvmqS pngHHgH9aybHGSr/AlB5ykWrVSV8pCtQ+/LIZL4jrerrNu3DiRWwDp1N/fXGzrnUCCJg eb8Tj5YQ2UNRypyMp+5gLwPOZhE7CSRd+L/FECczP1qYxtw9nlFPrUpUw7+pl7xzXRnM o7hnSiwHj+6pnDEEmhzD4/s/MBBRDc0gfZDre0zpxtdvG7qAezHecat1i42bPtZSxUGl M/3G4S2CGb5r57ESiaAyfMtu9Y+46kTtZmlPiPNyqFU4bx/ocQ1F7vm6j+kBTLOKk3dA k48Q== X-Gm-Message-State: AOAM53284q+qHik7JQgvYY93U0dO1tzA9atEKFH3Y8c885PU/pyLTi40 Kl0jqN3S+6k+CTHws+qF08yzwX+wDVEBo42dxtAY3SXUDbdsOzAlEG44L7z0nQm+SwsOPHjRRXA 6T2cemT9J1JHpTnm1VA24i89B X-Received: by 2002:a17:907:6294:b0:6e1:ea4:74a3 with SMTP id nd20-20020a170907629400b006e10ea474a3mr26223923ejc.168.1651760854354; Thu, 05 May 2022 07:27:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwv7wnqPWL1ffvs/IM4PL/CBY4zMVBL4inCsI3m/n3fhEsCLH0JW5UDS797AgWj/J9aY6TrsQ== X-Received: by 2002:a17:907:6294:b0:6e1:ea4:74a3 with SMTP id nd20-20020a170907629400b006e10ea474a3mr26223834ejc.168.1651760853491; Thu, 05 May 2022 07:27:33 -0700 (PDT) Received: from alrua-x1.borgediget.toke.dk ([2a0c:4d80:42:443::2]) by smtp.gmail.com with ESMTPSA id k20-20020a170906971400b006f3ef214dc9sm805808ejx.47.2022.05.05.07.27.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 May 2022 07:27:32 -0700 (PDT) Received: by alrua-x1.borgediget.toke.dk (Postfix, from userid 1000) id B4CF734D4E7; Thu, 5 May 2022 16:27:31 +0200 (CEST) From: Toke =?utf-8?Q?H=C3=B8iland-J=C3=B8rgensen?= To: shaozhengchao , "netdev@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "bpf@vger.kernel.org" , "davem@davemloft.net" , "edumazet@google.com" , "kuba@kernel.org" , "pabeni@redhat.com" Cc: "ast@kernel.org" , "daniel@iogearbox.net" , "hawk@kernel.org" , "john.fastabend@gmail.com" , "andrii@kernel.org" , "kafai@fb.com" , "songliubraving@fb.com" , "yhs@fb.com" , "kpsingh@kernel.org" , "bigeasy@linutronix.de" , "imagedong@tencent.com" , "petrm@nvidia.com" , "memxor@gmail.com" , "arnd@arndb.de" , "weiyongjun (A)" , yuehaibing Subject: Re: =?utf-8?B?562U5aSNOg==?= [PATCH bpf-next] bpf/xdp: Can't detach BPF XDP prog if not exist In-Reply-To: <594b5198d54c4c729728c20d167d9c2d@huawei.com> References: <20220504035207.98221-1-shaozhengchao@huawei.com> <875ymlwnmy.fsf@toke.dk> <594b5198d54c4c729728c20d167d9c2d@huawei.com> X-Clacks-Overhead: GNU Terry Pratchett Date: Thu, 05 May 2022 16:27:31 +0200 Message-ID: <87tua43vho.fsf@toke.dk> MIME-Version: 1.0 Content-Type: text/plain Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org shaozhengchao writes: > Thank you for your reply. I wiil change sample application firstly. > But if kernel does nothing and return 0, maybe user will think setup > is OK, actually It failed. Is this acceptable? Your patch was about detach; what has that got to do with "setup is OK"? As for detaching, it's possible to write the application in a way that it will always get a consistent result. There are basically two cases when using netlink to detach an XDP program (bpf_link has its own semantics, so setting that aside here): 1. The application just wants to turn off XDP entirely on the interface (e.g., 'ip link set dev XXX xdp off'). In this case you just send a RTM_SETLINK message with an IFLA_XDP_FD of -1, and if you don't get an error you can be sure that there is now no XDP program attached. Whether this was because there was already no program attached, or because you just detached it doesn't really matter in this case, since you're doing an unspecific detach anyway. 2. You attached a program earlier, and now you want to detach that (and only that) program. Or, equivalently, you queried the link and want to detach the program you know is attached there. In this case you send an RTM_SETLINK message with an IFLA_XDP_FD of -1 and an IFLA_XDP_EXPECTED_FD referring to the existing program. In this case you will get an error if that specific program is not in fact attached, whether because it was detached or swapped out in the meantime. I don't see how case 1. is improved by returning ENOENT if there is no program attached; if you care about detaching a specific program you'd use case 2. anyway, and if you just want to check if a program is attached, you'd do an RTM_GETLINK. -Toke