Received: by 2002:ac0:e350:0:0:0:0:0 with SMTP id g16csp472518imn; Fri, 29 Jul 2022 12:44:28 -0700 (PDT) X-Google-Smtp-Source: AGRyM1s5Z53KjmsBTdU6zjlWVKefSTrj2x+grlZJFIn/1oHfLnGwoJ3UCyp0BmOU7Ecy4fSs3kPX X-Received: by 2002:aa7:cf18:0:b0:43d:34e:11b9 with SMTP id a24-20020aa7cf18000000b0043d034e11b9mr5030013edy.145.1659123868324; Fri, 29 Jul 2022 12:44:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659123868; cv=none; d=google.com; s=arc-20160816; b=tXS4kRRjXRDeMc58JNflQy7qxLLiTipZUGxBRB/0CmfvG9CKijZuW94uwfIZ7BFL93 6Ytse7V9HrPT99ElSX8NTRoy/VTphCLZrZm/kA3H3nhd/kWRjrdu0Sai39EYFWDN3IT0 lNnWgwUSAj+CTe3TrwvS6mdxASFQZGslec4nFQqQSIMXuh1K28C/FwHCW4oHyMl6Ixkf 57H9S8wZWBapzY6RNuIun5s9O0Zwf90fz8CAESaPikdMh/dEBLliBXWKkXq476KlkxqN ojX2Cy6lfzTc2VXRidPVGVbklIoYCmJgX/69y98n6JIVG/YfGolfm5IEdZHsI1bO8w4d vCnA== 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; bh=Pc8G5wDhZAki5tmlp8jB/gyKI++p/zlwJ6w61cj/eZs=; b=A2Zmx8/w1w6Hp36CnVdGhRNgnEnLsbC/ytgfZtwOdmBjfi+eBU1sl0X2UUkYjEksy1 dyShhJyudA+XZcunBduPf+snqSiFA/PzxG7mU4mND9zWUzfisx3Qt5SFu5sq9HcWC/M2 ikl2e/hKNDHRrF1GsRxD58sna/iIOxnXZZ0VspXckVhNCUMiV9rwnu1I0TSGr3v8hlCM v/43gqC9c/y0FqYQTAyy7cdqk5j6/bzaudF1iXjLKHkAivOUD8zq4L16sgu8aYNpGE/I g6lYDb3t+MhwOC0diaQN8ew0zOkxckQCAUWKv9h5kh45Kbyda4WjB9v632xU6JphPA+d 6xIQ== ARC-Authentication-Results: i=1; mx.google.com; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p3-20020a17090635c300b0072b88a810c7si3528027ejb.493.2022.07.29.12.44.03; Fri, 29 Jul 2022 12:44:28 -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; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238238AbiG2Tl1 convert rfc822-to-8bit (ORCPT + 99 others); Fri, 29 Jul 2022 15:41:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55004 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237395AbiG2Tl0 (ORCPT ); Fri, 29 Jul 2022 15:41:26 -0400 Received: from mx0b-00082601.pphosted.com (mx0b-00082601.pphosted.com [67.231.153.30]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1A046EE0F for ; Fri, 29 Jul 2022 12:41:25 -0700 (PDT) Received: from pps.filterd (m0148460.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 26THAIXf028027 for ; Fri, 29 Jul 2022 12:41:24 -0700 Received: from maileast.thefacebook.com ([163.114.130.16]) by mx0a-00082601.pphosted.com (PPS) with ESMTPS id 3hkxjjgna0-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Fri, 29 Jul 2022 12:41:24 -0700 Received: from twshared22413.18.frc3.facebook.com (2620:10d:c0a8:1b::d) by mail.thefacebook.com (2620:10d:c0a8:82::e) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.28; Fri, 29 Jul 2022 12:41:23 -0700 Received: by devbig932.frc1.facebook.com (Postfix, from userid 4523) id 2B984AD80AAB; Fri, 29 Jul 2022 12:41:13 -0700 (PDT) From: Song Liu To: , , CC: , , , , Song Liu , Andrii Nakryiko Subject: [PATCH bpf-next] bpf: fix test_progs -j error with fentry/fexit tests Date: Fri, 29 Jul 2022 12:41:06 -0700 Message-ID: <20220729194106.1207472-1-song@kernel.org> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8BIT X-FB-Internal: Safe Content-Type: text/plain X-Proofpoint-GUID: 13PC6IpBdv9hnE5kHt8FaX4rOm_KkHCb X-Proofpoint-ORIG-GUID: 13PC6IpBdv9hnE5kHt8FaX4rOm_KkHCb X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.883,Hydra:6.0.517,FMLib:17.11.122.1 definitions=2022-07-29_19,2022-07-28_02,2022-06-22_01 X-Spam-Status: No, score=-1.6 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE autolearn=no 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 Then multiple threads are attaching/detaching fentry/fexit programs to the same trampoline, we may call register_fentry on the same trampoline twice: register_fentry(), unregister_fentry(), then register_fentry again. This causes ftrace_set_filter_ip() for the same ip on tr->fops twice, which leaves duplicated ip in tr->fops. The extra ip is not cleaned up properly on unregister and thus causes failures with further register in register_ftrace_direct_multi(): register_ftrace_direct_multi() { ... for (i = 0; i < size; i++) { hlist_for_each_entry(entry, &hash->buckets[i], hlist) { if (ftrace_find_rec_direct(entry->ip)) goto out_unlock; } } ... } This can be triggered with parallel fentry/fexit tests with test_progs: ./test_progs -t fentry,fexit -j Fix this by resetting tr->fops in ftrace_set_filter_ip(), so that there will never be duplicated entries in tr->fops. Fixes: 00963a2e75a8 ("bpf: Support bpf_trampoline on functions with IPMODIFY (e.g. livepatch)") Reported-by: Andrii Nakryiko Signed-off-by: Song Liu --- kernel/bpf/trampoline.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/bpf/trampoline.c b/kernel/bpf/trampoline.c index 42e387a12694..7ec7e23559ad 100644 --- a/kernel/bpf/trampoline.c +++ b/kernel/bpf/trampoline.c @@ -255,7 +255,7 @@ static int register_fentry(struct bpf_trampoline *tr, void *new_addr) return -ENOENT; if (tr->func.ftrace_managed) { - ftrace_set_filter_ip(tr->fops, (unsigned long)ip, 0, 0); + ftrace_set_filter_ip(tr->fops, (unsigned long)ip, 0, 1); ret = register_ftrace_direct_multi(tr->fops, (long)new_addr); } else { ret = bpf_arch_text_poke(ip, BPF_MOD_CALL, NULL, new_addr); -- 2.30.2