Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp5698290ybi; Tue, 4 Jun 2019 10:37:32 -0700 (PDT) X-Google-Smtp-Source: APXvYqwcEUEl618SgDd7XwiZA611hgyCV3rQByusbHpvOETFqiU7XBUJePiE86SXTi3YHsfNe/lt X-Received: by 2002:a63:514:: with SMTP id 20mr23095337pgf.272.1559669852301; Tue, 04 Jun 2019 10:37:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559669852; cv=none; d=google.com; s=arc-20160816; b=r9x85exSUh3LBahN6pEtuvRMOejG+LiSOclK8i9S2eM5lHUZCTOsBrOaJUNtbNtNqd AvVGv/ETX5WXcbhMA29TPIRm7qjY+nOeuAN7B17SpStENBNMJGP88kI2x+oWylv7Co9K uw3rf0ygBFU4hRIPqVyIu/EReBjLuGUTaHAEv/IVJXwiWJ4APN6+fkl2RAN/6qy8CCAf 71S6u/3tB2bf9iGDuIbD361tV+GEujEa8EFyMq8DNKEXlO7716a8DUDQEHs+itXK1mTs vot8X0e6QG5g2600Mwz+2HQUPCiCerJpydQ0/QWwy93vD4YYDHPGr96OwxBvqdRdKp7L 3onQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=jUpoQ7wlR2M1m2snusEKdFDracWmi3gm5oagc8bjyvc=; b=Gyemw5brnfK0pfYqCc8aHgylAKIUTn4KxgUgqv4WqthiLKdBLhTOD8egjzf0nS0No7 PMrWfugLymlH0QhlNMlPYeuGrX8rDWgXCv6zDVEmz/mptoBdgWBvm8oLIykB0ebLFKXl 2M6eUTjv57I/c8DnNN3cgFn+S2IWa/saTwxGw58rRf5horTNMqSbPHRssTrc9D3qxmVa t3mf9G2MW1Xk43gM3EM5r7NZbwJ4I6sS49wYapsgXrrAAtI0t4Jw+hwP3euCXORHILej B5oZX1zcKVbOoUq23tXn3LX+8+ZLcdVs4t0uMoYBQPTGHRbO6EnkN0Ecs2rQG2hhX6bC /Dsw== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i12si22252960pgt.255.2019.06.04.10.37.15; Tue, 04 Jun 2019 10:37:32 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726486AbfFDRgL (ORCPT + 99 others); Tue, 4 Jun 2019 13:36:11 -0400 Received: from foss.arm.com ([217.140.101.70]:48706 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726173AbfFDRgL (ORCPT ); Tue, 4 Jun 2019 13:36:11 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 523C980D; Tue, 4 Jun 2019 10:36:10 -0700 (PDT) Received: from [10.1.196.75] (e110467-lin.cambridge.arm.com [10.1.196.75]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 0002F3F5AF; Tue, 4 Jun 2019 10:36:05 -0700 (PDT) Subject: Re: [PATCH v3 04/11] arm64/mm: Add temporary arch_remove_memory() implementation To: David Hildenbrand , Wei Yang Cc: linux-mm@kvack.org, 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, linux-arm-kernel@lists.infradead.org, akpm@linux-foundation.org, Dan Williams , Igor Mammedov , Catalin Marinas , Will Deacon , Mark Rutland , Ard Biesheuvel , Chintan Pandya , Mike Rapoport , Jun Yao , Yu Zhao , Anshuman Khandual References: <20190527111152.16324-1-david@redhat.com> <20190527111152.16324-5-david@redhat.com> <20190603214139.mercn5hol2yyfl2s@master> <5059f68d-45d2-784e-0770-ee67060773c7@redhat.com> From: Robin Murphy Message-ID: <7a5b8c8d-f1bb-9c7e-9809-405af374fecd@arm.com> Date: Tue, 4 Jun 2019 18:36:04 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1 MIME-Version: 1.0 In-Reply-To: <5059f68d-45d2-784e-0770-ee67060773c7@redhat.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-GB Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 04/06/2019 07:56, David Hildenbrand wrote: > On 03.06.19 23:41, Wei Yang wrote: >> On Mon, May 27, 2019 at 01:11:45PM +0200, David Hildenbrand wrote: >>> A proper arch_remove_memory() implementation is on its way, which also >>> cleanly removes page tables in arch_add_memory() in case something goes >>> wrong. >> >> Would this be better to understand? >> >> removes page tables created in arch_add_memory > > That's not what this sentence expresses. Have a look at > arch_add_memory(), in case __add_pages() fails, the page tables are not > removed. This will also be fixed by Anshuman in the same shot. > >> >>> >>> As we want to use arch_remove_memory() in case something goes wrong >>> during memory hotplug after arch_add_memory() finished, let's add >>> a temporary hack that is sufficient enough until we get a proper >>> implementation that cleans up page table entries. >>> >>> We will remove CONFIG_MEMORY_HOTREMOVE around this code in follow up >>> patches. >>> >>> Cc: Catalin Marinas >>> Cc: Will Deacon >>> Cc: Mark Rutland >>> Cc: Andrew Morton >>> Cc: Ard Biesheuvel >>> Cc: Chintan Pandya >>> Cc: Mike Rapoport >>> Cc: Jun Yao >>> Cc: Yu Zhao >>> Cc: Robin Murphy >>> Cc: Anshuman Khandual >>> Signed-off-by: David Hildenbrand >>> --- >>> arch/arm64/mm/mmu.c | 19 +++++++++++++++++++ >>> 1 file changed, 19 insertions(+) >>> >>> diff --git a/arch/arm64/mm/mmu.c b/arch/arm64/mm/mmu.c >>> index a1bfc4413982..e569a543c384 100644 >>> --- a/arch/arm64/mm/mmu.c >>> +++ b/arch/arm64/mm/mmu.c >>> @@ -1084,4 +1084,23 @@ int arch_add_memory(int nid, u64 start, u64 size, >>> return __add_pages(nid, start >> PAGE_SHIFT, size >> PAGE_SHIFT, >>> restrictions); >>> } >>> +#ifdef CONFIG_MEMORY_HOTREMOVE >>> +void arch_remove_memory(int nid, u64 start, u64 size, >>> + struct vmem_altmap *altmap) >>> +{ >>> + unsigned long start_pfn = start >> PAGE_SHIFT; >>> + unsigned long nr_pages = size >> PAGE_SHIFT; >>> + struct zone *zone; >>> + >>> + /* >>> + * FIXME: Cleanup page tables (also in arch_add_memory() in case >>> + * adding fails). Until then, this function should only be used >>> + * during memory hotplug (adding memory), not for memory >>> + * unplug. ARCH_ENABLE_MEMORY_HOTREMOVE must not be >>> + * unlocked yet. >>> + */ >>> + zone = page_zone(pfn_to_page(start_pfn)); >> >> Compared with arch_remove_memory in x86. If altmap is not NULL, zone will be >> retrieved from page related to altmap. Not sure why this is not the same? > > This is a minimal implementation, sufficient for this use case here. A > full implementation is in the works. For now, this function will not be > used with an altmap (ZONE_DEVICE is not esupported for arm64 yet). FWIW the other pieces of ZONE_DEVICE are now due to land in parallel, but as long as we don't throw the ARCH_ENABLE_MEMORY_HOTREMOVE switch then there should still be no issue. Besides, given that we should consistently ignore the altmap everywhere at the moment, it may even work out regardless. One thing stands out about the failure path thing, though - if __add_pages() did fail, can it still be guaranteed to have initialised the memmap such that page_zone() won't return nonsense? Last time I looked that was still a problem when removing memory which had been successfully added, but never onlined (although I do know that particular case was already being discussed at the time, and I've not been paying the greatest attention since). Robin.