Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp1549449rwd; Thu, 25 May 2023 14:26:16 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5xQQaW+HSDSgjuvASSQherAlgE73oKMKHIrAKTEYj7/LLono11izJvZEI6FLXqkyy1oVJN X-Received: by 2002:a05:6a21:99a4:b0:10c:2cb7:29b1 with SMTP id ve36-20020a056a2199a400b0010c2cb729b1mr16077635pzb.51.1685049975953; Thu, 25 May 2023 14:26:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685049975; cv=none; d=google.com; s=arc-20160816; b=gqwyKAj5QGEInYzRm3GHjFxJl2LlLXrMcJdZann7SYMp3XcEh6mYwJkWKu7Ylvo6rI FiWt6lwq8CStG5H+QXMWYZjGvPkW7ywNE8j3TV4KhpXSRu3hAym1g8hy76SuthNRjvqy ySSc+4GZkia8c6JterzZwJwNtc7Puk6sgvzWskOGYKG6QRglDLGs1JagUI2pTT9a+9ZJ oO46xXkJOb09C9NC3ZWcWRFA/PdDRdWGukFtG/lxWwoaNud5SB4wr4CuC69TBrjRVZDH bXv6VUpziB9pNTBHVfyhG9thjzmvTGUAaOKHXMWuGaznnJghWrAy3gs7oozA6M8N2t4N MfEQ== 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=9SZgJkEuk57kDCIrdJoLldT8KXfqYqeFjG76R55NgrE=; b=QuFya6FyNxHIHDnOBvaYCUOeoLwx/ciwe+dJ2aSmPsBo5IHHo96+anZ9K2yMqdjg9F ztJwZQjisZyCF+abx9iU7ozg4VtOr4XF58PtwOOLfjBvP/+QKDvoG5IEstRGSmWXB63i 8HXUCP1e6llgL4SNo9XWD5lzd6seZNqbOH0V6i1GGQ9EOjg5SdY+IwBLCJPdlOhQD+ma KUAC+MGU/5/aXTS1xZPol3t7m4yxYX3I+05J8fxCrbXQRSxZOrqekz2julwsD73ULAXO je3n3llrAKEKgMGsmc2f6+kiqfCLxi9ZHUP7D9TWoeNcf6sZirfVln+6GDaJgthuiGhK tNGg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b=JaqdJoj9; 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 t23-20020aa79477000000b0063b872934a4si1043141pfq.340.2023.05.25.14.26.04; Thu, 25 May 2023 14:26:15 -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=JaqdJoj9; 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 S235290AbjEYVNd (ORCPT + 99 others); Thu, 25 May 2023 17:13:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58916 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229470AbjEYVNc (ORCPT ); Thu, 25 May 2023 17:13:32 -0400 Received: from mail-lf1-x131.google.com (mail-lf1-x131.google.com [IPv6:2a00:1450:4864:20::131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5F1E89E for ; Thu, 25 May 2023 14:13:30 -0700 (PDT) Received: by mail-lf1-x131.google.com with SMTP id 2adb3069b0e04-4f4b0a0b557so2966994e87.1 for ; Thu, 25 May 2023 14:13:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=google; t=1685049208; x=1687641208; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=9SZgJkEuk57kDCIrdJoLldT8KXfqYqeFjG76R55NgrE=; b=JaqdJoj9FHwmqSNvGCTLn6JkyfBJXC2SvUwAMk/jEV2ZshDAV0tXnrE12dQqxrI18Z /E6pgcbNwp5Qz6XhHWMAw6TpizGL5QO5arU/UQJmWffUcqub9HRQl1tcR5PEdTFy4DU+ xFZuQuCeSExnUERqP9+oy5Vc5i9LZzisLqRHQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685049208; x=1687641208; 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=9SZgJkEuk57kDCIrdJoLldT8KXfqYqeFjG76R55NgrE=; b=OcANQ5sYClEYqYNpggE/xbgHcH9zi64u0lKWPpPu/zkBFRvsHdj5NtlR77xLTGO2ic SScoNjiPnlunNNlf7RZXE7WBhn7fQ3oxrneDpZuevtGHqKkizYP37xxdNJ1q8IZgyt74 lpwmEzjGuHkKNDQLhlSHGYp64st7QswcwfYDg4ENEK1xngW20e0hk0/T/8KjoAHCJrxv MfPQDoJH15pB9i1/1zXsT23BlxxreIhiQdKyOxFaK3NREnCalzjosfgq49DOG4wKCg1A WSL3kIBUPYyo+6uRqFDAPUQRiLMhnmsiX3DBWdKZgq9W6BLznk81HjRtQ8sdoyqAk6OJ u6NA== X-Gm-Message-State: AC+VfDxUagl3kHWfdp+ytShmZ5FSH4B4MFlTss+3Iqge2LKYvIIlR1hn /5cMP5ZhRahelUL5QLGoEz1x9tUDx14mDFTnvPqX2qwi X-Received: by 2002:ac2:5fe4:0:b0:4f2:5338:d0a8 with SMTP id s4-20020ac25fe4000000b004f25338d0a8mr7375877lfg.56.1685049208378; Thu, 25 May 2023 14:13:28 -0700 (PDT) Received: from mail-lf1-f47.google.com (mail-lf1-f47.google.com. [209.85.167.47]) by smtp.gmail.com with ESMTPSA id j28-20020ac2551c000000b004f399531e8csm338457lfk.226.2023.05.25.14.13.27 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 25 May 2023 14:13:27 -0700 (PDT) Received: by mail-lf1-f47.google.com with SMTP id 2adb3069b0e04-4f3b39cea1eso2950967e87.3 for ; Thu, 25 May 2023 14:13:27 -0700 (PDT) X-Received: by 2002:a17:907:1628:b0:973:8edc:5a3a with SMTP id hb40-20020a170907162800b009738edc5a3amr82698ejc.30.1685049186309; Thu, 25 May 2023 14:13:06 -0700 (PDT) MIME-Version: 1.0 References: <20230524213620.3509138-1-mcgrof@kernel.org> <20230524213620.3509138-3-mcgrof@kernel.org> <8fc5b26b-d2f6-0c8f-34a1-af085dbef155@suse.com> <6gwjomw6sxxmlglxfoilelswv4hgygqelomevb4k4wrlrk3gtm@wrakbmwztgeu> In-Reply-To: <6gwjomw6sxxmlglxfoilelswv4hgygqelomevb4k4wrlrk3gtm@wrakbmwztgeu> From: Linus Torvalds Date: Thu, 25 May 2023 14:12:49 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH 2/2] module: add support to avoid duplicates early on load To: Lucas De Marchi Cc: Petr Pavlu , Luis Chamberlain , gregkh@linuxfoundation.org, rafael@kernel.org, song@kernel.org, lucas.de.marchi@gmail.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, 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, prarit@redhat.com, lennart@poettering.net Content-Type: multipart/mixed; boundary="0000000000002e29d205fc8b1635" 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 --0000000000002e29d205fc8b1635 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Thu, May 25, 2023 at 11:45=E2=80=AFAM Lucas De Marchi wrote: > > Are you willig to merge (a possibly improved version of) your patch > or the userspace change is still something that would be desired? I think a user space change should still be something that people should look at, particularly as the kernel side patch I'm willing to accept doesn't catch the "completely serial" cases, only the "trying to load at the same time that the same module is literally busy being loaded". But I've cleaned up my patch a bit, and while the cleaned-up version is rather larger as a patch (mainly because of just also re-organizing the finit_module() code to do all the 'struct file' prep), I'm actually pretty happy with this attached patch conceptually. In this form, it actually "makes sense" to me, rather than being just clearly a workaround. Also, unlike the previous patch, this doesn't actually make any changes to the basic kernel_read_file() set of functions, it's all done by the module loading code itself. Luis, would you mind testing this version on your load? It still won't actually handle the purely serial case, so there *will* be those spurious double module reads from different CPU's just doing the things serially, but the exclusive file access region has been extended to not just cover the actual file content reading, but to cover the whole "turn it into a a real module" part too. Also, this does *not* update some of the comments in the module loading. I changed finit_module to use "kernel_read_file()" instead of "kernel_read_file_from_fd()", since it actually now has to look up the file descriptor anyway. But the comments still talk about that "from_fd" thing. Anyway, this is back to "ENTIRELY UNTESTED" territory, in that I've compiled this, but haven't booted it. The changes look obvious, but hey, mistakes happen. And the commit message is just a place-holder. Obviously. I won't sign off on this or write more of a commit message until it has had some real testing. Linus --0000000000002e29d205fc8b1635 Content-Type: text/x-patch; charset="US-ASCII"; name="0001-Attempt-at-workaround-for-horrible-udev-module-loadi.patch" Content-Disposition: attachment; filename="0001-Attempt-at-workaround-for-horrible-udev-module-loadi.patch" Content-Transfer-Encoding: base64 Content-ID: X-Attachment-Id: f_li3mpxbp0 RnJvbSBlMzIyM2JmYmRkNTQ1NWYwYjExMzM3YTU5MWZhZDNhMTgxNmI5ZDA5IE1vbiBTZXAgMTcg MDA6MDA6MDAgMjAwMQpGcm9tOiBMaW51cyBUb3J2YWxkcyA8dG9ydmFsZHNAbGludXgtZm91bmRh dGlvbi5vcmc+CkRhdGU6IFRodSwgMjUgTWF5IDIwMjMgMDk6MzI6MjUgLTA3MDAKU3ViamVjdDog W1BBVENIXSBBdHRlbXB0IGF0IHdvcmthcm91bmQgZm9yIGhvcnJpYmxlIHVkZXYgbW9kdWxlIGxv YWRpbmcKIGJlaGF2aW9yCgotLS0KIGluY2x1ZGUvbGludXgvZnMuaCAgIHwgIDYgKysrKwoga2Vy bmVsL21vZHVsZS9tYWluLmMgfCA3MiArKysrKysrKysrKysrKysrKysrKysrKysrKysrKystLS0t LS0tLS0tLS0tLQogMiBmaWxlcyBjaGFuZ2VkLCA1NiBpbnNlcnRpb25zKCspLCAyMiBkZWxldGlv bnMoLSkKCmRpZmYgLS1naXQgYS9pbmNsdWRlL2xpbnV4L2ZzLmggYi9pbmNsdWRlL2xpbnV4L2Zz LmgKaW5kZXggMjFhOTgxNjgwODU2Li43MjJiNDJhNzdkNTEgMTAwNjQ0Ci0tLSBhL2luY2x1ZGUv bGludXgvZnMuaAorKysgYi9pbmNsdWRlL2xpbnV4L2ZzLmgKQEAgLTI1NjYsNiArMjU2NiwxMiBA QCBzdGF0aWMgaW5saW5lIGludCBkZW55X3dyaXRlX2FjY2VzcyhzdHJ1Y3QgZmlsZSAqZmlsZSkK IAlzdHJ1Y3QgaW5vZGUgKmlub2RlID0gZmlsZV9pbm9kZShmaWxlKTsKIAlyZXR1cm4gYXRvbWlj X2RlY191bmxlc3NfcG9zaXRpdmUoJmlub2RlLT5pX3dyaXRlY291bnQpID8gMCA6IC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