From patchwork Wed Nov 30 14:42:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Toke_H=C3=B8iland-J=C3=B8rgensen?= X-Patchwork-Id: 13059997 X-Patchwork-Delegate: bpf@iogearbox.net 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 16C80C4332F for ; Wed, 30 Nov 2022 14:43:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229591AbiK3Ons (ORCPT ); Wed, 30 Nov 2022 09:43:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41984 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229461AbiK3Onq (ORCPT ); Wed, 30 Nov 2022 09:43:46 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ED4C8183BD for ; Wed, 30 Nov 2022 06:42:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1669819369; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=crVCumDlTSh3ITTn1/1f42ksAkShS/hhF76AM8JHUUU=; b=QtizwF3FnSbXQPTChEr9jLlRJdGEKTY+3x06jmz0C2Fk4YyN6AB0xCVxu7BGMCrEDJqd8G JANNU9lZVqGwE26myBgFtVpbCCTTXXW+m2mvOjU2e0w+Y94ibZtQTJPwBP0ShRyG8N5eEm 8GZGIyI3iqVgJzgwytU/2oMIJC9zXxg= Received: from mail-ej1-f72.google.com (mail-ej1-f72.google.com [209.85.218.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-260-A--sjsrHPhWaZ2C3-UUqVA-1; Wed, 30 Nov 2022 09:42:48 -0500 X-MC-Unique: A--sjsrHPhWaZ2C3-UUqVA-1 Received: by mail-ej1-f72.google.com with SMTP id sh37-20020a1709076ea500b007c09b177cd1so1841157ejc.12 for ; Wed, 30 Nov 2022 06:42:47 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=crVCumDlTSh3ITTn1/1f42ksAkShS/hhF76AM8JHUUU=; b=qqrmf1OF+7c1HyUEPMUKLeJe78JGLzK6uNyIu39CW0UFopkG2Maj9i9r08ypF71PnW QZaAyhOUQWEWF6NvfcB2ZYT3sIH9v8+RbOxgJtogNBTFqFg0iNjN+SS+7SLymETbIcIL 7352/dS6wGomOLRJSi2Ki2Nz4gX568E65JRyFYpYO9XvMYnWcazXegYi03s9UlITe6W/ aNNBArmrAFtziSZBIl6sbQ9q2FvbE8r5mKwJ/QePJmg4lqawnViJ12t5xoS1r+2CVHuh kIimfVrZM8Q0lw3WDEPc9+H9WWwo+2xEGknY0q8Gfmn9kjFZTb6hodgmxHxnfgvIEA25 7asg== X-Gm-Message-State: ANoB5pl3SOpo8jypzVJPCs6lwyhBwMk++cHkfX5axP4+Gz82FG6CpPDG WZv7W1FdqrQXxM153w06fP2Tq8P9Wc1q5tTmz7wmZKRCPe4Vtna+tZULDIM3wozkZpNHsXiKz8q dafXwpKi1jiEeF3eE X-Received: by 2002:a05:6402:68c:b0:461:b506:6b8a with SMTP id f12-20020a056402068c00b00461b5066b8amr55986249edy.208.1669819365117; Wed, 30 Nov 2022 06:42:45 -0800 (PST) X-Google-Smtp-Source: AA0mqf7wdBNsOHHoOR7LIpapj/cFK+5DQiHiWjSP+unOpa4buIm9tnAkYDfRzgP9Ht5etXIxzIhVDw== X-Received: by 2002:a05:6402:68c:b0:461:b506:6b8a with SMTP id f12-20020a056402068c00b00461b5066b8amr55986089edy.208.1669819362601; Wed, 30 Nov 2022 06:42:42 -0800 (PST) Received: from alrua-x1.borgediget.toke.dk ([2a0c:4d80:42:443::2]) by smtp.gmail.com with ESMTPSA id x10-20020a1709060a4a00b00741a251d9e8sm710764ejf.171.2022.11.30.06.42.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Nov 2022 06:42:42 -0800 (PST) Received: by alrua-x1.borgediget.toke.dk (Postfix, from userid 1000) id 5847D80ADF3; Wed, 30 Nov 2022 15:42:41 +0100 (CET) From: =?utf-8?q?Toke_H=C3=B8iland-J=C3=B8rgensen?= To: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , "David S. Miller" , Jakub Kicinski , Jesper Dangaard Brouer , Lorenzo Bianconi Cc: Kumar Kartikeya Dwivedi , Jiri Benc , =?utf-8?q?Toke_H=C3=B8iland-J=C3=B8rgensen?= , Eric Dumazet , Paolo Abeni , bpf@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH bpf 1/2] bpf: Add dummy type reference to nf_conn___init to fix type deduplication Date: Wed, 30 Nov 2022 15:42:39 +0100 Message-Id: <20221130144240.603803-1-toke@redhat.com> X-Mailer: git-send-email 2.38.1 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net The bpf_ct_set_nat_info() kfunc is defined in the nf_nat.ko module, and takes as a parameter the nf_conn___init struct, which is allocated through the bpf_xdp_ct_alloc() helper defined in the nf_conntrack.ko module. However, because kernel modules can't deduplicate BTF types between each other, and the nf_conn___init struct is not referenced anywhere in vmlinux BTF, this leads to two distinct BTF IDs for the same type (one in each module). This confuses the verifier, as described here: https://lore.kernel.org/all/87leoh372s.fsf@toke.dk/ As a workaround, add a dummy pointer to the type in net/filter.c, so the type definition gets included in vmlinux BTF. This way, both modules can refer to the same type ID (as they both build on top of vmlinux BTF), and the verifier is no longer confused. Fixes: 820dc0523e05 ("net: netfilter: move bpf_ct_set_nat_info kfunc in nf_nat_bpf.c") Signed-off-by: Toke Høiland-Jørgensen --- net/core/filter.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/net/core/filter.c b/net/core/filter.c index bb0136e7a8e4..1bdf9efe8593 100644 --- a/net/core/filter.c +++ b/net/core/filter.c @@ -80,6 +80,7 @@ #include #include #include +#include static const struct bpf_func_proto * bpf_sk_base_func_proto(enum bpf_func_id func_id); @@ -11531,3 +11532,17 @@ bpf_sk_base_func_proto(enum bpf_func_id func_id) return func; } + +#if IS_MODULE(CONFIG_NF_CONNTRACK) && IS_ENABLED(CONFIG_DEBUG_INFO_BTF_MODULES) +/* The nf_conn___init type is used in the NF_CONNTRACK kfuncs. The kfuncs are + * defined in two different modules, and we want to be able to use them + * interchangably with the same BTF type ID. Because modules can't de-duplicate + * BTF IDs between each other, we need the type to be referenced in the vmlinux + * BTF or the verifier will get confused about the different types. So we add + * this dummy pointer to serve as a type reference which will be included in + * vmlinux BTF, allowing both modules to refer to the same type ID. + * + * We use a pointer as that is smaller than an instance of the struct. + */ +const struct nf_conn___init *ctinit; +#endif From patchwork Wed Nov 30 14:42:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Toke_H=C3=B8iland-J=C3=B8rgensen?= X-Patchwork-Id: 13059998 X-Patchwork-Delegate: bpf@iogearbox.net 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 81902C4332F for ; Wed, 30 Nov 2022 14:43:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229476AbiK3Ono (ORCPT ); Wed, 30 Nov 2022 09:43:44 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41950 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229461AbiK3Onm (ORCPT ); Wed, 30 Nov 2022 09:43:42 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 33B4DBE12 for ; Wed, 30 Nov 2022 06:42:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1669819366; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=PCyIoMGSiGDdstVNqCLmro74t1BNkUezYoweJpKNg/Q=; b=YZkLv6ln/nxREmhdhElreBFGYjRNwsVLagrJV4C5vV6XrCdfFzOTRp0gI/rAnnRbkM7/1+ /MyBNuWQlDDjd7i8X2eYn7f8waOzp01eu7kSBbrL23BrWAMMGVSZ3PIrjGyGoyR8lZtZTW IWiuLT9y3AuFwsyNGJNhslXwvi1H7p0= Received: from mail-ed1-f71.google.com (mail-ed1-f71.google.com [209.85.208.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-587-d-tfSih1PdWY3Tu4eq2xjg-1; Wed, 30 Nov 2022 09:42:44 -0500 X-MC-Unique: d-tfSih1PdWY3Tu4eq2xjg-1 Received: by mail-ed1-f71.google.com with SMTP id z3-20020a056402274300b0046b14f99390so5501760edd.9 for ; Wed, 30 Nov 2022 06:42:44 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=PCyIoMGSiGDdstVNqCLmro74t1BNkUezYoweJpKNg/Q=; b=u2BFF7tt2doE3RTbUzRd1t02gjXYaKn9vqEeq4QJtXVxtwy53ocH+LrgnKSWA73nUb 65H6cd9FuPv7bO1JUgxbhz+wXfnhas19qmUdLJhTkTSbUMTdxEiQ6Mldvc26Gla4qE7O BqauzCKewD63qNau4N9GZqCS7biAoqqaX9nJiUu8k9Wc9jFoYZAQEnLfmgKxd/Oq+5N6 p/5wiRj7a+IXWqa2gGUH4Lht9LbxoNiBzDffBYgcX7Lv65EOChIrA3jgMzN5+/b8qXPu R14CRkhAT9L4mHtiPzVqlvnJlvFqMTJawE9Hb26qy/mHU+cx0LcdNBys0ioo96yvojiZ fe8g== X-Gm-Message-State: ANoB5pmV2G1a4Lw7X3EajfTns1Lstv177bXwcazF2Iz/L1YCJopS2oM1 C1aXrj5Dy3pIRL9h6L3zqzSiGpYSwWITI0+QLurVeHlFKUkATnfbQYgDlSq3bIcUVWsVZpUmB1Q mmbqqjs/03xDj X-Received: by 2002:a05:6402:189:b0:469:85d:2663 with SMTP id r9-20020a056402018900b00469085d2663mr53175115edv.56.1669819363123; Wed, 30 Nov 2022 06:42:43 -0800 (PST) X-Google-Smtp-Source: AA0mqf4nznHyB26L9ozlWiRnu8euu+cP/TnaBByZcaYk6rRCEggUn6PevCLSEkOytUzStyKrRrbLcw== X-Received: by 2002:a05:6402:189:b0:469:85d:2663 with SMTP id r9-20020a056402018900b00469085d2663mr53175087edv.56.1669819362784; Wed, 30 Nov 2022 06:42:42 -0800 (PST) Received: from alrua-x1.borgediget.toke.dk ([45.145.92.2]) by smtp.gmail.com with ESMTPSA id q25-20020a17090676d900b007803083a36asm707204ejn.115.2022.11.30.06.42.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Nov 2022 06:42:42 -0800 (PST) Received: by alrua-x1.borgediget.toke.dk (Postfix, from userid 1000) id 90A8C80ADF5; Wed, 30 Nov 2022 15:42:41 +0100 (CET) From: =?utf-8?q?Toke_H=C3=B8iland-J=C3=B8rgensen?= To: Alexei Starovoitov , Lorenzo Bianconi Cc: Kumar Kartikeya Dwivedi , Jiri Benc , =?utf-8?q?Toke_H=C3=B8iland-J=C3=B8rgensen?= , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Mykola Lysenko , Shuah Khan , bpf@vger.kernel.org Subject: [PATCH bpf 2/2] selftests/bpf: Add local definition of enum nf_nat_manip_type to bpf_nf test Date: Wed, 30 Nov 2022 15:42:40 +0100 Message-Id: <20221130144240.603803-2-toke@redhat.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221130144240.603803-1-toke@redhat.com> References: <20221130144240.603803-1-toke@redhat.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net The bpf_nf selftest calls the bpf_ct_set_nat_info() kfunc, which takes a parameter of type enum nf_nat_manip_type. However, if the nf_nat code is compiled as a module, that enum is not defined in vmlinux BTF, and compilation of the selftest fails. A previous patch suggested just hard-coding the enum values: https://lore.kernel.org/r/tencent_4C0B445E0305A18FACA04B4A959B57835107@qq.com However, this doesn't work as the compiler then complains about an incomplete type definition in the function prototype. Instead, just add a local definition of the enum to the selftest code. Fixes: b06b45e82b59 ("selftests/bpf: add tests for bpf_ct_set_nat_info kfunc") Signed-off-by: Toke Høiland-Jørgensen --- tools/testing/selftests/bpf/progs/test_bpf_nf.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tools/testing/selftests/bpf/progs/test_bpf_nf.c b/tools/testing/selftests/bpf/progs/test_bpf_nf.c index 227e85e85dda..6350d11ec6f6 100644 --- a/tools/testing/selftests/bpf/progs/test_bpf_nf.c +++ b/tools/testing/selftests/bpf/progs/test_bpf_nf.c @@ -43,6 +43,11 @@ struct bpf_ct_opts___local { u8 reserved[3]; } __attribute__((preserve_access_index)); +enum nf_nat_manip_type { + NF_NAT_MANIP_SRC, + NF_NAT_MANIP_DST +}; + struct nf_conn *bpf_xdp_ct_alloc(struct xdp_md *, struct bpf_sock_tuple *, u32, struct bpf_ct_opts___local *, u32) __ksym; struct nf_conn *bpf_xdp_ct_lookup(struct xdp_md *, struct bpf_sock_tuple *, u32,