Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp804977imm; Mon, 21 May 2018 14:49:39 -0700 (PDT) X-Google-Smtp-Source: AB8JxZq6Nv70LzR1671UxXOo3a8+hSDnzpQept2z1Eq+Ex9Fk1bw+pu5sbTjfskLJSarVEluRQzn X-Received: by 2002:a17:902:1566:: with SMTP id b35-v6mr22201128plh.107.1526939379478; Mon, 21 May 2018 14:49:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526939379; cv=none; d=google.com; s=arc-20160816; b=bOt0T5GXxSksqS3AqWcVuDhE9ZoNn+PYDFkf/OI5I5Prl8aoFCLb060eIrX1qqcudt ENmwOSZFCSdHEFpg6LdHNtnWG8QPfHEQIx4uvTPOZ5yjtm7G1X/0p4Ita+cQNqNHo5dS +8hrgVElyFO8Afhivj01zZjl6uuBCEuEHNz5OdAMkhCMwMoXdjeOBhrPo3tvy4+be6X3 +h2kudxxfo127c9aONdsNyo5hc3vvlv0ffJxAk+wo7HIN/zcR6kKCulmXe7DXsTrQjnS L0kA6uU8BzhSxX3kmh0ju8wb8PMsLrFqNiKQjRw0NdWwZjayywG+CtsJnFz2GBCoAs2E xqVA== 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=n/FZbBKjge0osJuVpTmORqbreB1jIYklAniZg+cQnjo=; b=SXWz719Zg6DYI/NPpswMq5rtR9zHZUpx8DS8wJ3XG+bSg82zSWo44axDrcm8zK+fK4 ya5T8e2yRMGWC05nDDD8iXbEqR3dwdPQ6e0Q/mIT5W9JOkp5NazBywAEuWGZXLJL8xO3 APVOzCwZTKgaKfWg6Rq9NfW/Uayzs/DnIt2UZwWj9K1ez1gyH6CvM8++r9Z3l81jpzFU MQcoWRNOkuexTc7tyyYL++Hc70uoeGYEZG3svh+lr6IygasMblwDLh40IYjo/okKrgwi 3jzeqGWe6PrAUGYboIHUMitWB3bqE3RQOGo9zhFIQR/31H0iRZ87TlIXK/eiW3T2DK++ sOqQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=W0S9xrDF; 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 bj6-v6si14812360plb.405.2018.05.21.14.49.25; Mon, 21 May 2018 14:49:39 -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=W0S9xrDF; 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 S1754356AbeEUVXs (ORCPT + 99 others); Mon, 21 May 2018 17:23:48 -0400 Received: from mail.kernel.org ([198.145.29.99]:38532 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932170AbeEUVXl (ORCPT ); Mon, 21 May 2018 17:23:41 -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 D905120871; Mon, 21 May 2018 21:23:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1526937820; bh=paWzf3pYZ/I5pcZwlJYwTPjt7DgSQIzP0xb6s30yJWw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=W0S9xrDFBBx8zrx16cEKb2AeGADcv+uHLlGCWl3vUtNyRIgv5vdLxg0BKSWOz7INF FuoiaWVeN/WUybnvyc3T+K48jrPkfWhwss3XLogRFzClZeBzfC+gl6kUuAe8+2hNIu L6qshpdQomY3WkGng0HGDfeq+Yhgszd3fcPvgMVU= 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.16 038/110] mm: dont allow deferred pages with NEED_PER_CPU_KM Date: Mon, 21 May 2018 23:11:35 +0200 Message-Id: <20180521210507.196316358@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180521210503.823249477@linuxfoundation.org> References: <20180521210503.823249477@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.16-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 @@ -644,6 +644,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