Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp413660rwd; Wed, 24 May 2023 21:10:32 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5zk2u6yr1yfs/tCrXVz77QNq5JQmxQHRA/LU4Hh2f5jKi4kHkFvcyLgGzDoC8fUiEdIxXj X-Received: by 2002:a05:6a00:1493:b0:64a:ede1:13fb with SMTP id v19-20020a056a00149300b0064aede113fbmr6491737pfu.9.1684987831879; Wed, 24 May 2023 21:10:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684987831; cv=none; d=google.com; s=arc-20160816; b=W7IyAfaEKV2G8GRx+R181hbuqd+zC67UjtWf2k2qKGt6UZ+z9h98PvKJe/kerLhshl 9sn9N3iKCeFQ5smhenVh04gjtgCOAF6ECnPcmlb/aCwryM2CbVZkuuC1ADPo7kjZ8l/H ZHs/upxd3X78mjUYgO/+CWpG2W6/LSGS7TDLB+/2hlGxi5m3jqlhu0IsaO4wPw0yFBGg aZL1XV5Jvw/R/9VIaBlLXtb11Vnhudm5LI5wkJkyonFRtR/snGU9ODBvqUYJ+lNTEMsh mK4oWhgeVjWCd7hEfTDjJcJXdxuy0IsxjZgUbYQxtt4oc1h/CDPM7KaEawFMeXk8Kwg6 a46w== 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=M9wvkrHiO2vLfdNjz3Lr8jzqTeFi37UzWEdwoU59g04=; b=BySOn2SoDrFnb7NbN34gkYpvo10p+VHF8mzyU6FJY6RBr0HH0rEHSsTkCJVEXO+WJX LGFZ6xEJbRXJ6hK6mCX3aKQHLr7qzvDlrXTsK6drESV+oN/dbZXdipKAJS/zAelKq6aX 9axXOqUAcCGuKoUpLePn76LTCf8IF9mpcpWgkuG2rfyob3mQCRvtLtS7ApjgUU36X50C sckh1DmVFJ5ybQHKqp3dWF5lwY9thaT0LPHugXHv3HRnCnWJuTgtVx9H9cQze5kB7Zaj 5pcwVoKa8vrUFnefky+WYj6oG2KR2Sz2dpCdUqrocy3X5n1JocmLnvbJgXEb3A/wibFH N4wg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b=EWp2V1FB; 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 a5-20020a624d05000000b00624eb57b45dsi531772pfb.74.2023.05.24.21.10.18; Wed, 24 May 2023 21:10:31 -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=EWp2V1FB; 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 S229725AbjEYEA2 (ORCPT + 99 others); Thu, 25 May 2023 00:00:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38176 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229441AbjEYEA0 (ORCPT ); Thu, 25 May 2023 00:00:26 -0400 Received: from mail-ej1-x633.google.com (mail-ej1-x633.google.com [IPv6:2a00:1450:4864:20::633]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BA2F8E2 for ; Wed, 24 May 2023 21:00:23 -0700 (PDT) Received: by mail-ej1-x633.google.com with SMTP id a640c23a62f3a-96f7bf3cf9eso21629166b.0 for ; Wed, 24 May 2023 21:00:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=google; t=1684987222; x=1687579222; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=M9wvkrHiO2vLfdNjz3Lr8jzqTeFi37UzWEdwoU59g04=; b=EWp2V1FBv1aqQurjV8pfFEsaZFS9P8p1UAfqYOgaR8Td7ABfNpwyir3kgqWUmDJ2yf qBsPP7zq7pVIQIqaXCwxi6RQje+dU7w5NJhT4MwnUFJ3j67yqkV8aWZ4oHzSg+rBuoPa PLFOE8kIBZ1AZPb+bZkM24IO+g1UgtxhXiy/M= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684987222; x=1687579222; 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=M9wvkrHiO2vLfdNjz3Lr8jzqTeFi37UzWEdwoU59g04=; b=incdADAanhb+kbI2VU8kAhpcrdHG456OMGQZF5w2OVLuLEz4LYx4uCrB6qYsBSFlKA E5v/k1x5K/V1snpmCnWk0HzSFqhV31AmjPWPsklvMJI1wHHZxGvMWQwJFw42ookjp+dE dMvVZlq2pAA2/QF+o5zNFPCql7BG8tm3CX6op4sjcttDIV29E68eWWt9k3h3IQxiEBCP 49rwkIH3hmlSIPgSC2S5q+iCCjFiqlFbu8MM2UQm9cqyZqzwBVMdoCNHAr29aCVHTQSD SNyPlDSlVgVfH8D7f04WeoH6U0xo0OEeBZ4wvCaygaxE7ABdQmFctXLrFM4MxYIsILhB HdUg== X-Gm-Message-State: AC+VfDz54DjzCnCxV8h6VFVdzcgzsG3Nid3wuNc1GaOSZYkZ9pbTWLmp LTsEOBDQ+IiGgNogr3VFioRtkLnNTuo6/jZKyk+BV/AX X-Received: by 2002:a17:907:934c:b0:94e:e859:7b07 with SMTP id bv12-20020a170907934c00b0094ee8597b07mr159574ejc.32.1684987219910; Wed, 24 May 2023 21:00:19 -0700 (PDT) Received: from mail-ej1-f50.google.com (mail-ej1-f50.google.com. [209.85.218.50]) by smtp.gmail.com with ESMTPSA id x23-20020a170906149700b00969dc13d0b1sm250266ejc.43.2023.05.24.21.00.19 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 24 May 2023 21:00:19 -0700 (PDT) Received: by mail-ej1-f50.google.com with SMTP id a640c23a62f3a-970028cfb6cso20258066b.1 for ; Wed, 24 May 2023 21:00:19 -0700 (PDT) X-Received: by 2002:a17:907:985:b0:968:4ce9:677a with SMTP id bf5-20020a170907098500b009684ce9677amr154847ejc.38.1684987218743; Wed, 24 May 2023 21:00:18 -0700 (PDT) MIME-Version: 1.0 References: <20230524213620.3509138-1-mcgrof@kernel.org> <20230524213620.3509138-2-mcgrof@kernel.org> In-Reply-To: From: Linus Torvalds Date: Wed, 24 May 2023 21:00:02 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH 1/2] fs/kernel_read_file: add support for duplicate detection To: Luis Chamberlain Cc: david@redhat.com, tglx@linutronix.de, hch@lst.de, patches@lists.linux.dev, linux-modules@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, pmladek@suse.com, petr.pavlu@suse.com, prarit@redhat.com, lennart@poettering.net, gregkh@linuxfoundation.org, rafael@kernel.org, song@kernel.org, lucas.de.marchi@gmail.com, lucas.demarchi@intel.com, christophe.leroy@csgroup.eu, peterz@infradead.org, rppt@kernel.org, dave@stgolabs.net, willy@infradead.org, vbabka@suse.cz, mhocko@suse.com, dave.hansen@linux.intel.com, colin.i.king@gmail.com, jim.cromie@gmail.com, catalin.marinas@arm.com, jbaron@akamai.com, rick.p.edgecombe@intel.com, yujie.liu@intel.com Content-Type: multipart/mixed; boundary="000000000000a047aa05fc7ca823" 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 --000000000000a047aa05fc7ca823 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Wed, May 24, 2023 at 2:52=E2=80=AFPM Linus Torvalds wrote: > > This is all disgusting. Bringing back the original thread, because I just sent an alternate patch to Luis to test. That one is also disgusting, but for different reasons: it needs some polish if it works. It's a very simple patch, in that it just extends our existing i_writecount and ETXTBSY logic to also have a "exclusive" mode, and says that we do the module file reading in that exclusive mode (so if/when udev in its incompetence tries to load the same module X number of times at the same time, only one will read at a time). The disgusting part is mainly the hacky test for "id =3D=3D READING_MODULE", and it would probably be better with some kind of "exclusive flag" field for general use, but right now READING_MODULE is basically that one user. Luis having explained _why_ we'd want this (and honestly, it took a couple of tries), I can only say that udev is horribly broken, and this most definitely should be fixed in user mode. udev randomly loading the same module multiple times just because it gets confused is not ok. Any udev developer that goes "we can't fix it in user space" should be ashamed of themselves. Really? Just randomly doing the same thing in parallel and expecting the kernel to sort out your mess? What a crock. But this *might* mitigate that udev horror. And not introduce any new kernel-side horror, just a slight extension of our existing writer exclusion logic to allow "full exclusive access". (Note: it's not actually excluding other purely regular readers - but it *is* excluding not just writers, but also other "special readers" that want to exclude writers) I'd like to point out that this patch really is completely untested. It built for me, but that's all the testing it has gotten. It's _small_. Tiny, even. But that "id =3D=3D READING_MODULE" thing really is pretty disgusting and I feel this needs more thought. Linus --000000000000a047aa05fc7ca823 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_li2ltl2y0 IGZzL2tlcm5lbF9yZWFkX2ZpbGUuYyB8IDYgKysrKystCiBpbmNsdWRlL2xpbnV4L2ZzLmggICAg fCA2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