Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp121666imj; Wed, 13 Feb 2019 05:45:47 -0800 (PST) X-Google-Smtp-Source: AHgI3IYD07m9ZNFhbEzoVAEDC7o1tOThFICGnnFX43PlM6E+RDzNSisVdNzbAl3f27W5Afad6mRE X-Received: by 2002:a17:902:9a07:: with SMTP id v7mr575423plp.247.1550065547619; Wed, 13 Feb 2019 05:45:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550065547; cv=none; d=google.com; s=arc-20160816; b=jjaUIfe79d3tpwrDOSPlFQnm+fQu1j9dEEfkKG2qmD5Gr885dxa+BNfq5kw2v6gzuE DTxzju1bD8nRT7347JZnuiz1wodRX1hAYmFhZXLfbpxtyykqidShEmASnzkDooSSnTKn VULGNwf9yy3yFriPHkBvwvfxaM969b9VZR4AqdhEio5SIOiyye8/dtmI8m+rRrCQtUaE n8zJV9FTwp93IDpZbsdCXv9HbXj+rQ0GcQkJYruAeh2gXtvUr74loEyEcn1qapXiyWXP YN3Z9KX4sRPdp1PdJXRRZ9CztASXirG/ok+RBU1z96nR0dP9DORlAhj+gZPvX205SNy/ h+JA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=OZZ9xY+rGRWJMca7pfQOVcT8ZAsuK9fo6Jn5hT0P+rk=; b=db/DCczC09u9D4iasuka1F48Iy+0ErpRWdMcDrQsuLQuj8JncROVUBm4NZZ3PPJMts WQrYkVnJ+OE+tDlZw1h6ywqZCaU4shn1lrHR/8SJO5Dx6HByKdksbWYrpevXTFDEjlQY 6MOUZYQQU/BTDE3aIrL6d+4rPMbi/Ov7oSmR9DQuIucHQKj+fKRoQbPnOgCqAvnoDN4Z 9wqY6t9X7i7G45QwHIyZCl0QIgoPQyQx/1yVhYvXuVkKpqyGzQiL+RTLOtuRDcvRDJB9 et4gv0HBl9XhHnLURKN5dR5Pm1n+1//+d0tgH6IbdU3CPJTSzELemLWcX4pqwNHfdUKm bx3g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g4si10441120pfi.233.2019.02.13.05.45.31; Wed, 13 Feb 2019 05:45:47 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389288AbfBMKWF (ORCPT + 99 others); Wed, 13 Feb 2019 05:22:05 -0500 Received: from mx2.suse.de ([195.135.220.15]:59016 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1733047AbfBMKWF (ORCPT ); Wed, 13 Feb 2019 05:22:05 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 3FA1AAEE9; Wed, 13 Feb 2019 10:22:03 +0000 (UTC) Received: by quack2.suse.cz (Postfix, from userid 1000) id A27971E09C5; Wed, 13 Feb 2019 11:22:02 +0100 (CET) Date: Wed, 13 Feb 2019 11:22:02 +0100 From: Jan Kara To: Dan Williams Cc: linux-nvdimm@lists.01.org, Jan Kara , "Darrick J. Wong" , linux-kernel@vger.kernel.org, vishal.l.verma@intel.com, linux-fsdevel@vger.kernel.org Subject: Re: [PATCH 3/7] dax: Check the end of the block-device capacity with dax_direct_access() Message-ID: <20190213102202.GA13313@quack2.suse.cz> References: <155000668075.348031.9371497273408112600.stgit@dwillia2-desk3.amr.corp.intel.com> <155000669646.348031.16690970886357498896.stgit@dwillia2-desk3.amr.corp.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <155000669646.348031.16690970886357498896.stgit@dwillia2-desk3.amr.corp.intel.com> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue 12-02-19 13:24:56, Dan Williams wrote: > The checks in __bdev_dax_supported() helped mitigate a potential data > corruption bug in the pmem driver's handling of section alignment > padding. Strengthen the checks, including checking the end of the range, > to validate the dev_pagemap, Xarray entries, and sector-to-pfn > translation established for pmem namespaces. > > Cc: Jan Kara > Cc: "Darrick J. Wong" > Signed-off-by: Dan Williams > --- > drivers/dax/super.c | 39 +++++++++++++++++++++++++++++---------- > 1 file changed, 29 insertions(+), 10 deletions(-) > > diff --git a/drivers/dax/super.c b/drivers/dax/super.c > index 6e928f37d084..a27395cfcec6 100644 > --- a/drivers/dax/super.c > +++ b/drivers/dax/super.c > @@ -86,12 +86,14 @@ bool __bdev_dax_supported(struct block_device *bdev, int blocksize) > { > struct dax_device *dax_dev; > bool dax_enabled = false; > + pgoff_t pgoff, pgoff_end; > struct request_queue *q; > - pgoff_t pgoff; > - int err, id; > - pfn_t pfn; > - long len; > char buf[BDEVNAME_SIZE]; > + void *kaddr, *end_kaddr; > + pfn_t pfn, end_pfn; > + sector_t last_page; > + long len, len2; > + int err, id; > > if (blocksize != PAGE_SIZE) { > pr_debug("%s: error: unsupported blocksize for dax\n", > @@ -113,6 +115,15 @@ bool __bdev_dax_supported(struct block_device *bdev, int blocksize) > return false; > } > > + last_page = ALIGN_DOWN(part_nr_sects_read(bdev->bd_part) > + - PAGE_SIZE / 512, PAGE_SIZE / 512); Why not just (i_size_read(bdev->bd_inode) - 1) >> PAGE_SHIFT? Otherwise the patch looks good to me. Honza > + err = bdev_dax_pgoff(bdev, last_page, PAGE_SIZE, &pgoff_end); > + if (err) { > + pr_debug("%s: error: unaligned partition for dax\n", > + bdevname(bdev, buf)); > + return false; > + } > + > dax_dev = dax_get_by_host(bdev->bd_disk->disk_name); > if (!dax_dev) { > pr_debug("%s: error: device does not support dax\n", > @@ -121,14 +132,15 @@ bool __bdev_dax_supported(struct block_device *bdev, int blocksize) > } > > id = dax_read_lock(); > - len = dax_direct_access(dax_dev, pgoff, 1, NULL, &pfn); > + len = dax_direct_access(dax_dev, pgoff, 1, &kaddr, &pfn); > + len2 = dax_direct_access(dax_dev, pgoff_end, 1, &end_kaddr, &end_pfn); > dax_read_unlock(id); > > put_dax(dax_dev); > > - if (len < 1) { > + if (len < 1 || len2 < 1) { > pr_debug("%s: error: dax access failed (%ld)\n", > - bdevname(bdev, buf), len); > + bdevname(bdev, buf), len < 1 ? len : len2); > return false; > } > > @@ -143,13 +155,20 @@ bool __bdev_dax_supported(struct block_device *bdev, int blocksize) > */ > WARN_ON(IS_ENABLED(CONFIG_ARCH_HAS_PMEM_API)); > dax_enabled = true; > - } else if (pfn_t_devmap(pfn)) { > - struct dev_pagemap *pgmap; > + } else if (pfn_t_devmap(pfn) && pfn_t_devmap(end_pfn)) { > + struct dev_pagemap *pgmap, *end_pgmap; > > pgmap = get_dev_pagemap(pfn_t_to_pfn(pfn), NULL); > - if (pgmap && pgmap->type == MEMORY_DEVICE_FS_DAX) > + end_pgmap = get_dev_pagemap(pfn_t_to_pfn(end_pfn), NULL); > + if (pgmap && pgmap == end_pgmap && pgmap->type == MEMORY_DEVICE_FS_DAX > + && pfn_t_to_page(pfn)->pgmap == pgmap > + && pfn_t_to_page(end_pfn)->pgmap == pgmap > + && pfn_t_to_pfn(pfn) == PHYS_PFN(__pa(kaddr)) > + && pfn_t_to_pfn(end_pfn) == PHYS_PFN(__pa(end_kaddr))) > dax_enabled = true; > put_dev_pagemap(pgmap); > + put_dev_pagemap(end_pgmap); > + > } > > if (!dax_enabled) { > -- Jan Kara SUSE Labs, CR