Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp3603344pxu; Tue, 8 Dec 2020 17:03:36 -0800 (PST) X-Google-Smtp-Source: ABdhPJysU5wDzo2x8vIscQ/8AtRMw3wK/JJm4kTdzXR9flE/+gPnWZkgENwNuLM1ip65+etHSBle X-Received: by 2002:a17:907:a96:: with SMTP id by22mr25792ejc.171.1607475816627; Tue, 08 Dec 2020 17:03:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1607475816; cv=none; d=google.com; s=arc-20160816; b=t3rbpRk/foVl1tXFMEApHqht6QLkjaRGVA1O/j+GTSHsumpjuUR+WRxzGFXLFzN34Z HIOqxSUH/S9eyjOXSuxDVfdvumos8R+lr9fiTyeplWvs+olbhxQ/FrW2C5mLBeOh9blb m+go1Anb5bU+w0pWRqtDxdGj3761p6nibVYmZAt7lL4gpkxjsJ0cxvoM64amJEQINKTl FD1Ytx7EmM8sz/opDqTm89evaESby4/MTZVlqoHPhFQ0j7GKMwm9KxX3E6sQJ3csbQKE u1IS3GDpLguVogDYFDEcEr+FtWAbwBfwT7q1o+EywK35bZk0dXB/onoq9hQYoIil4RE+ JkPA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=jX3mNNkAYkA8sb0euHmnG4MILEbOBpNTv+pnHusb8uA=; b=K6CanTB5457SURweSQrn8PP26wqucQqKg/y9XZcDAgug4nLxOuc0vh8Kvn8lSskGs0 FPUhB/5cJsjvOY28Pz6od1R0Qt8KZfsbi9O5+lV/PUFUs6rv6Zm565YHi2DROwCEuFOc 2sSDxlSBtqYKhUU9RRBxzWhgPc6IaA42PsYaO7NSVrHD2CN2FhrqGpe37ypjYE3K10kO i4Ur7xpPxGREKCp1fODIp6Eq+5+UNZeb5iirPbMn0zWAhhw2DSG/X1Qb1iQr8RGBEnrp O6srlFzkDG+o4cNbY1ojkdLIxP/qe0Xu7mfzoWrdSPtTFeU9PLCnzvFx+NjSmv9xDy1Y hwOA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=Q8Noz5Mi; 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=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z7si104758edx.473.2020.12.08.17.03.13; Tue, 08 Dec 2020 17:03:36 -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=@chromium.org header.s=google header.b=Q8Noz5Mi; 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=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730411AbgLHRhM (ORCPT + 99 others); Tue, 8 Dec 2020 12:37:12 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38494 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726278AbgLHRhM (ORCPT ); Tue, 8 Dec 2020 12:37:12 -0500 Received: from mail-wm1-x342.google.com (mail-wm1-x342.google.com [IPv6:2a00:1450:4864:20::342]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C6D67C061749 for ; Tue, 8 Dec 2020 09:36:31 -0800 (PST) Received: by mail-wm1-x342.google.com with SMTP id v14so2715863wml.1 for ; Tue, 08 Dec 2020 09:36:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=jX3mNNkAYkA8sb0euHmnG4MILEbOBpNTv+pnHusb8uA=; b=Q8Noz5MiD0BJW9bcOCv07n6fYNbh0JVxW6ADcS+Y0QIR4ilExCStr8xV6rD3z80Y6S Z1CNdPOUU6mCceDa6wSVMEhJMSuR2Cp80nWtjx9GiKOa/l8eO1rVJO3hRpSyjyKjrAjS S5oiK/7LZDuvDNBeQyRRqpWtOs0CgLXTft36k= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=jX3mNNkAYkA8sb0euHmnG4MILEbOBpNTv+pnHusb8uA=; b=Xx4kQ42JO0EM8tvNsHIsPf/rzWGy/ZzgUpP7ML/cqP8ZwoYSCjbWLwM3cNtSQoVLR9 5RfpdinkEFqbIP6Fzg9pxwtUuTp1PnpZfu5+NaezXURbjzLowq+jGy/Jq39meBdaTawL pUDFM3+EmV5kt946OOxckgb5K4PHwfjjiPjeO+ynezGJrvnUHPn2OnqWp9ZNasq+Tnq3 TvLF2wcOpCm9E8stCl9qMCiQ0itWiQwAtUXQbVlZFp3z4cpDJ9WiltrAIT4XYchPAZRk RHfkId3VXB0ipaFkB+6k1mMRStmCk8b6TGT/6UyJwprYeDl58KXFyZKByFvTYhIXmYo3 UU1A== X-Gm-Message-State: AOAM532VyWiwBYJg50ajNxV34LGk++VZOHMCn0UhugU2+4vSBWLAJ3+F JiT6N6iA+8tfzC/Icv5PgPoLIQ== X-Received: by 2002:a1c:b608:: with SMTP id g8mr4858668wmf.110.1607448990508; Tue, 08 Dec 2020 09:36:30 -0800 (PST) Received: from revest.zrh.corp.google.com ([2a00:79e0:42:204:f693:9fff:fef4:a569]) by smtp.gmail.com with ESMTPSA id k7sm8619519wrn.63.2020.12.08.09.36.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Dec 2020 09:36:29 -0800 (PST) From: Florent Revest To: bpf@vger.kernel.org Cc: ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, kpsingh@chromium.org, rdunlap@infradead.org, kafai@fb.com, linux-next@vger.kernel.org, linux-kernel@vger.kernel.org, Florent Revest , kernel test robot Subject: [PATCH bpf-next v3] bpf: Only provide bpf_sock_from_file with CONFIG_NET Date: Tue, 8 Dec 2020 18:36:23 +0100 Message-Id: <20201208173623.1136863-1-revest@chromium.org> X-Mailer: git-send-email 2.29.2.576.ga3fc446d84-goog MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This moves the bpf_sock_from_file definition into net/core/filter.c which only gets compiled with CONFIG_NET and also moves the helper proto usage next to other tracing helpers that are conditional on CONFIG_NET. This avoids ld: kernel/trace/bpf_trace.o: in function `bpf_sock_from_file': bpf_trace.c:(.text+0xe23): undefined reference to `sock_from_file' When compiling a kernel with BPF and without NET. Reported-by: kernel test robot Reported-by: Randy Dunlap Acked-by: Randy Dunlap Signed-off-by: Florent Revest --- include/linux/bpf.h | 1 + kernel/trace/bpf_trace.c | 22 ++-------------------- net/core/filter.c | 18 ++++++++++++++++++ 3 files changed, 21 insertions(+), 20 deletions(-) diff --git a/include/linux/bpf.h b/include/linux/bpf.h index d05e75ed8c1b..07cb5d15e743 100644 --- a/include/linux/bpf.h +++ b/include/linux/bpf.h @@ -1859,6 +1859,7 @@ extern const struct bpf_func_proto bpf_snprintf_btf_proto; extern const struct bpf_func_proto bpf_per_cpu_ptr_proto; extern const struct bpf_func_proto bpf_this_cpu_ptr_proto; extern const struct bpf_func_proto bpf_ktime_get_coarse_ns_proto; +extern const struct bpf_func_proto bpf_sock_from_file_proto; const struct bpf_func_proto *bpf_tracing_func_proto( enum bpf_func_id func_id, const struct bpf_prog *prog); diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c index 0cf0a6331482..52ddd217d6a1 100644 --- a/kernel/trace/bpf_trace.c +++ b/kernel/trace/bpf_trace.c @@ -1270,24 +1270,6 @@ const struct bpf_func_proto bpf_snprintf_btf_proto = { .arg5_type = ARG_ANYTHING, }; -BPF_CALL_1(bpf_sock_from_file, struct file *, file) -{ - return (unsigned long) sock_from_file(file); -} - -BTF_ID_LIST(bpf_sock_from_file_btf_ids) -BTF_ID(struct, socket) -BTF_ID(struct, file) - -static const struct bpf_func_proto bpf_sock_from_file_proto = { - .func = bpf_sock_from_file, - .gpl_only = false, - .ret_type = RET_PTR_TO_BTF_ID_OR_NULL, - .ret_btf_id = &bpf_sock_from_file_btf_ids[0], - .arg1_type = ARG_PTR_TO_BTF_ID, - .arg1_btf_id = &bpf_sock_from_file_btf_ids[1], -}; - const struct bpf_func_proto * bpf_tracing_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog) { @@ -1384,8 +1366,6 @@ bpf_tracing_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog) return &bpf_per_cpu_ptr_proto; case BPF_FUNC_bpf_this_cpu_ptr: return &bpf_this_cpu_ptr_proto; - case BPF_FUNC_sock_from_file: - return &bpf_sock_from_file_proto; default: return NULL; } @@ -1778,6 +1758,8 @@ tracing_prog_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog) return &bpf_sk_storage_get_tracing_proto; case BPF_FUNC_sk_storage_delete: return &bpf_sk_storage_delete_tracing_proto; + case BPF_FUNC_sock_from_file: + return &bpf_sock_from_file_proto; #endif case BPF_FUNC_seq_printf: return prog->expected_attach_type == BPF_TRACE_ITER ? diff --git a/net/core/filter.c b/net/core/filter.c index 77001a35768f..255aeee72402 100644 --- a/net/core/filter.c +++ b/net/core/filter.c @@ -10413,6 +10413,24 @@ const struct bpf_func_proto bpf_skc_to_udp6_sock_proto = { .ret_btf_id = &btf_sock_ids[BTF_SOCK_TYPE_UDP6], }; +BPF_CALL_1(bpf_sock_from_file, struct file *, file) +{ + return (unsigned long)sock_from_file(file); +} + +BTF_ID_LIST(bpf_sock_from_file_btf_ids) +BTF_ID(struct, socket) +BTF_ID(struct, file) + +const struct bpf_func_proto bpf_sock_from_file_proto = { + .func = bpf_sock_from_file, + .gpl_only = false, + .ret_type = RET_PTR_TO_BTF_ID_OR_NULL, + .ret_btf_id = &bpf_sock_from_file_btf_ids[0], + .arg1_type = ARG_PTR_TO_BTF_ID, + .arg1_btf_id = &bpf_sock_from_file_btf_ids[1], +}; + static const struct bpf_func_proto * bpf_sk_base_func_proto(enum bpf_func_id func_id) { -- 2.29.2.576.ga3fc446d84-goog