Received: by 2002:a05:6a10:2785:0:0:0:0 with SMTP id ia5csp158110pxb; Tue, 12 Jan 2021 23:39:19 -0800 (PST) X-Google-Smtp-Source: ABdhPJwaVYo/GQl8wuvq6SDW73cNT0F06PS5OVbIZwG/MbY+3IxDABprD17BHV1oVeWRoa19tXOZ X-Received: by 2002:a17:906:660b:: with SMTP id b11mr690129ejp.458.1610523559270; Tue, 12 Jan 2021 23:39:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610523559; cv=none; d=google.com; s=arc-20160816; b=mOE6PVjSyF2slA0WGQCEHiA/2K+h6bv0/+E/Es17IvNRAe9bZLcHq82GhitvJnyNmM MGAZwnOtdE/ePgGZdx4RcqKvIXOqkpgfzOLhLuVDrkktVFJiImmO3p0sQ7Xyuuqrw9rU eydWB8aMNTgMqNm+amJiSL5CfqbMeAoQXwVfbrRgBXV1SGrgbWMBZytkJM/hcjEjeBSq jdMuyKvz7LM2ehVWVgXl0wRbFmwAZqV1A2jCD9xA+BAOCZZZ26w2Hcs6I2N91FVceqEe m6+jbJ/2aHRFOhCDkAlU0gOnzd5txOVCnxDSkEY2txbel0wZ9kaBqRSfL3HN/JYx5c0/ EdBQ== 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:references:in-reply-to:message-id:date:cc:to:from :subject:ironport-sdr:ironport-sdr; bh=wFVyGfvEcVNpNPx9M2h751f5qfcjzj0lhOdhuiW11uU=; b=wPGlW9rUMprnyWLwqDOnj0/gHhSRDPgVgZ9EtSrAGIaR8N1CyRJXLfui0pkcYHI1H0 ilNSv0KcRmT2Hay+DZ4lHu7zowOdTkihVPswQVJGlwWozrj+ECw3OwlivFuGExRwHNNY EBfQDDPZubeKPCthqRacWaGVI4JtCqZEpmEoN3Kgg1u8iV2ABNZ0cTQ9xPRLLRF/TMzT QVKf0OF4EeXgirObd5RM6yJY1Lrotx9Djj3V9bGd7Pv9Jb8miAuYZBqeuA5Zno7lvGIR xkiOYwvNrXFTjkCYiEUTuKjvRjYv/rDreEL5LqRSnprg8o5BgvUwihyWnvzTi0QTh+yI hxug== 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 jg13si658854ejc.669.2021.01.12.23.38.55; Tue, 12 Jan 2021 23:39:19 -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 S1726634AbhAMHg0 (ORCPT + 99 others); Wed, 13 Jan 2021 02:36:26 -0500 Received: from mga18.intel.com ([134.134.136.126]:49262 "EHLO mga18.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725998AbhAMHg0 (ORCPT ); Wed, 13 Jan 2021 02:36:26 -0500 IronPort-SDR: 0ZTcUgkjIh/yNbNuPlFX4Eh92VIxNAeqlXDa0fTzULOzdI+p3Exj+AiRGCygEphNA+NIqUJRUQ VtvaMQdQ1zig== X-IronPort-AV: E=McAfee;i="6000,8403,9862"; a="165840226" X-IronPort-AV: E=Sophos;i="5.79,343,1602572400"; d="scan'208";a="165840226" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Jan 2021 23:35:45 -0800 IronPort-SDR: 28I6HWqP63FwqhG/TATVhk4nMwwVx7CHClvMWqbcNPp9L92oWGDI0LkiW3eGlN1BmewynFs+zC hb9ByskkHLYQ== X-IronPort-AV: E=Sophos;i="5.79,343,1602572400"; d="scan'208";a="571943662" Received: from dwillia2-desk3.jf.intel.com (HELO dwillia2-desk3.amr.corp.intel.com) ([10.54.39.25]) by fmsmga005-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Jan 2021 23:35:44 -0800 Subject: [PATCH v3 5/6] mm: Fix memory_failure() handling of dax-namespace metadata From: Dan Williams To: linux-mm@kvack.org Cc: Naoya Horiguchi , Andrew Morton , David Hildenbrand , vishal.l.verma@intel.com, linux-nvdimm@lists.01.org, linux-kernel@vger.kernel.org Date: Tue, 12 Jan 2021 23:35:44 -0800 Message-ID: <161052334425.1805594.17861842381807251887.stgit@dwillia2-desk3.amr.corp.intel.com> In-Reply-To: <161052331545.1805594.2356512831689786960.stgit@dwillia2-desk3.amr.corp.intel.com> References: <161052331545.1805594.2356512831689786960.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 Given 'struct dev_pagemap' spans both data pages and metadata pages be careful to consult the altmap if present to delineate metadata. In fact the pfn_first() helper already identifies the first valid data pfn, so export that helper for other code paths via pgmap_pfn_valid(). Other usage of get_dev_pagemap() are not a concern because those are operating on known data pfns having been looking up by get_user_pages(). I.e. metadata pfns are never user mapped. Cc: Naoya Horiguchi Cc: Andrew Morton Reported-by: David Hildenbrand Signed-off-by: Dan Williams --- include/linux/memremap.h | 6 ++++++ mm/memory-failure.c | 6 ++++++ mm/memremap.c | 15 +++++++++++++++ 3 files changed, 27 insertions(+) diff --git a/include/linux/memremap.h b/include/linux/memremap.h index 79c49e7f5c30..f5b464daeeca 100644 --- a/include/linux/memremap.h +++ b/include/linux/memremap.h @@ -137,6 +137,7 @@ void *devm_memremap_pages(struct device *dev, struct dev_pagemap *pgmap); void devm_memunmap_pages(struct device *dev, struct dev_pagemap *pgmap); struct dev_pagemap *get_dev_pagemap(unsigned long pfn, struct dev_pagemap *pgmap); +bool pgmap_pfn_valid(struct dev_pagemap *pgmap, unsigned long pfn); unsigned long vmem_altmap_offset(struct vmem_altmap *altmap); void vmem_altmap_free(struct vmem_altmap *altmap, unsigned long nr_pfns); @@ -165,6 +166,11 @@ static inline struct dev_pagemap *get_dev_pagemap(unsigned long pfn, return NULL; } +static inline bool pgmap_pfn_valid(struct dev_pagemap *pgmap, unsigned long pfn) +{ + return false; +} + static inline unsigned long vmem_altmap_offset(struct vmem_altmap *altmap) { return 0; diff --git a/mm/memory-failure.c b/mm/memory-failure.c index 78b173c7190c..541569cb4a99 100644 --- a/mm/memory-failure.c +++ b/mm/memory-failure.c @@ -1308,6 +1308,12 @@ static int memory_failure_dev_pagemap(unsigned long pfn, int flags, */ put_page(page); + /* device metadata space is not recoverable */ + if (!pgmap_pfn_valid(pgmap, pfn)) { + rc = -ENXIO; + goto out; + } + /* * Prevent the inode from being freed while we are interrogating * the address_space, typically this would be handled by diff --git a/mm/memremap.c b/mm/memremap.c index 16b2fb482da1..2455bac89506 100644 --- a/mm/memremap.c +++ b/mm/memremap.c @@ -80,6 +80,21 @@ static unsigned long pfn_first(struct dev_pagemap *pgmap, int range_id) return pfn + vmem_altmap_offset(pgmap_altmap(pgmap)); } +bool pgmap_pfn_valid(struct dev_pagemap *pgmap, unsigned long pfn) +{ + int i; + + for (i = 0; i < pgmap->nr_range; i++) { + struct range *range = &pgmap->ranges[i]; + + if (pfn >= PHYS_PFN(range->start) && + pfn <= PHYS_PFN(range->end)) + return pfn >= pfn_first(pgmap, i); + } + + return false; +} + static unsigned long pfn_end(struct dev_pagemap *pgmap, int range_id) { const struct range *range = &pgmap->ranges[range_id];