diff mbox

[2/5] dax: fix offset to physical address translation

Message ID 147318057109.30325.17721163157375660986.stgit@dwillia2-desk3.amr.corp.intel.com (mailing list archive)
State Accepted
Commit a07b871
Headers show

Commit Message

Dan Williams Sept. 6, 2016, 4:49 p.m. UTC
In pgoff_to_phys() 'pgoff' is already relative to base of the dax
device, so we only need to compare if the current offset is within the
current resource extent.  Otherwise, we are double accounting the
resource start offset when translating pgoff to a physical address.

Cc: <stable@vger.kernel.org>
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
---
 drivers/dax/dax.c |   10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

Comments

Dan Williams Sept. 10, 2016, 1 a.m. UTC | #1
On Tue, Sep 6, 2016 at 9:49 AM, Dan Williams <dan.j.williams@intel.com> wrote:
> In pgoff_to_phys() 'pgoff' is already relative to base of the dax
> device, so we only need to compare if the current offset is within the
> current resource extent.  Otherwise, we are double accounting the
> resource start offset when translating pgoff to a physical address.
>
> Cc: <stable@vger.kernel.org>
> Signed-off-by: Dan Williams <dan.j.williams@intel.com>

On second look this results in the exact same translation, correct in
both cases.  This is also confirmed by a new ndctl unit test that does
data verification by writing through a /dev/pmem device and the
verifying via a /dev/dax device associated with the same namespace, so
I'm dropping this patch.
diff mbox

Patch

diff --git a/drivers/dax/dax.c b/drivers/dax/dax.c
index 29f600f2c447..4653f84cabe7 100644
--- a/drivers/dax/dax.c
+++ b/drivers/dax/dax.c
@@ -357,16 +357,18 @@  static int check_vma(struct dax_dev *dax_dev, struct vm_area_struct *vma,
 static phys_addr_t pgoff_to_phys(struct dax_dev *dax_dev, pgoff_t pgoff,
 		unsigned long size)
 {
+	phys_addr_t phys, offset;
 	struct resource *res;
-	phys_addr_t phys;
 	int i;
 
+	offset = pgoff * PAGE_SIZE;
 	for (i = 0; i < dax_dev->num_resources; i++) {
 		res = &dax_dev->res[i];
-		phys = pgoff * PAGE_SIZE + res->start;
-		if (phys >= res->start && phys <= res->end)
+		if (offset < resource_size(res)) {
+			phys = offset + res->start;
 			break;
-		pgoff -= PHYS_PFN(resource_size(res));
+		}
+		offset -= resource_size(res);
 	}
 
 	if (i < dax_dev->num_resources) {