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=-1.0 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,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 B8C01C43381 for ; Sat, 23 Feb 2019 12:11:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 8B425206B6 for ; Sat, 23 Feb 2019 12:11:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727829AbfBWMLF convert rfc822-to-8bit (ORCPT ); Sat, 23 Feb 2019 07:11:05 -0500 Received: from mail-ed1-f65.google.com ([209.85.208.65]:37683 "EHLO mail-ed1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726271AbfBWMLE (ORCPT ); Sat, 23 Feb 2019 07:11:04 -0500 Received: by mail-ed1-f65.google.com with SMTP id m12so3977100edv.4 for ; Sat, 23 Feb 2019 04:11:03 -0800 (PST) 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=SXyOjeeTMn2NlHlO6ecG+U3lOLFvl+/YcHQwiShTyEA=; b=uA8ka5EXUd9LDAyKCIEqQ5wHsI+KLJ2P222Z2WEMMdT7fldf/oGDKls6vK2ffYuwmp bILb2K978Y2XJXf/2BhZGA+7B48vWZZOfEiB7Wgwq3m0rZ8zTnc3wD3NIgH0bU1a6LrI 0GNgfk8NAMFHRfxJvVKXSX7XzL2UqJI7iafOy92dAAC84DJ3H3CzGXI1OSokVRBDUIEp H/oBwfkz0YIvrBkvXJvX9Lqw5X8ABJTioM1BEUjcCfmVZrbtaCqs/ELUowcjtQKMcdkh FuYrlIWGhqjau2tJAXmidnL5Hy5wpa24KwKicysg4425mEKPHsfitTTlDlVvx67lAuRx UkDw== X-Gm-Message-State: AHQUAubv7tXbEueoC6o1gG/xAfpfHjRnfJynTB/0xERBwlm+0SGFhybj 7KAkYZsiPJK2Pma70npltpl9aw== X-Google-Smtp-Source: AHgI3IbC1G3tAPXQBjv13dhyc2nmkv+D7wtNkxsMHKVh0rCjBodRroZPEnlmRdWJ1yD0wGIGFW5lGQ== X-Received: by 2002:a50:b3bc:: with SMTP id s57mr6955619edd.206.1550923863076; Sat, 23 Feb 2019 04:11:03 -0800 (PST) Received: from alrua-x1.borgediget.toke.dk (borgediget.toke.dk. [85.204.121.218]) by smtp.gmail.com with ESMTPSA id o5sm1077606edd.24.2019.02.23.04.11.02 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sat, 23 Feb 2019 04:11:02 -0800 (PST) Received: by alrua-x1.borgediget.toke.dk (Postfix, from userid 1000) id 189DE18350A; Sat, 23 Feb 2019 13:11:02 +0100 (CET) From: Toke =?utf-8?Q?H=C3=B8iland-J=C3=B8rgensen?= To: Jesper Dangaard Brouer , Jakub Kicinski Cc: David Miller , netdev@vger.kernel.org, Daniel Borkmann , Alexei Starovoitov , brouer@redhat.com Subject: Re: [PATCH net-next 1/2] xdp: Always use a devmap for XDP_REDIRECT to a device In-Reply-To: <20190223114343.5813f18a@carbon> References: <155075021399.13610.12521373406832889226.stgit@alrua-x1> <20190221163627.7b8aa2ce@cakuba.netronome.com> <87va1cgmg1.fsf@toke.dk> <20190222133734.1880a88d@cakuba.netronome.com> <20190223114343.5813f18a@carbon> X-Clacks-Overhead: GNU Terry Pratchett Date: Sat, 23 Feb 2019 13:11:02 +0100 Message-ID: <875ztawvqh.fsf@toke.dk> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8BIT Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Jesper Dangaard Brouer writes: > On Fri, 22 Feb 2019 13:37:34 -0800 Jakub Kicinski wrote: > >> On Fri, 22 Feb 2019 11:13:50 +0100, Toke Høiland-Jørgensen wrote: >> > Jakub Kicinski writes: >> > > On Thu, 21 Feb 2019 12:56:54 +0100, Toke Høiland-Jørgensen wrote: > [...] >> > > >> > > BPF programs don't obey by netns boundaries. The fact the program is >> > > verified in one ns doesn't mean this is the only ns it will be used in :( >> > > Meaning if any program is using the redirect map you may need a secret >> > > map in every ns.. no? >> > >> > Ah, yes, good point. Totally didn't think about the fact that load and >> > attach are decoupled. Hmm, guess I'll just have to move the call to >> > alloc_default_map() to the point where the program is attached to an >> > interface, then... >> >> Possibly.. and you also need to handle the case where interface with a >> program attached is moved, no? Yup, alloc on attach was easy enough; the moving turns out to be the tricky part :) > True, we need to handle if e.g. a veth gets an XDP program attached and > then is moved into a network namespace (as I've already explained to > Toke in a meeting). Yeah, I had somehow convinced myself that the XDP program was being removed when the interface was being torn down before moving between namespaces. Jesper pointed out that this was not in fact the case... :P > I'm still not sure how to handle this... There are a couple of options, I think. At least: 1. Maintain a flag on struct net_device indicating that this device needs the redirect map allocated, and react to that when interfaces are being moved. 2. Lookup the BPF program by ID (which we can get from the driver) on move, and react to the program flag. 3. Keep the allocation on program load, but allocate maps for all active namespaces (which would probably need a refcnt mechanism to deallocate things again). I think I'm leaning towards #2; possibly combined with a refcnt so we can actually deallocate the map in the root namespace when it's not needed anymore. -Toke