From patchwork Tue Sep 6 16:49:31 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Williams X-Patchwork-Id: 9317577 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 2C59B601C0 for ; Tue, 6 Sep 2016 16:52:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2594728DEF for ; Tue, 6 Sep 2016 16:52:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 19E2C28DF3; Tue, 6 Sep 2016 16:52:52 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.1 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE, RDNS_NONE autolearn=no version=3.3.1 Received: from ml01.01.org (unknown [198.145.21.10]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 08C8528DEF for ; Tue, 6 Sep 2016 16:52:50 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 99C1F1A1E68; Tue, 6 Sep 2016 09:52:30 -0700 (PDT) X-Original-To: linux-nvdimm@lists.01.org Delivered-To: linux-nvdimm@lists.01.org Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id A0F791A1E68 for ; Tue, 6 Sep 2016 09:52:29 -0700 (PDT) Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga105.fm.intel.com with ESMTP; 06 Sep 2016 09:52:29 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.30,292,1470726000"; d="scan'208";a="875640169" Received: from dwillia2-desk3.jf.intel.com (HELO dwillia2-desk3.amr.corp.intel.com) ([10.54.39.14]) by orsmga003.jf.intel.com with ESMTP; 06 Sep 2016 09:52:29 -0700 Subject: [PATCH 2/5] dax: fix offset to physical address translation From: Dan Williams To: linux-nvdimm@lists.01.org Date: Tue, 06 Sep 2016 09:49:31 -0700 Message-ID: <147318057109.30325.17721163157375660986.stgit@dwillia2-desk3.amr.corp.intel.com> In-Reply-To: <147318056046.30325.5100892122988191500.stgit@dwillia2-desk3.amr.corp.intel.com> References: <147318056046.30325.5100892122988191500.stgit@dwillia2-desk3.amr.corp.intel.com> User-Agent: StGit/0.17.1-9-g687f MIME-Version: 1.0 X-BeenThere: linux-nvdimm@lists.01.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Linux-nvdimm developer list." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-mm@kvack.org, akpm@linux-foundation.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org Errors-To: linux-nvdimm-bounces@lists.01.org Sender: "Linux-nvdimm" X-Virus-Scanned: ClamAV using ClamSMTP 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: Signed-off-by: Dan Williams --- drivers/dax/dax.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) 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) {