Received: by 2002:a05:7412:3b8b:b0:fc:a2b0:25d7 with SMTP id nd11csp2541234rdb; Mon, 12 Feb 2024 08:05:54 -0800 (PST) X-Google-Smtp-Source: AGHT+IGtApxVzVJbNIM5/7akpiZkLnBr3z4e1HGSFMWaPm503opG3gx4QsqL2j0gG/ZS/ObWUH5Q X-Received: by 2002:a17:90a:b38a:b0:297:179c:15bb with SMTP id e10-20020a17090ab38a00b00297179c15bbmr5744335pjr.9.1707753952173; Mon, 12 Feb 2024 08:05:52 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707753952; cv=pass; d=google.com; s=arc-20160816; b=CDqUIEKhpBrkDwPH/a3X+0FkAKeZBB47Rsbc6+UBwPLuJR+E4y8GJo3GkdHKX+ef1w u1yIF9TFK3vlkAtFEjvEBsw50AxddoTFA9K3H3mzdWY2onzEBbTRyJ3QljP2os3sKqMD IotAfpLEHBtkg5FmC7MyFYCMYUwEqjKOkyUcGCLF4eP2iieuA9BHXGaT8VpRMoz8/2E3 pj9p01dAIaY4W+x++9Vt/IWp4wT0sUWsftX4R/YL/0UoXSNZAjaaAtvnGp1jsZE5BmVU 4HsdtReiXf4Gi5QROS8ZEATEewoMs2zNGp4xGzM9L+/ea5QhLNgx37ZI1m1NtsqbKjYS +6oA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=user-agent:in-reply-to:content-disposition:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:references :message-id:subject:cc:to:from:date:dkim-signature; bh=sFUZ1ZPFZ/WDyHllg7SZ7uHP4YihqPe1LFWLeuVzMlk=; fh=rYXtfCC0LkmCgbU/bZAyuidlwDuAc6yLYWjHgIgELEk=; b=dR7n4yhJYwcQoxJGvDYU/9b5jgrXpPNIkj+1XnCsHMp54xvoT/Uq4SIaXOOVomEYAr ngUB0Ge3uR1cSHaJ6IHAHRkE4s3pLzYSIWRAX6+thBFZ6+GRdOTWP0A8v7GWUDHltPDA 0hOnyF7radqIroiDFebxxYWGbCAVp89BkpYyJ90bt9KtWXClOtdk02hsiurXJZuAnriM 5J/V8ptyn/mDDQ3PTESaZEJGa5ZljdaJ/qjDrHPo6t89Xq81u33gislMLo+gjWvN+1z9 kiFjoOCUrlZ6Mbp0m6Kis9ZpmTZ6kU/LcH4dFtkZ5GLkW1rpgudiRC6jafWxKGWLtcl4 OSug==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@hpe.com header.s=pps0720 header.b="aa6I/7nJ"; arc=pass (i=1 spf=pass spfdomain=hpe.com dkim=pass dkdomain=hpe.com dmarc=pass fromdomain=hpe.com); spf=pass (google.com: domain of linux-kernel+bounces-61933-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-61933-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=hpe.com X-Forwarded-Encrypted: i=2; AJvYcCU254oWiji3gLfApMRqzeZOC6JbYD5+o/91ASUOalbezM7pEhrK2PENVUvvPsvf6TX/DxFei3fkdQkYMYbHOETtR0mb+4toQO9m8eDgDw== Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id il2-20020a17090b164200b00296db812c4dsi480673pjb.116.2024.02.12.08.05.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Feb 2024 08:05:52 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-61933-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@hpe.com header.s=pps0720 header.b="aa6I/7nJ"; arc=pass (i=1 spf=pass spfdomain=hpe.com dkim=pass dkdomain=hpe.com dmarc=pass fromdomain=hpe.com); spf=pass (google.com: domain of linux-kernel+bounces-61933-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-61933-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=hpe.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id BE512B21937 for ; Mon, 12 Feb 2024 16:04:37 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id CCBB33D38D; Mon, 12 Feb 2024 16:04:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=hpe.com header.i=@hpe.com header.b="aa6I/7nJ" Received: from mx0b-002e3701.pphosted.com (mx0b-002e3701.pphosted.com [148.163.143.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E0DE93CF7C for ; Mon, 12 Feb 2024 16:04:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=148.163.143.35 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707753853; cv=none; b=Ihdt5OKwMRM0fMV4faMQDr4/Z8b91fuK5MlAjRqKx4i5BRJgLFYX4t+NOh/0PaI5DRJzqW8UXhJk1FU6rfHoziC3YxXwslNUQ1yGv0Z0tA20jsYhheuZ5oQ9hQ5BcoOTSrBbyDh0Ec+wnCQX3OsiP5lLKcgB/WWCt6L2l6kHmPk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707753853; c=relaxed/simple; bh=rl/yyVjmBu4nkntx95NTjP9MeBqwIZs3VgXZpyBSGGg=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Pw+8PrBzvSR5G2ie4ZQi/Qj/I6wtrXoPZxjBpVjgTnNxrRPMdSmXYun9JiE5TnGZUVv7VI9sfAuymEncs/3XnLfX4VNSOgijRSyE741aw+xSLtFZ/bZEqMAhyvuRsaUyB9LuDebhJGjAHxlTdgwokpv8Q2BDjgxxVLIqtx+FPW4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=hpe.com; spf=pass smtp.mailfrom=hpe.com; dkim=pass (2048-bit key) header.d=hpe.com header.i=@hpe.com header.b=aa6I/7nJ; arc=none smtp.client-ip=148.163.143.35 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=hpe.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=hpe.com Received: from pps.filterd (m0150244.ppops.net [127.0.0.1]) by mx0b-002e3701.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 41CG2VcP029891; Mon, 12 Feb 2024 16:03:29 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=hpe.com; h=date : from : to : cc : subject : message-id : references : mime-version : content-type : in-reply-to; s=pps0720; bh=sFUZ1ZPFZ/WDyHllg7SZ7uHP4YihqPe1LFWLeuVzMlk=; b=aa6I/7nJCtMDWox5l/XN0Mno+JoipZHShRa2/Lp+CnnaXpuvCe5S1YjmVjYK7sKk4uMm VmR1zkG2L6buf+Ij7D21wBfZEx6GhMr+UOa9bdu2yblvZ4/9Scqimcc87ACGHESjtjBL k8hlnaydbRDr9KSSQLCUkcb97tewOYbHWyuQgtJjumLZ8qfM+ulyGa6zoK7w07ylekxA WFs5If4wuK5Tlq6Bnk6VWHd8d05hWuG28ac6aQHgWLGPlbP7wg1W9mKoiM1YTDzxJ4nJ S2tPjtVXJewliOVHR6abcNd/799qqA6oCYDxpgAAvKlAi1e/AstIUfcK+cBbPrKFxtuW 7Q== Received: from p1lg14878.it.hpe.com ([16.230.97.204]) by mx0b-002e3701.pphosted.com (PPS) with ESMTPS id 3w7p7r0ads-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 12 Feb 2024 16:03:29 +0000 Received: from p1lg14885.dc01.its.hpecorp.net (unknown [10.119.18.236]) (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 p1lg14878.it.hpe.com (Postfix) with ESMTPS id 14FDD132DB; Mon, 12 Feb 2024 16:03:25 +0000 (UTC) Received: from dog.eag.rdlabs.hpecorp.net (unknown [16.231.227.36]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client did not present a certificate) by p1lg14885.dc01.its.hpecorp.net (Postfix) with ESMTPS id 60BEC80162E; Mon, 12 Feb 2024 16:03:23 +0000 (UTC) Date: Mon, 12 Feb 2024 10:03:21 -0600 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: Re: [PATCH v3] x86/mm/ident_map: Use gbpages only where full GB page should be mapped. Message-ID: <20240212160321.GA1508687@dog.eag.rdlabs.hpecorp.net> References: <20240126164841.170866-1-steve.wahl@hpe.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240126164841.170866-1-steve.wahl@hpe.com> User-Agent: Mutt/1.10.1 (2018-07-13) X-Proofpoint-ORIG-GUID: ARyePb20hroSPz7YuULDTLQnDM6LJ6b0 X-Proofpoint-GUID: ARyePb20hroSPz7YuULDTLQnDM6LJ6b0 X-HPE-SCL: -1 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-12_13,2024-02-12_03,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 bulkscore=0 phishscore=0 adultscore=0 mlxlogscore=999 priorityscore=1501 spamscore=0 suspectscore=0 lowpriorityscore=0 malwarescore=0 impostorscore=0 clxscore=1011 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2402120121 Gentle Ping... Thanks --> Steve Wahl On Fri, Jan 26, 2024 at 10:48:41AM -0600, Steve Wahl wrote: > When ident_pud_init() uses only gbpages to create identity maps, large > ranges of addresses not actually requested can be included in the > resulting table; a 4K request will map a full GB. 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. > > 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 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. > > The existing kernel option "nogbpages" would 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 > --- > > v3: per Dave Hansen review, re-arrange changelog info, > refactor code to use bool variable and split out conditions. > > v2: per Dave Hansen 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 | 23 ++++++++++++++++++----- > 1 file changed, 18 insertions(+), 5 deletions(-) > > diff --git a/arch/x86/mm/ident_map.c b/arch/x86/mm/ident_map.c > index 968d7005f4a7..f50cc210a981 100644 > --- a/arch/x86/mm/ident_map.c > +++ b/arch/x86/mm/ident_map.c > @@ -26,18 +26,31 @@ static int ident_pud_init(struct x86_mapping_info *info, pud_t *pud_page, > for (; addr < end; addr = next) { > pud_t *pud = pud_page + pud_index(addr); > pmd_t *pmd; > + bool use_gbpage; > > next = (addr & PUD_MASK) + PUD_SIZE; > 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; > + > + /* Is using a gbpage allowed? */ > + use_gbpage = info->direct_gbpages; > > - if (pud_present(*pud)) > - continue; > + /* Don't use gbpage if it maps more than the requested region. */ > + /* at the begining: */ > + use_gbpage &= ((addr & ~PUD_MASK) == 0); > + /* ... or at the end: */ > + use_gbpage &= ((next & ~PUD_MASK) == 0); > + > + /* Never overwrite existing mappings */ > + use_gbpage &= !pud_present(*pud); > + > + if (use_gbpage) { > + pud_t pudval; > > - addr &= PUD_MASK; > pudval = __pud((addr - info->offset) | info->page_flag); > set_pud(pud, pudval); > continue; > -- > 2.26.2 >