mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Christian König" <christian.koenig@amd.com>
To: Aveline Noir <jm5905938@gmail.com>,
	Jason Gunthorpe <jgg@ziepe.ca>,
	Andrew Morton <akpm@linux-foundation.org>,
	Felix Kuehling <Felix.Kuehling@amd.com>,
	Alex Deucher <alexander.deucher@amd.com>
Cc: "David Airlie" <airlied@gmail.com>,
	amd-gfx@lists.freedesktop.org, "Barry Song" <baohua@kernel.org>,
	"Baolin Wang" <baolin.wang@linux.alibaba.com>,
	"Jonathan Corbet" <corbet@lwn.net>,
	"Danilo Krummrich" <dakr@kernel.org>,
	"David Hildenbrand" <david@kernel.org>,
	"Dev Jain" <dev.jain@arm.com>,
	dri-devel@lists.freedesktop.org,
	"Francois Dugast" <francois.dugast@intel.com>,
	"Christoph Hellwig" <hch@lst.de>,
	"Himal Prasad Ghimiray" <himal.prasad.ghimiray@intel.com>,
	"Honglei Huang" <honghuan@amd.com>,
	"Jann Horn" <jannh@google.com>,
	"Kiryl Shutsemau" <kas@kernel.org>,
	"Lance Yang" <lance.yang@linux.dev>,
	"Leon Romanovsky" <leon@kernel.org>,
	"Liam R. Howlett" <liam@infradead.org>,
	linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-mm@kvack.org, "Lorenzo Stoakes" <ljs@kernel.org>,
	"Lyude Paul" <lyude@redhat.com>,
	"Matthew Brost" <matthew.brost@intel.com>,
	"Michal Hocko" <mhocko@suse.com>,
	"Nico Pache" <nico.pache@linux.dev>,
	nouveau@lists.freedesktop.org, "Pedro Falcato" <pfalcato@suse.de>,
	"Philip Yang" <Philip.Yang@amd.com>,
	"Randy Dunlap" <rdunlap@infradead.org>,
	"Mike Rapoport" <rppt@kernel.org>,
	"Ryan Roberts" <ryan.roberts@arm.com>,
	sashiko-bot@kernel.org, sashiko-reviews@lists.linux.dev,
	"Simona Vetter" <simona@ffwll.ch>,
	"Shuah Khan" <skhan@linuxfoundation.org>,
	"Sunil Khatri" <sunil.khatri@amd.com>,
	"Suren Baghdasaryan" <surenb@google.com>,
	"Thomas Hellström" <thomas.hellstrom@linux.intel.com>,
	"Usama Arif" <usama.arif@linux.dev>,
	"Vlastimil Babka" <vbabka@kernel.org>,
	"Vitaly Prosyak" <vitaly.prosyak@amd.com>,
	"Zi Yan" <ziy@nvidia.com>
Subject: Re: [PATCH] mm/hmm: honor write requests for owned device-private pages
Date: Mon, 2 Nov 2026 14:51:58 +0100	[thread overview]
Message-ID: <e925fde8-5d07-419f-a25e-4dd0bb90ad46@amd.com> (raw)
In-Reply-To: <179362220860.2958105.9509793190720553695.b4-reply@b4>

Hi Aveline,

On 11/2/26 13:23, Aveline Noir wrote:
> Hi all,
> 
> On Sun, 01 Nov 2026 19:58:21 +1100 Aveline Noir wrote:
> 
>> Oh, I missed that. I'll try to fix it.
> 
> While working on this, I found that the fix reaches well beyond
> mm/hmm.c and would likely need rework in several subsystems, so I'd
> like to hear your views before going further. v1 shouldn't be applied
> as is.
> 
> amdkfd holds svms->lock and prange->migrate_mutex across
> hmm_range_fault(), and svm_migrate_to_ram() needs both, so it can't
> migrate the page for the validating task. Migrating under those locks
> can deadlock, since do_swap_page() waits for the device page lock, which
> a concurrent CPU fault can hold while waiting for svms->lock.

Yeah those issues are already known.

