From patchwork Mon May 21 22:35:24 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Dan Williams X-Patchwork-Id: 10417013 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 BDA72600CC for ; Mon, 21 May 2018 22:45:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AB40D28AB7 for ; Mon, 21 May 2018 22:45:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9FDB028AD0; Mon, 21 May 2018 22:45:25 +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=-2.9 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4919528ACE for ; Mon, 21 May 2018 22:45:24 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2D0C56B0006; Mon, 21 May 2018 18:45:23 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 257036B0007; Mon, 21 May 2018 18:45:23 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0F9A36B0008; Mon, 21 May 2018 18:45:23 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pl0-f70.google.com (mail-pl0-f70.google.com [209.85.160.70]) by kanga.kvack.org (Postfix) with ESMTP id BF8446B0006 for ; Mon, 21 May 2018 18:45:22 -0400 (EDT) Received: by mail-pl0-f70.google.com with SMTP id a5-v6so10778489plp.8 for ; Mon, 21 May 2018 15:45:22 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:subject:from :to:cc:date:message-id:in-reply-to:references:user-agent :mime-version:content-transfer-encoding; bh=hbeADj5VEdJCMLPcsBKuc9j+UyvB1Lw+KDJYgrneSrg=; b=lfWxqcFHMgzvfViT7Fb9aTxTVCHl8CnRzsRZY9OMTMBzCJOeNHOJL3mYOqD8MVc8KY wsSsvU6g9iYB7zqCxIS0U8tG6wI6nAzkqo7eONtwo8FpYsyjWSPkPGZO1UbncceVgwxW GA9gQ56Lom/uGUqqW1fJljcmENemj9slgxaB9T6k66HqVzWm9jpRTlNDoKfkXRxt/c80 V6sEfJuIs4kDE07mEGPMdOp42IncW14agl8COSEii6DlzVgIIRuu4c7neak6rAdJNpFA T69alj6bmKK0cdymK88LT0ll0QH52YDHX5rmpK7vnelc3oXGc5QMyaTY+mKVtZDtRjjU Vn8w== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of dan.j.williams@intel.com designates 134.134.136.65 as permitted sender) smtp.mailfrom=dan.j.williams@intel.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Gm-Message-State: ALKqPwdmRi2cjajwsbbAEvQYqHLOtEPQM3Ec7MJ5lpb9rxlGGgbw/mqV AlladiVh7iVLh3jiKYR409upE8OuUlzXo2negQI0n66nof5JfZI+k/7jSfZm0KflwQy5DfZrHNJ FoVnk9vr7KLsZfvj05J6pTIjLqn4oKM3rSjsE2UL2dwFp0roiFsLYuktY1GGWM0bvwA== X-Received: by 2002:a62:4ec8:: with SMTP id c191-v6mr21383955pfb.153.1526942722479; Mon, 21 May 2018 15:45:22 -0700 (PDT) X-Google-Smtp-Source: AB8JxZpirxbeH2JT4MzD2OsOAu9rs1BJH+McSptZyxG84f3GWr8tDYKPug1H5LzgbDwL7RE0ffOM X-Received: by 2002:a62:4ec8:: with SMTP id c191-v6mr21383924pfb.153.1526942721825; Mon, 21 May 2018 15:45:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526942721; cv=none; d=google.com; s=arc-20160816; b=OO3i4a89N5GlF/LjEAMmAqlfH4UK9vvrhhzNpss9zVoa7Jrc18YFLIqZzIx1ecI2Tx 7SlW11UdksP4fW1enY64wSbsKzmRw0ARgoa1AMcKmwtyBh2m6T23iS5qdvw/OxpPy2+V 16T2XtERrB+7i8Q/ba+9Ge5RLN7h1TjzCY30j80Z7MsAyARnCBYTQoKyrQ7zDnQfVvyo dK/qJDCnY8rSdq6KZpmoqtMU8iAFP+/hs9lkKkapstDMWfZeUY9z8iZd8H6JAPK6H1d1 gikLBPLyQdONGrOO8TWEq5APOVUREinGveTP54pd0Zxc34pWriK2Tcskpd3qZWKB0yQf OaQA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:user-agent:references :in-reply-to:message-id:date:cc:to:from:subject :arc-authentication-results; bh=hbeADj5VEdJCMLPcsBKuc9j+UyvB1Lw+KDJYgrneSrg=; b=Ftl3VtOfnK66TRhq/FNUBS8RkmjT/aa8DYAJSpruhzr5O1UANU+2/DCG+W7ZUbHh6P Mbl0Eavur0/rkeakJJcHBJ/62NaafPA5qk+8/h0ejhGtYd5LSU/nc3t+OC/egCbx2krt /6GkINCc2Oe/D+IhwqhtM9VkM/yHHOTNpa8syJ4tEA5G+L6haNMJNTne+95F9bxj6kZH 3+gUcXIPnNyjmIXw519B0PKz7xdEqrP3GU8vo4jhm7sc8j4LyOXzRoYwdseSUtlaNPE8 XCyDK8Dyw1HkbuJnAGkLYmR01IvZHvcK6oneip2bnIXTNyv4eooG5jKfezkAEOEnlGC6 tYrA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of dan.j.williams@intel.com designates 134.134.136.65 as permitted sender) smtp.mailfrom=dan.j.williams@intel.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from mga03.intel.com (mga03.intel.com. [134.134.136.65]) by mx.google.com with ESMTPS id q9-v6si14979324plr.144.2018.05.21.15.45.21 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 21 May 2018 15:45:21 -0700 (PDT) Received-SPF: pass (google.com: domain of dan.j.williams@intel.com designates 134.134.136.65 as permitted sender) client-ip=134.134.136.65; Authentication-Results: mx.google.com; spf=pass (google.com: domain of dan.j.williams@intel.com designates 134.134.136.65 as permitted sender) smtp.mailfrom=dan.j.williams@intel.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga103.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 21 May 2018 15:45:21 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.49,427,1520924400"; d="scan'208";a="43098907" Received: from dwillia2-desk3.jf.intel.com (HELO dwillia2-desk3.amr.corp.intel.com) ([10.54.39.16]) by orsmga008.jf.intel.com with ESMTP; 21 May 2018 15:45:21 -0700 Subject: [PATCH 2/5] mm, devm_memremap_pages: handle errors allocating final devres action From: Dan Williams To: akpm@linux-foundation.org Cc: stable@vger.kernel.org, Christoph Hellwig , =?utf-8?b?SsOpcsO0bWU=?= Glisse , Logan Gunthorpe , linux-mm@kvack.org, linux-kernel@vger.kernel.org Date: Mon, 21 May 2018 15:35:24 -0700 Message-ID: <152694212460.5484.13180030631810166467.stgit@dwillia2-desk3.amr.corp.intel.com> In-Reply-To: <152694211402.5484.2277538346144115181.stgit@dwillia2-desk3.amr.corp.intel.com> References: <152694211402.5484.2277538346144115181.stgit@dwillia2-desk3.amr.corp.intel.com> User-Agent: StGit/0.18-2-gc94f MIME-Version: 1.0 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP The last step before devm_memremap_pages() returns success is to allocate a release action to tear the entire setup down. However, the result from devm_add_action() is not checked. Checking the error also means that we need to handle the fact that the percpu_ref may not be killed by the time devm_memremap_pages_release() runs. Add a new state flag for this case. Cc: Fixes: e8d513483300 ("memremap: change devm_memremap_pages interface...") Cc: Christoph Hellwig Cc: "Jérôme Glisse" Cc: Logan Gunthorpe Signed-off-by: Dan Williams Reviewed-by: Christoph Hellwig --- include/linux/memremap.h | 1 + kernel/memremap.c | 8 ++++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/include/linux/memremap.h b/include/linux/memremap.h index 7b4899c06f49..44a7ee517513 100644 --- a/include/linux/memremap.h +++ b/include/linux/memremap.h @@ -115,6 +115,7 @@ struct dev_pagemap { dev_page_free_t page_free; struct vmem_altmap altmap; bool altmap_valid; + bool registered; struct resource res; struct percpu_ref *ref; struct device *dev; diff --git a/kernel/memremap.c b/kernel/memremap.c index c614645227a7..30d96be5a965 100644 --- a/kernel/memremap.c +++ b/kernel/memremap.c @@ -296,7 +296,7 @@ static void devm_memremap_pages_release(void *data) for_each_device_pfn(pfn, pgmap) put_page(pfn_to_page(pfn)); - if (percpu_ref_tryget_live(pgmap->ref)) { + if (pgmap->registered && percpu_ref_tryget_live(pgmap->ref)) { dev_WARN(dev, "%s: page mapping is still live!\n", __func__); percpu_ref_put(pgmap->ref); } @@ -418,7 +418,11 @@ void *devm_memremap_pages(struct device *dev, struct dev_pagemap *pgmap) percpu_ref_get(pgmap->ref); } - devm_add_action(dev, devm_memremap_pages_release, pgmap); + error = devm_add_action_or_reset(dev, devm_memremap_pages_release, + pgmap); + if (error) + return ERR_PTR(error); + pgmap->registered = true; return __va(res->start);