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 2036CC433EF for ; Wed, 11 May 2022 06:10:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232202AbiEKGKt (ORCPT ); Wed, 11 May 2022 02:10:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36548 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229899AbiEKGKs (ORCPT ); Wed, 11 May 2022 02:10:48 -0400 Received: from mail-pj1-x1036.google.com (mail-pj1-x1036.google.com [IPv6:2607:f8b0:4864:20::1036]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AE104205EE; Tue, 10 May 2022 23:10:45 -0700 (PDT) Received: by mail-pj1-x1036.google.com with SMTP id x88so1298964pjj.1; Tue, 10 May 2022 23:10:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=Rxwmw7F4yraTtQttPtF/0wZ/ikGq2Rscn+f5iMrT7V8=; b=hk5nmcxWqr1+4XZIG4Y2EoHdn4MFyQuBSg3wMbJB03xCN3J0/fGQJI9kJKzQLLlWfP ZDVe37fm/UkBmm/PkjCtG1P4jelVut0rqGMNUuM6eaNwDqMDWJXOAVNl43inn/9fzuiX 08PIOuW+zLnKULD33PrfJiIhTaBGApajk5KJgbDuUBGdDqvD325R1qkKy6xn2plIZWb6 q0aQvfYNQ6zMw9ug/iMN/mRFoKLZLTd/4HF2ZzjOoZxf4gLk0u7t38GhennBESJ0W/R3 gpWBhIKHac6jv9zJ8sSWOg69s2c3x674NJk5GSfVmEAeoaiakgRb0u/l55Wh9RH3czUw sUqA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=Rxwmw7F4yraTtQttPtF/0wZ/ikGq2Rscn+f5iMrT7V8=; b=wYldsW1JXUalSrSHKRfmylqPaxvLv3fbH5+8XCpmWHWujyespPWtDMZFl/OhQQIeuF xN6sSG3THp+7hC+NeJHCqfYak2dtQAEgqOMTUF03TJXRFb4LF2iOlngGUZUODzmGZ3Ic 9xybs+godMM4/tPZH9Q0aDO1dJDHmDLSJ17gGpLVAD83Hs4Sxa9SZsSIEZdBDHiLR5qJ DZZlO80ePidx8M9oxFVzHntQfBotPAK3APKc/u4wp+6sA4oKTXCcSmt3yN3ZSUlkzKYh wI7nm3HKLd9l3bB48Wt5+szB9sszQZJAs1y2hpMPBzqlEpZq1VH2kmw9VrYEsFHNgyTf Jo9A== X-Gm-Message-State: AOAM5332wQMR0n45xZCerDPjr3xV7gf+k0OxDq9WS6rP1uYIi4Gc9gG1 IaqFJD5bZGodb8djffbq3tfKdwNyBuwQc8CzyzrOOM/97bk= X-Google-Smtp-Source: ABdhPJyvXv/OGzpotKsy1AIe0kD136J2PA88iaQfJStWhn17wXqCV6y8+g7+UBAut26mWSxafLKVkQRZipa4VxIIYG4= X-Received: by 2002:a17:902:8f8d:b0:15b:7b98:22e6 with SMTP id z13-20020a1709028f8d00b0015b7b9822e6mr23907991plo.102.1652249445174; Tue, 10 May 2022 23:10:45 -0700 (PDT) MIME-Version: 1.0 References: <20220502211235.142250-1-mathew.j.martineau@linux.intel.com> <20220502211235.142250-2-mathew.j.martineau@linux.intel.com> <20220511004818.qnfpzgepmg7xufwd@kafai-mbp.dhcp.thefacebook.com> In-Reply-To: From: Geliang Tang Date: Wed, 11 May 2022 14:10:42 +0800 Message-ID: Subject: Re: [PATCH bpf-next v3 1/8] bpf: expose is_mptcp flag to bpf_tcp_sock To: Andrii Nakryiko Cc: Martin KaFai Lau , Mat Martineau , Andrii Nakryiko , Networking , bpf , Nicolas Rybowski , Alexei Starovoitov , Daniel Borkmann , MPTCP Upstream , Matthieu Baerts Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org Andrii Nakryiko =E4=BA=8E2022=E5=B9=B45=E6=9C= =8811=E6=97=A5=E5=91=A8=E4=B8=89 13:02=E5=86=99=E9=81=93=EF=BC=9A > > On Tue, May 10, 2022 at 5:48 PM Martin KaFai Lau wrote: > > > > On Mon, May 02, 2022 at 02:12:27PM -0700, Mat Martineau wrote: > > > From: Nicolas Rybowski > > > > > > is_mptcp is a field from struct tcp_sock used to indicate that the > > > current tcp_sock is part of the MPTCP protocol. > > > > > > In this protocol, a first socket (mptcp_sock) is created with > > > sk_protocol set to IPPROTO_MPTCP (=3D262) for control purpose but it > > > isn't directly on the wire. This is the role of the subflow (kernel) > > > sockets which are classical tcp_sock with sk_protocol set to > > > IPPROTO_TCP. The only way to differentiate such sockets from plain TC= P > > > sockets is the is_mptcp field from tcp_sock. > > > > > > Such an exposure in BPF is thus required to be able to differentiate > > > plain TCP sockets from MPTCP subflow sockets in BPF_PROG_TYPE_SOCK_OP= S > > > programs. > > > > > > The choice has been made to silently pass the case when CONFIG_MPTCP = is > > > unset by defaulting is_mptcp to 0 in order to make BPF independent of > > > the MPTCP configuration. Another solution is to make the verifier fai= l > > > in 'bpf_tcp_sock_is_valid_ctx_access' but this will add an additional > > > '#ifdef CONFIG_MPTCP' in the BPF code and a same injected BPF program > > > will not run if MPTCP is not set. > > There is already bpf_skc_to_tcp_sock() and its returned tcp_sock pointe= r > > can access all fields of the "struct tcp_sock" without extending > > the bpf_tcp_sock. > > > > iiuc, I believe the needs to extend bpf_tcp_sock here is to make the > > same bpf sockops prog works for kernel with and without CONFIG_MPTCP > > because tp->is_mptcp is not always available: > > > > struct tcp_sock { > > /* ... */ > > > > #if IS_ENABLED(CONFIG_MPTCP) > > bool is_mptcp; > > #endif > > }; > > > > Andrii, do you think bpf_core_field_exists() can be used in > > the bpf prog to test if is_mptcp is available in the running kernel > > such that the same bpf prog can be used in kernel with and without > > CONFIG_MPTCP? > > yep, absolutely: > > bool is_mptcp =3D bpf_core_field_exists(struct tcp_sock, is_mptcp) ? > sock->is_mptcp : false; > > One can also directly check if CONFIG_MPTCP is set with the following > in BPF-side code: > > extern bool CONFIG_MPTCP __kconfig; Thanks Martin & Andrii, will update this in v4. -Geliang SUSE >