Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp1446559rwd; Thu, 25 May 2023 12:45:24 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4M8Ru1wLII5ZdOELoUy6RKpUPTLPpspVBhnD47d+6Cw+INeqPsSaMZwGiV1uhVjeg3Ay8A X-Received: by 2002:a05:6a20:8f07:b0:105:b75e:9df6 with SMTP id b7-20020a056a208f0700b00105b75e9df6mr27975370pzk.26.1685043924187; Thu, 25 May 2023 12:45:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685043924; cv=none; d=google.com; s=arc-20160816; b=WDB8oMVCecKXdauXROQ2XgIOVrwAklc83y1j76ws2ww4aEerI0xDgiLzsIYhU46jmQ HmF1uYU8Ti/QZKa1BJ/ezy9J8bpWvD1gI0viwMDJpzJMdhN+h7nYOQHVIPHcE8WtSLFC xdjzlkr/EUxiydWLQsOn/aIt9WpqWzs++K4hUHmidEJEU+BxfB4WqT+Yid39OVOhfYRp WAzN5WZ1O9bRAsKVQPyKU4HBt/OT5dIzeSJcKjf59XKBd1mDFDmAken9cz3/QX6I9mTv LkYo358esd6z8zekCCu+qCECMLSpHz5kC+dLWfM83sc4A52GiLgxU62x6JvMhSbE03tY mvfw== 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=aIsIFxmLlj97Nfx6D9vKSgsX1a6jDH3TwyPUkCdOSPQ=; b=yuP8N2LssrxgASOGT343qjDsMO0qcwwdu/v4W8IH50RTkcZ2MFl2ppM/CQ4P/ektG6 +kNBPZ6t5lvtD7f/XQIEq7vS29FBMrIciQEilIiANhRkXY0yGvCW4wqZ9wl8slRRq+S+ N60j0J1Ei08SXbNDvTWLkN2E/ThgeYNoeFiJ+d4slJhSa9Cfhkal9lm9zMd9/sNXTgyZ 49H85ZljvFtwSzNQ5Q3J5yuzmnMqjIJR0HpdCEpJU++TdC2S694PorKFEZofTh3xtT5s CXd2eu3xDq5MHbpYlYSJidyHV/o++8ntB4nNLaYt8HnrWY0nf9TUd4ikOcZxuRefT7wq MjVA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b=aJXv7msL; 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 m125-20020a633f83000000b0053f3e94d2ddsi468704pga.456.2023.05.25.12.45.10; Thu, 25 May 2023 12:45:24 -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=aJXv7msL; 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 S243680AbjEYTV7 (ORCPT + 99 others); Thu, 25 May 2023 15:21:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39050 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240643AbjEYTVm (ORCPT ); Thu, 25 May 2023 15:21:42 -0400 Received: from mail-ej1-x635.google.com (mail-ej1-x635.google.com [IPv6:2a00:1450:4864:20::635]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4D17AE68 for ; Thu, 25 May 2023 12:17:48 -0700 (PDT) Received: by mail-ej1-x635.google.com with SMTP id a640c23a62f3a-96ff9c0a103so161138066b.0 for ; Thu, 25 May 2023 12:17:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=google; t=1685042185; x=1687634185; 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=aIsIFxmLlj97Nfx6D9vKSgsX1a6jDH3TwyPUkCdOSPQ=; b=aJXv7msL9DrTUY8nTP6eYzvu5gs+lInFRlOLvZ9dPhvSmMchETpFRUDviL+a9C6jDA Tgw2Vv6ChUAI3TMz0fvwdsIjqCo1AKfeWd7A9CXtiLKiSctyFkHT3SKg0LiZk1NajQ4v saxwVtNg/PAhoBF+y2USvy4X9nKbiG2Knk+Dg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685042185; x=1687634185; 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=aIsIFxmLlj97Nfx6D9vKSgsX1a6jDH3TwyPUkCdOSPQ=; b=cVAcuZu1q7teCoPTpATzVuiHxUgZ9RTDmXaH6gP5z+WVndAAOV7peZPOPsQiP7BnqN 50BQYESE7+vr1cpA6h/NUYCiBB/ErRkKdQiA2gIkBXgbGLLHKnpevxCRFLqw3xwfBKiW 5nzgDENw77C/PGglzFUfIXkDhcfKaIiKJszQ4tWwE9nYfaH8hxbNh9OvxQ99pIbfSmD0 naeA2RHAFl6jsx3mo7OkIgqvaVT/mataEKoJIjLogAZT39T8QTGpBRKc2r6/bPPIsPgc Zj52PiYF0IzgV5bxxe/RkiEbRJ3NgedSOHVKn6FCdOK56NQpDtqACwe3kxTqfZiGJj+W by7w== X-Gm-Message-State: AC+VfDxKGXyNwq3zaNgTOalTHPseVS/srMpf3e4TdCrAyGMUkJHUOERG RG5QIAd/VKQEEOxAHaXLGT436TVMSRiDF9c7+Zl7yuYJ X-Received: by 2002:ac2:47f0:0:b0:4f4:dbcc:54da with SMTP id b16-20020ac247f0000000b004f4dbcc54damr376820lfp.27.1685041124236; Thu, 25 May 2023 11:58:44 -0700 (PDT) Received: from mail-lj1-f170.google.com (mail-lj1-f170.google.com. [209.85.208.170]) by smtp.gmail.com with ESMTPSA id v28-20020ac2593c000000b004f3946030fasm305060lfi.68.2023.05.25.11.58.43 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 25 May 2023 11:58:44 -0700 (PDT) Received: by mail-lj1-f170.google.com with SMTP id 38308e7fff4ca-2af20198f20so9808231fa.0 for ; Thu, 25 May 2023 11:58:43 -0700 (PDT) X-Received: by 2002:a17:907:6d9e:b0:96f:4ee4:10d4 with SMTP id sb30-20020a1709076d9e00b0096f4ee410d4mr2465428ejc.43.1685040638863; Thu, 25 May 2023 11:50:38 -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: Thu, 25 May 2023 11:50:21 -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: Linux FS Devel , hch@lst.de, brauner@kernel.org, david@redhat.com, tglx@linutronix.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: 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 Thu, May 25, 2023 at 11:08=E2=80=AFAM Luis Chamberlain wrote: > > Certainly on the track where I wish we could go. Now this goes tested. > On 255 cores: > > Before: > > vagrant@kmod ~ $ sudo systemd-analyze > Startup finished in 41.653s (kernel) + 44.305s (userspace) =3D 1min 25.95= 8s > graphical.target reached after 44.178s in userspace. > > root@kmod ~ # grep "Virtual mem wasted bytes" /sys/kernel/debug/modules/s= tats > Virtual mem wasted bytes 1949006968 > > > ; 1949006968/1024/1024/1024 > ~1.81515418738126754761 > > So ~1.8 GiB... of vmalloc space wasted during boot. > > After: > > systemd-analyze > Startup finished in 24.438s (kernel) + 41.278s (userspace) =3D 1min 5.717= s > graphical.target reached after 41.154s in userspace. > > root@kmod ~ # grep "Virtual mem wasted bytes" /sys/kernel/debug/modules/s= tats > Virtual mem wasted bytes 354413398 > > So still 337.99 MiB of vmalloc space wasted during boot due to > duplicates. Ok. I think this will count as 'good enough for mitigation purposes' > The reason is the exclusive_deny_write_access() must be > kept during the life of the module otherwise as soon as it is done > others can still race to load Yes. The exclusion only applies while the file is actively being read. > So with two other hunks added (2nd and 4th), this now matches parity with > my patch, not suggesting this is right, Yeah, we can't do that, because user space may quite validly want to write the file afterwards. Or, in fact, unload the module and re-load it. So the "exclusion" really needs to be purely temporary. That said, I considered moving the exclusion to module/main.c itself, rather than the reading part. That wouild get rid of the hacky "id =3D=3D READING_MODULE", and put the exclusion in the place that actually wants it. And that would allow us to at least extend that temporary exlusion a bit - we could keep it until the module has actually been loaded and inited. So it would probably improve on those numbers a bit more, but you'd still have the fundamental race where *serial* duplicates end up always wasting CPU effort and temporary vmalloc space. Linus