Because of that AMDs KFD team is in the process of replacing the self made KFD based SVN handling with the drm_gpusvm module which is also used by Intels XE driver.

> From
> reading the code, amdkfd also maps such read-only pages writable today,
> as it takes GPU write permission from the VMA rather than from
> HMM_PFN_WRITE, so GPU writes after fork() would be visible to the child.
> I haven't been able to confirm this on hardware.

That is a new issue as far as I know.

> One option I tried is an opt-in HMM flag that returns -EDEADLK and the
> page address instead of faulting, so amdkfd can drop its locks, fault
> the page and validate again. It works with test_hmm, but the amdkfd
> side grew to about 550 lines across the GPU fault handler, the restore
> worker and svm_range_set_attr(), and is only compile-tested. Read-only
> entries also come from NUMA hinting scans and mprotect(), so pages that
> aren't shared would be moved out of VRAM too, and Xe and nouveau would
> see their pages migrated in the same cases.

I don't think we should try to fix the KFD SVM code, as said we are already in the process of ditching it because of those problems.

> Would you prefer an opt-in interface like this, a change to the amdkfd
> locking so that migrate_to_ram() can run during validation, or
> something else? I can post the amdkfd part as an RFC if that helps.
> 
> I also found a few smaller related issues, and I'll send fixes for them
> separately.

There is also https://gitlab.freedesktop.org/drm/amd/-/work_items/6003 which I'm not sure how to properly handle.

Current AMD GPUs don't have dirty tracking in their GPUVM, so it doesn't really make sense to set the PTE or struct page dirty from the MMU notifier (both data pointers are not around there any more).

We also can't set the page dirty directly after calling hmm_range_fault() because we don't own a page reference and so it could change at any time.

At least for the GFX CS path it would make most sense to set the pages dirty in hmm_range_fault(), not sure about the SVM use case.

Regards,
Christian.

> 
> Thanks,
> Aveline Noir


      reply	other threads:[~2026-11-02 13:52 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-31  7:10 Aveline Noir
     [not found] ` <sashiko-outbox-192310@kernel.org>
2026-11-01  8:58   ` Aveline Noir
2026-11-02 12:23     ` Aveline Noir
2026-11-02 13:51       ` Christian König [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=e925fde8-5d07-419f-a25e-4dd0bb90ad46@amd.com \
    --to=christian.koenig@amd.com \
    --cc=Felix.Kuehling@amd.com \
    --cc=Philip.Yang@amd.com \
    --cc=airlied@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=alexander.deucher@amd.com \
    --cc=amd-gfx@lists.freedesktop.org \
    --cc=baohua@kernel.org \
    --cc=baolin.wang@linux.alibaba.com \
    --cc=corbet@lwn.net \
    --cc=dakr@kernel.org \
    --cc=david@kernel.org \
    --cc=dev.jain@arm.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=francois.dugast@intel.com \
    --cc=hch@lst.de \
    --cc=himal.prasad.ghimiray@intel.com \
    --cc=honghuan@amd.com \
    --cc=jannh@google.com \
    --cc=jgg@ziepe.ca \
    --cc=jm5905938@gmail.com \
    --cc=kas@kernel.org \
    --cc=lance.yang@linux.dev \
    --cc=leon@kernel.org \
    --cc=liam@infradead.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=ljs@kernel.org \
    --cc=lyude@redhat.com \
    --cc=matthew.brost@intel.com \
    --cc=mhocko@suse.com \
    --cc=nico.pache@linux.dev \
    --cc=nouveau@lists.freedesktop.org \
    --cc=pfalcato@suse.de \
    --cc=rdunlap@infradead.org \
    --cc=rppt@kernel.org \
    --cc=ryan.roberts@arm.com \
    --cc=sashiko-bot@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=simona@ffwll.ch \
    --cc=skhan@linuxfoundation.org \
    --cc=sunil.khatri@amd.com \
    --cc=surenb@google.com \
    --cc=thomas.hellstrom@linux.intel.com \
    --cc=usama.arif@linux.dev \
    --cc=vbabka@kernel.org \
    --cc=vitaly.prosyak@amd.com \
    --cc=ziy@nvidia.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®