From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from fanzine2.igalia.com (fanzine2.igalia.com [213.97.179.56]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9687B6A01E for ; Sat, 17 Feb 2024 12:13:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=213.97.179.56 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708172027; cv=none; b=UaVzeaRAJhvtOX5IjLlYPYrHaD8lIvj6JaVAJWmIRM6FyaZuLhdIfksTkHkwdp5wvjpEmpd02OXqF8ccjK2QVTlRrotZ86b6kfyTGIsohWRuYT8ap1bCWdlxLvNKKE1VLOeL/mop5Whom6PpguYfsMoC4ubabPupZLTHHXnass4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708172027; c=relaxed/simple; bh=01xWE4krICIaR9UvQF6OyU0iyvu8vmnGQhqSkwjmDMQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=oSOLf4JkVPzDn7uyIzxpNDhuYOVDRND3xp03D7Cm87HPGY/XWbyEBI7rxyAgMUEkHcvGvE6kMh04i3AwNvTljlM2dyk9O/Sqs2jOgV+lq+SWFnN7FBM59xQ3M+/zPPJBm1pVkALqsnYmMcuAzDqAFIBobyVSsTkODbO3HHUA/7E= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=igalia.com; spf=pass smtp.mailfrom=igalia.com; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b=axmUZ/cf; arc=none smtp.client-ip=213.97.179.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=igalia.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=igalia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b="axmUZ/cf" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=MFR5liHACkTyqQ+d1ZwE34xV46Yqur+JJS9WsOpKZP4=; b=axmUZ/cfs3HJ3Nlo/XZTaXAsez yIlqmHdwVEBg7kNbI/G06sfuLcLvF2r0z6JpofnpujuWCDlRvYNE1mb0npr+tztPf87rinHdCfJnT 3QUoLJ2yixcqxglj3lXc3bRYE5RBbqe+ttM/aY9bmXYTp+oH5m6+XznYux5WyR4V1anxV5Azbr+5g 3Po9B4kH/EIw0F9cgFWXABh0n8s95KjG3nSqCRtcDyCg3VOEc/X5Ao9Za2yokrrka+vp0ibL0h3ca fYslwPXqA2enfiVeFelczfjMkdRFSe8Ey54zz6XzlkwnQfupQOCp6MzDasP4oqXNZ+YWX7yJ6gyaf +4Jx6rgA==; Received: from 179-125-79-204-dinamico.pombonet.net.br ([179.125.79.204] helo=quatroqueijos.lan) by fanzine2.igalia.com with esmtpsa (Cipher TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1rbJZb-000joD-JX; Sat, 17 Feb 2024 13:13:40 +0100 From: Thadeu Lima de Souza Cascardo To: stable@vger.kernel.org Cc: cascardo@igalia.com, jolsa@kernel.org, daniel@iogearbox.net, yhs@fb.com Subject: [PATCH 5.15 1/4] bpf: Merge printk and seq_printf VARARG max macros Date: Sat, 17 Feb 2024 09:13:18 -0300 Message-Id: <20240217121321.2045993-5-cascardo@igalia.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240217121321.2045993-1-cascardo@igalia.com> References: <20240217121321.2045993-1-cascardo@igalia.com> Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Dave Marchevsky commit 335ff4990cf3bfa42d8846f9b3d8c09456f51801 upstream. MAX_SNPRINTF_VARARGS and MAX_SEQ_PRINTF_VARARGS are used by bpf helpers bpf_snprintf and bpf_seq_printf to limit their varargs. Both call into bpf_bprintf_prepare for print formatting logic and have convenience macros in libbpf (BPF_SNPRINTF, BPF_SEQ_PRINTF) which use the same helper macros to convert varargs to a byte array. Changing shared functionality to support more varargs for either bpf helper would affect the other as well, so let's combine the _VARARGS macros to make this more obvious. Signed-off-by: Dave Marchevsky Signed-off-by: Alexei Starovoitov Acked-by: Andrii Nakryiko Link: https://lore.kernel.org/bpf/20210917182911.2426606-2-davemarchevsky@fb.com Signed-off-by: Thadeu Lima de Souza Cascardo --- include/linux/bpf.h | 2 ++ kernel/bpf/helpers.c | 4 +--- kernel/trace/bpf_trace.c | 4 +--- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/include/linux/bpf.h b/include/linux/bpf.h index 00c615fc8ec3..175d623a16a1 100644 --- a/include/linux/bpf.h +++ b/include/linux/bpf.h @@ -2286,6 +2286,8 @@ void bpf_arch_poke_desc_update(struct bpf_jit_poke_descriptor *poke, struct btf_id_set; bool btf_id_set_contains(const struct btf_id_set *set, u32 id); +#define MAX_BPRINTF_VARARGS 12 + int bpf_bprintf_prepare(char *fmt, u32 fmt_size, const u64 *raw_args, u32 **bin_buf, u32 num_args); void bpf_bprintf_cleanup(void); diff --git a/kernel/bpf/helpers.c b/kernel/bpf/helpers.c index 11e406ad16ae..4eb3b929504d 100644 --- a/kernel/bpf/helpers.c +++ b/kernel/bpf/helpers.c @@ -979,15 +979,13 @@ int bpf_bprintf_prepare(char *fmt, u32 fmt_size, const u64 *raw_args, return err; } -#define MAX_SNPRINTF_VARARGS 12 - BPF_CALL_5(bpf_snprintf, char *, str, u32, str_size, char *, fmt, const void *, data, u32, data_len) { int err, num_args; u32 *bin_args; - if (data_len % 8 || data_len > MAX_SNPRINTF_VARARGS * 8 || + if (data_len % 8 || data_len > MAX_BPRINTF_VARARGS * 8 || (data_len && !data)) return -EINVAL; num_args = data_len / 8; diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c index 85a36b19c2b8..34455856c035 100644 --- a/kernel/trace/bpf_trace.c +++ b/kernel/trace/bpf_trace.c @@ -414,15 +414,13 @@ const struct bpf_func_proto *bpf_get_trace_printk_proto(void) return &bpf_trace_printk_proto; } -#define MAX_SEQ_PRINTF_VARARGS 12 - BPF_CALL_5(bpf_seq_printf, struct seq_file *, m, char *, fmt, u32, fmt_size, const void *, data, u32, data_len) { int err, num_args; u32 *bin_args; - if (data_len & 7 || data_len > MAX_SEQ_PRINTF_VARARGS * 8 || + if (data_len & 7 || data_len > MAX_BPRINTF_VARARGS * 8 || (data_len && !data)) return -EINVAL; num_args = data_len / 8; -- 2.34.1