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=-6.6 required=3.0 tests=FROM_EXCESS_BASE64, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS autolearn=ham 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 482B7C31E4A for ; Wed, 12 Jun 2019 18:39:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 1FC82206E0 for ; Wed, 12 Jun 2019 18:39:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728579AbfFLSja (ORCPT ); Wed, 12 Jun 2019 14:39:30 -0400 Received: from mga09.intel.com ([134.134.136.24]:21282 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726475AbfFLSja (ORCPT ); Wed, 12 Jun 2019 14:39:30 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 12 Jun 2019 11:39:29 -0700 X-ExtLoop1: 1 Received: from unknown (HELO btopel-mobl.ger.intel.com) ([10.255.41.153]) by orsmga002.jf.intel.com with ESMTP; 12 Jun 2019 11:39:23 -0700 Subject: Re: [PATCH bpf-next] net: Don't uninstall an XDP program when none is installed To: Maxim Mikityanskiy , Alexei Starovoitov , Daniel Borkmann Cc: "bpf@vger.kernel.org" , "netdev@vger.kernel.org" , "David S. Miller" , Saeed Mahameed , Jakub Kicinski , Jesper Dangaard Brouer , John Fastabend , Martin KaFai Lau , Song Liu , Yonghong Song References: <20190612161405.24064-1-maximmi@mellanox.com> From: =?UTF-8?B?QmrDtnJuIFTDtnBlbA==?= Message-ID: Date: Wed, 12 Jun 2019 20:39:22 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.7.0 MIME-Version: 1.0 In-Reply-To: <20190612161405.24064-1-maximmi@mellanox.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit Sender: bpf-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org On 2019-06-12 18:14, Maxim Mikityanskiy wrote: > dev_change_xdp_fd doesn't perform any checks in case it uninstalls an > XDP program. It means that the driver's ndo_bpf can be called with > XDP_SETUP_PROG asking to set it to NULL even if it's already NULL. This > case happens if the user runs `ip link set eth0 xdp off` when there is > no XDP program attached. > > The drivers typically perform some heavy operations on XDP_SETUP_PROG, > so they all have to handle this case internally to return early if it > happens. This patch puts this check into the kernel code, so that all > drivers will benefit from it. > > Signed-off-by: Maxim Mikityanskiy > --- > Björn, please take a look at this, Saeed told me you were doing > something related, but I couldn't find it. If this fix is already > covered by your work, please tell about that. > Yeah, I'm trying make the query code more generic (pull common work out from the drivers). However, my patch set is still not done (I'll try to get a v4 out this week), but your improvement is! I don't see why this should be held back because of my still not finished work. I like this. Acked-by: Björn Töpel > net/core/dev.c | 3 +++ > 1 file changed, 3 insertions(+) > > diff --git a/net/core/dev.c b/net/core/dev.c > index 66f7508825bd..68b3e3320ceb 100644 > --- a/net/core/dev.c > +++ b/net/core/dev.c > @@ -8089,6 +8089,9 @@ int dev_change_xdp_fd(struct net_device *dev, struct netlink_ext_ack *extack, > bpf_prog_put(prog); > return -EINVAL; > } > + } else { > + if (!__dev_xdp_query(dev, bpf_op, query)) > + return 0; > } > > err = dev_xdp_install(dev, bpf_op, extack, flags, prog); >