Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp1680520pxj; Fri, 18 Jun 2021 12:29:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxVa6XLDSCepjKUzuNvRPwTyGphk0yfIS7ahn+X/2uVHuj3R3NeBF6zA5mG/nlEkraDVZ+i X-Received: by 2002:a05:6402:b75:: with SMTP id cb21mr7096151edb.255.1624044587022; Fri, 18 Jun 2021 12:29:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624044587; cv=none; d=google.com; s=arc-20160816; b=r0wagR4eYdIBQd60NaeFNYRXG+3ICGdUkXITziPE50tvP+VqVNbxH5XbGU7iOCnUpF F44CtMDHOEVG4+ksMEy8Lzl9Do9DAJBhsqMZyGoj3iSQm57rWJ3FLwxp4KUOmC7UQJfB mhBVuFTG9kAoashIKjl3g3jjFC6ju7EkwMlgql4xKNWxxunIkHYio7yz6KhwdSjM2LEC GDUsOHnNkcbHSbiR4cK8QaJg5oLTeqas/va5v0bjBVK5oflrtL3hjhyptBE5qrTs82nS Uj5RcjYwz4iLmrRs1tSrLFqnA7ybxg352KKlm6ayo0febQA95BColeB6zVhDiclDMuVa dXRA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:robot-unsubscribe :robot-id:message-id:mime-version:references:in-reply-to:cc:subject :to:reply-to:sender:from:dkim-signature:dkim-signature:date; bh=m4T6r4OFbKcFYZScWGv36zptdxpcLrCD12HgvKArkW0=; b=pNQthe2iGVImlLIHgSJ0bMWWJjzXHBWOZQycpgY+LGTAxgdWvTnunaBtgoOrBB5Vox i2bKHXIs4xOBR9q0aWimyVLQH3iwdDUka75vBcNMVpYjLiMuRedoCoQ71peQsIzGyIrl Hq8Hr4r8x0rk5g+nQ4XhSvA21mhqulUoclfbyhLN76ttoidl8ShtXZ4tjliQCOt3RqUP 988j7nLDRY5IIwrq3x7nTx/uYXzy8wkoeEVBvL12I//YdNWzF9KhD3qr1zdleOSjtS/x D/ihii4Tj1fU12OewIODbuaSvGRkh9nifIL3i4rPjv47wvCzV7usaaHYAPZBXS02egNq H2vg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=Vbk2whrV; dkim=neutral (no key) header.i=@linutronix.de header.b=kL4cKFhR; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h10si9620649edb.203.2021.06.18.12.29.24; Fri, 18 Jun 2021 12:29:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=Vbk2whrV; dkim=neutral (no key) header.i=@linutronix.de header.b=kL4cKFhR; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234221AbhFRRo4 (ORCPT + 99 others); Fri, 18 Jun 2021 13:44:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60920 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233934AbhFRRoz (ORCPT ); Fri, 18 Jun 2021 13:44:55 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CBBCBC061574; Fri, 18 Jun 2021 10:42:45 -0700 (PDT) Date: Fri, 18 Jun 2021 17:42:42 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1624038163; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=m4T6r4OFbKcFYZScWGv36zptdxpcLrCD12HgvKArkW0=; b=Vbk2whrVEWRzOaBsDa1SRsBK7OamJQ8mv5uqqWjypR9RDo3dHD/o9LRWo6iHNfoqTADaIY W3ZjgN+0VOgI+ivvb/52RJadYfWq8DhKPKKT6C6Aa1lvy3nuXE1Oqro/QSW4La4BKFSxCz mP9aqf/FJZynNSpnFaO7u8PNsE++MJZd0kDZag3bRIwdJoeEGYpsv8C3uL7HKy/fmuZ/bD b8oNE9JoOosE7cDqFHWRP6HWBGkWkJI5o1zLofiFRaafo/IhZaxb/mDy9TJ5MuNqhKUnhr 56fyhN6sh5m8aqTGXxSZR+x1YvfV9VcDj1l6nIPiJyRd8nWKtOxZrGoZMx1ARA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1624038163; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=m4T6r4OFbKcFYZScWGv36zptdxpcLrCD12HgvKArkW0=; b=kL4cKFhRia7OCNkSrXx51ld7LaN/rAwOHPXqshk9eODPGS/Y6Bt+QwjCuiSMUExgho5YxG vXDpxBOjZqAiRhAA== From: "tip-bot2 for Fan Du" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: x86/urgent] x86/mm: Avoid truncating memblocks for SGX memory Cc: Reinette Chatre , Fan Du , Dave Hansen , Borislav Petkov , Jarkko Sakkinen , Dan Williams , , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20210617194657.0A99CB22@viggo.jf.intel.com> References: <20210617194657.0A99CB22@viggo.jf.intel.com> MIME-Version: 1.0 Message-ID: <162403816226.19906.11145156429556481411.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The following commit has been merged into the x86/urgent branch of tip: Commit-ID: 28e5e44aa3f4e0e0370864ed008fb5e2d85f4dc8 Gitweb: https://git.kernel.org/tip/28e5e44aa3f4e0e0370864ed008fb5e2d85f4dc8 Author: Fan Du AuthorDate: Thu, 17 Jun 2021 12:46:57 -07:00 Committer: Borislav Petkov CommitterDate: Fri, 18 Jun 2021 19:37:01 +02:00 x86/mm: Avoid truncating memblocks for SGX memory tl;dr: Several SGX users reported seeing the following message on NUMA systems: sgx: [Firmware Bug]: Unable to map EPC section to online node. Fallback to the NUMA node 0. This turned out to be the memblock code mistakenly throwing away SGX memory. === Full Changelog === The 'max_pfn' variable represents the highest known RAM address. It can be used, for instance, to quickly determine for which physical addresses there is mem_map[] space allocated. The numa_meminfo code makes an effort to throw out ("trim") all memory blocks which are above 'max_pfn'. SGX memory is not considered RAM (it is marked as "Reserved" in the e820) and is not taken into account by max_pfn. Despite this, SGX memory areas have NUMA affinity and are enumerated in the ACPI SRAT table. The existing SGX code uses the numa_meminfo mechanism to look up the NUMA affinity for its memory areas. In cases where SGX memory was above max_pfn (usually just the one EPC section in the last highest NUMA node), the numa_memblock is truncated at 'max_pfn', which is below the SGX memory. When the SGX code tries to look up the affinity of this memory, it fails and produces an error message: sgx: [Firmware Bug]: Unable to map EPC section to online node. Fallback to the NUMA node 0. and assigns the memory to NUMA node 0. Instead of silently truncating the memory block at 'max_pfn' and dropping the SGX memory, add the truncated portion to 'numa_reserved_meminfo'. This allows the SGX code to later determine the NUMA affinity of its 'Reserved' area. Before, numa_meminfo looked like this (from 'crash'): blk = { start = 0x0, end = 0x2080000000, nid = 0x0 } { start = 0x2080000000, end = 0x4000000000, nid = 0x1 } numa_reserved_meminfo is empty. With this, numa_meminfo looks like this: blk = { start = 0x0, end = 0x2080000000, nid = 0x0 } { start = 0x2080000000, end = 0x4000000000, nid = 0x1 } and numa_reserved_meminfo has an entry for node 1's SGX memory: blk = { start = 0x4000000000, end = 0x4080000000, nid = 0x1 } [ daveh: completely rewrote/reworked changelog ] Fixes: 5d30f92e7631 ("x86/NUMA: Provide a range-to-target_node lookup facility") Reported-by: Reinette Chatre Signed-off-by: Fan Du Signed-off-by: Dave Hansen Signed-off-by: Borislav Petkov Reviewed-by: Jarkko Sakkinen Reviewed-by: Dan Williams Reviewed-by: Dave Hansen Cc: Link: https://lkml.kernel.org/r/20210617194657.0A99CB22@viggo.jf.intel.com --- arch/x86/mm/numa.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/arch/x86/mm/numa.c b/arch/x86/mm/numa.c index 5eb4dc2..e94da74 100644 --- a/arch/x86/mm/numa.c +++ b/arch/x86/mm/numa.c @@ -254,7 +254,13 @@ int __init numa_cleanup_meminfo(struct numa_meminfo *mi) /* make sure all non-reserved blocks are inside the limits */ bi->start = max(bi->start, low); - bi->end = min(bi->end, high); + + /* preserve info for non-RAM areas above 'max_pfn': */ + if (bi->end > high) { + numa_add_memblk_to(bi->nid, high, bi->end, + &numa_reserved_meminfo); + bi->end = high; + } /* and there's no empty block */ if (bi->start >= bi->end)