Received: by 10.223.148.5 with SMTP id 5csp6591755wrq; Wed, 17 Jan 2018 16:08:16 -0800 (PST) X-Google-Smtp-Source: ACJfBotemeZamZm67qVlfqE/fXx5smRquYnuI5lSGm+XdZM/P5NpMyPDSFHoGQQIEMKAoO1Ce/Ww X-Received: by 10.101.70.140 with SMTP id h12mr4933227pgr.166.1516234096639; Wed, 17 Jan 2018 16:08:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516234096; cv=none; d=google.com; s=arc-20160816; b=tH+kkeSJpW0c4kFNuw5eAazoovtkr0EoQ8CZNbs8EywupgAqew9t73SnE8nVZo7p7x 8zBga/BDAJivM3JyHv11kEhPTUK1Twr9QYwmv/kFiefBDml4WXr+k9xusLtefioWUPlH yiNmrd3T49DOfg956gMU4ZYCU7lZ56qM5iyLx0dYZDvn9Y3+IzhuIUlanbLVh2q/rMMr wgtDAXTMmGKXhiDyzEAhm3HVZHSDNl0BkCCS8RUe4WBVgRSjm2WK5E3dG83OYWi2BDOJ Ok+E8U0l2ZxRP0KISakfGlehSYcdMQeX87kPPPQqvZ4RASke/anvvBB5umGyeb51JMmC Gi4A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=sr85YJ8NxXUHzTuP6EE4L4v3d3uSg5fo1Da9hzcofzY=; b=Ys0UwOZi74pCl9IwisVppHk7SF5sX871iUwZaXfYlyUl7GK8JT8V5qNuE9QHmHAXjc SDVsf/iistUigDUuIiIM5CaBfGGbI2fyYmZaig/idWTMK+SSzzsWiVOgwtWQoE4Hwdjz i7bGTXPWUjQm3QUA47MslsDnAmIvfalmXxCOE4M5fqQu97AOMJmqLhY9l0MmPZ+9WQkV 7lFhr5MMlPvKnKE4XYVNQJgKmLmJkTi9ZNS0M3ziL+CeYZl0yP8A2VLXww1vrp+RbZEy btwsMD0PhFDHuU9Rx7B/M+NxU4L9YKqqN47YrLIjKPJvDx84j2MKP//n8Wb7Wh0Usj2Q Tl9A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amazon.de header.s=amazon201209 header.b=vPN3rf2J; 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; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amazon.de Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r17si4761155pgu.809.2018.01.17.16.08.02; Wed, 17 Jan 2018 16:08:16 -0800 (PST) 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; dkim=pass header.i=@amazon.de header.s=amazon201209 header.b=vPN3rf2J; 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; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amazon.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754429AbeARAHM (ORCPT + 99 others); Wed, 17 Jan 2018 19:07:12 -0500 Received: from smtp-fw-9102.amazon.com ([207.171.184.29]:14929 "EHLO smtp-fw-9102.amazon.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752062AbeARAHL (ORCPT ); Wed, 17 Jan 2018 19:07:11 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.de; i=@amazon.de; q=dns/txt; s=amazon201209; t=1516234031; x=1547770031; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=sr85YJ8NxXUHzTuP6EE4L4v3d3uSg5fo1Da9hzcofzY=; b=vPN3rf2J/YQu0b/Q/sP0pHSJ6CvQgJgdvvSDw6VfIFIys4Kg7uyuX3pe fbs4DB9d0ASP62F8apoZ/P0GvnxV26yIatBd+VgejXNCu0jRS2GcWRxWk vUzhXU5gez1hzlgs+j4GrCwVzRX5sbUurtw3WUjsgon0Mu6UnXkbwusYd w=; X-IronPort-AV: E=Sophos;i="5.46,374,1511827200"; d="scan'208";a="587415159" Received: from sea3-co-svc-lb6-vlan3.sea.amazon.com (HELO email-inbound-relay-2a-e7be2041.us-west-2.amazon.com) ([10.47.22.38]) by smtp-border-fw-out-9102.sea19.amazon.com with ESMTP/TLS/DHE-RSA-AES256-SHA; 18 Jan 2018 00:07:09 +0000 Received: from u7588a65da6b65f.ant.amazon.com (pdx2-ws-svc-lb17-vlan3.amazon.com [10.247.140.70]) by email-inbound-relay-2a-e7be2041.us-west-2.amazon.com (8.14.7/8.14.7) with ESMTP id w0I075bc089458 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=FAIL); Thu, 18 Jan 2018 00:07:06 GMT Received: from u7588a65da6b65f.ant.amazon.com (localhost [127.0.0.1]) by u7588a65da6b65f.ant.amazon.com (8.15.2/8.15.2/Debian-3) with ESMTPS id w0I073KD005665 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 18 Jan 2018 01:07:04 +0100 Received: (from jschoenh@localhost) by u7588a65da6b65f.ant.amazon.com (8.15.2/8.15.2/Submit) id w0I072SZ005664; Thu, 18 Jan 2018 01:07:02 +0100 From: =?UTF-8?q?Jan=20H=2E=20Sch=C3=B6nherr?= To: Andrew Morton , Dan Williams Cc: =?UTF-8?q?Jan=20H=2E=20Sch=C3=B6nherr?= , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/2] mm: Fix devm_memremap_pages() collision handling Date: Thu, 18 Jan 2018 01:06:02 +0100 Message-Id: <20180118000602.5527-2-jschoenh@amazon.de> X-Mailer: git-send-email 2.9.3.1.gcba166c.dirty In-Reply-To: <20180118000602.5527-1-jschoenh@amazon.de> References: <20180118000602.5527-1-jschoenh@amazon.de> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org If devm_memremap_pages() detects a collision while adding entries to the radix-tree, we call pgmap_radix_release(). Unfortunately, the function removes *all* entries for the range -- including the entries that caused the collision in the first place. Modify pgmap_radix_release() to take an additional argument to indicate where to stop, so that only newly added entries are removed from the tree. Fixes: 9476df7d80df ("mm: introduce find_dev_pagemap()") Signed-off-by: Jan H. Schönherr --- kernel/memremap.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/kernel/memremap.c b/kernel/memremap.c index 4712ce6..2b136d4 100644 --- a/kernel/memremap.c +++ b/kernel/memremap.c @@ -248,13 +248,16 @@ int device_private_entry_fault(struct vm_area_struct *vma, EXPORT_SYMBOL(device_private_entry_fault); #endif /* CONFIG_DEVICE_PRIVATE */ -static void pgmap_radix_release(struct resource *res) +static void pgmap_radix_release(struct resource *res, unsigned long end_pgoff) { unsigned long pgoff, order; mutex_lock(&pgmap_lock); - foreach_order_pgoff(res, order, pgoff) + foreach_order_pgoff(res, order, pgoff) { + if (pgoff >= end_pgoff) + break; radix_tree_delete(&pgmap_radix, PHYS_PFN(res->start) + pgoff); + } mutex_unlock(&pgmap_lock); synchronize_rcu(); @@ -309,7 +312,7 @@ static void devm_memremap_pages_release(struct device *dev, void *data) mem_hotplug_done(); untrack_pfn(NULL, PHYS_PFN(align_start), align_size); - pgmap_radix_release(res); + pgmap_radix_release(res, -1); dev_WARN_ONCE(dev, pgmap->altmap && pgmap->altmap->alloc, "%s: failed to free all reserved pages\n", __func__); } @@ -459,7 +462,7 @@ void *devm_memremap_pages(struct device *dev, struct resource *res, untrack_pfn(NULL, PHYS_PFN(align_start), align_size); err_pfn_remap: err_radix: - pgmap_radix_release(res); + pgmap_radix_release(res, pgoff); devres_free(page_map); return ERR_PTR(error); } -- 2.9.3.1.gcba166c.dirty