Received: by 10.192.165.148 with SMTP id m20csp1047119imm; Thu, 10 May 2018 04:56:23 -0700 (PDT) X-Google-Smtp-Source: AB8JxZo4+BTra9e15PJVQjF5ZPaQyu2A5+X73F8llPKudma/DNCpaW7XO2IpskrLG+eSUnRxy2ia X-Received: by 2002:a63:7253:: with SMTP id c19-v6mr905293pgn.425.1525953383205; Thu, 10 May 2018 04:56:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525953383; cv=none; d=google.com; s=arc-20160816; b=vNYUWCU+ZbykdzzLPkDdtPTHPScidqkKe2/SNFoxE9dL810TpHQNoGeVy5HjQijMBZ ynlJno77v84RqePJ32dZtn+zCh8m30eisFj8/viAH+UfwLb94DfBTQvzLlj53OJyRmIn 8ZwvXzD/D7eGFJCAxxxdKQ7vJqSFE28aO+Hqa7zS/+R8NGgjy0azCx9SN8dbSXhQNQII yQ0LLo7qAl37Q7x3oDe+wEZuozXz4GyCH8skMfkN48fbOHsCnP3dZlrfMOR6ifEkWelV kGgv92YK19SjqEjjVFeBJE5HyPJz+eldQIPzqkN+9v3X56yDJIDTBdIp38VKy1Pj/4G8 rlCg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:to:from :dkim-signature:arc-authentication-results; bh=XQ49fCTdiCkgoN+/TQ5KoKSYgvRuCJlF12nj8e7fGzs=; b=PV5Itzu00uG1SV53bwpdO5G1U2/+LC/mVu29A5ea8J4JotrOUOfZI9R3VvrV1O5K6/ Ucn0hGxhxCiGfGQZ4JxW3WShoXWl+4jDS1ytMiiIYNkNiKQFycLGsofxcY5GdKSBa7f0 KWmbGyPRqpkFNruKynwkiV0EHDyfbo7UogR/X3wxSuAK7Coiw/hCphGn4QPWGAZGv17S QniG8BnmDVgvN3SmBC0kdxpCJtRI5xa/NFN5ZTYnDggIL0lQ4XKlYivs2MvR3ciHI1HL r9IliGbNgTf5chyLe67bnPXWpAZaQGV0jszlL+Jxpaj8quIPeXMPnVxi+iHz0qzzmbOj s0/g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2017-10-26 header.b=bu1b50xq; 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=oracle.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g92-v6si604232plg.256.2018.05.10.04.56.08; Thu, 10 May 2018 04:56:23 -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=@oracle.com header.s=corp-2017-10-26 header.b=bu1b50xq; 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=oracle.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757184AbeEJLyt (ORCPT + 99 others); Thu, 10 May 2018 07:54:49 -0400 Received: from userp2120.oracle.com ([156.151.31.85]:47048 "EHLO userp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756998AbeEJLys (ORCPT ); Thu, 10 May 2018 07:54:48 -0400 Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.22/8.16.0.22) with SMTP id w4ABpTns136544; Thu, 10 May 2018 11:54:07 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : subject : date : message-id; s=corp-2017-10-26; bh=XQ49fCTdiCkgoN+/TQ5KoKSYgvRuCJlF12nj8e7fGzs=; b=bu1b50xqRviKEQYvDQzG4SvKAoGdjf8JmjXKckyLXnLzzAn/c77NRVvWIOZZ6qSTk5xA 5ApnLjeUnuQmntODbhzG4vuIH7pDb1LOWR/D86fVtA/cEEqGKPS3e1uYRorqQBqwcATO fDFv65o2jUKYdOq3h6VdaHSLS7QlTIZfDX+vzn6wEA7gZaKiPcLohBITq9JtXfaJzoM7 f+BPBBdGHYosWZ7nKAE3ZUe9UUPnLhhY+U0+KVGoageKZQfqBP+WsNBg+ZoN771naHuj iNbt8vEREjEFPugGR3qwNy1E3ms5BETeSqQttvID2OsJ2TpEi4fwOTIUzn6yRmbt6/4T Dw== Received: from aserv0022.oracle.com (aserv0022.oracle.com [141.146.126.234]) by userp2120.oracle.com with ESMTP id 2hv6kp380v-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 10 May 2018 11:54:06 +0000 Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by aserv0022.oracle.com (8.14.4/8.14.4) with ESMTP id w4ABs5i0014284 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 10 May 2018 11:54:05 GMT Received: from abhmp0006.oracle.com (abhmp0006.oracle.com [141.146.116.12]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id w4ABs3rA020620; Thu, 10 May 2018 11:54:03 GMT Received: from localhost.localdomain (/73.69.118.222) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 10 May 2018 04:54:03 -0700 From: Pavel Tatashin To: steven.sistare@oracle.com, daniel.m.jordan@oracle.com, akpm@linux-foundation.org, linux-kernel@vger.kernel.org, tglx@linutronix.de, mhocko@suse.com, linux-mm@kvack.org, mgorman@techsingularity.net, mingo@kernel.org, peterz@infradead.org, rostedt@goodmis.org, fengguang.wu@intel.com, dennisszhou@gmail.com Subject: [PATCH v2] mm: allow deferred page init for vmemmap only Date: Thu, 10 May 2018 07:53:56 -0400 Message-Id: <20180510115356.31164-1-pasha.tatashin@oracle.com> X-Mailer: git-send-email 2.17.0 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=8888 signatures=668698 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=2 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1711220000 definitions=main-1805100117 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 Here is a sample path, where translation is required, that occurs before mm_init(): 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) 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 --- mm/Kconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/Kconfig b/mm/Kconfig index d5004d82a1d6..1cd32d67ca30 100644 --- a/mm/Kconfig +++ b/mm/Kconfig @@ -635,7 +635,7 @@ config DEFERRED_STRUCT_PAGE_INIT bool "Defer initialisation of struct pages to kthreads" default n depends on NO_BOOTMEM - depends on !FLATMEM + depends on SPARSEMEM_VMEMMAP 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