Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1365603pxb; Wed, 10 Feb 2021 06:54:27 -0800 (PST) X-Google-Smtp-Source: ABdhPJx9nHOqK+n8EqTqtVIidU2lQEMT+zvQn/2qXidpOoGKtK8jbs/TDMj1UQizsOnmCWA8ZftE X-Received: by 2002:aa7:d80b:: with SMTP id v11mr3485405edq.17.1612968866879; Wed, 10 Feb 2021 06:54:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612968866; cv=none; d=google.com; s=arc-20160816; b=kn0FE6ElKQqoOMIGyd4bcdup5Ykcjo6gwVbcJ448OcJwXOagiQjDb/i4eKVwLzKZrD BWJsjsA4y0H1ohoqMBiPoCDsftVp0mg05DYejDuhs2Wl8AT4nmabU2GAD9zq/D8yNDqv j2EnqF9FcfqHKRrtACUpVgiEWtAWGSFPzxphwG07NAoocBIe+Lg6bikK2lo6MSVLK8Zi zYs+0kPvix7lrqE7i6aMxuRLDVHEwDzMEo0SvF1xStk5oWARxGCKaI6MLQn0ji8Jp7rP B5KcNL1z/z9XXAoEBFQSs7V2iWuoQy5rcvDtSl1j3vXhLiGBwFhgW+m8F70NRg5XHe4O AYVA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject:dkim-signature; bh=zjhXKo3lnsUCaAO03EAAKy7XedvCevX8vo7EKjAoj3Q=; b=yQjsHBTYU88L39SQZOhoEVmr4EEtddSWGI9HJipVX6HeEbf2F5WxhSKX1kJm69y5gD zmASwerw03PGGDSa5EmnCglLOstwC7ulDE8ZrOIspVoF928KDKY5kHR8A8zQNW5/9WMf Bmr/Wm702CiUVszNpRQFcEGt0SPgTERhOu7g7mrLZ3fzy+wItLOs+ASIukLvfJaEDui5 doSkhWf+nLqBN2gmMzPY+dslVwzwRFPs6mgu24qIyNsdsOdE4c9Df9T3SYXVidmzBo4Q wi4Lz/bBhvlfk7oXHHYxutDtCvmMzIaXbk1Zc8QlngED+4yN7DzAJS8DmM1M9CjQdRhS JNkQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=jJ8LF025; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a67si1595061edf.198.2021.02.10.06.54.03; Wed, 10 Feb 2021 06:54:26 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=jJ8LF025; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231626AbhBJOwW (ORCPT + 99 others); Wed, 10 Feb 2021 09:52:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46360 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229888AbhBJOwS (ORCPT ); Wed, 10 Feb 2021 09:52:18 -0500 Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com [IPv6:2a00:1450:4864:20::334]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9FEEDC06174A; Wed, 10 Feb 2021 06:51:36 -0800 (PST) Received: by mail-wm1-x334.google.com with SMTP id m1so2069215wml.2; Wed, 10 Feb 2021 06:51:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=zjhXKo3lnsUCaAO03EAAKy7XedvCevX8vo7EKjAoj3Q=; b=jJ8LF025NOB5tTRRmh45iSwVNW9BiH2jesDquvAlwBgGfOycUUj9SneIWmt0+ZsKNg G4jfNkdmBdVwNrf6KziMjZyDhDfsh0VTabiZ88CqjMSEyWAAB9KcF0LqWF574ojQJWfB uEcBjTGL5J1sN7VltBi5masq/ykxXWJ71FekRuG1mMOVHDXcYAaB69OZ0pm/EZyGUojM E8ghijNjy9n51CKDhciWDBttcc7mGU9VLnekLrNRsHhHEJw6eo3kNbDjNnFbJryP9S1m HqCjtV55tT0SgA+5jTrOqavLEvYCCRxhlE/v9SL/9kkxp+24Qjc3js9+kLYBwSORR2i+ /jyg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=zjhXKo3lnsUCaAO03EAAKy7XedvCevX8vo7EKjAoj3Q=; b=N0NSqR7UJcDgyWO/9pfk5rjy2qj1WSru0YnBPESxmPdaloVurwSjVrzHn/driXgDQM X8PTlMUwGV+XNd5qs0dXNxnTsJb5M30fE0w1ArsgkhiUCZyzeLEKkWGsNvSNAeZDsDnX ilsW5+XVTDaY3mNDCphDp2uNFHELY4tVL2cXhPNbbLhOnEWaB+BRJQcbq3KNieNy//VO 8JjWI6bEwRS/C7W1WLSfxk9xnAtS4qYzAK3/pvxkpZYWoqoGbDSbwTsGVMnr/77IJIis sjUfvH2B6MKjv03KQhYOiSCqc7V+f63nn4HtGvWg4cBZ8VZngZoV4983t1EGrM7v8cd9 R7gA== X-Gm-Message-State: AOAM531BYnuYLAHIBaTrzjxGkPbQjsCpPNQkflsWWmmPHZW69fhi1GwZ 2VZSz06yZmbgh2SjqBfr8yxc40ffyFE= X-Received: by 2002:a1c:67c3:: with SMTP id b186mr3336454wmc.24.1612968695135; Wed, 10 Feb 2021 06:51:35 -0800 (PST) Received: from [192.168.1.101] ([37.170.168.78]) by smtp.gmail.com with ESMTPSA id v15sm4054700wra.61.2021.02.10.06.51.33 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 10 Feb 2021 06:51:34 -0800 (PST) Subject: Re: [PATCH bpf 1/4] net: add SO_NETNS_COOKIE socket option To: Lorenz Bauer , Richard Henderson , Ivan Kokshaysky , Matt Turner , Thomas Bogendoerfer , "James E.J. Bottomley" , Helge Deller , "David S. Miller" , Arnd Bergmann , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Jakub Kicinski Cc: kernel-team@cloudflare.com, linux-api@vger.kernel.org, linux-alpha@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mips@vger.kernel.org, linux-parisc@vger.kernel.org, sparclinux@vger.kernel.org, linux-arch@vger.kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org References: <20210210120425.53438-1-lmb@cloudflare.com> <20210210120425.53438-2-lmb@cloudflare.com> From: Eric Dumazet Message-ID: Date: Wed, 10 Feb 2021 15:51:32 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.6.1 MIME-Version: 1.0 In-Reply-To: <20210210120425.53438-2-lmb@cloudflare.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2/10/21 1:04 PM, Lorenz Bauer wrote: > We need to distinguish which network namespace a socket belongs to. > BPF has the useful bpf_get_netns_cookie helper for this, but accessing > it from user space isn't possible. Add a read-only socket option that > returns the netns cookie, similar to SO_COOKIE. If network namespaces > are disabled, SO_NETNS_COOKIE returns the cookie of init_net. > > The BPF helpers change slightly: instead of returning 0 when network > namespaces are disabled we return the init_net cookie as for the > socket option. > > Cc: linux-api@vger.kernel.org > Signed-off-by: Lorenz Bauer > --- ... > > +static inline u64 __sock_gen_netns_cookie(struct sock *sk) > +{ > +#ifdef CONFIG_NET_NS > + return __net_gen_cookie(sk->sk_net.net); > +#else > + return __net_gen_cookie(&init_net); > +#endif > +} > + > +static inline u64 sock_gen_netns_cookie(struct sock *sk) > +{ > + u64 cookie; > + > + preempt_disable(); > + cookie = __sock_gen_netns_cookie(sk); > + preempt_enable(); > + > + return cookie; > +} > + > I suggest we make net->net_cookie a mere u64 initialized in setup_net(), instead of having to preempt_disable() around reading it. (Here and in your patch 2/4) Your patches would be much simpler. Cleanup patch : https://patchwork.kernel.org/project/netdevbpf/patch/20210210144144.24284-1-eric.dumazet@gmail.com/