From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.219.42 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796133362; b=095QS5Q0QcO9wJVJFJ5205nRObHDeepZDgVuMSEWiwCFIHcmCECSDN3o3QX7NM3mc7o5 NE7KX2z8n5b4dnuPWyFeo5IvDw0qAg7tMxWHx0w38TZ1DbjvSZs9g9QHJm2KTt+tx2Vlh ok6sHQLf6T4aZ/GogsUMYdA5kqoKDfNcVK3aF0XIF0DTtTVmSGsw5W4WaTEdIHewgkU0V j9+pE/I7ioXn/ayHSa3txeJ6RfH68xHZLDSPuo6fNEjDWTRDE+4KrjWANqwKDPmXbsomv KxjCwn5Ju7roKFHrbUuTkGSPjtOQWBfhpEvnaFF9g0YB6Ne+ODc8dIow8VxkE4Ccdkw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796133362; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: MIME-Version:Content-Type:Content-Transfer-Encoding:Subject:From:To: Cc:In-Reply-To:References:Date:Message-Id:X-Mailer; bh=eXBWzu0e6z8OG7uOvte6aDqb2e3Vuh7OKyGiPCFsrQY=; b=fHnDKB1Dh8w6wAsYg3msYIIEl2DNMsenMNNmvDx6zsrQzIVcGXQxEJZqpxIIkaHRrIVZ TJ6GzjVh1hzkSaRb0iHP81cqjpNstr7XhOF04qPhLtiNiyhRUnzo7MCeBsqT9TO6qyH4/ QCjHwQENOTkNdqL9HiyYbBJnJp8zN5I7Bt3v6X8yY9xnKEuU7QR59cqzESc5eLYr0hxNE 1Zn1D1JtbVU6l+zHYjlzYawhk0sJiK7WsKD6p9IINKHWBMQeDspHc5InHQcheLB84dOcf U5psy6Y39G4M3SJJf/d4wQhVO/QLccYgkYeNSXbF//4qsithjivQI2XNUE7unBLD2Dw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none header.from=gourry.net; spf=pass smtp.mailfrom=gourry.net; dkim=pass header.d=gourry.net header.i=@gourry.net header.a=rsa-sha256 header.s=google header.b=alOagc1T; arc=none smtp.remote-ip=209.85.219.42 Received: from mail-qv1-f42.google.com (mail-qv1-f42.google.com [209.85.219.42]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C1344606A329 for ; Tue, 1 Dec 2026 13:56:01 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org C1344606A329 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=gourry.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gourry.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gourry.net header.i=@gourry.net header.a=rsa-sha256 header.s=google header.b=alOagc1T Received: by mail-qv1-f42.google.com with SMTP id 6a1803df08f44-91e8a05ec5aso154230296d6.1 for ; Tue, 01 Dec 2026 05:56:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gourry.net; s=google; t=1796133360; x=1796738160; darn=vger.kernel.org; h=message-id:date:references:in-reply-to:cc:to:from:subject :content-transfer-encoding:content-type:mime-version:from:to:cc :subject:date:message-id:reply-to:content-type; bh=eXBWzu0e6z8OG7uOvte6aDqb2e3Vuh7OKyGiPCFsrQY=; b=alOagc1TzGV4ifiuHTgWFTei7bVj/y3ry9mjaQ4EPw0oNC5Lu/saapESRs5usSDqri Z1ApqoUqyksuvyIw+k4vL2yIzqI8wg14zkHfMdv1axBNCIIvYpG0Pi0no1KhggE8YV2y ZFpG59k84GP6tmjVNs2erFK5ZLoz8WiKm9aaS+LZe91zaJZhKqEKdZVa+61Qe6l9oNkD GnqPgkIXlThY83majbTZlQq0FMTm+2RcwoK3WRrNs3FCLxWdPL50AkDqECZfGlvDcNPs bIkh/uGII4hSt5Fm1ndMjniLIgsX5ldvIGIz0YWKgg8IVskvwpicHft87V+MhFG6a5U4 Yt3A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796133360; x=1796738160; h=message-id:date:references:in-reply-to:cc:to:from:subject :content-transfer-encoding:content-type:mime-version:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=eXBWzu0e6z8OG7uOvte6aDqb2e3Vuh7OKyGiPCFsrQY=; b=n58yagEdFRfXlo7vJFq2zAz/Pvle7WhstEVuIi7cRD7dqs9mBmnuBgFUK4aolI4gmX LokCYBk1ml2HR2JUs7NlDc3g55yK6uZg0ZIZTlUtLxgtWyLPJBnFCxZuANWOO/bUu1iG fr5eGU3DPsIlr+m36QnWJYdm3ydlLsPUEXoQXIT32XreXfwsChSGIE25VHNME7iic0Ez aMqFIfIbY8ruzbcEmxJ6idZ7EWk+hvZZGmOeEmZlfBHRT3Tcyts8Y6DyOEm1lfsHx0F+ 1ky5Q9QEU6muIPWSXBWfwUfAVWC5v+4tnAWgbRFj457NnS+0DamOFsghW0lwIlhspDbJ OT+w== X-Forwarded-Encrypted: i=1; AL+hErGiT8WER4fDjwjzC61UVn30p055Ai5pBH0B9ue8hcu0igaW6pVLd5i4YjLFAFAObrC/TMFm4ev45Slb6vc=@vger.kernel.org X-Gm-Message-State: APuU4Z/DT1GTgKlaH+eNIGhb3rqR600cnILOzK7SGXzN+5OP0wzblmED 2mItQ2Kk52YH1SN9UmUJb23uQ7YZbSnJugKPN5pxnOUYgv9WRzXBZdXenZPqLCjwm1E= X-Gm-Gg: AZFdTZfFUjDzjCpFfaEXgQ6wnzgt0GAHhRRYGepczABbv0euwfCfsltcpDFBYrZEkoi a6B+9L78GzCbmBGZ9ugeT4gLJBvli4OdngMwOoDKpaTi86tE6rm8ngJm5hc+zz1Xno9h7gMuN47 CaThI2DkY7N5/OOC3kp6pcdSi/146CXpyQwIZcBp4Z243KdJxFYUAlof7ZGIrxH9KNo+gdllD05 Nq0ZYxsexMDyblo7GQI1m25NIqKP0/6cA9Q7n9WCEuSlCEMPqd4lQf/SvPuFrcbJI5WjW67Yah3 WWembO/W8By0YHrmJpMsO+lfka2JUAO+DOxWYVotKgdMDXCw58Q6uMDRdaklpGliqaCk5V7JwMQ 2nXI5AtcmstmAZs6TsnkIFx0Et5/AntHFfUGP7TLC5CCBpxg6eZOk7SEOJ39GrjvEaafjTDlSw/ Mkz9J2FiaNt/7X7U44poUwtLWiUgO9LdxLCmczawdQx6CzjxgoIyLrMelGt0EG5gxICMPPXqLT3 2nRzy/WTonQR4UFXh3X80USOO2oVS7WD5stsfEGeKiC8RJMOY6bFDCYTyGGqKR4zJ8bcPBqJicV 6T4vdlx64hj/NiNRtT1nqyAdoizqgD1HxPP/7dwrzhz1VX+OcNGZUKsXPT/wiJJneaPKpcTuUOI vHvN7kBk= X-Received: by 2002:a05:6214:1c0c:b0:921:21c4:1d53 with SMTP id 6a1803df08f44-92134b9cd13mr711625106d6.50.1796133360461; Tue, 01 Dec 2026 05:56:00 -0800 (PST) Received: from [192.168.50.231] (pool-71-191-145-202.washdc.fios.verizon.net. [71.191.145.202]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-92134a08552sm321574406d6.34.2026.12.01.05.55.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Dec 2026 05:56:00 -0800 (PST) X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Subject: Re: [PATCH 21/32] mm/migrate_device: mark folios leaving device memory dirty From: "Gregory Price (Meta)" To: "David Hildenbrand (Arm)" Cc: Hugh Dickins , Baolin Wang , Andrew Morton , Mike Rapoport , Peter Xu , Michal Hocko , Kiryl Shutsemau , Manfred Spraul , Davidlohr Bueso , Cyrill Gorcunov , Zi Yan , "Liam R. Howlett" , Nico Pache , Ryan Roberts , Dev Jain , Barry Song , Lance Yang , Usama Arif , Lorenzo Stoakes , Rik van Riel , Vlastimil Babka , Harry Yoo , Jann Horn , Yang Shi , Zach O'Keefe , Song Liu , David Stevens , Kefeng Wang , Alex Williamson , Suren Baghdasaryan , Dave Jiang , Matthew Wilcox , Miaohe Lin , David Rientjes , Shakeel Butt , Jan Kara , Mel Gorman , Jason Gunthorpe , John Hubbard , Gerd Hoffmann , Vivek Kasireddy , Dave Airlie , Matthew Brost , Joshua Hahn , Byungchul Park , Gregory Price , Ying Huang , Alistair Popple , Hagen Paul Pfeifer , James Bottomley , Felix Kuehling , Alex Sierra , Balbir Singh , Kairui Song , Qi Zheng , Axel Rasmussen , Yuanchu Xie , Wei Xu , Baoquan He , Oscar Salvador , Muchun Song , Dan Williams , Rakie Kim , Hao Li , Christoph Lameter , Roman Gushchin , Sebastian Andrzej Siewior , Clark Williams , Steven Rostedt , Alexei Starovoitov , Xu Xin , Chengming Zhou , Shivank Garg , linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-cxl@vger.kernel.org, linux-rt-devel@lists.linux.dev, SJ Park , stable@vger.kernel.org, Chris Mason In-Reply-To: <20261129-fixes_core_3-v1-21-f66094116801@kernel.org> References: <20261129-fixes_core_3-v1-0-f66094116801@kernel.org> <20261129-fixes_core_3-v1-21-f66094116801@kernel.org> Date: Tue, 01 Dec 2026 08:55:53 -0500 Message-Id: <179613335337.412063.6101109255640231969.b4-reply@b4> X-Mailer: b4 0.17-dev On 2026-11-29 11:06 +0100, David Hildenbrand (Arm) wrote: > Device-private page table entries are weird: they are non-present page > table entries, and the device can write to the memory without the CPU > noticing or the CPU page tables reflecting it. > > So there is no dirty bit on the PTE we could sync to the folio. And > usually, nobody cares about the dirty bit for these folios, as these > folios are not on the LRU. Device-coherent memory has the same problem: > it is mapped through present PTEs, but the device writes through its own > page tables and does not set the PTE dirty bit. > > There is one problem, though: when we migrate such a clean folio back > to system RAM, the new folio will be clean, and will be mapped through > clean PTEs. > > Consequently, reclaim can discard the data if the folio is lazyfree: > > (1) MADV_FREE on an ordinary anonymous folio makes the folio lazyfree > and clean. > (2) We migrate the folio to device memory. The new (device) folio is > lazyfree and clean. > (3) The device writes to the folio. > (4) We migrate the folio back to system RAM. The new folio is still > lazyfree, and clean just like the PTE that now maps it. > (5) Reclaim discards the folio, and the data the device wrote is lost. > > Similarly, after fork(), a child that shares such a clean folio can call > MADV_FREE, which does not check a clean folio for other mappings. > > So let's fix it by simply marking folios dirty when migrating them out > of device memory. > > This has low urgency, as it requires MADV_FREE on memory that is > migrated to device memory and written by the device. > > Fixes: a5430dda8a3a ("mm/migrate: support un-addressable ZONE_DEVICE page in migration") > Fixes: 8315ada7f095 ("mm/migrate: allow migrate_vma() to alloc new page on empty entry") > Fixes: f25cbb7a95a2 ("mm: add zone device coherent type memory support") > Fixes: a30b48bf1b24 ("mm/migrate_device: implement THP migration of zone device pages") > Cc: stable@vger.kernel.org > Reported-by: Chris Mason > Signed-off-by: David Hildenbrand (Arm) Tested-by: Gregory Price (Meta) Reviewed-by: Gregory Price (Meta) -- ~Gregory