From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-qk1-f178.google.com (mail-qk1-f178.google.com [209.85.222.178]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D4A4C239E79 for ; Mon, 12 Jan 2026 23:31:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.178 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768260719; cv=none; b=YWIJf6dXCpsl4ZJmwOQAYNLnBnKhvxO0gwGtGWmZ719foUURhol9gxVSAXPaO4hVaJxdJzoLV8uEUSiX9Vyh1n+4RqXBz3x+S11HKIekIPPF7ZzLGjlbqfdP8NCIUoxF+VwMjxhhLDFT9fknjBY/ui8mJ0rzHSnBuh1FayXyLZY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768260719; c=relaxed/simple; bh=L++MAkaQvqNItCkQiT64oQtoza/heC4MjDaHxXJXLzk=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=cPpqz5l6K0M/tYZgZkGTEeCn1uPEfZ0OF0GcdKp2VWgF8JHBkY11lGtL1u0ziilMUa8wrjIH6MomfFI+WVfm3YGEtaPcv2T6EnUZ3Nyf0T0bHpUnCT94hOswBXJ0bS0t2oN+2Mr1YU6hOiKjjGj/piWmD9GUYGNAOPrIqBisUOs= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ziepe.ca; spf=pass smtp.mailfrom=ziepe.ca; dkim=pass (2048-bit key) header.d=ziepe.ca header.i=@ziepe.ca header.b=NesXOhhM; arc=none smtp.client-ip=209.85.222.178 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ziepe.ca Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ziepe.ca Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ziepe.ca header.i=@ziepe.ca header.b="NesXOhhM" Received: by mail-qk1-f178.google.com with SMTP id af79cd13be357-8b2d56eaaceso794826285a.0 for ; Mon, 12 Jan 2026 15:31:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ziepe.ca; s=google; t=1768260717; x=1768865517; darn=vger.kernel.org; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:from:to :cc:subject:date:message-id:reply-to; bh=pIO8dQifpp5qZTd7WcwNdFqrDRKIKFleYoHUkXQdAb0=; b=NesXOhhM3RHd1sfBQMYZi8oTKdiUBU7ArfmPPZ2ookjGX9GilzxcZy7ZsMITZEfhmT atK3pcoNDQ7fXeUBnXlOaQhs7TkHhQLxymDBxRraId3xgBHRxQ0CvEjaT0ZQY898mLW1 OgAoPGH9FODHRUMXjttUrb78JkzswM2lxC9mke2j4mfZ+SnwZh37jbs0OJOj9sTRf9Y+ /lNvgSkJpPprccWu1SeFpxsP2wVrF/izp9QUHXT7a1ltzRvuEkMOuAt/M/LNrjxi/anX qpAxHku+U0VUggJ1zyl7vH5eInqY383srH2IJEov+I9bn/94GeaIHXIuyns9L4xF1Sul 4ZKw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1768260717; x=1768865517; h=in-reply-to:content-transfer-encoding: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=pIO8dQifpp5qZTd7WcwNdFqrDRKIKFleYoHUkXQdAb0=; b=lzCy9tuf1HSCNbCBwsLREqxTGLJieHpwdZfRM8ky98kS4aIFvbQmo9ke/3qU7A7Fjk TFcG8rUys+c0XZCAYdlU9dIp12ojG6y15IQTYzNfY74bRpKeB2kL5BTLPBDiqTXEByLV pnghHtxpCEQz8+ZRSVuY4CmozYdxR++Q2DLFHmbnTGvmJ6EBXblGmNEfVtkbrPBV73RW INmhEKPP0bnr8fTO9BfIdY1x8OFqLXWH7gXwMOVutNRHM566QonPnsvb9he0zTaixSwN LbBZ1njSt1BxIR20ByUKRpXrnmt33I6VEXGUGS/3H5U3/4hgVjmm6/Lk6fTGhmqUHx5s 101Q== X-Forwarded-Encrypted: i=1; AJvYcCU4+WqG/7B63A09rWUm9OrHrXcFvhpYUUimFTWIWTP1ELDFmmNHeQr5GFacplNQc8fGagDk5FmnQYEH0JE=@vger.kernel.org X-Gm-Message-State: AOJu0Yz7cCyo0Cam6lrJK6BbDHtT+9qa/A5lM8+AcT49IJKDpjlEVlkJ zV8helYDHWLNPLJQUNaC4veu3iXE/trX3qpEJNgZg/oWFYfme77bAoy2fwA872aMl20= X-Gm-Gg: AY/fxX7NC6GZBioLzUF6KbFgSOA0bF8DznN1b++V/9Njjiyq6g0tj6E0Is1IZg1gP92 efMTf6gE+DgeOqcCT4K8VoB6pzBnlHXu9wbGdnDUkixetLuBptJvp38/1C9MoLgEjJ3z/9e9i4s LIFn9CBzkAJJTVz36ysH60aS4CcFkYldEICpgMBIM517E7q/LrGv6MbFk5oZBDseiqxjz22i+vW b0RiziAl38QHehtZNwPtckzjdUZ7PjiMf21Hcro4bYptJrmFhb2bYIZJrasunao+Yeicqe+tsnw zwwg/jBu0Vw1B/IJvFhwgRrAA8c8R3tPqgqYOpIkJ0NpqM9L7KaWLDyY5j83S801w1B6S5BndCX ET1HV+vEpFLVrcmZ9W0pz1t9Y9eRh1SLM3Xg9tR3KnArVmvuSLGob6A9cAYDKeUKYauGaAg2ldN r+cfYldmo3GzfDwl2LOcM2PEo3brghKbRtaAzO8T95hPLQIYL9qIVTSQOaSDZXyqvFcRY= X-Google-Smtp-Source: AGHT+IHEv3oyWJcb06Rw4VjhDeFEk4R9SXi3D7aPoLG3khcVAljGyaq9fJ2LebD88CvTcTHK3Zmx+A== X-Received: by 2002:a05:620a:3952:b0:89e:99b3:2eaa with SMTP id af79cd13be357-8c389375870mr2741069685a.8.1768260716611; Mon, 12 Jan 2026 15:31:56 -0800 (PST) Received: from ziepe.ca (hlfxns017vw-142-162-112-119.dhcp-dynamic.fibreop.ns.bellaliant.net. [142.162.112.119]) by smtp.gmail.com with ESMTPSA id af79cd13be357-8c37f51bf8csm1591462585a.28.2026.01.12.15.31.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Jan 2026 15:31:55 -0800 (PST) Received: from jgg by wakko with local (Exim 4.97) (envelope-from ) id 1vfRO6-00000003evB-2tne; Mon, 12 Jan 2026 19:31:54 -0400 Date: Mon, 12 Jan 2026 19:31:54 -0400 From: Jason Gunthorpe To: Zi Yan Cc: Matthew Brost , Matthew Wilcox , Balbir Singh , Francois Dugast , intel-xe@lists.freedesktop.org, dri-devel@lists.freedesktop.org, Madhavan Srinivasan , Nicholas Piggin , Michael Ellerman , "Christophe Leroy (CS GROUP)" , Felix Kuehling , Alex Deucher , Christian =?utf-8?B?S8O2bmln?= , David Airlie , Simona Vetter , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , Lyude Paul , Danilo Krummrich , Bjorn Helgaas , Logan Gunthorpe , David Hildenbrand , Oscar Salvador , Andrew Morton , Leon Romanovsky , Lorenzo Stoakes , "Liam R . Howlett" , Vlastimil Babka , Mike Rapoport , Suren Baghdasaryan , Michal Hocko , Alistair Popple , linuxppc-dev@lists.ozlabs.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, amd-gfx@lists.freedesktop.org, nouveau@lists.freedesktop.org, linux-pci@vger.kernel.org, linux-mm@kvack.org, linux-cxl@vger.kernel.org Subject: Re: [PATCH v4 1/7] mm/zone_device: Add order argument to folio_free callback Message-ID: <20260112233154.GM745888@ziepe.ca> References: <20260111205820.830410-1-francois.dugast@intel.com> <20260111205820.830410-2-francois.dugast@intel.com> <874d29da-2008-47e6-9c27-6c00abbf404a@nvidia.com> <0D532F80-6C4D-4800-9473-485B828B55EC@nvidia.com> <20260112134510.GC745888@ziepe.ca> <45A4E73B-F6C2-44B7-8C81-13E24ED12127@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=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <45A4E73B-F6C2-44B7-8C81-13E24ED12127@nvidia.com> On Mon, Jan 12, 2026 at 06:15:26PM -0500, Zi Yan wrote: > > We could move the call to free_zone_device_folio_prepare() [1] into the > > driver-side implementation of ->folio_free() and drop the order argument > > here. Zi didn’t particularly like that; he preferred calling > > free_zone_device_folio_prepare() [2] before invoking ->folio_free(), > > which is why this patch exists. > > On a second thought, if calling free_zone_device_folio_prepare() in > ->folio_free() works, feel free to do so. I don't think there is anything "prepare" about free_zone_device_folio_prepare() it effectively zeros the struct page memory - ie undoes some amount of zone_device_page_init() and AFAIK there are only two reasons to do this: 1) It helps catch bugs where things are UAF'ing the folio, now they read back zeros (it also creates bugs where zero might be OK, so you might be better to poison it under a debug flag) 2) It avoids the allocate side having to zero the page memory - and perhaps the allocate side is not doing a good job of this right now but I think you should state a position why it makes more sense for the free side to do this instead of the allocate side. IOW why should it be mandatory to call free_zone_device_folio_prepare() prior to zone_device_page_init() ? Certainly if the only reason you are passing the order is because the core code zero'd the order too early, that doesn't make alot of sense. I think calling the deinit function paired with zone_device_page_init() within the driver does make alot of sense and I see no issue with that. But please name it more sensibly and describe concretely why it should be split up like this. Because what I see is you write to all the folios on free and then write to them all again on allocation - which is 2x the cost that is probably really needed... Jason