From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6D00521A955 for ; Fri, 24 Jan 2025 18:15:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737742537; cv=none; b=K0xQ/bz2HhD7neLabbmUOmjOIa75xl45dm6pvFmSjefKsCag+30gXiWs4yoTaUeVGhlkOjAIpMM2o60QiNTaWq1jyZgoCLonUD/8t5z0GHZF4uc1VWg2DsFW/CXz3/p73jlDUK1KdI0mj2WPwgDqL8UiODwNc0xBG0RONcj1zAA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737742537; c=relaxed/simple; bh=D02XDcMSsOtveQCJfINbqCFi4Qc/jgciD+zijEATDu0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=utTatCjXk1gG45cdnrMRF9mccRjOOISf62rmflmZPE4IM87GAZYHWHdCDzA2W6OPgBA7BKF6Bj//bc6qIyZjPPG/3mWZrlEDkvWsejkhzsdSrAKqDXMEZP15H0xLo6U8wQzCgy5n/ZbgwdDJJ5QybgknXzIF+XUN2Y7YejoY/wc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=ApFTaihj; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="ApFTaihj" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1737742533; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=sH2n76/tf6JZeoIK8d2JObbHEPa7c6/XDsbabI03lVU=; b=ApFTaihj8ht39GsURA9tlxRA+pzjDXZPmKoRp2DifgApJjKpujorlJdK5q7xC/4xHkzXPs 0F1IPv6y7nINLi/BkbE2xkka8Ki7YcodjtAt1fVq7/q15twEGBAqKKgsQo4KhhiMaIGp1C Gu5V0ZFO+GduF/j/0R+ETduHHTGzhHI= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-615-vP8JfGp9OgGpAS_mGVVNdw-1; Fri, 24 Jan 2025 13:15:32 -0500 X-MC-Unique: vP8JfGp9OgGpAS_mGVVNdw-1 X-Mimecast-MFC-AGG-ID: vP8JfGp9OgGpAS_mGVVNdw Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-4361f371908so16496175e9.0 for ; Fri, 24 Jan 2025 10:15:31 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737742531; x=1738347331; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=sH2n76/tf6JZeoIK8d2JObbHEPa7c6/XDsbabI03lVU=; b=FVBk43o7XZxJztbKnef089gXIUVPlUC+eJ5Jcq1xAB/L8EQKH0jH9V8PiKIwxDTK33 4izonXxAOSFpTSC6JTZ0ENM3hHr8HTiRi7sOFEw7kj+OJXklnHyx9/2G/CM6sIvumKYd mikxGfOMwWGqNW+tGXiC1Z/scTuZrKdzrpwOCyOVKte1MoAHcanrbMyJGqHnU2Kz7NZ8 /nXRE8hRqD1YogAA6OjskK4T7jbJYGpEe0DP6ccPWlmSc9nePM3GD2EyLNtFrfB9Kd/d yPJe4pfjZWD1o14sGZtMTwFjRaDh+2ntyc2uQukoiYCplsEFdNOgW0cXjzdprveAPD5n sPpg== X-Gm-Message-State: AOJu0YyO+CU4GFGHBRZa1qWbwKpsFUsLKkm2e/EG+f/o8EiIY+XMKc4F DrwxzufuBMIeA9Ss3jsTbUMHYSF1+LD7j7Nk937xfS7pDNWt1jzWWaYBC6pBDAPgOG0dNLId+rx VaQfij/Fxmhgpfq34R3D9Fk9vWT30tbeufOxNtPwpkWpGExgmmYSj5sxVgdvVMEYH+0vYPhMqV8 F0u91JrkNneTs+jwyLsbsYXJkiRUTek5Q5h4b4Z46NyjBl X-Gm-Gg: ASbGncujQy8+A0Cr/IN1kRClsQgk+xt9ESChIEkDAu8gInkIjGv1YSZ4SDgdhjW3Wpl KWYQ00CcBAoyGpNkF8ade+Ocede1JKPsBxfMDLMNP9ripUkwSZWHtsjiDBGa7lq1h6YoxtEOR27 VS2nbg+gfcYPqhibTWdLWAC2xGUKbefLGUvBxixov/pkPGg/EU9cVkBjwEuS3RvW1AUn0mKzgMJ GSewufV7eHNz69sZrendyM35A8chDIoamOfc/vTX+M1upDnFx0wNUjHdlhgJX9+T74Lk8qCyH93 JWnWiEz8ET9Z3gVdY7c= X-Received: by 2002:a05:6000:1863:b0:385:df4e:366f with SMTP id ffacd0b85a97d-38bf57a97c7mr38957989f8f.38.1737742530937; Fri, 24 Jan 2025 10:15:30 -0800 (PST) X-Google-Smtp-Source: AGHT+IHXfQxgBsiTmTBvy8dlTrww1P+DiJSU6LKwAirl4rMiJ8To7yEoRhGiZ5C7DyirkpNpMNuBwA== X-Received: by 2002:a05:6000:1863:b0:385:df4e:366f with SMTP id ffacd0b85a97d-38bf57a97c7mr38957950f8f.38.1737742530494; Fri, 24 Jan 2025 10:15:30 -0800 (PST) Received: from localhost (p4ff2332e.dip0.t-ipconnect.de. [79.242.51.46]) by smtp.gmail.com with UTF8SMTPSA id ffacd0b85a97d-38c2a1766d8sm3520477f8f.14.2025.01.24.10.15.28 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 24 Jan 2025 10:15:29 -0800 (PST) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: dri-devel@lists.freedesktop.org, nouveau@lists.freedesktop.org, David Hildenbrand , Karol Herbst , Lyude Paul , Danilo Krummrich , David Airlie , Simona Vetter , Alistair Popple Subject: [PATCH v1 1/2] nouveau/svm: fix missing folio unlock + put after make_device_exclusive_range() Date: Fri, 24 Jan 2025 19:15:23 +0100 Message-ID: <20250124181524.3584236-2-david@redhat.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250124181524.3584236-1-david@redhat.com> References: <20250124181524.3584236-1-david@redhat.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 In case we have to retry the loop, we are missing to unlock+put the folio. In that case, we will keep failing make_device_exclusive_range() because we cannot grab the folio lock, and even return from the function with the folio locked and referenced, effectively never succeeding the make_device_exclusive_range(). While at it, convert the other unlock+put to use a folio as well. This was found by code inspection. Fixes: 8f187163eb89 ("nouveau/svm: implement atomic SVM access") Signed-off-by: David Hildenbrand --- drivers/gpu/drm/nouveau/nouveau_svm.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/nouveau/nouveau_svm.c b/drivers/gpu/drm/nouveau/nouveau_svm.c index b4da82ddbb6b2..8ea98f06d39af 100644 --- a/drivers/gpu/drm/nouveau/nouveau_svm.c +++ b/drivers/gpu/drm/nouveau/nouveau_svm.c @@ -590,6 +590,7 @@ static int nouveau_atomic_range_fault(struct nouveau_svmm *svmm, unsigned long timeout = jiffies + msecs_to_jiffies(HMM_RANGE_DEFAULT_TIMEOUT); struct mm_struct *mm = svmm->notifier.mm; + struct folio *folio; struct page *page; unsigned long start = args->p.addr; unsigned long notifier_seq; @@ -616,12 +617,16 @@ static int nouveau_atomic_range_fault(struct nouveau_svmm *svmm, ret = -EINVAL; goto out; } + folio = page_folio(page); mutex_lock(&svmm->mutex); if (!mmu_interval_read_retry(¬ifier->notifier, notifier_seq)) break; mutex_unlock(&svmm->mutex); + + folio_unlock(folio); + folio_put(folio); } /* Map the page on the GPU. */ @@ -637,8 +642,8 @@ static int nouveau_atomic_range_fault(struct nouveau_svmm *svmm, ret = nvif_object_ioctl(&svmm->vmm->vmm.object, args, size, NULL); mutex_unlock(&svmm->mutex); - unlock_page(page); - put_page(page); + folio_unlock(folio); + folio_put(folio); out: mmu_interval_notifier_remove(¬ifier->notifier); -- 2.47.1