Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp2699401rwd; Wed, 17 May 2023 13:11:34 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ74z/5lTrfsE69kGV04kyLaMoo6K4huVCB+RXK2EX0j6lE3Q6dD98xWnMHugDuOFKRdUdEz X-Received: by 2002:a05:6a20:394d:b0:104:8824:74eb with SMTP id r13-20020a056a20394d00b00104882474ebmr24424018pzg.51.1684354294165; Wed, 17 May 2023 13:11:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684354294; cv=none; d=google.com; s=arc-20160816; b=oyM7BIlwc+MmM+zZVneJypvDnGwBz0lr8BHs6dFVBnXWSqZ+oJk6vOZcaJvERfrYGt y37GEB8TebxGMDuZnzrVWYHqvk/UtWhqgkYQbGLjaZT0M2oslJiX4USCpRfuRq85VQYv i5LG/mgox0K+sGjOTKmb7eWCSRJl1p/ZmY89xKeeR1jcQ8slF1rnlZsJm7SFCxGHrAWt Jjv7CYNGjPE4ROqYvoVbY6FV4paW6VOCMsvuPle2y5/W2CzAgYoDqubPOMwFhDdtwtFr bwWSW9++tXbpBfw3F3Hn6tlsvMYZ91F2HYV+0DiJ3Kx4RhJ7QJ/L98KTWNZMkUM/PQxG s8PA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=qUJuL+2WvYBnwuI2AxMqbxeUZxgtHjH0G/Zm8si7raQ=; b=0RO5UtkyfZjKjc4nYVGRyQmJfH9itIlSdhlLWO712FYRFhk1b8d/VP7jeEjRH1+oH+ uzX1CtZJofwmVNQyRNMfejLTNbRyi3r1Ev5Epl2/0A62mPRp6clOW40kmMh1rSO6bwzB 7UnFOyjWhz9qYVFjPPaJTkXuSvVP1nmHU7hD6TTV6whkX2NeYRFxdF8nSwDrmLVdqGHI w0hYBEJVT4qPDJTm3UW/H6laIYrPa80ZvqtXZS1eXyicXBiYhClN/VXAd4YjxCCTb7lk BDvKh9Us1DXp78hc7uIQQ4MMOe531NvBX88XLI9XTS5smq+OQGBuH5bXr5fnACm6KWyo X69w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b=FswP8g2F; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g12-20020a63ad0c000000b0051b29733bc9si21402604pgf.715.2023.05.17.13.11.19; Wed, 17 May 2023 13:11:34 -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=@linux-foundation.org header.s=google header.b=FswP8g2F; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229453AbjEQUJX (ORCPT + 99 others); Wed, 17 May 2023 16:09:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44756 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229445AbjEQUJV (ORCPT ); Wed, 17 May 2023 16:09:21 -0400 Received: from mail-ed1-x535.google.com (mail-ed1-x535.google.com [IPv6:2a00:1450:4864:20::535]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 066706E8B for ; Wed, 17 May 2023 13:09:19 -0700 (PDT) Received: by mail-ed1-x535.google.com with SMTP id 4fb4d7f45d1cf-50bc456cc39so1857504a12.1 for ; Wed, 17 May 2023 13:09:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=google; t=1684354157; x=1686946157; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=qUJuL+2WvYBnwuI2AxMqbxeUZxgtHjH0G/Zm8si7raQ=; b=FswP8g2FI3659/s/93gVCGsv3xZZtGIZfyfW2LeNfXS8vk7ZVBjKBV5EubqxsPWC4B DTiSzYAVTqlLfpqatXRUYC2ud7ZZO/vsf5e6eQGX32M+kzCJw+W5bHv1BObk06wK2Nh+ YyCLeqhvFzPSmMK/EQYkoCJ95VGK9AkRl/KJw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684354157; x=1686946157; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=qUJuL+2WvYBnwuI2AxMqbxeUZxgtHjH0G/Zm8si7raQ=; b=efikaB8+A6N2UdeoZECoqy+hyktb2rFsuOLq7RNS4zHczTJDmDI5+D+GQ9TxbJJkKq ITmXV4tUh1TaBZytp42jQBd4vUNkvGGGmsqIJd7bQ41KqgxBmkOwBv/CBNZdBDwcI3R3 S4maX4mH0XHplL+hwvgDuEQvTTjzNWEi+nZZuZS2Ib7627DqviaifgTDLNJRTWysDX2h fWHRHBL8lJweHRvzizsZP1YKybxkK7n+Iv9JKvZ903TQq9rtASmMvKfT56rSYZ8rjO4Z R7B9sbHRXur+cu1TrWGrkZ21joP2xqq+CjBTh++ZW9gDNDS4Q7l6tK51RPyCLQ/8JVO7 +JSg== X-Gm-Message-State: AC+VfDzCpmlpbWfELQ/Tbz9zEZlLHN2l2bC1BGuOpFLp1LQ5ZdUZf1hp DL74Ynhv8TQwd94JtJWj1MMX+e77gvjqf6LNpRCWdpvN X-Received: by 2002:aa7:df0d:0:b0:50b:c9d7:8b24 with SMTP id c13-20020aa7df0d000000b0050bc9d78b24mr3270574edy.6.1684354157288; Wed, 17 May 2023 13:09:17 -0700 (PDT) Received: from mail-ej1-f45.google.com (mail-ej1-f45.google.com. [209.85.218.45]) by smtp.gmail.com with ESMTPSA id u24-20020a056402111800b0050bc4eb9846sm9583584edv.1.2023.05.17.13.09.16 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 17 May 2023 13:09:16 -0700 (PDT) Received: by mail-ej1-f45.google.com with SMTP id a640c23a62f3a-9659c5b14d8so189325666b.3 for ; Wed, 17 May 2023 13:09:16 -0700 (PDT) X-Received: by 2002:a17:907:7291:b0:96a:717:d452 with SMTP id dt17-20020a170907729100b0096a0717d452mr29868922ejc.19.1684354155799; Wed, 17 May 2023 13:09:15 -0700 (PDT) MIME-Version: 1.0 References: <20230509163050.127d5123@rorschach.local.home> <20230515165707.hv65ekwp2djkjj5i@MacBook-Pro-8.local> <20230515192407.GA85@W11-BEAU-MD.localdomain> <20230517003628.aqqlvmzffj7fzzoj@MacBook-Pro-8.local> <20230516222919.79bba667@rorschach.local.home> <20230517172243.GA152@W11-BEAU-MD.localdomain> <20230517190750.GA366@W11-BEAU-MD.localdomain> In-Reply-To: From: Linus Torvalds Date: Wed, 17 May 2023 13:08:59 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH] tracing/user_events: Run BPF program if attached To: Beau Belgrave Cc: Steven Rostedt , Alexei Starovoitov , Masami Hiramatsu , LKML , linux-trace-kernel@vger.kernel.org, Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , bpf , David Vernet , dthaler@microsoft.com, brauner@kernel.org, hch@infradead.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-1.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE, URIBL_BLOCKED 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 On Wed, May 17, 2023 at 12:36=E2=80=AFPM Linus Torvalds wrote: > > .. this is the patch that I think should go on top of it to fix the > misleading "safe" and the incorrect RCU walk. > > NOTE! This adds that > > lockdep_assert_held(&event_mutex); > > to user_event_enabler_update() too. One more note: I think it would be really good to use different names for the "links". We have "mm->link", that is the list of mm's on the 'user_event_mms' list, protected by the 'user_event_mms_lock' and RCU-walked. And then we have 'enabler->link', which is the list of enables on the 'user_mm->enablers' list, protected by event_mutex, and _also_ occasionally RCU-walked. And then we have 'validator->link', which isn't RCU-walked, and seems to also be protected by the event_mutex (?). This is all very confusing when looking at it as an outsider. Particularly when you sometimes just see list_del_rcu(&mm->link); and you have to figure "which 'link' are we talking about again?". Also, I have to say, I found "mm->next" *really* confusing at first. It turns out that "mm->next" is this list that is dynamically built up by user_event_mm_get_all(), and is only a one-shot list that is valid only as long as 'event_mutex' is held. But the only lock the code *talks* about is the RCU lock, which does *not* protect that list, and only exists as a way to walk that user_event_mms list without taking any locks. So user_event_enabler_update() actually relies on that 'event_mutex' lock in another way than the obvious one that is about the mm->enablers list that it *also* walks. Again, that all seems to work, but it's *really* confusing how "mm->next" always exists as a field, but is only usable and valid while you hold that event_mutex and have called user_event_mm_get_all() to gather the list. I think both user_event_enabler_update() and user_event_mm_get_all() should have a mention of how they require event_mutex and how that ->next list works. Anyway, I still *think* the two patches I sent out are right, but I'm just mentioning this confusion I had to deal with when trying to decode what the rules were. Maybe all the above is obvious to everybody else, but it took me a while to decipher (and maybe I misread something). Linus