From patchwork Fri Apr 22 10:57:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Beulich X-Patchwork-Id: 12823236 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 90590C433F5 for ; Fri, 22 Apr 2022 10:57:32 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.310818.527753 (Exim 4.92) (envelope-from ) id 1nhqyN-0004E8-Kt; Fri, 22 Apr 2022 10:57:11 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 310818.527753; Fri, 22 Apr 2022 10:57:11 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nhqyN-0004E1-Gi; Fri, 22 Apr 2022 10:57:11 +0000 Received: by outflank-mailman (input) for mailman id 310818; Fri, 22 Apr 2022 10:57:09 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nhqyL-0004Dv-NP for xen-devel@lists.xenproject.org; Fri, 22 Apr 2022 10:57:09 +0000 Received: from de-smtp-delivery-102.mimecast.com (de-smtp-delivery-102.mimecast.com [194.104.111.102]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id f3f9961e-c22a-11ec-a405-831a346695d4; Fri, 22 Apr 2022 12:57:08 +0200 (CEST) Received: from EUR05-AM6-obe.outbound.protection.outlook.com (mail-am6eur05lp2112.outbound.protection.outlook.com [104.47.18.112]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id de-mta-10-ibRGHiTZNdG6ENlJzCN1MA-1; Fri, 22 Apr 2022 12:57:05 +0200 Received: from DU2PR04MB8616.eurprd04.prod.outlook.com (2603:10a6:10:2db::16) by VI1PR04MB4800.eurprd04.prod.outlook.com (2603:10a6:803:5a::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5186.15; Fri, 22 Apr 2022 10:57:04 +0000 Received: from DU2PR04MB8616.eurprd04.prod.outlook.com ([fe80::5cb0:5195:4203:7c2f]) by DU2PR04MB8616.eurprd04.prod.outlook.com ([fe80::5cb0:5195:4203:7c2f%7]) with mapi id 15.20.5186.015; Fri, 22 Apr 2022 10:57:04 +0000 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: f3f9961e-c22a-11ec-a405-831a346695d4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=mimecast20200619; t=1650625027; 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; bh=50ko0r9Z9sZripDqhzhdZ+ifhKviRjtt7QFwGCPfRnI=; b=QZn3ofJVaNFdLDJxeI6gggPpk50ZJGikdbz9QFVg40DB+GR9VGeAWfAOb9qFvz2zguzVRY BMhjw5qVFyNx6VMDnElm5VLGc9uxYc+Qql2jzU0c8MlHzh4Vajasp9QLk5TkWlTEQ7ZP6o eX8Tvc/iRYoeh2EjjLEXAMUQ2dkwQUg= X-MC-Unique: ibRGHiTZNdG6ENlJzCN1MA-1 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=VlyRxy/TE+glo6GB9jhSSWjqSj3PCooym3mTQ5X+q/vFGw0esE/v8TYm/t/OOsx8W4kRwY9tyqbb0U6gL47Ne46kk7kpe4SVArJmZQ82u+cWxMEAqycC/eBWgW5E0ogXhyMZVK2voulwdJ5754FYEJCa6ufNrrQjvE/WAdjU4r0714sCDGBx97kQzV1yh1xl6FQSReT3UN8UCSVBXz2IdRDyGP6yGdSrnLPQlyS+tC3be5HM+gA9EbP4OMb94mBhGof7TYsbdUeLhOu+SlQUNBbbc1/TSqUPv9CJn2cQTom29SqJsfPbFAbPu0UmpaoW1LdgdhD6kHC5akBAzgKr+w== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=50ko0r9Z9sZripDqhzhdZ+ifhKviRjtt7QFwGCPfRnI=; b=laYd7pEuTRbNQqr7j09s7Xw5ZIyBuaUYgiE4N79k8XOSiaokVfD3h3uQxAPiWWlgDtZmv/OUW7h3ICfpfYBWHRYYqTy3wFZOGa8D2tNJAtE8mKix6ip0/xCLxX+nl8/sjzISY2lwdy4GuLJQGeCdnf3jhyOuE4PE8XN0GogmALV8Xtoyi/NqWWhje+zRVPWWZZcaST7nflJbOykWBeUDMLE1+JxaFtA/3BLpo/dPPhfo4CgWd38j2PGRptNCoVD33DXmgTA9qcngrMcxPKzGADpoV3iGcfF4lF9rK/M1ZVvBtsP2Tdyq30Nr09U+7SCGkusqS0sQqFU+zu96YmzTKw== 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: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com; Message-ID: Date: Fri, 22 Apr 2022 12:57:03 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.8.1 Content-Language: en-US To: "xen-devel@lists.xenproject.org" Cc: Andrew Cooper , Wei Liu , =?utf-8?q?Roger_Pau_Monn=C3=A9?= , Anthony Perard , Juergen Gross From: Jan Beulich Subject: [PATCH RFC] x86+libxl: correct p2m (shadow) memory pool size calculation X-ClientProxiedBy: AS9PR06CA0080.eurprd06.prod.outlook.com (2603:10a6:20b:464::16) To DU2PR04MB8616.eurprd04.prod.outlook.com (2603:10a6:10:2db::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: db4f3a5c-2c72-42aa-b3fd-08da244ed5de X-MS-TrafficTypeDiagnostic: VI1PR04MB4800:EE_ X-LD-Processed: f7a17af6-1c5c-4a36-aa8b-f5be247aa4ba,ExtFwd X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: wmoOvlnssPZUtov3RyaSG2z1C2HB4sBXyhM8anG9WtXrBzDSNekjwlFF+X7NKaW0gVDhwYt1A8fGr0z9ubFnrqc1rMT9dYTz2YEY+b2ycZa5yRN79DNtVxCVZIBSiaDbNU1wr4sX6VEsL4gHrI+8Aisf4WQ/vbCvKh0zmNuOWVI5XMVFECfLBzuimIZham8f499CQQA+iwgqX46baSp8upoGkZFP8ZiGQdMtLgx/M2YTb704sIBHqNuquGkjI6yYefUwTypP6N+W5IU2u05MiRsrMyZp6RFf8ri5CbvtiRyMsoP3mYsfJ8MnQvzKnUbhSGcWfISPZL9eDkzQjOQGB2iwvlBiTkVIiMjdy+kIR1rMXTddMOTILREPK498bwS14MSQwY68EniLRkf5bUkJp7xe2na74JggzNQFdPdb6Tb6XHX4j8cQis4VedRvwvIYBwATWCfWtzXhM0ivc5aFn1uQ0Q6YKGgl3/X/WfOSR53Y2wWiQ20z6pyWPVAzKHgY63xzA2jdc/+RanI/5GWd2ci61LknfA5puWbdp4sT92abMHVB5nokoHWENZqBjA16HMxKiFvG0+rWSYtud9tx+AYcbG2+DGvOxYe7MUFhKOmOwQdfB+hT3BCg1EwZT6k4/VoEaQJiwggTUSCTyUOUUVYHXmwSTgndqzw4QOAlOOzP0kWyAvFkrnOXXqNO8La+Xz/6R0bHLij59NUElJdF/7wUTDdexdTN2+6J9lQ1BVs= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DU2PR04MB8616.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230001)(366004)(38100700002)(66946007)(6916009)(66476007)(4326008)(8676002)(54906003)(66556008)(316002)(107886003)(508600001)(6486002)(186003)(2616005)(6512007)(26005)(6506007)(8936002)(2906002)(31696002)(36756003)(5660300002)(86362001)(31686004)(43740500002)(45980500001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?04s+IP9+5XfjXVlVfwjN2pW2Wb2E?= =?utf-8?q?+wf1yYEVfVl0bSXFMYUuPVXDDptZU6kmNlxBaMDTfL1qZFener2G2Z491Bb0jLMe9?= =?utf-8?q?xbgnI8IQ9r7rLNQTnjGay9YrBvcDCAnCs/IAwwgFPAyEXr4YPSLNC00hCIqmuKxIA?= =?utf-8?q?AZQzluab5caDUVfEr3CNBe7eWbQIhtoMxeRhZsu/v/oF31Vg8NkNsVPZ8u7PqFFNP?= =?utf-8?q?eJ1jA2IrzHY+WqYuyGC3/R1TfimBPgtb1hVwJoZDT9B8wywRZQWiCYopLS6VOkXx0?= =?utf-8?q?ISAFQy5phW27SjqoQNzZ7SFuthlR3Ijbnl8J/bhfNlLvhVeohTfPYMklPuo2q/dh2?= =?utf-8?q?ANzK27L5hYabtkpKUNAzDLsxGtOM1kUZ0dPxmdeXt3r9OBOdyW9/WI/i3l7gKJAj5?= =?utf-8?q?WMxJUowYs6F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EtyTC8L3JLfc42t3w0Ws48BEP+ilLyIpOhL6q+aRloZXJpWOr7NU?= =?utf-8?q?WddRasGHOE2wrmF71Va5txadF2LcCcY1+idMo9gk/Dhp0LTm52mXzGT4OGTu3DurL?= =?utf-8?q?F3WlQk1iXz54NO7MJgIHNwYKWi50Ep15L4jLmQSRu+texHlK6PSai+tboZeqAt1i+?= =?utf-8?q?QALV+Ejn6vq7YTWdZApOh/Y7opqoR1VFH0ozZFgdQlb8fNEG7DziATvHG+2bHhUCG?= =?utf-8?q?SLQya9Q8Aq5hCFi9DPzegpWlZb7hQyFf6wdMykezZholAPB29nP9yTi8YyThFxCi3?= =?utf-8?q?2aHOsy8xm4N/RuoVgwCiVo+MQQ0GjFJZvB65/t1w9qUmthCa+dOVFx/O99pFrHnrJ?= =?utf-8?q?fprdkUMEHTdgq6B/XcsXJe9nMWnMPoVQ=3D=3D?= X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: db4f3a5c-2c72-42aa-b3fd-08da244ed5de X-MS-Exchange-CrossTenant-AuthSource: DU2PR04MB8616.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Apr 2022 10:57:04.1631 (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: grPqT5vbvhrVzBYCdRTODahmIUphew7ycZ4DoU1tWP1nkSgiVKPkUsxO9VoAQ44WChYXgH8Gci9y8Bp57H0Udg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR04MB4800 The reference "to shadow the resident processes" is applicable to domains (potentially) running in shadow mode only. Adjust the calculations accordingly. In dom0_paging_pages() also take the opportunity and stop open-coding DIV_ROUND_UP(). Signed-off-by: Jan Beulich --- RFC: I'm pretty sure I can't change a public libxl function (deprecated or not) like this, but I also don't know how I should go about doing so (short of introducing a brand new function and leaving the existing one broken). --- a/tools/include/libxl_utils.h +++ b/tools/include/libxl_utils.h @@ -23,7 +23,10 @@ const #endif char *libxl_basename(const char *name); /* returns string from strdup */ -unsigned long libxl_get_required_shadow_memory(unsigned long maxmem_kb, unsigned int smp_cpus); +unsigned long libxl_get_required_shadow_memory(unsigned long maxmem_kb, + unsigned int smp_cpus, + libxl_domain_type type, + bool hap); /* deprecated; see LIBXL_HAVE_DOMAIN_NEED_MEMORY_CONFIG in libxl.h */ int libxl_name_to_domid(libxl_ctx *ctx, const char *name, uint32_t *domid); int libxl_domain_qualifier_to_domid(libxl_ctx *ctx, const char *name, uint32_t *domid); --- a/tools/libs/light/libxl_create.c +++ b/tools/libs/light/libxl_create.c @@ -1194,10 +1194,17 @@ int libxl__domain_config_setdefault(libx } if (d_config->b_info.shadow_memkb == LIBXL_MEMKB_DEFAULT - && ok_to_default_memkb_in_create(gc)) + && ok_to_default_memkb_in_create(gc)) { + bool hap = d_config->c_info.type != LIBXL_DOMAIN_TYPE_PV + ? libxl_defbool_val(d_config->c_info.hap) + : false; + d_config->b_info.shadow_memkb = libxl_get_required_shadow_memory(d_config->b_info.max_memkb, - d_config->b_info.max_vcpus); + d_config->b_info.max_vcpus, + d_config->c_info.type, + hap); + } /* No IOMMU reservation is needed if passthrough mode is not 'sync_pt' */ if (d_config->b_info.iommu_memkb == LIBXL_MEMKB_DEFAULT --- a/tools/libs/light/libxl_utils.c +++ b/tools/libs/light/libxl_utils.c @@ -36,15 +36,21 @@ char *libxl_basename(const char *name) return strdup(name); } -unsigned long libxl_get_required_shadow_memory(unsigned long maxmem_kb, unsigned int smp_cpus) +unsigned long libxl_get_required_shadow_memory(unsigned long maxmem_kb, + unsigned int smp_cpus, + libxl_domain_type type, + bool hap) { /* 256 pages (1MB) per vcpu, - plus 1 page per MiB of RAM for the P2M map, - plus 1 page per MiB of RAM to shadow the resident processes. + plus 1 page per MiB of RAM for the P2M map (for non-PV guests), + plus 1 page per MiB of RAM to shadow the resident processes (for shadow + mode guests). This is higher than the minimum that Xen would allocate if no value were given (but the Xen minimum is for safety, not performance). */ - return 4 * (256 * smp_cpus + 2 * (maxmem_kb / 1024)); + return 4 * (256 * smp_cpus + + ((type != LIBXL_DOMAIN_TYPE_PV) + !hap) * + (maxmem_kb / 1024)); } char *libxl_domid_to_name(libxl_ctx *ctx, uint32_t domid) --- a/xen/arch/x86/dom0_build.c +++ b/xen/arch/x86/dom0_build.c @@ -317,9 +317,12 @@ unsigned long __init dom0_paging_pages(c /* Copied from: libxl_get_required_shadow_memory() */ unsigned long memkb = nr_pages * (PAGE_SIZE / 1024); - memkb = 4 * (256 * d->max_vcpus + 2 * (memkb / 1024)); + memkb = 4 * (256 * d->max_vcpus + + (paging_mode_enabled(d) + + (opt_dom0_shadow || opt_pv_l1tf_hwdom)) * + (memkb / 1024)); - return ((memkb + 1023) / 1024) << (20 - PAGE_SHIFT); + return DIV_ROUND_UP(memkb, 1024) << (20 - PAGE_SHIFT); }