From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (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 D22A928E0 for ; Tue, 30 Jun 2026 00:06:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782778018; cv=none; b=YFXgOl3I9PKhkLfWyzneZfT6ioJOZgnoTzF3besyBFB6s8loayBNJRnfyvjRBCjnIoMYYZoBaJNAhSBXT25t7Qe5p+Y0bMMkvrMGTPFbYgcXO9MtzIg47hEysfGWI7GKijy+K3rp8ciLEnzQk/16chLxYMfsG9f3LvbCGWbrZ8w= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782778018; c=relaxed/simple; bh=2DeAG2cc+0zTOvpq3kgF286eOYWAs0614mHV8ku5wTA=; h=Date:From:To:Cc:Subject:Message-Id:In-Reply-To:References: Mime-Version:Content-Type; b=I/pm3/LiWuXtXWKthXZW/bkKoQdchk5FAbj28Ynk1qIjc4dCI2OwGumQgW9Hc1zh8P+s/BzmBB4GttoMQX6N808atEiKyaaZIyPVgcwho2lbhGHsKTZcazNwaqSJBgo8AGOYK04utVJV9kCpo12JvCn94WcVc/PGt/30qRkFnis= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b=USBc7FPR; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b="USBc7FPR" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3D5CF1F000E9; Tue, 30 Jun 2026 00:06:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=korg; t=1782778017; bh=rdd22wUNJeSeBAxSgra0m8c0OqrzMGZhMBav1VBCRnc=; h=Date:From:To:Cc:Subject:In-Reply-To:References; b=USBc7FPRZ4xTMksC0a8oiz0gtczsa03CQCr+LaeTXZRgKQg1YL3akDHAahGCayirK /f2zbntvoZgUM0IFuSk2fmhGxdo90Dt3eiy6ZxvPWye4xWuOD1IpviHb+mKH+lMh/p tdObjw8zl6tfmXlNW7ntBRHnM3HoGBxOiWqFvOCg= Date: Mon, 29 Jun 2026 17:06:56 -0700 From: Andrew Morton To: Stanislav Kinsburskii Cc: jgg@ziepe.ca, leon@kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Alistair Popple , Balbir Singh , Zenghui Yu (Huawei) Subject: Re: [PATCH] lib: test_hmm: use device devt for coherent device range selection Message-Id: <20260629170656.2c5408b46b1ce53183f672dd@linux-foundation.org> In-Reply-To: <178277581197.172200.16265155329935822153.stgit@skinsburskii> References: <178277581197.172200.16265155329935822153.stgit@skinsburskii> X-Mailer: Sylpheed 3.8.0beta1 (GTK+ 2.24.33; x86_64-pc-linux-gnu) 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-Transfer-Encoding: 7bit On Mon, 29 Jun 2026 16:30:14 -0700 Stanislav Kinsburskii wrote: > Commit af69016dab96 ("lib: test_hmm: implement a device release method") > moved the initial dmirror_allocate_chunk() call before cdev_device_add(). > That means the struct cdev has not been added yet, so cdev_add() has not > initialized mdevice->cdevice.dev. > > The coherent-device range selection uses the device minor to choose between > spm_addr_dev0 and spm_addr_dev1. Reading MINOR(mdevice->cdevice.dev) before > cdev_add() therefore always sees an uninitialized dev_t. As a result, both > coherent devices select the same physical range, and adding the second > device fails due to the overlapping dev_pagemap range. > > Use mdevice->device.devt instead. It is initialized in > dmirror_device_init() before dmirror_allocate_chunk() is called and is the > same dev_t later passed to cdev_device_add(). Thanks. > Fixes: af69016dab96 ("lib: test_hmm: implement a device release method") We should cc the people involved with that commit. Added. > --- a/lib/test_hmm.c > +++ b/lib/test_hmm.c > @@ -581,7 +581,7 @@ static int dmirror_allocate_chunk(struct dmirror_device *mdevice, > devmem->pagemap.type = MEMORY_DEVICE_PRIVATE; > break; > case HMM_DMIRROR_MEMORY_DEVICE_COHERENT: > - devmem->pagemap.range.start = (MINOR(mdevice->cdevice.dev) - 2) ? > + devmem->pagemap.range.start = (MINOR(mdevice->device.devt) - 2) ? > spm_addr_dev0 : > spm_addr_dev1; > devmem->pagemap.range.end = devmem->pagemap.range.start + > af69016dab96 had cc:stable, so I'll add cc:stable to this patch, to help ensure that it lands in the appropriate places.