From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 61EC9C433EF for ; Tue, 12 Jul 2022 09:31:29 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DAAD594005B; Tue, 12 Jul 2022 05:31:28 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D59EA940033; Tue, 12 Jul 2022 05:31:28 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C20A094005B; Tue, 12 Jul 2022 05:31:28 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id AFE52940033 for ; Tue, 12 Jul 2022 05:31:28 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 818F6345CE for ; Tue, 12 Jul 2022 09:31:28 +0000 (UTC) X-FDA: 79677929856.07.E0F90B4 Received: from sender4-op-o14.zoho.com (sender4-op-o14.zoho.com [136.143.188.14]) by imf06.hostedemail.com (Postfix) with ESMTP id D76B618002D for ; Tue, 12 Jul 2022 09:31:26 +0000 (UTC) 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 ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1657618287; a=rsa-sha256; cv=pass; b=L2hdOV8lY29UK0A37+I2c/bIpkEaIa9MkLGjcKtHWUBLaVuy8eoaN38mM4/Z1z2Tu/ZbwK Oq9Pqf74vQw+JF3hfuJzv+ITjTxMTgaE94u1X9wyY3XFExuvrMadu3IpBj64TeNnUmtLKJ 112u4A6dBkO64buEnOM1XB9+4gS2FFY= ARC-Authentication-Results: i=2; imf06.hostedemail.com; dkim=pass header.d=linux.beauty header.s=zmail header.b=nYbhbFyM; spf=pass (imf06.hostedemail.com: domain of me@linux.beauty designates 136.143.188.14 as permitted sender) smtp.mailfrom=me@linux.beauty; arc=pass ("zohomail.com:s=zohoarc:i=1"); dmarc=none ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1657618287; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=0D684KlQxe15o6oPTlLFmpWsKQgQVLQH0JtURWns8cw=; b=iWFlVwZyAxcXBOI0SgI5w4uI+tI6mWL71+j2ltHjT2trV0lHv28P6o3QXGefQpRS/5RP71 wKr4hAQvM/xzjm2lhMgZduUb9VCC42kV5GvetU3U4DFp6Qxix+ehAnzzrjEP5LajFPMpSy uHKk6cQYBqW7JOfzrWmW58VJeUlpoKI= X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: D76B618002D X-Rspam-User: X-Stat-Signature: s4k4y5t9w3ijw4nr6kr48adhjxsa9fx9 Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=linux.beauty header.s=zmail header.b=nYbhbFyM; spf=pass (imf06.hostedemail.com: domain of me@linux.beauty designates 136.143.188.14 as permitted sender) smtp.mailfrom=me@linux.beauty; arc=pass ("zohomail.com:s=zohoarc:i=1"); dmarc=none X-HE-Tag: 1657618286-649644 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: 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 > >