From patchwork Fri Sep 15 17:34:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nick Desaulniers X-Patchwork-Id: 13387327 X-Patchwork-Delegate: bpf@iogearbox.net Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (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 18129CA6F for ; Fri, 15 Sep 2023 17:35:30 +0000 (UTC) Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A20FA2D7F for ; Fri, 15 Sep 2023 10:34:37 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id 3f1490d57ef6-d81873bf443so2524628276.1 for ; Fri, 15 Sep 2023 10:34:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1694799277; x=1695404077; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=XJJJkdYQoV+TuxyICMmymuiRvcaqdo/oW6N/B153WLE=; b=Hz8jyX9trB5SbK12NzI2q1kW8Cf/npNWwmFvDkY+H9qRrI4zEJ2hTZqhmA6ki3V85n gXXHSCi2mR3seK/b7NF9GXcCvkBZT1vhiPcmsYvx8iV7+e8YxV0IHvgJ3/jsNS1wlAUH FPJpwifjOuHdQeHeMefLGDqcd232Ad/3yDAsvsDN4fuFZ65t6EAe2bHH4gmoXDiobC4A LZSQsAS5O+bN2wRTQEJRzD0NNUE6nbimgOFZQv+DEs+5J4TP32JEPrtAksm2kKShh+b1 Sf4EPVxAV7c8ln1fa25+5xJ5k1ZWRtsw8QTGo8uUVOP6hRvBd10dfC0sx46izelumbaU bCIQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694799277; x=1695404077; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=XJJJkdYQoV+TuxyICMmymuiRvcaqdo/oW6N/B153WLE=; b=idYqAgV2SXERBe1k3JOVWYBvep5l//aXqi7wddd3uV7aN6eryJd54fE0zwkAcP8NwQ Q/RV9Y89rk6E5fI6izHofZ/8C/qCY8y9lHUINIANao1OWONLF226OUrFVMglP9wufyGJ SYwWdgqcBi4mfgzLz0n333pERd3k3h0IZOI1FtB7cEQv4CtXfVWShk0uxk2eg2VIXf1Q URMkxjrn/ZbUyYZdTwU5JyxY3S/iy6BAalFmojkJTVbGpkIIfTB+wr5KXuA8iEvo9+vC 375Z5jtBbHymYwGgXJ3NuZQhgwNxNUP292ToDGX+VxIbU2ec4hifFNOrGCJ8kN41fJJR PQ7w== X-Gm-Message-State: AOJu0YxVDAlnfMxfb/HgoKxn6rJcyH9GV+28BdxMpBGrEJqtCp15i1QQ eCuRvDbsIl6/b+jyq+41Nh0GqR5DkgTkDwVHvg8= X-Google-Smtp-Source: AGHT+IEAHmjL5dTMrhswiFhjsYks3tmeFWHVYfPFl5tpcAmcDOUwNVDZ9Oub8FCz1WrA9lAgdMaDDhBi7ijkvR//Z9s= X-Received: from ndesaulniers-desktop.svl.corp.google.com ([2620:15c:2d1:203:7f04:6b3:b482:dd2c]) (user=ndesaulniers job=sendgmr) by 2002:a25:804f:0:b0:d81:7f38:6d69 with SMTP id a15-20020a25804f000000b00d817f386d69mr56369ybn.0.1694799276916; Fri, 15 Sep 2023 10:34:36 -0700 (PDT) Date: Fri, 15 Sep 2023 10:34:27 -0700 In-Reply-To: <20230915-bpf_collision-v3-0-263fc519c21f@google.com> Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20230915-bpf_collision-v3-0-263fc519c21f@google.com> X-Developer-Key: i=ndesaulniers@google.com; a=ed25519; pk=eMOZeIQ4DYNKvsNmDNzVbQZqpdex34Aww3b8Ah957X4= X-Developer-Signature: v=1; a=ed25519-sha256; t=1694799273; l=1627; i=ndesaulniers@google.com; s=20230823; h=from:subject:message-id; bh=Un0BK6Kn/Y9x5wHtdOd6qUrWjso13vQumzj2rjmjBdg=; b=5rueaC75pOHuA1brjat1Uh1IHpP8UpGk090yWGibirzkwVfVTSK3QKijrRtvJGvRfelm2Ou2H XSO66QfARkFC4DnKw4VJgK1+C1hdJdgOulmLsUL76zhBZiawI1HpDVv X-Mailer: b4 0.12.3 Message-ID: <20230915-bpf_collision-v3-1-263fc519c21f@google.com> Subject: [PATCH bpf v3 1/2] bpf: Fix BTF_ID symbol generation collision From: Nick Desaulniers To: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , KP Singh , Jiri Olsa Cc: linux-kernel@vger.kernel.org, bpf@vger.kernel.org, Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Nick Desaulniers , stable@vger.kernel.org, Satya Durga Srinivasu Prabhala , Marcus Seyfarth , Nathan Chancellor X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: bpf@iogearbox.net From: Jiri Olsa Marcus and Satya reported an issue where BTF_ID macro generates same symbol in separate objects and that breaks final vmlinux link. ld.lld: error: ld-temp.o :14577:1: symbol '__BTF_ID__struct__cgroup__624' is already defined This can be triggered under specific configs when __COUNTER__ happens to be the same for the same symbol in two different translation units, which is already quite unlikely to happen. Add __LINE__ number suffix to make BTF_ID symbol more unique, which is not a complete fix, but it would help for now and meanwhile we can work on better solution as suggested by Andrii. Cc: stable@vger.kernel.org Reported-by: Satya Durga Srinivasu Prabhala Reported-by: Marcus Seyfarth Closes: https://github.com/ClangBuiltLinux/linux/issues/1913 Debugged-by: Nathan Chancellor Link: https://lore.kernel.org/bpf/CAEf4Bzb5KQ2_LmhN769ifMeSJaWfebccUasQOfQKaOd0nQ51tw@mail.gmail.com/ Signed-off-by: Jiri Olsa Signed-off-by: Nick Desaulniers Reviewed-by: Nathan Chancellor --- include/linux/btf_ids.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/linux/btf_ids.h b/include/linux/btf_ids.h index a3462a9b8e18..a9cb10b0e2e9 100644 --- a/include/linux/btf_ids.h +++ b/include/linux/btf_ids.h @@ -49,7 +49,7 @@ word \ ____BTF_ID(symbol, word) #define __ID(prefix) \ - __PASTE(prefix, __COUNTER__) + __PASTE(__PASTE(prefix, __COUNTER__), __LINE__) /* * The BTF_ID defines unique symbol for each ID pointing From patchwork Fri Sep 15 17:34:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nick Desaulniers X-Patchwork-Id: 13387328 X-Patchwork-Delegate: bpf@iogearbox.net Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (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 3916ECA6F for ; Fri, 15 Sep 2023 17:35:55 +0000 (UTC) Received: from mail-yw1-x1149.google.com (mail-yw1-x1149.google.com [IPv6:2607:f8b0:4864:20::1149]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 797DD30D4 for ; Fri, 15 Sep 2023 10:34:39 -0700 (PDT) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-59c081a44afso16004997b3.3 for ; Fri, 15 Sep 2023 10:34:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1694799278; x=1695404078; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=sJC1MpNA41XSWsvvv83w1mhfvF8TpSh3HYkxNC3IYos=; b=jgFa188BP2SILiAWR0B1X6XsgVn7BslM7Us/SDpdwusZSBp4uy5fa4ZWfRopAT4u0s SAbSQVVtOHZAdekCInESBcRinfCezDiagRudwdZzr6sfx2YnmOWO780oo5cNQjItwNZu vI4Efah3+uA29/9yQAucvuKOYPKkU23xhlAvyFxhb95D5dFCX0T3WgjKkKM1nJPfWPNu fhI/ZZiwKXYkgWbsSwJVaqK4dH61qq8WaGms2VBnhb0soPQeGPeS9xh/Kp4NS+S4kkcm DaqUJNBLgEFroMV4tPSOPEH/AUKlk+hQS/pkr2armRbxVfkSpASKcedhRvk1q9J+ZwBI atXw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694799278; x=1695404078; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=sJC1MpNA41XSWsvvv83w1mhfvF8TpSh3HYkxNC3IYos=; b=gh4lnnA6Xe7NQ1TZjhO72j15O3RzIAfG5pAVBhX6lAwJT7QijY0UlOlsdueG9gc/Vd luJZqx1BnxRrMhjDU+HJZ16q7LbhjCwSPJlda7IXpUMTrRyWF0JeXlb6rY/eJF44rOML UTdibD3/0hNyVeXMrA5z54UYDD8o1Qczz4tT2qw4TyJyQPMeKpOH0E/nn486mMmKRI6D RzRxAKuuY1HXDWrc5RrJKQ1vsJ1MIoXeQbvBIx0slevg05LL+WhDUrB/H8x+y6dW11ty 9Z8HR0pXXRdvQAoY1Fm/tQDalXUQSAkivDgTRRFbPOQ1KJRe8HukdmFlp/CpkLaUu4P8 iO+g== X-Gm-Message-State: AOJu0YxEP0SJcY8krwGTscaHufE7NIykap+EuuXPAH2ZC4t0eILN7F7y w57b/C3hAhQ8t22QdiS1kl3sqAmftJys1KiTzME= X-Google-Smtp-Source: AGHT+IE9UAT+K+q9ytinkFyMWYt0GrL3lw/3Oewo8P4+2sZ76QzEaJefM4cOvauekXpyLQEY5rvHcSIjPxsuBoor+qM= X-Received: from ndesaulniers-desktop.svl.corp.google.com ([2620:15c:2d1:203:7f04:6b3:b482:dd2c]) (user=ndesaulniers job=sendgmr) by 2002:a81:ac05:0:b0:59b:ea2e:23f0 with SMTP id k5-20020a81ac05000000b0059bea2e23f0mr60367ywh.2.1694799278777; Fri, 15 Sep 2023 10:34:38 -0700 (PDT) Date: Fri, 15 Sep 2023 10:34:28 -0700 In-Reply-To: <20230915-bpf_collision-v3-0-263fc519c21f@google.com> Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20230915-bpf_collision-v3-0-263fc519c21f@google.com> X-Developer-Key: i=ndesaulniers@google.com; a=ed25519; pk=eMOZeIQ4DYNKvsNmDNzVbQZqpdex34Aww3b8Ah957X4= X-Developer-Signature: v=1; a=ed25519-sha256; t=1694799273; l=1657; i=ndesaulniers@google.com; s=20230823; h=from:subject:message-id; bh=kgMWLZDqu9UqeTMmXyEC7cxyK+tytDiO2sXAmlSWnBI=; b=7Fop81vSJL23p4VMu5VzZxe8rIQuLhkNpBVhUlwKmPRY48Ma16klxeWZnl8lr8TXo/sQ0gPcx t/omK9dcidKAX6N/6NMBikRu7Gj1erxfAt6dZLA53bmu2mXDriFKJow X-Mailer: b4 0.12.3 Message-ID: <20230915-bpf_collision-v3-2-263fc519c21f@google.com> Subject: [PATCH bpf v3 2/2] bpf: Fix BTF_ID symbol generation collision in tools/ From: Nick Desaulniers To: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , KP Singh , Jiri Olsa Cc: linux-kernel@vger.kernel.org, bpf@vger.kernel.org, Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Nick Desaulniers , stable@vger.kernel.org, Satya Durga Srinivasu Prabhala , Marcus Seyfarth , Nathan Chancellor X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_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 X-Patchwork-Delegate: bpf@iogearbox.net Marcus and Satya reported an issue where BTF_ID macro generates same symbol in separate objects and that breaks final vmlinux link. ld.lld: error: ld-temp.o :14577:1: symbol '__BTF_ID__struct__cgroup__624' is already defined This can be triggered under specific configs when __COUNTER__ happens to be the same for the same symbol in two different translation units, which is already quite unlikely to happen. Add __LINE__ number suffix to make BTF_ID symbol more unique, which is not a complete fix, but it would help for now and meanwhile we can work on better solution as suggested by Andrii. Cc: stable@vger.kernel.org Reported-by: Satya Durga Srinivasu Prabhala Reported-by: Marcus Seyfarth Closes: https://github.com/ClangBuiltLinux/linux/issues/1913 Debugged-by: Nathan Chancellor Co-developed-by: Jiri Olsa Link: https://lore.kernel.org/bpf/CAEf4Bzb5KQ2_LmhN769ifMeSJaWfebccUasQOfQKaOd0nQ51tw@mail.gmail.com/ Signed-off-by: Nick Desaulniers --- tools/include/linux/btf_ids.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/include/linux/btf_ids.h b/tools/include/linux/btf_ids.h index 71e54b1e3796..2f882d5cb30f 100644 --- a/tools/include/linux/btf_ids.h +++ b/tools/include/linux/btf_ids.h @@ -38,7 +38,7 @@ asm( \ ____BTF_ID(symbol) #define __ID(prefix) \ - __PASTE(prefix, __COUNTER__) + __PASTE(__PASTE(prefix, __COUNTER__), __LINE__) /* * The BTF_ID defines unique symbol for each ID pointing