From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-dl1-f41.google.com (mail-dl1-f41.google.com [74.125.82.41]) (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 EE2EE36CDEC for ; Tue, 17 Feb 2026 16:21:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=74.125.82.41 ARC-Seal:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771345298; cv=pass; b=Qs6k5BNYTsbClONCQo5inRAALGkEE5HGiUj1LgzfGxu1kbFKFWcEDgzZbXKkqUqo4nagP+fp8y4Rk7GMNSEJTJgzr25d+SDj/rMYOhDrOSaihthj2nufZzgNaZtOWl+jEvhrQTXFbGbBMES9DJQsKLsh7xZC9+DyXaBs6qBG9QA= ARC-Message-Signature:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771345298; c=relaxed/simple; bh=jKAw4Kmv+Q27QqlJtPVQ5bpdRN+N3gh112ql2N1J7YU=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=BpgMIy3XjbJHV7vDdsded55OByt9i4MrjO/UNoZ6WUNufOWMW9GDHhzrV8bmwUANnUEIrYxZ4ZdnEUQBYT+1HLzyUPHLGICf7gY9NKy4Ocqr2ANDc4d1w3IGiJXe/ZZGdj9/Kgalj5a0ZRkS0YwKz9/jnYmgHbuDVUdTXYi9iBs= ARC-Authentication-Results:i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=XGqcHyOT; arc=pass smtp.client-ip=74.125.82.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="XGqcHyOT" Received: by mail-dl1-f41.google.com with SMTP id a92af1059eb24-12734af2cdcso295140c88.0 for ; Tue, 17 Feb 2026 08:21:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1771345296; cv=none; d=google.com; s=arc-20240605; b=dfbiDXPYzHg3h6vBbXtr2smdfJw7RTZZl2dy+opcnuSkKzRuT24XuwsuAd4I4leUhz bruyYuOTM7yXIWiA9NiB2jRaAdMZfy28sTwpXZQ9lvmwIl3xtkpeL3PNkg27tGuQlZtB ozP8Kpw+mqyOuJqL1I09ATF8lylLAC7c8KaFI4nZGewlFaI5q8nisNJ4U/YcSI4PcK7C Mw25Cju6nrDc7ai3d/J3b345oJFFTQVssgKHCMnhqzRh4gsuhFiC0/mX8kNsXh8PMMNW O8yBlPg4B0omETrF7NAr1EmmAOlWdx6tAfpmY+CivUSjc6Ga1fcX6Rr4f9CMOj8NgT/T Vw9Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=5OjLMNpEhGZOhH95nEM9Q612OzOTY/1NripapqhTwW8=; fh=7LYnNdlDFJDq0ecOjvyNN/R4oK0yk5eMYdTo4VYGrPg=; b=cQ/oL2te0Tg6EBKw2VP/eYClRf3Eqw//g3onB6hYaTVQVYjSYd1/1+FgFHoHGEBSbD MaM4biEgSWRA0WFd1tPtpd/Kl4ogowx20S/Y0D/NRVyf3Fy6ItyQyohFHmxXBlh3wjgV v7LVNrlENDpCGBevkn+9p85lxW6+BGKrwxKF+snPTuvsKYO/jbssHneDZjHFrGHr76pQ 5thAbOBrbYytPP+7fIDXpDfB4iUXH7g3SUXf1ePRJC0JXzSl5AW18Nl2gkiH0VvelcSa w3B7R+H94+Qh8zVj4Wsbwvh+a/e8ncePdM3/V+lVxpUJaycOHBr8Ls2WrnhAIl0xc+BT AHgg==; darn=vger.kernel.org ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1771345296; x=1771950096; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=5OjLMNpEhGZOhH95nEM9Q612OzOTY/1NripapqhTwW8=; b=XGqcHyOTG93z42plaa5IjYA7pmczu/NXS6XFfd0LBUZZg7TTF6HASCHxgbv07Ctj1b lpIrbOnQY22Q+FVWAeQaxF8aCYOlfrEtX28Y9KVWNUOPbIP956evBEO5qfkmZkvcAEaQ jrzFX9S1q8o71LLT83VFmbQdDW4xfcO/3up1Upx6Sj7+WhvXmhBL4DtblP0QZoAgKj5+ Qk1XAbKbHpH6N7Wu/4SvldN2+4UORW6Sq3JXHTUoij1GjH5bC6lNvej6S8eouWlOufsW kPyC9wdSlOAtBYc6wk5cAEupRdoODKhYoK95EwcqMDxzHL2QObyMYWZUdm4QX5xdrDEC An2w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1771345296; x=1771950096; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=5OjLMNpEhGZOhH95nEM9Q612OzOTY/1NripapqhTwW8=; b=VeZQsqLLDOe7A+jQaESGTJahqb08mcFszanzd21kDcItUnpej3xYdaDfAiGbRK8+k+ /riAg8RjZpKOEQ0edZ4NF5wjPYOn+/4abUzlIc1E6Ieab+Ln+MEjlnNkSUTbsctmtNJy O00KeMV3HdQTWQYf7H4GeMyl6a1YTN4ic5Iorcj2HGr3oPDctI0uLI4BDlxz/qF366j5 esehozcSKBHgPb5zn6aZFKjAWw5FKmwLsghZUcnqjzUYopb0umazkvDaULNDRnYbCNZW 2Qp7PZMBaGtQETAb/H8T/5yKCuULB9hkbagoaWnv03kHuNSVG/T66qITWMl4x88efzjb Z/IA== X-Forwarded-Encrypted: i=1; AJvYcCWyTZiSadhykZVkLr6koXSX3Me7b1BmuHvYZV2T5L2uAxnqVYQDQFXSpQ8ptPVnOT4RbSDuVJn9ZAdzPLw=@vger.kernel.org X-Gm-Message-State: AOJu0YwiRv92qZfTrLQK9eWK20AV7m1DMWkAFzg6gBnAMF5eU8PiUHK1 4ooK0cUg670gP8er9mRFxuLX4GLyEbYvIZpJ3ypx8yaMgfsqsoUIp7ZbIpvkgrplNa5jxNKqldt 9zsdYEpgovekUitSV/1+3AYC3nVBwU0Y= X-Gm-Gg: AZuq6aK4ZUz/U2CsplSImfAK4nfypXJ77gEKrD32vNyXAZPn+XaCajz9QfC1FLUHMsX s5m/Rh1J9keLPjYIRL8ZFAcHoZK9pUKa7OXggzY92NoIsLRO+Wk9DEwnoJYovTQ2STc0CzJTxHd FFgV0tf/7iUcpKzKK4bxQoArgJ+j7WYY6fi8E1rDz6lFxUR3d2nVu4yIzfWG/I1TRh5w7xEVVV3 190OuTBpL2NmO+fZxat/Cmf6TUT2h6HyAmpbFV9NlU31wpkksHwWSmjFPMo1SY4/EHpcGlE4sb/ ZuCJpdKkHtDi4sKs6FsFqurMncfV01YwQU1t0ihDvEt1s6MCoiQFgtre+WGkv/5V9EpwhA== X-Received: by 2002:a05:7022:6b98:b0:123:308f:667b with SMTP id a92af1059eb24-12739793cc8mr4162045c88.2.1771345295795; Tue, 17 Feb 2026 08:21:35 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20260211102657.4180-1-pierre-eric.pelloux-prayer@amd.com> <20260211102657.4180-4-pierre-eric.pelloux-prayer@amd.com> In-Reply-To: <20260211102657.4180-4-pierre-eric.pelloux-prayer@amd.com> From: Alex Deucher Date: Tue, 17 Feb 2026 11:21:23 -0500 X-Gm-Features: AaiRm50OCgHm5iw9B2jU8EV7pEsKwcUfBQT0WA1EEpOMEpk41fegxP0li_OlOuc Message-ID: Subject: Re: [PATCH v1 4/6] drm/amdgpu: extract amdgpu_vm_lock_by_pasid from amdgpu_vm_handle_fault To: Pierre-Eric Pelloux-Prayer Cc: Alex Deucher , =?UTF-8?Q?Christian_K=C3=B6nig?= , David Airlie , Simona Vetter , amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Wed, Feb 11, 2026 at 5:37=E2=80=AFAM Pierre-Eric Pelloux-Prayer wrote: > > This is tricky to implement right and we're going to need > it from the devcoredump. > > Signed-off-by: Pierre-Eric Pelloux-Prayer Acked-by: Alex Deucher > --- > drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 84 +++++++++++++++++--------- > drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h | 3 + > 2 files changed, 57 insertions(+), 30 deletions(-) > > diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c b/drivers/gpu/drm/amd= /amdgpu/amdgpu_vm.c > index 807f8bcc7de5..6a5b3e148554 100644 > --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c > +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c > @@ -2930,6 +2930,50 @@ int amdgpu_vm_ioctl(struct drm_device *dev, void *= data, struct drm_file *filp) > return 0; > } > > +/** > + * amdgpu_vm_lock_by_pasid - return an amdgpu_vm and its root bo from a = pasid, if possible. > + * @adev: amdgpu device pointer > + * @root: root BO of the VM > + * @pasid: PASID of the VM > + * The caller needs to unreserve and unref the root bo on success. > + */ > +struct amdgpu_vm *amdgpu_vm_lock_by_pasid(struct amdgpu_device *adev, > + struct amdgpu_bo **root, u32 pa= sid) > +{ > + unsigned long irqflags; > + struct amdgpu_vm *vm; > + int r; > + > + xa_lock_irqsave(&adev->vm_manager.pasids, irqflags); > + vm =3D xa_load(&adev->vm_manager.pasids, pasid); > + *root =3D vm ? amdgpu_bo_ref(vm->root.bo) : NULL; > + xa_unlock_irqrestore(&adev->vm_manager.pasids, irqflags); > + > + if (!*root) > + return NULL; > + > + r =3D amdgpu_bo_reserve(*root, true); > + if (r) > + goto error_unref; > + > + /* Double check that the VM still exists */ > + xa_lock_irqsave(&adev->vm_manager.pasids, irqflags); > + vm =3D xa_load(&adev->vm_manager.pasids, pasid); > + if (vm && vm->root.bo !=3D *root) > + vm =3D NULL; > + xa_unlock_irqrestore(&adev->vm_manager.pasids, irqflags); > + if (!vm) > + goto error_unlock; > + > + return vm; > +error_unlock: > + amdgpu_bo_unreserve(*root); > + > +error_unref: > + amdgpu_bo_unref(root); > + return NULL; > +} > + > /** > * amdgpu_vm_handle_fault - graceful handling of VM faults. > * @adev: amdgpu device pointer > @@ -2945,50 +2989,31 @@ int amdgpu_vm_ioctl(struct drm_device *dev, void = *data, struct drm_file *filp) > * shouldn't be reported any more. > */ > bool amdgpu_vm_handle_fault(struct amdgpu_device *adev, u32 pasid, > - u32 vmid, u32 node_id, uint64_t addr, uint64_= t ts, > - bool write_fault) > + u32 vmid, u32 node_id, uint64_t addr, > + uint64_t ts, bool write_fault) > { > bool is_compute_context =3D false; > struct amdgpu_bo *root; > - unsigned long irqflags; > uint64_t value, flags; > struct amdgpu_vm *vm; > int r; > > - xa_lock_irqsave(&adev->vm_manager.pasids, irqflags); > - vm =3D xa_load(&adev->vm_manager.pasids, pasid); > - if (vm) { > - root =3D amdgpu_bo_ref(vm->root.bo); > - is_compute_context =3D vm->is_compute_context; > - } else { > - root =3D NULL; > - } > - xa_unlock_irqrestore(&adev->vm_manager.pasids, irqflags); > - > - if (!root) > + vm =3D amdgpu_vm_lock_by_pasid(adev, &root, pasid); > + if (!vm) > return false; > > + is_compute_context =3D vm->is_compute_context; > + > addr /=3D AMDGPU_GPU_PAGE_SIZE; > > - if (is_compute_context && !svm_range_restore_pages(adev, pasid, v= mid, > - node_id, addr, ts, write_fault)) { > + if (is_compute_context && > + !svm_range_restore_pages(adev, pasid, vmid, node_id, addr= , > + ts, write_fault)) { > + amdgpu_bo_unreserve(root); > amdgpu_bo_unref(&root); > return true; > } > > - r =3D amdgpu_bo_reserve(root, true); > - if (r) > - goto error_unref; > - > - /* Double check that the VM still exists */ > - xa_lock_irqsave(&adev->vm_manager.pasids, irqflags); > - vm =3D xa_load(&adev->vm_manager.pasids, pasid); > - if (vm && vm->root.bo !=3D root) > - vm =3D NULL; > - xa_unlock_irqrestore(&adev->vm_manager.pasids, irqflags); > - if (!vm) > - goto error_unlock; > - > flags =3D AMDGPU_PTE_VALID | AMDGPU_PTE_SNOOPED | > AMDGPU_PTE_SYSTEM; > > @@ -3027,7 +3052,6 @@ bool amdgpu_vm_handle_fault(struct amdgpu_device *a= dev, u32 pasid, > if (r < 0) > dev_err(adev->dev, "Can't handle page fault (%d)\n", r); > > -error_unref: > amdgpu_bo_unref(&root); > > return false; > diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h b/drivers/gpu/drm/amd= /amdgpu/amdgpu_vm.h > index 139642eacdd0..2051eda55c99 100644 > --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h > +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h > @@ -589,6 +589,9 @@ bool amdgpu_vm_handle_fault(struct amdgpu_device *ade= v, u32 pasid, > u32 vmid, u32 node_id, uint64_t addr, uint64_= t ts, > bool write_fault); > > +struct amdgpu_vm *amdgpu_vm_lock_by_pasid(struct amdgpu_device *adev, > + struct amdgpu_bo **root, u32 pa= sid); > + > void amdgpu_vm_set_task_info(struct amdgpu_vm *vm); > > void amdgpu_vm_move_to_lru_tail(struct amdgpu_device *adev, > -- > 2.43.0 >