From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id ABCE82D5925 for ; Mon, 8 Jun 2026 21:03:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780952619; cv=none; b=lHgYN7LpVzJFYQOkTSp5Gq3V0YwZYWNYKw+c7FVjrE3Qw2mej6Xc3rA9jF07Mo2jpJiOzPD3Q9+7L3AtCMErgkO0iq9I8Kd3zvsqSqUvUc6qILVmD0XX5fqps/4wIMmiLQ+2EUnMHUO90fJEfmYICe69PKCziA9GjqFmqCAJpqY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780952619; c=relaxed/simple; bh=fL//XCAOIiyIn0ronmlF/wWx77EaGyvJmJxt2U5uk5c=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=qnttdU9Bxiz/66FPOYiIHZKsoaYAuuHnXOu8JeVZ5tsnrZ2NEYNwekbUnK8rr71SFvEWDirwfewDBqsho6ko+fp7cmO9JR42hC/8YqOA9lwGJFAwD6JtitvaROMXa3jDhc93ur898KcJICBaUbOpPWExdkTVVShfxnuRepDNn4U= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=JHgpq6OV; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=fQUO1Vhs; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="JHgpq6OV"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="fQUO1Vhs" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1780952617; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=yPKXt45eBuYwq4y81CcQcHJA9vR4mX15BetGx3tuktA=; b=JHgpq6OVBDOoGk4jSdzCiHG0PeyK7NrpN/aETRVpZ1eH9FL7R6A585urgzBJYXtyJDzAsa /esPrM6vlYYHvmqj6AyuVY1DhvgkPnbZLUFcJoB1fI0eKHiPRyxkvTbLsuhXJwPNKTRZH2 JOueb9utHNAxqYLZ3UYacqY3RdoNQNg= Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-297-VR3gFyXnNaC7oAGmSxIEXw-1; Mon, 08 Jun 2026 17:03:36 -0400 X-MC-Unique: VR3gFyXnNaC7oAGmSxIEXw-1 X-Mimecast-MFC-AGG-ID: VR3gFyXnNaC7oAGmSxIEXw_1780952615 Received: by mail-wr1-f72.google.com with SMTP id ffacd0b85a97d-45ef616db45so3821035f8f.2 for ; Mon, 08 Jun 2026 14:03:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1780952615; x=1781557415; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=yPKXt45eBuYwq4y81CcQcHJA9vR4mX15BetGx3tuktA=; b=fQUO1VhsECXqCJF6nsMRf5PODCkYlm64mUm68O/4bJiKCuoQsJYCfoN+dVL4Aethut OY7sfS6BHT6tW57reHeNzcDZHxiL6Mgq1nQ0OjWzOXkWxhcBDv050VauQkGS7Fmp3v70 QLb0kYv6Frmvm4qV0u1ckKVIrF8BppHWYgNYDBrSQPxD++EfI90Fbm3Hzzfbp6PlTwhB KevePIS0gyAcC+KotBLn6DWUoi4fcQ35ysBrHhomuOqve0rhG51OMCHlzXql7+Q5bhld +s0MJIc9TSpV4YlXOaFKV7iR8fqA/fGaiq+Foqa0ByMFNyIK09zBTJbTsfV0ubaSSirT joBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780952615; x=1781557415; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=yPKXt45eBuYwq4y81CcQcHJA9vR4mX15BetGx3tuktA=; b=ehzdKowKfRpZbG7anzOC0bGN1HcJ6A73jsRA9msv03CW2cDYtxtgKe8Qy/G2mMRg+c g6Fm+A8bKXcDCiVbwybc1me/oPvFCLvWDD27nyY8kwyeJzIZTFtUeO8Lo+/ThrRUB1p7 J9822W3hHDiMzxF6ndV+OAP7LJsDzAlZpAPWRuFXFMngvIwQ9ikwlB3e60of9jlN62WA Y8fwkfuozN+gfktoB3phnGe1iNHrO/mzpfvYKTTzsmFJyf5utHO/vaip7oeUpGNvKATp HAYfQlHYo/ad5g2DQW5RatqeeWZavQm5v+tfGe3jA+9LA7k4gepvKsuuooKmBLQmqxBa ZUJA== X-Forwarded-Encrypted: i=1; AFNElJ8ScbUq47HM3WAMWIuw7KjtF+zVYG6/9gSTWCwQS8CvjjiTWlnYYd5I6jl/Yo3qvmKViTzMZfulDuuVcmY=@vger.kernel.org X-Gm-Message-State: AOJu0YzH6lnPDZR8ZPoGZB1vcZwGlDkQMKmBB6F89spN/u9vwdyrqV3A yd7OeQMrWMdhCtQZeylaAXhC5RkO2uIYZwD7GNgq5yOY/yCH/ZXz1mWmX7tnf64Jn19tsWdIcs+ y57XvANZYu0Cx1W6e88eUw42Pffm68186yVa4ToUdckSo+Qi75XNeNX5ltFw7qaHCWQ== X-Gm-Gg: Acq92OG37kRQyaIxc7K6FhRejMyPRUJCpnkKVoH1qkIgNhWYmrZD+f0gqU08dpYkuyz sHjDI0LNapdA9ik9C5+6iwWtNrA/iV15kX+D/E3m/0ZodigDrwaNALrNtMJ/6Zk+g+LL36Vc+cp gmszdLtz5T3O+xO9mO0zOXfzuHbj3VdVPXHHLqJCuRo+/31+Mft9v76hmP9qFm2oiT+aHXhXo2m JO34g4DeDQW7PVPKrZEZRFsxtDGexFw6lckFWBRNnAiTH4dsE9PyyAFzP1jf4obP3o+FAwudGnj ikoKmvcVKOs8GKK4wHD9ECPMzgZV547J4sbU6E87owxAHjhD98mQCK5MHPWp88wGc62qHlx2+58 KEvqGqiZangwuwCvDMArODc/+d7NZeVcSsJWZRPIRSB4hCh7hS5+y+w== X-Received: by 2002:a5d:5e08:0:b0:43d:77a8:3baf with SMTP id ffacd0b85a97d-4603062bc2amr28471182f8f.32.1780952615124; Mon, 08 Jun 2026 14:03:35 -0700 (PDT) X-Received: by 2002:a5d:5e08:0:b0:43d:77a8:3baf with SMTP id ffacd0b85a97d-4603062bc2amr28471102f8f.32.1780952614599; Mon, 08 Jun 2026 14:03:34 -0700 (PDT) Received: from redhat.com (IGLD-80-230-85-71.inter.net.il. [80.230.85.71]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4601f2dcae2sm58735162f8f.6.2026.06.08.14.03.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Jun 2026 14:03:33 -0700 (PDT) Date: Mon, 8 Jun 2026 17:03:28 -0400 From: "Michael S. Tsirkin" To: Zi Yan Cc: Gregory Price , "David Hildenbrand (Arm)" , Lorenzo Stoakes , linux-kernel@vger.kernel.org, Jason Wang , Xuan Zhuo , Eugenio =?iso-8859-1?Q?P=E9rez?= , Muchun Song , Oscar Salvador , Andrew Morton , "Liam R. Howlett" , Vlastimil Babka , Mike Rapoport , Suren Baghdasaryan , Michal Hocko , Brendan Jackman , Johannes Weiner , Baolin Wang , Nico Pache , Ryan Roberts , Dev Jain , Barry Song , Lance Yang , Hugh Dickins , Matthew Brost , Joshua Hahn , Rakie Kim , Byungchul Park , Ying Huang , Alistair Popple , Christoph Lameter , David Rientjes , Roman Gushchin , Harry Yoo , Axel Rasmussen , Yuanchu Xie , Wei Xu , Chris Li , Kairui Song , Kemeng Shi , Nhat Pham , Baoquan He , virtualization@lists.linux.dev, linux-mm@kvack.org, Andrea Arcangeli Subject: Re: [PATCH v10 07/37] mm: thread user_addr through page allocator for cache-friendly zeroing Message-ID: <20260608165819-mutt-send-email-mst@kernel.org> References: <50d410b47fe3f45327783e05bd306d5eaab75e65.1780906288.git.mst@redhat.com> <64f2e580-aa82-4849-9236-b8ec4208ca24@kernel.org> <2475e4c4-9ba3-4091-9bfd-1c1c15163da7@kernel.org> <8BB8D6E5-8644-4CBC-BAF1-0AA19702E042@nvidia.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: On Mon, Jun 08, 2026 at 04:37:59PM -0400, Zi Yan wrote: > On 8 Jun 2026, at 16:25, Gregory Price wrote: > > > On Mon, Jun 08, 2026 at 03:52:20PM -0400, Zi Yan wrote: > >> On 8 Jun 2026, at 15:43, Gregory Price wrote: > >> > >>> On Mon, Jun 08, 2026 at 08:39:10PM +0200, David Hildenbrand (Arm) wrote: > >>>> On 6/8/26 17:27, Zi Yan wrote: > >>>>> On 8 Jun 2026, at 7:08, David Hildenbrand (Arm) wrote: > >>>>> > >>>>> Or should we defer zeroing after a page is returned from allocator? So that > >>>>> user_addr does not need to be passed through irrelevant allocation APIs. > >>>>> Something like: > >>>>> > >>>>> alloc_page_wrapper(gfp, order, user_addr) > >>>>> { > >>>>> page = alloc_pages(); > >>>>> if (gfp & __GFP_ZERO) > >>>>> clear_page(page); > >>>>> } > >>>>> > >>>> > >>>> Not really sure what's best here. I think we'd want to limit the lifting to some > >>>> internal API, so it cannot easily be messed up by random kernel code calling > >>>> into the wrong API and not getting pages cleared. > >>>> > >>> > >>> We're a bit in circles on this. We discussed explicit interfaces a few > >>> months back and the trade off was: > >>> > >>> a) add user_addr to the existing API and cause churn > >>> > >>> or > >>> > >>> b) add special interface like above > >>> increase the buddy surface > >>> leaves open the ability for users to get it wrong easily > >>> > >>> If we forget VMs for a moment and break this step out separately, the > >>> core question is whether page_alloc.c is the right place to be calling > >>> the folio_user_zero() or whatever it is. > >> > >> page_alloc.c calling folio_user_zero() is fine, but my question is > >> whether we should do the zeroing inside post_alloc_hook(), part of > >> allocation. > >> > >> What I propose is to lift __GFP_ZERO up as much as possible, > >> so that most of allocation code does not need to care about it. > >> We do the zeroing right before the page is returned to callers. > >> > > > > essentially we end up with something like > > > > alloc_frozen_...(..., gfp) > > { > > folio = whatever(..., gfp); > > if (gfp & __GFP_ZERO) > > folio_zero(folio, -1); /* don't do cache flush part */ > > } > > > > alloc_frozen_user_...(..., gfp, user_addr) > > { > > folio = whatever(..., gfp); > > if (gfp & __GFP_ZERO) > > folio_zero(folio, user_addr); /* do cache flush part */ > > } > > > > The downside of this is obvious: it's easy for developers to get this > > wrong and call the non-user interface for user-bound allocations and > > miss the cache flush (that is only needed on some archs). > > > > Not saying that's a deal breaker, but it's something to chew on. > > I agree that misuse can cause trouble. But if we do the churn approach, > what prevents developer from doing alloc_frozen(..., user_addr = -1) > and using the returned page for userspace? It is possible the allocated > page can be exported to userspace later. > > BTW, that cache flush thing is fragile even today, Probably arch dependent. On arm32, I think if you miss the flush, then PG_dcache_clean will be clear and then you get a perf hit but it's still correct. Didn't check others. > you probably can > do alloc_page() + vm_insert() to get a page without doing proper flush > and export it to userspace. There seems to be no mechanism to > prevent that. > > Best Regards, > Yan, Zi Because maybe you want to expose data to userspace? -- MST