Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp2986458imm; Sun, 1 Jul 2018 09:45:07 -0700 (PDT) X-Google-Smtp-Source: AAOMgpey26E3M0YWaBo3IZ3n8hBYVQrFvNOGlhH3+z35s0cEyc0KsUYPgpEiM+SyP0ljE0xWihQX X-Received: by 2002:a63:c60:: with SMTP id 32-v6mr4335652pgm.155.1530463507017; Sun, 01 Jul 2018 09:45:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530463506; cv=none; d=google.com; s=arc-20160816; b=aV/m9G0pkhtx+VN/0OAek3TvYeoU9s30xiYqZeWoIwtf7LcsZ9pp5wvVT+QuvUqYSN EYiAPAOtZOpCRQ+n6t9ZmTxj4BgkiD6Jv3mQSAYEUu/afGFsL+t8VzPTZKUbh/gw2JnT k/iF5a3skjM7wdr9/r2oKd/lC9oUeCe1pytnHB9Y61sg/+LIcmaukFik7wKS48A+qewT L0LgRDD4DP/FtA3sgtsGRN2mE6vA2IZUQOT+A3kS3I8RC0Zpt65MqFPh04jYbthMNgZn PwqnbNbM6edKAzOnJr0DF0ZjZWN649+1GQ75Cpnpu+NSdUE0zJBfF6qz1G9qda/JJDVi joHQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=5LcmAgKaeSxa28VTI+TkmWEeKSLz5psqzgDCu/7CWd4=; b=b5812cMaPkQvQz/7YgC0HlOB2wj3M+qFG/PATue7mXfn6jhIDFFQqzyqm6nx6+afWa aDsBv5qMDoLMmlEuewDbtXsAyRBCMyYeY74ZbNTWNEa58nv8ILhkdpaFVbC/7Hsa9CHE ANwKMLJbzol6iO8TSCuqIufRLc+mxgImVD6Ol3EGZJjr+Ns+HcOVMmh0V/8VOEABcC+I rpGZmGlJCHI+9nLs95HW3ylOkRKLmXXoAqaQH3qpMJRTNvQTCLrr2dztaxPd3W+l9QM9 6tmZLYZ0jDmMzMYDq9tZ5EHIfHD1na1hBWhTRHDk8ZtYz0DQMFFYp3Xr5g2RWsHZAP8E /mEg== 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 h4-v6si12108749pgp.490.2018.07.01.09.44.52; Sun, 01 Jul 2018 09:45:06 -0700 (PDT) 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 S1032352AbeGAQnZ (ORCPT + 99 others); Sun, 1 Jul 2018 12:43:25 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:37798 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1032077AbeGAQnQ (ORCPT ); Sun, 1 Jul 2018 12:43:16 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 4085CA73; Sun, 1 Jul 2018 16:43:15 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Robert Elliott , Dan Williams Subject: [PATCH 4.17 145/220] linvdimm, pmem: Preserve read-only setting for pmem devices Date: Sun, 1 Jul 2018 18:22:49 +0200 Message-Id: <20180701160914.368620326@linuxfoundation.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180701160908.272447118@linuxfoundation.org> References: <20180701160908.272447118@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.17-stable review patch. If anyone has any objections, please let me know. ------------------ From: Robert Elliott commit 254a4cd50b9fe2291a12b8902e08e56dcc4e9b10 upstream. The pmem driver does not honor a forced read-only setting for very long: $ blockdev --setro /dev/pmem0 $ blockdev --getro /dev/pmem0 1 followed by various commands like these: $ blockdev --rereadpt /dev/pmem0 or $ mkfs.ext4 /dev/pmem0 results in this in the kernel serial log: nd_pmem namespace0.0: region0 read-write, marking pmem0 read-write with the read-only setting lost: $ blockdev --getro /dev/pmem0 0 That's from bus.c nvdimm_revalidate_disk(), which always applies the setting from nd_region (which is initially based on the ACPI NFIT NVDIMM state flags not_armed bit). In contrast, commit 20bd1d026aac ("scsi: sd: Keep disk read-only when re-reading partition") fixed this issue for SCSI devices to preserve the previous setting if it was set to read-only. This patch modifies bus.c to preserve any previous read-only setting. It also eliminates the kernel serial log print except for cases where read-write is changed to read-only, so it doesn't print read-only to read-only non-changes. Cc: Fixes: 581388209405 ("libnvdimm, nfit: handle unarmed dimms, mark namespaces read-only") Signed-off-by: Robert Elliott Signed-off-by: Dan Williams Signed-off-by: Greg Kroah-Hartman --- drivers/nvdimm/bus.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) --- a/drivers/nvdimm/bus.c +++ b/drivers/nvdimm/bus.c @@ -566,14 +566,18 @@ int nvdimm_revalidate_disk(struct gendis { struct device *dev = disk_to_dev(disk)->parent; struct nd_region *nd_region = to_nd_region(dev->parent); - const char *pol = nd_region->ro ? "only" : "write"; + int disk_ro = get_disk_ro(disk); - if (nd_region->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) return 0; - dev_info(dev, "%s read-%s, marking %s read-%s\n", - dev_name(&nd_region->dev), pol, disk->disk_name, pol); - set_disk_ro(disk, nd_region->ro); + dev_info(dev, "%s read-only, marking %s read-only\n", + dev_name(&nd_region->dev), disk->disk_name); + set_disk_ro(disk, 1); return 0;