Received: by 10.213.65.68 with SMTP id h4csp2107284imn; Mon, 2 Apr 2018 00:55:02 -0700 (PDT) X-Google-Smtp-Source: AIpwx49q1i0g6vdK0cD8oekCyYmh1NRoMCrED1G6GQPH5umnC9IIVvk83eyJrcAC2BSAgcna1Jv5 X-Received: by 10.99.124.2 with SMTP id x2mr5721639pgc.262.1522655702152; Mon, 02 Apr 2018 00:55:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522655702; cv=none; d=google.com; s=arc-20160816; b=IGG6MLp4bL+/wihxfOuq0Cyi47YeWywVRFP6yxwHxeYRjtifRb7Q+rKKejzdOs8jq6 k1JRaPC+ZUc9bpakNPjRMPCt53a5LPSIh7uXTuyKWgiVWSzuuLvgcaxgkucTmJHlSMw4 uc9nVxEhZ44dMWeaZ+jx49O+w6DpBs1jNacRipoCZ/h6a2KmjT+8hTzAsBa+EOw8dpVD 7fmmdwcfeCkTA3ca2SuTzIyz0VmwhJL0zCwwsFhyMe0n2jMAVVoEKDUIHLeyIyTQu1zJ xHF/K9rIe0tBR/7bMEZ66F/PAcLGDcfKaFy7QrBcV288G/eqXgvGpvNitPUN1ehUZ64L EvrA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature :arc-authentication-results; bh=L8wq1PsdSiTYOdG+Kp7k9cvgBgHVMIBiqPHHUDJSflE=; b=hBhLsBLVfYA7EAmI0SLovhRx7CFtLZd6SEQd/3z/YGq60lftXcMM5VVS8Y022umpO1 1Qkyq+KoH97uEaaNeFVonT6LpgYWrx1T/0E5J23BBI8NCt2yTLwfNl8QMjlw0oAjiEuW mUXEWW5J5Nvs4SdLiJl3UgqYVFsNsQfjUhmdj1vcqPMPieXBoI9yM6AAiwuCH23iuudA OHMhlDJ3k51IaLuJZaLzs23jaTwGSAK+VxdM3Y/Lbpt6SgkGEa9cF5xdK4C81uae+AUe T3cTQSUiAbE6oqNm2+1IBAMOigwFhCPAfLEstCq+RHIWQxyUlTz14qty8KdQkdlMANsL Dtdw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=VkQlz6pG; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 9-v6si14019315plb.140.2018.04.02.00.54.48; Mon, 02 Apr 2018 00:55:02 -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; dkim=pass header.i=@linaro.org header.s=google header.b=VkQlz6pG; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754298AbeDBHxf (ORCPT + 99 others); Mon, 2 Apr 2018 03:53:35 -0400 Received: from mail-io0-f194.google.com ([209.85.223.194]:45188 "EHLO mail-io0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752775AbeDBHxe (ORCPT ); Mon, 2 Apr 2018 03:53:34 -0400 Received: by mail-io0-f194.google.com with SMTP id 141so17046803iou.12 for ; Mon, 02 Apr 2018 00:53:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=L8wq1PsdSiTYOdG+Kp7k9cvgBgHVMIBiqPHHUDJSflE=; b=VkQlz6pG62vwZvbDA6lZQdfJAhFKCTYCXhosbtB1KH/bCf0dM/cU5/rzEkwanH5Tpt XSRWGL4jRwmSUH6XAJ5u22KUm7Yu50rENMbnMu0desYmbhP7zxfU+YqnIvOWACkL4cJm 9w4rNhAoxkUyzvw6sRd4YjWM4CIVWDh/S+EZ0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=L8wq1PsdSiTYOdG+Kp7k9cvgBgHVMIBiqPHHUDJSflE=; b=d7kMvleLjHbJax80jDQzrcby7Hr+KseSwGMKcdqnEsRBAR/CdB+uzor7H74IlaZR3j Yz1m752le+EWbQDQfcPmgvO3EWQ3VpALZUCycUv2FjddK96R5PUN2r+yGVjeWqLNHLFL IIAH+ObUGUo6g7sp9knDcvz6KR3BjOYBH/zNcDaa/wOMIhlHWrTDVoBAkoi9Pti62dlc qyv6AGDgascPgYTBsTimi1E6PnqnYmtURLP7dCi6Z2yaIWEtNrbNXitMOYeqikCJJXQA 10yvJ5fpP0IpuNHDpsbNzFr+gjC3omHXKTebLglwI3GjZwnXt8CWrItgEI6uD70HC53V Miew== X-Gm-Message-State: ALQs6tBq+0wU7oRhzJFv8ZKZh8S8canMn3H284zglj/loAagy1J7OMdG oEaglVlIOieaOfCvIUxkJO05gCdMmeTbTu81XcBWfw== X-Received: by 10.107.139.212 with SMTP id n203mr7851573iod.107.1522655613787; Mon, 02 Apr 2018 00:53:33 -0700 (PDT) MIME-Version: 1.0 Received: by 10.107.187.67 with HTTP; Mon, 2 Apr 2018 00:53:33 -0700 (PDT) In-Reply-To: <41445229-043c-976f-3961-13770163444f@gmail.com> References: <1522636236-12625-1-git-send-email-hejianet@gmail.com> <1522636236-12625-2-git-send-email-hejianet@gmail.com> <41445229-043c-976f-3961-13770163444f@gmail.com> From: Ard Biesheuvel Date: Mon, 2 Apr 2018 09:53:33 +0200 Message-ID: Subject: Re: [PATCH v5 1/5] mm: page_alloc: remain memblock_next_valid_pfn() on arm and arm64 To: Jia He Cc: Russell King , Catalin Marinas , Will Deacon , Mark Rutland , Andrew Morton , Michal Hocko , Wei Yang , Kees Cook , Laura Abbott , Vladimir Murzin , Philip Derrin , AKASHI Takahiro , James Morse , Steve Capper , Pavel Tatashin , Gioh Kim , Vlastimil Babka , Mel Gorman , Johannes Weiner , Kemi Wang , Petr Tesarik , YASUAKI ISHIMATSU , Andrey Ryabinin , Nikolay Borisov , Daniel Jordan , Daniel Vacek , Eugeniu Rosca , linux-arm-kernel , Linux Kernel Mailing List , Linux-MM , Jia He Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2 April 2018 at 09:49, Jia He wrote: > > > On 4/2/2018 2:55 PM, Ard Biesheuvel Wrote: >> >> On 2 April 2018 at 04:30, Jia He wrote: >>> >>> Commit b92df1de5d28 ("mm: page_alloc: skip over regions of invalid pfns >>> where possible") optimized the loop in memmap_init_zone(). But it causes >>> possible panic bug. So Daniel Vacek reverted it later. >>> >>> But as suggested by Daniel Vacek, it is fine to using memblock to skip >>> gaps and finding next valid frame with CONFIG_HAVE_ARCH_PFN_VALID. >>> >>> On arm and arm64, memblock is used by default. But generic version of >>> pfn_valid() is based on mem sections and memblock_next_valid_pfn() does >>> not always return the next valid one but skips more resulting in some >>> valid frames to be skipped (as if they were invalid). And that's why >>> kernel was eventually crashing on some !arm machines. >>> >>> And as verified by Eugeniu Rosca, arm can benifit from commit >>> b92df1de5d28. So remain the memblock_next_valid_pfn on arm{,64} and move >>> the related codes to arm64 arch directory. >>> >>> Suggested-by: Daniel Vacek >>> Signed-off-by: Jia He >> >> Hello Jia, >> >> Apologies for chiming in late. > > no problem, thanks for your comments ;-) >> >> >> If we are going to rearchitect this, I'd rather we change the loop in >> memmap_init_zone() so that we skip to the next valid PFN directly >> rather than skipping to the last invalid PFN so that the pfn++ in the > > hmm... Maybe this macro name makes you confused > > pfn = skip_to_last_invalid_pfn(pfn); > > how about skip_to_next_valid_pfn? > >> for () results in the next value. Can we replace the pfn++ there with >> a function calls that defaults to 'return pfn + 1', but does the skip >> for architectures that implement it? > > I am not sure I understand your question here. > With this patch, on !arm arches, skip_to_last_invalid_pfn is equal to (pfn), > and will be increased > when for{} loop continue. We only *skip* to the start pfn of next valid > region when > CONFIG_HAVE_MEMBLOCK and CONFIG_HAVE_ARCH_PFN_VALID(arm/arm64 supports > both). > What I am saying is that the loop in memmap_init_zone for (pfn = start_pfn; pfn < end_pfn; pfn++) { ... } should be replaced by something like for (pfn = start_pfn; pfn < end_pfn; pfn = next_valid_pfn(pfn)) where next_valid_pfn() is simply defined as static ulong next_valid_pfn(ulong pfn) { return pfn + 1; } by default, unless we do something special like you are proposing for ARM and arm64, in which case you provide a different implementation. That way, we no longer have to reason around the pfn++, and return an invalid pfn so that the ++ will produce a valid pfn