From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-qk1-f180.google.com (mail-qk1-f180.google.com [209.85.222.180]) (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 DB87A2550A3 for ; Mon, 12 Jan 2026 23:31:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.180 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768260719; cv=none; b=eQtuUkxBHG0BMOFNaNqs2Yp3VKPBGJ1Cu1eqkoMetaBEglCi7nmqWBseis2YcDXFJAO7oX2rxJKy6ubgTv1kal9f3oS+q5ODMsxCIWdRLSZH3CWuIU0GDhBLIx67hFUN9Jn5REVuvthnW1ASTTzlkrSqJTOM2E1ubpeFzbSRH2U= 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.180 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-f180.google.com with SMTP id af79cd13be357-8b23b6d9f11so747202985a.3 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=ZSqomq6CCjB+pSxz8SbLmQSXlcZtZ6DONf1PSymcEvEhDG0vumYkGufJpM1STZqvJb NESs9/sKoVP14G0qh0uVWelkyeRLTIIsNX3huoOqiTG3GE1/VA7zL+da3ZpBkgfdtm4Q uFwPciSFFVObo/ijqLIV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: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-cxl@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