From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f180.google.com (mail-pl1-f180.google.com [209.85.214.180]) (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 DF34146D2BB for ; Tue, 21 Jul 2026 16:30:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.180 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784651424; cv=none; b=X95VJ9HzMMGIUoGZ16hLwFNYOQ2sMrlV2zs5174mSfzpRGbSdMi7wne53lRCSF3InrQS2Xr2cf3F861Qn38AEBe4Jmoakp3R0m8iZUCsF9G9hRRwViBtamFCHtGNekqw3dEJPK8PKqlQJ1CfiL/mlKpfPEFXyBl6hoz8ei3530I= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784651424; c=relaxed/simple; bh=sRL/AboceP9RTbXpHxyPeUdgzWpPfsUln2HGrQY4moo=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=tOHLLnRm/sbo1As4ioT8VCRTNJ/6h4qo1cskO8hjhbbyo0PlfnxFgLGXwOyRwm9ZBsl+jIQFX4NQnyumsxHcLuPMq6PvPnU4E9Saz72Ux7FgIQHL//kKbjbagKY2kOYlLDlRsAjkdRCqzpZ0xlmC3mKK7bR1rjwQKyQFJobVUuc= 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=Rthgastz; arc=none smtp.client-ip=209.85.214.180 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="Rthgastz" Received: by mail-pl1-f180.google.com with SMTP id d9443c01a7336-2ce98cb8165so54441825ad.1 for ; Tue, 21 Jul 2026 09:30:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1784651422; x=1785256222; darn=vger.kernel.org; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:from:date:from:to:cc:subject :date:message-id:reply-to:content-type; bh=MHdawj2rFYjyK3F10CxJAoaZBnVtB6lTHhJb84UOuRM=; b=Rthgastzt5xnaF5++mKnnAIYfOytYO+jj9FBRrasM1kdyTX7PxgdNQ5/9MEonbWHlW Ij+oYRvW1JWElinOAWhuJBsYYYjfC/cHQV5ti4lJpfwkkZOnsCkymblaNufLz41mMUj3 sYaQiPxot6KsyNt3ZM/Mzidm7kIvZnIu/HWn9zIlnT7Ybse7Y2rztrz1LEUKs1fNoau7 YixC3UgPW7yvDm/cex1rQS4kdwfFnW5yAJ4ZfUXLQM+Iihjpy+1Uhr9I0yuINxeo4Sa8 AR41po2sLV/c//zuDpYj/1Od20DcEfmcNxx9gRZ2d/6ToiGsVtfc+rgmOSDg/qBLSPwq oQ9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784651422; x=1785256222; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:from:date:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=MHdawj2rFYjyK3F10CxJAoaZBnVtB6lTHhJb84UOuRM=; b=OaLbUkjC4XHwIypJMhLdrgh2gJ5qYnYSKprnXgQnaK5FVtIXgqBJYyYTc0vUcrgV3d JOH9ABwKvljmVby+wAmtdwXXZrKkLt9/TKjpS8RIAaKv5LW/z3cGb6bXTcBf5Q3UrJSt cnhMThHxpwFiczQIbR7Pvi/XT2AOhekP/Y6ZCfLq+JlUwpMr72noptkVkbDpbTUqIHvp hvK3k72bAF1fzT6AbTcDTZJuytMmLy4p1YnVgG8uRMEyixyWW3wRfqYbq4adyrF3/aXd BKQvKAJRc/GflKSCq+IqByqUvRF9zzMh/oRwB4gWVoUZfVif7WJUtE2xwP7fIolnMequ DTjA== X-Forwarded-Encrypted: i=1; AHgh+RpsZTNkRI5mrf+Km3kbUcZ1X1t4uQpC8phfU9RbTqr2KtqLd+14yM0gL0olGn9yYAvbGTQodlBpjYla1js=@vger.kernel.org X-Gm-Message-State: AOJu0YzdQU4dHXF2Zi3tFaWn75CNCaR4m92vaUvjCLeKPnnR30MSPvcX EzZXZXbVKe1UaZxAhNPEU5oKN3i/yh+fl5RKSZfRSDb2S0K0GUZLLEnn X-Gm-Gg: AR+sD11M4N4PsL5B2YfeFRI/gQbE+QXfUVvTCYGHUEqYy4PtPwkgmV7XYlUtg4doEnT dRzHq5U7GzgnMnWKCmBT1LDbMFoS8FagM5fUXGg+2UrEMjcYT07PRMuEGFLCDvE186NzJv9IfkI gOGTb1P8x+9IXVJtNk1M7XMUffHWMKy2urBiKZQtuQ7Ow1ha5rRwqAMJiW2WMkXAplxIZTlJ6pG jQt9WF39r1CA9FE+6u0yLUMgd6C7hk/KdTE9e+2CFfLqUFPrYd6cqljL3o18PDH3KmnZktyH7/M nO2vR/FAC38iyT4Bq6FWAwr8jOwWpb1XVOizu4go4RQ0uNUp70BtPJSyb9P6Bs0fq+FpMa/X1vd RTBC/CxRKySuWuYZwJeBaV+WobT07SKul4E0y1ut2yDnjRlg/wazsqrtypxf4X4Pbxidu3SFfaO R1xvt0hFCDoDBBkW9DuXkeoXx4vW4KFMD8FJJ/ptIgQDQn X-Received: by 2002:a17:903:f83:b0:2c9:d277:2cdb with SMTP id d9443c01a7336-2cf8dcccd50mr3432635ad.9.1784651421915; Tue, 21 Jul 2026 09:30:21 -0700 (PDT) Received: from skinsburskii (c-98-225-44-182.hsd1.wa.comcast.net. [98.225.44.182]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2cf34729df7sm80984405ad.63.2026.07.21.09.30.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Jul 2026 09:30:21 -0700 (PDT) Date: Tue, 21 Jul 2026 09:30:19 -0700 From: Stanislav Kinsburskii To: Matthew Brost Cc: maarten.lankhorst@linux.intel.com, mripard@kernel.org, tzimmermann@suse.de, airlied@gmail.com, simona@ffwll.ch, thomas.hellstrom@linux.intel.com, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, intel-xe@lists.freedesktop.org Subject: Re: [PATCH] drm/gpusvm: Zero HMM PFNs before scanning ranges Message-ID: References: <178406967042.1113483.2116704310277917086.stgit@skinsburskii> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: On Mon, Jul 20, 2026 at 05:26:52PM -0700, Matthew Brost wrote: > On Mon, Jul 20, 2026 at 04:48:02PM -0700, Stanislav Kinsburskii wrote: > > On Mon, Jul 20, 2026 at 11:54:50AM -0700, Matthew Brost wrote: > > > On Tue, Jul 14, 2026 at 03:54:32PM -0700, Stanislav Kinsburskii wrote: > > > > drm_gpusvm_scan_mm() asks HMM to report the current CPU page-table > > > > state without faulting missing entries by leaving default_flags set to > > > > zero. The HMM PFN array is still caller-owned input/output state, and > > > > the framework may preserve input bits while filling entries. It is not > > > > safe for the caller to hand HMM an uninitialized array and then treat > > > > entries without HMM_PFN_VALID as an authoritative unpopulated result. > > > > > > > > Use kvcalloc() for the temporary PFN array so entries that are not > > > > reported as valid start from the documented zero state. This prevents > > > > random stack or heap contents from being interpreted as HMM PFN flags or > > > > PFN values during the scan. > > > > > > > > Fixes: f1d08a586482 ("drm/gpusvm: Introduce a function to scan the current migration state") > > > > Cc: stable@vger.kernel.org > > > > Signed-off-by: Stanislav Kinsburskii > > > > --- > > > > drivers/gpu/drm/drm_gpusvm.c | 2 +- > > > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > > > > > diff --git a/drivers/gpu/drm/drm_gpusvm.c b/drivers/gpu/drm/drm_gpusvm.c > > > > index 1a8bb83bd28d..c8f489d7ff7e 100644 > > > > --- a/drivers/gpu/drm/drm_gpusvm.c > > > > +++ b/drivers/gpu/drm/drm_gpusvm.c > > > > @@ -859,7 +859,7 @@ enum drm_gpusvm_scan_result drm_gpusvm_scan_mm(struct drm_gpusvm_range *range, > > > > > > Two other cases in gpusvm would need to be fixed as well: > > > > > > - drm_gpusvm_get_pages > > > - drm_gpusvm_range_evict > > > > > > > No, these two are fine, as the faulting is done with HMM_PFN_REQ_FAULT, > > which either populates all the PFNs or fails. > > > > Ah, yes clearly misunderstood the issue here / didn't read the commit > message. > > This patch LGTM: > Reviewed-by: Matthew Brost > > Will merge to drm-misc-fixes shortly. > > But then drm_gpusvm_check_pages() should be fixed too as we don't set > HMM_PFN_REQ_FAULT there either. > Indeed. Please, see v2 of the patch. Thanks, Stanislav > Matt > > > The only case where PFNs must be zeroed is when the caller wants to > > collect the mapped PFNs. In this case, the missing PFNs are simply > > ignored by the HMM framework. > > > > Thanks, > > Stanislav > > > > > The offending patch is likely the one that added sticky bits to HMM: > > > `git format-patch -1 285e871884ff3` for above two cases. > > > > > > While I think zeroing here would be the safest approach, it does not appear > > > to be a problem in practice because the sticky bits are only used by > > > `hmm_dma_map_pfn()` and `hmm_dma_unmap_pfn()`. > > > > > > Also, there are several non-gpusvm cases in the kernel that do not zero > > > the PFN array either. So I'd say we should either fix the entire kernel > > > in one pass, document that pfns must initialized to a known state, or > > > leave this code alone. > > > > > > Matt > > > > > > > const struct dev_pagemap *other = NULL; > > > > int err, i; > > > > > > > > - pfns = kvmalloc_array(npages, sizeof(*pfns), GFP_KERNEL); > > > > + pfns = kvcalloc(npages, sizeof(*pfns), GFP_KERNEL); > > > > if (!pfns) > > > > return DRM_GPUSVM_SCAN_UNPOPULATED; > > > > > > > > > > > >