Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp4569282imw; Tue, 19 Jul 2022 09:01:56 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uqfMqC5yD6O7oYD/m+G0gvhUudzZJlczjjj0gDhGciqqz0uRN9TBM+oHg5Sol6/H12cnXj X-Received: by 2002:a05:6402:3690:b0:43a:83f8:93bf with SMTP id ej16-20020a056402369000b0043a83f893bfmr39199944edb.49.1658246516735; Tue, 19 Jul 2022 09:01:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658246516; cv=none; d=google.com; s=arc-20160816; b=M6oLeUvNSy0dusYA/LO67tWDcw9M5QS1gFIEEOtGfPS+O4ZstiCLi30frsvV25+E0t Cn+I9DF5P3qtZe0HwU5R/lnx40pQHVSQ77eTadejMBIhX+d87+YztayGdMbHSrKycmAL WU45qAOA9QuzTMHCQRQK0KnXRTrqV1udMrPmvdFlqu+qKPY/cQfzkXtdrzlan4bJ5oEt 9iMY+A1hRJ7Y2vKXWmhKuh2wpbPio1rGZ4M/OdRS5wxhkHdt2NjqETc52MZn6gxGQCt+ KIff2p9Dm2tD0yvmwsW9wnkIsfsXnMydpSuGIb93Sdz16Bd/dEvnWdaHx4gu69CGsrAE QaBw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=rLGineCxzdUhqZ0totHv9/HyxhWkFQEif+a4cEJSDL8=; b=nbtMfM3EqezhnkQSHQIkm9M7dJ/UL9QWafJdClCNan6sysXFfzNyfbfMvi0ZCN3jEo Zc65JAIy5kXAxyzVuP07gD4XB/jxj4afFvQmT8fnSovTwkegfDKTBXK0u3F9SmDqegEW 6C0ZMJp4h2c1jv3ostxY0DDOTpfWTASIIy8uYsY2OBbF56pTfUCqUXKMnKtzK4QoVQAl TKTJw9tbjO28+uXg1RsX6RU2EX/RuwcxNDNP/WXhBuIVDL5S355Bh50xlGrxU5NYE5jh oaZLzey4Qr+Z8hYNoWOyMRLgq/BXFnFXO1BKBnu4DWTwXzqfCvTPSxB2QmiFIViMeUYb 3Fjw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=DW0EnfRw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b18-20020a170906709200b006ff20273cccsi3478788ejk.231.2022.07.19.09.01.25; Tue, 19 Jul 2022 09:01:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=DW0EnfRw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238499AbiGSPq1 (ORCPT + 99 others); Tue, 19 Jul 2022 11:46:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49212 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238485AbiGSPqZ (ORCPT ); Tue, 19 Jul 2022 11:46:25 -0400 Received: from mail-pl1-x629.google.com (mail-pl1-x629.google.com [IPv6:2607:f8b0:4864:20::629]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9128D54672 for ; Tue, 19 Jul 2022 08:46:24 -0700 (PDT) Received: by mail-pl1-x629.google.com with SMTP id g17so12321564plh.2 for ; Tue, 19 Jul 2022 08:46:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=rLGineCxzdUhqZ0totHv9/HyxhWkFQEif+a4cEJSDL8=; b=DW0EnfRwpOw1uNv4VAVwjEIGLJYOoNSuCcD40y6h3lKcLGS+MBuBuVX/UegUgNbGel +ty0PUe3Zb5MGym/CRL0C7cxczOoUDRB2VP8Z7dfuTUi4o4EzqlWCDqwMCwNw0ZqySm8 dGT45EkwtMUdEu1hOA4Fq6e2jBTS1CT/czPuB5AIWXV/0cy0/bwFrjwF74jEBzBgiLhA zFXzOZPXeQbAVHysr3nHY0jIK04lSl1vTt7r6/RsCR+Sq7IF/S/yNCcDX1b/aF1DMQfz SBLxG1AP0/K0cftPJ8Yez80ecG/GS7X5fD7ZYwk/Nzq9o9RNTDtp/ZjTBQQnUpbL3rxI Ndtg== 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; bh=rLGineCxzdUhqZ0totHv9/HyxhWkFQEif+a4cEJSDL8=; b=IlQqOd7Iaz3nWbUBy8EhiYWq24phUt2upSRu+xxwfiqWZ2g8jfoKJ0+AfFsLFEIkpk R2kHpNRz5JbJtq64XOVvAvCEnw+nVYxhGtQHydsuhCQ7jyPuSSgrnaD1uDsuaz3nvnnO JFdDN0cNrkfvLtyRuEY+CFRhTbAq1LsxJG53yEvAkavRS9OUGJUnotRax1M0yv/6irXK GWBs7IJ5MPUnqfapynQEvV81sKdMUUqXpC+cYj6DHPASoB78VX/AyDja4z1NpT699Ngc 1rRM+G190CVIm+gSSGtxBnYYY1oUyN2lk/UJAfWPuM/fg0mO7bg/VApPM7GKtf9c+1I4 Agdw== X-Gm-Message-State: AJIora9i4g+xHH5uqOpomSc7MnK5HMoiGc0cyddzYa7mmatyArq3ufIE r47HywcL3Mnbtcxt+R5enb9S+UqSJnJWCmCx7k0OGpL5cie4PA== X-Received: by 2002:a17:902:db11:b0:16c:3e90:12e5 with SMTP id m17-20020a170902db1100b0016c3e9012e5mr33546576plx.73.1658245583818; Tue, 19 Jul 2022 08:46:23 -0700 (PDT) MIME-Version: 1.0 References: <1658221305-35718-1-git-send-email-xujia39@huawei.com> In-Reply-To: <1658221305-35718-1-git-send-email-xujia39@huawei.com> From: Stanislav Fomichev Date: Tue, 19 Jul 2022 08:46:12 -0700 Message-ID: Subject: Re: [PATCH bpf-next] bpf: fix bpf compile error caused by CONFIG_CGROUP_BPF To: Xu Jia Cc: netdev@vger.kernel.org, bpf@vger.kernel.org, linux-kernel@vger.kernel.org, ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jul 19, 2022 at 1:49 AM Xu Jia wrote: > > We failed to compile when CONFIG_BPF_LSM is enabled but CONFIG_CGROUP_BPF > is not set. The failings are shown as below: > > kernel/bpf/trampoline.o: in function `bpf_trampoline_link_cgroup_shim' > trampoline.c: undefined reference to `bpf_cgroup_atype_get' > kernel/bpf/bpf_lsm.o: In function `bpf_lsm_find_cgroup_shim': > bpf_lsm.c: undefined reference to `__cgroup_bpf_run_lsm_current' > bpf_lsm.c: undefined reference to `__cgroup_bpf_run_lsm_sock' > bpf_lsm.c: undefined reference to `__cgroup_bpf_run_lsm_socket' > > Fix them by protecting these functions with CONFIG_CGROUP_BPF. Should be fixed by the following? https://lore.kernel.org/bpf/20220714185404.3647772-1-sdf@google.com/ > Fixes: 69fd337a975c ("bpf: per-cgroup lsm flavor") > Signed-off-by: Xu Jia > --- > include/linux/bpf.h | 12 +++++++++--- > include/linux/bpf_lsm.h | 10 ++++++---- > kernel/bpf/bpf_lsm.c | 2 ++ > kernel/bpf/trampoline.c | 2 ++ > 4 files changed, 19 insertions(+), 7 deletions(-) > > diff --git a/include/linux/bpf.h b/include/linux/bpf.h > index 2b21f2a3452f..add8895c02cc 100644 > --- a/include/linux/bpf.h > +++ b/include/linux/bpf.h > @@ -1255,9 +1255,7 @@ struct bpf_dummy_ops { > int bpf_struct_ops_test_run(struct bpf_prog *prog, const union bpf_attr *kattr, > union bpf_attr __user *uattr); > #endif > -int bpf_trampoline_link_cgroup_shim(struct bpf_prog *prog, > - int cgroup_atype); > -void bpf_trampoline_unlink_cgroup_shim(struct bpf_prog *prog); > + > #else > static inline const struct bpf_struct_ops *bpf_struct_ops_find(u32 type_id) > { > @@ -1281,6 +1279,14 @@ static inline int bpf_struct_ops_map_sys_lookup_elem(struct bpf_map *map, > { > return -EINVAL; > } > +#endif > + > +#if defined(CONFIG_BPF_JIT) && defined(CONFIG_BPF_SYSCALL) && \ > + defined(CONFIG_CGROUP_BPF) > +int bpf_trampoline_link_cgroup_shim(struct bpf_prog *prog, > + int cgroup_atype); > +void bpf_trampoline_unlink_cgroup_shim(struct bpf_prog *prog); > +#else > static inline int bpf_trampoline_link_cgroup_shim(struct bpf_prog *prog, > int cgroup_atype) > { > diff --git a/include/linux/bpf_lsm.h b/include/linux/bpf_lsm.h > index 4bcf76a9bb06..bed45a0c8a9c 100644 > --- a/include/linux/bpf_lsm.h > +++ b/include/linux/bpf_lsm.h > @@ -42,8 +42,6 @@ extern const struct bpf_func_proto bpf_inode_storage_get_proto; > extern const struct bpf_func_proto bpf_inode_storage_delete_proto; > void bpf_inode_storage_free(struct inode *inode); > > -void bpf_lsm_find_cgroup_shim(const struct bpf_prog *prog, bpf_func_t *bpf_func); > - > #else /* !CONFIG_BPF_LSM */ > > static inline bool bpf_lsm_is_sleepable_hook(u32 btf_id) > @@ -67,11 +65,15 @@ static inline void bpf_inode_storage_free(struct inode *inode) > { > } > > +#endif /* CONFIG_BPF_LSM */ > + > +#if defined(CONFIG_BPF_LSM) && defined(CONFIG_BPF_CGROUP) > +void bpf_lsm_find_cgroup_shim(const struct bpf_prog *prog, bpf_func_t *bpf_func); > +#else > static inline void bpf_lsm_find_cgroup_shim(const struct bpf_prog *prog, > bpf_func_t *bpf_func) > { > } > - > -#endif /* CONFIG_BPF_LSM */ > +#endif > > #endif /* _LINUX_BPF_LSM_H */ > diff --git a/kernel/bpf/bpf_lsm.c b/kernel/bpf/bpf_lsm.c > index d469b7f3deef..29527828b38b 100644 > --- a/kernel/bpf/bpf_lsm.c > +++ b/kernel/bpf/bpf_lsm.c > @@ -63,6 +63,7 @@ BTF_ID(func, bpf_lsm_socket_post_create) > BTF_ID(func, bpf_lsm_socket_socketpair) > BTF_SET_END(bpf_lsm_unlocked_sockopt_hooks) > > +#ifdef CONFIG_BPF_CGROUP > void bpf_lsm_find_cgroup_shim(const struct bpf_prog *prog, > bpf_func_t *bpf_func) > { > @@ -86,6 +87,7 @@ void bpf_lsm_find_cgroup_shim(const struct bpf_prog *prog, > #endif > *bpf_func = __cgroup_bpf_run_lsm_current; > } > +#endif /* CONFIG_BPF_CGROUP */ > > int bpf_lsm_verify_prog(struct bpf_verifier_log *vlog, > const struct bpf_prog *prog) > diff --git a/kernel/bpf/trampoline.c b/kernel/bpf/trampoline.c > index 6cd226584c33..127924711935 100644 > --- a/kernel/bpf/trampoline.c > +++ b/kernel/bpf/trampoline.c > @@ -525,6 +525,7 @@ static const struct bpf_link_ops bpf_shim_tramp_link_lops = { > .dealloc = bpf_shim_tramp_link_dealloc, > }; > > +#ifdef CONFIG_CGROUP_BPF > static struct bpf_shim_tramp_link *cgroup_shim_alloc(const struct bpf_prog *prog, > bpf_func_t bpf_func, > int cgroup_atype) > @@ -668,6 +669,7 @@ void bpf_trampoline_unlink_cgroup_shim(struct bpf_prog *prog) > > bpf_trampoline_put(tr); /* bpf_trampoline_lookup above */ > } > +#endif /* CONFIG_CGROUP_BPF */ > #endif > > struct bpf_trampoline *bpf_trampoline_get(u64 key, > -- > 2.25.1 >