Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp3057703imm; Sun, 1 Jul 2018 11:14:55 -0700 (PDT) X-Google-Smtp-Source: ADUXVKIlwpE+E5j8z/Fla0/9tq/79ukee9RfZSDSeqZmFWy5xevnTgLjs9TowpFxXruPZosk1Ipd X-Received: by 2002:a65:4b4a:: with SMTP id k10-v6mr19749825pgt.12.1530468895331; Sun, 01 Jul 2018 11:14:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530468895; cv=none; d=google.com; s=arc-20160816; b=C6vQnCla8bf+2FYPkZNLQoeaf1/0oxd9iGQ+xXg+uFqTFma7nglJrwTIP/YXOJ9uOE wVfDPF6qo89Otg0C0guGr1aZu6ram0xyJdlX2l5j+TfJlfIWGSxTdR0z5ycGEKkh+QgS ZDcoh8v44p5jL8RFi6rsDRI+94R4D0sOoT1+ouoPDW269RdS1kfGknErOqsqQE+IxYeY w68ZI83E+rhCbBdgPf8kLFR0EsccLIjvwGPH8SqMS316OVK+ZFEGprAlP669BRFFNe/g PYUonREESEHXrfe4ydWnWu60WfUkzpLQX78nManUSxoq7dzc/8tZrT1IOjxso5+hqGZh OkOQ== 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=2qkmdlY5UkEMane+SDt/Jnxql7gUnG9ahk0v2m1PMTw=; b=gm5cqEL3oJA5/U+x4PDCQ7yREeCMKA6ilpyvKMfPI565G7Ouu5BRXHU+GLuZchU4kz 5tSrxdv1hH5g+bJz6jDvaeHds/DxMhF3NGjdezjdLJ9xqqFul8kVS3z2xtqsdJMEbBXd v+PgropbGZZVJ7d+UjBDXqyyHW2IlgdraLFYYD9oaCNuMcPV/0w0RXiSMYdorx5u2qw3 e8dT3cRnsHa+YI2nCSrovr/0+31GqtmAMknVCmIjHRfaTXKITASYLKR4/WQ39VZa0lnF Ri0HBcErGXJrHyIWg2DmRoalMBMOKLiGALHbXxy/e7O2Q4Feg9YJk3Lsv7VYV5BumyM3 BFyw== 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 r3-v6si12603687pgo.606.2018.07.01.11.14.41; Sun, 01 Jul 2018 11:14:55 -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 S965457AbeGAQ1M (ORCPT + 99 others); Sun, 1 Jul 2018 12:27:12 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:34028 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965191AbeGAQ1I (ORCPT ); Sun, 1 Jul 2018 12:27:08 -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 227F592B; Sun, 1 Jul 2018 16:27:06 +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.9 064/101] linvdimm, pmem: Preserve read-only setting for pmem devices Date: Sun, 1 Jul 2018 18:21:50 +0200 Message-Id: <20180701160759.723566185@linuxfoundation.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180701160757.138608453@linuxfoundation.org> References: <20180701160757.138608453@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.9-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 @@ -505,14 +505,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;