Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp1910515imm; Thu, 24 May 2018 02:46:58 -0700 (PDT) X-Google-Smtp-Source: AB8JxZprb6ueQPdsK2Pj2+tGaCqWYbUjhqOs7GLFWzGpP+niZYklqDTMR9mGcoU+d/Nal2LBYHCQ X-Received: by 2002:a17:902:8685:: with SMTP id g5-v6mr6467320plo.302.1527155218009; Thu, 24 May 2018 02:46:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527155217; cv=none; d=google.com; s=arc-20160816; b=An+7CjU/C1gF/9ena/Q7N9O8FKXx0ELqIvBjroJfcHpl5vj8sOFm/C1L8tpUGnW1AU tNjr3hgeaqmHwY371qcEeQSQGklqiWU0jNkqSXtgDvQJaUrHzs6dlGuJRQZsRDgWOJdH lfJJXhx4pyLp955eNEQySQ4KOhPS7QcYD/DpEYmNX8kMeNYpaMQe9Xc1oeFoXT4wB3tc D01rZdyxtE91jGB4JMfGiDjkcMmXJ/L8orJmTC1/3n1OmsLO606Vgn56ywSRAykn9jSx WUOlbN0Q0Lg+y/6cTvl1QVkmLpwyGd5Bou7QUxb/MoVHdi8Qn9sFlpyQMgVxUB/vmZab fhuQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=3H+/DvZRpUKFx57SpA2yIsCriNdH8W5HtReENNvtb7Y=; b=WHzTE1RO7cN/yM5PmHG4zPI6JM/ZehA/OruMnJvLF6D0AkcfQ0V0FwYrazTqaIkap0 yRZjqg6cOInplm2jo83ZfEQ4EWz6kMACAsvz3rIw9OuBLMXofqahAIArkmJwT9H3u/KW WMVibv1M8Rwoj7ILYeCP0ES9fY89eoJubUuKOw1Qtdscp2fczjvgxKBJewchdwa3J3M+ mpKp5LSGa9Ni+k2w1DutJAqFvmXTUneIguqsh/XQ+ZhA63rS1rT2GXeDYefbMfYDdsW2 GBE+jcEYvQKRVICwMCRhntgsWTj2MyyItF6v1J79REXzt6ASBkf/vNh63Cxqz0APkLp8 04Ug== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=yh/G2J9D; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u74-v6si16008060pgc.186.2018.05.24.02.46.43; Thu, 24 May 2018 02:46:57 -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=@kernel.org header.s=default header.b=yh/G2J9D; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S966751AbeEXJpK (ORCPT + 99 others); Thu, 24 May 2018 05:45:10 -0400 Received: from mail.kernel.org ([198.145.29.99]:56266 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S966710AbeEXJpF (ORCPT ); Thu, 24 May 2018 05:45:05 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id D8236208D6; Thu, 24 May 2018 09:45:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1527155104; bh=+k4gw8ma9OyKizxERZB/NjEWtKL1RcZkx2enGGz+ILE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=yh/G2J9D0rFyY1U43TDqEwV3RhYVD6zglqHAYIB4TUDXcq61tmgpkNcfddNQEk542 HCbj3ODFxu8cUS5N8wdi5rhlYiCQVBVY1X0GZjIfHUMNusIZ5WMpr5VY2JyVFOjjrZ kWwLaiAdRGvFTKtkA95I/hJrlME+GSlE7wu+9cno= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Pavel Tatashin , Michal Hocko , Andrew Morton , Steven Sistare , Daniel Jordan , Mel Gorman , Fengguang Wu , Dennis Zhou , Linus Torvalds Subject: [PATCH 4.4 57/92] mm: dont allow deferred pages with NEED_PER_CPU_KM Date: Thu, 24 May 2018 11:38:34 +0200 Message-Id: <20180524093204.769111897@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180524093159.286472249@linuxfoundation.org> References: <20180524093159.286472249@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 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 4.4-stable review patch. If anyone has any objections, please let me know. ------------------ From: Pavel Tatashin commit ab1e8d8960b68f54af42b6484b5950bd13a4054b upstream. 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 in commit c9e97a1997 ("mm: initialize pages on demand during boot") 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 Link: http://lkml.kernel.org/r/20180515175124.1770-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 Reviewed-by: Andrew Morton Cc: Steven Sistare Cc: Daniel Jordan Cc: Mel Gorman Cc: Fengguang Wu Cc: Dennis Zhou Cc: Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Greg Kroah-Hartman --- mm/Kconfig | 1 + 1 file changed, 1 insertion(+) --- a/mm/Kconfig +++ b/mm/Kconfig @@ -628,6 +628,7 @@ config DEFERRED_STRUCT_PAGE_INIT default n depends on ARCH_SUPPORTS_DEFERRED_STRUCT_PAGE_INIT depends on MEMORY_HOTPLUG + 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