From patchwork Tue May 7 18:37:57 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 10933555 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 8EE62933 for ; Tue, 7 May 2019 18:38:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7B10C2880D for ; Tue, 7 May 2019 18:38:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6C0462891A; Tue, 7 May 2019 18:38:27 +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 EEF702880D for ; Tue, 7 May 2019 18:38:26 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AEF556B0003; Tue, 7 May 2019 14:38:25 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id A9F726B0006; Tue, 7 May 2019 14:38:25 -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 98D4A6B0007; Tue, 7 May 2019 14:38:25 -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 756456B0003 for ; Tue, 7 May 2019 14:38:25 -0400 (EDT) Received: by mail-qt1-f199.google.com with SMTP id n39so20309907qtn.0 for ; Tue, 07 May 2019 11:38:25 -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=CjinF/w3oTEj1XHUUxl+s+vuw8d/lE+ezDsJCNr9RN24fgHlX6mrZW1p3kC7gchl+L xpzfpqirgVE1vTM7ukZxEz+iuic18JMpdodnXOxvMSlLtUQjz9mqx0kjdOuluinP05XQ KgoACxZ8qKAijpVCJ2ablAbwiM+mbib9ikhgDmDNgUfJg0Zbd44IO5yanu8ICuY5HY5G y7c02T3Tu2ifkfss43PKA9WT1MthChvgf7ADl5QGYvj6oZD5vIiAeibdexqjFew0l14E g52EIKl/B/wrVnTVpefZze2j/qCbEChpG6AWWS11Aja2tacFs3L1yPyp22IPT44gb2ky XgSA== 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: APjAAAWUHzOukG5b/3SkgF3mBV9uWxBJZ7BPanEGM2E5EznVvX5UUUF4 kq5teNX6NG0Fr6bc/H/INT0TqnwgBMQRnTHZwQadKXfop3MPFgzU30dfykCPaBLZzl6dSWQe/aj jsQd419U4Yjusjf0wZ2OHwL485IeG2JA8cFFXmhrfsDbkh0oY+BmKL0TFrvzBtY5NMA== X-Received: by 2002:a37:b683:: with SMTP id g125mr313310qkf.249.1557254305147; Tue, 07 May 2019 11:38:25 -0700 (PDT) X-Google-Smtp-Source: APXvYqyAqBFuiWFJNfQxchoxM9forM1wuUPL7XTMzAk2Rt7GoxISFJKRXsTELwToYEw+BwZiy4fY X-Received: by 2002:a37:b683:: with SMTP id g125mr313261qkf.249.1557254304209; Tue, 07 May 2019 11:38:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557254304; cv=none; d=google.com; s=arc-20160816; b=zul8zOF/K9Se66ufyZurVlflSOlPbuyiY+U+2Ajbg2lITxE++97fp9LV99Jk+UGoIU n/VpWbAfgke8kk/PmSPDwLUtXdiyzi/Xy73SD/ncqLGAIete1rgZk8Ymsob8vclcM0va Se0HBNWDYxTFVq8hVxyOERrJBjfwJnJBmoLXiiXnIIjKA6z3Cb8uNmYfO/gKx1L0HY/l TLhwFg5CofEzFb8ECg6fyVyUDGvUyZrebICOH6m/y7tYH9GDJRjnZPrp1/sIXMMf4WW+ LFpCDE6MuP9c0J2m6KillILGhYh8LeYOGx3HUrONxFe6m0yxbZuH/oEw6lzsiX1DuDoC p2Nw== 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=D/g3Nwix/N7DwSZyl3x7ExzILOWnZrGI1Zao4oAwXLyJtH+ODselZ14/D2Y8PgKoxk gmh8O9IZE0qeBdJsG3NYVKeargJadDC26sx/z+iNw6JOM7kkHegh3XjkJlzYCtGFZgNE 9+rFD18XC605nMJrj84MXX/mAhgSooccx3eto+V4Hgo1jE/9L+6kNXT9UFjbfEtnKfVr o8+6Y044KGnNQ7yupW6mhXLA2XAhoyFfKuE2Fb/fdWDpjiVrQlAbYlwMZd8BqJFmeIGC r2cq67MbMqKwO2il4U225Zivw3QpA+8l2SAbqxLC4pXtstvi4zXhL+zfCpUR4ECKsEWC pzhQ== 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 f67si5841625qkj.72.2019.05.07.11.38.24 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 07 May 2019 11:38:24 -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-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5F73F83F3C; Tue, 7 May 2019 18:38:23 +0000 (UTC) Received: from t460s.redhat.com (ovpn-116-95.ams2.redhat.com [10.36.116.95]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5B9301778E; Tue, 7 May 2019 18:38:20 +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 v2 1/8] mm/memory_hotplug: Simplify and fix check_hotplug_memory_range() Date: Tue, 7 May 2019 20:37:57 +0200 Message-Id: <20190507183804.5512-2-david@redhat.com> In-Reply-To: <20190507183804.5512-1-david@redhat.com> References: <20190507183804.5512-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Tue, 07 May 2019 18:38:23 +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 Reviewed-by: Dan Williams Reviewed-by: Wei Yang --- 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 Tue May 7 18:37:58 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 10933563 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 91D37112C for ; Tue, 7 May 2019 18:38:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 826772880D for ; Tue, 7 May 2019 18:38:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 76DCB2891A; Tue, 7 May 2019 18:38:32 +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 2223E2880D for ; Tue, 7 May 2019 18:38:32 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9DE5C6B0007; Tue, 7 May 2019 14:38:30 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 9907B6B0008; Tue, 7 May 2019 14:38:30 -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 859D86B000A; Tue, 7 May 2019 14:38:30 -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 643036B0007 for ; Tue, 7 May 2019 14:38:30 -0400 (EDT) Received: by mail-qk1-f199.google.com with SMTP id u15so18996801qkj.12 for ; Tue, 07 May 2019 11:38:30 -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=S+eOGatgZeskj0KU0uy0qphspDfnUZrs/C9R13O+fz8=; b=MxfNKBFWG5P6vg6ILAgTLGRVEVvGL3k7bMHxfEVUlNjrl+pd01eepSRDjqmk3VHKuu HcdXMU8uSnBtfJyzNhDIDEoMAVXEr2F2LeiFbO9R2b/l+FYjHDqdBTfJ6AXuQ6maOe7F hlVWWRswAZYkwiyTnd7sX9dzcpVhPkNb9dgLlhjl2CV9j2hVZJfUe+QHkTcD7iNYW/eq P4EICM46Y8B77s3FV55aQDPnsxwF3iVBSlT/oyJ5knS4PvB5XJRUJk10RgOrv+O1+cre hXQ6hTTewmcjs2lVlExUpsY3sod7MdUHgD+XVuIV3awoSuWF6lUdktzSQ8nMJZ9/uBEm +goQ== 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: APjAAAVhkewPbQf9mrxrrrpN5pMydKm87My3F8+sybkHgI6TpFu8DwjY 5c8MBpMWvhzrdJwaRv2WEbtwUZQ3/ydcUg+RHwSndamrlKV+w+FMLLlP8zu1Vu2uV5nhYDx24rN O1Ee0kw4AljKjD0Mxf9T0ZMEIiHUj4djx5D5EYqD5Q+TaMQzqMxvNAFJ+9KcxZXFVMw== X-Received: by 2002:a0c:969d:: with SMTP id a29mr27368157qvd.56.1557254310188; Tue, 07 May 2019 11:38:30 -0700 (PDT) X-Google-Smtp-Source: APXvYqyXDiwvoDslaowcUAc/MgTBtuaF6GiP8dz1ZcxtSl0jtlrUAG+rPoeM0HfYI/YLP3qUpVEn X-Received: by 2002:a0c:969d:: with SMTP id a29mr27368121qvd.56.1557254309640; Tue, 07 May 2019 11:38:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557254309; cv=none; d=google.com; s=arc-20160816; b=EFBisREWI8fm8K7ZXX+VOx6ZGf71R0Aq/GL/wEkYU4dRB4fT61kKcFovgycKwvjtv0 eXVJ9cb5miF8iAtyFlIRcTyySm6JQzo6qdk2805EkPSYNZiBBFFtlVDe06tSA4YozPjp 7goh2UFUf8sy5ukDhP7OWDjex5PEnkVXmORKuAzVQgpjoysn07WZ5Q3EDgt2JaG5W2r0 dpW3l9G7TcEP829H7E+CS3VFk3/MH98SsMwsa2JYGmirdlA4y4OZNO2cQOYUTS9BHB+G FB8e+lHPefhbFOOOnZQADkIPX4TbLjsm/2oVbNXmX9yKGTDrLgl3Puz3QSFDUsnA/l4V stYA== 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=S+eOGatgZeskj0KU0uy0qphspDfnUZrs/C9R13O+fz8=; b=tguUGNsoZ4SHpTi0agOzOz87VcIko0CHtTMSI0VPlE97D7I6pSKICILSsh+jyNC3im io2EEV3TglIDH1fZpGMIWiMQotW/BS/VZrsMzYwWF1y0YJksAlyOoZzGk2Pppdllp2Hx ieZKS+iXgOzL98gCzaU1+2VDGyG+Snd/1mFnWfGzMaKa9Izh4nk1oo0H/xpIgdFxrR2l ATFFhPC2ZY4gX6qohoSpuJBDaqjyJ0tsSzl6vcOyapoUmhsGTPyix6dGnvW5zyX3UGCx G0rsVCpG4cPrC4qCbRFXbeDNvQDrNvEm6BQQkrBmpIsr37F/TKqKveMlbL8T0rERVHCt 0dng== 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 l12si7632452qtj.182.2019.05.07.11.38.29 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 07 May 2019 11:38:29 -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-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id ABD9B308FEE2; Tue, 7 May 2019 18:38:28 +0000 (UTC) Received: from t460s.redhat.com (ovpn-116-95.ams2.redhat.com [10.36.116.95]) by smtp.corp.redhat.com (Postfix) with ESMTP id B1B871EF; Tue, 7 May 2019 18:38:23 +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 v2 2/8] s390x/mm: Implement arch_remove_memory() Date: Tue, 7 May 2019 20:37:58 +0200 Message-Id: <20190507183804.5512-3-david@redhat.com> In-Reply-To: <20190507183804.5512-1-david@redhat.com> References: <20190507183804.5512-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.49]); Tue, 07 May 2019 18:38:28 +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..1e0cbae69f12 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; + + zone = page_zone(pfn_to_page(start_pfn)); + __remove_pages(zone, start_pfn, nr_pages, altmap); + vmem_remove_mapping(start, size); } #endif #endif /* CONFIG_MEMORY_HOTPLUG */ From patchwork Tue May 7 18:37:59 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 10933565 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 6F4AD933 for ; Tue, 7 May 2019 18:38:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5A9052880D for ; Tue, 7 May 2019 18:38:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4D71F2891A; Tue, 7 May 2019 18:38:43 +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 B726B2880D for ; Tue, 7 May 2019 18:38:41 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C76366B0008; Tue, 7 May 2019 14:38:40 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id C266D6B000A; Tue, 7 May 2019 14:38:40 -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 B13726B000C; Tue, 7 May 2019 14:38:40 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-qt1-f200.google.com (mail-qt1-f200.google.com [209.85.160.200]) by kanga.kvack.org (Postfix) with ESMTP id 8F6526B0008 for ; Tue, 7 May 2019 14:38:40 -0400 (EDT) Received: by mail-qt1-f200.google.com with SMTP id k20so20322911qtk.13 for ; Tue, 07 May 2019 11:38:40 -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=KySQd0kjiKhRG9oPnhQLROfeO5buG3jojX3hCzFXPnQ=; b=qz1VUZ6swq7Krc0UEHVPYD68JZhE0N1d4v83wcPDi+gkn8R/TkUeHcM5pvu4X5xeH5 PmbFzR+s05tap7Wr71IRd0g/TJMZygRMd0UtePH/jHbWSQrL+m1U/dcET2lJGin7WDTY llU5DtSoyCk8hiTATA2jDTPvOwRQLpDUbpbRbQXfz+fxFgrr2r3G7rCwQNwto17IB5rf u4cXSB+BQu32IMSSZGpJqO/GOO6yRjGSiDMJteYiRggjcu6rqIQNDmJeIJQQKJFsDuH4 r57RX+/orPWyRND82kUoE+H/JBEsdEd/wCI1p82PmIfPZfajo3Ud5aubjpzHsdbCQFJS pv4w== 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: APjAAAXzUCMdqcI/8CdzQaLqPgrF0DIw9lk3MSnAJLHjT80RCAZdgZw0 x7Azo/P2H/rACMZlVgV+VezCrUbN6+M508FAN7fVOYrJwsGcaaKvjUAS7e+L7qYdmsWhEDBMkDC Qe4pPNHWpOfy1rXZIQdBmJ/nuVj1ylr/jZS0TZHoyVLDpyoeMf7ddeo6tdNv53X7xKA== X-Received: by 2002:ac8:2bb9:: with SMTP id m54mr22576589qtm.303.1557254320319; Tue, 07 May 2019 11:38:40 -0700 (PDT) X-Google-Smtp-Source: APXvYqzzkJ1JpillO+6fQZAzWrgZRFpgKyIt+y2WuaotrIID6SPiGzbm9Iu2XM693b0KT7mdVC60 X-Received: by 2002:ac8:2bb9:: with SMTP id m54mr22576509qtm.303.1557254318894; Tue, 07 May 2019 11:38:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557254318; cv=none; d=google.com; s=arc-20160816; b=015a9j4KH23ungMeR5ruuy77LB8DizFqF0pMfNP3IPKD/poBGnEpR5YmGgCD2pSX0q VdIcK3xmushgE2hzxCP3V3HUwaRpMjMQXkfAKZWsSYovnFhPOJbzA98bXXevZvqY4KQE KCGnq6tbEGwHQme4a0Q+SILy23px44tmJOjvhqz7snZwjO1DCVPewKOYWULYXtD4raCk meEk94okRfT3oSosbIUsbtOgyiyWG1x+6qKVLeIzDjuZjo716mVrcZOfX89SXyKwW7mj 4WLArGAIW/IWFs9LfyBQGcnvbFtetFKkcnsUXGDMjTDkdDKT+xyYhsQU1vdeEGzFyrFz DEDw== 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=KySQd0kjiKhRG9oPnhQLROfeO5buG3jojX3hCzFXPnQ=; b=oJyi2UCu+IgroTiFH+EnNRQL3vzM8HZYClZkiIWsdBOLdRFHIO7qmCCxFsr7pIdw2w KalRIWgC1nLDBoOUP+hhr175JeZWmNKWIal/KE4KEwIH9ZYkWkKLB5Ar4W4jt/bYJpzs vzFyLfuvGEIhdNP+WaPqQbOKhdnx8MsCR1KU2/kUFpqjlxvvda15FmSIhnXhFW7xMA7t /ZTTvrO3YwXvNqECfUow9sIydo+nAW+vtFLB0K4cQbCCLeIIr2c9UxMYFt3VkwW5Mi0X BPoBDc5hg4s2uCOeQtypDapw6ACXGaZdS9rew4bxZ7XODW1TQxsJGLTMtikDY97H2EG5 /now== 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 x17si1855759qvu.118.2019.05.07.11.38.38 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 07 May 2019 11:38:38 -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-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 945253001821; Tue, 7 May 2019 18:38:37 +0000 (UTC) Received: from t460s.redhat.com (ovpn-116-95.ams2.redhat.com [10.36.116.95]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0EF2A3DA5; Tue, 7 May 2019 18:38:28 +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 v2 3/8] mm/memory_hotplug: arch_remove_memory() and __remove_pages() with CONFIG_MEMORY_HOTPLUG Date: Tue, 7 May 2019 20:37:59 +0200 Message-Id: <20190507183804.5512-4-david@redhat.com> In-Reply-To: <20190507183804.5512-1-david@redhat.com> References: <20190507183804.5512-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Tue, 07 May 2019 18:38:38 +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 a2b78e72452f..ddc69b59575c 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, return __add_pages(nid, start_pfn, nr_pages, restrictions); } -#ifdef CONFIG_MEMORY_HOTREMOVE void __ref arch_remove_memory(int nid, u64 start, u64 size, struct vmem_altmap *altmap) { @@ -164,7 +163,6 @@ void __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 1e0cbae69f12..eafa3c750efc 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, __remove_pages(zone, start_pfn, nr_pages, altmap); vmem_remove_mapping(start, size); } -#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 Tue May 7 18:38:00 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 10933567 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 D5C18933 for ; Tue, 7 May 2019 18:38:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C30E32880D for ; Tue, 7 May 2019 18:38:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B63322891A; Tue, 7 May 2019 18:38: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 EF2C92880D for ; Tue, 7 May 2019 18:38:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 76C696B000A; Tue, 7 May 2019 14:38:44 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 71C166B000C; Tue, 7 May 2019 14:38: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 60AC76B000D; Tue, 7 May 2019 14:38:44 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-qt1-f200.google.com (mail-qt1-f200.google.com [209.85.160.200]) by kanga.kvack.org (Postfix) with ESMTP id 3E74A6B000A for ; Tue, 7 May 2019 14:38:44 -0400 (EDT) Received: by mail-qt1-f200.google.com with SMTP id s46so9789233qtj.4 for ; Tue, 07 May 2019 11:38:44 -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=dLJUAZ7p030rjL0d0Q6/jfOQbVzDz6d2+21QAjs9B8jYGtg6aW5vDqqBkoKYvl3DXG /coKW/nUoKxK+ntcVANanxdpvZF/L7Uo+cZpC8I5iK3PiChavxVqpApmI8wzTxKNS9XO bCDzVEnaozBbzOfIcq9swuhAzUkZgfH62MixDSLH+z26w+olk/wT+DM1wL7/X9DkEa2y wtFnWV1Z4zdf077dVp9w8fmPZlv1O8RNw6R+dgFPbr4mG92j6WqEvD0CMd18iAzHMAU7 jl+ByPpEa04J1akV0dt0SIXdBaATPUUlXQTbaYgMcCUpp7q9Yxj3N01UoEF1lYwQA8UE rGTg== 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: APjAAAW7cuopNeHV+OntQb810Qeu2KV4MrrrLEQj4FkYPEAqHnlC8N34 7wuvRdorC7iNxnyUv4Hfe3WVvdCimEbm8sjHzC6tjR7NPZ3I4AFJxKM5hX8Tlt28U34eN6SXsSn wiHlepK+0VLL6BFFPglLUgJUW9h3T2OUYB1BB1KEI+2yNJL19A6/dyNZaPcLA/Cp7BA== X-Received: by 2002:a37:52c1:: with SMTP id g184mr17747007qkb.338.1557254324005; Tue, 07 May 2019 11:38:44 -0700 (PDT) X-Google-Smtp-Source: APXvYqwMK2RywF8wQdSkZ1VIl0mdWxfWqn9MDNfaFGryd0NL4mHo8tiplMnHo4k2fJiUNcfVFSrg X-Received: by 2002:a37:52c1:: with SMTP id g184mr17746942qkb.338.1557254322827; Tue, 07 May 2019 11:38:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557254322; cv=none; d=google.com; s=arc-20160816; b=LRgRK60FSTTcHvlOCn1j7BVScKooBM0G0YSZv2iFi7wFe8C1Hn2EWbkd33roEg5Gf2 TMtguzRVhtA27/tSwMn8+K8E2YeRI5zPEU31X8LMNRSFAGESYnUmPmbC8cmKEt36dFIw 0so10Z5zfnKJOIaLdnPwJCYFhWnf91a5EC8w6Ohf63r5PDmSrDxV9H0wTqTOyq25gl0s FjLuqrEQzXUQ2QoUolQi0odXOpLCNa+UmqzucdblCkvg4GGGBgxwDuxXC8u6krnQLp4e vsO+kKJAJwgwbb1ep1cHMpK9gdE4rDzsiGlCkfXIzjo6626kD9K5bBAsDKRFpXS9LhT/ BKgQ== 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=Bf3wtZbRQhGsSxAbWgtaf8Hgu/Ay6+piYzemUtIorn0tTQiAThgdAPD6M792lQXr4r ROBqQ8wTmPHh7T4iUpa2JkSg94vzDnRUjuwELq9XPePIfg9itTc/Vn4Jqy/EKjLfol26 u2zfj9G/odD0fPstASjgbRZr1muAzkjqxeHA9pDk9eX+Z5cL7lAvw7tnWJEcNJwrPr9i SJhxy2xM6pYzIiDPq+1dD20wFwdA+q0guxCzpYkogToX/i1sNY/cYIgyDgs+Eg9UXbeX EbMVT2Ni0UN49uWrt8pepFkbopm+UjRnM/evf1X0SpL6i1PgjOMNPjdPEpYGRdtvwDMQ t0uQ== 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 q26si3262160qte.68.2019.05.07.11.38.42 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 07 May 2019 11:38: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-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id BAEE5300180F; Tue, 7 May 2019 18:38:41 +0000 (UTC) Received: from t460s.redhat.com (ovpn-116-95.ams2.redhat.com [10.36.116.95]) by smtp.corp.redhat.com (Postfix) with ESMTP id E8CB58162; Tue, 7 May 2019 18:38:37 +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 v2 4/8] mm/memory_hotplug: Create memory block devices after arch_add_memory() Date: Tue, 7 May 2019 20:38:00 +0200 Message-Id: <20190507183804.5512-5-david@redhat.com> In-Reply-To: <20190507183804.5512-1-david@redhat.com> References: <20190507183804.5512-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Tue, 07 May 2019 18:38: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 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 Tue May 7 18:38:01 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 10933571 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 D0768112C for ; Tue, 7 May 2019 18:38:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BF5B52880D for ; Tue, 7 May 2019 18:38:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B37F52891A; Tue, 7 May 2019 18:38:51 +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 E471C2880D for ; Tue, 7 May 2019 18:38:50 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E227C6B000C; Tue, 7 May 2019 14:38:49 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id DD2C66B000D; Tue, 7 May 2019 14:38:49 -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 CEB216B000E; Tue, 7 May 2019 14:38:49 -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 AAD046B000C for ; Tue, 7 May 2019 14:38:49 -0400 (EDT) Received: by mail-qk1-f197.google.com with SMTP id u15so18997826qkj.12 for ; Tue, 07 May 2019 11:38:49 -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=m3bGGHkDfTM21NLFIWPfw3DPKATS6zsru0rFElOQqsh/29nAGggvdvVN5FD2BMEJZK S3tVXspAo4s7Rh5gQk25ALJD9mS7+jGKaJT7VA7BqfpcSOrW66GUmYYXuMGC1fozqHka dtOSxWHEOY9GDL3rfUkOD+DiGTgDlZbQoTODyM9NKEHa3MELuWN9lDW5cuvOdI7MNxHh rMHBn7RfElTF/zYvkUg/fHVf78OmThP6GZdZmi+NOAJv6MfmpeIdsXrM1FR9901ksxlM H6nq9xQ7DMPverkv113qWbvpqEU7V1fNaHwkUolos7QSHI7p695oSY/K4asBm6ioeTXp fv3g== 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: APjAAAWDzPWWho9kP+raQlsw7GofN7zIMGE+HqDnpJM4a4lgMU2g9/fm 52nAyqwp/TZdaQEfCp0XKud2efGfkLnOS+BoSYJbY5qyDs7ArUgTZN2X2iREX6S1KtxkK6AsPUE 1gYV8M3ap3d1hPYppeEtZ91zH/BkUZrysmBedgkepQ8N7aUln86Xv1X/OhKTY/IrRvw== X-Received: by 2002:a0c:8c49:: with SMTP id o9mr9577788qvb.7.1557254329417; Tue, 07 May 2019 11:38:49 -0700 (PDT) X-Google-Smtp-Source: APXvYqymmhjzYW4EyFggWUmTqENRibDfu57yYXuqBpxZcuZWOjmsQovCK/t7HBOAovonkdfRhYGH X-Received: by 2002:a0c:8c49:: with SMTP id o9mr9577716qvb.7.1557254328286; Tue, 07 May 2019 11:38:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557254328; cv=none; d=google.com; s=arc-20160816; b=finC03hudmC/3JKCW2hGCxtFYB32fRLAcveZCRyLRHq4637OmnjIzVKZQxGihuplU3 BjnLVQhi30n8R+k86gl8/q6nFfGOFQIUd7vu0wBHYyxz2PJVksyS3hQVhKiQ7B8visAS OWy17il0eGo0qrBipM6zzVWyMJAUwBFWppMkj8G7Q4Rr9MIjWC68uVi1dKIen7+xnu12 vDlFrBmbqitWnTqJsMK0HefytUUHXEFIIt6qpvbOXsIz32KDTqERqJItHJWHf1qONFnG 4p6ypbq51UV1UtQGPxDMWbQ5Nraxa3ZXSJI6veCshurPAtLUm81uFVw8smJ2Pl371pNU IEEg== 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=o3g63udwJgN8LMf6m0kSiyfTf3ooivJSX3pndSXZcVE77zUp01uiaL2ctYFdJmHcj3 N/Eci2veDiAqkOPqXiWOBnmQByyUjVj22HKYlJz9DB0ubiMP4dQHACmCjZ2a5sGNZdPJ fnJyXMqPb4q1Dq2O/u2DsY4EHY18bDi1c144C+RE0kNX/onKLcYoGiYfn1stQwSqTeiM +NV86O7RzZvQ/xJlXvQ6vjaKhI6ZJfFrKrtG/a4ZPS0PMPniKU/cC+Qi8kDkl5oBb23x Z2NTDcWe2mhQGSUwcu3qFrEDbBh9IM5Mrw4OwzRDJmqfv6cXEwP9HgTJVviW669RVPBx dohQ== 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 u185si2978109qkb.135.2019.05.07.11.38.48 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 07 May 2019 11:38:48 -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-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6315F3082E72; Tue, 7 May 2019 18:38:47 +0000 (UTC) Received: from t460s.redhat.com (ovpn-116-95.ams2.redhat.com [10.36.116.95]) by smtp.corp.redhat.com (Postfix) with ESMTP id 172023DA5; Tue, 7 May 2019 18:38:41 +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 v2 5/8] mm/memory_hotplug: Drop MHP_MEMBLOCK_API Date: Tue, 7 May 2019 20:38:01 +0200 Message-Id: <20190507183804.5512-6-david@redhat.com> In-Reply-To: <20190507183804.5512-1-david@redhat.com> References: <20190507183804.5512-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.46]); Tue, 07 May 2019 18:38:47 +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 Tue May 7 18:38:02 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 10933575 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 DEA78112C for ; Tue, 7 May 2019 18:38:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CBE112880D for ; Tue, 7 May 2019 18:38:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BEC3E2891A; Tue, 7 May 2019 18:38: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 E8E222880D for ; Tue, 7 May 2019 18:38:55 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C271F6B000D; Tue, 7 May 2019 14:38:54 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id BD7666B000E; Tue, 7 May 2019 14:38: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 A9F6E6B0010; Tue, 7 May 2019 14:38:54 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-qk1-f198.google.com (mail-qk1-f198.google.com [209.85.222.198]) by kanga.kvack.org (Postfix) with ESMTP id 88E6D6B000D for ; Tue, 7 May 2019 14:38:54 -0400 (EDT) Received: by mail-qk1-f198.google.com with SMTP id p190so11392965qke.10 for ; Tue, 07 May 2019 11:38: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=6alr3xAWbp/4sFY4rIt7l7CbtIsbDy+NJtgQONgCG9U=; b=lKLmnFrZXg53kp75bSjjxrwU5PG1N2EZPVAwNFNkTuFp0xGd7hLqTQ4/cjBpGY60vO J7rvPGPjjV5sbPFW+k2x83m/i0CbkoPUbV+IvOQK/Doz+nCry/n7HLlE2yk+8hOV6MKV 6OsjcgmvOpUCHpCnpDU1yWGMoZJ6+5vTDBR0gwl2QQsWdEJ+GVqCZ0BEe7viV/WF5fGK 8+9dkPTn068BGApaZEcWJUTLO/LycFQboJiYWBal8jO6sEGWS92bVqITc+Jd1OJmX0bL 44SZ22wAcDuDPb2VDrDrzy0KeiGP/ULqeWWYW0kHz8AvMXNqtXcYKxXl2qR0tN4r5Ddn QhHA== 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: APjAAAVaJTLQ6s8fZsWvYze92G5YNKuc5aZRF+UJL8jo2KOFny3Db5Za VTncGCdaiErVqIjaDmXvNVer0tVnIMR0jfrQpDFpX79LRe3mRxPcaU38jrsya+8FaEfMpBybaGp u9vpXhdRxr4+Z6lQfQQ/9+4s0Ep1Z3c7w84/O+/ZowDaJzhX/YdI18zoA/t02p3scJg== X-Received: by 2002:a37:84c2:: with SMTP id g185mr26353856qkd.183.1557254334314; Tue, 07 May 2019 11:38:54 -0700 (PDT) X-Google-Smtp-Source: APXvYqzPvHfUZ/VBcrZix9/FsHWmCDStRKaiPNQxUVOyvHD4Ehm4nvVFAiTGPIWrvriQjVWEBPil X-Received: by 2002:a37:84c2:: with SMTP id g185mr26353798qkd.183.1557254333081; Tue, 07 May 2019 11:38:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557254333; cv=none; d=google.com; s=arc-20160816; b=S6qvCaAXV1IAixL0kf+G8n0Lxbe8CTgLITxtaGU8nIeVefAHbWvgpnjsv8yOZI/fuA md19ny4HVWEpmo1ejWuC51TDQDXxXDs/ZZ1LXzhyGl4gXf/eILm0ikgEkbKlQtRL7SFX /NlHnf1X8W4/A34Ni7NIcjFuqCYlKASypvPGmUvVF+sDwimcvGCglxPOf/gLPqCs1o/j i+SxHoRT/Q7lrgALnbGF8IIQz0mbz9KhEIbKmhuh3fnUbacmCSm6Y8Ae0uodmQQtqzgg BRiGcWI63p3l5Rgk7bNZNDsu4kBVYJ9YLqYXr2GHHm5WT9QkyBLOO6jNAg+cGGExU7WF ytVA== 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=cV32iUBEmPygnx9jXCnxVuaH/sUZXkrrFFo7Q9ioVD2m8SxA1f1tXlj3H5aZbAU2D+ cAcXO0Gdp6d+jP4ezdnNwIplDmrXofp8BW6gadfx2pVvlbgfz0qGdvTTM20ZOMRt7VmD bCUBwqZVmhXz1Z1NtyZr6h1fRaXdW12yVuRGZB3m35JM3ZXRphI53lnB8cfjLGANFyto LB7oD99jS4nNLDJOxFY9uSI9h+ICSqfx0E/NV64LlxGswK4A7OX7tFw+IbAXK8f1+TN2 1Njl49Q59pvdyczyjU9YrSrOEpQ93q0W0ftDQgOKeJ/8b/QxArpuHQqz0BzqP4GTGapv JLVg== 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 f8si3909090qkl.243.2019.05.07.11.38.52 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 07 May 2019 11:38:53 -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-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 103E33082E72; Tue, 7 May 2019 18:38:52 +0000 (UTC) Received: from t460s.redhat.com (ovpn-116-95.ams2.redhat.com [10.36.116.95]) by smtp.corp.redhat.com (Postfix) with ESMTP id B29323D99; Tue, 7 May 2019 18:38:47 +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 v2 6/8] mm/memory_hotplug: Remove memory block devices before arch_remove_memory() Date: Tue, 7 May 2019 20:38:02 +0200 Message-Id: <20190507183804.5512-7-david@redhat.com> In-Reply-To: <20190507183804.5512-1-david@redhat.com> References: <20190507183804.5512-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.46]); Tue, 07 May 2019 18:38:52 +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 Reviewed-by: Dan Williams --- 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 Tue May 7 18:38:03 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 10933577 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 008B3112C for ; Tue, 7 May 2019 18:39:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E19E72880D for ; Tue, 7 May 2019 18:38:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D5EC82891A; Tue, 7 May 2019 18:38:59 +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 415722880D for ; Tue, 7 May 2019 18:38:59 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 019F56B000E; Tue, 7 May 2019 14:38:58 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id EE8AB6B0010; Tue, 7 May 2019 14:38: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 DACCC6B0266; Tue, 7 May 2019 14:38:57 -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 BDB326B000E for ; Tue, 7 May 2019 14:38:57 -0400 (EDT) Received: by mail-qt1-f198.google.com with SMTP id t51so3409075qtb.11 for ; Tue, 07 May 2019 11:38: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=jwqamueXeySfeFxINzjppTw9mQ9ehliTYQXoU7pLAas=; b=Js/v6wjZjJM6kFy4wcqudp7ElYv09az+lKp+Ka1laccdW+C3oxCPdXQxWouYglMMaP 1GwA9uR0pjDspPdG0UZLhjRQtlqi0PLacOnvKpYn19k5uyqDv25aia/JvW9YaA7z2MfK hkangk+FUMAOzilBTyZOD9XYisThhTts1KSpHUNgKjPTCC3/jFqvmSrWO3PlyHrK6FZZ IBf+jOOZYpahXJw+w9kejSq13n64syn500kATQOM99vODoWwgMg2QrSRSa0ZHErP7dZK clXySxZ/C1GSoLbF/avDUL5M8GdAf3yg39CAguO2iXo/v8xINihEZvVxuHoL3ggqbbI9 OhSw== 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: APjAAAViirLW+1KqPWYr8h6z6nmSzzzkEK/D6dWNr98/AXHxnrjInYP8 sRGCUJW+CyoQQE6ixhDPS314COtNs2DFdfnlWyVt3wtzkajhKl1FtBJydeVVYq4WG93o5oxcNo9 2USyLWIUvnvHtnStzet2acSk3Ze9mVSkMgKk82hpphnee17jzZB3HVprpX5doakyjrw== X-Received: by 2002:ac8:3884:: with SMTP id f4mr24711250qtc.300.1557254337502; Tue, 07 May 2019 11:38:57 -0700 (PDT) X-Google-Smtp-Source: APXvYqwAc8O/3oNyx6TLQl5VNGoqa3IMmOy31uUeWvWKVRU5TtcNc9ojWEyu2x1xf+fCqxbieg/X X-Received: by 2002:ac8:3884:: with SMTP id f4mr24711190qtc.300.1557254336455; Tue, 07 May 2019 11:38:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557254336; cv=none; d=google.com; s=arc-20160816; b=kpzH+Br6+eXpmrFSDFfUK0U91WwZ5Abalhk8lYCJfxibc/adyBnoee7rH3Uma0muVH ehF12OTQWK0bMd6gdHjOyRwpyOxkgamHr6Nojxf2U/maKucmKfduhVer5tbp1aiG/JVa ps4cE+DYVeb4JRX/7joVeHAPDApFlwbu6OTiCsUGTM9djhuFAyO6bHecW5mqVfdcQ7RB W81g3UjjpI1qjw8OPcFpy5QBF2prayWSe7yJdX3jY4Ha3gKDX+HbdVs/uAhqUaz5lUHk uHRWNC6Ab3eOn4Y0c2XBBJQ1Mz133i0jUYmcMck7zSav5ovXwj091OygCM6QLo8/VQ7I XtOA== 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=Eb7Pm+4Pk+qR6JR1inVRUGP4XSk2ZqQlmfjkF0kFcJDA5VRhF4KIbpuCoey2gxcKw9 WOc3tP+S7L/FfeH3FinwWGt7hYS3X7Vh6vdiHzUWtml3pc74m8IjTJ/VDv6drw7YMRIa aTsCAEy8Sq1crhCg0K9P2gO/XboHmDEFuQwAgI0L7+FShBT9moQeehCacPNvaOk+TTdA w0Dr6GVHa7IIcpuMPyukpBg+FnwPKrHy5abNWGX1weU4px2vEsO8JpGhUoNLfFELaYZ4 HuRhpyrBvSZPYji01rDahiyEX7CxSmTo+4EFUPSyC9M17eoJwCz5f797fzy61/TFTfdw gUug== 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 o37si4358957qte.143.2019.05.07.11.38.56 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 07 May 2019 11:38: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-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8C55C309B15B; Tue, 7 May 2019 18:38:55 +0000 (UTC) Received: from t460s.redhat.com (ovpn-116-95.ams2.redhat.com [10.36.116.95]) by smtp.corp.redhat.com (Postfix) with ESMTP id 663664123; Tue, 7 May 2019 18:38:52 +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 v2 7/8] mm/memory_hotplug: Make unregister_memory_block_under_nodes() never fail Date: Tue, 7 May 2019 20:38:03 +0200 Message-Id: <20190507183804.5512-8-david@redhat.com> In-Reply-To: <20190507183804.5512-1-david@redhat.com> References: <20190507183804.5512-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.49]); Tue, 07 May 2019 18:38: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 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 Reviewed-by: Dan Williams --- 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, From patchwork Tue May 7 18:38:04 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 10933579 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 5F879933 for ; Tue, 7 May 2019 18:39:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4EDE62880D for ; Tue, 7 May 2019 18:39:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 433392891A; Tue, 7 May 2019 18:39:02 +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 C62A32880D for ; Tue, 7 May 2019 18:39:01 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B145E6B0010; Tue, 7 May 2019 14:38:59 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id AC73F6B0266; Tue, 7 May 2019 14:38:59 -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 8F29D6B0269; Tue, 7 May 2019 14:38:59 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-qt1-f200.google.com (mail-qt1-f200.google.com [209.85.160.200]) by kanga.kvack.org (Postfix) with ESMTP id 6CF066B0010 for ; Tue, 7 May 2019 14:38:59 -0400 (EDT) Received: by mail-qt1-f200.google.com with SMTP id l20so17286358qtq.21 for ; Tue, 07 May 2019 11:38:59 -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=BEy7q9rHfwt3l5FIt7jpUEGaL3ViTPH7RwPgQioEzsM=; b=otpoQRtUswxjSVD3bicPC8izmn1b0k/T6MKPibuGWbWf4uuwIrgzPAI5CWhGifP4WR 6SKdyUV7WU3ZEk0Tep44t812FE2rPwAjIHWu/5T0KK9KEpBE9nHt08gJPM+en0Ogsm2h a/WUXWP3D6+UVKDZNCUKIFdJ2psRK1kvzGU8Jmc5DlJ8D+X1frv9SDtwRtH0+Omnrb/J x1pk+3wcrjPGAWKjv7qsGukfZn+Hqj8OtvIiZAhQLAr99guvfKqR3MGhCgogfTQ9qVK/ 1PYjNobRYEio8mxriQSsFkoElyWOxY2csAlvy65QiwuR9We9kJ7uxEKHNeVpKmqD0QF4 b/mA== 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: APjAAAX+cCRcO5OwyLovSvnttOeWA8FJf7AoXl8jesIMsEAVIZ/B7XOT 2fc3DUaVpMv8/G+QdR28PYxoxFOnW0qP18ibURTu1e2C68RoaRgB7eeVJMFODlPIzNCr4m6hfGg 7tPjZF1b4h8FJ7HM6rCSlOlx1jHqH/xn0TtNB82RbGGJbaeB7pq2VfofkqzsBr7arqA== X-Received: by 2002:ac8:e0f:: with SMTP id a15mr28674208qti.360.1557254339228; Tue, 07 May 2019 11:38:59 -0700 (PDT) X-Google-Smtp-Source: APXvYqzn9Pv1krEOut7XGzFgXvjR7AZzNsDNjvZSqfrc4f8zLIJKKyJ/je9Kazn/JOgqMK9vnFSG X-Received: by 2002:ac8:e0f:: with SMTP id a15mr28674158qti.360.1557254338573; Tue, 07 May 2019 11:38:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557254338; cv=none; d=google.com; s=arc-20160816; b=PBloashZraBX8xHTkp/G/mAv+f5JJpsGlofcqxLTUigCk+FsM4559HGBxhw93cH+Xl JhW/eIRR2fdXzwEn4OK47AqJwarSf0FD5ML15Twn3aHsPjDUVfUjOR43FsBxjfsRiu+X esOjtWKYMmOjqdKzLwTsiSLqDOuwcYBnK01TYmdGIMxmcaYAKLp1ooGytdVdJwV8fDTn R7YMRBIWdFIeaQUa1IJYAfPKhOore6V2EjUKgIsJMVur1pWWlrY3jmKoGpP+yIapM9Qk Zrzc7OO6fD9L07n+DHfvQ8NncAfwz6arF/WwwCYxby5NmlV2QZXnqpyBIsrS2bVcrWlT l1oA== 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=BEy7q9rHfwt3l5FIt7jpUEGaL3ViTPH7RwPgQioEzsM=; b=OQOd+3mtpFqs6wa+NLbq4raES0iIfCIv0UGSQ7xWfQ8UVPihC3xu3VP/EoB7X3b8tr IGwC5v8J7vctALYCpmOTu7A7Mwnq9K8BDCjfbbY3tJggo/2egtvj9/WcvreFOd1V0/SP h02uLCRcjQeuyYxoMbAXePpsx1Twa+dotYLYCLSyCzsEm5LZlm6OF6sloeASq2SMA5wW F5Vbz+DEKA0ycIqEvlQUpSKLfaxwUM/RScLN3oQ46b40IKt0BKQcLV7QarLd4STGAoy1 KyTb6EXI/IVCPwdnxR6XAB9CrBC9QTmbX/Lln9cpHw4Tj0C2B1IenvIU4iocXuFsLkjw LSYQ== 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 r58si1211338qtr.405.2019.05.07.11.38.58 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 07 May 2019 11:38:58 -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-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id BF6BDC05FBCB; Tue, 7 May 2019 18:38:57 +0000 (UTC) Received: from t460s.redhat.com (ovpn-116-95.ams2.redhat.com [10.36.116.95]) by smtp.corp.redhat.com (Postfix) with ESMTP id E0C683DA5; Tue, 7 May 2019 18:38: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 Subject: [PATCH v2 8/8] mm/memory_hotplug: Remove "zone" parameter from sparse_remove_one_section Date: Tue, 7 May 2019 20:38:04 +0200 Message-Id: <20190507183804.5512-9-david@redhat.com> In-Reply-To: <20190507183804.5512-1-david@redhat.com> References: <20190507183804.5512-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Tue, 07 May 2019 18:38:57 +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 Unused, and memory unplug path should never care about zones. This is the job of memory offlining. ZONE_DEVICE might require special care - the caller of arch_remove_memory() should handle this. Signed-off-by: David Hildenbrand Reviewed-by: Dan Williams --- include/linux/memory_hotplug.h | 2 +- mm/memory_hotplug.c | 2 +- mm/sparse.c | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/include/linux/memory_hotplug.h b/include/linux/memory_hotplug.h index 2f1f87e13baa..1a4257c5f74c 100644 --- a/include/linux/memory_hotplug.h +++ b/include/linux/memory_hotplug.h @@ -346,7 +346,7 @@ extern void move_pfn_range_to_zone(struct zone *zone, unsigned long start_pfn, extern bool is_memblock_offlined(struct memory_block *mem); extern int sparse_add_one_section(int nid, unsigned long start_pfn, struct vmem_altmap *altmap); -extern void sparse_remove_one_section(struct zone *zone, struct mem_section *ms, +extern void sparse_remove_one_section(struct mem_section *ms, unsigned long map_offset, struct vmem_altmap *altmap); extern struct page *sparse_decode_mem_map(unsigned long coded_mem_map, unsigned long pnum); diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c index 527fe4f9c620..e0340c8f6df4 100644 --- a/mm/memory_hotplug.c +++ b/mm/memory_hotplug.c @@ -523,7 +523,7 @@ static void __remove_section(struct zone *zone, struct mem_section *ms, start_pfn = section_nr_to_pfn((unsigned long)scn_nr); __remove_zone(zone, start_pfn); - sparse_remove_one_section(zone, ms, map_offset, altmap); + sparse_remove_one_section(ms, map_offset, altmap); } /** diff --git a/mm/sparse.c b/mm/sparse.c index d1d5e05f5b8d..1552c855d62a 100644 --- a/mm/sparse.c +++ b/mm/sparse.c @@ -800,8 +800,8 @@ static void free_section_usemap(struct page *memmap, unsigned long *usemap, free_map_bootmem(memmap); } -void sparse_remove_one_section(struct zone *zone, struct mem_section *ms, - unsigned long map_offset, struct vmem_altmap *altmap) +void sparse_remove_one_section(struct mem_section *ms, unsigned long map_offset, + struct vmem_altmap *altmap) { struct page *memmap = NULL; unsigned long *usemap = NULL;