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 X-Spam-Level: X-Spam-Status: No, score=-8.1 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 70A46C33CB1 for ; Tue, 14 Jan 2020 10:41:19 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 29C8A24672 for ; Tue, 14 Jan 2020 10:41:19 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=shutemov-name.20150623.gappssmtp.com header.i=@shutemov-name.20150623.gappssmtp.com header.b="D8dS1CwR" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 29C8A24672 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=shutemov.name Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 9FEE88E0005; Tue, 14 Jan 2020 05:41:18 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 9AFCA8E0003; Tue, 14 Jan 2020 05:41:18 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 89DD48E0005; Tue, 14 Jan 2020 05:41:18 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0120.hostedemail.com [216.40.44.120]) by kanga.kvack.org (Postfix) with ESMTP id 761C28E0003 for ; Tue, 14 Jan 2020 05:41:18 -0500 (EST) Received: from smtpin06.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with SMTP id 38D2B180AD804 for ; Tue, 14 Jan 2020 10:41:18 +0000 (UTC) X-FDA: 76375897836.06.veil89_457bad420ff4f X-HE-Tag: veil89_457bad420ff4f X-Filterd-Recvd-Size: 7578 Received: from mail-lj1-f193.google.com (mail-lj1-f193.google.com [209.85.208.193]) by imf31.hostedemail.com (Postfix) with ESMTP for ; Tue, 14 Jan 2020 10:41:17 +0000 (UTC) Received: by mail-lj1-f193.google.com with SMTP id m26so13701289ljc.13 for ; Tue, 14 Jan 2020 02:41:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=shutemov-name.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to :user-agent; bh=ciknfppj1LCOHQAPNZhrYGHRrM+p8c24oaVfpOlu9CU=; b=D8dS1CwRdv4R6AuTAzh6R3DnDJF22Y3FxbdHfLb2409DLsWz8gAfHlk428NSgrdgLO NjdxkwAKeY5Kur60odrJ+vowBJOF690oPx3CzOV13Zs42tu00UlKvGCJCf2bomxCsyLG AUibM1WEOWuvhj7akWItw2LSu31aihjZxdMs5UTLicQc1SiFHWAoOpdgVK0sBFHOPkQC 9fdeHzmoVx2GUbE1NaI3qT8Z8EYUek5pEvW9cajGNwkU3X6SLvP/g2FWhbaRBsaazU0L fbSjgeECYGGRB01cbRFxqBuAai8OuSSU/9eRsTYVvsx1cHkrVVynNu6JekAACW6aZaE9 qRcA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to:user-agent; bh=ciknfppj1LCOHQAPNZhrYGHRrM+p8c24oaVfpOlu9CU=; b=Htm/0GREEi2KXKLMQMcmPnuvPU7e7Bw/r/15brySzJhvMoBrUObqanWb/KIa8sC6N3 BCifYHkQ0tkp8X6U0FY6CWSuihzmELx6gCMu2e8W3qG7L37AuvrGCKXKV+MxMjK+Rizb qkdw9a8T95o+xzGy9jlnBtebXSfEJXoYTPr137Q5fj/FJbe1zEZ/oiCOqOVHlKF9uPmc OHUFds3ouIybNfOsbTm2LFaexj+9LhIFc39GSSFX2JhvbyRFfTdfzPbeQRhbm9rIVxTj UAN0fMAdI6Z9d3nn0WTcTmVzEX9VmOcAFaMUFqfJVm9sAVWUHI+BZcP27DcealcxrTrA 63vQ== X-Gm-Message-State: APjAAAW41tZgWkRtnwAjJt1gLGHmDUeHvvdyaXrjgf4nB981GupJYXwr hkPRV6c5onZ5GdxiMlDoUgE16w== X-Google-Smtp-Source: APXvYqxWzh95I3QAQNvY5+6K/3YoTBogFK1CQsi8v8vBUONaYxTq4v11GUzTxzshYKjUICr3d5c7og== X-Received: by 2002:a2e:8188:: with SMTP id e8mr12524747ljg.57.1578998475904; Tue, 14 Jan 2020 02:41:15 -0800 (PST) Received: from box.localdomain ([86.57.175.117]) by smtp.gmail.com with ESMTPSA id r21sm7346380ljn.64.2020.01.14.02.41.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Jan 2020 02:41:15 -0800 (PST) Received: by box.localdomain (Postfix, from userid 1000) id 496BF100823; Tue, 14 Jan 2020 13:41:19 +0300 (+03) Date: Tue, 14 Jan 2020 13:41:19 +0300 From: "Kirill A. Shutemov" To: David Hildenbrand Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, Andrew Morton , Michal Hocko , Oscar Salvador Subject: Re: [PATCH v1 2/2] mm: factor out next_present_section_nr() Message-ID: <20200114104119.pybggnb4b2mq45wr@box> References: <0B77E39C-BD38-4A61-AB28-3578B519952F@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: User-Agent: NeoMutt/20180716 Content-Transfer-Encoding: quoted-printable 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: On Tue, Jan 14, 2020 at 12:02:00AM +0100, David Hildenbrand wrote: >=20 >=20 > > Am 13.01.2020 um 23:57 schrieb David Hildenbrand : > >=20 > > =EF=BB=BF > >=20 > >>> Am 13.01.2020 um 23:41 schrieb Kirill A. Shutemov : > >>>=20 > >>> =EF=BB=BFOn Mon, Jan 13, 2020 at 03:40:35PM +0100, David Hildenbran= d wrote: > >>> Let's move it to the header and use the shorter variant from > >>> mm/page_alloc.c (the original one will also check > >>> "__highest_present_section_nr + 1", which is not necessary). While = at it, > >>> make the section_nr in next_pfn() const. > >>>=20 > >>> In next_pfn(), we now return section_nr_to_pfn(-1) instead of -1 on= ce > >>> we exceed __highest_present_section_nr, which doesn't make a differ= ence in > >>> the caller as it is big enough (>=3D all sane end_pfn). > >>>=20 > >>> Cc: Andrew Morton > >>> Cc: Michal Hocko > >>> Cc: Oscar Salvador > >>> Cc: Kirill A. Shutemov > >>> Signed-off-by: David Hildenbrand > >>> --- > >>> include/linux/mmzone.h | 10 ++++++++++ > >>> mm/page_alloc.c | 11 ++--------- > >>> mm/sparse.c | 10 ---------- > >>> 3 files changed, 12 insertions(+), 19 deletions(-) > >>>=20 > >>> diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h > >>> index c2bc309d1634..462f6873905a 100644 > >>> --- a/include/linux/mmzone.h > >>> +++ b/include/linux/mmzone.h > >>> @@ -1379,6 +1379,16 @@ static inline int pfn_present(unsigned long = pfn) > >>> return present_section(__nr_to_section(pfn_to_section_nr(pfn))); > >>> } > >>>=20 > >>> +static inline unsigned long next_present_section_nr(unsigned long = section_nr) > >>> +{ > >>> + while (++section_nr <=3D __highest_present_section_nr) { > >>> + if (present_section_nr(section_nr)) > >>> + return section_nr; > >>> + } > >>> + > >>> + return -1; > >>> +} > >>> + > >>> /* > >>> * These are _only_ used during initialisation, therefore they > >>> * can use __initdata ... They could have names to indicate > >>> diff --git a/mm/page_alloc.c b/mm/page_alloc.c > >>> index a92791512077..26e8044e9848 100644 > >>> --- a/mm/page_alloc.c > >>> +++ b/mm/page_alloc.c > >>> @@ -5852,18 +5852,11 @@ overlap_memmap_init(unsigned long zone, uns= igned long *pfn) > >>> /* Skip PFNs that belong to non-present sections */ > >>> static inline __meminit unsigned long next_pfn(unsigned long pfn) > >>> { > >>> - unsigned long section_nr; > >>> + const unsigned long section_nr =3D pfn_to_section_nr(++pfn); > >>>=20 > >>> - section_nr =3D pfn_to_section_nr(++pfn); > >>> if (present_section_nr(section_nr)) > >>> return pfn; > >>> - > >>> - while (++section_nr <=3D __highest_present_section_nr) { > >>> - if (present_section_nr(section_nr)) > >>> - return section_nr_to_pfn(section_nr); > >>> - } > >>> - > >>> - return -1; > >>> + return section_nr_to_pfn(next_present_section_nr(section_nr)); > >>=20 > >> This changes behaviour in the corner case: if next_present_section_n= r() > >> returns -1, we call section_nr_to_pfn() for it. It's unlikely would = give > >> any valid pfn, but I can't say for sure for all archs. I guess the w= orst > >> case scenrio would be endless loop over the same secitons/pfns. > >>=20 > >> Have you considered the case? > >=20 > > Yes, see the patch description. We return -1 << PFN_SECTION_SHIFT, so= a number close to the end of the address space (0xfff...000). (Will doub= le check tomorrow if any 32bit arch could be problematic here) >=20 > ... but thinking again, 0xfff... is certainly an invalid PFN, so this s= hould work just fine. >=20 > (biggest possible pfn is -1 >> PFN_SHIFT) >=20 > But it=E2=80=98s late in Germany, will double check tomorrow :) If the end_pfn happens the be more than -1UL << PFN_SECTION_SHIFT we are screwed: the pfn is invalid, next_present_section_nr() returns -1, the next iterartion is on the same pfn and we have endless loop. The question is whether we can prove end_pfn is always less than -1UL << PFN_SECTION_SHIFT in any configuration of any arch. It is not obvious for me. --=20 Kirill A. Shutemov