From patchwork Mon Oct 5 09:49:01 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Durrant X-Patchwork-Id: 11816417 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 19D3592C for ; Mon, 5 Oct 2020 09:50:52 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id D8A8020776 for ; Mon, 5 Oct 2020 09:50:51 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=xen.org header.i=@xen.org header.b="LHvT0/yK" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D8A8020776 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=xen.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from list by lists.xenproject.org with outflank-mailman.2945.8412 (Exim 4.92) (envelope-from ) id 1kPN7K-0000aJ-95; Mon, 05 Oct 2020 09:49:14 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 2945.8412; Mon, 05 Oct 2020 09:49:14 +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" Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kPN7K-0000aC-6A; Mon, 05 Oct 2020 09:49:14 +0000 Received: by outflank-mailman (input) for mailman id 2945; Mon, 05 Oct 2020 09:49:12 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kPN7I-0000a2-9z for xen-devel@lists.xenproject.org; Mon, 05 Oct 2020 09:49:12 +0000 Received: from mail.xenproject.org (unknown [104.130.215.37]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id d5ee281d-a4a4-454e-8da2-b8c551704b45; Mon, 05 Oct 2020 09:49:11 +0000 (UTC) Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kPN7F-00018R-FE; Mon, 05 Oct 2020 09:49:09 +0000 Received: from host109-146-187-185.range109-146.btcentralplus.com ([109.146.187.185] helo=u2f063a87eabd5f.home) by xenbits.xenproject.org with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kPN7F-0007gW-5T; Mon, 05 Oct 2020 09:49:09 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kPN7I-0000a2-9z for xen-devel@lists.xenproject.org; Mon, 05 Oct 2020 09:49:12 +0000 X-Inumbo-ID: d5ee281d-a4a4-454e-8da2-b8c551704b45 Received: from mail.xenproject.org (unknown [104.130.215.37]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id d5ee281d-a4a4-454e-8da2-b8c551704b45; Mon, 05 Oct 2020 09:49:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org; s=20200302mail; h=Content-Transfer-Encoding:MIME-Version:References: In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=JndE2IT1FR1VzwIIZT6xeGdSTmev8bp7YBG/Bt30IPQ=; b=LHvT0/yKr0tJ+uY0azfHrBacfx T6bE7maz3Yo3mUsnUWLpLBpdZo8zOS9ZHmdAHl7kQsCRCxn5DAr60IRnS339n+uMzBKrN6ejqkkpV 4TTPt5FCqCuCR8jUHZ9c5gkaiwd0rQj4rNdkacPLNpoDo33IF77b2PeMVCChiWcHd71c=; Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kPN7F-00018R-FE; Mon, 05 Oct 2020 09:49:09 +0000 Received: from host109-146-187-185.range109-146.btcentralplus.com ([109.146.187.185] helo=u2f063a87eabd5f.home) by xenbits.xenproject.org with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kPN7F-0007gW-5T; Mon, 05 Oct 2020 09:49:09 +0000 From: Paul Durrant To: xen-devel@lists.xenproject.org Cc: Paul Durrant , Ian Jackson , Wei Liu , Anthony PERARD Subject: [PATCH 1/5] libxl: remove separate calculation of IOMMU memory overhead Date: Mon, 5 Oct 2020 10:49:01 +0100 Message-Id: <20201005094905.2929-2-paul@xen.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20201005094905.2929-1-paul@xen.org> References: <20201005094905.2929-1-paul@xen.org> MIME-Version: 1.0 From: Paul Durrant When using 'shared_pt' mode the IOMMU is using the EPT PTEs. In 'sync_pt' mode these PTEs are instead replicated for the IOMMU to use. Hence, it is fairly clear that the memory overhead in this mode is essentially another copy of the P2M. This patch removes the independent calculation done in libxl__get_required_iommu_memory() and instead simply uses 'shadow_memkb' as the value of the IOMMU overhead since this is the estimated size of the P2M. Signed-off-by: Paul Durrant Acked-by: Wei Liu --- Cc: Ian Jackson Cc: Wei Liu Cc: Anthony PERARD --- tools/libs/light/libxl_create.c | 22 +++++----------------- 1 file changed, 5 insertions(+), 17 deletions(-) diff --git a/tools/libs/light/libxl_create.c b/tools/libs/light/libxl_create.c index 9a6e92b3a5..f07ba84850 100644 --- a/tools/libs/light/libxl_create.c +++ b/tools/libs/light/libxl_create.c @@ -1001,21 +1001,6 @@ static bool ok_to_default_memkb_in_create(libxl__gc *gc) */ } -static unsigned long libxl__get_required_iommu_memory(unsigned long maxmem_kb) -{ - unsigned long iommu_pages = 0, mem_pages = maxmem_kb / 4; - unsigned int level; - - /* Assume a 4 level page table with 512 entries per level */ - for (level = 0; level < 4; level++) - { - mem_pages = DIV_ROUNDUP(mem_pages, 512); - iommu_pages += mem_pages; - } - - return iommu_pages * 4; -} - int libxl__domain_config_setdefault(libxl__gc *gc, libxl_domain_config *d_config, uint32_t domid /* for logging, only */) @@ -1168,12 +1153,15 @@ int libxl__domain_config_setdefault(libxl__gc *gc, libxl_get_required_shadow_memory(d_config->b_info.max_memkb, d_config->b_info.max_vcpus); - /* No IOMMU reservation is needed if passthrough mode is not 'sync_pt' */ + /* No IOMMU reservation is needed if passthrough mode is not 'sync_pt' + * otherwise we need a reservation sufficient to accommodate a copy of + * the P2M. + */ if (d_config->b_info.iommu_memkb == LIBXL_MEMKB_DEFAULT && ok_to_default_memkb_in_create(gc)) d_config->b_info.iommu_memkb = (d_config->c_info.passthrough == LIBXL_PASSTHROUGH_SYNC_PT) - ? libxl__get_required_iommu_memory(d_config->b_info.max_memkb) + ? d_config->b_info.shadow_memkb : 0; ret = libxl__domain_build_info_setdefault(gc, &d_config->b_info);