Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp2332761pxb; Mon, 8 Mar 2021 22:56:14 -0800 (PST) X-Google-Smtp-Source: ABdhPJyrDtJf7PG0Q+XyiSyUOolZ9wvmL+KrVpex8rE2XSJDfgdEwngnFI+q59Bg7BwiamWXWEWC X-Received: by 2002:a17:906:110d:: with SMTP id h13mr19016758eja.357.1615272974339; Mon, 08 Mar 2021 22:56:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1615272974; cv=none; d=google.com; s=arc-20160816; b=Nt2xEqMZLjfcUiKPDxnVqDYFhQ4RXD26OX5SF6lY/Zlo75xYboUban5jprY2KeF0yv 1E+1/b4FCW6J4Fel8EF1G0IJN4oe3Sss7MTiYdnpMGyxY4zzcn0ly/zfvGO37twLQ+C6 zPuAQSJLpbYdCaF8E8Xpvx4UPryjE9aMtfDY4tMQhrZ0Zq3QJ45niuSeMNv9w+Tpxlg3 BV2/QXOYS4AYkJRCNXnqXmx7k6ZPuoxGgJfsPFjCKjO3ZgLijYP6OapZ/489gGx9q53w U+zpF9IfbwwPpA2yxGmARDrWznVd8OH+edMkZwlBSePqWpVAdToLEKnZ9xMHCX2y9R5Q RoQA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:message-id:date:cc:to:from:subject:ironport-sdr :ironport-sdr; bh=re8jTFzzTNQKcDZd7TviTzYgtVr8uFOE7c2UPnI3BaY=; b=qm48x8l7wnkw9GiIjJq8GKgFIpxJefDYYcjLDY9wwL5oFqaHx89eS+tWPDg2rAyeho SUO9W5oMC790zGPeScdrZVbs+44Qq6Dg789HUlUBZ0YbGo4HULSO+Y0/SSGeUztCbBAV P4GlAu0KMUeCJRR26m+UFQEgAct84+6KE4y6BKFKCF62r0ww1w20tVXyfzAm+uMZ+lQ+ PhV5aLeIObELLo2arR19I2U0fXK6l/uUrvA9YvYUGx+LUrKn+WgUcWcd+e30ZnUQFyn0 khDMq+NFiMxXferUc87E5bhy0POLqAws7PGsWNzC37n9JXz+UuVIRQw5xIXqWqhzdqV/ vK6Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id cw21si8462456edb.344.2021.03.08.22.55.49; Mon, 08 Mar 2021 22:56:14 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229637AbhCIGyk (ORCPT + 99 others); Tue, 9 Mar 2021 01:54:40 -0500 Received: from mga14.intel.com ([192.55.52.115]:32597 "EHLO mga14.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229520AbhCIGyX (ORCPT ); Tue, 9 Mar 2021 01:54:23 -0500 IronPort-SDR: VYsOELHL9HME5jppojtuht8hTq5dSczJKc3TCpbS/SW8QZsxlmAWnzdprO5V6WrPx+KMTPIqmo CKmPhXkV+1yA== X-IronPort-AV: E=McAfee;i="6000,8403,9917"; a="187536076" X-IronPort-AV: E=Sophos;i="5.81,234,1610438400"; d="scan'208";a="187536076" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Mar 2021 22:54:22 -0800 IronPort-SDR: dAdWMk+JmlDxVk9M4A/URs+ost3nLPKwcJrq77fVg6oR6mQ2pIIvTAH8qM+HEUGr7z6MhnKkF+ bBc0A5Z9L0jg== X-IronPort-AV: E=Sophos;i="5.81,234,1610438400"; d="scan'208";a="437569479" Received: from dwillia2-desk3.jf.intel.com (HELO dwillia2-desk3.amr.corp.intel.com) ([10.54.39.25]) by fmsmga002-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Mar 2021 22:54:22 -0800 Subject: [PATCH] libnvdimm: Let revalidate_disk() revalidate region read-only From: Dan Williams To: linux-nvdimm@lists.01.org Cc: Christoph Hellwig , Ming Lei , "Martin K. Petersen" , Hannes Reinecke , Jens Axboe , kernel test robot , Vishal Verma , linux-kernel@vger.kernel.org, linux-block@vger.kernel.org Date: Mon, 08 Mar 2021 22:54:22 -0800 Message-ID: <161527286194.446794.5215036039655765042.stgit@dwillia2-desk3.amr.corp.intel.com> User-Agent: StGit/0.18-3-g996c MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Previous kernels allowed the BLKROSET to override the disk's read-only status. With that situation fixed the pmem driver needs to rely on revalidate_disk() to clear the disk read-only status after the host region has been marked read-write. Recall that when libnvdimm determines that the persistent memory has lost persistence (for example lack of energy to flush from DRAM to FLASH on an NVDIMM-N device) it marks the region read-only, but that state can be overridden by the user via: echo 0 > /sys/bus/nd/devices/regionX/read_only ...to date there is no notification that the region has restored persistence, so the user override is the only recovery. Fixes: 52f019d43c22 ("block: add a hard-readonly flag to struct gendisk") Cc: Christoph Hellwig Cc: Ming Lei Cc: Martin K. Petersen Cc: Hannes Reinecke Cc: Jens Axboe Reported-by: kernel test robot Reported-by: Vishal Verma Signed-off-by: Dan Williams --- drivers/nvdimm/btt.c | 7 +++++++ drivers/nvdimm/bus.c | 14 ++++++-------- drivers/nvdimm/pmem.c | 7 +++++++ 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/drivers/nvdimm/btt.c b/drivers/nvdimm/btt.c index 41aa1f01fc07..73d3bf5aa208 100644 --- a/drivers/nvdimm/btt.c +++ b/drivers/nvdimm/btt.c @@ -1508,11 +1508,18 @@ static int btt_getgeo(struct block_device *bd, struct hd_geometry *geo) return 0; } +static int btt_revalidate(struct gendisk *disk) +{ + nvdimm_check_and_set_ro(disk); + return 0; +} + static const struct block_device_operations btt_fops = { .owner = THIS_MODULE, .submit_bio = btt_submit_bio, .rw_page = btt_rw_page, .getgeo = btt_getgeo, + .revalidate_disk = btt_revalidate, }; static int btt_blk_init(struct btt *btt) diff --git a/drivers/nvdimm/bus.c b/drivers/nvdimm/bus.c index 48f0985ca8a0..3a777d0073b7 100644 --- a/drivers/nvdimm/bus.c +++ b/drivers/nvdimm/bus.c @@ -631,16 +631,14 @@ void nvdimm_check_and_set_ro(struct gendisk *disk) struct nd_region *nd_region = to_nd_region(dev->parent); int disk_ro = get_disk_ro(disk); - /* - * Upgrade to read-only if the region is read-only preserve as - * read-only if the disk is already read-only. - */ - if (disk_ro || nd_region->ro == disk_ro) + /* catch the disk up with the region ro state */ + if (disk_ro == nd_region->ro) return; - dev_info(dev, "%s read-only, marking %s read-only\n", - dev_name(&nd_region->dev), disk->disk_name); - set_disk_ro(disk, 1); + dev_info(dev, "%s read-%s, marking %s read-%s\n", + dev_name(&nd_region->dev), nd_region->ro ? "only" : "write", + disk->disk_name, nd_region->ro ? "only" : "write"); + set_disk_ro(disk, nd_region->ro); } EXPORT_SYMBOL(nvdimm_check_and_set_ro); diff --git a/drivers/nvdimm/pmem.c b/drivers/nvdimm/pmem.c index b8a85bfb2e95..af204fce1b1c 100644 --- a/drivers/nvdimm/pmem.c +++ b/drivers/nvdimm/pmem.c @@ -276,10 +276,17 @@ __weak long __pmem_direct_access(struct pmem_device *pmem, pgoff_t pgoff, return PHYS_PFN(pmem->size - pmem->pfn_pad - offset); } +static int pmem_revalidate(struct gendisk *disk) +{ + nvdimm_check_and_set_ro(disk); + return 0; +} + static const struct block_device_operations pmem_fops = { .owner = THIS_MODULE, .submit_bio = pmem_submit_bio, .rw_page = pmem_rw_page, + .revalidate_disk = pmem_revalidate, }; static int pmem_dax_zero_page_range(struct dax_device *dax_dev, pgoff_t pgoff,