From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 30046364028 for ; Wed, 24 Jun 2026 14:49:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782312581; cv=none; b=Bh+ceX2pBfmVjnH3Iq4+pxI8Jyi0mXbOzebMvShgPu1pmtrYN/0etfo4QMEffQiP9ETHZisfmEfsLic3wNjxtHWYrRbBZmcPkMwf/UAOPv8BKZPdNCZabOLYGOO/I20n4v9oXkRQNfoQ/hR0g6vu6M37UuaE3PyP8HX6YvinTx8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782312581; c=relaxed/simple; bh=dC6yLgSD24dCQW7aW4L3yU0ARGBkfl+NeBQGhJFN724=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=W+cmp5mT64p01xhDnlRDFBKldPgIkHf1/XHa8ryHCTQBCLOtThBcAVts/gowRjokhbn5OVz8sEkHp3XhUKG4OeQIddEA/AKkP59C4Tw8bIZpsd5LpqYgwBRIEs4h36tLkqCZL5XHuT0RI3IwjFbJ7yqxT+K5zKzVGelOD+8xq30= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.b=uSt2o4+b; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.b="uSt2o4+b" Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id E4CD72944; Wed, 24 Jun 2026 07:49:33 -0700 (PDT) Received: from [10.57.80.146] (unknown [10.57.80.146]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 7B6B53F62B; Wed, 24 Jun 2026 07:49:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=arm.com; s=foss; t=1782312578; bh=dC6yLgSD24dCQW7aW4L3yU0ARGBkfl+NeBQGhJFN724=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=uSt2o4+boIOBZcx+BIRTuO74pIJ2hGZsxX/psMM7Pm4YvuzXcrtFBrGL7MFsqwBqf UGTQL/XktWfdQ84vf8px+B6MdMyAPrRlzX1W0QAlPGaFN54z+kAwM4aj0clpgoX0TN q4PjcXhwwhpBQ7pqYvY5WtFD45BokSL4WXOhsol4= Message-ID: Date: Wed, 24 Jun 2026 15:49:32 +0100 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2 1/2] drm/panthor: Add vm_bind region with kbo range overlap check To: =?UTF-8?Q?Adri=C3=A1n_Larumbe?= , Boris Brezillon , Liviu Dudau , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org References: <20260619-vm_bind_checks-v2-0-b51abab35f71@collabora.com> <20260619-vm_bind_checks-v2-1-b51abab35f71@collabora.com> From: Steven Price Content-Language: en-GB In-Reply-To: <20260619-vm_bind_checks-v2-1-b51abab35f71@collabora.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On 19/06/2026 13:41, Adrián Larumbe wrote: > When a VM is created, caller has to specify the range of the address space > carve-out set aside for mapping kernel BO's. That means vm_bind mappings of > UM-exposed BO's should not intersect with that region, but at the moment > we're not checking this. > > At first, I thought of giving these values to drm_gpuvm_init() through its > reserve_{offset, range} arguments, but it turns out that is meant for VM > address spans that are not managed through the usual drm_gpuvm split/merge > circuit, so storing the end of the user VA range at VM creation time and > doing a quick check in the vm_bind ioctl path was the simplest workaround. > > Signed-off-by: Adrián Larumbe > --- > drivers/gpu/drm/panthor/panthor_mmu.c | 9 +++++++++ > 1 file changed, 9 insertions(+) > > diff --git a/drivers/gpu/drm/panthor/panthor_mmu.c b/drivers/gpu/drm/panthor/panthor_mmu.c > index 31cc57029c12..a8de4fe6b231 100644 > --- a/drivers/gpu/drm/panthor/panthor_mmu.c > +++ b/drivers/gpu/drm/panthor/panthor_mmu.c > @@ -310,6 +310,9 @@ struct panthor_vm { > u64 end; > } kernel_auto_va; > > + /** @user_va_end: Last VA in the address range VM users can map objects against. */ > + u64 user_va_end; > + > /** @as: Address space related fields. */ > struct { > /** > @@ -2893,6 +2896,8 @@ panthor_vm_create(struct panthor_device *ptdev, bool for_mcu, > va_range = full_va_range; > } > > + vm->user_va_end = kernel_va_start - 1; > + > mutex_init(&vm->mm_lock); > drm_mm_init(&vm->mm, kernel_va_start, kernel_va_size); > vm->kernel_auto_va.start = auto_kernel_va_start; > @@ -2981,6 +2986,10 @@ panthor_vm_bind_prepare_op_ctx(struct drm_file *file, > if (!IS_ALIGNED(op->va | op->size | op->bo_offset, vm_pgsz)) > return -EINVAL; > > + /* We don't allow mappings that overlap with kbo's reserved range */ > + if (op->va + op->size > vm->user_va_end) > + return -EINVAL; Minor issue, but this is off-by-one. If you attempt to map just the last page then op->va==kernel_va_start - PAGE_SIZE and op->size == PAGE_SIZE. But this check will reject it. I suggest removing the "- 1" from user_vm_end, which also means it matches the user_va_range we pass back to user space (will appropriate comment/name updates). Thanks, Steve > + > switch (op->flags & DRM_PANTHOR_VM_BIND_OP_TYPE_MASK) { > case DRM_PANTHOR_VM_BIND_OP_TYPE_MAP: > if (!(op->flags & DRM_PANTHOR_VM_BIND_OP_MAP_SPARSE)) { >