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=-4.0 required=3.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SPF_PASS,URIBL_BLOCKED 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 F3961C43381 for ; Fri, 22 Feb 2019 21:37:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id BD9E2206BB for ; Fri, 22 Feb 2019 21:37:42 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=netronome-com.20150623.gappssmtp.com header.i=@netronome-com.20150623.gappssmtp.com header.b="ehT/OW0A" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726023AbfBVVhl (ORCPT ); Fri, 22 Feb 2019 16:37:41 -0500 Received: from mail-qt1-f195.google.com ([209.85.160.195]:32908 "EHLO mail-qt1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725936AbfBVVhl (ORCPT ); Fri, 22 Feb 2019 16:37:41 -0500 Received: by mail-qt1-f195.google.com with SMTP id z39so4274383qtz.0 for ; Fri, 22 Feb 2019 13:37:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=netronome-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:in-reply-to:references :organization:mime-version:content-transfer-encoding; bh=888nRsho4mQ57gvwRYZ5mfBcRiDNZJu4gmD4vIY9pjE=; b=ehT/OW0A8o/WsWpjS8u0i3HTgbsSUhXMbQmFdmFaFOpt2hnjDeNhnlWIbWju+TVA6E E7lZcYd9HgIAolWvAumo8UtaN+lpPYVSEunAaKpWRw+Hhw9tkFz/A/bs+9vj4z0D47TA LvcDayXw0Msd4+DasdwFVqPMRb7iNY+yDBEoPbZP24Hh9RZhk7Pn4FriNARCEBjXR4P/ J4rtI1mUemR92FBejoYOhM3IccBGiOb4TFoT/hz0sixwsiUEeHL6+h8utQ1mjwOPB0Jq W7Nic6YjlAPSMKfIzUXp+qeGfNRDSczO73pMWITlSdJ9V1qYSCaWi6FwQsGaZtJhUmlz KhaQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:in-reply-to :references:organization:mime-version:content-transfer-encoding; bh=888nRsho4mQ57gvwRYZ5mfBcRiDNZJu4gmD4vIY9pjE=; b=OOGqejbnXVTauzwhRPPGH7OgqGHMeCetqXfDajy7aqMk5wFCzZTjLCp4NAe7bY7wES gTUGroPoRmqnoYcA6lNwxs93LX1lgFJS9sR6Wf+C3RZY8HQ/N2Cl5op0BshyATTdZ9im UYSQCc0JJR2YpGi0O9lYJQ2AA3/SbgR97lUz89lQv9m3o2gu7yPcS3PEqha1ZCYA2e1Z 815j69WH/c2tVQvNh+xtjB5/g8A9ZG3LQASgEtnxHvpWqgb2uoBc/fNAdo2k3xxTiaYx 3VLWnBfeyWG1Td0cEijpH1ZP7dCvaZdf6jOmLI46fWb13JiQl2uSyUHkatSIzy77FP3C 7ybg== X-Gm-Message-State: AHQUAub2N3rSquN2b6kRrnt5JLuyt8HOQr3UrbZYAl94cjLJdyUbuc6S 2+a7r2/oDPKqM09k4qhryYoU6CdcVdw= X-Google-Smtp-Source: AHgI3IYT5if16k/ooVQCtW35Qk8xqbERh76lBVjdtIWHBBGLC9gTbb8Y8aZKrL443tQkrCZy8sXWsg== X-Received: by 2002:a0c:92e1:: with SMTP id c30mr4773159qvc.159.1550871459828; Fri, 22 Feb 2019 13:37:39 -0800 (PST) Received: from cakuba.netronome.com ([66.60.152.14]) by smtp.gmail.com with ESMTPSA id n2sm1911658qtc.13.2019.02.22.13.37.38 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 22 Feb 2019 13:37:39 -0800 (PST) Date: Fri, 22 Feb 2019 13:37:34 -0800 From: Jakub Kicinski To: Toke =?UTF-8?B?SMO4aWxhbmQtSsO4cmdlbnNlbg==?= Cc: David Miller , netdev@vger.kernel.org, Jesper Dangaard Brouer , Daniel Borkmann , Alexei Starovoitov Subject: Re: [PATCH net-next 1/2] xdp: Always use a devmap for XDP_REDIRECT to a device Message-ID: <20190222133734.1880a88d@cakuba.netronome.com> In-Reply-To: <87va1cgmg1.fsf@toke.dk> References: <155075021399.13610.12521373406832889226.stgit@alrua-x1> <20190221163627.7b8aa2ce@cakuba.netronome.com> <87va1cgmg1.fsf@toke.dk> Organization: Netronome Systems, Ltd. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org On Fri, 22 Feb 2019 11:13:50 +0100, Toke H=C3=B8iland-J=C3=B8rgensen wrote: > Jakub Kicinski writes: > > On Thu, 21 Feb 2019 12:56:54 +0100, Toke H=C3=B8iland-J=C3=B8rgensen wr= ote: =20 > >> diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c > >> index b63bc77af2d1..629661db36ee 100644 > >> --- a/kernel/bpf/verifier.c > >> +++ b/kernel/bpf/verifier.c > >> @@ -7527,6 +7527,12 @@ static int fixup_bpf_calls(struct bpf_verifier_= env *env) > >> prog->dst_needed =3D 1; > >> if (insn->imm =3D=3D BPF_FUNC_get_prandom_u32) > >> bpf_user_rnd_init_once(); > >> + if (insn->imm =3D=3D BPF_FUNC_redirect) { > >> + int err =3D dev_map_alloc_default_map(); > >> + > >> + if (err) > >> + return err; > >> + } > >> if (insn->imm =3D=3D BPF_FUNC_override_return) > >> prog->kprobe_override =3D 1; > >> if (insn->imm =3D=3D BPF_FUNC_tail_call) { =20 > > =20 > >> +int dev_map_alloc_default_map(void) > >> +{ > >> + struct net *net =3D current->nsproxy->net_ns; > >> + struct bpf_dtab *dtab, *old_dtab; > >> + struct net_device *netdev; > >> + union bpf_attr attr =3D {}; > >> + u32 idx; > >> + int err; =20 > > > > 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? =20 >=20 > 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? > I trust it's safe to skip the allocation in case the program is > offloaded to hardware, right? I.e., an offloaded program will never need > to fall back to the kernel helper? We will cross that bridge when we get there ;) I'd definitely want the ability to do a redirect to a non-offloaded netdev (e.g. redirect to a veth) via some fallback, but the plan is to try to only add support for the map version of redirect on offload, anyway.