From nobody Fri Nov 29 20:55:26 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; arc=pass (i=1 dmarc=pass fromdomain=suse.com); dmarc=pass(p=quarantine dis=none) header.from=suse.com ARC-Seal: i=2; a=rsa-sha256; t=1630328624; cv=pass; d=zohomail.com; s=zohoarc; b=c4VNSajZZ/Ssl2JqZAE290fmnmlb3Ybl9FaTiNMtkW2RWD1h0rU/EIF44QujWUhYcjpn0Zy32lqDHQFGTSPzfmvioOdwcTjea8yUst2DNqdxs8VIZ4p/RYf09m9zpuwfHKFfyfEbSZOM7ZUJs3YecOv+yM9rwkQ++4EYGvDOYuc= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1630328624; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=4Vo4Dkwt5tDPO7OINdISKIs97Cf1OIMtewg4ko0cXdk=; b=E57T1c65FHggtwH+R0vcdugnJJGqAt4wLyciaRNUSGxY82IRLKTwCAAvB78obcYCaspMKeWbmlirPUFTidZ0OFCWZII78Sn+zX7b5OfWv5h/7s6u5/wUSQhuDjE031e4h1z7eBBrdcBbwIlNg7HaVilsHbKbfkOs8RI1AsWB2KM= ARC-Authentication-Results: i=2; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; arc=pass (i=1 dmarc=pass fromdomain=suse.com); dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1630328623983478.86948093049034; Mon, 30 Aug 2021 06:03:43 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.175043.318990 (Exim 4.92) (envelope-from ) id 1mKgwe-00008j-9x; Mon, 30 Aug 2021 13:03:24 +0000 Received: by outflank-mailman (output) from mailman id 175043.318990; Mon, 30 Aug 2021 13:03:24 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mKgwe-00008b-6v; Mon, 30 Aug 2021 13:03:24 +0000 Received: by outflank-mailman (input) for mailman id 175043; Mon, 30 Aug 2021 13:03:22 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mKgwc-0008TI-An for xen-devel@lists.xenproject.org; Mon, 30 Aug 2021 13:03:22 +0000 Received: from de-smtp-delivery-102.mimecast.com (unknown [194.104.109.102]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id a5ee4862-0992-11ec-ac87-12813bfff9fa; Mon, 30 Aug 2021 13:03:20 +0000 (UTC) Received: from EUR05-VI1-obe.outbound.protection.outlook.com (mail-vi1eur05lp2169.outbound.protection.outlook.com [104.47.17.169]) (Using TLS) by relay.mimecast.com with ESMTP id de-mta-39-5hhDC0mZNTqVg6rGr1Oq0Q-1; Mon, 30 Aug 2021 15:03:18 +0200 Received: from VI1PR04MB5600.eurprd04.prod.outlook.com (2603:10a6:803:e7::16) by VI1PR04MB5901.eurprd04.prod.outlook.com (2603:10a6:803:e9::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4457.19; Mon, 30 Aug 2021 13:03:15 +0000 Received: from VI1PR04MB5600.eurprd04.prod.outlook.com ([fe80::4d37:ec64:4e90:b16b]) by VI1PR04MB5600.eurprd04.prod.outlook.com ([fe80::4d37:ec64:4e90:b16b%7]) with mapi id 15.20.4457.024; Mon, 30 Aug 2021 13:03:14 +0000 Received: from [10.156.60.236] (37.24.206.209) by PR3P192CA0005.EURP192.PROD.OUTLOOK.COM (2603:10a6:102:56::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4457.17 via Frontend Transport; Mon, 30 Aug 2021 13:03:14 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: a5ee4862-0992-11ec-ac87-12813bfff9fa DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=mimecast20200619; t=1630328599; h=from:from: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=4Vo4Dkwt5tDPO7OINdISKIs97Cf1OIMtewg4ko0cXdk=; b=dPZT6bgkv0JWkP/m7KtNuWJxv7OxoA1k/t6jB9hZy0hIX7v9uRyp9F35KetVYeU5cKjjke 9xsy2to1HXl5/+xnZtI1e5MoqAfghpeHHw2afhZ8btvuKZIDUlu5n7y4lJbsQR7269o3cl W1ogKD2srsLd79rWDpcKPWizQo5xcOM= X-MC-Unique: 5hhDC0mZNTqVg6rGr1Oq0Q-1 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=n4IQooAn+HJd4MfKZk/G78eDewM0T7ANn9HppOYZjlhRC2mh72iZxrl1AiSyMWZ/RuwkoyOu/zgnHYr4zxj9jcCQOqzrnOCERUGB1gsIWYWiBIRVl/XTyyPdio9T3nqgpliQSMIiRf83E+25ngJEDiSvPOgStynZtNj9SHU+m0AjrU1Cz3DUGrJk8n359tHzcAq9fNtbdLkHVk21SUAaQbx0XRGeqzsMrtW3ZAv7X0YYKx76rP/U7cZ25zsrWl2kw1Zm4cNID9pY7Nq2Y/Z9h6U2il7tCRKmQqvHzfhEyHz2j0E8333EamulKdMpqM24AVm2Ogu3H0IQriyX50p8Ng== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=4Vo4Dkwt5tDPO7OINdISKIs97Cf1OIMtewg4ko0cXdk=; b=ctN1sDxY9EEHTl9xG02Wx5tW+UZKpSwq275EfztG3aCbblc2NtW2db4hDgOAWjVhII+4Z5svCUK2rto6F9gfIfWfjYsTW8WeKzuNjjsm0o2xzqSGLjOPhtmvPZEmSBOQEIhV/RsxpIB7QV9zhfvKoNf3F+ggngJgBPYY7aOADtTKspfjBVVFsrBig0iJWGvUaWBrdQ1x6y4iJATVorev+uamN1l1A4Gk76wMpdQaMLMxxSSalgryY7AR59TFCI4FuKxoPNdG/YGiG8sm4FDMG83EsaGhS4V6QAuZ2zaYzKSRJ0zieOw3FddSWNiSWXUwCL7SMiObK5QYLynKjjhPUA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=suse.com; dmarc=pass action=none header.from=suse.com; dkim=pass header.d=suse.com; arc=none Authentication-Results: citrix.com; dkim=none (message not signed) header.d=none;citrix.com; dmarc=none action=none header.from=suse.com; Subject: [PATCH 3/4] x86/PVH: improve Dom0 memory size calculation From: Jan Beulich To: "xen-devel@lists.xenproject.org" Cc: Andrew Cooper , Wei Liu , =?UTF-8?Q?Roger_Pau_Monn=c3=a9?= References: Message-ID: Date: Mon, 30 Aug 2021 15:03:13 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.13.0 In-Reply-To: Content-Language: en-US Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: PR3P192CA0005.EURP192.PROD.OUTLOOK.COM (2603:10a6:102:56::10) To VI1PR04MB5600.eurprd04.prod.outlook.com (2603:10a6:803:e7::16) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: d38b6e6d-3f34-45f9-1c93-08d96bb68744 X-MS-TrafficTypeDiagnostic: VI1PR04MB5901: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:2276; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: S3ylkW9CoSVK4xSXaZ0CXLHGVibFaTqY2xdGil4nzZc0uE/a/frcIrKgmDq9TaqHOkoJk6Xsme6ORWPZsYE5rYCuoMQL4IwjLC85Z0kFZLZ+lWcO+7Z9AVWrMGjrAeHgf0x/QvUO6wS+/3cWianYqMesR+J6TEoz7qX4epp2N6g8d1xbkRGZ6KUUos2RFdy3U418ZX2wDooq/oetaYt81PQ3SalP7tnx1DEQXsjSag5qe6+ptdb0JZiB4ScBk8FAHyeeFPu7dUbdsP5yt1XrGPaicVFQ7hXKHmHx1tGZgqmlhr4zQ7ltRYvYU5zGoAvnlZyh6ZuDY5c+msX9sY/r4xTED8B3WCur6ecbiFZbFwUSBnZfkgWHMPW+R/JMGNO1nbgJoXEnzoQbA118mFdY0uKaaCdU1hz1IhpEmCQDO7KWjhEALjTgP+sUPyaoSXiF/DPpjWsPSkJyP/9xU7F5OZ6cYpWsouU4lEIkpMTJVEaWzJCSSxzSHInkBM9t5SqJu2mawUQfAkvurhBw6dc4umgy0y711Ws80CDiXOvQAy1zivjR4mtw+AtPZRpJL3MuaVC4BZF1x/MfWg9EL05D41uppE3ch7rNJ0ZjmR1xBDLwpmFE67ZWXL4gI9KU7/e8zGWEAKflsUxEawjFt6uhKvbvwbQ9FK9uLoepaQuZxc5NGyVt0VImoDjCqOXPt4urZWkbE8TRr1MzHM6Hx5dGzOIg9ItvWJvC9hv1ARNoe+Anv1oCrSXY5TWI32Vl3VepIjisbo+/wFgH3OhDkRZnXQ== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:VI1PR04MB5600.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(376002)(136003)(366004)(346002)(39860400002)(396003)(316002)(66476007)(6486002)(66556008)(16576012)(6916009)(5660300002)(8936002)(83380400001)(54906003)(8676002)(36756003)(66946007)(38100700002)(186003)(2906002)(4326008)(26005)(86362001)(2616005)(956004)(478600001)(31686004)(31696002)(25903002)(43740500002)(45980500001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?bWwwN3h5bGNXRzNMWjEveWlYbDRReVVYOFJpMDhoNjBmWWk1cFNCV2NXVXdV?= =?utf-8?B?dHVLaVFFV0ZZSUpTcXVTc2IzemVkRjRRNE40RzN3QnU1T2lzd210akgvdDlt?= =?utf-8?B?bHRJblB6QmFRZEV6U1U5N1JpVDN4UVIwWDlFYlNGU3FMSlBmT0RvZjh6aWE4?= =?utf-8?B?dE1qSUk3QlVuOTAyYmkvbWJnLzNFdjlEelNMYUI4WlFmOUZ2Sy92UkptaGdF?= =?utf-8?B?ZUVlODVBdzBHSnJEdnZ1Y3hmT214VUhxOXhZUWdrSjFVTG52S1lDNnpGREJV?= =?utf-8?B?Yi9BRlg5emFqY0c4MUtwTENBSHA1Q3IwblJ3b2dZc0xEaFU1MkpzNEVlNHQv?= =?utf-8?B?VEtrS1p6TTQvZTVIS2JySnJ5TTkvRVBlOHFvSGYxTlcxSzVoT2FSRXhsMDcr?= =?utf-8?B?blZJVW82THVjZGxIUndMUnZ6S3lnUnhUanUvbGtPNHRadkRMUmd4MmxhaTJZ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3lVTUUzR1dMVzFaT2Zo?= =?utf-8?B?WjNIWlVVb2pXd3p3em5oVUowTGxoRm12b09Qdm8wTWsybDVicVJLZ0RjTG4z?= =?utf-8?B?QnNPZG1vSlIyY3FnQVQxNHhkWUgxNld0cE5HMjhHdFgySSsvMUlBNjlIVTJi?= =?utf-8?B?NTlraWtyZFJpa1JQMFhnOTNrczZGY0VQaEpjaXRIUDl3ZDhTaFJhKzUyeVJQ?= =?utf-8?B?LzdqZ3NFVWx0bzErb2Z5UVZvSXovaU54anRRYmo4SUdjcmRyUjYvQ2pMWjh5?= =?utf-8?B?UnpBWTFydHQvdE1GZldncXl3Q21Kc1owM2ZpT0tKd3lCWUswdjlpNTBIY09T?= =?utf-8?B?b29RRWVwcnhaTjlvK3NaTk1Ldm5aRlJNd3ZvcEVsR2hPejBrcllNWVNlUTNU?= =?utf-8?Q?nnwFgys6MZHaZEwBgfqWUxBqQ2+QKME4PaClC/G?= X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: d38b6e6d-3f34-45f9-1c93-08d96bb68744 X-MS-Exchange-CrossTenant-AuthSource: VI1PR04MB5600.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Aug 2021 13:03:14.8632 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: f7a17af6-1c5c-4a36-aa8b-f5be247aa4ba X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: vYK4CWYjmMjiVYQTOqfr1uxzwY0MvyALIR+QV1e92vY2LszhmLeaBKNer8SL2eZykwIF4uMGNDfQlf2DyIbC9w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR04MB5901 X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1630328630354100001 Content-Type: text/plain; charset="utf-8" Assuming that the accounting for IOMMU page tables will also take care of the P2M needs was wrong: dom0_paging_pages() can determine a far higher value, high enough for the system to run out of memory while setting up Dom0. Hence in the case of shared page tables the larger of the two values needs to be used (without shared page tables the sum of both continues to be applicable). While there also account for two further aspects in the PV case: With "iommu=3Ddom0-passthrough" no IOMMU page tables would get allocated, so none need accounting for. And if shadow mode is to be enabled, setting aside a suitable amount for the P2M pool to get populated is also necessary (i.e. similar to the non-shared-page-tables case of PVH). Signed-off-by: Jan Beulich --- a/xen/arch/x86/dom0_build.c +++ b/xen/arch/x86/dom0_build.c @@ -318,7 +318,7 @@ unsigned long __init dom0_compute_nr_pag struct domain *d, struct elf_dom_parms *parms, unsigned long initrd_le= n) { nodeid_t node; - unsigned long avail =3D 0, nr_pages, min_pages, max_pages; + unsigned long avail =3D 0, nr_pages, min_pages, max_pages, iommu_pages= =3D 0; bool need_paging; =20 /* The ordering of operands is to work around a clang5 issue. */ @@ -337,18 +337,23 @@ unsigned long __init dom0_compute_nr_pag avail -=3D d->max_vcpus - 1; =20 /* Reserve memory for iommu_dom0_init() (rough estimate). */ - if ( is_iommu_enabled(d) ) + if ( is_iommu_enabled(d) && !iommu_hwdom_passthrough ) { unsigned int s; =20 for ( s =3D 9; s < BITS_PER_LONG; s +=3D 9 ) - avail -=3D max_pdx >> s; + iommu_pages +=3D max_pdx >> s; + + avail -=3D iommu_pages; } =20 - need_paging =3D is_hvm_domain(d) && - (!iommu_use_hap_pt(d) || !paging_mode_hap(d)); + need_paging =3D is_hvm_domain(d) + ? !iommu_use_hap_pt(d) || !paging_mode_hap(d) + : opt_dom0_shadow; for ( ; ; need_paging =3D false ) { + unsigned long paging_pages; + nr_pages =3D get_memsize(&dom0_size, avail); min_pages =3D get_memsize(&dom0_min_size, avail); max_pages =3D get_memsize(&dom0_max_size, avail); @@ -377,11 +382,20 @@ unsigned long __init dom0_compute_nr_pag nr_pages =3D min(nr_pages, max_pages); nr_pages =3D min(nr_pages, avail); =20 - if ( !need_paging ) - break; + paging_pages =3D paging_mode_enabled(d) || need_paging + ? dom0_paging_pages(d, nr_pages) : 0; =20 /* Reserve memory for shadow or HAP. */ - avail -=3D dom0_paging_pages(d, nr_pages); + if ( !need_paging ) + { + if ( paging_pages <=3D iommu_pages ) + break; + + avail -=3D paging_pages - iommu_pages; + } + else + avail -=3D paging_pages; + iommu_pages =3D paging_pages; } =20 if ( is_pv_domain(d) &&