From patchwork Thu Aug 16 10:06:26 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 10567277 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 A8637139B for ; Thu, 16 Aug 2018 10:06:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 947572856F for ; Thu, 16 Aug 2018 10:06:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 888902A836; Thu, 16 Aug 2018 10:06:49 +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 1BE862856F for ; Thu, 16 Aug 2018 10:06:49 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D65476B000D; Thu, 16 Aug 2018 06:06:47 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id CED646B0266; Thu, 16 Aug 2018 06:06:47 -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 B8EB96B0269; Thu, 16 Aug 2018 06:06:47 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-qt0-f200.google.com (mail-qt0-f200.google.com [209.85.216.200]) by kanga.kvack.org (Postfix) with ESMTP id 882C86B000D for ; Thu, 16 Aug 2018 06:06:47 -0400 (EDT) Received: by mail-qt0-f200.google.com with SMTP id j9-v6so3248691qtn.22 for ; Thu, 16 Aug 2018 03:06:47 -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; bh=9AmwCETxK5BLAns08GejjkVezlq4beKGZdoiq+TAw3o=; b=uVk2JMi+8OnNT2MOhJSVH8f/sbtuvs4Hl/rtBNJzHjG1R0xLtIqJEn1mCcGk2JWzXk h08hrJUNy3S2vIFlvEomx0hdGtBqupcvnfQTRIMSWXrcsi73AI6oQKJgonPdAvM8Afuw rdRp8cT+1w2MT7uG8EC9IJKztOITuhESnzJ8tK/6Q4BZCi7MPwoB/+qGTa6qYqQBJDC9 QZ1ooz5MeC6/L9jiCsFZWwYQW04oxQTbAOO8kFkdRu1SJTEGKtJeISPWi4sNtSWyq6r4 38CEfkr+XBcaURbBmGnW1lV2sv/OwV/INJxiK94HSPetgdn+HwDzIqTKBKHoPYnk9pbO ZDnQ== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of david@redhat.com designates 66.187.233.73 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com X-Gm-Message-State: AOUpUlFDdaCcmw1T/9gWntUR1ByviDsLmuUXsWBoRnfXP9o8kDLz1dwZ znQC8twzIL9ooyessH8qDzVNnUyMKmS1lQnEpESihUcjiIEFps7g870q4GSVy69W4/V5K/GR3XA NRlTE6Zg3vhngk2reIOneP7d1a3ju/StvloPOdKBhVreovQOfJGjq4FYOEIPrKKKOJQ== X-Received: by 2002:ae9:e606:: with SMTP id z6-v6mr11800756qkf.117.1534414007329; Thu, 16 Aug 2018 03:06:47 -0700 (PDT) X-Google-Smtp-Source: AA+uWPz/veLxseTEbyPhD7UCJLGAahsnnbgL7LhnZZWochG70e+T7UewlR02MsIisZF7JCy/7PZm X-Received: by 2002:ae9:e606:: with SMTP id z6-v6mr11800719qkf.117.1534414006707; Thu, 16 Aug 2018 03:06:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1534414006; cv=none; d=google.com; s=arc-20160816; b=QpJscs9Sjta3f8los4RYXOJwbBNA8DHWFE87aQZ2+v48YSxc1zBbx53Rw8Vs4N68nN GyEyQwIrU2FM+O24c34bm2Z+6aYs0RsV9YAKROyE98RFsTCIjS5bbRmVYq9SlPexkKuO 3i38y7/6lgSgYqvLhitho3EeHacJVnwHnr3KdmC1LHPeGNO++h4BbiHQj9SOJrN5XS0g tkhB6SVPdlWoPl8Pm1noy3WI8ghaV8UEq3kJ/APSmmLECRijSVJvHNWbeHQZ1hQcTg5G fIqw86005R8t4xZ8YU0s4EiL6aXMUAVgbHhcqGft4Bj7xH0plUyFzNqeA0ClKuh6XVpk 4nhQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=9AmwCETxK5BLAns08GejjkVezlq4beKGZdoiq+TAw3o=; b=hKojJCNg9hfgQGwCJjxQI9M/abpKxarh0Ob19L2YQvC38cpMsUnBMpJJLo6uzZol36 aWXRMvOtKVrRjP2b9tZpMAeFxDoff0tGoBUZhYoUP4fvF+9L57Lp9JNUzDMHBjVb/Vno JmHDXPShGjGzsHIdo7VtlK9jMn7nh5bRTtJoja1uJYeTW9XnMEaVSOlDcQjuaUPf9+OM /jVY1IwLCOc7w12Xy5LeFjFZzA1Y5ASr4235e572Ys689urpU8J1zU+95lMxLy+ApVsh 7TO7H5CV+y0+sjyqYqMjzqDxXLoxuCLyilT0fjnyRJ8lLaeGJKQAVfTbyhNuuQ3f57gE JFPw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of david@redhat.com designates 66.187.233.73 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 (mx3-rdu2.redhat.com. [66.187.233.73]) by mx.google.com with ESMTPS id y131-v6si1655301qka.286.2018.08.16.03.06.46 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 16 Aug 2018 03:06:46 -0700 (PDT) Received-SPF: pass (google.com: domain of david@redhat.com designates 66.187.233.73 as permitted sender) client-ip=66.187.233.73; Authentication-Results: mx.google.com; spf=pass (google.com: domain of david@redhat.com designates 66.187.233.73 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-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4878A814FDCE; Thu, 16 Aug 2018 10:06:46 +0000 (UTC) Received: from t460s.redhat.com (ovpn-116-94.ams2.redhat.com [10.36.116.94]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4326610EE784; Thu, 16 Aug 2018 10:06:43 +0000 (UTC) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, Andrew Morton , Michal Hocko , Vlastimil Babka , Stephen Rothwell , Pavel Tatashin , Kemi Wang , David Rientjes , Jia He , Oscar Salvador , Petr Tesarik , Andrey Ryabinin , Dan Williams , David Hildenbrand , Mathieu Malaterre , Baoquan He , Wei Yang , Ross Zwisler , "Kirill A . Shutemov" Subject: [PATCH v1 3/5] mm/memory_hotplug: check if sections are already online/offline Date: Thu, 16 Aug 2018 12:06:26 +0200 Message-Id: <20180816100628.26428-4-david@redhat.com> In-Reply-To: <20180816100628.26428-1-david@redhat.com> References: <20180816100628.26428-1-david@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Thu, 16 Aug 2018 10:06:46 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Thu, 16 Aug 2018 10:06:46 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'david@redhat.com' RCPT:'' 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 add some more sanity checking now that onlining/offlining code works completely on section basis. This will make sure that we will never try to online/offline sections that are already (or partially) in the desired state. Signed-off-by: David Hildenbrand --- include/linux/mmzone.h | 2 ++ mm/memory_hotplug.c | 5 +++++ mm/sparse.c | 28 ++++++++++++++++++++++++++++ 3 files changed, 35 insertions(+) diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h index 0859130e4db8..addfa41c047a 100644 --- a/include/linux/mmzone.h +++ b/include/linux/mmzone.h @@ -1228,6 +1228,8 @@ static inline int online_section_nr(unsigned long nr) } #ifdef CONFIG_MEMORY_HOTPLUG +bool mem_sections_online(unsigned long pfn, unsigned long end_pfn); +bool mem_sections_offline(unsigned long pfn, unsigned long end_pfn); void online_mem_sections(unsigned long start_pfn, unsigned long end_pfn); #ifdef CONFIG_MEMORY_HOTREMOVE void offline_mem_sections(unsigned long start_pfn, unsigned long end_pfn); diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c index 30d2fa42b0bb..3dc6d2a309c2 100644 --- a/mm/memory_hotplug.c +++ b/mm/memory_hotplug.c @@ -901,6 +901,8 @@ int __ref online_pages(unsigned long pfn, unsigned long nr_pages, int online_typ return -EINVAL; if (!IS_ALIGNED(nr_pages, PAGES_PER_SECTION)) return -EINVAL; + if (!mem_sections_offline(pfn, pfn + nr_pages)) + return -EINVAL; /* * We can't use pfn_to_nid() because nid might be stored in struct page @@ -1609,6 +1611,9 @@ int offline_pages(unsigned long start_pfn, unsigned long nr_pages) return -EINVAL; if (!IS_ALIGNED(nr_pages, PAGES_PER_SECTION)) return -EINVAL; + if (!mem_sections_online(start_pfn, end_pfn)) + return -EINVAL; + /* This makes hotplug much easier...and readable. we assume this for now. .*/ if (!test_pages_in_a_zone(start_pfn, end_pfn, &valid_start, &valid_end)) diff --git a/mm/sparse.c b/mm/sparse.c index 10b07eea9a6e..44693cf38ca9 100644 --- a/mm/sparse.c +++ b/mm/sparse.c @@ -520,6 +520,34 @@ void __init sparse_init(void) #ifdef CONFIG_MEMORY_HOTPLUG +/* check if all mem sections are online */ +bool mem_sections_online(unsigned long pfn, unsigned long end_pfn) +{ + for (; pfn < end_pfn; pfn += PAGES_PER_SECTION) { + unsigned long section_nr = pfn_to_section_nr(pfn); + + if (WARN_ON(!valid_section_nr(section_nr))) + continue; + if (!online_section_nr(section_nr)) + return false; + } + return true; +} + +/* check if all mem sections are offline */ +bool mem_sections_offline(unsigned long pfn, unsigned long end_pfn) +{ + for (; pfn < end_pfn; pfn += PAGES_PER_SECTION) { + unsigned long section_nr = pfn_to_section_nr(pfn); + + if (WARN_ON(!valid_section_nr(section_nr))) + continue; + if (online_section_nr(section_nr)) + return false; + } + return true; +} + /* Mark all memory sections within the pfn range as online */ void online_mem_sections(unsigned long start_pfn, unsigned long end_pfn) {