From patchwork Mon Jul 17 21:27:39 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Verma, Vishal L" X-Patchwork-Id: 9846343 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 3C84260392 for ; Mon, 17 Jul 2017 21:29:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7146B274D0 for ; Mon, 17 Jul 2017 21:29:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6609727F81; Mon, 17 Jul 2017 21:29:40 +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=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id ECED126E4E for ; Mon, 17 Jul 2017 21:29:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752013AbdGQV3j (ORCPT ); Mon, 17 Jul 2017 17:29:39 -0400 Received: from mga14.intel.com ([192.55.52.115]:20874 "EHLO mga14.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751956AbdGQV3i (ORCPT ); Mon, 17 Jul 2017 17:29:38 -0400 Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 17 Jul 2017 14:29:38 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.40,375,1496127600"; d="scan'208";a="288033682" Received: from omniknight.lm.intel.com ([10.232.112.78]) by fmsmga004.fm.intel.com with ESMTP; 17 Jul 2017 14:29:37 -0700 From: Vishal Verma To: Cc: Dan Williams , Jeff Moyer , "Rafael J. Wysocki" , Toshi Kani , Vishal Verma , linux-acpi@vger.kernel.org, Robert Moore Subject: [PATCH v2 6/6] pmem, btt: fix potential deadlock while clearing errors Date: Mon, 17 Jul 2017 15:27:39 -0600 Message-Id: <20170717212739.5411-7-vishal.l.verma@intel.com> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20170717212739.5411-1-vishal.l.verma@intel.com> References: <20170717212739.5411-1-vishal.l.verma@intel.com> Sender: linux-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP With the ACPI NFIT 'DSM' methods, acpi can be called from IO paths. Specifically, the DSM to clear media errors is called during writes, so that we can provide a writes-fix-errors model. However it is easy to imagine a scenario like: -> write through the nvdimm driver -> acpi allocation -> writeback, causes more IO through the nvdimm driver -> deadlock Fix this by using memalloc_noio_{save,restore}, which sets the GFP_NOIO flag for the current scope when issuing commands/IOs that are expected to clear errors. Cc: Cc: Cc: Dan Williams Cc: Robert Moore Cc: Rafael J. Wysocki Signed-off-by: Vishal Verma --- drivers/nvdimm/btt.c | 8 +++++++- drivers/nvdimm/pmem.c | 4 ++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/drivers/nvdimm/btt.c b/drivers/nvdimm/btt.c index 48382ca9..25b576d 100644 --- a/drivers/nvdimm/btt.c +++ b/drivers/nvdimm/btt.c @@ -11,6 +11,7 @@ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * more details. */ +#include #include #include #include @@ -494,17 +495,22 @@ static int arena_clear_freelist_error(struct arena_info *arena, u32 lane) if (arena->freelist[lane].has_err) { u32 lba = arena->freelist[lane].block; u64 nsoff = to_namespace_offset(arena, lba); + unsigned int noio_flag; void *zerobuf; + noio_flag = memalloc_noio_save(); zerobuf = kzalloc(arena->sector_size, GFP_KERNEL); - if (!zerobuf) + if (!zerobuf) { + memalloc_noio_restore(noio_flag); return -ENOMEM; + } mutex_lock(&arena->freelist[lane].err_lock); ret = arena_write_bytes(arena, nsoff, zerobuf, arena->sector_size, 0); arena->freelist[lane].has_err = 0; mutex_unlock(&arena->freelist[lane].err_lock); + memalloc_noio_restore(noio_flag); kfree(zerobuf); } return ret; diff --git a/drivers/nvdimm/pmem.c b/drivers/nvdimm/pmem.c index 5c45e17..468e032 100644 --- a/drivers/nvdimm/pmem.c +++ b/drivers/nvdimm/pmem.c @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include @@ -53,12 +54,14 @@ static int pmem_clear_poison(struct pmem_device *pmem, phys_addr_t offset, unsigned int len) { struct device *dev = to_dev(pmem); + unsigned int noio_flag; sector_t sector; long cleared; int rc = 0; sector = (offset - pmem->data_offset) / 512; + noio_flag = memalloc_noio_save(); cleared = nvdimm_clear_poison(dev, pmem->phys_addr + offset, len); if (cleared < len) rc = -EIO; @@ -69,6 +72,7 @@ static int pmem_clear_poison(struct pmem_device *pmem, phys_addr_t offset, cleared > 1 ? "s" : ""); badblocks_clear(&pmem->bb, sector, cleared); } + memalloc_noio_restore(noio_flag); invalidate_pmem(pmem->virt_addr + offset, len);