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 9C9FAE7716C for ; Thu, 5 Dec 2024 08:05:15 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 150C56B007B; Thu, 5 Dec 2024 03:05:15 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 0DA506B0082; Thu, 5 Dec 2024 03:05:15 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E95BB6B0083; Thu, 5 Dec 2024 03:05:14 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id CB4396B007B for ; Thu, 5 Dec 2024 03:05:14 -0500 (EST) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 46BBD1C8507 for ; Thu, 5 Dec 2024 08:05:14 +0000 (UTC) X-FDA: 82860169854.16.59AA3CD Received: from mail-vs1-f48.google.com (mail-vs1-f48.google.com [209.85.217.48]) by imf10.hostedemail.com (Postfix) with ESMTP id 658F1C0004 for ; Thu, 5 Dec 2024 08:05:05 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf10.hostedemail.com: domain of geert.uytterhoeven@gmail.com designates 209.85.217.48 as permitted sender) smtp.mailfrom=geert.uytterhoeven@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1733385897; a=rsa-sha256; cv=none; b=m3mlzF47P9+oFY+fN+P97YJToOmcHBqh+SJKdHaQe0TPVY68Uc69SwgpkfGKqiRHdnXNR5 PwzPCRkTHie5DgAMiiwZ/FoNUjUZnFbTijsiP0qtMEurgK7S6UvZmnCBBBY4dj3rpjhoQJ xE1GZOylPB9QQB6KAthRO6QTinLk/IY= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf10.hostedemail.com: domain of geert.uytterhoeven@gmail.com designates 209.85.217.48 as permitted sender) smtp.mailfrom=geert.uytterhoeven@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1733385897; 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=AlP4q3uC5bDLtilUpgKfXFCPT7CpFieLIRjR7udPpU4=; b=fL3ZBnsKqrRkWBDebEcGTbemweILvk+efYxA6YSvnR+ZaHnR920WAXnPaqRvBnyc6vUedX mFlTaNrSoKY19kpF4C3DykxVcQjBBicd9HkZQ6eIudiAJI2fK4RP4+gXGfM8rh13ct9FI+ m75ZHOwaSnK5JraYVQjlRxUc83MbZtA= Received: by mail-vs1-f48.google.com with SMTP id ada2fe7eead31-4afbbb9fc1dso177230137.1 for ; Thu, 05 Dec 2024 00:05:11 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733385910; x=1733990710; 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=AlP4q3uC5bDLtilUpgKfXFCPT7CpFieLIRjR7udPpU4=; b=R4DEYYYDG9JwNBRjB2shhCM9U9kMPy1asGCE2R9iUWYgdb3iZeZdmZIKM4RPt+UJ+5 yB2ts40CKWp/GtZBJpyqGYjE8lkCiZyv5oKksyhAd2pysOqxMrqTmxcTEAaZYlT/lEBd cnVI9lLY3K07Z3Ug5zlFpoY5uyKs1FfRSU9onwEBhBwN/P7r09j7scR46Rm+klRmcAQy O7srA+WPCsNAOVEXOZIsxYqeXhly4Y89mBxawZYIBWC8+OHTGa4i0GwtOs6DOFtH8PQL QgJcDuoJ3/PgbT0lAoOsYmTftIvGkoQliPtRbMjvR0WIurjlXM1wsahZAFfb8YligaIA p+xQ== X-Forwarded-Encrypted: i=1; AJvYcCWzy+zo1d82vPPd4/9vJvTs1NU7nmL+W83rL43LApC6jzgYVIxjUnHrs7340OWZufaT3OIIgBvxHg==@kvack.org X-Gm-Message-State: AOJu0Yx5KIfeUj7/KKh0pqSf25wOja25qzpUcIzwQQWRdqEGTJBMJ/XO XWFfsOo1EXrwH5r1CyKTpzcriITe2C1X2PfIBuz+fp5ts4DY+h+UTjKrjtD3 X-Gm-Gg: ASbGncuo9lEcumL0Q7IUGOCiunazU3kpmHlML2rQju1AQw0wRw+4kPT10CPnTlxfVa6 m4puRofc46HQuLFlpFYr/PjGaMoFVYgEz1hP/S+E2ucQyasdFdkQUDSWAkaisHZbj524hSO/kSE G4OAdTf+YbEWUhEvyDRHve7A3QhmV2OSFz5BZo9MuTBfTXXxZENkJJv+28fXds4hPI18Po/hkR5 MTILktlg5HQDizfvxuS8Gvq7lNKCHQOudMWiGcfXQAX5oI3neTX05ylqdJG8whf84RwGmbBonlD svKoIQcTgnCp X-Google-Smtp-Source: AGHT+IE0gMl92LysANdKDjTv0ChlCKYaHehzjWuW5oz41DcppRzEzZLnPDjBilbqhmsgxNkBIt3DzQ== X-Received: by 2002:a05:6102:304c:b0:4af:c297:f494 with SMTP id ada2fe7eead31-4afc297f533mr525266137.1.1733385909878; Thu, 05 Dec 2024 00:05:09 -0800 (PST) Received: from mail-ua1-f42.google.com (mail-ua1-f42.google.com. [209.85.222.42]) by smtp.gmail.com with ESMTPSA id a1e0cc1a2514c-85c2ba8b29bsm115909241.20.2024.12.05.00.05.08 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 05 Dec 2024 00:05:08 -0800 (PST) Received: by mail-ua1-f42.google.com with SMTP id a1e0cc1a2514c-85ba92b3acfso143621241.1 for ; Thu, 05 Dec 2024 00:05:08 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCUJ6kWQxfdGY0QUxivhcQ7P8Cypytr4Z6T8LBgvaOQD6mSVfc84cB9Z53nQQEaV8+OvTSncQGIYvg==@kvack.org X-Received: by 2002:a05:6102:26d1:b0:4af:c1b6:c4fd with SMTP id ada2fe7eead31-4afc1b6c9d1mr500382137.22.1733385908547; Thu, 05 Dec 2024 00:05:08 -0800 (PST) MIME-Version: 1.0 References: <20241011150304.709590-1-ziy@nvidia.com> <9942C08D-C188-461C-B731-F08DE294CD2B@nvidia.com> <09B2AB6A-B122-4287-B97E-F800E511097E@nvidia.com> <995E365D-5B83-41B3-A46C-6493D203A761@nvidia.com> In-Reply-To: <995E365D-5B83-41B3-A46C-6493D203A761@nvidia.com> From: Geert Uytterhoeven Date: Thu, 5 Dec 2024 09:04:56 +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: Matthew Wilcox , Vlastimil Babka , linux-mm@kvack.org, Andrew Morton , David Hildenbrand , 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-Stat-Signature: qwmsgtkm88jd86su8wtm7tejgujn1mdp X-Rspam-User: X-Rspamd-Queue-Id: 658F1C0004 X-Rspamd-Server: rspam08 X-HE-Tag: 1733385905-476639 X-HE-Meta: U2FsdGVkX1+BczdlOo0hBR/e8j3qleMLUJkuaYgPVZB35M16ePfpI5QtBD90IJztXDnUvt95UAExYGQnLlbYJVIzsfv2FiS3eFpj8Dglzo0eCM1cFbORe09sbUAGopTZS0ZR+HjA1QAG6/r9ysAKWsw1+8tMrDIjOsPBbqvGDOe8Eph4cDSk91NzUfKF2bn/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b2nz3w7JS5yFAO8HyfJ6IkRVDsZfMqTbGfGhP/3fIvNJOG8f8McSlqe5Ne+U6vH9SU3KJte+ftI193lNaolG8m2+iGk+aZgtTwNDkV2jH1p77+IBRSje3s7Vb9QDalqJid7vGYA/F71PQ/cO10N7PzbJ07+45iIVdzXqW/Z82jUxie86/Ra3nVoj0EyfYYbyqkVQNeXidABqc 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 7:30=E2=80=AFPM Zi Yan wrote: > On 4 Dec 2024, at 12:33, Zi Yan wrote: > > On 4 Dec 2024, at 11:29, Matthew Wilcox wrote: > >> On Wed, Dec 04, 2024 at 11:16:51AM -0500, Zi Yan wrote: > >>>> So maybe the clearing done as part of page allocator isn't enough he= re. > >>>> > >>> Basically, mips needs to flush data cache if kmap address is aliased = to > >> > >> People use "aliased" in contronym ways. Do you mean "has a > >> non-congruent alias" or "has a congruent alias"? > >> > >>> userspace address. This means when mips has THP on, the patch below > >>> is not enough to fix the issue. > >>> > >>> In post_alloc_hook(), it does not make sense to pass userspace addres= s > >>> in to determine whether to flush dcache or not. > >>> > >>> One way to fix it is to add something like arch_userpage_post_alloc() > >>> to flush dcache if kmap address is aliased to userspace address. > >>> But my questions are that > >>> 1) if kmap address will always be the same for two separate kmap_loca= l() calls, > >> > >> No. It just takes the next address in the stack. > > > > Hmm, if kmap_local() gives different addresses, wouldn=E2=80=99t init_o= n_alloc be > > causing issues before my patch? In the page allocator, the page is zero= ed > > from one kmap address without flush, then clear_user_highpage() clears > > it again with another kmap address with flush. After returning to users= pace, > > the user application works on the page but when the cache line used by > > init_on_alloc is written back (with 0s) at eviction, user data is corru= pted. > > Am I missing anything? Or all arch with cache aliasing never enables > > init_on_alloc? > > Hi Geert, > > Regarding the above concern, have you ever had CONFIG_INIT_ON_ALLOC_DEFAU= LT_ON > for your MIPS machine and encountered any issue? Or let me know if my rea= soning > above is flawed. > > To test it, I wonder if you can 1) revert my patch and 2) turn on > CONFIG_INIT_ON_ALLOC_DEFAULT_ON for your MIPS machine and run some applic= ations > to see if any error happens. That seems to work fine... Kernel log confirms it's enabled: -mem auto-init: stack:off, heap alloc:off, heap free:off +mem auto-init: stack:off, heap alloc:on, heap free:off 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