Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp2544653imm; Thu, 16 Aug 2018 11:12:52 -0700 (PDT) X-Google-Smtp-Source: AA+uWPyx3rxilD3illJTQM56dYj1eaSz7ZbMfsFZBPG5rXA2ncAII20/PRfAYgPTEfPMdJo6m+L4 X-Received: by 2002:a65:62d8:: with SMTP id m24-v6mr30317331pgv.307.1534443172123; Thu, 16 Aug 2018 11:12:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1534443172; cv=none; d=google.com; s=arc-20160816; b=KYgmdJh0F1t8F15Wtj6GlnuzzJVlAfcmZnO776QkUm33tI0gQvZ6oA4cBsdNyLF5AK JDZQKF72xxTzUEAquJQro1o1/TNfxbJyb3pT+aKUz0xT3mTXxiPxiEPsFvK40AqkJA7u G6TGnXkW+lQbvfhW1hbR/y/WGP729Oq9K1q8f+Xa8DSqdWaLbO1aSyN7eC2MvyrNI0Oy GR4B/Tgi2843B7hiIgVefu1Tq97KhT2J7KN6ARPZew7UWoa3N+MpVV6UKJU+90i5v19w pS6KevQxjPa8SfWqzPxg5o9tr9l9kckOXVxC96/1mODry/KBM4goLGm8Ty9OdS1BONot dtww== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=kyp7fPQclWGZBlYTNBuM7MhOM2Q42exOsD1g/XpCns8=; b=iEGLPJ9dDngliTsKFmjhhXAxV4GpNpKgwD4qWCcm3CPwLGGw+wLRjX/XN6hajb+XPm DeL6XlFr7jwy68GbaBbmvcBkp+BtBGfK2v4Lqo+5Wsq5anr5lQQ4sbg8YWLVoUdbdlUl nZ4gHfkm7tjz3rK+uk99r6+yb1m1Av3tLLXsW08N55kA/HssvfbFluFs4FvvDoLzr0j4 N2xPeSBSh61EQJtlJqqqncF/jaqi7ZnqHb1Zegc5XMNmD6XwRnLUhcQA53BXskHdDG0W Wc9ETbe+df2NCH4AOCFVnaXLHtnE/7u1osuaUv9lC5lYhYr6jopTU4TbezoXlH+6sTHE y5mQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c5-v6si1730828pgd.478.2018.08.16.11.12.37; Thu, 16 Aug 2018 11:12:52 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390764AbeHPNEN (ORCPT + 99 others); Thu, 16 Aug 2018 09:04:13 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:55824 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728018AbeHPNEM (ORCPT ); Thu, 16 Aug 2018 09:04:12 -0400 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 054E440122C4; Thu, 16 Aug 2018 10:06:43 +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 020A510EE95C; Thu, 16 Aug 2018 10:06:39 +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 2/5] mm/memory_hotplug: enforce section alignment when onlining/offlining Date: Thu, 16 Aug 2018 12:06:25 +0200 Message-Id: <20180816100628.26428-3-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.5]); Thu, 16 Aug 2018 10:06:43 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Thu, 16 Aug 2018 10:06:43 +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:'' Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org onlining/offlining code works on whole sections, so let's enforce that. Existing code only allows to add memory in memory block size. And only whole memory blocks can be onlined/offlined. Memory blocks are always aligned to sections, so this should not break anything. online_pages/offline_pages will implicitly mark whole sections online/offline, so the code really can only handle such granularities. (especially offlining code cannot deal with pageblock_nr_pages but theoretically only MAX_ORDER-1) Signed-off-by: David Hildenbrand --- mm/memory_hotplug.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c index 090cf474de87..30d2fa42b0bb 100644 --- a/mm/memory_hotplug.c +++ b/mm/memory_hotplug.c @@ -897,6 +897,11 @@ int __ref online_pages(unsigned long pfn, unsigned long nr_pages, int online_typ struct memory_notify arg; struct memory_block *mem; + if (!IS_ALIGNED(pfn, PAGES_PER_SECTION)) + return -EINVAL; + if (!IS_ALIGNED(nr_pages, PAGES_PER_SECTION)) + return -EINVAL; + /* * We can't use pfn_to_nid() because nid might be stored in struct page * which is not yet initialized. Instead, we find nid from memory block. @@ -1600,10 +1605,9 @@ int offline_pages(unsigned long start_pfn, unsigned long nr_pages) struct zone *zone; struct memory_notify arg; - /* at least, alignment against pageblock is necessary */ - if (!IS_ALIGNED(start_pfn, pageblock_nr_pages)) + if (!IS_ALIGNED(start_pfn, PAGES_PER_SECTION)) return -EINVAL; - if (!IS_ALIGNED(end_pfn, pageblock_nr_pages)) + if (!IS_ALIGNED(nr_pages, PAGES_PER_SECTION)) return -EINVAL; /* This makes hotplug much easier...and readable. we assume this for now. .*/ -- 2.17.1