Received: by 2002:a05:7412:8521:b0:e2:908c:2ebd with SMTP id t33csp696188rdf; Fri, 3 Nov 2023 12:06:49 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGHCsGMWawi92bewUvvHwuFIN5DUwNiM3kUWKNsdrtDbAKHCV8FR6mlfMoi/4KAyeNWWFYA X-Received: by 2002:a17:90a:c698:b0:280:3772:5c2e with SMTP id n24-20020a17090ac69800b0028037725c2emr17138267pjt.25.1699038408861; Fri, 03 Nov 2023 12:06:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1699038408; cv=none; d=google.com; s=arc-20160816; b=xOOLhRYJ4TCmHbsTcCp/qFWrQ/vyDFul/iVmNF/n52TDSAjk9U3OC3aVvWF63KXKtt jVA6clCyxj4H1V9zXbLVSNEu4BL1nze3y480vBVNqVooTxxpBhwg+9Y+QjmkNVmDzPk3 zXjC/V6CTVth0fl9AXz+uq7GNWrqPcy5XyedprwP3sNIRvdof+rzH+GH3wcAYIpAmO1b s4BGYsP3jBUCvXYOd8nny8txKQJYcJ3vq6S3EPAJUrI7fk0/xmwo3xAsiy2HAGDwp5fm 1zwziOJhnvjQOLWRYUO61N+waIZC/lMnWCv7LtKp3wNqCZfMhduoj+5vq5SKvBRhVZ5S +vcg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=fWctpsPV3PH/7sLW4j6O5J5E8Yl+oUi96i/KVhJR+g8=; fh=dvPuEpu0oJuTXhfSmKRfCjweQ2pj8YqfIwBDmHw7zR8=; b=bkRvO623REKoCZJaHcw+rbFZlczZVXrqKj3wGRDcuO5YmImwDENhCrFAMFPWQZ47bg S7pc7Na82JS9IBtpjaL1IjpicidzDiQI+Klx7zCun0a9/9p+k3/ecPNr7FxFWCFWDB3b 3FihVxgsg1i7hd/HMYfCXGfGXLnwglCzJGZ82mFzqMVkklZ0p++u9k/SqfASAKuKxvUp i9tmb3I53oq4hJIWKAOmjtVlJKY4d1XUDfAiX7WmpWcbr2eQvx3c7KeIH9iFG9hJdtCI bLIqzI956AuQwqGXljlxF0ex6JbuZbyrbIRreizsQVjQCuoJvkIbezghrtd9Ub2q/bvr yYbA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@hpe.com header.s=pps0720 header.b=Y6wJlKjp; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=hpe.com Return-Path: Received: from groat.vger.email (groat.vger.email. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id k18-20020a170902c41200b001bb8a57d518si2187980plk.379.2023.11.03.12.06.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Nov 2023 12:06:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) client-ip=2620:137:e000::3:5; Authentication-Results: mx.google.com; dkim=pass header.i=@hpe.com header.s=pps0720 header.b=Y6wJlKjp; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=hpe.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id 312368087FF4; Fri, 3 Nov 2023 12:05:08 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230368AbjKCTCK (ORCPT + 99 others); Fri, 3 Nov 2023 15:02:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55394 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230192AbjKCTCI (ORCPT ); Fri, 3 Nov 2023 15:02:08 -0400 Received: from mx0b-002e3701.pphosted.com (mx0b-002e3701.pphosted.com [148.163.143.35]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 031A6BD for ; Fri, 3 Nov 2023 12:02:02 -0700 (PDT) Received: from pps.filterd (m0134423.ppops.net [127.0.0.1]) by mx0b-002e3701.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 3A3IlS9m025788; Fri, 3 Nov 2023 19:01:20 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=hpe.com; h=from : to : cc : subject : date : message-id : mime-version : content-transfer-encoding; s=pps0720; bh=fWctpsPV3PH/7sLW4j6O5J5E8Yl+oUi96i/KVhJR+g8=; b=Y6wJlKjpkHD8kbOPFPNSt0/VmmKgObJTIBnjqq/KLDxwc+FbXJ2bXfVbw271p43Bys1t kCaNc7bpB4SPCvy6TATjg52abxeKoQG2mRqNus7ReXkbPgJDAT5EfUfLiisrre1G+TOj cMh0EAwOFLEEM3yvSnAOM+k38pZxHo1LsvWU5+q/eUDXbtdHflQ4SmGQUiMCl5wW8xuv mA0gsNw3zMkKEuDw2FsNh8191SrcjaQgyoKLM+p1N3Lx8NlN66Zg9Rg+nUH24DcSQuoc b5UdVuS05POo7aeHjUemQKaQ+LSIUbQafpIJ+BrPgymaiIoVphzixAvntc8ye7Zw6GQX nA== Received: from p1lg14879.it.hpe.com ([16.230.97.200]) by mx0b-002e3701.pphosted.com (PPS) with ESMTPS id 3u54v6s1r9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 03 Nov 2023 19:01:20 +0000 Received: from p1lg14886.dc01.its.hpecorp.net (unknown [10.119.18.237]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by p1lg14879.it.hpe.com (Postfix) with ESMTPS id 4A7651317B; Fri, 3 Nov 2023 19:01:19 +0000 (UTC) Received: from dog.eag.rdlabs.hpecorp.net (unknown [16.231.227.36]) by p1lg14886.dc01.its.hpecorp.net (Postfix) with ESMTP id AB4A480E713; Fri, 3 Nov 2023 19:01:08 +0000 (UTC) Received: by dog.eag.rdlabs.hpecorp.net (Postfix, from userid 200934) id 20D90302F47FB; Fri, 3 Nov 2023 14:01:08 -0500 (CDT) From: Steve Wahl To: Steve Wahl , Dave Hansen , Andy Lutomirski , Peter Zijlstra , Thomas Gleixner , Ingo Molnar , Borislav Petkov , x86@kernel.org, "H. Peter Anvin" , linux-kernel@vger.kernel.org Cc: Russ Anderson , Dimitri Sivanich Subject: [PATCH v2] x86/mm/ident_map: Use gbpages only where full GB page should be mapped. Date: Fri, 3 Nov 2023 14:01:08 -0500 Message-Id: <20231103190108.184817-1-steve.wahl@hpe.com> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Proofpoint-ORIG-GUID: qaegrJ8pxD5nlpULjEzqJp2JfCpzm-Fm X-Proofpoint-GUID: qaegrJ8pxD5nlpULjEzqJp2JfCpzm-Fm X-HPE-SCL: -1 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.987,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-11-03_18,2023-11-02_03,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 malwarescore=0 mlxlogscore=999 priorityscore=1501 bulkscore=0 clxscore=1015 suspectscore=0 impostorscore=0 spamscore=0 phishscore=0 lowpriorityscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2310240000 definitions=main-2311030159 X-Spam-Status: No, score=-1.3 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Fri, 03 Nov 2023 12:05:08 -0700 (PDT) Instead of using gbpages for all memory regions, which can include vast areas outside what's actually been requested, use them only when map creation requests include the full GB page of space; descend to using smaller 2M pages when only portions of a GB page are included in the request. No attempt is made to coalesce mapping requests. If a request requires a map entry at the 2M (pmd) level, subsequent mapping requests within the same 1G region will also be at the pmd level, even if adjacent or overlapping such requests could theoretically have been combined to map a full gbpage. Existing usage starts with larger regions and then adds smaller regions, so this should not have any great consequence. When gbpages are used exclusively to create identity maps, large ranges of addresses not actually requested can be included in the resulting table. On UV systems, this ends up including regions that will cause hardware to halt the system if accessed (these are marked "reserved" by BIOS). Even though code does not actually make references to these addresses, including them in an active map allows processor speculation into this region, which is enough to trigger the system halt. The kernel option "nogbpages" will disallow use of gbpages entirely and avoid this problem, but uses a lot of extra memory for page tables that are not really needed. Signed-off-by: Steve Wahl --- v2: per Dave Hanson review: Additional changelog info, moved pud_large() check earlier in the code, and improved the comment describing the conditions that restrict gbpage usage. arch/x86/mm/ident_map.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/arch/x86/mm/ident_map.c b/arch/x86/mm/ident_map.c index 968d7005f4a7..5c88c3a7d12a 100644 --- a/arch/x86/mm/ident_map.c +++ b/arch/x86/mm/ident_map.c @@ -31,13 +31,23 @@ static int ident_pud_init(struct x86_mapping_info *info, pud_t *pud_page, if (next > end) next = end; - if (info->direct_gbpages) { - pud_t pudval; + /* if this is already a gbpage, this portion is already mapped */ + if (pud_large(*pud)) + continue; - if (pud_present(*pud)) - continue; + /* + * To be eligible to use a gbpage: + * - gbpages must be enabled + * - addr must be gb aligned (start of region) + * - next must be gb aligned (end of region) + * - PUD must be empty (nothing already mapped in this region) + */ + if (info->direct_gbpages + && !(addr & ~PUD_MASK) + && !(next & ~PUD_MASK) + && !pud_present(*pud)) { + pud_t pudval; - addr &= PUD_MASK; pudval = __pud((addr - info->offset) | info->page_flag); set_pud(pud, pudval); continue; -- 2.26.2