Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp4142067imw; Tue, 12 Jul 2022 02:39:39 -0700 (PDT) X-Google-Smtp-Source: AGRyM1tym12mpK6pQ3ANuOEAurgjzK8TUyCh3j35gs0jOGxrKhs3bz8rvt4R+JUdFKqwr10f+aYF X-Received: by 2002:a17:903:22cf:b0:16c:4145:75c5 with SMTP id y15-20020a17090322cf00b0016c414575c5mr11381889plg.127.1657618779370; Tue, 12 Jul 2022 02:39:39 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1657618779; cv=pass; d=google.com; s=arc-20160816; b=RPgE+lED1YNj0DYUwPZKo31Xzjs6Dch2MQfOwjP/pfbKSR3YpOF6IKi+RIw+PF4HjW U4fH1N0TzpxpeWFT+cKa7E8OoWBZmu+5aCUphM22t49NAogJslcJDPjSOILhl77rL12w 4PHnp6uI/NK3Z4XglO0ipivZM8/Q4AjjXwzwFiVM2eyAYckf/6Csx/QNnDwbn7D++DWH xAtGI8HmNHuXfxjs+ZTqdM0EnDzxoCZTpxV0EITu1T65Fbnrkg1rAUXmgrIe7l/bHVRl 8N9lptuG8xqZrQBySiSjvAC9ogAx1pc0p2HXhKVte3Suki2I06Fv20AgtKVTgI9n2Zg3 rMzA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:importance:content-transfer-encoding :mime-version:subject:references:in-reply-to:message-id:cc:to:from :date:dkim-signature; bh=0D684KlQxe15o6oPTlLFmpWsKQgQVLQH0JtURWns8cw=; b=irnZNubr3Vph66fzeQykdfC4HcUJ7egTdfkgmue4GWKcVTK++QORDUJHHi4qug8wQ7 /YTUJFB3SQkYfpUSA7yYb8CNLUSymVL77QcB/5kP4RCqqe0ScJx3l2kSFChs3+6y1nLC weJkDoFDNHOPym/ewSPxdJkSL9SaoWUPANYpE5ewoa+j+h61HIHMpqA0hTtOlP0JidOL mSnw/8+z04QUetWyKULq3bpeJ+LnXo8pSSrvwCLejzQzslJ41EQYmS2XoGmrI8yTjJlb zGPWRHRWXXjIRs2VuEnR2zuYKV6E9eNF0q24CepfO6QTZt6Oj+9aH1Mso1eyVNwXDuQf U5lg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.beauty header.s=zmail header.b=nYbhbFyM; arc=pass (i=1 spf=pass spfdomain=linux.beauty dkim=pass dkdomain=linux.beauty dmarc=pass fromdomain=linux.beauty>); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l14-20020a170902f68e00b0016bf48465e7si14570001plg.380.2022.07.12.02.39.26; Tue, 12 Jul 2022 02:39:39 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.beauty header.s=zmail header.b=nYbhbFyM; arc=pass (i=1 spf=pass spfdomain=linux.beauty dkim=pass dkdomain=linux.beauty dmarc=pass fromdomain=linux.beauty>); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232181AbiGLJbd (ORCPT + 99 others); Tue, 12 Jul 2022 05:31:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55842 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229621AbiGLJbb (ORCPT ); Tue, 12 Jul 2022 05:31:31 -0400 Received: from sender4-op-o14.zoho.com (sender4-op-o14.zoho.com [136.143.188.14]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5AB159CE2A; Tue, 12 Jul 2022 02:31:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657618275; cv=none; d=zohomail.com; s=zohoarc; b=esepyqqENhbUHssqbm3w5bD5cdhGO5fi2Rhz8vN7REpruv8h5AblXGWeHGMfA9CuPc0LxktiSlmHc0n4RDO4uc3GXuGbn6b+1ZOlqZqOk5xdCrVt/1P8fB3E60rphH+ZAQ9FWeikvWSzzHJeDKmtyixozeQOWMblbKccAnnARuo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1657618275; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=0D684KlQxe15o6oPTlLFmpWsKQgQVLQH0JtURWns8cw=; b=gWxrPwEeg3nDSUhtbtH0/Xo5toBJDzLtgUCngbwwy7b/qXsE91WtAXt+TMZl3FJNpVMTJh5ZUSTUSYE1dPOHCodPK2lIZntIx8qU2b+eI470DkAvCIOBArmKXmHnz7nI2BzmEB4ett02PWa53oNf4dBfVNQu0l1aeWv1r2pkYB4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=linux.beauty; spf=pass smtp.mailfrom=me@linux.beauty; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1657618275; s=zmail; d=linux.beauty; i=me@linux.beauty; h=Date:Date:From:From:To:To:Cc:Cc:Message-ID:In-Reply-To:References:Subject:Subject:MIME-Version:Content-Type:Content-Transfer-Encoding:Message-Id:Reply-To; bh=0D684KlQxe15o6oPTlLFmpWsKQgQVLQH0JtURWns8cw=; b=nYbhbFyMB24s2IBlrQPVHYwrZ0Qx9G5U6vygHoQ12UM8PR/GHKdFKyhPLy5IxZRu Lv/ipEBG63JcgQ4nBhmUF1XfXqu8jHsKWgaMUE5AFqXcjfZOVrM17A7Up2J9hMXOWnc 3ggyzk4gH9y4h1PMtH/FTkJIJvHwaEsYCPibLvgA= Received: from mail.zoho.com by mx.zohomail.com with SMTP id 1657618273698671.8295056333932; Tue, 12 Jul 2022 02:31:13 -0700 (PDT) Date: Tue, 12 Jul 2022 17:31:13 +0800 From: Li Chen To: "David Hildenbrand" Cc: "Catalin Marinas" , "Will Deacon" , "Rob Herring" , "Frank Rowand" , "Andrew Morton" , "Li Chen" , "linux-arm-kernel" , "linux-kernel" , "devicetree" , "linux-mm" Message-ID: <181f1bf9584.f463724e580236.5502316582440422915@linux.beauty> In-Reply-To: <4cf14bde-fb4c-99d9-58ce-a788a700d5f3@redhat.com> References: <20220711122459.13773-1-me@linux.beauty> <20220711122459.13773-3-me@linux.beauty> <181f0a5f2a5.cf94ce78513585.4158910057206462182@linux.beauty> <4cf14bde-fb4c-99d9-58ce-a788a700d5f3@redhat.com> Subject: Re: [PATCH 2/4] mm/sparse: skip no-map memblock check when fill_subsection_map MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit Importance: Medium User-Agent: Zoho Mail X-Mailer: Zoho Mail X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_RED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi David, ---- On Tue, 12 Jul 2022 15:31:08 +0800 David Hildenbrand wrote --- > On 12.07.22 06:23, Li Chen wrote: > > Hi David, > > ---- On Mon, 11 Jul 2022 22:53:36 +0800 David Hildenbrand wrote --- > > > On 11.07.22 14:24, Li Chen wrote: > > > > From: Li Chen > > > > > > > > When mhp use sparse_add_section, don't check no-map region, > > > > so that to allow no-map reserved memory to get struct page > > > > support. > > > > > > > > Signed-off-by: Li Chen > > > > Change-Id: I0d2673cec1b66adf695251037a00c240976b226f > > > > --- > > > > mm/sparse.c | 4 +++- > > > > 1 file changed, 3 insertions(+), 1 deletion(-) > > > > > > > > diff --git a/mm/sparse.c b/mm/sparse.c > > > > index 120bc8ea5293..a29cd1e7014f 100644 > > > > --- a/mm/sparse.c > > > > +++ b/mm/sparse.c > > > > @@ -690,7 +690,9 @@ static int fill_subsection_map(unsigned long pfn, unsigned long nr_pages) > > > > > > > > if (bitmap_empty(map, SUBSECTIONS_PER_SECTION)) > > > > rc = -EINVAL; > > > > - else if (bitmap_intersects(map, subsection_map, SUBSECTIONS_PER_SECTION)) > > > > + else if (memblock_is_map_memory(PFN_PHYS(pfn)) && > > > > + bitmap_intersects(map, subsection_map, > > > > + SUBSECTIONS_PER_SECTION)) > > > > rc = -EEXIST; > > > > else > > > > bitmap_or(subsection_map, map, subsection_map, > > > > > > I'm not sure I follow completely what you are trying to achieve. But if > > > you have to add memblock hacks into mm/sparse.c you're most probably > > > doing something wrong. > > > > > > Please explain why that change is necessary, and why it is safe. > > > > In the current sparse memory model, free_area_init will insert all memblock.memory into subsection_map and no-map rmem is also a > > memblock.memory. So, without this change, fill_subsection_map will return -EEXIST. > > > > I would say it's not a good idea to insert no-map memblock into subsection_map, and I have no idea why sparse do this. > > So, I simply skip no-map region here. > > The thing is: > > if the subsection map is set, then there already *is* a memmap and you > would simply be ignoring it (and overwriting a memmap in e.g., > ZONE_NORMAL to be in ZONE_DEVICE suddenly, which is wrong). > > > Reading memblock_mark_nomap(): > > "The memory regions marked with %MEMBLOCK_NOMAP will not be added to the > direct mapping of the physical memory. These regions will still be > covered by the memory map. The struct page representing NOMAP memory > frames in the memory map will be PageReserved()" > > > So having a memmap for these ranges is expected, and a direct map is not > desired. What you propose is a hack. You either have to reuse the > existing memmap (which is !ZONE_DEVICE -- not sure if that's a problem) > or we'd have to look into teaching init code to not allocate a memmap > for sub-sections that are fully nomap. > > But not sure who depends on the existing memmap for nomap memory. Points taken, thanks! I will try to dig into it. Regards, Li > > > > As for safety: > > 1. The caller of fill_subsection_map are mhp and *_memremap_pages functions, no-map regions are not related to them, so existing codes won't be broken. > > 2. This change doesn't change memblock and subsection_map. > > > > Sorry, but AFAIKT it's a hack and we need a clean way to deal with nomap > memory that already has a memmap instead. > > > -- > Thanks, > > David / dhildenb > >