Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp2664457rwd; Wed, 17 May 2023 12:39:57 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5dGuLvNOq9YtvYpNBPgdctB7xfJVx+FvED2hE7gBj3fGZcO9ESjD6AD7OtDoiB53qvNUCV X-Received: by 2002:a05:6a00:10c9:b0:64c:e899:dcd1 with SMTP id d9-20020a056a0010c900b0064ce899dcd1mr1206083pfu.5.1684352396695; Wed, 17 May 2023 12:39:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684352396; cv=none; d=google.com; s=arc-20160816; b=uG6dbfLtm/BT3ey7AWzaA0exdfQZYU1vmKafNgMjspZ0zTqVlkHiGp4u7ZjuBkqdAo FQXLmiOwPGVPc1JgFHSdlSj8Dy8pI3Ju/qCmqAZQbdVZ2Pxc8AED/MoNQKQ9BHebRtz/ rgbg5AlVSMtCdQaCCpb6j2pKzCXcbRfqnR372B+v800B26F8gbTdlsZEE1Yi8LheDPPZ M+AGfpIHSswCzSpm0cFs13jHmWFLbrfJDF8EhdUGVLXrarwgLQgF3tf08tbQshKN1/Mi wmWO+4Zh4YrXwSzEu70Ed+fzcgW4uVs6C/aUMlKYbnbfndSkywcZ349KPm8m6C74SAnD b4hg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=WBSaYe/tGc9yPiLd8UilCx8N10jcny5QbPvRBer8Htw=; b=wGA47WtoSRvMD5nsO+d2W0oxpMuvhMUlHEx2DsbT1z/kd7Tat+xExOibQo2CR2WnTo sT41wTzIeBuNHGBa9J88ZucZN8UFHmWwoMWvhYGGqsttB5MFnjFuVmNOySS3IszGgPDb 5bTG2AGAZLPqr/xSBWgD3o23i0Db1g+agTEvgBfQudyrZe1fHtyvbbdPGQHZASRHGxM9 2bzfxRloLw5CUeWrHvPA4z8btlqnPdiYca8VE6bwO7GtiO3Nr0lYS6pVb1O9xm2wxFku ZRRCqfgww64AlooxpTcFFI8+7mnyBZJcw/INfLEHePJRT7fA3jXO1kDlU7gvMeafPEAu /BJQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b=HBKWQFa2; 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 v29-20020aa799dd000000b0063d270ccc12si23036210pfi.180.2023.05.17.12.39.43; Wed, 17 May 2023 12:39:56 -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=HBKWQFa2; 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 S230219AbjEQT2H (ORCPT + 99 others); Wed, 17 May 2023 15:28:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46040 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229949AbjEQT1n (ORCPT ); Wed, 17 May 2023 15:27:43 -0400 Received: from mail-ed1-x52a.google.com (mail-ed1-x52a.google.com [IPv6:2a00:1450:4864:20::52a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5AEC6D2C2 for ; Wed, 17 May 2023 12:27:10 -0700 (PDT) Received: by mail-ed1-x52a.google.com with SMTP id 4fb4d7f45d1cf-50bc456cc39so1797646a12.1 for ; Wed, 17 May 2023 12:27:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=google; t=1684351625; x=1686943625; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=WBSaYe/tGc9yPiLd8UilCx8N10jcny5QbPvRBer8Htw=; b=HBKWQFa2DPuj10BEKCtwv9YqZn8eBlRBDdJcmGxpxHSnoWtAtw1CLdBOvdjGsImt8W 3o8o/2/sH+g+2v1pUbcZpmcpZQU0oQAY9v33YPR0JJk1aZfxpwQjsRZgvvoqdeA0h7Ba VVyDKj3O0rxroNIUQI90EXatNrBQofxO4GsDU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684351625; x=1686943625; h=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=WBSaYe/tGc9yPiLd8UilCx8N10jcny5QbPvRBer8Htw=; b=KMWmxAlWRph0ZTzW6NE9qs+an1G3FaXtWHK24KqVQml18s3f8joeqmuC/25Fgwqe0t jBdCKHmP73oPeWZBlcdLJiMhliRkLcd3DrQq3D/SEqOeY4tgGnMmKaGn28Y9s1h86DkM XvKpqczAzeDkBXavKcahrjt2MmRvgqiP0j6aOyWuGMcfLfpYUAK7DZnXIxA9KwrgktJO xTKeDdM2bzLiv7OKDOitacuCaSFo4bl8YfcCyLyb9xCUXsOtmwjrTsC2yySQt4HHjwt2 kBL5UhjNWB9VOttbkcXYLuGyC/sgNR1U95ZMtWzbUKYDoYtnOLsOeE6FElEvQN/JhFv9 CCcg== X-Gm-Message-State: AC+VfDx197+fj9BtPwT/9ZQtiEyaOZeQDnVrHnhtEB+GG4krdvZGW2/A AKWmEf+6GLQu0fomwNPaAicgYWVX54QHJZNgK3z2pxCU X-Received: by 2002:a05:6402:783:b0:50d:ff73:64ef with SMTP id d3-20020a056402078300b0050dff7364efmr3064535edy.20.1684351624744; Wed, 17 May 2023 12:27:04 -0700 (PDT) Received: from mail-ej1-f52.google.com (mail-ej1-f52.google.com. [209.85.218.52]) by smtp.gmail.com with ESMTPSA id q22-20020aa7da96000000b0050470aa444fsm9658707eds.51.2023.05.17.12.27.02 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 17 May 2023 12:27:03 -0700 (PDT) Received: by mail-ej1-f52.google.com with SMTP id a640c23a62f3a-965ab8ed1c0so182855066b.2 for ; Wed, 17 May 2023 12:27:02 -0700 (PDT) X-Received: by 2002:a17:907:9603:b0:960:ce5:20c0 with SMTP id gb3-20020a170907960300b009600ce520c0mr30090557ejc.20.1684351622229; Wed, 17 May 2023 12:27:02 -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: <20230517190750.GA366@W11-BEAU-MD.localdomain> From: Linus Torvalds Date: Wed, 17 May 2023 12:26:44 -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: multipart/mixed; boundary="0000000000001f8c7105fbe8ac17" 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 --0000000000001f8c7105fbe8ac17 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Wed, May 17, 2023 at 12:08=E2=80=AFPM Beau Belgrave wrote: > > user_event_mm_dup() puts a new mm into the global list before the > enablers list is fully populated. Then that simply needs to be fixed. user_event_mm_dup() should not madd the mm into the global list until it is *done*. Because if it makes that list visible to others in a half-way state, then it needs to use the proper locking and use event_mutex. You can't say "this is so critical that we can't take a lock" and then use that as an excuse to simply do buggy code. Either take the lock in user_event_mm_dup(), or make sure that the data structures are all completely local so that no lock is necessary. Here's a COMPLETELY UNTESTED patch that just separates out the notion of "allocate" and "attach". NOTE NOTE NOTE! I am *not* claiming this patch works. It builds for me. It looks right. It seems like it's the right thing to do. But it might have some issues. With this, the newly dup'ed list is attached to the process once after it is done, so nobody can see the list being built up. Also note that this does NOT fix the incorrect RCU walks. Linus --0000000000001f8c7105fbe8ac17 Content-Type: text/x-patch; charset="US-ASCII"; name="patch.diff" Content-Disposition: attachment; filename="patch.diff" Content-Transfer-Encoding: base64 Content-ID: X-Attachment-Id: f_lhs3gera0 IGtlcm5lbC90cmFjZS90cmFjZV9ldmVudHNfdXNlci5jIHwgMjkgKysrKysrKysrKysrKysrKysr LS0tLS0tLS0tLS0KIDEgZmlsZSBjaGFuZ2VkLCAxOCBpbnNlcnRpb25zKCspLCAxMSBkZWxldGlv bnMoLSkKCmRpZmYgLS1naXQgYS9rZXJuZWwvdHJhY2UvdHJhY2VfZXZlbnRzX3VzZXIuYyBiL2tl cm5lbC90cmFjZS90cmFjZV9ldmVudHNfdXNlci5jCmluZGV4IGIxZWNkNzY3NzY0Mi4uYjJhZWNi ZmJiZDI0IDEwMDY0NAotLS0gYS9rZXJuZWwvdHJhY2UvdHJhY2VfZXZlbnRzX3VzZXIuYworKysg Yi9rZXJuZWwvdHJhY2UvdH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