Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp791354pxb; Wed, 29 Sep 2021 09:43:11 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzTDVrJf+CuuXHjNnMMPjZEzB/t9xQc5wHVKhVqnlbrJOdIDUD56ZpMxjCvPOneecHHPvnK X-Received: by 2002:a17:906:940c:: with SMTP id q12mr775444ejx.151.1632933791423; Wed, 29 Sep 2021 09:43:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632933791; cv=none; d=google.com; s=arc-20160816; b=tQe0cHrXdLwB1AH9Q1+3SKufwX85nxhHZm2mWg/7F+reuqhamuOzatp3XN/3nxuqso NivUXLDKIX73NjFUyKYpTjXbBONMU/EtFyWIRgV3e2B+nvhPdhAgtqmg3Z8HD06HZnMH KH5lkEq1+0RYNoR0xXtlSvEGVEkAEirJ0ICQujLLEDCloq3N12nmp2EpyHSubBtgsBHR uzN6egRCr3Tq8VEoFnCZVEePV6ah0CgC9Vw+hBhDcNGQPIcNXjs98CXTgl3T15TJbwYv OJ54Q88H3XfaFSl5vSfaG2cCTKaVhb1zNVeh7Yhzm4n5EOsFy8DPZGA75yz9Eq/0C+35 Lm2w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=bUZ6uQevTFO1JHOfeOD0IUvgdvgnyGZnnt8rVFx/Nt8=; b=SiFQgkcb8q1h8YYXYsdl2TYuv3Mx/VFQ2fzii0zeMKo/NPSRUXhxMphYkePikL4QOm lglwmDLbsEdbPjB4Rc7o06vu7+K+KoikD6zBMkAUQWYO9uvRu8eQOvmwxAwJHVZvcB90 C/saVqWQVr+Dy4nUQmhBH0rj5huIjv5S0tRHyYeyd3B9Z4NFqTOHtMwdpLbc80zdGcHH i9qZZpnzPRbLwpVLn6Sg0rJQFCGzXCs1TZdpb3S+WJpfaS/Migd0vz2uK3bCS209uZeI IlVTVuftMXGgeNmcOB1CUdMJlYUoSGPGTypdNEys+jV+GJNsjRteR14VwieN9domqp16 ec4g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=SuGn5wf4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id x9si367160ejn.252.2021.09.29.09.42.42; Wed, 29 Sep 2021 09:43:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=SuGn5wf4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346057AbhI2Qll (ORCPT + 99 others); Wed, 29 Sep 2021 12:41:41 -0400 Received: from mail.kernel.org ([198.145.29.99]:42032 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345941AbhI2Qlk (ORCPT ); Wed, 29 Sep 2021 12:41:40 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 8683761411; Wed, 29 Sep 2021 16:39:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1632933599; bh=t8dn/WnbBBYbLwRPmrH71m1uQ/o93fnaL1REzEP+yOs=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=SuGn5wf4j66NI18xGqtKOMcbTU3KcbpcZgDCLxzsuVnUtCLZTFT19+lBcWHpX8l5Y 4HJt3SEXjTF8YFlmYhiRqC3Q7e2EIIhbZHzkA4PWpwavCaveL76xurOeZQChTMoP9G rSRG1qLj38huXnzTeWAzkYTYXFbJIAMb5egCuWxdDLUhGyl1zH02ClSM0KB9MmcD49 nLWVlcXk/IDGZs0YiU+Hh7V4VGJe5X3YINZpqugr6yEpnMKAIHPeLZUU7CqOhCT879 znp+/oqCsnMuduLTlsGm00As2ESqshUFy23cAs69hXOWfZANijgY7kzxg3rq/btf3P sqf5f4Xu/Jqag== Date: Wed, 29 Sep 2021 09:39:58 -0700 From: Mike Rapoport To: David Hildenbrand Cc: linux-kernel@vger.kernel.org, Andrew Morton , Michal Hocko , Oscar Salvador , Jianyong Wu , "Aneesh Kumar K . V" , Vineet Gupta , Geert Uytterhoeven , Huacai Chen , Jiaxun Yang , Thomas Bogendoerfer , Heiko Carstens , Vasily Gorbik , Christian Borntraeger , Eric Biederman , Arnd Bergmann , linux-snps-arc@lists.infradead.org, linux-ia64@vger.kernel.org, linux-m68k@lists.linux-m68k.org, linux-mips@vger.kernel.org, linux-s390@vger.kernel.org, linux-mm@kvack.org, kexec@lists.infradead.org Subject: Re: [PATCH v1 3/4] memblock: add MEMBLOCK_DRIVER_MANAGED to mimic IORESOURCE_SYSRAM_DRIVER_MANAGED Message-ID: References: <20210927150518.8607-1-david@redhat.com> <20210927150518.8607-4-david@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210927150518.8607-4-david@redhat.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, On Mon, Sep 27, 2021 at 05:05:17PM +0200, David Hildenbrand wrote: > Let's add a flag that corresponds to IORESOURCE_SYSRAM_DRIVER_MANAGED. > Similar to MEMBLOCK_HOTPLUG, most infrastructure has to treat such memory > like ordinary MEMBLOCK_NONE memory -- for example, when selecting memory > regions to add to the vmcore for dumping in the crashkernel via > for_each_mem_range(). Can you please elaborate on the difference in semantics of MEMBLOCK_HOTPLUG and MEMBLOCK_DRIVER_MANAGED? Unless I'm missing something they both mark memory that can be unplugged anytime and so it should not be used in certain cases. Why is there a need for a new flag? > However, especially kexec_file is not supposed to select such memblocks via > for_each_free_mem_range() / for_each_free_mem_range_reverse() to place > kexec images, similar to how we handle IORESOURCE_SYSRAM_DRIVER_MANAGED > without CONFIG_ARCH_KEEP_MEMBLOCK. > > Let's document why kexec_walk_memblock() won't try placing images on > areas marked MEMBLOCK_DRIVER_MANAGED -- similar to > IORESOURCE_SYSRAM_DRIVER_MANAGED handling in locate_mem_hole_callback() > via kexec_walk_resources(). > > We'll make sure that memory hotplug code sets the flag where applicable > (IORESOURCE_SYSRAM_DRIVER_MANAGED) next. This prepares architectures > that need CONFIG_ARCH_KEEP_MEMBLOCK, such as arm64, for virtio-mem > support. > > Signed-off-by: David Hildenbrand > --- > include/linux/memblock.h | 16 ++++++++++++++-- > kernel/kexec_file.c | 5 +++++ > mm/memblock.c | 4 ++++ > 3 files changed, 23 insertions(+), 2 deletions(-) > > diff --git a/include/linux/memblock.h b/include/linux/memblock.h > index b49a58f621bc..7d8d656d5082 100644 > --- a/include/linux/memblock.h > +++ b/include/linux/memblock.h > @@ -33,12 +33,17 @@ extern unsigned long long max_possible_pfn; > * @MEMBLOCK_NOMAP: don't add to kernel direct mapping and treat as > * reserved in the memory map; refer to memblock_mark_nomap() description > * for further details > + * @MEMBLOCK_DRIVER_MANAGED: memory region that is always detected via a driver, > + * corresponding to IORESOURCE_SYSRAM_DRIVER_MANAGED in the kernel resource > + * tree. Especially kexec should never use this memory for placing images and > + * shouldn't expose this memory to the second kernel. > */ > enum memblock_flags { > MEMBLOCK_NONE = 0x0, /* No special request */ > MEMBLOCK_HOTPLUG = 0x1, /* hotpluggable region */ > MEMBLOCK_MIRROR = 0x2, /* mirrored region */ > MEMBLOCK_NOMAP = 0x4, /* don't add to kernel direct mapping */ > + MEMBLOCK_DRIVER_MANAGED = 0x8, /* always detected via a driver */ > }; > > /** > @@ -209,7 +214,8 @@ static inline void __next_physmem_range(u64 *idx, struct memblock_type *type, > */ > #define for_each_mem_range(i, p_start, p_end) \ > __for_each_mem_range(i, &memblock.memory, NULL, NUMA_NO_NODE, \ > - MEMBLOCK_HOTPLUG, p_start, p_end, NULL) > + MEMBLOCK_HOTPLUG | MEMBLOCK_DRIVER_MANAGED, \ > + p_start, p_end, NULL) > > /** > * for_each_mem_range_rev - reverse iterate through memblock areas from > @@ -220,7 +226,8 @@ static inline void __next_physmem_range(u64 *idx, struct memblock_type *type, > */ > #define for_each_mem_range_rev(i, p_start, p_end) \ > __for_each_mem_range_rev(i, &memblock.memory, NULL, NUMA_NO_NODE, \ > - MEMBLOCK_HOTPLUG, p_start, p_end, NULL) > + MEMBLOCK_HOTPLUG | MEMBLOCK_DRIVER_MANAGED,\ > + p_start, p_end, NULL) > > /** > * for_each_reserved_mem_range - iterate over all reserved memblock areas > @@ -250,6 +257,11 @@ static inline bool memblock_is_nomap(struct memblock_region *m) > return m->flags & MEMBLOCK_NOMAP; > } > > +static inline bool memblock_is_driver_managed(struct memblock_region *m) > +{ > + return m->flags & MEMBLOCK_DRIVER_MANAGED; > +} > + > int memblock_search_pfn_nid(unsigned long pfn, unsigned long *start_pfn, > unsigned long *end_pfn); > void __next_mem_pfn_range(int *idx, int nid, unsigned long *out_start_pfn, > diff --git a/kernel/kexec_file.c b/kernel/kexec_file.c > index 33400ff051a8..8347fc158d2b 100644 > --- a/kernel/kexec_file.c > +++ b/kernel/kexec_file.c > @@ -556,6 +556,11 @@ static int kexec_walk_memblock(struct kexec_buf *kbuf, > if (kbuf->image->type == KEXEC_TYPE_CRASH) > return func(&crashk_res, kbuf); > > + /* > + * Using MEMBLOCK_NONE will properly skip MEMBLOCK_DRIVER_MANAGED. See > + * IORESOURCE_SYSRAM_DRIVER_MANAGED handling in > + * locate_mem_hole_callback(). > + */ > if (kbuf->top_down) { > for_each_free_mem_range_reverse(i, NUMA_NO_NODE, MEMBLOCK_NONE, > &mstart, &mend, NULL) { > diff --git a/mm/memblock.c b/mm/memblock.c > index 47a56b223141..540a35317fb0 100644 > --- a/mm/memblock.c > +++ b/mm/memblock.c > @@ -979,6 +979,10 @@ static bool should_skip_region(struct memblock_type *type, > if (!(flags & MEMBLOCK_NOMAP) && memblock_is_nomap(m)) > return true; > > + /* skip driver-managed memory unless we were asked for it explicitly */ > + if (!(flags & MEMBLOCK_DRIVER_MANAGED) && memblock_is_driver_managed(m)) > + return true; > + > return false; > } > > -- > 2.31.1 > -- Sincerely yours, Mike.