From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 71679E77171 for ; Thu, 5 Dec 2024 08:15:51 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D42A96B0083; Thu, 5 Dec 2024 03:15:50 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id CF2426B0085; Thu, 5 Dec 2024 03:15:50 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BE0B56B0088; Thu, 5 Dec 2024 03:15:50 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 97C786B0083 for ; Thu, 5 Dec 2024 03:15:50 -0500 (EST) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id F3967AF1F2 for ; Thu, 5 Dec 2024 08:15:49 +0000 (UTC) X-FDA: 82860196650.28.B4F499F Received: from mail-ua1-f41.google.com (mail-ua1-f41.google.com [209.85.222.41]) by imf13.hostedemail.com (Postfix) with ESMTP id 8277820028 for ; Thu, 5 Dec 2024 08:15:31 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=none; spf=pass (imf13.hostedemail.com: domain of geert.uytterhoeven@gmail.com designates 209.85.222.41 as permitted sender) smtp.mailfrom=geert.uytterhoeven@gmail.com; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1733386531; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=TxwEuUP0RFmoaIeR9CtOUPb98unFbw4v06g3fCFWPf4=; b=qYHZRP2xoCVoxNZj0WZ2ljHAUil/GXqlwHxT/Gq08i82nIHxaiTeS/b4sHn6rpoguvsPDZ OW5r2iUaR69olHOBmlYHBk1pit5jLF5Ka2zKv1FZ+BfjnnWCArRY+q8dqjwIxrKvfoCUi6 cpwgJKvSNVSmiokqhDAJ6FUktbz7ZzE= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=none; spf=pass (imf13.hostedemail.com: domain of geert.uytterhoeven@gmail.com designates 209.85.222.41 as permitted sender) smtp.mailfrom=geert.uytterhoeven@gmail.com; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1733386531; a=rsa-sha256; cv=none; b=4RFhYEmZ8bHWLy9PPiqEUB2thGwawMwGZ/TP/4EiRGkxswML9rWWYXkwyTSByjczaavtG7 Oy0e5emWt14vo8lgGEOiyVhr51xGGjxz/ddYGN+bEJciaHGJRPT/EkCwi86nZyJQSfeDRI +jN/H+6krbUOj650rR3K/S00dgZVTTY= Received: by mail-ua1-f41.google.com with SMTP id a1e0cc1a2514c-85bad7be09dso207704241.0 for ; Thu, 05 Dec 2024 00:15:47 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733386545; x=1733991345; 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=TxwEuUP0RFmoaIeR9CtOUPb98unFbw4v06g3fCFWPf4=; b=drq7XqO9yxF2AOKWNuoo/ETLzineDNPmCUg4S+1LEj4ke4YIiosTO3mWRq1+pg1hHH e4lKkDKbFpyuy3809JcpURmtNYHSVn6laOuBaDDN3T4qSbZZoZnYYHdELBTrX1+7m914 LrfpUIw3D6D/dVQQdbd/cCghYHH/yHxZihI+GWMrWRFYLvybUO8tV/70AUKaXIayy80h 38pMMSCutxFTiz22zsdlAUz4gjt5lpgBbCgAi/8UtTsE89+ZVQqDsNWB/zD1x7UsdK4e MpsQ6+6ecErWJ+bf/V6hL4h4mOb3SKyCtJ0iwcv2DUcB+TSWsSZXTOQ7dgLPYO42syUE XdSg== X-Gm-Message-State: AOJu0Yxh53JHdFVAwtVzd2u/9jhjpeq3C9f1Y6xzdhzqnxhrDcvxT4+Y q4SKFk1TZ2GQMpSt518B7rFEe2IqGwy3d6KvYqG8aVU6GLnhee3Q1wHUOW02 X-Gm-Gg: ASbGnctIYTExllWpuIP0oXEjqyRQAZ0hG+cs2YfeF3ZuKI70RNabF4xGDw15N6mUPr4 u3UMHWW3+SkHlEOTUOhL7rubRRUdzzNqRuLCXzCbkmeUHNkbNEX1pOZFf6vNRBdAxZNXI/VLIgD KhGC2lYbZsOM0hQTcBFE4KTWXlYs319HaXT3UmHfW2fGODJOglOWmnNCEE49sU/7Okck84cT6RX ZiOUpkCgLjUqB7HPXPyZ0h+lUcBEpoVXhtshkJkw+QVgKmzE2pfSAFVOJX8d70D8pD27MMIlmz1 fradXFL9yRbr X-Google-Smtp-Source: AGHT+IGJMpywHZknGPTkZG1sVyBpv02nrGzmPFpA8VnBDdR9nCP0yxOZ9jNrkMwtZSRHOKOeCMNu0Q== X-Received: by 2002:a05:6102:38cd:b0:4af:4cb0:a310 with SMTP id ada2fe7eead31-4af9719d74fmr11924120137.11.1733386545364; Thu, 05 Dec 2024 00:15:45 -0800 (PST) Received: from mail-vs1-f50.google.com (mail-vs1-f50.google.com. [209.85.217.50]) by smtp.gmail.com with ESMTPSA id a1e0cc1a2514c-85c2ba7dca5sm108174241.17.2024.12.05.00.15.44 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 05 Dec 2024 00:15:44 -0800 (PST) Received: by mail-vs1-f50.google.com with SMTP id ada2fe7eead31-4afbbb9fc1dso180385137.1 for ; Thu, 05 Dec 2024 00:15:44 -0800 (PST) X-Received: by 2002:a05:6102:3753:b0:4af:469b:d3ae with SMTP id ada2fe7eead31-4af9729081cmr12311913137.27.1733386544384; Thu, 05 Dec 2024 00:15:44 -0800 (PST) MIME-Version: 1.0 References: <20241011150304.709590-1-ziy@nvidia.com> In-Reply-To: From: Geert Uytterhoeven Date: Thu, 5 Dec 2024 09:15:32 +0100 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH] mm: avoid zeroing user movable page twice with init_on_alloc=1 To: Zi Yan Cc: linux-mm@kvack.org, Andrew Morton , David Hildenbrand , "Matthew Wilcox (Oracle)" , Miaohe Lin , Kefeng Wang , John Hubbard , "Huang, Ying" , Ryan Roberts , Alexander Potapenko , Kees Cook , linux-kernel@vger.kernel.org, linux-mips@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 8277820028 X-Rspam-User: X-Stat-Signature: zgp8o6h4z6sfr1m9okot796wx6jwqh8j X-HE-Tag: 1733386531-600220 X-HE-Meta: U2FsdGVkX18NiM3Kz1giKHm/LZGHs5/hQOL3jN9n2LQeYDIoaUIR0EtSye0Pfc+Gm+czcsDKLoGHePCesPJSpxJD1fztybn1aYYMZZMvAYzFBjjGr5FQ/zxjKcjDgC6MX7QE0yJXeTQd1qzvjfdvANMcah7QKCkuJfCV0EIQbzTG/exsNOK+tB4cgm9ZCYCCR4/tYJLG0MQFlcAy0UZQyxLCSIepNl1DdgnazX4vaI9KHZ/tWPmdgRsySgyNye155OAtB+NsMaYpetRodLZnIrg5n1D+q7RIRhwmNYPO9kvLPbuEcjLyLEidVXPCqgo+qDZs2AlHnH+JR4z2D4297fQFt4CD1H+lPFTx5ZmEsXk2HFlWafX3J9plSpyylVq+5o4QXNKgxSeQEQ8ALGuJGcxkbcjFJ65Z4L0aPUEaYibM0R1UiESGbrvt4oNy9VCMC5y+OXf90+Kkekpbpk5nx3XAZBCXEiBal6SPPGyDFuSEzgMSG5gP9qmZ9/6KTd+85QvV55h0/yGvHX/rZcvGRjERY67INobBkrUY4EffSgU47xdxwRv/9L3YUTL7G0vlXRi/B4fVi/A50Whkhr8D826ZkXL63N7KOOElQiaT4pXHhzxl+lYrcEgBC2C5LzXsrBjYrsx+MUTjS7Ie+ktnfOm52KiU4j864L2GcjFn01j2rqKDoqyhky5fQFhf2Sues/1Cslvnm4qS7rpFFHiDmGjn8IDMnIGSMdK5g1WXzcFg+jV5O5gu+PWCGIbdohGOMNJhzUG34TAKId/LA5l12X9rV54U+P3/yTCOydhvVG/ayCiA6OKBavP4+z2EgHp0H1s/CZC0sBExBUMi/FGO+MzT9N+D0zfcgkh5uuaD2E9I1FW8x+4DwKPc6gS5HZYI9h1BtdACjKCWWStiRmhz1hnqqixmgQFGiS5cmwr9jQm3SVl7+tTZ95M2vMRA5VkpkYIbuLFiSc0e+pFAYFY UOqlAkk1 cKB/ab1U8zub9iN9lgfVQPWKegSMX434duFiRV+HMClmSn2+zmAHkyHxaXGFcq7cRlUwMA6cNQVxZfIIxL14fl6yLZmNJaANNsfZUCw+bwaPqRv77L0G7Ee24rLFKJU/hZy/PRmcTuk8CwuYoAmO5FgPiUDzVR7UAt2dTYAR0B9VrAvb/o+7/F3TjVsnRHEPcscDW5fXn60anwlXwW/R6FlP86+8FUgRgt5Eg2XV0C9NjKrGKl8ocQlYtLmMzCDKJu7dZr5PQIVanXBzQYxySgdOoy9LR7emCORTeiZeCKnacIrLeBqMjXZ/wLI5GWe8aL5cudx/AUqMNG8StP0sQ4xKOqRa4C0t1tLHKWlCFiexHfV/U89WiFilFLfS5/6JY0pfNNb9PIISXqEiXCjJcDbW4Bj4eJO+k3bfVAEeE4jgE6QdmEUfbfitirq0LED/rc23vi76fmW9pZXaretDBxe0qFt+clKJkprrh X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Hi Zi, On Wed, Dec 4, 2024 at 4:24=E2=80=AFPM Zi Yan wrote: > On 4 Dec 2024, at 5:41, Geert Uytterhoeven wrote: > > On Fri, Oct 11, 2024 at 5:13=E2=80=AFPM Zi Yan wrote: > >> Commit 6471384af2a6 ("mm: security: introduce init_on_alloc=3D1 and > >> init_on_free=3D1 boot options") forces allocated page to be zeroed in > >> post_alloc_hook() when init_on_alloc=3D1. > >> > >> For order-0 folios, if arch does not define > >> vma_alloc_zeroed_movable_folio(), the default implementation again zer= os > >> the page return from the buddy allocator. So the page is zeroed twice. > >> Fix it by passing __GFP_ZERO instead to avoid double page zeroing. > >> At the moment, s390,arm64,x86,alpha,m68k are not impacted since they > >> define their own vma_alloc_zeroed_movable_folio(). > >> > >> For >0 order folios (mTHP and PMD THP), folio_zero_user() is called to > >> zero the folio again. Fix it by calling folio_zero_user() only if > >> init_on_alloc is set. All arch are impacted. > >> > >> Added alloc_zeroed() helper to encapsulate the init_on_alloc check. > >> > >> Signed-off-by: Zi Yan > > > > Thanks for your patch, which is now commit 5708d96da20b99b4 ("mm: > > avoid zeroing user movable page twice with init_on_alloc=3D1") > > in v6.13-rc1. > > > > This causing a panic when starting userspace on MIPS64 RBTX4927: > > > > Run /sbin/init as init process > > process '/lib/systemd/systemd' started with executable stack > > Kernel panic - not syncing: Attempted to kill init! exitcode=3D0x00= 00000b > > ---[ end Kernel panic - not syncing: Attempted to kill init! > > exitcode=3D0x0000000b ]--- > > > > or > > > > Run /sbin/init as init process > > process '/lib/systemd/systemd' started with executable stack > > do_page_fault(): sending SIGSEGV to init for invalid read access > > from 00000000583399f8 > > epc =3D 0000000077e2b094 in ld-2.19.so[3094,77e28000+22000] > > ra =3D 0000000077e2afcc in ld-2.19.so[2fcc,77e28000+22000] > > Kernel panic - not syncing: Attempted to kill init! exitcode=3D0x00= 00000b > > ---[ end Kernel panic - not syncing: Attempted to kill init! > > exitcode=3D0x0000000b ]--- > > > > or > > > > Run /sbin/init as init process > > process '/lib/systemd/systemd' started with executable stack > > /sbin/inKernel panic - not syncing: Attempted to kill init! > > exitcode=3D0x00007f00 > > ---[ end Kernel panic - not syncing: Attempted to kill init! > > exitcode=3D0x00007f00 ]--- > > it: error while loading shared libraries: libpthread.so.0: object > > file has no dynamic section > > > > Reverting the commit (and fixing the trivial conflict) fixes the issue. > The provided config does not have THP on, so the changes to mm/huge_memor= y.c > and mm/memory.c do not apply. > > Can you try the patch below and see if the machine boots? Thanks. > diff --git a/include/linux/highmem.h b/include/linux/highmem.h > index 6e452bd8e7e3..bec9bd715acf 100644 > --- a/include/linux/highmem.h > +++ b/include/linux/highmem.h > @@ -224,7 +224,13 @@ static inline > struct folio *vma_alloc_zeroed_movable_folio(struct vm_area_struct *vma, > unsigned long vaddr) > { > - return vma_alloc_folio(GFP_HIGHUSER_MOVABLE | __GFP_ZERO, 0, vma,= vaddr); > + struct folio *folio; > + > + folio =3D vma_alloc_folio(GFP_HIGHUSER_MOVABLE, 0, vma, vaddr); > + if (folio) > + clear_user_highpage(&folio->page, vaddr); > + > + return folio; > } > #endif Thanks, that works! Tested-by: Geert Uytterhoeven Gr{oetje,eeting}s, Geert --=20 Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k= .org In personal conversations with technical people, I call myself a hacker. Bu= t when I'm talking to journalists I just say "programmer" or something like t= hat. -- Linus Torvalds