Received: by 2002:a25:824b:0:0:0:0:0 with SMTP id d11csp1300654ybn; Wed, 25 Sep 2019 15:58:07 -0700 (PDT) X-Google-Smtp-Source: APXvYqxImnG4sHFm58UEiIgXA57HtzmAWTaMaqAX4welp6TDps2/8kHTHuzjhT53XNvrxA/zTtet X-Received: by 2002:a17:906:1c05:: with SMTP id k5mr523753ejg.286.1569452287107; Wed, 25 Sep 2019 15:58:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1569452287; cv=none; d=google.com; s=arc-20160816; b=SiOlTtgUMS4tdi0iA22n/CTv89BeKS3sMjE1BgANx2wrIfa4/WaLPHTDmmsJMlAlGD YopLjO0JU2ofEYOZ7LhzGOj/lDNmyHiWk0+v3Z5/GC2+lV5J98gtHis/r+FqZygEaTJI QBbQh5OxOZbqd98VgIweFetYrXqNmZiHNW9RWnptp7+opDL+0NDpkwlHZGJxQFkRwrKu ldjhD2HnbaGxI5j3byAXe3lHsaTLAj28SGDMRGpP6dZbCjOnMJ6cHRyc1XBa4j+cQHP/ rN89OE7VlhafQBFEct6DJrNyx/65qJosrveCVCN6tlgSXfwokvdMlL2tM3KTEwtzQmj0 e6pA== 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; bh=Z2UVTGDGdmBepvX5D9PV0KSCbkz3s4ls6FmPZJUOX8M=; b=gz1Ee4gwTnsG/DjYLqfNB8DkgqtA1N7q7s48VF2dVdYYfE4bXnwx5geyyl9WLq1H5B Yulzj7yNW0zto6/8uaB7sxis5dZlbKcV/hOu82reA4TDitqA7Kn9ZgMB8V9YhsBQW5eB 3aRAJUp49LQa//q39wvXBWRuHXKWCGcOA9Ti20XH4ZSINqjuSCsHDGy9SfA6UNO/bUNr XsXBy8r0OGleKviQyCKlKGuw6ktA7U+xotLFRjAyltLQFwnkpCEx7gqi+uIRRLNK3YOV ILRqAKR3HJ8HUnrr+RGYOQ3GLOi4tjNS6kWvHCSj7kLf5IjxnZkhUkQ0eKDc8v0Zk2Gs Ph8A== 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=hpe.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e23si123662ejt.379.2019.09.25.15.57.41; Wed, 25 Sep 2019 15:58:07 -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=hpe.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2438327AbfIWSPl (ORCPT + 99 others); Mon, 23 Sep 2019 14:15:41 -0400 Received: from mx0a-002e3701.pphosted.com ([148.163.147.86]:23926 "EHLO mx0a-002e3701.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2394280AbfIWSPk (ORCPT ); Mon, 23 Sep 2019 14:15:40 -0400 Received: from pps.filterd (m0148663.ppops.net [127.0.0.1]) by mx0a-002e3701.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id x8NI1klJ006535; Mon, 23 Sep 2019 18:15:22 GMT Received: from g4t3425.houston.hpe.com (g4t3425.houston.hpe.com [15.241.140.78]) by mx0a-002e3701.pphosted.com with ESMTP id 2v72ny8fux-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 23 Sep 2019 18:15:22 +0000 Received: from g9t2301.houston.hpecorp.net (g9t2301.houston.hpecorp.net [16.220.97.129]) by g4t3425.houston.hpe.com (Postfix) with ESMTP id 322709A; Mon, 23 Sep 2019 18:15:21 +0000 (UTC) Received: from swahl-linux (swahl-linux.americas.hpqcorp.net [10.33.153.21]) by g9t2301.houston.hpecorp.net (Postfix) with ESMTP id 67BEF4E; Mon, 23 Sep 2019 18:15:20 +0000 (UTC) Date: Mon, 23 Sep 2019 13:15:20 -0500 From: Steve Wahl To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H. Peter Anvin" , x86@kernel.org, Juergen Gross , "Kirill A. Shutemov" , Brijesh Singh , Steve Wahl , Jordan Borgner , Feng Tang , linux-kernel@vger.kernel.org, Chao Fan , Zhenzhong Duan Cc: Baoquan He , russ.anderson@hpe.com, dimitri.sivanich@hpe.com, mike.travis@hpe.com Subject: [PATCH v2 1/2] x86/boot/64: Make level2_kernel_pgt pages invalid outside kernel area. Message-ID: <51b87d62e0cade3c46a69706b9be249190abc7bd.1569004923.git.steve.wahl@hpe.com> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.12.1 (2019-06-15) X-HPE-SCL: -1 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.95,1.0.8 definitions=2019-09-23_05:2019-09-23,2019-09-23 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 lowpriorityscore=0 clxscore=1015 impostorscore=0 suspectscore=0 phishscore=0 bulkscore=0 adultscore=0 mlxlogscore=999 malwarescore=0 spamscore=0 priorityscore=1501 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-1908290000 definitions=main-1909230158 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Our hardware (UV aka Superdome Flex) has address ranges marked reserved by the BIOS. Access to these ranges is caught as an error, causing the BIOS to halt the system. Initial page tables mapped a large range of physical addresses that were not checked against the list of BIOS reserved addresses, and sometimes included reserved addresses in part of the mapped range. Including the reserved range in the map allowed processor speculative accesses to the reserved range, triggering a BIOS halt. Used early in booting, the page table level2_kernel_pgt addresses 1 GiB divided into 2 MiB pages, and it was set up to linearly map a full 1 GiB of physical addresses that included the physical address range of the kernel image, as chosen by KASLR. But this also included a large range of unused addresses on either side of the kernel image. And unlike the kernel image's physical address range, this extra mapped space was not checked against the BIOS tables of usable RAM addresses. So there were times when the addresses chosen by KASLR would result in processor accessible mappings of BIOS reserved physical addresses. The kernel code did not directly access any of this extra mapped space, but having it mapped allowed the processor to issue speculative accesses into reserved memory, causing system halts. This was encountered somewhat rarely on a normal system boot, and much more often when starting the crash kernel if "crashkernel=512M,high" was specified on the command line (this heavily restricts the physical address of the crash kernel, in our case usually within 1 GiB of reserved space). The solution is to invalidate the pages of this table outside the kernel image's space before the page table is activated. This patch has been validated to fix this problem on our hardware. Signed-off-by: Steve Wahl Cc: stable@vger.kernel.org --- Changes since v1: * Added comment. * Reworked changelog text. arch/x86/kernel/head64.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/arch/x86/kernel/head64.c b/arch/x86/kernel/head64.c index 29ffa495bd1c..ee9d0e3e0c46 100644 --- a/arch/x86/kernel/head64.c +++ b/arch/x86/kernel/head64.c @@ -222,13 +222,27 @@ unsigned long __head __startup_64(unsigned long physaddr, * we might write invalid pmds, when the kernel is relocated * cleanup_highmap() fixes this up along with the mappings * beyond _end. + * + * Only the region occupied by the kernel image has so far + * been checked against the table of usable memory regions + * provided by the firmware, so invalidate pages outside that + * region. A page table entry that maps to a reserved area of + * memory would allow processor speculation into that area, + * and on some hardware (particularly the UV platform) even + * speculative access to some reserved areas is caught as an + * error, causing the BIOS to halt the system. */ pmd = fixup_pointer(level2_kernel_pgt, physaddr); - for (i = 0; i < PTRS_PER_PMD; i++) { + for (i = 0; i < pmd_index((unsigned long)_text); i++) + pmd[i] &= ~_PAGE_PRESENT; + + for (; i <= pmd_index((unsigned long)_end); i++) if (pmd[i] & _PAGE_PRESENT) pmd[i] += load_delta; - } + + for (; i < PTRS_PER_PMD; i++) + pmd[i] &= ~_PAGE_PRESENT; /* * Fixup phys_base - remove the memory encryption mask to obtain -- 2.21.0 -- Steve Wahl, Hewlett Packard Enterprise