From patchwork Tue Nov 27 16:20:02 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oscar Salvador X-Patchwork-Id: 10700787 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1CD4D109C for ; Tue, 27 Nov 2018 16:20:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0C5102C0A7 for ; Tue, 27 Nov 2018 16:20:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 005FB2C068; Tue, 27 Nov 2018 16:20:46 +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 8FCA22C067 for ; Tue, 27 Nov 2018 16:20:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C39AF6B48F0; Tue, 27 Nov 2018 11:20:40 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id BC19E6B48F3; Tue, 27 Nov 2018 11:20:40 -0500 (EST) 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 9EDEC6B48F4; Tue, 27 Nov 2018 11:20:40 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pf1-f199.google.com (mail-pf1-f199.google.com [209.85.210.199]) by kanga.kvack.org (Postfix) with ESMTP id 526726B48F0 for ; Tue, 27 Nov 2018 11:20:40 -0500 (EST) Received: by mail-pf1-f199.google.com with SMTP id 68so14408424pfr.6 for ; Tue, 27 Nov 2018 08:20:40 -0800 (PST) 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:from:to:cc :subject:date:message-id:in-reply-to:references; bh=r9zH0dsu92dA/Tq/CzWHsmLnQoLC/zgThHTFaLEiF9U=; b=DlsrBvtLmocGC6o66IQ/uyDrBui42ESOZEIyO4NqgiJZYqTy6N7ltX8Ui8ji5yR+OG 2DDrNMSYvY4VtGcDh+bkU/R6QJkv5I6qSf5u+9J45OUfv58zbHBNLQ4Rqm6ml/ThcZBL IBXBCmz8RkcFtXadhDvSGLo292R2vNWgJsQ7egRn1dP3QL5LKuvkc9cy2eC3f4+WYRRp wskDrpATBbOUppay3uY9MFt2mw6qFEAok4zPynkAirb4XQpLb+Xf8KHfgYe1hL5W/iac j8aEhtRS6GMR5PGGzb/5pRFU0CyN2yzZmzC4S9NRG5VToEZenLqThoPke/eMUrUPv3Os MofQ== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of osalvador@suse.de designates 195.135.221.5 as permitted sender) smtp.mailfrom=osalvador@suse.de X-Gm-Message-State: AA+aEWYek6/rA2RAKQqxEuCWwZsjjyoRQylybFs7WppOlDDGkgSgNpPU yX0bXs32o36oR1UzgrYMo7WUK2uUowf9wCc47X4OluPrGMqiQkbru7T4Zx7T8tSJh9C6kCDvfrL xGbCtmIgOw+9x++uuewn+uLX4QrktYDdfwpPbwdQszGJUfx9A83Wlehg1imInKWQWkQ== X-Received: by 2002:a17:902:be0c:: with SMTP id r12mr19947745pls.299.1543335639927; Tue, 27 Nov 2018 08:20:39 -0800 (PST) X-Google-Smtp-Source: AFSGD/VWstrTsCMcrrD7M5waYfHsT9/Sc31FlecJ83baS7dWfZuG3DayZe/qAJYc2F7wGokKF5IA X-Received: by 2002:a17:902:be0c:: with SMTP id r12mr19947681pls.299.1543335638760; Tue, 27 Nov 2018 08:20:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543335638; cv=none; d=google.com; s=arc-20160816; b=Rlwf8h0KkLo9QOIFKPzrticGmT2KuS7bZUQUW5t1HusiEUwFm2r5/+d+HomMhMlsjC aI0aQDGcrCJ6BFjxUEQEg0jZztXrGrwop3j07c7ihwgEKmlgP1B1Y4j80CYzagCwu9GQ nrs3+Gy9uaGzOZOxGIberASmtTt2JvUGK8qhXUJOvXXzZyuuMreSEIpnmJbKOxyp8R+8 PkcCVv6SLhykZnEzc28AHBg0OUmirjlU631fVfPc4sNJXp3ar0uU2VA+3k2drn30zGjD TF8MilNLrwKvX4zzeI6itKYYf+rAL+e1U+KtBcThZk03ILtfMZeyiDOnTDmaCMD4kATm 9VKA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from; bh=r9zH0dsu92dA/Tq/CzWHsmLnQoLC/zgThHTFaLEiF9U=; b=zK7yE2J4vPudLRWw24/R0B87YDLh2uflQCcmfTV46SkmIj2axH/UPJD/wGCfIjvr2a DRmVmmLuWmJKcrcMcJw08TT8+G8V70jq1bsJYrE0JblieyPuYPgDrQ3oZLWNms1GDq/O azIu95hOW7aztYNaL+UxJ4jhikAISfikQOsU4eJ4lG4Gh/N4894SON6eXKLu7a/iDCGK OKAnyMduJRKFNWiITnfWQozdtbHbf0LniNODNXrJ84llPGPpPLtms5FRBs2QXjsOV9hs ehW9XBIDgQT+Yd24G+bHkB+IMLToFC2cgwXll8YRzg7/EDhaJDeupBE2tpAtmPV6gmZp MIMw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of osalvador@suse.de designates 195.135.221.5 as permitted sender) smtp.mailfrom=osalvador@suse.de Received: from smtp.nue.novell.com (smtp.nue.novell.com. [195.135.221.5]) by mx.google.com with ESMTPS id p26si5129609pli.225.2018.11.27.08.20.38 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 27 Nov 2018 08:20:38 -0800 (PST) Received-SPF: pass (google.com: domain of osalvador@suse.de designates 195.135.221.5 as permitted sender) client-ip=195.135.221.5; Authentication-Results: mx.google.com; spf=pass (google.com: domain of osalvador@suse.de designates 195.135.221.5 as permitted sender) smtp.mailfrom=osalvador@suse.de Received: from emea4-mta.ukb.novell.com ([10.120.13.87]) by smtp.nue.novell.com with ESMTP (TLS encrypted); Tue, 27 Nov 2018 17:20:36 +0100 Received: from d104.suse.de (nwb-a10-snat.microfocus.com [10.120.13.201]) by emea4-mta.ukb.novell.com with ESMTP (NOT encrypted); Tue, 27 Nov 2018 16:20:14 +0000 From: Oscar Salvador To: akpm@linux-foundation.org Cc: mhocko@suse.com, dan.j.williams@intel.com, pavel.tatashin@microsoft.com, jglisse@redhat.com, Jonathan.Cameron@huawei.com, rafael@kernel.org, david@redhat.com, linux-mm@kvack.org, Oscar Salvador Subject: [PATCH v2 2/5] kernel, resource: Check for IORESOURCE_SYSRAM in release_mem_region_adjustable Date: Tue, 27 Nov 2018 17:20:02 +0100 Message-Id: <20181127162005.15833-3-osalvador@suse.de> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20181127162005.15833-1-osalvador@suse.de> References: <20181127162005.15833-1-osalvador@suse.de> 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 This is a preparation for the next patch. Currently, we only call release_mem_region_adjustable() in __remove_pages if the zone is not ZONE_DEVICE, because resources that belong to HMM/devm are being released by themselves with devm_release_mem_region. Since we do not want to touch any zone/page stuff during the removing of the memory (but during the offlining), we do not want to check for the zone here. So we need another way to tell release_mem_region_adjustable() to not realease the resource in case it belongs to HMM/devm. HMM/devm acquires/releases a resource through devm_request_mem_region/devm_release_mem_region. These resources have the flag IORESOURCE_MEM, while resources acquired by hot-add memory path (register_memory_resource()) contain IORESOURCE_SYSTEM_RAM. So, we can check for this flag in release_mem_region_adjustable, and if the resource does not contain such flag, we know that we are dealing with a HMM/devm resource, so we can back off. Signed-off-by: Oscar Salvador Reviewed-by: David Hildenbrand Reviewed-by: Pavel Tatashin --- kernel/resource.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/kernel/resource.c b/kernel/resource.c index 0aaa95005a2e..e20cea416f1f 100644 --- a/kernel/resource.c +++ b/kernel/resource.c @@ -1266,6 +1266,21 @@ int release_mem_region_adjustable(struct resource *parent, continue; } + /* + * All memory regions added from memory-hotplug path have the + * flag IORESOURCE_SYSTEM_RAM. If the resource does not have + * this flag, we know that we are dealing with a resource coming + * from HMM/devm. HMM/devm use another mechanism to add/release + * a resource. This goes via devm_request_mem_region and + * devm_release_mem_region. + * HMM/devm take care to release their resources when they want, + * so if we are dealing with them, let us just back off here. + */ + if (!(res->flags & IORESOURCE_SYSRAM)) { + ret = 0; + break; + } + if (!(res->flags & IORESOURCE_MEM)) break;