From patchwork Wed Apr 24 10:25:05 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 10914457 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 74AFF922 for ; Wed, 24 Apr 2019 10:25:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6555128A6D for ; Wed, 24 Apr 2019 10:25:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5949828A70; Wed, 24 Apr 2019 10:25:45 +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=unavailable 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 0024C28A6D for ; Wed, 24 Apr 2019 10:25:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 45AC46B0007; Wed, 24 Apr 2019 06:25:42 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 40C836B0008; Wed, 24 Apr 2019 06:25:42 -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 2AD666B000C; Wed, 24 Apr 2019 06:25:42 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-qt1-f198.google.com (mail-qt1-f198.google.com [209.85.160.198]) by kanga.kvack.org (Postfix) with ESMTP id 0C1496B0007 for ; Wed, 24 Apr 2019 06:25:42 -0400 (EDT) Received: by mail-qt1-f198.google.com with SMTP id p26so17238637qtq.21 for ; Wed, 24 Apr 2019 03:25:42 -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:from:to:cc :subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=X3Se80q1dKdim+vPqx/FPGIOapUfHtVIBKJDjYe8V8k=; b=QjbP70HAIyzVPochIxS7B32gcF4un4fcd4JqiB3e+JJsXUMpQolaL3o/mwe1+B1VDN E6IkgBJY1Al3FPwcEwUrDel/cmXFoaRnb/FqAQHvtoDGB64Vb0J9mT6Ial88pYxuhieq gcEO5wjgoZGTZu5tYunFRiF4rwY8ukJira4DKL9nXMUin4vDvGowX+6VTSS5EvZ+7Lq9 zCO3SCQ8TDo5/nIka75kI4Vhf9Dw69tu8BP0306RE04p2fR1c3KHfgpNFXYtGRb2ZzOD YzxDJlvYBNSOj6W7gGF2XUkGx+uEiJNJJ3SFmSoFI7T89Tj9gJHRYbGUpWBnW8s0NAhG kL/w== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of david@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com X-Gm-Message-State: APjAAAUGJ8r9k8bJEFTlY8uWRr9RTaToX4ETUVUt8SAx9fOx20/FtEOk GloT2iTIWH1XRMD+3+58vZVias3lk8WkUwZXINMHLPon3jA/3XFiGeqf1hag5S8IhcSIIEWVBGJ oP7HwtS1d9ybOfgdrcDl0mSSzIDAJyNsIaQiqXxl9320SGRJQUTZ1P757uozWOQ9Rlw== X-Received: by 2002:a05:6214:162:: with SMTP id y2mr5270025qvs.157.1556101541825; Wed, 24 Apr 2019 03:25:41 -0700 (PDT) X-Google-Smtp-Source: APXvYqz1M3V8eS4QwXdPjVL12zypdmXXxd9zWHJSLSB87matZkh/mYtaMph02DAB4fbI9iXMENJl X-Received: by 2002:a05:6214:162:: with SMTP id y2mr5269977qvs.157.1556101540980; Wed, 24 Apr 2019 03:25:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556101540; cv=none; d=google.com; s=arc-20160816; b=HHWJ+Q9oDlgGvujWU+crFYq24zRmJdW5eBct+TBe3u+xRbw2+QjglCcgrWaCBt9cQi MMalsp1CTkv1/GDaKxdkdr7KtvuRQ1KJghKEbyst2Xr0MdNIQ3FOYpGEkHqp2oGhsY+8 uYCDmMJQH9Kw9eFDUrPTuYbbUgfba4hEBaImRtNufS5/TTRkqi3dxMJFfBQj8y2lVBOI aypfM9PNIjRcdmgsfWqJGRe+M9pGYfYAIPqNm10xNhFYZtCGQw7F1nzwDQUAMTtlW0PL vX0nG4nu0y+74b5UxIS79QDHtfQR8P56m6A8Z9nTa6B5t4BPxjO9Uxlc4uo51SLse6If e3cA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from; bh=X3Se80q1dKdim+vPqx/FPGIOapUfHtVIBKJDjYe8V8k=; b=lncWN2VEWVkdkl/C1XNeXa9pSnSOGjYF1x1KL/rAaqTGD1/7Vcl80MOEgWyTLmUNeo /9R9yUTY8JZ6VN80JkRF5TiFD9uV/6gckyMpYtXqdrcK4Zi2nsa1ZuuAtQJwyEVxeIXA zX9MWQcbWJX2NADYUJZdJUw4YPVXMsQ14+pAQUep+dxo4gyl2boqM33OoYkjppsjrVzc UYQS9syvmJXEQdlH1gmHSSZyr5OqOJ8KFR89AQk3PMqP5bZI8JCsmYvgzGuTHwealPdA 7xCkj8IGRfUSYbhQ+K2fp6Wu5sw7uhmMMcNib0tIIjP4YGyoVM0uPSHd6GwRt1235vQK WlpA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of david@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from mx1.redhat.com (mx1.redhat.com. [209.132.183.28]) by mx.google.com with ESMTPS id b5si1182817qtr.404.2019.04.24.03.25.40 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 24 Apr 2019 03:25:40 -0700 (PDT) Received-SPF: pass (google.com: domain of david@redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; Authentication-Results: mx.google.com; spf=pass (google.com: domain of david@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 10061308FB9D; Wed, 24 Apr 2019 10:25:39 +0000 (UTC) Received: from t460s.redhat.com (ovpn-116-45.ams2.redhat.com [10.36.116.45]) by smtp.corp.redhat.com (Postfix) with ESMTP id F03CD600C1; Wed, 24 Apr 2019 10:25:33 +0000 (UTC) From: David Hildenbrand To: linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org, linux-ia64@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-s390@vger.kernel.org, linux-sh@vger.kernel.org, akpm@linux-foundation.org, Dan Williams , David Hildenbrand , Oscar Salvador , Michal Hocko , Pavel Tatashin , Qian Cai , Wei Yang , Arun KS , Mathieu Malaterre Subject: [PATCH v1 1/7] mm/memory_hotplug: Simplify and fix check_hotplug_memory_range() Date: Wed, 24 Apr 2019 12:25:05 +0200 Message-Id: <20190424102511.29318-2-david@redhat.com> In-Reply-To: <20190424102511.29318-1-david@redhat.com> References: <20190424102511.29318-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.43]); Wed, 24 Apr 2019 10:25:39 +0000 (UTC) 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 By converting start and size to page granularity, we actually ignore unaligned parts within a page instead of properly bailing out with an error. Cc: Andrew Morton Cc: Oscar Salvador Cc: Michal Hocko Cc: David Hildenbrand Cc: Pavel Tatashin Cc: Qian Cai Cc: Wei Yang Cc: Arun KS Cc: Mathieu Malaterre Signed-off-by: David Hildenbrand --- mm/memory_hotplug.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c index 328878b6799d..202febe88b58 100644 --- a/mm/memory_hotplug.c +++ b/mm/memory_hotplug.c @@ -1050,16 +1050,11 @@ int try_online_node(int nid) static int check_hotplug_memory_range(u64 start, u64 size) { - unsigned long block_sz = memory_block_size_bytes(); - u64 block_nr_pages = block_sz >> PAGE_SHIFT; - u64 nr_pages = size >> PAGE_SHIFT; - u64 start_pfn = PFN_DOWN(start); - /* memory range must be block size aligned */ - if (!nr_pages || !IS_ALIGNED(start_pfn, block_nr_pages) || - !IS_ALIGNED(nr_pages, block_nr_pages)) { + if (!size || !IS_ALIGNED(start, memory_block_size_bytes()) || + !IS_ALIGNED(size, memory_block_size_bytes())) { pr_err("Block size [%#lx] unaligned hotplug range: start %#llx, size %#llx", - block_sz, start, size); + memory_block_size_bytes(), start, size); return -EINVAL; } From patchwork Wed Apr 24 10:25:06 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 10914459 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 640D01515 for ; Wed, 24 Apr 2019 10:25:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 546DA28A72 for ; Wed, 24 Apr 2019 10:25:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 487D728A74; Wed, 24 Apr 2019 10:25:48 +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 2F19628A6D for ; Wed, 24 Apr 2019 10:25:47 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 23D156B0008; Wed, 24 Apr 2019 06:25:44 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 1CDDB6B000C; Wed, 24 Apr 2019 06:25:44 -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 EC1B76B000D; Wed, 24 Apr 2019 06:25:43 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-qk1-f197.google.com (mail-qk1-f197.google.com [209.85.222.197]) by kanga.kvack.org (Postfix) with ESMTP id C443E6B0008 for ; Wed, 24 Apr 2019 06:25:43 -0400 (EDT) Received: by mail-qk1-f197.google.com with SMTP id t67so10206163qkd.15 for ; Wed, 24 Apr 2019 03:25:43 -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:from:to:cc :subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=Sstr/K0HceJCPLq+MhzSzTpSmFovLaEMCGEENQ8I26Y=; b=Y3t1sShMXfhDhJ9Gao9GtLePmNMkE5oAAJZaAZ7F5nzE1cuSnI8dKsOdN7QnrCeZ/N 4DO2h4AjaWr6mG6DYo7WQtU3SB4QmL0eDd2oG2Z8lXRcsBRcPAsXwLH6wRub3G9EJKmC 45mnM3kRMV2CyjOpfRzM5QRxFB8SMs/oD36v+xfO1wJoLAQ3A9OVSN9+KTafIg73gN7V /pKZr9fgpnTuEVluCgZqFzi0nL/jerVRFtaH1PZVV3FMMY0eSYqiQNqjKSyunak0/uq7 E4Yo6JPstzX5BVTInn9GzPB9VQNW78rRB7QuIAGsab8nRcT8yJ0vS4prXqhu7j9zXxw6 //Wg== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of david@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com X-Gm-Message-State: APjAAAUSbd/MPDrBVmNP74ZMaMXrSsLdyv/aXyaPOrtvPKzS5n5kw5sZ vKMnM7+nJ/c9miRMeOsmPSvz/8OSkTE77ghKArji8Fv4zQgimD6f8Ejk1ulACCebJW6mYju0Rvm JmrskqqRW68J5KXlGJUKkClzpdZkDI5oiac7pxELKUY5lqiBp2t1sT3fKicc8LMIU7g== X-Received: by 2002:ac8:74d6:: with SMTP id j22mr5135052qtr.144.1556101543583; Wed, 24 Apr 2019 03:25:43 -0700 (PDT) X-Google-Smtp-Source: APXvYqx64zuXMgoeTF83FCEa5ZmbEVOjuJzIVFNxwHgDZuvW3jAXEEjW15E0g212YPwys2UeH6Qb X-Received: by 2002:ac8:74d6:: with SMTP id j22mr5135012qtr.144.1556101543004; Wed, 24 Apr 2019 03:25:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556101542; cv=none; d=google.com; s=arc-20160816; b=OVI8mQ1fpCGR5yIgdgFP9fqxj2y3YdUZ8gE6pWvd/C5SpBHgf7vc1b1bOOxM40iZPk bMgZI2t9Onn1hNIKgaXHCp52sBGk4p/QjQcmMh5e1UCrAl1q+uXzhHsvML8mlxmpDhGl aQhndjX/z8hXKcEDqNjztl+13zX9tYgS9xzMuppDngCropgWEmEVidXevGfwOtV7m03T M1bqQktDbtiRMV+/dcaBt8VjqaRRB/U4aX8ik8l/1KlKwBEB1CQHRcMvXtLksU2jcp20 7rOXw8vm+oX1WQz6jlCRVmEwfqS5k7Ih9By+l6IkJq2CIZ2GePeA/XOFaWfJn2hyuLGP enJg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from; bh=Sstr/K0HceJCPLq+MhzSzTpSmFovLaEMCGEENQ8I26Y=; b=Z6MV9KiHtq3CiZFzAFfaNhqffqn15PsgOWfGZWLj/M7XFCNB/Z/B+4OOYZVbpt9IQk +dGmMMzv/KkYUe1ASgXeaja4bJ5pA2B1/evACrDXtK2mEdQDHoDqrS8dC8nARTBYiisO ZczvyxuA1xjaMnMhzKOU03cPj+EZKO6Lu1jSrphpP4gljcDfXCVKipQyVHBnPtHMSoYv i8uHxCrPd33BZGzVQQT9BDLt5q89TV4ySerIuQjiXORYGqcJexr3u46bFI2D97UFcOmC tWHeLqklF141y5898127TsvSa6UVrD9c240IsdBe1FSI2g8ehw+i7Tmif8SiIeLiMjtA bL7Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of david@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from mx1.redhat.com (mx1.redhat.com. [209.132.183.28]) by mx.google.com with ESMTPS id c9si4814226qte.102.2019.04.24.03.25.42 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 24 Apr 2019 03:25:42 -0700 (PDT) Received-SPF: pass (google.com: domain of david@redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; Authentication-Results: mx.google.com; spf=pass (google.com: domain of david@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2D2062D6A11; Wed, 24 Apr 2019 10:25:42 +0000 (UTC) Received: from t460s.redhat.com (ovpn-116-45.ams2.redhat.com [10.36.116.45]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6357E600C1; Wed, 24 Apr 2019 10:25:39 +0000 (UTC) From: David Hildenbrand To: linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org, linux-ia64@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-s390@vger.kernel.org, linux-sh@vger.kernel.org, akpm@linux-foundation.org, Dan Williams , David Hildenbrand , Martin Schwidefsky , Heiko Carstens , Michal Hocko , Mike Rapoport , Vasily Gorbik , Oscar Salvador Subject: [PATCH v1 2/7] s390x/mm: Implement arch_remove_memory() Date: Wed, 24 Apr 2019 12:25:06 +0200 Message-Id: <20190424102511.29318-3-david@redhat.com> In-Reply-To: <20190424102511.29318-1-david@redhat.com> References: <20190424102511.29318-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Wed, 24 Apr 2019 10:25:42 +0000 (UTC) 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 Will come in handy when wanting to handle errors after arch_add_memory(). Cc: Martin Schwidefsky Cc: Heiko Carstens Cc: Andrew Morton Cc: Michal Hocko Cc: Mike Rapoport Cc: David Hildenbrand Cc: Vasily Gorbik Cc: Oscar Salvador Signed-off-by: David Hildenbrand --- arch/s390/mm/init.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/arch/s390/mm/init.c b/arch/s390/mm/init.c index 31b1071315d7..2636d62df04e 100644 --- a/arch/s390/mm/init.c +++ b/arch/s390/mm/init.c @@ -237,12 +237,13 @@ int arch_add_memory(int nid, u64 start, u64 size, void arch_remove_memory(int nid, u64 start, u64 size, struct vmem_altmap *altmap) { - /* - * There is no hardware or firmware interface which could trigger a - * hot memory remove on s390. So there is nothing that needs to be - * implemented. - */ - BUG(); + unsigned long start_pfn = start >> PAGE_SHIFT; + unsigned long nr_pages = size >> PAGE_SHIFT; + struct zone *zone; + + vmem_remove_mapping(start, size); + zone = page_zone(pfn_to_page(start_pfn)); + __remove_pages(zone, start_pfn, nr_pages, altmap); } #endif #endif /* CONFIG_MEMORY_HOTPLUG */ From patchwork Wed Apr 24 10:25:07 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 10914463 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 CA392922 for ; Wed, 24 Apr 2019 10:25:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B893728A6D for ; Wed, 24 Apr 2019 10:25:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AC42328A70; Wed, 24 Apr 2019 10:25:56 +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 8094D28A6D for ; Wed, 24 Apr 2019 10:25:55 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 78F6E6B000C; Wed, 24 Apr 2019 06:25:54 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 742906B000D; Wed, 24 Apr 2019 06:25:54 -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 62D936B000E; Wed, 24 Apr 2019 06:25:54 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-qk1-f199.google.com (mail-qk1-f199.google.com [209.85.222.199]) by kanga.kvack.org (Postfix) with ESMTP id 40A356B000C for ; Wed, 24 Apr 2019 06:25:54 -0400 (EDT) Received: by mail-qk1-f199.google.com with SMTP id q79so858561qke.18 for ; Wed, 24 Apr 2019 03:25:54 -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:from:to:cc :subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=KPf8h/IzMsCll1/Af/aIy5UPE0Ln9eS1RQdhTbcxmok=; b=GxW3gzrIkXQ5Fob1QJiZligwy/mgbEQM+e7cRRRoWZq3tNVtKq9PO9FidAU1xDITjS cqtXq7kLXZqiYzqCsbNjce6iKrRZuLXCfItGT3qiEfRa5R5YNpAy2ivj6TVTzojWIVvL XicLlr49+T+In9utQwZS0sQNIEVrqaT/kfpFAimbZdZN8GXX0nBvPdClyd248ymWk5RL WEU7WOCIc6Y5i89y5l2EScgip5xTwwa+k5x0FX7gGBKQT9/dm8ea+7jkvc7/m2OtNKv4 LtJVigupoM2GmrqOgqdCcvwtUo43K1G1lWNBftINLx/EOR9noKyjOxQmJQG2y5Ly4/cl 9/Gw== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of david@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com X-Gm-Message-State: APjAAAVop5KiFZSmxrTcnHwEl8GLp1oFKSbwflulSLlqem8KYllx1x1B kavwVgEWlHHUwJC8zy0E15iLHhtPG5BKfl7rsRLPvpRsAzlPCkpGAZ4FwdTUGVgKTXzbxRXZ8Gi 8Qmz9heJvrj1HtZmzmDi/wgd5MAKsO/STYZGZWngMumQ1BrPOM+qWJYPd77JA/IC6Xg== X-Received: by 2002:ac8:67c8:: with SMTP id r8mr19912586qtp.370.1556101553992; Wed, 24 Apr 2019 03:25:53 -0700 (PDT) X-Google-Smtp-Source: APXvYqxcQe0BFcq+pABLGFyAp7kkRmncRQQRVopl2qOqr6MB0WeXBV/HgsAURKUnxJ54ivd1c41t X-Received: by 2002:ac8:67c8:: with SMTP id r8mr19912490qtp.370.1556101552431; Wed, 24 Apr 2019 03:25:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556101552; cv=none; d=google.com; s=arc-20160816; b=k6nkWhn8zSMgvHVDNIP3H0NP7H34WAc7n+g6eGioGmnZvWQci6NuYoN1zdmBVdwMfm GR7MxO0W79Zrb3G4CffMneFxTGL53U5XXhoOvn7v9yZtpgp/PpeqkPCsbSYvvyOJpK4i xxCpWmK7vOUWyc6kpwSjw5HXpU2TaMyNvrLpX+p+zPWU29DXBaD4YwGnFQXNjHTQkJDP BKBbPSE99LfFaRNARQHGB9m5fcF8m6hqZjGJQF6ViHJwgGmf74uHPt4bPsS7KqnTCs5/ 3l9CkDATxpD7aFu3uCBCk1NaT2kTGuZ2OoDfP/XVWLLWdhOqOXpFPTj6CpRmfH96JhuX 7rCw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from; bh=KPf8h/IzMsCll1/Af/aIy5UPE0Ln9eS1RQdhTbcxmok=; b=Sum6YYPX+8DnHNGAotZnXoP34IMHTCi54P175BG/zC/qnLIakSq6wg3Q+38qIVCaKz mz58MC5MdoFq3KW9pyqZGf1ljo49mHfvnOPJcH+T+Z/OvE12AoHDQY/tzkqyE6RI9Q7h Nf2BZx0KKbccRqs4vWGxCA0cI3elyVJ2s+F22Q1LDKKPMbcFxYlC8vzTQs9zp5pT1kce aWhVCM95snvrFQDp/QkCcIUlw5JoqZzhbR1AfwL4590eCTkbZ97Co3uPptx1AxgtqvfH P/cqxQHE5GSi3p0tLb7SAj3oQGrRwaDF6yFCS11GKodWtN5Qq2VZFJDxXiv/uQHKqzeb Jmlg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of david@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from mx1.redhat.com (mx1.redhat.com. [209.132.183.28]) by mx.google.com with ESMTPS id c21si2570502qtb.51.2019.04.24.03.25.52 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 24 Apr 2019 03:25:52 -0700 (PDT) Received-SPF: pass (google.com: domain of david@redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; Authentication-Results: mx.google.com; spf=pass (google.com: domain of david@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 094AEC06A7EF; Wed, 24 Apr 2019 10:25:51 +0000 (UTC) Received: from t460s.redhat.com (ovpn-116-45.ams2.redhat.com [10.36.116.45]) by smtp.corp.redhat.com (Postfix) with ESMTP id 80B97600C1; Wed, 24 Apr 2019 10:25:42 +0000 (UTC) From: David Hildenbrand To: linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org, linux-ia64@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-s390@vger.kernel.org, linux-sh@vger.kernel.org, akpm@linux-foundation.org, Dan Williams , David Hildenbrand , Tony Luck , Fenghua Yu , Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman , Martin Schwidefsky , Heiko Carstens , Yoshinori Sato , Rich Felker , Dave Hansen , Andy Lutomirski , Peter Zijlstra , Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H. Peter Anvin" , Greg Kroah-Hartman , "Rafael J. Wysocki" , Michal Hocko , Mike Rapoport , Oscar Salvador , "Kirill A. Shutemov" , Alex Deucher , "David S. Miller" , Mark Brown , Chris Wilson , Christophe Leroy , Nicholas Piggin , Vasily Gorbik , Rob Herring , Masahiro Yamada , "mike.travis@hpe.com" , Andrew Banman , Pavel Tatashin , Wei Yang , Arun KS , Qian Cai , Mathieu Malaterre , Baoquan He , Logan Gunthorpe Subject: [PATCH v1 3/7] mm/memory_hotplug: arch_remove_memory() and __remove_pages() with CONFIG_MEMORY_HOTPLUG Date: Wed, 24 Apr 2019 12:25:07 +0200 Message-Id: <20190424102511.29318-4-david@redhat.com> In-Reply-To: <20190424102511.29318-1-david@redhat.com> References: <20190424102511.29318-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Wed, 24 Apr 2019 10:25:51 +0000 (UTC) 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 Let's prepare for better error handling while adding memory by allowing to use arch_remove_memory() and __remove_pages() even if CONFIG_MEMORY_HOTREMOVE is not set. CONFIG_MEMORY_HOTREMOVE effectively covers - Offlining of system ram (memory block devices) - offline_pages() - Unplug of system ram - remove_memory() - Unplug/remap of device memory - devm_memremap() This allows e.g. for handling like arch_add_memory() rc = do_something(); if (rc) { arch_remove_memory(); } Whereby do_something() will for example be memory block device creation after it has been factored out. Cc: Tony Luck Cc: Fenghua Yu Cc: Benjamin Herrenschmidt Cc: Paul Mackerras Cc: Michael Ellerman Cc: Martin Schwidefsky Cc: Heiko Carstens Cc: Yoshinori Sato Cc: Rich Felker Cc: Dave Hansen Cc: Andy Lutomirski Cc: Peter Zijlstra Cc: Thomas Gleixner Cc: Ingo Molnar Cc: Borislav Petkov Cc: "H. Peter Anvin" Cc: Greg Kroah-Hartman Cc: "Rafael J. Wysocki" Cc: Andrew Morton Cc: Michal Hocko Cc: Mike Rapoport Cc: David Hildenbrand Cc: Oscar Salvador Cc: "Kirill A. Shutemov" Cc: Alex Deucher Cc: "David S. Miller" Cc: Mark Brown Cc: Chris Wilson Cc: Christophe Leroy Cc: Nicholas Piggin Cc: Vasily Gorbik Cc: Rob Herring Cc: Masahiro Yamada Cc: "mike.travis@hpe.com" Cc: Andrew Banman Cc: Pavel Tatashin Cc: Wei Yang Cc: Arun KS Cc: Qian Cai Cc: Mathieu Malaterre Cc: Baoquan He Cc: Logan Gunthorpe Signed-off-by: David Hildenbrand --- arch/ia64/mm/init.c | 2 -- arch/powerpc/mm/mem.c | 2 -- arch/s390/mm/init.c | 2 -- arch/sh/mm/init.c | 2 -- arch/x86/mm/init_32.c | 2 -- arch/x86/mm/init_64.c | 2 -- drivers/base/memory.c | 2 -- include/linux/memory.h | 2 -- include/linux/memory_hotplug.h | 2 -- mm/memory_hotplug.c | 2 -- mm/sparse.c | 6 ------ 11 files changed, 26 deletions(-) diff --git a/arch/ia64/mm/init.c b/arch/ia64/mm/init.c index d28e29103bdb..aae75fd7b810 100644 --- a/arch/ia64/mm/init.c +++ b/arch/ia64/mm/init.c @@ -681,7 +681,6 @@ int arch_add_memory(int nid, u64 start, u64 size, return ret; } -#ifdef CONFIG_MEMORY_HOTREMOVE void arch_remove_memory(int nid, u64 start, u64 size, struct vmem_altmap *altmap) { @@ -693,4 +692,3 @@ void arch_remove_memory(int nid, u64 start, u64 size, __remove_pages(zone, start_pfn, nr_pages, altmap); } #endif -#endif diff --git a/arch/powerpc/mm/mem.c b/arch/powerpc/mm/mem.c index c14fc0bd422d..28fea4c56cd4 100644 --- a/arch/powerpc/mm/mem.c +++ b/arch/powerpc/mm/mem.c @@ -131,7 +131,6 @@ int __ref arch_add_memory(int nid, u64 start, u64 size, struct vmem_altmap *altm return __add_pages(nid, start_pfn, nr_pages, restrictions); } -#ifdef CONFIG_MEMORY_HOTREMOVE int __ref arch_remove_memory(int nid, u64 start, u64 size, struct vmem_altmap *altmap) { @@ -164,7 +163,6 @@ int __ref arch_remove_memory(int nid, u64 start, u64 size, resize_hpt_for_hotplug(memblock_phys_mem_size()); } #endif -#endif /* CONFIG_MEMORY_HOTPLUG */ #ifndef CONFIG_NEED_MULTIPLE_NODES void __init mem_topology_setup(void) diff --git a/arch/s390/mm/init.c b/arch/s390/mm/init.c index 2636d62df04e..5874cfb392da 100644 --- a/arch/s390/mm/init.c +++ b/arch/s390/mm/init.c @@ -233,7 +233,6 @@ int arch_add_memory(int nid, u64 start, u64 size, return rc; } -#ifdef CONFIG_MEMORY_HOTREMOVE void arch_remove_memory(int nid, u64 start, u64 size, struct vmem_altmap *altmap) { @@ -245,5 +244,4 @@ void arch_remove_memory(int nid, u64 start, u64 size, zone = page_zone(pfn_to_page(start_pfn)); __remove_pages(zone, start_pfn, nr_pages, altmap); } -#endif #endif /* CONFIG_MEMORY_HOTPLUG */ diff --git a/arch/sh/mm/init.c b/arch/sh/mm/init.c index 5aeb4d7099a1..59c5fe511f25 100644 --- a/arch/sh/mm/init.c +++ b/arch/sh/mm/init.c @@ -428,7 +428,6 @@ int memory_add_physaddr_to_nid(u64 addr) EXPORT_SYMBOL_GPL(memory_add_physaddr_to_nid); #endif -#ifdef CONFIG_MEMORY_HOTREMOVE void arch_remove_memory(int nid, u64 start, u64 size, struct vmem_altmap *altmap) { @@ -439,5 +438,4 @@ void arch_remove_memory(int nid, u64 start, u64 size, zone = page_zone(pfn_to_page(start_pfn)); __remove_pages(zone, start_pfn, nr_pages, altmap); } -#endif #endif /* CONFIG_MEMORY_HOTPLUG */ diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c index 075e568098f2..8d4bf2d97d50 100644 --- a/arch/x86/mm/init_32.c +++ b/arch/x86/mm/init_32.c @@ -859,7 +859,6 @@ int arch_add_memory(int nid, u64 start, u64 size, return __add_pages(nid, start_pfn, nr_pages, restrictions); } -#ifdef CONFIG_MEMORY_HOTREMOVE void arch_remove_memory(int nid, u64 start, u64 size, struct vmem_altmap *altmap) { @@ -871,7 +870,6 @@ void arch_remove_memory(int nid, u64 start, u64 size, __remove_pages(zone, start_pfn, nr_pages, altmap); } #endif -#endif int kernel_set_to_readonly __read_mostly; diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c index 20d14254b686..f1b55ddea23f 100644 --- a/arch/x86/mm/init_64.c +++ b/arch/x86/mm/init_64.c @@ -1131,7 +1131,6 @@ void __ref vmemmap_free(unsigned long start, unsigned long end, remove_pagetable(start, end, false, altmap); } -#ifdef CONFIG_MEMORY_HOTREMOVE static void __meminit kernel_physical_mapping_remove(unsigned long start, unsigned long end) { @@ -1156,7 +1155,6 @@ void __ref arch_remove_memory(int nid, u64 start, u64 size, __remove_pages(zone, start_pfn, nr_pages, altmap); kernel_physical_mapping_remove(start, start + size); } -#endif #endif /* CONFIG_MEMORY_HOTPLUG */ static struct kcore_list kcore_vsyscall; diff --git a/drivers/base/memory.c b/drivers/base/memory.c index f180427e48f4..6e0cb4fda179 100644 --- a/drivers/base/memory.c +++ b/drivers/base/memory.c @@ -728,7 +728,6 @@ int hotplug_memory_register(int nid, struct mem_section *section) return ret; } -#ifdef CONFIG_MEMORY_HOTREMOVE static void unregister_memory(struct memory_block *memory) { @@ -767,7 +766,6 @@ void unregister_memory_section(struct mem_section *section) out_unlock: mutex_unlock(&mem_sysfs_mutex); } -#endif /* CONFIG_MEMORY_HOTREMOVE */ /* return true if the memory block is offlined, otherwise, return false */ bool is_memblock_offlined(struct memory_block *mem) diff --git a/include/linux/memory.h b/include/linux/memory.h index e1dc1bb2b787..474c7c60c8f2 100644 --- a/include/linux/memory.h +++ b/include/linux/memory.h @@ -112,9 +112,7 @@ extern void unregister_memory_notifier(struct notifier_block *nb); extern int register_memory_isolate_notifier(struct notifier_block *nb); extern void unregister_memory_isolate_notifier(struct notifier_block *nb); int hotplug_memory_register(int nid, struct mem_section *section); -#ifdef CONFIG_MEMORY_HOTREMOVE extern void unregister_memory_section(struct mem_section *); -#endif extern int memory_dev_init(void); extern int memory_notify(unsigned long val, void *v); extern int memory_isolate_notify(unsigned long val, void *v); diff --git a/include/linux/memory_hotplug.h b/include/linux/memory_hotplug.h index ae892eef8b82..2d4de313926d 100644 --- a/include/linux/memory_hotplug.h +++ b/include/linux/memory_hotplug.h @@ -123,12 +123,10 @@ static inline bool movable_node_is_enabled(void) return movable_node_enabled; } -#ifdef CONFIG_MEMORY_HOTREMOVE extern void arch_remove_memory(int nid, u64 start, u64 size, struct vmem_altmap *altmap); extern void __remove_pages(struct zone *zone, unsigned long start_pfn, unsigned long nr_pages, struct vmem_altmap *altmap); -#endif /* CONFIG_MEMORY_HOTREMOVE */ /* * Do we want sysfs memblock files created. This will allow userspace to online diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c index 202febe88b58..7b5439839d67 100644 --- a/mm/memory_hotplug.c +++ b/mm/memory_hotplug.c @@ -317,7 +317,6 @@ int __ref __add_pages(int nid, unsigned long phys_start_pfn, return err; } -#ifdef CONFIG_MEMORY_HOTREMOVE /* find the smallest valid pfn in the range [start_pfn, end_pfn) */ static unsigned long find_smallest_section_pfn(int nid, struct zone *zone, unsigned long start_pfn, @@ -581,7 +580,6 @@ void __remove_pages(struct zone *zone, unsigned long phys_start_pfn, set_zone_contiguous(zone); } -#endif /* CONFIG_MEMORY_HOTREMOVE */ int set_online_page_callback(online_page_callback_t callback) { diff --git a/mm/sparse.c b/mm/sparse.c index fd13166949b5..d1d5e05f5b8d 100644 --- a/mm/sparse.c +++ b/mm/sparse.c @@ -604,7 +604,6 @@ static void __kfree_section_memmap(struct page *memmap, vmemmap_free(start, end, altmap); } -#ifdef CONFIG_MEMORY_HOTREMOVE static void free_map_bootmem(struct page *memmap) { unsigned long start = (unsigned long)memmap; @@ -612,7 +611,6 @@ static void free_map_bootmem(struct page *memmap) vmemmap_free(start, end, NULL); } -#endif /* CONFIG_MEMORY_HOTREMOVE */ #else static struct page *__kmalloc_section_memmap(void) { @@ -651,7 +649,6 @@ static void __kfree_section_memmap(struct page *memmap, get_order(sizeof(struct page) * PAGES_PER_SECTION)); } -#ifdef CONFIG_MEMORY_HOTREMOVE static void free_map_bootmem(struct page *memmap) { unsigned long maps_section_nr, removing_section_nr, i; @@ -681,7 +678,6 @@ static void free_map_bootmem(struct page *memmap) put_page_bootmem(page); } } -#endif /* CONFIG_MEMORY_HOTREMOVE */ #endif /* CONFIG_SPARSEMEM_VMEMMAP */ /** @@ -746,7 +742,6 @@ int __meminit sparse_add_one_section(int nid, unsigned long start_pfn, return ret; } -#ifdef CONFIG_MEMORY_HOTREMOVE #ifdef CONFIG_MEMORY_FAILURE static void clear_hwpoisoned_pages(struct page *memmap, int nr_pages) { @@ -823,5 +818,4 @@ void sparse_remove_one_section(struct zone *zone, struct mem_section *ms, PAGES_PER_SECTION - map_offset); free_section_usemap(memmap, usemap, altmap); } -#endif /* CONFIG_MEMORY_HOTREMOVE */ #endif /* CONFIG_MEMORY_HOTPLUG */ From patchwork Wed Apr 24 10:25:08 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 10914465 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 76AF5922 for ; Wed, 24 Apr 2019 10:26:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6228B28A6D for ; Wed, 24 Apr 2019 10:26:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 566B928A70; Wed, 24 Apr 2019 10:26:01 +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 4616728A6D for ; Wed, 24 Apr 2019 10:25:59 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C725E6B000D; Wed, 24 Apr 2019 06:25:57 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id C21386B000E; Wed, 24 Apr 2019 06:25:57 -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 AE9506B0010; Wed, 24 Apr 2019 06:25:57 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-qk1-f200.google.com (mail-qk1-f200.google.com [209.85.222.200]) by kanga.kvack.org (Postfix) with ESMTP id 8B8E26B000D for ; Wed, 24 Apr 2019 06:25:57 -0400 (EDT) Received: by mail-qk1-f200.google.com with SMTP id t67so10206549qkd.15 for ; Wed, 24 Apr 2019 03:25:57 -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:from:to:cc :subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=B1Kd+1vGze1HjX/yglunSURjRhlNiu1tUGyDV/OWBKI=; b=RJ/lzcTFWHAmlOtqIH9NKM4ME6teyc82TJyoq7H7+inoFCZSybt5eAO4nAsspWEhtC Zn7kEEfLsMynrJPCWjgrbvhTc+nmdcIq5m8l+bvGctI5NdFTKiXuP3UiqXUBy/bQIuAG CXQwJTajczGWPbLqgpyqccujmU2FnWVP0jTy+xWD9oEuFBApCEBbw4FXqiA7UIHEayjo gmXWCCRvg/nmzxAdv2WBHwTSBSMFHZ9rMb7dy0u4+Mh52CGvUp9tQbwjYekijPUpAeYB 8Fy/0ZVZh/5mtUvQEfBWKxXeQENHGsYbM402lwqbrcN8OzH0QGHiw0w89j8G7b4RL5O5 512A== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of david@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com X-Gm-Message-State: APjAAAVkgvjURa2ysc1F72802cOs7FCyjM8+9TEtBKNakp8yoU1tqKRu vr4ksajLb9zItqI9SFLcovgm9C5WlgSoCm7jNO6JpzvRhCFTP0TvNnr5qukH91EE+SbuQZ9ZCQ3 NID0RwFWz8A4m0cxjsjxoE6Bv3K5cBY3dCFkcOroof89km1COVsCkv2Z0pkL8Ioal1Q== X-Received: by 2002:ac8:2a51:: with SMTP id l17mr24943470qtl.76.1556101557304; Wed, 24 Apr 2019 03:25:57 -0700 (PDT) X-Google-Smtp-Source: APXvYqyTmBPm2rPlwzWygiy13iuU13fi9TUkzREZd4HBk4Rh0X0l7QkhVjEFaTxlO+T0+Qvm4G+y X-Received: by 2002:ac8:2a51:: with SMTP id l17mr24943399qtl.76.1556101556066; Wed, 24 Apr 2019 03:25:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556101556; cv=none; d=google.com; s=arc-20160816; b=Q02zxo/cW8H7iKZqIvHZiUtRtSStN71zZzxwMdiIjet3CVISJ7gP7+ydMDn3qxM1XO 3KsvbzSQnhtkOQDHE4v/T0sjTvoGkMghgbvZ1mbeM8GAQAaQpEksg3knCvt3dXsJThV5 dfkH9eamnfmQeA+g/8JiWZRETRoR+84w7ljx9f89lvUFHK6ZD2Lk9sPl1mIuRQ/Hrw5z C0eo0FJLiEbf5875nD2VsV6nR1fVZiNEuZtSnG/FgU/cqSQwPcETfxwihvjTtSIYklE7 IrEZG2fFHsQyO6Oioikgb7FBh+uULAPhOx+0y040Tc+y31/IluHf/MGcxEPxQph6qWJm 30BQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from; bh=B1Kd+1vGze1HjX/yglunSURjRhlNiu1tUGyDV/OWBKI=; b=yas9/rQxtHkNlbxhVlsBHwdmB7UgDP4871/m0LCnoidqslFiVGVUmyKAUursYPluNX j4qmSfnAhe/EciGQ4Ig6gpTvbTb4SqZyU+LFZSwOiLn+SUzc0+qfSR8wofTBf9mAIs+a 1RlNvo9AAo1v+DPYmZqajTzM0BomOSET8sKQsm9taliG0lVj70XcGcqqfFiJErmQP9/U rQ8gV0Ne2mtm6tigIs6TGDvrah7VcOwjpJm/UiPi0SjbUiBN4EhZ6WQUfe4wNmw5plFc WLEekrQmRJ4/uKT3kt80A5T8vL8DCY8UhC5sc7JFmFKqMqy/c9e7YT0kZtuz/DR6gge/ gJOQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of david@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from mx1.redhat.com (mx1.redhat.com. [209.132.183.28]) by mx.google.com with ESMTPS id 31si1681000qto.242.2019.04.24.03.25.55 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 24 Apr 2019 03:25:56 -0700 (PDT) Received-SPF: pass (google.com: domain of david@redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; Authentication-Results: mx.google.com; spf=pass (google.com: domain of david@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 21AB530A818B; Wed, 24 Apr 2019 10:25:55 +0000 (UTC) Received: from t460s.redhat.com (ovpn-116-45.ams2.redhat.com [10.36.116.45]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5D0EA600C4; Wed, 24 Apr 2019 10:25:51 +0000 (UTC) From: David Hildenbrand To: linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org, linux-ia64@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-s390@vger.kernel.org, linux-sh@vger.kernel.org, akpm@linux-foundation.org, Dan Williams , David Hildenbrand , Greg Kroah-Hartman , "Rafael J. Wysocki" , "mike.travis@hpe.com" , Ingo Molnar , Andrew Banman , Oscar Salvador , Michal Hocko , Pavel Tatashin , Qian Cai , Wei Yang , Arun KS , Mathieu Malaterre Subject: [PATCH v1 4/7] mm/memory_hotplug: Create memory block devices after arch_add_memory() Date: Wed, 24 Apr 2019 12:25:08 +0200 Message-Id: <20190424102511.29318-5-david@redhat.com> In-Reply-To: <20190424102511.29318-1-david@redhat.com> References: <20190424102511.29318-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.44]); Wed, 24 Apr 2019 10:25:55 +0000 (UTC) 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 Only memory to be added to the buddy and to be onlined/offlined by user space using memory block devices needs (and should have!) memory block devices. Factor out creation of memory block devices Create all devices after arch_add_memory() succeeded. We can later drop the want_memblock parameter, because it is now effectively stale. Only after memory block devices have been added, memory can be onlined by user space. This implies, that memory is not visible to user space at all before arch_add_memory() succeeded. Cc: Greg Kroah-Hartman Cc: "Rafael J. Wysocki" Cc: David Hildenbrand Cc: "mike.travis@hpe.com" Cc: Andrew Morton Cc: Ingo Molnar Cc: Andrew Banman Cc: Oscar Salvador Cc: Michal Hocko Cc: Pavel Tatashin Cc: Qian Cai Cc: Wei Yang Cc: Arun KS Cc: Mathieu Malaterre Signed-off-by: David Hildenbrand --- drivers/base/memory.c | 70 ++++++++++++++++++++++++++---------------- include/linux/memory.h | 2 +- mm/memory_hotplug.c | 15 ++++----- 3 files changed, 53 insertions(+), 34 deletions(-) diff --git a/drivers/base/memory.c b/drivers/base/memory.c index 6e0cb4fda179..862c202a18ca 100644 --- a/drivers/base/memory.c +++ b/drivers/base/memory.c @@ -701,44 +701,62 @@ static int add_memory_block(int base_section_nr) return 0; } +static void unregister_memory(struct memory_block *memory) +{ + BUG_ON(memory->dev.bus != &memory_subsys); + + /* drop the ref. we got via find_memory_block() */ + put_device(&memory->dev); + device_unregister(&memory->dev); +} + /* - * need an interface for the VM to add new memory regions, - * but without onlining it. + * Create memory block devices for the given memory area. Start and size + * have to be aligned to memory block granularity. Memory block devices + * will be initialized as offline. */ -int hotplug_memory_register(int nid, struct mem_section *section) +int hotplug_memory_register(unsigned long start, unsigned long size) { - int ret = 0; + unsigned long block_nr_pages = memory_block_size_bytes() >> PAGE_SHIFT; + unsigned long start_pfn = PFN_DOWN(start); + unsigned long end_pfn = start_pfn + (size >> PAGE_SHIFT); + unsigned long pfn; struct memory_block *mem; + int ret = 0; - mutex_lock(&mem_sysfs_mutex); + BUG_ON(!IS_ALIGNED(start, memory_block_size_bytes())); + BUG_ON(!IS_ALIGNED(size, memory_block_size_bytes())); - mem = find_memory_block(section); - if (mem) { - mem->section_count++; - put_device(&mem->dev); - } else { - ret = init_memory_block(&mem, section, MEM_OFFLINE); + mutex_lock(&mem_sysfs_mutex); + for (pfn = start_pfn; pfn != end_pfn; pfn += block_nr_pages) { + mem = find_memory_block(__pfn_to_section(pfn)); + if (mem) { + WARN_ON_ONCE(false); + put_device(&mem->dev); + continue; + } + ret = init_memory_block(&mem, __pfn_to_section(pfn), + MEM_OFFLINE); if (ret) - goto out; - mem->section_count++; + break; + mem->section_count = memory_block_size_bytes() / + MIN_MEMORY_BLOCK_SIZE; + } + if (ret) { + end_pfn = pfn; + for (pfn = start_pfn; pfn != end_pfn; pfn += block_nr_pages) { + mem = find_memory_block(__pfn_to_section(pfn)); + if (!mem) + continue; + mem->section_count = 0; + unregister_memory(mem); + } } - -out: mutex_unlock(&mem_sysfs_mutex); return ret; } -static void -unregister_memory(struct memory_block *memory) -{ - BUG_ON(memory->dev.bus != &memory_subsys); - - /* drop the ref. we got via find_memory_block() */ - put_device(&memory->dev); - device_unregister(&memory->dev); -} - -void unregister_memory_section(struct mem_section *section) +static int remove_memory_section(struct mem_section *section) { struct memory_block *mem; diff --git a/include/linux/memory.h b/include/linux/memory.h index 474c7c60c8f2..95505fbb5f85 100644 --- a/include/linux/memory.h +++ b/include/linux/memory.h @@ -111,7 +111,7 @@ extern int register_memory_notifier(struct notifier_block *nb); extern void unregister_memory_notifier(struct notifier_block *nb); extern int register_memory_isolate_notifier(struct notifier_block *nb); extern void unregister_memory_isolate_notifier(struct notifier_block *nb); -int hotplug_memory_register(int nid, struct mem_section *section); +int hotplug_memory_register(unsigned long start, unsigned long size); extern void unregister_memory_section(struct mem_section *); extern int memory_dev_init(void); extern int memory_notify(unsigned long val, void *v); diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c index 7b5439839d67..e1637c8a0723 100644 --- a/mm/memory_hotplug.c +++ b/mm/memory_hotplug.c @@ -258,13 +258,7 @@ static int __meminit __add_section(int nid, unsigned long phys_start_pfn, return -EEXIST; ret = sparse_add_one_section(nid, phys_start_pfn, altmap); - if (ret < 0) - return ret; - - if (!want_memblock) - return 0; - - return hotplug_memory_register(nid, __pfn_to_section(phys_start_pfn)); + return ret < 0 ? ret : 0; } /* @@ -1106,6 +1100,13 @@ int __ref add_memory_resource(int nid, struct resource *res) if (ret < 0) goto error; + /* create memory block devices after memory was added */ + ret = hotplug_memory_register(start, size); + if (ret) { + arch_remove_memory(nid, start, size, NULL); + goto error; + } + if (new_node) { /* If sysfs file of new node can't be created, cpu on the node * can't be hot-added. There is no rollback way now. From patchwork Wed Apr 24 10:25:09 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 10914471 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 68725922 for ; Wed, 24 Apr 2019 10:26:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5862428A6D for ; Wed, 24 Apr 2019 10:26:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4C25828A70; Wed, 24 Apr 2019 10:26:04 +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=unavailable 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 CF6C828A6D for ; Wed, 24 Apr 2019 10:26:03 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A9DCA6B000E; Wed, 24 Apr 2019 06:26:02 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id A4BD36B0010; Wed, 24 Apr 2019 06:26:02 -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 9681B6B0266; Wed, 24 Apr 2019 06:26:02 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-qt1-f197.google.com (mail-qt1-f197.google.com [209.85.160.197]) by kanga.kvack.org (Postfix) with ESMTP id 72D286B000E for ; Wed, 24 Apr 2019 06:26:02 -0400 (EDT) Received: by mail-qt1-f197.google.com with SMTP id z34so17287910qtz.14 for ; Wed, 24 Apr 2019 03:26:02 -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:from:to:cc :subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=1AHud2ZD6tXhbo4XTIHImH/7A+j/bT1tgyCj7c12ovw=; b=b7M2DWA8mZ6e25mvXbPRedANDWjQdOEfKt5J1dm5swsYy7HQseidVUBwgneA1x+tSn 5ox73Eox3bFgXZ92aBo3ysihGsW967Vlx5QDBnpJRVec93++ukrpETB8ZA4kdtvg8YBo JIH2fAj6+QheEH7bsJqkkJJZsn2b/QlJs78aDTRssyxrdzIsJ79E2gmNwvjTJX1Mrjo2 QBBU6NRGd+Td5y2YgxnOER7YyptqwKDhFeMO3UZ05VxSr8IHl83H+sdmob7bP6IUusOj hnXZTzFQIlBE6a8PtKVWr481Psyf0DK/7poQsrHGaXOjR0/KXhpP4pFKw+tkd+y3PelW vazw== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of david@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com X-Gm-Message-State: APjAAAWiGQBNJBURdrm/lLwFiMYU5h3TflUkkhbbWr1ktdfx4WMuyGPe uskvyisDPaeSKPt3B6bZS0yhyS0DNPgnvBDpWql0mfNWTKqi8J2x0lqMvoet20ffDZ1p5XLII08 R61IG1YMUwNBWF3naqnBArQ8OS0MtE2I/Z/ZCEV4w41DOzeItQuWLxtmcKM8PqYbJHQ== X-Received: by 2002:ae9:f00e:: with SMTP id l14mr24180692qkg.127.1556101562235; Wed, 24 Apr 2019 03:26:02 -0700 (PDT) X-Google-Smtp-Source: APXvYqxwDOqvJqpBoUGUCEKgAIj9gvr9W+EXAm8uSmW1ebFfA/D2LWN2S6YofR/ubbkVzfUAw7tK X-Received: by 2002:ae9:f00e:: with SMTP id l14mr24180649qkg.127.1556101561615; Wed, 24 Apr 2019 03:26:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556101561; cv=none; d=google.com; s=arc-20160816; b=ZHhSAEEq0uBw9CV+mBPE+zwgQOAcTVSiRV43ATepFeJrhBHSnpALFsOyL3LCTIjOcJ LKwF4PTe9rHU29ld2cNlBManZxzmVsWQeqy4x/c1sotW+XBtgnvXT0uRYbBG6odnTxaP NgpKFN3bkN+BEskLK4c/Qp0z1yGjC7fMszzkXyWX2WdbfEBZRO9xJd4WZsh+bvyd5MeK IPWw42JihkRc4tYj+Yg+qsWI2QIErwQvnekl9CHyyznSUzzJyuUzcFYRBdbQCDqe2OAM cNP36pUuzOeDmG0f03OmXR7PrEvcU+tVhMfo5EtskLIs3xmTvBf+gsL9Vp9D5hZq+WvY 8bQg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from; bh=1AHud2ZD6tXhbo4XTIHImH/7A+j/bT1tgyCj7c12ovw=; b=fb8msNhvZTMTZrdIQjp/twkhkwKUd74XEXHCdHScsoxik0UCcZi+TUvwIrhoocpzPF C3noyAZJ70s/7vxlicbeoweiYiiN+SftwGrHcxgaVyIca7TksHFTDGx7ISrA3796vUAf QDeQHmsW5ap7gfxfBWFNznVQiqYJkmBqVvTkvxvrJdvOOtDL5nY9pzAy99gJxV/UdGIK AwzjE2ZPhDHp8DGlH0pTZRbLrvQOe25pufGg/xmLNsB4UYjz6GcPnIlS3wuJWfC9V1ie Wm1c1qTFYpQlSXSPf/Uh/k5XwTmPCghgMtSHa2prqr7qIG78/ZlQpYwrEc7q3WO3PANW cDqQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of david@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from mx1.redhat.com (mx1.redhat.com. [209.132.183.28]) by mx.google.com with ESMTPS id o4si1207581qkb.139.2019.04.24.03.26.01 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 24 Apr 2019 03:26:01 -0700 (PDT) Received-SPF: pass (google.com: domain of david@redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; Authentication-Results: mx.google.com; spf=pass (google.com: domain of david@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B2E9F8AE76; Wed, 24 Apr 2019 10:26:00 +0000 (UTC) Received: from t460s.redhat.com (ovpn-116-45.ams2.redhat.com [10.36.116.45]) by smtp.corp.redhat.com (Postfix) with ESMTP id 776E0600C4; Wed, 24 Apr 2019 10:25:55 +0000 (UTC) From: David Hildenbrand To: linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org, linux-ia64@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-s390@vger.kernel.org, linux-sh@vger.kernel.org, akpm@linux-foundation.org, Dan Williams , David Hildenbrand , Michal Hocko , Oscar Salvador , Pavel Tatashin , Wei Yang , Joonsoo Kim , Qian Cai , Arun KS , Mathieu Malaterre Subject: [PATCH v1 5/7] mm/memory_hotplug: Drop MHP_MEMBLOCK_API Date: Wed, 24 Apr 2019 12:25:09 +0200 Message-Id: <20190424102511.29318-6-david@redhat.com> In-Reply-To: <20190424102511.29318-1-david@redhat.com> References: <20190424102511.29318-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Wed, 24 Apr 2019 10:26:00 +0000 (UTC) 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 No longer needed, the callers of arch_add_memory() can handle this manually. Cc: Andrew Morton Cc: David Hildenbrand Cc: Michal Hocko Cc: Oscar Salvador Cc: Pavel Tatashin Cc: Wei Yang Cc: Joonsoo Kim Cc: Qian Cai Cc: Arun KS Cc: Mathieu Malaterre Signed-off-by: David Hildenbrand --- include/linux/memory_hotplug.h | 8 -------- mm/memory_hotplug.c | 9 +++------ 2 files changed, 3 insertions(+), 14 deletions(-) diff --git a/include/linux/memory_hotplug.h b/include/linux/memory_hotplug.h index 2d4de313926d..2f1f87e13baa 100644 --- a/include/linux/memory_hotplug.h +++ b/include/linux/memory_hotplug.h @@ -128,14 +128,6 @@ extern void arch_remove_memory(int nid, u64 start, u64 size, extern void __remove_pages(struct zone *zone, unsigned long start_pfn, unsigned long nr_pages, struct vmem_altmap *altmap); -/* - * Do we want sysfs memblock files created. This will allow userspace to online - * and offline memory explicitly. Lack of this bit means that the caller has to - * call move_pfn_range_to_zone to finish the initialization. - */ - -#define MHP_MEMBLOCK_API (1<<0) - /* reasonably generic interface to expand the physical pages */ extern int __add_pages(int nid, unsigned long start_pfn, unsigned long nr_pages, struct mhp_restrictions *restrictions); diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c index e1637c8a0723..107f72952347 100644 --- a/mm/memory_hotplug.c +++ b/mm/memory_hotplug.c @@ -250,7 +250,7 @@ void __init register_page_bootmem_info_node(struct pglist_data *pgdat) #endif /* CONFIG_HAVE_BOOTMEM_INFO_NODE */ static int __meminit __add_section(int nid, unsigned long phys_start_pfn, - struct vmem_altmap *altmap, bool want_memblock) + struct vmem_altmap *altmap) { int ret; @@ -293,8 +293,7 @@ int __ref __add_pages(int nid, unsigned long phys_start_pfn, } for (i = start_sec; i <= end_sec; i++) { - err = __add_section(nid, section_nr_to_pfn(i), altmap, - restrictions->flags & MHP_MEMBLOCK_API); + err = __add_section(nid, section_nr_to_pfn(i), altmap); /* * EEXIST is finally dealt with by ioresource collision @@ -1066,9 +1065,7 @@ static int online_memory_block(struct memory_block *mem, void *arg) */ int __ref add_memory_resource(int nid, struct resource *res) { - struct mhp_restrictions restrictions = { - .flags = MHP_MEMBLOCK_API, - }; + struct mhp_restrictions restrictions = {}; u64 start, size; bool new_node = false; int ret; From patchwork Wed Apr 24 10:25:10 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 10914475 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 BE5861515 for ; Wed, 24 Apr 2019 10:26:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AAF0D28A71 for ; Wed, 24 Apr 2019 10:26:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9EFA428A74; Wed, 24 Apr 2019 10:26:11 +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=unavailable 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 E7A8D28A71 for ; Wed, 24 Apr 2019 10:26:10 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CE7576B0010; Wed, 24 Apr 2019 06:26:09 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id C97BE6B0266; Wed, 24 Apr 2019 06:26:09 -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 B5F536B0269; Wed, 24 Apr 2019 06:26:09 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-qk1-f200.google.com (mail-qk1-f200.google.com [209.85.222.200]) by kanga.kvack.org (Postfix) with ESMTP id 969E36B0010 for ; Wed, 24 Apr 2019 06:26:09 -0400 (EDT) Received: by mail-qk1-f200.google.com with SMTP id i124so15545931qkf.14 for ; Wed, 24 Apr 2019 03:26:09 -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:from:to:cc :subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=6alr3xAWbp/4sFY4rIt7l7CbtIsbDy+NJtgQONgCG9U=; b=tupqHzxJCNMATs6nsr451eHD/55oCHrsecqBO3bq0xJZ2MSQNz2HO+CW31/AKpxe6l n+yxs+aIo5MokdQrom2QDxTv3yfLVbX2IzI1UDfcZIeEZ0zetZCjdSQpmbac7O7xDZvc x765Q56fdGNXvU/aOzC8TPMUsdpVOxo5BXcfjUeoQfSHFFya3v1E2Rn41yVdT1fMIyW1 Ui1cF9wWenWEZFvJ3kl2cHJ1GeWAdhoI3jkQGtLpJ1/iyJDSua9Eo9RklUora9BGmBKy jap4BQ13+oyEkwpClMwFIstr7oYep9JZZAXosi57XRpctktWvEZMe36D4MZmYklyxUuY Jaxw== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of david@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com X-Gm-Message-State: APjAAAW/9X09WlQlWm2dBUpioWMSzkYst6T8JDrgCAuE7LepAc+hw/M6 PgZ+EVbqACQK3XqiV5yQZQ48r8wjMlBiEFZIPPmKUrv7A3AYqMMnAXqeurTcee1Oo8gS58WBnIH 42YgJI2YRJIrmizHQev4tp/AIIuHDR5N3NsOY1EGIXK75flB++prUwMOENBUHQoEP7A== X-Received: by 2002:ac8:3f78:: with SMTP id w53mr11638765qtk.317.1556101569363; Wed, 24 Apr 2019 03:26:09 -0700 (PDT) X-Google-Smtp-Source: APXvYqwEtv4HEn/k8shoSMNEdFtsCyVElk0yGR0p+mi37z2LhfvZvlNQYXR+N+SxNg1s2oHJfhkX X-Received: by 2002:ac8:3f78:: with SMTP id w53mr11638690qtk.317.1556101568182; Wed, 24 Apr 2019 03:26:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556101568; cv=none; d=google.com; s=arc-20160816; b=mx2nfk+Kq919e46jbbhhIRn2O+vUyjRq3EqJbSRFGNvELpWXcOogL/uBS3aFPQLkV4 CQiYQzXWHA0sqhQsQOad/V2Yu4ioRuvok/mg7LJvlk3c8kN1uHh00WPmoDqYdf6aOZPD wDrGNPqwNR3FGWfGwqLLgFTFjGe3/OZ8JHBZpJ2wCQzNdDIAZV40cuMF/d7LcQeSiL8m nzEBnMXqinPXasjPjVh/0/9qxQv3E4089qu+rOxcoQSd8e8F/zx1xQna04KQ5YGBZAql OweEFUYtVAvaLQrH9X/HD4EwhOmdkcuu1XWMzOKBLPkZpDEDGWHpmL0FNVm2TTQE5dHO xdEw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from; bh=6alr3xAWbp/4sFY4rIt7l7CbtIsbDy+NJtgQONgCG9U=; b=EPmzDiM0iDEXUf0bcgVTPdWqNZAG3Slex4SxJ0E2Pm5wpkmoezD2k9kc8nNLnxXXj/ puuKfn9NQLnZTaFpHv5tX/Zdoo9Sulr67/zIRk25VnSH3CEfSl+pf7BOEMlO1KQKQ+YR I4BKL6ORXPMNIQjptJeywta2FXz5zBZ5PFgVkYIBbx3br/hwJ4CFWKXEOGYpJArbOtrz ZYtquYPI/pvFe9Aj+Vaqc/mfVkVuxaDeChYd4CiNDVyCtMYeFPpceGzcCTHBpgbO5XB3 6qzlwA3mp3U6lmNIealoBDtTnuPRVuogx3aQw5YtOCMTZDopn+g/zPSuA783Hn65ulVB eEIg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of david@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from mx1.redhat.com (mx1.redhat.com. [209.132.183.28]) by mx.google.com with ESMTPS id l21si818727qtj.365.2019.04.24.03.26.08 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 24 Apr 2019 03:26:08 -0700 (PDT) Received-SPF: pass (google.com: domain of david@redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; Authentication-Results: mx.google.com; spf=pass (google.com: domain of david@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 27BA088AB9; Wed, 24 Apr 2019 10:26:07 +0000 (UTC) Received: from t460s.redhat.com (ovpn-116-45.ams2.redhat.com [10.36.116.45]) by smtp.corp.redhat.com (Postfix) with ESMTP id 12CE1600C4; Wed, 24 Apr 2019 10:26:00 +0000 (UTC) From: David Hildenbrand To: linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org, linux-ia64@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-s390@vger.kernel.org, linux-sh@vger.kernel.org, akpm@linux-foundation.org, Dan Williams , David Hildenbrand , Greg Kroah-Hartman , "Rafael J. Wysocki" , "mike.travis@hpe.com" , Andrew Banman , Ingo Molnar , Alex Deucher , "David S. Miller" , Mark Brown , Chris Wilson , Oscar Salvador , Jonathan Cameron , Michal Hocko , Pavel Tatashin , Arun KS , Mathieu Malaterre Subject: [PATCH v1 6/7] mm/memory_hotplug: Remove memory block devices before arch_remove_memory() Date: Wed, 24 Apr 2019 12:25:10 +0200 Message-Id: <20190424102511.29318-7-david@redhat.com> In-Reply-To: <20190424102511.29318-1-david@redhat.com> References: <20190424102511.29318-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Wed, 24 Apr 2019 10:26:07 +0000 (UTC) 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 Let's factor out removing of memory block devices, which is only necessary for memory added via add_memory() and friends that created memory block devices. Remove the devices before calling arch_remove_memory(). This finishes factoring out memory block device handling from arch_add_memory() and arch_remove_memory(). Cc: Greg Kroah-Hartman Cc: "Rafael J. Wysocki" Cc: David Hildenbrand Cc: "mike.travis@hpe.com" Cc: Andrew Morton Cc: Andrew Banman Cc: Ingo Molnar Cc: Alex Deucher Cc: "David S. Miller" Cc: Mark Brown Cc: Chris Wilson Cc: Oscar Salvador Cc: Jonathan Cameron Cc: Michal Hocko Cc: Pavel Tatashin Cc: Arun KS Cc: Mathieu Malaterre Signed-off-by: David Hildenbrand --- drivers/base/memory.c | 39 +++++++++++++++++++-------------------- drivers/base/node.c | 11 ++++++----- include/linux/memory.h | 2 +- include/linux/node.h | 6 ++---- mm/memory_hotplug.c | 5 +++-- 5 files changed, 31 insertions(+), 32 deletions(-) diff --git a/drivers/base/memory.c b/drivers/base/memory.c index 862c202a18ca..47ff49058d1f 100644 --- a/drivers/base/memory.c +++ b/drivers/base/memory.c @@ -756,32 +756,31 @@ int hotplug_memory_register(unsigned long start, unsigned long size) return ret; } -static int remove_memory_section(struct mem_section *section) +/* + * Remove memory block devices for the given memory area. Start and size + * have to be aligned to memory block granularity. Memory block devices + * have to be offline. + */ +void hotplug_memory_unregister(unsigned long start, unsigned long size) { + unsigned long block_nr_pages = memory_block_size_bytes() >> PAGE_SHIFT; + unsigned long start_pfn = PFN_DOWN(start); + unsigned long end_pfn = start_pfn + (size >> PAGE_SHIFT); struct memory_block *mem; + unsigned long pfn; - if (WARN_ON_ONCE(!present_section(section))) - return; + BUG_ON(!IS_ALIGNED(start, memory_block_size_bytes())); + BUG_ON(!IS_ALIGNED(size, memory_block_size_bytes())); mutex_lock(&mem_sysfs_mutex); - - /* - * Some users of the memory hotplug do not want/need memblock to - * track all sections. Skip over those. - */ - mem = find_memory_block(section); - if (!mem) - goto out_unlock; - - unregister_mem_sect_under_nodes(mem, __section_nr(section)); - - mem->section_count--; - if (mem->section_count == 0) + for (pfn = start_pfn; pfn != end_pfn; pfn += block_nr_pages) { + mem = find_memory_block(__pfn_to_section(pfn)); + if (!mem) + continue; + mem->section_count = 0; + unregister_memory_block_under_nodes(mem); unregister_memory(mem); - else - put_device(&mem->dev); - -out_unlock: + } mutex_unlock(&mem_sysfs_mutex); } diff --git a/drivers/base/node.c b/drivers/base/node.c index 8598fcbd2a17..04fdfa99b8bc 100644 --- a/drivers/base/node.c +++ b/drivers/base/node.c @@ -801,9 +801,10 @@ int register_mem_sect_under_node(struct memory_block *mem_blk, void *arg) return 0; } -/* unregister memory section under all nodes that it spans */ -int unregister_mem_sect_under_nodes(struct memory_block *mem_blk, - unsigned long phys_index) +/* + * Unregister memory block device under all nodes that it spans. + */ +int unregister_memory_block_under_nodes(struct memory_block *mem_blk) { NODEMASK_ALLOC(nodemask_t, unlinked_nodes, GFP_KERNEL); unsigned long pfn, sect_start_pfn, sect_end_pfn; @@ -816,8 +817,8 @@ int unregister_mem_sect_under_nodes(struct memory_block *mem_blk, return -ENOMEM; nodes_clear(*unlinked_nodes); - sect_start_pfn = section_nr_to_pfn(phys_index); - sect_end_pfn = sect_start_pfn + PAGES_PER_SECTION - 1; + sect_start_pfn = section_nr_to_pfn(mem_blk->start_section_nr); + sect_end_pfn = section_nr_to_pfn(mem_blk->end_section_nr); for (pfn = sect_start_pfn; pfn <= sect_end_pfn; pfn++) { int nid; diff --git a/include/linux/memory.h b/include/linux/memory.h index 95505fbb5f85..aa236c2a0466 100644 --- a/include/linux/memory.h +++ b/include/linux/memory.h @@ -112,7 +112,7 @@ extern void unregister_memory_notifier(struct notifier_block *nb); extern int register_memory_isolate_notifier(struct notifier_block *nb); extern void unregister_memory_isolate_notifier(struct notifier_block *nb); int hotplug_memory_register(unsigned long start, unsigned long size); -extern void unregister_memory_section(struct mem_section *); +void hotplug_memory_unregister(unsigned long start, unsigned long size); extern int memory_dev_init(void); extern int memory_notify(unsigned long val, void *v); extern int memory_isolate_notify(unsigned long val, void *v); diff --git a/include/linux/node.h b/include/linux/node.h index 1a557c589ecb..02a29e71b175 100644 --- a/include/linux/node.h +++ b/include/linux/node.h @@ -139,8 +139,7 @@ extern int register_cpu_under_node(unsigned int cpu, unsigned int nid); extern int unregister_cpu_under_node(unsigned int cpu, unsigned int nid); extern int register_mem_sect_under_node(struct memory_block *mem_blk, void *arg); -extern int unregister_mem_sect_under_nodes(struct memory_block *mem_blk, - unsigned long phys_index); +extern int unregister_memory_block_under_nodes(struct memory_block *mem_blk); extern int register_memory_node_under_compute_node(unsigned int mem_nid, unsigned int cpu_nid, @@ -176,8 +175,7 @@ static inline int register_mem_sect_under_node(struct memory_block *mem_blk, { return 0; } -static inline int unregister_mem_sect_under_nodes(struct memory_block *mem_blk, - unsigned long phys_index) +static inline int unregister_memory_block_under_nodes(struct memory_block *mem_blk) { return 0; } diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c index 107f72952347..527fe4f9c620 100644 --- a/mm/memory_hotplug.c +++ b/mm/memory_hotplug.c @@ -519,8 +519,6 @@ static void __remove_section(struct zone *zone, struct mem_section *ms, if (WARN_ON_ONCE(!valid_section(ms))) return; - unregister_memory_section(ms); - scn_nr = __section_nr(ms); start_pfn = section_nr_to_pfn((unsigned long)scn_nr); __remove_zone(zone, start_pfn); @@ -1844,6 +1842,9 @@ void __ref __remove_memory(int nid, u64 start, u64 size) memblock_free(start, size); memblock_remove(start, size); + /* remove memory block devices before removing memory */ + hotplug_memory_unregister(start, size); + arch_remove_memory(nid, start, size, NULL); __release_memory_resource(start, size); From patchwork Wed Apr 24 10:25:11 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 10914477 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 C8834922 for ; Wed, 24 Apr 2019 10:26:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B71EF28A6F for ; Wed, 24 Apr 2019 10:26:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AABE528A72; Wed, 24 Apr 2019 10:26:14 +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 F0D2528A71 for ; Wed, 24 Apr 2019 10:26:13 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A03366B0266; Wed, 24 Apr 2019 06:26:12 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 9B0D46B0269; Wed, 24 Apr 2019 06:26:12 -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 8A0AD6B026A; Wed, 24 Apr 2019 06:26:12 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-qt1-f199.google.com (mail-qt1-f199.google.com [209.85.160.199]) by kanga.kvack.org (Postfix) with ESMTP id 6B3476B0266 for ; Wed, 24 Apr 2019 06:26:12 -0400 (EDT) Received: by mail-qt1-f199.google.com with SMTP id f89so17324278qtb.4 for ; Wed, 24 Apr 2019 03:26:12 -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:from:to:cc :subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=jwqamueXeySfeFxINzjppTw9mQ9ehliTYQXoU7pLAas=; b=ecnOAbwG8mUZHjsAt43/D/e3fDkmBeuJWIE+p8a1cgc6ilflfIs7AlQx74KcP5faLx S8okv8N4o+SULCmKGCXDQg3v9/gb1M7ebtBKeHeiW17WwmlzdmFWrQhJc3LIg6AEwbwj gFu6QB/ROvRMMKZI4l/9kYxZ1xu0vKX2ixb2Wb4FeCI2SqHp4+zJ28nMRbZ68ofHdtxr GiCI4D+EwslmBFnl+0e5DLrMyqo6nFhYIZ05UVv2mF8Vik3jgCDgJl9Pw+KHF4n4vJuo TNOUlYIfdTScPEULy5bi8tg8SnR2eEde1L4ccM2QH+iu8hikJyggAYNPvRyXcTPLlQXo U89g== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of david@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com X-Gm-Message-State: APjAAAUxwUtYHy/ogiBGsXidh4nICbfui+fdprz8yghva4kWZqsJyNfC 7XN7YNGSaGrkExGafA23QoIOCPz5cLwnucq5zMxN0XswShZ2akxZEuZa1M5qc1+2xDm0mXwXDhv bi7LJbBw/OxQESa5Y+Loto0kdbG/TBuZzPoKzGcS1L1Fvcz6Y/FK1ajCGYbaUSD7saA== X-Received: by 2002:a05:620a:1389:: with SMTP id k9mr247822qki.192.1556101572186; Wed, 24 Apr 2019 03:26:12 -0700 (PDT) X-Google-Smtp-Source: APXvYqxk5WwAih+n1AJV6CsLUWg8AyONoz1LNBD8jFNREmkQOGUTuQewEeCqrY8WmHpjWWdCnDQx X-Received: by 2002:a05:620a:1389:: with SMTP id k9mr247784qki.192.1556101571520; Wed, 24 Apr 2019 03:26:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556101571; cv=none; d=google.com; s=arc-20160816; b=SjnPR/FY4osUQ2GflBL+g5YJdTZXpca9mX+EZhVV7SHeb/X9Jj1sC+HGV1j0T4NQ+V 2F6oR1Fs8/yYphsFNF6oQd6QoREil/mcc5HLyv+7ZiasxvzjmouSEBWLYVfdY+jAQ/MR LI/7t86tzahLXq6oNsHi0bW+BLeNTLIhiAFl9eL0hkQfJ2opIIssm9AayTgymgm1oaum sv3z6rJ8e7Izxs3pX/zCvkGVLTph154ShVZERBPt3QYUFCEFnMB6OJHY8vVrz/bdcsF6 G7QDuVR9L8rd0fEzWAQuMmnY6MHPNCEJNExnwzBtSO0/HbQIk/Mvw5nUW9Jfn1BQfhQV 8wnQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from; bh=jwqamueXeySfeFxINzjppTw9mQ9ehliTYQXoU7pLAas=; b=c0s2uMfS16Mp/RzJCyjDxhD7H1HMPTDiCXnfxEyTQ7Nx26eWfMYA4XyM1YOdGN2piZ P8hb1JprOZdPShggctYCeA1NZLK9ZJf9uE9ch+bxd8y4iIgPvKMCO6lCcRcAvcNsrdza J56KHgioBABCxCAPaTJPI42v6XYG3d1izQuqXk5XlJPQYNLBD+2SHLAdp8MeWfT+jpHL RzVAnZKwEl2xAfMHk97rgajWm+s3zTuHrACJZtTqhi8Ro3uC1Ygjm7d8bKEMCkXUtc7A Mjtxn5pvZHW1Cu+dgG4jT2hrhHPk7Bv1JhOc4Jk714i7GUgFM2ldx4EWGmtFCzIt2dax OxwQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of david@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from mx1.redhat.com (mx1.redhat.com. [209.132.183.28]) by mx.google.com with ESMTPS id x26si6129187qto.160.2019.04.24.03.26.11 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 24 Apr 2019 03:26:11 -0700 (PDT) Received-SPF: pass (google.com: domain of david@redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; Authentication-Results: mx.google.com; spf=pass (google.com: domain of david@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9334940F46; Wed, 24 Apr 2019 10:26:10 +0000 (UTC) Received: from t460s.redhat.com (ovpn-116-45.ams2.redhat.com [10.36.116.45]) by smtp.corp.redhat.com (Postfix) with ESMTP id 79977600C4; Wed, 24 Apr 2019 10:26:07 +0000 (UTC) From: David Hildenbrand To: linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org, linux-ia64@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-s390@vger.kernel.org, linux-sh@vger.kernel.org, akpm@linux-foundation.org, Dan Williams , David Hildenbrand , Greg Kroah-Hartman , "Rafael J. Wysocki" , Alex Deucher , "David S. Miller" , Mark Brown , Chris Wilson , Oscar Salvador , Jonathan Cameron Subject: [PATCH v1 7/7] mm/memory_hotplug: Make unregister_memory_block_under_nodes() never fail Date: Wed, 24 Apr 2019 12:25:11 +0200 Message-Id: <20190424102511.29318-8-david@redhat.com> In-Reply-To: <20190424102511.29318-1-david@redhat.com> References: <20190424102511.29318-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Wed, 24 Apr 2019 10:26:10 +0000 (UTC) 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 We really don't want anything during memory hotunplug to fail. We always pass a valid memory block device, that check can go. Avoid allocating memory and eventually failing. As we are always called under lock, we can use a static piece of memory. This avoids having to put the structure onto the stack, having to guess about the stack size of callers. Patch inspired by a patch from Oscar Salvador. In the future, there might be no need to iterate over nodes at all. mem->nid should tell us exactly what to remove. Memory block devices with mixed nodes (added during boot) should properly fenced off and never removed. Cc: Greg Kroah-Hartman Cc: "Rafael J. Wysocki" Cc: Alex Deucher Cc: "David S. Miller" Cc: Mark Brown Cc: Chris Wilson Cc: David Hildenbrand Cc: Oscar Salvador Cc: Andrew Morton Cc: Jonathan Cameron Signed-off-by: David Hildenbrand --- drivers/base/node.c | 18 +++++------------- include/linux/node.h | 5 ++--- 2 files changed, 7 insertions(+), 16 deletions(-) diff --git a/drivers/base/node.c b/drivers/base/node.c index 04fdfa99b8bc..9be88fd05147 100644 --- a/drivers/base/node.c +++ b/drivers/base/node.c @@ -803,20 +803,14 @@ int register_mem_sect_under_node(struct memory_block *mem_blk, void *arg) /* * Unregister memory block device under all nodes that it spans. + * Has to be called with mem_sysfs_mutex held (due to unlinked_nodes). */ -int unregister_memory_block_under_nodes(struct memory_block *mem_blk) +void unregister_memory_block_under_nodes(struct memory_block *mem_blk) { - NODEMASK_ALLOC(nodemask_t, unlinked_nodes, GFP_KERNEL); unsigned long pfn, sect_start_pfn, sect_end_pfn; + static nodemask_t unlinked_nodes; - if (!mem_blk) { - NODEMASK_FREE(unlinked_nodes); - return -EFAULT; - } - if (!unlinked_nodes) - return -ENOMEM; - nodes_clear(*unlinked_nodes); - + nodes_clear(unlinked_nodes); sect_start_pfn = section_nr_to_pfn(mem_blk->start_section_nr); sect_end_pfn = section_nr_to_pfn(mem_blk->end_section_nr); for (pfn = sect_start_pfn; pfn <= sect_end_pfn; pfn++) { @@ -827,15 +821,13 @@ int unregister_memory_block_under_nodes(struct memory_block *mem_blk) continue; if (!node_online(nid)) continue; - if (node_test_and_set(nid, *unlinked_nodes)) + if (node_test_and_set(nid, unlinked_nodes)) continue; sysfs_remove_link(&node_devices[nid]->dev.kobj, kobject_name(&mem_blk->dev.kobj)); sysfs_remove_link(&mem_blk->dev.kobj, kobject_name(&node_devices[nid]->dev.kobj)); } - NODEMASK_FREE(unlinked_nodes); - return 0; } int link_mem_sections(int nid, unsigned long start_pfn, unsigned long end_pfn) diff --git a/include/linux/node.h b/include/linux/node.h index 02a29e71b175..548c226966a2 100644 --- a/include/linux/node.h +++ b/include/linux/node.h @@ -139,7 +139,7 @@ extern int register_cpu_under_node(unsigned int cpu, unsigned int nid); extern int unregister_cpu_under_node(unsigned int cpu, unsigned int nid); extern int register_mem_sect_under_node(struct memory_block *mem_blk, void *arg); -extern int unregister_memory_block_under_nodes(struct memory_block *mem_blk); +extern void unregister_memory_block_under_nodes(struct memory_block *mem_blk); extern int register_memory_node_under_compute_node(unsigned int mem_nid, unsigned int cpu_nid, @@ -175,9 +175,8 @@ static inline int register_mem_sect_under_node(struct memory_block *mem_blk, { return 0; } -static inline int unregister_memory_block_under_nodes(struct memory_block *mem_blk) +static inline void unregister_memory_block_under_nodes(struct memory_block *mem_blk) { - return 0; } static inline void register_hugetlbfs_with_node(node_registration_func_t reg,