From nobody Fri Oct 3 23:02:52 2025 Received: from mail-wm1-f73.google.com (mail-wm1-f73.google.com [209.85.128.73]) (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 3CBDB2EE262 for ; Fri, 22 Aug 2025 09:28:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755854932; cv=none; b=uERoU9svRGiVqgjmkaAMo9pYDf4hDbWoHIRoCr6unq+QzkdPFwFnF6C0Wz6HoO689Xr2kM1bFAyqQK+GroU0fI5rOIHVIKKizepjcbcgq8IckxFkODMZqHDBMXTFKFi7ng9XGdXzqpEG4YSdX7EnL6t7yqduMg+zD5XPMKa2Tyk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755854932; c=relaxed/simple; bh=Kl3w8GhwSkTKnL4gpM3EUOD9jKMCH83Id+WyJ393gAc=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=mIfFCxWPHUOMaTgR4seymMSSD7Qg31V/oYZiOoy8cnj3T55yusvn/Tcn/65iSHQUb3Z5AZRrz33vqOsPPtIkllGEoxS/TgQjA3JEjzXlUr9VLIdXe01LeQfRM4h10jHVfLNNFLK2+hgki4TbastAsquha66H5dnevDova/1S4X0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--aliceryhl.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=gqCfs67q; arc=none smtp.client-ip=209.85.128.73 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--aliceryhl.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="gqCfs67q" Received: by mail-wm1-f73.google.com with SMTP id 5b1f17b1804b1-45a1b05d31cso9955045e9.1 for ; Fri, 22 Aug 2025 02:28:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1755854928; x=1756459728; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=TrBXsBfJN9Hl0C60LtHP8goa7t5Q56hpklQFi7rDf1M=; b=gqCfs67qxC/11CqwR68IeUZpwPkblykzHz2CJDsysjfKGTyHmU/coT38Ji2gwx9joj JbxGt13kBucD+OL5SXdja7ow44QoqE6MKiQqUklSSJGVjOlPWjByO4uiVaw2Y6Gh095H n2arGU6qZe4UEMcL/b1G6sEwitypj0b1M6SwAAar0zDT4YX749tbhbghO+6Gwom+bBzs In18sExNS6Ywo2KPFKfkxD4i/UdZyKs+6wfcVKaCDqRFilvqEMNXBEnutuYZWpZTnmAy j7hj8naWMbwmPb+vRiTyRBgdYN7jvgNioEGYQMoWXlJTpZqlQrgiyV5zqicqN/DjlwaS Q6Ag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1755854928; x=1756459728; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=TrBXsBfJN9Hl0C60LtHP8goa7t5Q56hpklQFi7rDf1M=; b=TPAasPyihZAWOl8Aen3y4CgCmpaARvXAGSzSRNWS5/uknFEoqQwu5/9OSidoupYPIF +0K5hOr8qZrAOt/CX0MGkVbEY4OECZT9+8wuKIVRcNNFD5+rlujvwD68DzJUME95sy37 AEmsW1bSKq2Kh9krqwFzzqpcazdIO51tUOB0S2/ZLIPbwFq+NbHZUBqGo4t3nu89lNvT Dtf6rC7CQqMMEYu+6guGCQawcybQXNUeic+EACRqXsj+vKObMlxvnnT2AMF/jGrfdwp3 DnhjemjiDER2Z5mR5Cf3GyfzeTh6MmcTgQU0nd4JsXyT8z9R9Jn27J9IRcftxw40QS+A 1kLg== X-Forwarded-Encrypted: i=1; AJvYcCU9EjAwMBnKuQVRRkDFEOc4EDmgKZ2v+RdbWVvhWgR7GeROmPkojgXZoDjpVMhh4FEWbj2hQfUaHnQvrjQ=@vger.kernel.org X-Gm-Message-State: AOJu0YwwkydWXrcQCGX2Q9Z4brlHit0pbI7ObPtetJzPbjlQaG+IgcK6 gER7dpnpUHWnEpiil03JP0ztr6Ogxa5/mRpvplQ0Q14sI/7xTgRKyX4crdUq5pKfmeyHUvKBo5C 9ov72A2PgbwdUokytIg== X-Google-Smtp-Source: AGHT+IED8wcDTUn+Pl5RltIzM8gjl/tmIptfRKwT5dyprtog5nBFWSTOA4EQbWXFpewTcpCsnhP5UIL7y4PF/Bo= X-Received: from wmbeu9.prod.google.com ([2002:a05:600c:81c9:b0:459:dd37:a6bf]) (user=aliceryhl job=prod-delivery.src-stubby-dispatcher) by 2002:a05:600c:35c9:b0:458:b7d1:99f9 with SMTP id 5b1f17b1804b1-45b517a0655mr17952605e9.11.1755854928516; Fri, 22 Aug 2025 02:28:48 -0700 (PDT) Date: Fri, 22 Aug 2025 09:28:24 +0000 In-Reply-To: <20250822-gpuva-mutex-in-gem-v2-0-c41a10d1d3b9@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250822-gpuva-mutex-in-gem-v2-0-c41a10d1d3b9@google.com> X-Developer-Key: i=aliceryhl@google.com; a=openpgp; fpr=49F6C1FAA74960F43A5B86A1EE7A392FDE96209F X-Developer-Signature: v=1; a=openpgp-sha256; l=3464; i=aliceryhl@google.com; h=from:subject:message-id; bh=Kl3w8GhwSkTKnL4gpM3EUOD9jKMCH83Id+WyJ393gAc=; b=owEBbQKS/ZANAwAKAQRYvu5YxjlGAcsmYgBoqDhNzfZv5dJM175fnbqNeGceTMeDRW5pDdq+k uA1ND5WFxOJAjMEAAEKAB0WIQSDkqKUTWQHCvFIvbIEWL7uWMY5RgUCaKg4TQAKCRAEWL7uWMY5 Rlf2D/4/xi0frU0yUeXbZcDX1ScUrrZ9zjuUgR8Ow3W8K1zQqyzFnU07/S7HCg/80TBBvLfDsTb U8rKOyiqaOMkIJxi/CQ/QQ3zKZTKPJlUUwzWroZ48SzkjbGZ9ONBcua6H6qna6Zs2a9Mjj4UsGU 879eChTLDjFwsOir565HgrdVVD2LC3S67e6np8Y8D7Ma8I6edYhq/vIKMU1nOlu8Zh9KhPq9sNW Q2mAhyB9JndoKQW/drIemw2iArNDnS0i25+MBR+6fJzfHfwv/ZkQyH+0M0R/n9VCLkXLZH16c0u EZFjs9/7UlkOoOgF522g5Qic/+hRDWLFpL+0dduz2Qzj63YQ0Iw5IihTM2eYKSr2FxF0ngI87Yk 2MSSd+Mbn7RfCHp7oOLsnA/3o5F/ByIiE1UuOuziOffja/SbazXtuUijUEx9AUvCLOQftAZQ4mJ GAaaBQrXVwm14fxr+tPlkyEgtObdXzO2uKkVRoPpMHe1tEzkQZVqj+pNPJIsol0PJKb8ahK15la IxGzUej4znW0rwkkgjwEhNqXmNMhAQZQYgdQtYvSFe1AxBiBb4zRbqw+0+mG8XytrFHz9OLnK2A Txn6S1/a3nJfFCSFjinfwkUm1lFF1GQarGz2bgTR7kj39g6xwMI3+d7QbHB4n7WeR/KvrtMwvQ/ VfbKwcalfrR0+Kw== X-Mailer: b4 0.14.2 Message-ID: <20250822-gpuva-mutex-in-gem-v2-1-c41a10d1d3b9@google.com> Subject: [PATCH v2 1/3] drm_gem: add mutex to drm_gem_object.gpuva From: Alice Ryhl To: Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter , Danilo Krummrich , Boris Brezillon , Daniel Almeida , Steven Price , Liviu Dudau , Rob Clark , Rob Herring Cc: Miguel Ojeda , Boqun Feng , Gary Guo , "=?utf-8?q?Bj=C3=B6rn_Roy_Baron?=" , Benno Lossin , Andreas Hindborg , Trevor Gross , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org, Alice Ryhl Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable There are two main ways that GPUVM might be used: * staged mode, where VM_BIND ioctls update the GPUVM immediately so that the GPUVM reflects the state of the VM *including* staged changes that are not yet applied to the GPU's virtual address space. * immediate mode, where the GPUVM state is updated during run_job(), i.e., in the DMA fence signalling critical path, to ensure that the GPUVM and the GPU's virtual address space has the same state at all times. Currently, only Panthor uses GPUVM in immediate mode, but the Rust drivers Tyr and Nova will also use GPUVM in immediate mode, so it is worth to support both staged and immediate mode well in GPUVM. To use immediate mode, the GEMs gpuva list must be modified during the fence signalling path, which means that it must be protected by a lock that is fence signalling safe. For this reason, a mutex is added to struct drm_gem_object that is intended to achieve this purpose. Adding it directly in the GEM object both makes it easier to use GPUVM in immediate mode, but also makes it possible to take the gpuva lock from core drm code. As a follow-up, another change that should probably be made to support immediate mode is a mechanism to postpone cleanup of vm_bo objects, as dropping a vm_bo object in the fence signalling path is problematic for two reasons: * When using DRM_GPUVM_RESV_PROTECTED, you cannot remove the vm_bo from the extobj/evicted lists during the fence signalling path. * Dropping a vm_bo could lead to the GEM object getting destroyed. The requirement that GEM object cleanup is fence signalling safe is dubious and likely to be violated in practice. Panthor already has its own custom implementation of postponing vm_bo cleanup. Signed-off-by: Alice Ryhl Reviewed-by: Boris Brezillon --- drivers/gpu/drm/drm_gem.c | 2 ++ include/drm/drm_gem.h | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/drm_gem.c b/drivers/gpu/drm/drm_gem.c index 4a89b6acb6af39720451ac24033b89e144d282dc..8d25cc65707d5b44d931beb0207= c9d08a3e2de5a 100644 --- a/drivers/gpu/drm/drm_gem.c +++ b/drivers/gpu/drm/drm_gem.c @@ -187,6 +187,7 @@ void drm_gem_private_object_init(struct drm_device *dev, kref_init(&obj->refcount); obj->handle_count =3D 0; obj->size =3D size; + mutex_init(&obj->gpuva.lock); dma_resv_init(&obj->_resv); if (!obj->resv) obj->resv =3D &obj->_resv; @@ -210,6 +211,7 @@ void drm_gem_private_object_fini(struct drm_gem_object = *obj) WARN_ON(obj->dma_buf); =20 dma_resv_fini(&obj->_resv); + mutex_destroy(&obj->gpuva.lock); } EXPORT_SYMBOL(drm_gem_private_object_fini); =20 diff --git a/include/drm/drm_gem.h b/include/drm/drm_gem.h index d3a7b43e2c637b164eba5af7cc2fc8ef09d4f0a4..5934d8dc267a65aaf62d2d02586= 9221cd110b325 100644 --- a/include/drm/drm_gem.h +++ b/include/drm/drm_gem.h @@ -403,11 +403,13 @@ struct drm_gem_object { * Provides the list of GPU VAs attached to this GEM object. * * Drivers should lock list accesses with the GEMs &dma_resv lock - * (&drm_gem_object.resv) or a custom lock if one is provided. + * (&drm_gem_object.resv) or a custom lock if one is provided. The + * mutex inside this struct may be used as the custom lock. */ struct { struct list_head list; =20 + struct mutex lock; #ifdef CONFIG_LOCKDEP struct lockdep_map *lock_dep_map; #endif --=20 2.51.0.rc2.233.g662b1ed5c5-goog From nobody Fri Oct 3 23:02:52 2025 Received: from mail-ed1-f73.google.com (mail-ed1-f73.google.com [209.85.208.73]) (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 D0FBE2F4A13 for ; Fri, 22 Aug 2025 09:28:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755854933; cv=none; b=mMLq7YKlxdKTsAKrFm0yzL7J/gpZkv86AIHml0BbWoWW32oL6BuhRKSqIT8McV2RgMVwqxH2fTcRaotDYBj1xyo9JJzac20SpiWcaofrByokWlrSt34tHQEnRua0IGQ/j0UqdiFEYMs9Jeji0/DFY60TK3cgzOxggeu0rK5jglI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755854933; c=relaxed/simple; bh=PXzH6D27ejnFW1kfBtz8z7koA1/45HNd1QgE8a5IH60=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=KRTAU1967FxJW0NOEQ64BVWH9bPrARadRDAdUC6ildE9wVbUPBXpL01QW8WJCfwMSLXGPduMJkUXdH7SvLALu1GWEPD5I8Z2Wa4bRFUvVzRSPZmyAHm3LoAbDKbbGo7+cmT8kLCTt6/dcMZihcH3dAfNj6NGxYRP3TDUM8vn7sg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--aliceryhl.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=spy5cHP5; arc=none smtp.client-ip=209.85.208.73 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--aliceryhl.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="spy5cHP5" Received: by mail-ed1-f73.google.com with SMTP id 4fb4d7f45d1cf-6188b5b20efso1634110a12.0 for ; Fri, 22 Aug 2025 02:28:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1755854930; x=1756459730; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=e+7jovikICPfeDBh9+sigj3WevDGgGN+HdnZFDA9m7c=; b=spy5cHP5P5KBANNvhzeAyuk4I+ZYxFl4PjfLR3KqYTok8x6l9aPH5NMLsr2dL19uH0 Czex0p3yhsnM/WnDerkxyU7bQNVRNGqg5llg/YWi9O4m1sJaX27HeXk4ciBxuAD8lf95 kMOr0VRhtWVYpleps/2b+5h9aFMYajRV4gOacU46yqnWzOcoVLzyx7tDIN7sH3bSNaDE mObHxua7CWqjCJtLSeEq87jaLourXY0S+e2VMnWm87qyWPaKqgkcUfdkYxgY+TH9lvwl fPSURrXlCV64JLl/8L8CMUbVdfVZ1aV4f7vtesBRNLkxJzMaUQwaQ+ELmRHSIiBjrwKl aKPA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1755854930; x=1756459730; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=e+7jovikICPfeDBh9+sigj3WevDGgGN+HdnZFDA9m7c=; b=kvWKoDq3Deu6DTMG6VGDuHN58UcHnTsObWwP2e4wLOAe6CAwhxj1LGmvprTSfnGSF4 evnw/c2mTbHkXv1xbUNmhLKhqG/Gb3DCrB/sXfwI1Ltc0ST7m+81W3jWxbxP1M9/a2BR TVKdsuVr1i1lVKBsUQZyN13XM/b0/brDsO+juz8CJjXGFh0rSH/EHFGeB+LdfY2ywh5w k3DTtPqMPr2Oruc5k4cKNV9l7KwNwOu4EeOmszHt4D55PQsNkRo94MHmB6ibs0Oc8fJk F0N+dEgB8s0F5mWVjJd26gJc+1OC+aGEQ4EDJwgtructndTHB/eJgpO988PJ42CYytqo OGYQ== X-Forwarded-Encrypted: i=1; AJvYcCUnaR5vHdscXCmwF8Z9J7/aQFZkSw8MGC5EPtHjZHuY8oBC1/PTX5POq6L6jAeqkCteUlRk2ZeZ3uh8A/w=@vger.kernel.org X-Gm-Message-State: AOJu0YzhupnHDOfY9eGxzJAV83myog02r6xmi5Tmx3KAq2MjX0rGHBgZ x1C5xe+dqrGrCZtd9qpJ0LNKEnU3MCIc89KdL/soq+gBF8eWrpm9eIKbW+U5lOMRonoVKLkOMMn vz/GmRf2B3HQxmjLHng== X-Google-Smtp-Source: AGHT+IE81vOe3lF3Q9HAiE1tAlqMVP84gxQgFX6xDbenk+VWIFgDGNBFMwKCHBju2vp5v0tvD1PRFr8A05p7R1A= X-Received: from edo22.prod.google.com ([2002:a05:6402:52d6:b0:617:9713:6b2c]) (user=aliceryhl job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6402:27c7:b0:617:b4ce:9d48 with SMTP id 4fb4d7f45d1cf-61c1b708c8amr1890750a12.26.1755854930000; Fri, 22 Aug 2025 02:28:50 -0700 (PDT) Date: Fri, 22 Aug 2025 09:28:25 +0000 In-Reply-To: <20250822-gpuva-mutex-in-gem-v2-0-c41a10d1d3b9@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250822-gpuva-mutex-in-gem-v2-0-c41a10d1d3b9@google.com> X-Developer-Key: i=aliceryhl@google.com; a=openpgp; fpr=49F6C1FAA74960F43A5B86A1EE7A392FDE96209F X-Developer-Signature: v=1; a=openpgp-sha256; l=4671; i=aliceryhl@google.com; h=from:subject:message-id; bh=PXzH6D27ejnFW1kfBtz8z7koA1/45HNd1QgE8a5IH60=; b=owEBbQKS/ZANAwAKAQRYvu5YxjlGAcsmYgBoqDhNFkdUCFnLCzTxX9L1OCDaI309mAZ5aNQku U139j2Nfe2JAjMEAAEKAB0WIQSDkqKUTWQHCvFIvbIEWL7uWMY5RgUCaKg4TQAKCRAEWL7uWMY5 RgsNEACi3Y6feRIY6sBuKb23tinwq23L8T+85OmKG7u2LpgibYo6zXf6cZAkNCedH+eTv8OtlM/ UvY+RcQNvuD+7H1g1FIP1OEP7PSS7j/DXvkyHoTM7Z6yAdEQ1z8oMsm2SUHSS+/7K5X38PQ8Q0G HrLQKdbgsKBQPrT7/S7TjZl1WMX5+ZbynZXzewuwX7ceyVdMrWKDzqr3CohBPWv74i1sC1rKcR8 VmjEWJ34BXDlqqBdwOArqb6gjq+ssFz6YMI3X0Wtc0lzXNhS0mNWG5E+JGod06Cf+dAfF09DL8q 7XcfDO2n3xDQQvhfPGtO/+mb2liLFFAPmsYzWKOtQhx921pQ/kP13KfRw1vujIB14kVYDluj/e7 2eHwR9puo4BYOozLSSxNL8xnnivse/4G8NWATIBYSIB8nt2Qxkyc7zdIS4QPes08NUcKnUIqIW6 0P7rJLzEOYMVs0ouQUI1m4R+4kguLNxen/rmAxXASIYKjhcGbA7NaaMVYWKvcbtESmAic/vInzq C7Rv6daJSKKA4yQs0Kbs1Hekxfuny0Ni/Bnh8IyDsVEzQCEe9GjNgSEa91iJNT7IQEE0yAg0JuJ APJv4fwGP3NSqB7Y+YbLgS1i0t4uEoXlaCmDLa+EZCC9pMKckt36wZ6YyIgE+Rlr0RXmxSZh9FS l7g8Fk1KYpNbA/g== X-Mailer: b4 0.14.2 Message-ID: <20250822-gpuva-mutex-in-gem-v2-2-c41a10d1d3b9@google.com> Subject: [PATCH v2 2/3] panthor: use drm_gem_object.gpuva.lock instead of gpuva_list_lock From: Alice Ryhl To: Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter , Danilo Krummrich , Boris Brezillon , Daniel Almeida , Steven Price , Liviu Dudau , Rob Clark , Rob Herring Cc: Miguel Ojeda , Boqun Feng , Gary Guo , "=?utf-8?q?Bj=C3=B6rn_Roy_Baron?=" , Benno Lossin , Andreas Hindborg , Trevor Gross , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org, Alice Ryhl Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Now that drm_gem_object has a dedicated mutex for the gpuva list that is intended to be used in cases that must be fence signalling safe, use it in Panthor. Reviewed-by: Boris Brezillon Signed-off-by: Alice Ryhl --- drivers/gpu/drm/panthor/panthor_gem.c | 4 +--- drivers/gpu/drm/panthor/panthor_gem.h | 12 ------------ drivers/gpu/drm/panthor/panthor_mmu.c | 16 ++++++++-------- 3 files changed, 9 insertions(+), 23 deletions(-) diff --git a/drivers/gpu/drm/panthor/panthor_gem.c b/drivers/gpu/drm/pantho= r/panthor_gem.c index a123bc740ba1460f96882206f598b148b64dc5f6..c654a3377903cf7e067becdb481= fb14895a4eaa5 100644 --- a/drivers/gpu/drm/panthor/panthor_gem.c +++ b/drivers/gpu/drm/panthor/panthor_gem.c @@ -74,7 +74,6 @@ static void panthor_gem_free_object(struct drm_gem_object= *obj) mutex_destroy(&bo->label.lock); =20 drm_gem_free_mmap_offset(&bo->base.base); - mutex_destroy(&bo->gpuva_list_lock); drm_gem_shmem_free(&bo->base); drm_gem_object_put(vm_root_gem); } @@ -246,8 +245,7 @@ struct drm_gem_object *panthor_gem_create_object(struct= drm_device *ddev, size_t =20 obj->base.base.funcs =3D &panthor_gem_funcs; obj->base.map_wc =3D !ptdev->coherent; - mutex_init(&obj->gpuva_list_lock); - drm_gem_gpuva_set_lock(&obj->base.base, &obj->gpuva_list_lock); + drm_gem_gpuva_set_lock(&obj->base.base, &obj->base.base.gpuva.lock); mutex_init(&obj->label.lock); =20 panthor_gem_debugfs_bo_init(obj); diff --git a/drivers/gpu/drm/panthor/panthor_gem.h b/drivers/gpu/drm/pantho= r/panthor_gem.h index 8fc7215e9b900ed162e03aebeae999fda00eeb7a..80c6e24112d0bd0f1561ae4d222= 4842afb735a59 100644 --- a/drivers/gpu/drm/panthor/panthor_gem.h +++ b/drivers/gpu/drm/panthor/panthor_gem.h @@ -79,18 +79,6 @@ struct panthor_gem_object { */ struct drm_gem_object *exclusive_vm_root_gem; =20 - /** - * @gpuva_list_lock: Custom GPUVA lock. - * - * Used to protect insertion of drm_gpuva elements to the - * drm_gem_object.gpuva.list list. - * - * We can't use the GEM resv for that, because drm_gpuva_link() is - * called in a dma-signaling path, where we're not allowed to take - * resv locks. - */ - struct mutex gpuva_list_lock; - /** @flags: Combination of drm_panthor_bo_flags flags. */ u32 flags; =20 diff --git a/drivers/gpu/drm/panthor/panthor_mmu.c b/drivers/gpu/drm/pantho= r/panthor_mmu.c index 2003b91a84097d419484c284c2d6241a82b5cde2..2881942ab5115686803fb9d9036= bc059d56b7fa3 100644 --- a/drivers/gpu/drm/panthor/panthor_mmu.c +++ b/drivers/gpu/drm/panthor/panthor_mmu.c @@ -1107,9 +1107,9 @@ static void panthor_vm_bo_put(struct drm_gpuvm_bo *vm= _bo) * GEM vm_bo list. */ dma_resv_lock(drm_gpuvm_resv(vm), NULL); - mutex_lock(&bo->gpuva_list_lock); + mutex_lock(&bo->base.base.gpuva.lock); unpin =3D drm_gpuvm_bo_put(vm_bo); - mutex_unlock(&bo->gpuva_list_lock); + mutex_unlock(&bo->base.base.gpuva.lock); dma_resv_unlock(drm_gpuvm_resv(vm)); =20 /* If the vm_bo object was destroyed, release the pin reference that @@ -1282,9 +1282,9 @@ static int panthor_vm_prepare_map_op_ctx(struct panth= or_vm_op_ctx *op_ctx, * calling this function. */ dma_resv_lock(panthor_vm_resv(vm), NULL); - mutex_lock(&bo->gpuva_list_lock); + mutex_lock(&bo->base.base.gpuva.lock); op_ctx->map.vm_bo =3D drm_gpuvm_bo_obtain_prealloc(preallocated_vm_bo); - mutex_unlock(&bo->gpuva_list_lock); + mutex_unlock(&bo->base.base.gpuva.lock); dma_resv_unlock(panthor_vm_resv(vm)); =20 /* If the a vm_bo for this combination exists, it already @@ -2036,10 +2036,10 @@ static void panthor_vma_link(struct panthor_vm *vm, { struct panthor_gem_object *bo =3D to_panthor_bo(vma->base.gem.obj); =20 - mutex_lock(&bo->gpuva_list_lock); + mutex_lock(&bo->base.base.gpuva.lock); drm_gpuva_link(&vma->base, vm_bo); drm_WARN_ON(&vm->ptdev->base, drm_gpuvm_bo_put(vm_bo)); - mutex_unlock(&bo->gpuva_list_lock); + mutex_unlock(&bo->base.base.gpuva.lock); } =20 static void panthor_vma_unlink(struct panthor_vm *vm, @@ -2048,9 +2048,9 @@ static void panthor_vma_unlink(struct panthor_vm *vm, struct panthor_gem_object *bo =3D to_panthor_bo(vma->base.gem.obj); struct drm_gpuvm_bo *vm_bo =3D drm_gpuvm_bo_get(vma->base.vm_bo); =20 - mutex_lock(&bo->gpuva_list_lock); + mutex_lock(&bo->base.base.gpuva.lock); drm_gpuva_unlink(&vma->base); - mutex_unlock(&bo->gpuva_list_lock); + mutex_unlock(&bo->base.base.gpuva.lock); =20 /* drm_gpuva_unlink() release the vm_bo, but we manually retained it * when entering this function, so we can implement deferred VMA --=20 2.51.0.rc2.233.g662b1ed5c5-goog From nobody Fri Oct 3 23:02:52 2025 Received: from mail-wm1-f73.google.com (mail-wm1-f73.google.com [209.85.128.73]) (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 F19CA2F5320 for ; Fri, 22 Aug 2025 09:28:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755854936; cv=none; b=Y8ofzu23uxOPLAq/DBKzI2n6IZHZxQOllGH5Q9a3R62nRXWyeDLMiELxiqW4B1Klvd6XkgJKy1chY59Kt4+D9UZXMAiyMpmeTEC2ioFvUl5Hofya9+x8QU+UI+pf0phw7TUKo7SiqbvUGTuO3EHZnMP42seM2JGZzwix+gFQESg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755854936; c=relaxed/simple; bh=k9/xP2hkYInqqac45oA3gCzuPA512fZCIHyvxtWcpMg=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=DBxQDcLzvOB46sfQGnQZE1UmTWYOv0e4BBYKHw8iBkh0cefRHzbFCuudeTBdXu1OUNe0oyt3a04232W0+n/tjZtK+Tq0IsALDjSpKeduHJ8Oirjo0BkK8gcUYtPBjAZK+EKelRanCdtk4/PO/Xaq+mUuM4m9JQp91LDfWTE4cq4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--aliceryhl.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=rocDaoLG; arc=none smtp.client-ip=209.85.128.73 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--aliceryhl.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="rocDaoLG" Received: by mail-wm1-f73.google.com with SMTP id 5b1f17b1804b1-45a1ba17bbcso9816105e9.0 for ; Fri, 22 Aug 2025 02:28:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1755854931; x=1756459731; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=2Ow6XvHySGVB+W2kkd4+T1fvI3S18fIKSk8k0aXDVNI=; b=rocDaoLGg4w6MEC0kAzihMVq8zutH7wlGcpJKH2AG1WCuV56dqi1WZYABMP9C5pHFE dMiRvPPTlU4YmELay9dA8Zlb4TDHrJzhbvCxlJkFiBMz6JP4xPKUhVbK0OME0/b/Quut YU7ExiffmD9xHnZ+XPFy66KG6vBhwjLjFHOvKm7lAILsOy0Mxa/q1IqfDrhFj0YoTNY4 4WonJeakbGVfuyjWgyQJcV1281YtA2UWWqeP5AXcnVJk/2Rvmcy2iKittGmq3aZeX9ce 7TxrDA7M0KjVYLiQGGQK2gDPwZrVmPhzxcAxJU6DlMTPQhAbX36ScbLWsSQmZ8Xr891t Mtgg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1755854931; x=1756459731; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=2Ow6XvHySGVB+W2kkd4+T1fvI3S18fIKSk8k0aXDVNI=; b=qICOaDBnUdH6BZ80u1dOYwMcWUvdl5FRvIHdNQxQ/L30rgOxu4V7BjizFmWmddpqhI aNZv7w7QaN4jyhOtjlMgt4ah3cWoU9w58Fp+V16mz3p8B3LJ05TVGFdXZQbpFQXIrEmS SswPj0jkdG5svh7QWH3LkZTAoqNoBdCQTIH9FO3nhagMGfZNYVXeBeAblKx2ELLn261a eQxReLfb8IkOQEhtFB9WpNDzzeyiFf6cHd+ODCDuK7SjknB5D8UNhu+nydVAhnXyIMKs jcc47ClXSeTk/wxJTketjI+OozTvI5xcg4vN161JB76Rwat7dbsxrfApGcaZ55TwKtxK 0OKg== X-Forwarded-Encrypted: i=1; AJvYcCX7fLyiIApP2Av4DqpUM4LijU8lGE3eQhugqUcnrrP9J5XYptCf2RXOc55jXtEDAFQdU18gBqq4+cwS+pM=@vger.kernel.org X-Gm-Message-State: AOJu0Yyo/HU1DLYuiVmAHFeaNSXKwIKxH62Ut5/PZg6e9BSXzRri36vt 6DDGD9wliBrZnLqqncCP2h0JN51cbP0leRkLVbAxPSC8VB8nocPJoBGQNND3Z5DlHW+GiK6LurZ 2Lb48MaEp0yec+xL5Sg== X-Google-Smtp-Source: AGHT+IF8c3P0Z1vVWG+q1H8oB/tl+UK9nbE+C7bMQrs2JLINSn9yU5stP/o7VIvQ7k/31mTwRHsWj+ndEZHzbog= X-Received: from wmbfp14.prod.google.com ([2002:a05:600c:698e:b0:459:dd85:efda]) (user=aliceryhl job=prod-delivery.src-stubby-dispatcher) by 2002:a05:600c:46cb:b0:458:bf7c:f744 with SMTP id 5b1f17b1804b1-45b517c2d5fmr15962175e9.32.1755854931287; Fri, 22 Aug 2025 02:28:51 -0700 (PDT) Date: Fri, 22 Aug 2025 09:28:26 +0000 In-Reply-To: <20250822-gpuva-mutex-in-gem-v2-0-c41a10d1d3b9@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250822-gpuva-mutex-in-gem-v2-0-c41a10d1d3b9@google.com> X-Developer-Key: i=aliceryhl@google.com; a=openpgp; fpr=49F6C1FAA74960F43A5B86A1EE7A392FDE96209F X-Developer-Signature: v=1; a=openpgp-sha256; l=11713; i=aliceryhl@google.com; h=from:subject:message-id; bh=k9/xP2hkYInqqac45oA3gCzuPA512fZCIHyvxtWcpMg=; b=owEBbQKS/ZANAwAKAQRYvu5YxjlGAcsmYgBoqDhOQQ087NxYuUsEEHxVqXjk/V0HkIsZnfuwq OpQGacdCY2JAjMEAAEKAB0WIQSDkqKUTWQHCvFIvbIEWL7uWMY5RgUCaKg4TgAKCRAEWL7uWMY5 Rkh1EACbdGSW+CooCJs/PhJwX0poaGeozdfxI18YoRFDYpQ24dqxZ5tp818A8OpttybLAT1/xto gxrudf7pULaUyz2tyAeny8BWOuwL5u4g2zwrEJtMu3L9+jKoS2nbzLe9QuL3uUuW/NH0ibvxR22 Sxl8QnTJiJKoQE8EMituIZxAdNo/QzTWRavUtyvcN7KWZ8chRhz+NVvBpJwJKsWmOWH5vaqZBxU XZsUXR8vPGkJZBA2e9XDgxPpX3qWsTcGFXhRLpzz0LneulEX52MCUrxqvxD+A1133XKddm081me yGN85EA4HJ5psOPm5SQhmqhEu4Yrw5J5FJLy/SQpMGQ4q9EdOXOyioISu1bvvlvDIEJ1uophX4Q FdpaNhiQyQjCn7eej8N2HrlxQtmn+XUbLn7fmmmeE9Mo7k1OfSLu8i4tIyTyaXW8LM76xb84TaN n2iIeRU1pIOWE+IvoDqfxx1AXeLufMRnfGYPskc4kTSFBmMNGf4/n5QdIQb7to9Oabsk8jKFOkb 2H9MKo7UnjFG2K6SANiT493HJceFM/Jv8h2YQUH86o2wWds6frpG+a/yjuaFaWYIcYFRe1BYj30 RLSaPMoiSuOwrZnkD0CH2eq2b+LOaDWSC+K48q9pUZIWVGZQE2M7Qdf1HSiVnfc3oskTwQxyx89 dkLbygBbPlgWnpw== X-Mailer: b4 0.14.2 Message-ID: <20250822-gpuva-mutex-in-gem-v2-3-c41a10d1d3b9@google.com> Subject: [PATCH v2 3/3] gpuvm: remove gem.gpuva.lock_dep_map From: Alice Ryhl To: Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter , Danilo Krummrich , Boris Brezillon , Daniel Almeida , Steven Price , Liviu Dudau , Rob Clark , Rob Herring Cc: Miguel Ojeda , Boqun Feng , Gary Guo , "=?utf-8?q?Bj=C3=B6rn_Roy_Baron?=" , Benno Lossin , Andreas Hindborg , Trevor Gross , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org, Alice Ryhl Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Since all users of gem.gpuva.lock_dep_map now rely on the mutex directly in gpuva, we may remove it. Whether the mutex is used is now tracked by a flag in gpuvm rather than by whether lock_dep_map is null. Note that a GEM object may not be pushed to multiple gpuvms that disagree on the value of this new flag. But that's okay because a single driver should use the same locking scheme everywhere, and a GEM object is driver specific (when a GEM is exported with prime, a new GEM object instance is created from the backing dma-buf). The flag is present even with CONFIG_LOCKDEP=3Dn because the intent is that the flag will also cause vm_bo cleanup to become deferred. However, that will happen in a follow-up patch. Signed-off-by: Alice Ryhl Reviewed-by: Boris Brezillon --- drivers/gpu/drm/drm_gpuvm.c | 30 +++++++++++++-------------- drivers/gpu/drm/panthor/panthor_gem.c | 1 - drivers/gpu/drm/panthor/panthor_mmu.c | 5 +++-- include/drm/drm_gem.h | 39 ++++++++++++++-----------------= ---- include/drm/drm_gpuvm.h | 30 ++++++++++++++++++++++++--- 5 files changed, 59 insertions(+), 46 deletions(-) diff --git a/drivers/gpu/drm/drm_gpuvm.c b/drivers/gpu/drm/drm_gpuvm.c index d6bea8a4fffd7613fb9b9ed5c795df373da2e7b6..78a1a4f095095e9379bdf604d58= 3f6c8b9863ccb 100644 --- a/drivers/gpu/drm/drm_gpuvm.c +++ b/drivers/gpu/drm/drm_gpuvm.c @@ -497,8 +497,7 @@ * DRM GPUVM also does not take care of the locking of the backing * &drm_gem_object buffers GPU VA lists and &drm_gpuvm_bo abstractions by * itself; drivers are responsible to enforce mutual exclusion using eithe= r the - * GEMs dma_resv lock or alternatively a driver specific external lock. Fo= r the - * latter see also drm_gem_gpuva_set_lock(). + * GEMs dma_resv lock or the GEMs gpuva.lock mutex. * * However, DRM GPUVM contains lockdep checks to ensure callers of its API= hold * the corresponding lock whenever the &drm_gem_objects GPU VA list is acc= essed @@ -1582,7 +1581,7 @@ drm_gpuvm_bo_destroy(struct kref *kref) drm_gpuvm_bo_list_del(vm_bo, extobj, lock); drm_gpuvm_bo_list_del(vm_bo, evict, lock); =20 - drm_gem_gpuva_assert_lock_held(obj); + drm_gem_gpuva_assert_lock_held(gpuvm, obj); list_del(&vm_bo->list.entry.gem); =20 if (ops && ops->vm_bo_free) @@ -1603,7 +1602,8 @@ drm_gpuvm_bo_destroy(struct kref *kref) * If the reference count drops to zero, the &gpuvm_bo is destroyed, which * includes removing it from the GEMs gpuva list. Hence, if a call to this * function can potentially let the reference count drop to zero the calle= r must - * hold the dma-resv or driver specific GEM gpuva lock. + * hold the lock that the GEM uses for its gpuva list (either the GEM's + * dma-resv or gpuva.lock mutex). * * This function may only be called from non-atomic context. * @@ -1627,7 +1627,7 @@ __drm_gpuvm_bo_find(struct drm_gpuvm *gpuvm, { struct drm_gpuvm_bo *vm_bo; =20 - drm_gem_gpuva_assert_lock_held(obj); + drm_gem_gpuva_assert_lock_held(gpuvm, obj); drm_gem_for_each_gpuvm_bo(vm_bo, obj) if (vm_bo->vm =3D=3D gpuvm) return vm_bo; @@ -1686,7 +1686,7 @@ drm_gpuvm_bo_obtain(struct drm_gpuvm *gpuvm, if (!vm_bo) return ERR_PTR(-ENOMEM); =20 - drm_gem_gpuva_assert_lock_held(obj); + drm_gem_gpuva_assert_lock_held(gpuvm, obj); list_add_tail(&vm_bo->list.entry.gem, &obj->gpuva.list); =20 return vm_bo; @@ -1722,7 +1722,7 @@ drm_gpuvm_bo_obtain_prealloc(struct drm_gpuvm_bo *__v= m_bo) return vm_bo; } =20 - drm_gem_gpuva_assert_lock_held(obj); + drm_gem_gpuva_assert_lock_held(gpuvm, obj); list_add_tail(&__vm_bo->list.entry.gem, &obj->gpuva.list); =20 return __vm_bo; @@ -1894,8 +1894,7 @@ EXPORT_SYMBOL_GPL(drm_gpuva_remove); * reference of the latter is taken. * * This function expects the caller to protect the GEM's GPUVA list against - * concurrent access using either the GEMs dma_resv lock or a driver speci= fic - * lock set through drm_gem_gpuva_set_lock(). + * concurrent access using either the GEM's dma-resv or gpuva.lock mutex. */ void drm_gpuva_link(struct drm_gpuva *va, struct drm_gpuvm_bo *vm_bo) @@ -1910,7 +1909,7 @@ drm_gpuva_link(struct drm_gpuva *va, struct drm_gpuvm= _bo *vm_bo) =20 va->vm_bo =3D drm_gpuvm_bo_get(vm_bo); =20 - drm_gem_gpuva_assert_lock_held(obj); + drm_gem_gpuva_assert_lock_held(gpuvm, obj); list_add_tail(&va->gem.entry, &vm_bo->list.gpuva); } EXPORT_SYMBOL_GPL(drm_gpuva_link); @@ -1930,8 +1929,7 @@ EXPORT_SYMBOL_GPL(drm_gpuva_link); * the latter is dropped. * * This function expects the caller to protect the GEM's GPUVA list against - * concurrent access using either the GEMs dma_resv lock or a driver speci= fic - * lock set through drm_gem_gpuva_set_lock(). + * concurrent access using either the GEM's dma-resv or gpuva.lock mutex. */ void drm_gpuva_unlink(struct drm_gpuva *va) @@ -1942,7 +1940,7 @@ drm_gpuva_unlink(struct drm_gpuva *va) if (unlikely(!obj)) return; =20 - drm_gem_gpuva_assert_lock_held(obj); + drm_gem_gpuva_assert_lock_held(va->vm, obj); list_del_init(&va->gem.entry); =20 va->vm_bo =3D NULL; @@ -2943,8 +2941,8 @@ EXPORT_SYMBOL_GPL(drm_gpuvm_prefetch_ops_create); * After the caller finished processing the returned &drm_gpuva_ops, they = must * be freed with &drm_gpuva_ops_free. * - * It is the callers responsibility to protect the GEMs GPUVA list against - * concurrent access using the GEMs dma_resv lock. + * This function expects the caller to protect the GEM's GPUVA list against + * concurrent access using either the GEM's dma-resv or gpuva.lock mutex. * * Returns: a pointer to the &drm_gpuva_ops on success, an ERR_PTR on fail= ure */ @@ -2956,7 +2954,7 @@ drm_gpuvm_bo_unmap_ops_create(struct drm_gpuvm_bo *vm= _bo) struct drm_gpuva *va; int ret; =20 - drm_gem_gpuva_assert_lock_held(vm_bo->obj); + drm_gem_gpuva_assert_lock_held(vm_bo->vm, vm_bo->obj); =20 ops =3D kzalloc(sizeof(*ops), GFP_KERNEL); if (!ops) diff --git a/drivers/gpu/drm/panthor/panthor_gem.c b/drivers/gpu/drm/pantho= r/panthor_gem.c index c654a3377903cf7e067becdb481fb14895a4eaa5..156c7a0b62a231219645095d601= 2a5b108130bbc 100644 --- a/drivers/gpu/drm/panthor/panthor_gem.c +++ b/drivers/gpu/drm/panthor/panthor_gem.c @@ -245,7 +245,6 @@ struct drm_gem_object *panthor_gem_create_object(struct= drm_device *ddev, size_t =20 obj->base.base.funcs =3D &panthor_gem_funcs; obj->base.map_wc =3D !ptdev->coherent; - drm_gem_gpuva_set_lock(&obj->base.base, &obj->base.base.gpuva.lock); mutex_init(&obj->label.lock); =20 panthor_gem_debugfs_bo_init(obj); diff --git a/drivers/gpu/drm/panthor/panthor_mmu.c b/drivers/gpu/drm/pantho= r/panthor_mmu.c index 2881942ab5115686803fb9d9036bc059d56b7fa3..ee9e94448b76ffd31a97d82a857= fa925c4cf0cb5 100644 --- a/drivers/gpu/drm/panthor/panthor_mmu.c +++ b/drivers/gpu/drm/panthor/panthor_mmu.c @@ -2420,8 +2420,9 @@ panthor_vm_create(struct panthor_device *ptdev, bool = for_mcu, * to be handled the same way user VMAs are. */ drm_gpuvm_init(&vm->base, for_mcu ? "panthor-MCU-VM" : "panthor-GPU-VM", - DRM_GPUVM_RESV_PROTECTED, &ptdev->base, dummy_gem, - min_va, va_range, 0, 0, &panthor_gpuvm_ops); + DRM_GPUVM_RESV_PROTECTED | DRM_GPUVM_IMMEDIATE_MODE, + &ptdev->base, dummy_gem, min_va, va_range, 0, 0, + &panthor_gpuvm_ops); drm_gem_object_put(dummy_gem); return vm; =20 diff --git a/include/drm/drm_gem.h b/include/drm/drm_gem.h index 5934d8dc267a65aaf62d2d025869221cd110b325..85a25bbb387c4590678e4ba243b= 51acd94b008ed 100644 --- a/include/drm/drm_gem.h +++ b/include/drm/drm_gem.h @@ -402,17 +402,22 @@ struct drm_gem_object { * * Provides the list of GPU VAs attached to this GEM object. * - * Drivers should lock list accesses with the GEMs &dma_resv lock - * (&drm_gem_object.resv) or a custom lock if one is provided. The - * mutex inside this struct may be used as the custom lock. + * When DRM_GPUVM_IMMEDIATE_MODE is set, this list is protected by the + * mutex. Otherwise, the list is protected by the GEMs &dma_resv lock. + * + * Note that all entries in this list must agree on whether + * DRM_GPUVM_IMMEDIATE_MODE is set. */ struct { struct list_head list; =20 + /** + * @gpuva.lock: Only used when DRM_GPUVM_IMMEDIATE_MODE is set. + * It should be safe to take this mutex during the fence + * signalling path, so do not allocate memory while holding + * this lock. + */ struct mutex lock; -#ifdef CONFIG_LOCKDEP - struct lockdep_map *lock_dep_map; -#endif } gpuva; =20 /** @@ -597,26 +602,12 @@ static inline bool drm_gem_is_imported(const struct d= rm_gem_object *obj) } =20 #ifdef CONFIG_LOCKDEP -/** - * drm_gem_gpuva_set_lock() - Set the lock protecting accesses to the gpuv= a list. - * @obj: the &drm_gem_object - * @lock: the lock used to protect the gpuva list. The locking primitive - * must contain a dep_map field. - * - * Call this if you're not proctecting access to the gpuva list with the - * dma-resv lock, but with a custom lock. - */ -#define drm_gem_gpuva_set_lock(obj, lock) \ - if (!WARN((obj)->gpuva.lock_dep_map, \ - "GEM GPUVA lock should be set only once.")) \ - (obj)->gpuva.lock_dep_map =3D &(lock)->dep_map -#define drm_gem_gpuva_assert_lock_held(obj) \ - lockdep_assert((obj)->gpuva.lock_dep_map ? \ - lock_is_held((obj)->gpuva.lock_dep_map) : \ +#define drm_gem_gpuva_assert_lock_held(gpuvm, obj) \ + lockdep_assert(drm_gpuvm_immediate_mode(gpuvm) ? \ + lock_is_held(&(obj)->gpuva.lock.dep_map) : \ dma_resv_held((obj)->resv)) #else -#define drm_gem_gpuva_set_lock(obj, lock) do {} while (0) -#define drm_gem_gpuva_assert_lock_held(obj) do {} while (0) +#define drm_gem_gpuva_assert_lock_held(gpuvm, obj) do {} while (0) #endif =20 /** diff --git a/include/drm/drm_gpuvm.h b/include/drm/drm_gpuvm.h index 4a22b9d848f7b3d5710ca554f5b01556abf95985..598ba376b9430cdd4ab7bacdc15= de031a887cf71 100644 --- a/include/drm/drm_gpuvm.h +++ b/include/drm/drm_gpuvm.h @@ -196,10 +196,20 @@ enum drm_gpuvm_flags { */ DRM_GPUVM_RESV_PROTECTED =3D BIT(0), =20 + /** + * @DRM_GPUVM_IMMEDIATE_MODE: use the locking scheme that makes it safe + * to modify the GPUVM during the fence signalling path + * + * When set, gpuva.lock is used to protect gpuva.list in all GEM + * objects associated with this GPUVM. Otherwise, the GEMs dma-resv is + * used. + */ + DRM_GPUVM_IMMEDIATE_MODE =3D BIT(1), + /** * @DRM_GPUVM_USERBITS: user defined bits */ - DRM_GPUVM_USERBITS =3D BIT(1), + DRM_GPUVM_USERBITS =3D BIT(2), }; =20 /** @@ -369,6 +379,19 @@ drm_gpuvm_resv_protected(struct drm_gpuvm *gpuvm) return gpuvm->flags & DRM_GPUVM_RESV_PROTECTED; } =20 +/** + * drm_gpuvm_immediate_mode() - indicates whether &DRM_GPUVM_IMMEDIATE_MOD= E is + * set + * @gpuvm: the &drm_gpuvm + * + * Returns: true if &DRM_GPUVM_IMMEDIATE_MODE is set, false otherwise. + */ +static inline bool +drm_gpuvm_immediate_mode(struct drm_gpuvm *gpuvm) +{ + return gpuvm->flags & DRM_GPUVM_IMMEDIATE_MODE; +} + /** * drm_gpuvm_resv() - returns the &drm_gpuvm's &dma_resv * @gpuvm__: the &drm_gpuvm @@ -742,9 +765,10 @@ drm_gpuvm_bo_gem_evict(struct drm_gem_object *obj, boo= l evict) { struct drm_gpuvm_bo *vm_bo; =20 - drm_gem_gpuva_assert_lock_held(obj); - drm_gem_for_each_gpuvm_bo(vm_bo, obj) + drm_gem_for_each_gpuvm_bo(vm_bo, obj) { + drm_gem_gpuva_assert_lock_held(vm_bo->vm, obj); drm_gpuvm_bo_evict(vm_bo, evict); + } } =20 void drm_gpuvm_bo_extobj_add(struct drm_gpuvm_bo *vm_bo); --=20 2.51.0.rc2.233.g662b1ed5c5-goog