From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pg1-f171.google.com (mail-pg1-f171.google.com [209.85.215.171]) (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 3815042B73B for ; Mon, 27 Jul 2026 21:14:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.171 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785186866; cv=none; b=igT0vEXmtek5Co5Btrfas4uxIXMh58KQyfq/6xfrSBBZQH/BA3Vy0nAuj8P/Z2dmarJe0P2Hi/7/pd0KraV45d7nmMU5r+pFSgdh/OxhHraBj7XjuUlpi+Y/9mWrZ3LuCU2JyLfDufSZQM7bbxFASyVb7aoozcStGKVGnjQvCp8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785186866; c=relaxed/simple; bh=5V7f0e2Wd/GYysaBOb5U+e7W5ITzR3ZvWTTFgT0mY5s=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=FzPeV2lTokAoHz3aHSEICkiQI7CCSFunr0abHAJHD7sFIhydU+aR5jo9k3p13nfKXaosnql1CmzaBCp1i0iSvw00fk0gTUeVglLLY+nw/fX9/9H6h/u/DqkpDwEysxXcAwriFxBYVlktp/JVJPUca2rT+4aa2hsypHbYzcZwitk= ARC-Authentication-Results:i=1; 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=dgcWUXrV; arc=none smtp.client-ip=209.85.215.171 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="dgcWUXrV" Received: by mail-pg1-f171.google.com with SMTP id 41be03b00d2f7-c9b373d5af0so2314225a12.2 for ; Mon, 27 Jul 2026 14:14:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1785186864; x=1785791664; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=kjy5MK4aAcCv+w38WsNjg39N/6ew3Hf2N4qUhAbHfKM=; b=dgcWUXrVQUbXpmEpeC6CXbul8q0SUgDNI1RV3Fr0QhRxir3Qlknt42XV5WU3+YVgwP Kr9ev4BqoP9LFkDARCt6JLbUdly2qNws9l9dr37f+sGc9Hq08p8wgMH0VVASpHuYA2r9 Z5wBq2MHp5TDMacp/KiYUHl2zIMv6k8c/uJBurXKIPQ4cKQ6XvTII4NEP0EK8Ey7gLRk 4MYJPthFP1n4/xjRtHPA64ln2WjO0Jb7GFsX31IJz0AAynnLRmGleRURcbb/20ChQ3bY YmGxK2RLyih0GxuI+q/sOYCErh0HEcaBZeyXnc1+90LAANLQVdDRnETfCQzO3z4cNDDY saWQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785186864; x=1785791664; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=kjy5MK4aAcCv+w38WsNjg39N/6ew3Hf2N4qUhAbHfKM=; b=OCejRHxxth+nh2jaXp6AcHlyqYXWza+hp7KoyANM1QPx2jVi4l/iwacLRdXCaLRpBq jFF/HG+nsnVbTvQzFjzefp4ypns901V860n6VFePmo2Aw5O7VlQ73WFeFlqJXzkBVZp8 AVwkhgI1AjauSmECzoOU0vdRlKps1Nl8XEwIxIJUWIFzYt0oqfjJYX75fwgvHntx4iT+ Si4OBuCjymVktHZmKOQQ/LHwWaqvCOlkqFjCt8CmCq9O0mGTL7VSBI59BEOdCTg5PpSD QDVH/gFI6bz71M21xp8Za6PbxIk8PYAZOPvPg7ZGZXQgJE3MW9kKCEJpiZDJ27zmlz8u 1YqA== X-Forwarded-Encrypted: i=1; AHgh+RqtENmVxLCJC3XFYXPCBn6fs4ZT4SDPvdAPgr5mMbcAj+thmfRDoozAwWIcyxD5r31l4Hdq0wgpBp1rLNo=@vger.kernel.org X-Gm-Message-State: AOJu0YwJxpZRc56vTJDntP83WS5qNIdf93kTBD6QeywPQLRLlPoQlrzd PPfN29yUlnC2qfXMAYmACIq0FTzPc1j8KzaS5hGS8XsQhB1fQ+w+ypad X-Gm-Gg: AR+sD13bgluqo2arKYeHUL8sfeJSkNFZlSDShL1RXd1952QyDsDr/kb+ehDFeNyw308 P9QuuYVIj+5DyGEAG7khipmjtEsGxLDZoI5g/WoSTVGVsWcfB5hbTMyB7Gk52yQvkxAiu0mXaQa JMUYu4R2z9NWjcDSJN2m5B8ncyrtU0DuXtU1OghK/mw37rIPr86oN1hY2dPAgT4iC6yWNdJhCZm lO7222CexR8RIxb1Exoi2WnGKCwg0NzZEtAu4aohdpsXptzfkw/6R7su0mzxYdnu76I2wcmQsqW 7Q+wKrjaFOe0sx3x5BKdBPTHf2eiYVjxi2NQmPYsZuyVejwwRsTJgqv3O6ttZQ7O+kj9oBXWyjo XemnaOec2hu0G/pbAavSZZQDC6rkVj+XModX1yide81WeRSuc/6iJ598HBrJ/XIvypbUefWUiL7 ZMB4PRyBFS3iBnEaVCVTgzVpwlIZ3eDoR/y8M7GKflvC0YtFWcdKlO8w== X-Received: by 2002:a05:6a21:9d95:b0:3c0:9c19:65c2 with SMTP id adf61e73a8af0-3c67e0727f2mr8884194637.74.1785186864472; Mon, 27 Jul 2026 14:14:24 -0700 (PDT) Received: from archd ([2601:640:8c00:a:1544:c19e:8a1c:4058]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-314bc3e127asm58456645eec.2.2026.07.27.14.14.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Jul 2026 14:14:24 -0700 (PDT) From: Daniel Pesic To: Danilo Krummrich Cc: Matthew Brost , =?UTF-8?q?Thomas=20Hellstr=C3=B6m?= , Alice Ryhl , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter , Miguel Ojeda , Boqun Feng , Gary Guo , =?UTF-8?q?Bj=C3=B6rn=20Roy=20Baron?= , Benno Lossin , Andreas Hindborg , Trevor Gross , Daniel Almeida , Tamir Duberstein , Alexandre Courbot , =?UTF-8?q?Onur=20=C3=96zkan?= , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org, Daniel Pesic Subject: [PATCH 2/2] rust: drm: gpuvm: call drm_gpuvm_bo_destroy_not_in_lists() in Drop Date: Mon, 27 Jul 2026 07:11:21 -0700 Message-ID: <20260727141121.11975-3-danny.pesic@gmail.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260727141121.11975-1-danny.pesic@gmail.com> References: <20260727141121.11975-1-danny.pesic@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit GpuVmBoAlloc's type invariant guarantees a refcount of one and absence from the gem, extobj, and evict lists for as long as the value exists as itself. The only way to consume it is via obtain(), which moves it out via ManuallyDrop, so the invariant holds when Drop::drop runs. Since this is the required precondition for drm_gpuvm_bo_destroy_not_in_lists(), call it directly rather than going through the deferred put, and drop the TODO. The GEM's gpuva lock must not be held when this runs, since freeing the last reference to the GEM object would free the lock embedded in it. Drop::drop has a fixed safe signature, so this precondition cannot be enforced by the type system and is documented instead, matching the existing note on GpuVmBoAlloc::obtain(). It currently holds as lock_gpuva()'s two call sites, in sm_ops.rs, operate on a GpuVmBo that is already obtained and never construct or drop a GpuVmBoAlloc. Suggested-by: Alice Ryhl Signed-off-by: Daniel Pesic --- rust/kernel/drm/gpuvm/vm_bo.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/rust/kernel/drm/gpuvm/vm_bo.rs b/rust/kernel/drm/gpuvm/vm_bo.rs index a30f838c11b8..7c0f5846cf39 100644 --- a/rust/kernel/drm/gpuvm/vm_bo.rs +++ b/rust/kernel/drm/gpuvm/vm_bo.rs @@ -249,10 +249,14 @@ fn deref(&self) -> &GpuVmBo { } impl Drop for GpuVmBoAlloc { + /// Must not be dropped while holding the `drm_gem_object` gpuva lock. #[inline] fn drop(&mut self) { - // TODO: Call drm_gpuvm_bo_destroy_not_in_lists() directly. - // SAFETY: It's safe to perform a deferred put in any context. - unsafe { bindings::drm_gpuvm_bo_put_deferred(self.as_raw()) }; + // SAFETY: By the type invariant, `drm_gpuvm_bo` has a refcount + // of one and is absent from the gem, extobj, and evict lists. + // Per the precondition documented in impl, the caller does not + // hold the object's gpuva lock. Therefore, the preconditions of + // `drm_gpuvm_bo_destroy_not_in_lists()` are satisfied. + unsafe { bindings::drm_gpuvm_bo_destroy_not_in_lists(self.as_raw()) }; } } -- 2.55.0