Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp1092420imm; Tue, 15 May 2018 13:44:29 -0700 (PDT) X-Google-Smtp-Source: AB8JxZoi+N8uvm99jZ1KuKsXSqmT+wfc3xI0it8vbaCQ4nEkmDtcD3Vbq6U7CnRfSFwjnhBneRcP X-Received: by 2002:a65:6510:: with SMTP id x16-v6mr511381pgv.204.1526417069207; Tue, 15 May 2018 13:44:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526417069; cv=none; d=google.com; s=arc-20160816; b=i7did7XOldNuWFiSYN3IG8z870Mk4PuZlfaByFuLoY3rEq/ii02XqZCvkiCiWFPriJ ZCcke2jtfG6hynk6C9SqEekZ2dZjhTL573kwKXOZuZuWp0uaRuWk4arGp4IRexZunI0p tTt54wUn/ZhCTAvbo9h1SaiSyqudLfj4DHPoOSw9PCcxmXu5U6j2EJOzRrrV6f4U63aV bjKXuGXTxfT/RKXQjJNxBVnmpN7o5pAQbo8WHGHgn3nbLuEm84RDyhjdWUlT9Nsjo8NJ IFf0JRfnj8K4LmbXfDBTNAfwoJHtPkhzEd8cbVSFSQz/Sh3JXspE6r5Am5NTa5ZuQr+Y PUxw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:arc-authentication-results; bh=9Ot++F4mURXPmuNE2lldCtvnisSYzcnVUkbz6PB98IU=; b=rGs5q3taH0iiKvYkSbn2ilN7MdzvOJ4lm8h2Xn6NoMU44rV9HCpamYXh82xoJnfFIu tJvqIafOsyLNWq1rGWsTNgObzpf6+VGxRIVJKkMwQXKcgtnrRmg9sJFFWaahK3O//qK6 ENQvvlCTTbvajGJBZAiEB3uyxY5esLeZ0W/Mx51AE/nZOUSjp4ClPGgZ6VJOQ3XDvUe3 v0AIoV/jMYQTaIAWSQAT+qCQ5/aLXkvyRXSJ8DfPlgfoVNJ+kK27db20nVqEet/r/RQ/ c/4wIMuM7SsNdEq+dE3D16pZa+w4t5Hw4X7WVG6e1vEsCPxCTZFz+uLmOPhi8/ek6lK8 KeaA== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 3-v6si852739plp.515.2018.05.15.13.44.14; Tue, 15 May 2018 13:44:29 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752567AbeEOUnr (ORCPT + 99 others); Tue, 15 May 2018 16:43:47 -0400 Received: from mx2.suse.de ([195.135.220.15]:53093 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752179AbeEOUnq (ORCPT ); Tue, 15 May 2018 16:43:46 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 4A24CAD0E; Tue, 15 May 2018 20:43:45 +0000 (UTC) Date: Tue, 15 May 2018 22:43:40 +0200 From: Michal Hocko To: Pavel Tatashin Cc: steven.sistare@oracle.com, daniel.m.jordan@oracle.com, akpm@linux-foundation.org, linux-kernel@vger.kernel.org, tglx@linutronix.de, linux-mm@kvack.org, mgorman@techsingularity.net, mingo@kernel.org, peterz@infradead.org, rostedt@goodmis.org, fengguang.wu@intel.com, dennisszhou@gmail.com Subject: Re: [PATCH v5] mm: don't allow deferred pages with NEED_PER_CPU_KM Message-ID: <20180515204340.GL12670@dhcp22.suse.cz> References: <20180515175124.1770-1-pasha.tatashin@oracle.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180515175124.1770-1-pasha.tatashin@oracle.com> User-Agent: Mutt/1.9.5 (2018-04-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue 15-05-18 13:51:24, Pavel Tatashin wrote: > It is unsafe to do virtual to physical translations before mm_init() is > called if struct page is needed in order to determine the memory section > number (see SECTION_IN_PAGE_FLAGS). This is because only in mm_init() we > initialize struct pages for all the allocated memory when deferred struct > pages are used. > > My recent fix exposed this problem, because it greatly reduced number of > pages that are initialized before mm_init(), but the problem existed even > before my fix, as Fengguang Wu found. > > Below is a more detailed explanation of the problem. > > We initialize struct pages in four places: > > 1. Early in boot a small set of struct pages is initialized to fill > the first section, and lower zones. > 2. During mm_init() we initialize "struct pages" for all the memory > that is allocated, i.e reserved in memblock. > 3. Using on-demand logic when pages are allocated after mm_init call (when > memblock is finished) > 4. After smp_init() when the rest free deferred pages are initialized. > > The problem occurs if we try to do va to phys translation of a memory > between steps 1 and 2. Because we have not yet initialized struct pages for > all the reserved pages, it is inherently unsafe to do va to phys if the > translation itself requires access of "struct page" as in case of this > combination: CONFIG_SPARSE && !CONFIG_SPARSE_VMEMMAP > > The following path exposes the problem: > > start_kernel() > trap_init() > setup_cpu_entry_areas() > setup_cpu_entry_area(cpu) > get_cpu_gdt_paddr(cpu) > per_cpu_ptr_to_phys(addr) > pcpu_addr_to_page(addr) > virt_to_page(addr) > pfn_to_page(__pa(addr) >> PAGE_SHIFT) > > We disable this path by not allowing NEED_PER_CPU_KM with deferred struct > pages feature. > > The problems are discussed in these threads: > http://lkml.kernel.org/r/20180418135300.inazvpxjxowogyge@wfg-t540p.sh.intel.com > http://lkml.kernel.org/r/20180419013128.iurzouiqxvcnpbvz@wfg-t540p.sh.intel.com > http://lkml.kernel.org/r/20180426202619.2768-1-pasha.tatashin@oracle.com > > Fixes: 3a80a7fa7989 ("mm: meminit: initialise a subset of struct pages if CONFIG_DEFERRED_STRUCT_PAGE_INIT is set") > Signed-off-by: Pavel Tatashin Acked-by: Michal Hocko Thanks a lot! > --- > mm/Kconfig | 1 + > 1 file changed, 1 insertion(+) > > diff --git a/mm/Kconfig b/mm/Kconfig > index d5004d82a1d6..e14c01513bfd 100644 > --- a/mm/Kconfig > +++ b/mm/Kconfig > @@ -636,6 +636,7 @@ config DEFERRED_STRUCT_PAGE_INIT > default n > depends on NO_BOOTMEM > depends on !FLATMEM > + depends on !NEED_PER_CPU_KM > help > Ordinarily all struct pages are initialised during early boot in a > single thread. On very large machines this can take a considerable > -- > 2.17.0 -- Michal Hocko SUSE Labs