From patchwork Fri Dec 15 14:18:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Roger_Pau_Monn=C3=A9?= X-Patchwork-Id: 13494519 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 A5736C46CA2 for ; Fri, 15 Dec 2023 14:19:54 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.655132.1022834 (Exim 4.92) (envelope-from ) id 1rE92Y-0007Ny-AZ; Fri, 15 Dec 2023 14:19:46 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 655132.1022834; Fri, 15 Dec 2023 14:19:46 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rE92Y-0007Mq-4w; Fri, 15 Dec 2023 14:19:46 +0000 Received: by outflank-mailman (input) for mailman id 655132; Fri, 15 Dec 2023 14:19:44 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rE92W-0007Jp-Qd for xen-devel@lists.xenproject.org; Fri, 15 Dec 2023 14:19:44 +0000 Received: from mail-wm1-x32e.google.com (mail-wm1-x32e.google.com [2a00:1450:4864:20::32e]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id dea13028-9b54-11ee-9b0f-b553b5be7939; Fri, 15 Dec 2023 15:18:51 +0100 (CET) Received: by mail-wm1-x32e.google.com with SMTP id 5b1f17b1804b1-40c2308faedso8281565e9.1 for ; Fri, 15 Dec 2023 06:18:51 -0800 (PST) Received: from localhost ([213.195.127.70]) by smtp.gmail.com with ESMTPSA id jb4-20020a05600c54e400b0040c5cf930e6sm10304507wmb.19.2023.12.15.06.18.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Dec 2023 06:18:50 -0800 (PST) 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: dea13028-9b54-11ee-9b0f-b553b5be7939 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.com; s=google; t=1702649930; x=1703254730; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=micbYiHo1/eCgvDXtChxHAYytkH71LDeDIW7HuEr1a4=; b=gHuIKTHMNPbo5fam2PXpRNXWTVdFAxLaQAfa95l5BshF7aMQIMVY58N3g2CTed6ABD lw6v+EOu7nOOq4uwdXCcS/tHTTUfwDEmtH3a4Pcd1CKvn/oLXf9s2KhQYYmywPvCD2sb kml/WhEBQN9S1uaXWRNYEo+c2Mzg9wQPVDi5I= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702649930; x=1703254730; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=micbYiHo1/eCgvDXtChxHAYytkH71LDeDIW7HuEr1a4=; b=vJgHS0V0bDqop2Q1dHFWTosuraE92p/c9d91Dp80KoU534VxZ+0ZuBGhz0MFivl1kR P6tQqhXr11zxNByQ+7gshWaPtSha6BMTcAjpPz/Y6gs0JHJg/409W4YDtGEzB6rMp5Dw UMwhnVTWkMrTkW/7fWBfpGvE4/JZssoGiXX8cQbAj1dbBQwp6MoyhPFBX4NhGIWMwIfO pcHnxPZDjBBB/eO9vrOSqpI0F+2FJw8DgE76otegfDJ5Lx77LGYr1c6pXDBjMPO+6hfW 7jvyQ2Ctcpz7VpQoyjhrR4F5B/IgfFiKO7NzPTU2YCsBm0g6fnH1hP1RwEPqmLfS6y7R ErLQ== X-Gm-Message-State: AOJu0Ywh4B5yJZY9rcEKrmgFMhejVNQvHhQo6R99NrHlFgdajcUpK7u5 ukWlg+oWMTve4TmykgedpJwUMQiisgxsx4Crm14= X-Google-Smtp-Source: AGHT+IGWmSEZYLoT7xDKGoqko8aP4/fZXUAfOWv+AmUwoE7mtuX1+6GMblkV4W+DGOpW3sm4PuQ7QQ== X-Received: by 2002:a05:600c:1c05:b0:40c:3856:5e07 with SMTP id j5-20020a05600c1c0500b0040c38565e07mr6063639wms.9.1702649930379; Fri, 15 Dec 2023 06:18:50 -0800 (PST) From: Roger Pau Monne To: xen-devel@lists.xenproject.org Cc: Roger Pau Monne , Kevin Tian , Jan Beulich Subject: [PATCH v3 1/7] iommu/vt-d: do not assume page table levels for quarantine domain Date: Fri, 15 Dec 2023 15:18:26 +0100 Message-ID: <20231215141832.9492-2-roger.pau@citrix.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231215141832.9492-1-roger.pau@citrix.com> References: <20231215141832.9492-1-roger.pau@citrix.com> MIME-Version: 1.0 Like XSA-445, do not assume IOMMU page table levels on VT-d are always set based on DEFAULT_DOMAIN_ADDRESS_WIDTH and instead fetch the value set by intel_iommu_domain_init() from the domain iommu structure. This prevents changes to intel_iommu_domain_init() possibly getting the levels out of sync with what intel_iommu_quarantine_init() expects. No functional change, since on Intel domains are hardcoded to use DEFAULT_DOMAIN_ADDRESS_WIDTH. Signed-off-by: Roger Pau Monné Reviewed-by: Jan Beulich --- Changes since v1: - New in this version. --- xen/drivers/passthrough/vtd/iommu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xen/drivers/passthrough/vtd/iommu.c b/xen/drivers/passthrough/vtd/iommu.c index e13b7d99db40..bc6181c9f911 100644 --- a/xen/drivers/passthrough/vtd/iommu.c +++ b/xen/drivers/passthrough/vtd/iommu.c @@ -3162,7 +3162,7 @@ static int cf_check intel_iommu_quarantine_init(struct pci_dev *pdev, { struct domain_iommu *hd = dom_iommu(dom_io); struct page_info *pg; - unsigned int agaw = width_to_agaw(DEFAULT_DOMAIN_ADDRESS_WIDTH); + unsigned int agaw = hd->arch.vtd.agaw; unsigned int level = agaw_to_level(agaw); const struct acpi_drhd_unit *drhd; const struct acpi_rmrr_unit *rmrr; From patchwork Fri Dec 15 14:18:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Roger_Pau_Monn=C3=A9?= X-Patchwork-Id: 13494522 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 C0716C46CD4 for ; Fri, 15 Dec 2023 14:19:58 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.655136.1022880 (Exim 4.92) (envelope-from ) id 1rE92b-000092-Sm; Fri, 15 Dec 2023 14:19:49 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 655136.1022880; Fri, 15 Dec 2023 14:19:49 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rE92b-00006o-Mo; Fri, 15 Dec 2023 14:19:49 +0000 Received: by outflank-mailman (input) for mailman id 655136; Fri, 15 Dec 2023 14:19:48 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rE92a-0007Jp-7Z for xen-devel@lists.xenproject.org; Fri, 15 Dec 2023 14:19:48 +0000 Received: from mail-wm1-x333.google.com (mail-wm1-x333.google.com [2a00:1450:4864:20::333]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id df8f4edd-9b54-11ee-9b0f-b553b5be7939; Fri, 15 Dec 2023 15:18:52 +0100 (CET) Received: by mail-wm1-x333.google.com with SMTP id 5b1f17b1804b1-40c236624edso7547545e9.1 for ; Fri, 15 Dec 2023 06:18:52 -0800 (PST) Received: from localhost ([213.195.127.70]) by smtp.gmail.com with ESMTPSA id k20-20020a5d5254000000b003365b5df349sm190650wrc.93.2023.12.15.06.18.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Dec 2023 06:18:51 -0800 (PST) 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: df8f4edd-9b54-11ee-9b0f-b553b5be7939 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.com; s=google; t=1702649931; x=1703254731; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=i40rODJO/X0LXQNlEUFaGjc3uP8fUKGEa0LahLnFqZ4=; b=OwkYD66IIPftCSkkiC1fwKj9Pgye/tPEMWK4sQx6dsS6e6DR00aNHXEanAIiOh+J+y piI5fQ3icHQREdTygqb/LQKQ7LQW8bcuzIHnPyAyK1Me1WjBh8ws1uuwNc4uY4w1yiRN MCLO460EiIwYS67XG6kl8Qmzr5FkJ3ohQ5I4s= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702649931; x=1703254731; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=i40rODJO/X0LXQNlEUFaGjc3uP8fUKGEa0LahLnFqZ4=; b=hr+nvWUMZM6Pn1a6xEQIvssbyasAgj/qHNnl5GcLtX+pd8WCftF4imDeWlr+u5FRnm j/F9U5cI/RRIRtCanAP7r9CGlTRkBMi7v2Ry//jLaDTXcHa93lkT0IWuqreGE3NHzuCx X0MZrl1kAU1aWdiKSDod3l9jdm/xwNoixpIYYdKx1/yJibSmizgO7d7k1YMvQe5HJd6w 8cvhiBqu07lIVLLT2/gJlyiiDDrE4uI/pZO/nxCsZyez7gVOn3XJnKBvN9aiLox6DTJ1 tuzHUsRV5tFi1M36AAeCOk/gx+/JvAQWvXREiXAMCQrkAa0LGH/koK2RUpM9w1e8kejp xidw== X-Gm-Message-State: AOJu0Yz0ixUG1Rx26OwG4rB0YTTwwSLzEwP057qRp4GUvEvjGjE0wcsW JY/fUsSBevrGAJx8IJwB61kO+qafPn4SskPmWlU= X-Google-Smtp-Source: AGHT+IHolaIVqpjYAMNLgKYfrrXCOS+fc4hUrxfSN2XF9Ny4iN8pmO3vuABTOUeCM7ux/KAzFMr1uw== X-Received: by 2002:a05:600c:6cf:b0:40c:5777:da1a with SMTP id b15-20020a05600c06cf00b0040c5777da1amr2998869wmn.113.1702649931612; Fri, 15 Dec 2023 06:18:51 -0800 (PST) From: Roger Pau Monne To: xen-devel@lists.xenproject.org Cc: Roger Pau Monne , Jan Beulich , Andrew Cooper , Wei Liu Subject: [PATCH v3 2/7] x86/p2m: move and rename paging_max_paddr_bits() Date: Fri, 15 Dec 2023 15:18:27 +0100 Message-ID: <20231215141832.9492-3-roger.pau@citrix.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231215141832.9492-1-roger.pau@citrix.com> References: <20231215141832.9492-1-roger.pau@citrix.com> MIME-Version: 1.0 The function also supports non-paging domains, and hence it being placed in p2m.h and named with the paging_ prefix is misleading. Move to x86 domain.c and rename to domain_max_paddr_bits(). Moving to a different header is non trivial, as the function depends on helpers declared in p2m.h. There's no performance reason for the function being inline. No functional change intended. Signed-off-by: Roger Pau Monné Reviewed-by: Jan Beulich --- Changes since v2: - New in this version. --- xen/arch/x86/cpu-policy.c | 2 +- xen/arch/x86/domain.c | 21 +++++++++++++++++++++ xen/arch/x86/include/asm/domain.h | 3 +++ xen/arch/x86/include/asm/paging.h | 22 ---------------------- 4 files changed, 25 insertions(+), 23 deletions(-) diff --git a/xen/arch/x86/cpu-policy.c b/xen/arch/x86/cpu-policy.c index 423932bc13d6..76efb050edf7 100644 --- a/xen/arch/x86/cpu-policy.c +++ b/xen/arch/x86/cpu-policy.c @@ -864,7 +864,7 @@ void recalculate_cpuid_policy(struct domain *d) p->extd.maxphysaddr = min(p->extd.maxphysaddr, max->extd.maxphysaddr); p->extd.maxphysaddr = min_t(uint8_t, p->extd.maxphysaddr, - paging_max_paddr_bits(d)); + domain_max_paddr_bits(d)); p->extd.maxphysaddr = max_t(uint8_t, p->extd.maxphysaddr, (p->basic.pae || p->basic.pse36) ? 36 : 32); diff --git a/xen/arch/x86/domain.c b/xen/arch/x86/domain.c index 3712e36df930..8a31d18f6967 100644 --- a/xen/arch/x86/domain.c +++ b/xen/arch/x86/domain.c @@ -2552,6 +2552,27 @@ static int __init cf_check init_vcpu_kick_softirq(void) } __initcall(init_vcpu_kick_softirq); +unsigned int domain_max_paddr_bits(const struct domain *d) +{ + unsigned int bits = paging_mode_hap(d) ? hap_paddr_bits : paddr_bits; + + if ( paging_mode_external(d) ) + { + if ( !IS_ENABLED(CONFIG_BIGMEM) && paging_mode_shadow(d) ) + { + /* Shadowed superpages store GFNs in 32-bit page_info fields. */ + bits = min(bits, 32U + PAGE_SHIFT); + } + else + { + /* Both p2m-ept and p2m-pt only support 4-level page tables. */ + bits = min(bits, 48U); + } + } + + return bits; +} + /* * Local variables: * mode: C diff --git a/xen/arch/x86/include/asm/domain.h b/xen/arch/x86/include/asm/domain.h index 4b6b7ceab1ed..622d22bef255 100644 --- a/xen/arch/x86/include/asm/domain.h +++ b/xen/arch/x86/include/asm/domain.h @@ -777,6 +777,9 @@ static inline void pv_inject_sw_interrupt(unsigned int vector) struct arch_vcpu_io { }; +/* Maxphysaddr supportable by the paging infrastructure. */ +unsigned int domain_max_paddr_bits(const struct domain *d); + #endif /* __ASM_DOMAIN_H__ */ /* diff --git a/xen/arch/x86/include/asm/paging.h b/xen/arch/x86/include/asm/paging.h index 76162a9429ce..8a2a0af40874 100644 --- a/xen/arch/x86/include/asm/paging.h +++ b/xen/arch/x86/include/asm/paging.h @@ -336,28 +336,6 @@ static inline bool gfn_valid(const struct domain *d, gfn_t gfn) return !(gfn_x(gfn) >> (d->arch.cpuid->extd.maxphysaddr - PAGE_SHIFT)); } -/* Maxphysaddr supportable by the paging infrastructure. */ -static always_inline unsigned int paging_max_paddr_bits(const struct domain *d) -{ - unsigned int bits = paging_mode_hap(d) ? hap_paddr_bits : paddr_bits; - - if ( paging_mode_external(d) ) - { - if ( !IS_ENABLED(CONFIG_BIGMEM) && paging_mode_shadow(d) ) - { - /* Shadowed superpages store GFNs in 32-bit page_info fields. */ - bits = min(bits, 32U + PAGE_SHIFT); - } - else - { - /* Both p2m-ept and p2m-pt only support 4-level page tables. */ - bits = min(bits, 48U); - } - } - - return bits; -} - #endif /* XEN_PAGING_H */ /* From patchwork Fri Dec 15 14:18:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Roger_Pau_Monn=C3=A9?= X-Patchwork-Id: 13494525 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 BFD35C46CD7 for ; Fri, 15 Dec 2023 14:20:00 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.655137.1022890 (Exim 4.92) (envelope-from ) id 1rE92d-0000WR-9v; Fri, 15 Dec 2023 14:19:51 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 655137.1022890; Fri, 15 Dec 2023 14:19:51 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rE92d-0000VQ-5m; Fri, 15 Dec 2023 14:19:51 +0000 Received: by outflank-mailman (input) for mailman id 655137; Fri, 15 Dec 2023 14:19:49 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rE92b-0007Jp-7c for xen-devel@lists.xenproject.org; Fri, 15 Dec 2023 14:19:49 +0000 Received: from mail-wm1-x332.google.com (mail-wm1-x332.google.com [2a00:1450:4864:20::332]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id e0166d80-9b54-11ee-9b0f-b553b5be7939; Fri, 15 Dec 2023 15:18:53 +0100 (CET) Received: by mail-wm1-x332.google.com with SMTP id 5b1f17b1804b1-40c2c5a8150so6716615e9.2 for ; Fri, 15 Dec 2023 06:18:53 -0800 (PST) Received: from localhost ([213.195.127.70]) by smtp.gmail.com with ESMTPSA id jb4-20020a05600c54e400b0040c5cf930e6sm10304639wmb.19.2023.12.15.06.18.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Dec 2023 06:18:52 -0800 (PST) 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: e0166d80-9b54-11ee-9b0f-b553b5be7939 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.com; s=google; t=1702649933; x=1703254733; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=FDw1hBjsMh2mJKl/ow003iacu/0pNjCq+t0PtXkwl9g=; b=MA9kWeo8D7n3EFjRQHy72QWjaVBKDBDkyJ8xGyQ02Y/M3Dq5E64UoPpFroWejcvD98 qMFgJ1G8lG9jdN5RS9xnwL9A7XwjbRHbc+hbfWEQWYdcvYwGQTbtktEefHajCejCZuxv YmL+lmOZRo49+Tsoyytqzvopnsdv32S8YPO8Q= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702649933; x=1703254733; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=FDw1hBjsMh2mJKl/ow003iacu/0pNjCq+t0PtXkwl9g=; b=pEXLA/ORfObDc+ZVoAPpXnJ2WLLCom72LjAGqfbHB626XuRbL8x8xvcorbrHzFAL6A Y/QmdsHkRuQv0Z8byHOrFQcodUiU536JPkvqYbCmPHXL+yxazVI4V6F5dofuQ6nI7/9f jtCVah7nY7BsuOk/kjahYIlLv6po60dRuPgvE3Xp1Uhwvwz2TTLgUVUfzkCw5p3weIu0 tkyRG78T9SIEZDdpDDuW4RD0mC6K63e9BnfSBhmzKh48dxAhGf61G/neq9eoO7c4aYUL dfpTfobxzEXDtvqmX/BY6OfIVnTAwbcFruRD/7r2Dbv2Jchej0cbxq1WWeYv5QgaVhMc dIIA== X-Gm-Message-State: AOJu0YxYqty5jJTvK89u1QxROx2/ZJ7N2eNiIK1l5ITxUwf77UYwASKO uI3jBtcAefAZsuI6kWiDPshDql+LLYDx+X6Socw= X-Google-Smtp-Source: AGHT+IEKFd55/ZjZslr+01W7mD8pITw5hJ9VLgKPE1npdtdCJtacXmzMitWqw+BqgZzK1lArug7B/w== X-Received: by 2002:a05:600c:1705:b0:40b:3fc7:c887 with SMTP id c5-20020a05600c170500b0040b3fc7c887mr6586131wmn.20.1702649932808; Fri, 15 Dec 2023 06:18:52 -0800 (PST) From: Roger Pau Monne To: xen-devel@lists.xenproject.org Cc: Roger Pau Monne , Jan Beulich , Andrew Cooper Subject: [PATCH v3 3/7] amd-vi: set IOMMU page table levels based on guest reported paddr width Date: Fri, 15 Dec 2023 15:18:28 +0100 Message-ID: <20231215141832.9492-4-roger.pau@citrix.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231215141832.9492-1-roger.pau@citrix.com> References: <20231215141832.9492-1-roger.pau@citrix.com> MIME-Version: 1.0 However take into account the minimum number of levels required by unity maps when setting the page table levels. The previous setting of the page table levels for PV guests based on the highest RAM address was bogus, as there can be other non-RAM regions past the highest RAM address that need to be mapped, for example device MMIO. For HVM we also take amd_iommu_min_paging_mode into account, however if unity maps require more than 4 levels attempting to add those will currently fail at the p2m level, as 4 levels is the maximum supported. Fixes: 0700c962ac2d ('Add AMD IOMMU support into hypervisor') Signed-off-by: Roger Pau Monné Reviewed-by: Jan Beulich --- Changes since v2: - Use the renamed domain_max_paddr_bits(). Changes since v1: - Use paging_max_paddr_bits() instead of hardcoding DEFAULT_DOMAIN_ADDRESS_WIDTH. --- xen/drivers/passthrough/amd/pci_amd_iommu.c | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/xen/drivers/passthrough/amd/pci_amd_iommu.c b/xen/drivers/passthrough/amd/pci_amd_iommu.c index 6bc73dc21052..cc3e2ccd5ed7 100644 --- a/xen/drivers/passthrough/amd/pci_amd_iommu.c +++ b/xen/drivers/passthrough/amd/pci_amd_iommu.c @@ -359,21 +359,17 @@ int __read_mostly amd_iommu_min_paging_mode = 1; static int cf_check amd_iommu_domain_init(struct domain *d) { struct domain_iommu *hd = dom_iommu(d); + int pglvl = amd_iommu_get_paging_mode( + PFN_DOWN(1UL << domain_max_paddr_bits(d))); + + if ( pglvl < 0 ) + return pglvl; /* - * Choose the number of levels for the IOMMU page tables. - * - PV needs 3 or 4, depending on whether there is RAM (including hotplug - * RAM) above the 512G boundary. - * - HVM could in principle use 3 or 4 depending on how much guest - * physical address space we give it, but this isn't known yet so use 4 - * unilaterally. - * - Unity maps may require an even higher number. + * Choose the number of levels for the IOMMU page tables, taking into + * account unity maps. */ - hd->arch.amd.paging_mode = max(amd_iommu_get_paging_mode( - is_hvm_domain(d) - ? 1UL << (DEFAULT_DOMAIN_ADDRESS_WIDTH - PAGE_SHIFT) - : get_upper_mfn_bound() + 1), - amd_iommu_min_paging_mode); + hd->arch.amd.paging_mode = max(pglvl, amd_iommu_min_paging_mode); return 0; } From patchwork Fri Dec 15 14:18:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Roger_Pau_Monn=C3=A9?= X-Patchwork-Id: 13494521 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 7C5EDC46CD3 for ; Fri, 15 Dec 2023 14:19:58 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.655133.1022841 (Exim 4.92) (envelope-from ) id 1rE92Y-0007UV-N4; Fri, 15 Dec 2023 14:19:46 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 655133.1022841; Fri, 15 Dec 2023 14:19:46 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rE92Y-0007Sz-Ga; Fri, 15 Dec 2023 14:19:46 +0000 Received: by outflank-mailman (input) for mailman id 655133; Fri, 15 Dec 2023 14:19:45 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rE92X-0007Jp-7E for xen-devel@lists.xenproject.org; Fri, 15 Dec 2023 14:19:45 +0000 Received: from mail-wr1-x432.google.com (mail-wr1-x432.google.com [2a00:1450:4864:20::432]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id e0f36918-9b54-11ee-9b0f-b553b5be7939; Fri, 15 Dec 2023 15:18:55 +0100 (CET) Received: by mail-wr1-x432.google.com with SMTP id ffacd0b85a97d-336447100e9so660666f8f.1 for ; Fri, 15 Dec 2023 06:18:55 -0800 (PST) Received: from localhost ([213.195.127.70]) by smtp.gmail.com with ESMTPSA id m11-20020a056000008b00b0033332524235sm18838237wrx.82.2023.12.15.06.18.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Dec 2023 06:18:53 -0800 (PST) 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: e0f36918-9b54-11ee-9b0f-b553b5be7939 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.com; s=google; t=1702649934; x=1703254734; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Oi/OU1B+BD1EA3x0F7BUpdNkno4zp2sbqcsBzG1DxYU=; b=nFDC5G/l+7sldOARFp40VwKOHEcm0cFiA8bzoJMJzjEc6+OKCr2eVtuV9PwX1aN6rk v8gH8FpR4QzpchbWj1/5dtZQqGawAbGFLStCZdZyV9uxijH3WDtZVxLtrcHGGO2I57tP 09rDhNeut/SPPXNtKR1lBdw9sEikmozXgUVnU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702649934; x=1703254734; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Oi/OU1B+BD1EA3x0F7BUpdNkno4zp2sbqcsBzG1DxYU=; b=Qi0RjgvS2HwwS9bZJCjSaIOR4fgXU5ZVHrS2Q3FbmoQIR3X0ZPabZjaaxIpvKVxePu l1VPDEJNlhjEIA8oUTl5yUMO4O9F2AgVBD/LarT42qG4OLUGDJkKG+R3guO3OwQFnxNk deyhgcu4rUpZyF9+EmW+C4bDya/Z/SDkRqBkTCwPysyfFe8jhNjRH4HRbzAGsUnxtXmV jXHIzDNRAmbzspuBKe7yv2PGwrXSGm0bXNxVCKsmheZuqiLuc11L2bvN+vNlgx9Zmem6 8rs0FEbKrZcgFaEo6KLL7DU5EYDghGkh9L1t9fH0o8r7tCQmdfjoYa4xiuq2PqMKY4l+ ig9A== X-Gm-Message-State: AOJu0Yz8OB22eR5zUXfYazHoyLxoQzBpWLNWmexxQRgoe7jNSYa7bP0n +S6PUi0fwRi6P/5+BePx9x2Bbv+3IYEs22ySZOc= X-Google-Smtp-Source: AGHT+IGNAKxLrG4i+x0ulksZxzM5IxMcvmrPVWewI4viXKQy/+N3xsRzrOj4Cn+xThFRixmYztTIsA== X-Received: by 2002:adf:f94a:0:b0:336:2548:2e21 with SMTP id q10-20020adff94a000000b0033625482e21mr3922947wrr.38.1702649934301; Fri, 15 Dec 2023 06:18:54 -0800 (PST) From: Roger Pau Monne To: xen-devel@lists.xenproject.org Cc: Roger Pau Monne , Jan Beulich , Paul Durrant Subject: [PATCH v3 4/7] x86/iommu: introduce a rangeset to perform hwdom IOMMU setup Date: Fri, 15 Dec 2023 15:18:29 +0100 Message-ID: <20231215141832.9492-5-roger.pau@citrix.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231215141832.9492-1-roger.pau@citrix.com> References: <20231215141832.9492-1-roger.pau@citrix.com> MIME-Version: 1.0 This change just introduces the boilerplate code in order to use a rangeset when setting up the hardware domain IOMMU mappings. The rangeset is never populated in this patch, so it's a non-functional change as far as the mappings the domain gets established. Note there will be a change for HVM domains (ie: PVH dom0) when the code introduced here gets used: the p2m mappings will be established using map_mmio_regions() instead of p2m_add_identity_entry(), so that ranges can be mapped with a single function call if possible. Note that the interface of map_mmio_regions() doesn't allow creating read-only mappings, but so far there are no such mappings created for PVH dom0 in arch_iommu_hwdom_init(). Signed-off-by: Roger Pau Monné --- Changes since v2: - Better deal with read-only regions. - Destroy rangeset earlier. - Switch to using map_data.flush_flags. - Reword commit message to clarify the change in behaviour for HVM will only take effect after later changes. Changes since v1: - Split from bigger patch. --- xen/drivers/passthrough/x86/iommu.c | 102 +++++++++++++++++++++++++++- 1 file changed, 101 insertions(+), 1 deletion(-) diff --git a/xen/drivers/passthrough/x86/iommu.c b/xen/drivers/passthrough/x86/iommu.c index 857dccb6a465..ca5e0bca810f 100644 --- a/xen/drivers/passthrough/x86/iommu.c +++ b/xen/drivers/passthrough/x86/iommu.c @@ -370,10 +370,88 @@ static unsigned int __hwdom_init hwdom_iommu_map(const struct domain *d, return perms; } +struct map_data { + struct domain *d; + unsigned int flush_flags; + bool mmio_ro; +}; + +static int __hwdom_init cf_check identity_map(unsigned long s, unsigned long e, + void *data) +{ + struct map_data *info = data; + struct domain *d = info->d; + long rc; + + if ( iommu_verbose ) + printk(XENLOG_INFO " [%010lx, %010lx] R%c\n", + s, e, info->mmio_ro ? 'O' : 'W'); + + if ( paging_mode_translate(d) ) + { + if ( info->mmio_ro ) + { + ASSERT_UNREACHABLE(); + return 0; + } + while ( (rc = map_mmio_regions(d, _gfn(s), e - s + 1, _mfn(s))) > 0 ) + { + s += rc; + process_pending_softirqs(); + } + } + else + { + const unsigned int perms = IOMMUF_readable | IOMMUF_preempt | + (info->mmio_ro ? 0 : IOMMUF_writable); + + /* + * Read-only ranges are only created based on the contents of mmio + * read-only rangeset, and hence need the additional iomem permissions + * check. + */ + while( info->mmio_ro && s <= e && !iomem_access_permitted(d, s, e) ) + { + /* + * Consume a frame per iteration until the reminder is accessible + * or there's nothing left to map. + */ + if ( iomem_access_permitted(d, s, s) ) + { + rc = iommu_map(d, _dfn(s), _mfn(s), 1, perms, + &info->flush_flags); + if ( rc < 0 ) + break; + /* Must map a frame at least, which is what we request for. */ + ASSERT(rc == 1); + process_pending_softirqs(); + } + s++; + } + while ( (rc = iommu_map(d, _dfn(s), _mfn(s), e - s + 1, + perms, &info->flush_flags)) > 0 ) + { + s += rc; + process_pending_softirqs(); + } + } + ASSERT(rc <= 0); + if ( rc ) + printk(XENLOG_WARNING + "IOMMU identity mapping of [%lx, %lx] failed: %ld\n", + s, e, rc); + + /* Ignore errors and attempt to map the remaining regions. */ + return 0; +} + void __hwdom_init arch_iommu_hwdom_init(struct domain *d) { unsigned long i, top, max_pfn, start, count; unsigned int flush_flags = 0, start_perms = 0; + struct rangeset *map; + struct map_data map_data = { .d = d }; + int rc; BUG_ON(!is_hardware_domain(d)); @@ -397,6 +475,10 @@ void __hwdom_init arch_iommu_hwdom_init(struct domain *d) if ( iommu_hwdom_passthrough ) return; + map = rangeset_new(NULL, NULL, 0); + if ( !map ) + panic("IOMMU init: unable to allocate rangeset\n"); + max_pfn = (GB(4) >> PAGE_SHIFT) - 1; top = max(max_pdx, pfn_to_pdx(max_pfn) + 1); @@ -451,8 +533,26 @@ void __hwdom_init arch_iommu_hwdom_init(struct domain *d) goto commit; } + if ( iommu_verbose ) + printk(XENLOG_INFO "%pd: identity mappings for IOMMU:\n", d); + + rc = rangeset_report_ranges(map, 0, ~0UL, identity_map, &map_data); + if ( rc ) + panic("IOMMU unable to create mappings: %d\n", rc); + rangeset_destroy(map); + + if ( is_pv_domain(d) ) + { + map_data.mmio_ro = true; + rc = rangeset_report_ranges(mmio_ro_ranges, 0, ~0UL, identity_map, + &map_data); + if ( rc ) + panic("IOMMU unable to create read-only mappings: %d\n", rc); + } + + map_data.flush_flags |= flush_flags; /* Use if to avoid compiler warning */ - if ( iommu_iotlb_flush_all(d, flush_flags) ) + if ( iommu_iotlb_flush_all(d, map_data.flush_flags) ) return; } From patchwork Fri Dec 15 14:18:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Roger_Pau_Monn=C3=A9?= X-Patchwork-Id: 13494524 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 8DEA6C46CD8 for ; Fri, 15 Dec 2023 14:19:59 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.655134.1022859 (Exim 4.92) (envelope-from ) id 1rE92Z-00080Z-Vz; Fri, 15 Dec 2023 14:19:47 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 655134.1022859; Fri, 15 Dec 2023 14:19:47 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rE92Z-0007zJ-RI; Fri, 15 Dec 2023 14:19:47 +0000 Received: by outflank-mailman (input) for mailman id 655134; Fri, 15 Dec 2023 14:19:46 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rE92Y-0007Jp-7M for xen-devel@lists.xenproject.org; Fri, 15 Dec 2023 14:19:46 +0000 Received: from mail-wm1-x332.google.com (mail-wm1-x332.google.com [2a00:1450:4864:20::332]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id e1f8004f-9b54-11ee-9b0f-b553b5be7939; Fri, 15 Dec 2023 15:18:56 +0100 (CET) Received: by mail-wm1-x332.google.com with SMTP id 5b1f17b1804b1-40c3f68b69aso6816685e9.1 for ; Fri, 15 Dec 2023 06:18:56 -0800 (PST) Received: from localhost ([213.195.127.70]) by smtp.gmail.com with ESMTPSA id az27-20020a05600c601b00b0040c34e763ecsm28577461wmb.44.2023.12.15.06.18.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Dec 2023 06:18:55 -0800 (PST) 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: e1f8004f-9b54-11ee-9b0f-b553b5be7939 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.com; s=google; t=1702649935; x=1703254735; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=414KfQ9OMqT0fBT+K6thqF0nIM6hdKEG00zYxPdik0w=; b=Wn8guxtRaQvyoGYHLkju5wUaDvNjmmYWwaABSUyOxjsqsD4ZoCiVnpECU4SZ45Dhtb afxlKD0xjB1UjYohLW939RTozmc8JkLrfO7I6UZX1AbQF8afmEXUX3PhmLUV8+Qu7UKN 9ipuiO3Rcs7IDeS9GsqFPaqCsazYPhAIGSMI4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702649935; x=1703254735; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=414KfQ9OMqT0fBT+K6thqF0nIM6hdKEG00zYxPdik0w=; b=lfzsfRqMU0SiJ/886P5ZTsqS1fHcGWy30/+9QS19Nubx9RYhS8qpnrWS6aBvjNr9m7 UWPwb9qkSvgGWHHREmehkVKrC4JuV4tNkgk2rqFVTwaso+/HDrm9tEba7rO7xCzOJAC5 zKI3nGdLNL1AhEvlXnergFdE0EOofs+2czK2EmAe84kG7+s6bWlDVzAzqbdmyp1JIbOt U/OiRsQPAoOq6Zi04NV+rv9wJCjqeLm0t5A1/GnWKUpJCTcqHudXJwkdBssJ4Ka0CuIo +Jq5+X+Uzkc4NmcPh33jGVVf54UQjFPb8U/4lA1JEvCEkhA/sYkCXKKOuFc9uoA4TXOq SGTw== X-Gm-Message-State: AOJu0Yxf0MAxfH8sPUDaywr3T+62WcZYnCxh7QcqVOOAdlNdC5DgIn6r ENovyTJSJIUeW/6QI+Gku/XY+G4lA89o9Woll/0= X-Google-Smtp-Source: AGHT+IH7hD0UjG+r2dSu+6dpB/MUorArHBJNnw3LjFfKrbo9+qfGJuZuK7QBI4wpwsIp6QxvAycbtQ== X-Received: by 2002:a05:600c:3556:b0:40c:2d76:d2a8 with SMTP id i22-20020a05600c355600b0040c2d76d2a8mr7455414wmq.7.1702649935600; Fri, 15 Dec 2023 06:18:55 -0800 (PST) From: Roger Pau Monne To: xen-devel@lists.xenproject.org Cc: Roger Pau Monne , Paul Durrant , Jan Beulich , Andrew Cooper , Wei Liu Subject: [PATCH v3 5/7] x86/iommu: remove regions not to be mapped Date: Fri, 15 Dec 2023 15:18:30 +0100 Message-ID: <20231215141832.9492-6-roger.pau@citrix.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231215141832.9492-1-roger.pau@citrix.com> References: <20231215141832.9492-1-roger.pau@citrix.com> MIME-Version: 1.0 Introduce the code to remove regions not to be mapped from the rangeset that will be used to setup the IOMMU page tables for the hardware domain. This change also introduces two new functions: remove_xen_ranges() and vpci_subtract_mmcfg() that copy the logic in xen_in_range() and vpci_is_mmcfg_address() respectively and remove the ranges that would otherwise be intercepted by the original functions. Note that the rangeset is still not populated. Signed-off-by: Roger Pau Monné Reviewed-by: Jan Beulich --- Changes since v1: - Split from bigger patch. --- xen/arch/x86/hvm/io.c | 16 ++++++++ xen/arch/x86/include/asm/hvm/io.h | 3 ++ xen/arch/x86/include/asm/setup.h | 1 + xen/arch/x86/setup.c | 48 ++++++++++++++++++++++ xen/drivers/passthrough/x86/iommu.c | 64 +++++++++++++++++++++++++++++ 5 files changed, 132 insertions(+) diff --git a/xen/arch/x86/hvm/io.c b/xen/arch/x86/hvm/io.c index d75af83ad01f..a42854c52b65 100644 --- a/xen/arch/x86/hvm/io.c +++ b/xen/arch/x86/hvm/io.c @@ -369,6 +369,22 @@ bool vpci_is_mmcfg_address(const struct domain *d, paddr_t addr) return vpci_mmcfg_find(d, addr); } +int __hwdom_init vpci_subtract_mmcfg(const struct domain *d, struct rangeset *r) +{ + const struct hvm_mmcfg *mmcfg; + + list_for_each_entry ( mmcfg, &d->arch.hvm.mmcfg_regions, next ) + { + int rc = rangeset_remove_range(r, PFN_DOWN(mmcfg->addr), + PFN_DOWN(mmcfg->addr + mmcfg->size - 1)); + + if ( rc ) + return rc; + } + + return 0; +} + static unsigned int vpci_mmcfg_decode_addr(const struct hvm_mmcfg *mmcfg, paddr_t addr, pci_sbdf_t *sbdf) { diff --git a/xen/arch/x86/include/asm/hvm/io.h b/xen/arch/x86/include/asm/hvm/io.h index a97731657801..e1e5e6fe7491 100644 --- a/xen/arch/x86/include/asm/hvm/io.h +++ b/xen/arch/x86/include/asm/hvm/io.h @@ -156,6 +156,9 @@ void destroy_vpci_mmcfg(struct domain *d); /* Check if an address is between a MMCFG region for a domain. */ bool vpci_is_mmcfg_address(const struct domain *d, paddr_t addr); +/* Remove MMCFG regions from a given rangeset. */ +int vpci_subtract_mmcfg(const struct domain *d, struct rangeset *r); + #endif /* __ASM_X86_HVM_IO_H__ */ diff --git a/xen/arch/x86/include/asm/setup.h b/xen/arch/x86/include/asm/setup.h index 9a460e4db8f4..cd07d98101d8 100644 --- a/xen/arch/x86/include/asm/setup.h +++ b/xen/arch/x86/include/asm/setup.h @@ -37,6 +37,7 @@ void discard_initial_images(void); void *bootstrap_map(const module_t *mod); int xen_in_range(unsigned long mfn); +int remove_xen_ranges(struct rangeset *r); extern uint8_t kbd_shift_flags; diff --git a/xen/arch/x86/setup.c b/xen/arch/x86/setup.c index 3cba2be0af6c..71fa0b46f181 100644 --- a/xen/arch/x86/setup.c +++ b/xen/arch/x86/setup.c @@ -2136,6 +2136,54 @@ int __hwdom_init xen_in_range(unsigned long mfn) return 0; } +int __hwdom_init remove_xen_ranges(struct rangeset *r) +{ + paddr_t start, end; + int rc; + + /* S3 resume code (and other real mode trampoline code) */ + rc = rangeset_remove_range(r, PFN_DOWN(bootsym_phys(trampoline_start)), + PFN_DOWN(bootsym_phys(trampoline_end))); + if ( rc ) + return rc; + + /* + * This needs to remain in sync with the uses of the same symbols in + * - __start_xen() + * - is_xen_fixed_mfn() + * - tboot_shutdown() + */ + /* hypervisor .text + .rodata */ + rc = rangeset_remove_range(r, PFN_DOWN(__pa(&_stext)), + PFN_DOWN(__pa(&__2M_rodata_end))); + if ( rc ) + return rc; + + /* hypervisor .data + .bss */ + if ( efi_boot_mem_unused(&start, &end) ) + { + ASSERT(__pa(start) >= __pa(&__2M_rwdata_start)); + rc = rangeset_remove_range(r, PFN_DOWN(__pa(&__2M_rwdata_start)), + PFN_DOWN(__pa(start))); + if ( rc ) + return rc; + ASSERT(__pa(end) <= __pa(&__2M_rwdata_end)); + rc = rangeset_remove_range(r, PFN_DOWN(__pa(end)), + PFN_DOWN(__pa(&__2M_rwdata_end))); + if ( rc ) + return rc; + } + else + { + rc = rangeset_remove_range(r, PFN_DOWN(__pa(&__2M_rwdata_start)), + PFN_DOWN(__pa(&__2M_rwdata_end))); + if ( rc ) + return rc; + } + + return 0; +} + static int __hwdom_init cf_check io_bitmap_cb( unsigned long s, unsigned long e, void *ctx) { diff --git a/xen/drivers/passthrough/x86/iommu.c b/xen/drivers/passthrough/x86/iommu.c index ca5e0bca810f..3bc84d1bfb3e 100644 --- a/xen/drivers/passthrough/x86/iommu.c +++ b/xen/drivers/passthrough/x86/iommu.c @@ -370,6 +370,14 @@ static unsigned int __hwdom_init hwdom_iommu_map(const struct domain *d, return perms; } +static int __hwdom_init cf_check map_subtract(unsigned long s, unsigned long e, + void *data) +{ + struct rangeset *map = data; + + return rangeset_remove_range(map, s, e); +} + struct map_data { struct domain *d; unsigned int flush_flags; @@ -533,6 +541,62 @@ void __hwdom_init arch_iommu_hwdom_init(struct domain *d) goto commit; } + /* Remove any areas in-use by Xen. */ + rc = remove_xen_ranges(map); + if ( rc ) + panic("IOMMU failed to remove Xen ranges: %d\n", rc); + + /* Remove any overlap with the Interrupt Address Range. */ + rc = rangeset_remove_range(map, 0xfee00, 0xfeeff); + if ( rc ) + panic("IOMMU failed to remove Interrupt Address Range: %d\n", + rc); + + /* If emulating IO-APIC(s) make sure the base address is unmapped. */ + if ( has_vioapic(d) ) + { + for ( i = 0; i < d->arch.hvm.nr_vioapics; i++ ) + { + rc = rangeset_remove_singleton(map, + PFN_DOWN(domain_vioapic(d, i)->base_address)); + if ( rc ) + panic("IOMMU failed to remove IO-APIC: %d\n", + rc); + } + } + + if ( is_pv_domain(d) ) + { + /* + * Be consistent with CPU mappings: Dom0 is permitted to establish r/o + * ones there (also for e.g. HPET in certain cases), so it should also + * have such established for IOMMUs. Remove any read-only ranges here, + * since ranges in mmio_ro_ranges are already explicitly mapped below + * in read-only mode. + */ + rc = rangeset_report_ranges(mmio_ro_ranges, 0, ~0UL, map_subtract, map); + if ( rc ) + panic("IOMMU failed to remove read-only regions: %d\n", + rc); + } + + if ( has_vpci(d) ) + { + /* + * TODO: runtime added MMCFG regions are not checked to make sure they + * don't overlap with already mapped regions, thus preventing trapping. + */ + rc = vpci_subtract_mmcfg(d, map); + if ( rc ) + panic("IOMMU unable to remove MMCFG areas: %d\n", rc); + } + + /* Remove any regions past the last address addressable by the domain. */ + rc = rangeset_remove_range(map, PFN_DOWN(1UL << domain_max_paddr_bits(d)), + ~0UL); + if ( rc ) + panic("IOMMU unable to remove unaddressable ranges: %d\n", rc); + if ( iommu_verbose ) printk(XENLOG_INFO "%pd: identity mappings for IOMMU:\n", d); From patchwork Fri Dec 15 14:18:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Roger_Pau_Monn=C3=A9?= X-Patchwork-Id: 13494523 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 7B67BC46CD2 for ; Fri, 15 Dec 2023 14:19:59 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.655135.1022867 (Exim 4.92) (envelope-from ) id 1rE92a-00089W-LH; Fri, 15 Dec 2023 14:19:48 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 655135.1022867; Fri, 15 Dec 2023 14:19:48 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rE92a-00087W-Cr; Fri, 15 Dec 2023 14:19:48 +0000 Received: by outflank-mailman (input) for mailman id 655135; Fri, 15 Dec 2023 14:19:47 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rE92Z-0007Jp-7Q for xen-devel@lists.xenproject.org; Fri, 15 Dec 2023 14:19:47 +0000 Received: from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com [2a00:1450:4864:20::42e]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id e2cf4adf-9b54-11ee-9b0f-b553b5be7939; Fri, 15 Dec 2023 15:18:58 +0100 (CET) Received: by mail-wr1-x42e.google.com with SMTP id ffacd0b85a97d-3365424df34so306128f8f.1 for ; Fri, 15 Dec 2023 06:18:58 -0800 (PST) Received: from localhost ([213.195.127.70]) by smtp.gmail.com with ESMTPSA id f6-20020adff446000000b0033657514fcfsm855835wrp.88.2023.12.15.06.18.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Dec 2023 06:18:56 -0800 (PST) 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: e2cf4adf-9b54-11ee-9b0f-b553b5be7939 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.com; s=google; t=1702649937; x=1703254737; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=5lykRqqEdrF/krYjCiZGA6WQAOyP6ulgqiaZTejSNGo=; b=cij/3YMP060wV+SXGsYd0P8ts7rBnTqZv38Ws3VJrq7HHquf5i9M3npzwuPg4vEcu+ Nb926wNvu7HRjYqvPOijzqGanZzUIuaEOHfeOyRuEq7xkPohuLvsttarLfFDlKfw89R+ 2pMAqI0WE0OeyXMYQzGLhubxAg6Yh5SWy1WF4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702649937; x=1703254737; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=5lykRqqEdrF/krYjCiZGA6WQAOyP6ulgqiaZTejSNGo=; b=xSY74aVqk3jRzC0Kolbu8WbXmO2VIQGm76nIVNCInfjCpuzH2bRAqnvE7KdlWw5qOE yojTSvNLfHyzJIjxV8XttejF7pgAYg7Db2ErGEV0KQUve0QYLmA84BFejfhWv7DKfKqE shYjzART0Q1aYcxMPdKyXBULZmDhBrzQ7VpglpdkhuYg4tzejN9BSyWH0XZPcuO/rUhP rFCzuyr31+23mgyATdOeAnTkMD/jOGqWq477UtONs8VizLoQeqsDdZ63Zr8f5HrkczcY pYaJ76ei7+PATedMpoQ/0lPOIWOzwTGIhZV7UDImKpJ9e6q4s4xzkc+Gsy6xPiAtxB8a JJBA== X-Gm-Message-State: AOJu0YzP1RPjjA3AWmnlEEXnQZpfbl21VOeE0uKx1wB/z7r4Q9SjTvnP /t1TQdZqS2vChZFjlzt4nFiSsUDGCkHdMkaOkLs= X-Google-Smtp-Source: AGHT+IGQGsI0lKB1NPkzVppEMIHv2TdUuGosUDtge/cbC0NcVsYiccA3HK76OV2Km7hq4OxXDv5IJw== X-Received: by 2002:adf:e2cc:0:b0:334:b157:f155 with SMTP id d12-20020adfe2cc000000b00334b157f155mr5895378wrj.28.1702649936944; Fri, 15 Dec 2023 06:18:56 -0800 (PST) From: Roger Pau Monne To: xen-devel@lists.xenproject.org Cc: Roger Pau Monne , Jan Beulich , Paul Durrant Subject: [PATCH v3 6/7] x86/iommu: switch hwdom IOMMU to use a rangeset Date: Fri, 15 Dec 2023 15:18:31 +0100 Message-ID: <20231215141832.9492-7-roger.pau@citrix.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231215141832.9492-1-roger.pau@citrix.com> References: <20231215141832.9492-1-roger.pau@citrix.com> MIME-Version: 1.0 The current loop that iterates from 0 to the maximum RAM address in order to setup the IOMMU mappings is highly inefficient, and it will get worse as the amount of RAM increases. It's also not accounting for any reserved regions past the last RAM address. Instead of iterating over memory addresses, iterate over the memory map regions and use a rangeset in order to keep track of which ranges need to be identity mapped in the hardware domain physical address space. On an AMD EPYC 7452 with 512GiB of RAM, the time to execute arch_iommu_hwdom_init() in nanoseconds is: x old + new N Min Max Median Avg Stddev x 5 2.2364154e+10 2.338244e+10 2.2474685e+10 2.2622409e+10 4.2949869e+08 + 5 1025012 1033036 1026188 1028276.2 3623.1194 Difference at 95.0% confidence -2.26214e+10 +/- 4.42931e+08 -99.9955% +/- 9.05152e-05% (Student's t, pooled s = 3.03701e+08) Execution time of arch_iommu_hwdom_init() goes down from ~22s to ~0.001s. Note there's a change for HVM domains (ie: PVH dom0) that get switched to create the p2m mappings using map_mmio_regions() instead of p2m_add_identity_entry(), so that ranges can be mapped with a single function call if possible. Note that the interface of map_mmio_regions() doesn't allow creating read-only mappings, but so far there are no such mappings created for PVH dom0 in arch_iommu_hwdom_init(). No change intended in the resulting mappings that a hardware domain gets. Signed-off-by: Roger Pau Monné Reviewed-by: Jan Beulich --- Changes since v2: - Simplify a bit the logic related to inclusive option, at the cost of making some no-op calls on some cases. Changes since v1: - Split from bigger patch. - Remove unneeded default case. --- xen/drivers/passthrough/x86/iommu.c | 149 ++++++---------------------- 1 file changed, 32 insertions(+), 117 deletions(-) diff --git a/xen/drivers/passthrough/x86/iommu.c b/xen/drivers/passthrough/x86/iommu.c index 3bc84d1bfb3e..67cf9bff1c29 100644 --- a/xen/drivers/passthrough/x86/iommu.c +++ b/xen/drivers/passthrough/x86/iommu.c @@ -300,76 +300,6 @@ void iommu_identity_map_teardown(struct domain *d) } } -static unsigned int __hwdom_init hwdom_iommu_map(const struct domain *d, - unsigned long pfn, - unsigned long max_pfn) -{ - mfn_t mfn = _mfn(pfn); - unsigned int i, type, perms = IOMMUF_readable | IOMMUF_writable; - - /* - * Set up 1:1 mapping for dom0. Default to include only conventional RAM - * areas and let RMRRs include needed reserved regions. When set, the - * inclusive mapping additionally maps in every pfn up to 4GB except those - * that fall in unusable ranges for PV Dom0. - */ - if ( (pfn > max_pfn && !mfn_valid(mfn)) || xen_in_range(pfn) ) - return 0; - - switch ( type = page_get_ram_type(mfn) ) - { - case RAM_TYPE_UNUSABLE: - return 0; - - case RAM_TYPE_CONVENTIONAL: - if ( iommu_hwdom_strict ) - return 0; - break; - - default: - if ( type & RAM_TYPE_RESERVED ) - { - if ( !iommu_hwdom_inclusive && !iommu_hwdom_reserved ) - perms = 0; - } - else if ( is_hvm_domain(d) ) - return 0; - else if ( !iommu_hwdom_inclusive || pfn > max_pfn ) - perms = 0; - } - - /* Check that it doesn't overlap with the Interrupt Address Range. */ - if ( pfn >= 0xfee00 && pfn <= 0xfeeff ) - return 0; - /* ... or the IO-APIC */ - if ( has_vioapic(d) ) - { - for ( i = 0; i < d->arch.hvm.nr_vioapics; i++ ) - if ( pfn == PFN_DOWN(domain_vioapic(d, i)->base_address) ) - return 0; - } - else if ( is_pv_domain(d) ) - { - /* - * Be consistent with CPU mappings: Dom0 is permitted to establish r/o - * ones there (also for e.g. HPET in certain cases), so it should also - * have such established for IOMMUs. - */ - if ( iomem_access_permitted(d, pfn, pfn) && - rangeset_contains_singleton(mmio_ro_ranges, pfn) ) - perms = IOMMUF_readable; - } - /* - * ... or the PCIe MCFG regions. - * TODO: runtime added MMCFG regions are not checked to make sure they - * don't overlap with already mapped regions, thus preventing trapping. - */ - if ( has_vpci(d) && vpci_is_mmcfg_address(d, pfn_to_paddr(pfn)) ) - return 0; - - return perms; -} - static int __hwdom_init cf_check map_subtract(unsigned long s, unsigned long e, void *data) { @@ -455,8 +385,7 @@ static int __hwdom_init cf_check identity_map(unsigned long s, unsigned long e, void __hwdom_init arch_iommu_hwdom_init(struct domain *d) { - unsigned long i, top, max_pfn, start, count; - unsigned int flush_flags = 0, start_perms = 0; + unsigned int i; struct rangeset *map; struct map_data map_data = { .d = d }; int rc; @@ -487,58 +416,45 @@ void __hwdom_init arch_iommu_hwdom_init(struct domain *d) if ( !map ) panic("IOMMU init: unable to allocate rangeset\n"); - max_pfn = (GB(4) >> PAGE_SHIFT) - 1; - top = max(max_pdx, pfn_to_pdx(max_pfn) + 1); + if ( iommu_hwdom_inclusive ) + { + /* Add the whole range below 4GB, UNUSABLE regions will be removed. */ + rc = rangeset_add_range(map, 0, PFN_DOWN(GB(4)) - 1); + if ( rc ) + panic("IOMMU inclusive mappings can't be added: %d\n", + rc); + } - for ( i = 0, start = 0, count = 0; i < top; ) + for ( i = 0; i < e820.nr_map; i++ ) { - unsigned long pfn = pdx_to_pfn(i); - unsigned int perms = hwdom_iommu_map(d, pfn, max_pfn); + const struct e820entry entry = e820.map[i]; - if ( !perms ) - /* nothing */; - else if ( paging_mode_translate(d) ) + switch ( entry.type ) { - int rc; - - rc = p2m_add_identity_entry(d, pfn, - perms & IOMMUF_writable ? p2m_access_rw - : p2m_access_r, - 0); + case E820_UNUSABLE: + /* Only relevant for inclusive mode, otherwise this is a no-op. */ + rc = rangeset_remove_range(map, PFN_DOWN(entry.addr), + PFN_DOWN(entry.addr + entry.size - 1)); if ( rc ) - printk(XENLOG_WARNING - "%pd: identity mapping of %lx failed: %d\n", - d, pfn, rc); - } - else if ( pfn != start + count || perms != start_perms ) - { - long rc; + panic("IOMMU failed to remove unusable memory: %d\n", + rc); + continue; - commit: - while ( (rc = iommu_map(d, _dfn(start), _mfn(start), count, - start_perms | IOMMUF_preempt, - &flush_flags)) > 0 ) - { - start += rc; - count -= rc; - process_pending_softirqs(); - } - if ( rc ) - printk(XENLOG_WARNING - "%pd: IOMMU identity mapping of [%lx,%lx) failed: %ld\n", - d, start, start + count, rc); - start = pfn; - count = 1; - start_perms = perms; - } - else - ++count; + case E820_RESERVED: + if ( !iommu_hwdom_inclusive && !iommu_hwdom_reserved ) + continue; + break; - if ( !(++i & 0xfffff) ) - process_pending_softirqs(); + case E820_RAM: + if ( iommu_hwdom_strict ) + continue; + break; + } - if ( i == top && count ) - goto commit; + rc = rangeset_add_range(map, PFN_DOWN(entry.addr), + PFN_DOWN(entry.addr + entry.size - 1)); + if ( rc ) + panic("IOMMU failed to add identity range: %d\n", rc); } /* Remove any areas in-use by Xen. */ @@ -614,7 +530,6 @@ void __hwdom_init arch_iommu_hwdom_init(struct domain *d) panic("IOMMU unable to create read-only mappings: %d\n", rc); } - map_data.flush_flags |= flush_flags; /* Use if to avoid compiler warning */ if ( iommu_iotlb_flush_all(d, map_data.flush_flags) ) return; From patchwork Fri Dec 15 14:18:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Roger_Pau_Monn=C3=A9?= X-Patchwork-Id: 13494518 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 4671FC41535 for ; Fri, 15 Dec 2023 14:19:20 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.655128.1022820 (Exim 4.92) (envelope-from ) id 1rE91p-0006f5-Jr; Fri, 15 Dec 2023 14:19:01 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 655128.1022820; Fri, 15 Dec 2023 14:19:01 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rE91p-0006ey-G7; Fri, 15 Dec 2023 14:19:01 +0000 Received: by outflank-mailman (input) for mailman id 655128; Fri, 15 Dec 2023 14:19:00 +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 1rE91n-0006es-W5 for xen-devel@lists.xenproject.org; Fri, 15 Dec 2023 14:18:59 +0000 Received: from mail-wm1-x32a.google.com (mail-wm1-x32a.google.com [2a00:1450:4864:20::32a]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id e3510af2-9b54-11ee-98ea-6d05b1d4d9a1; Fri, 15 Dec 2023 15:18:59 +0100 (CET) Received: by mail-wm1-x32a.google.com with SMTP id 5b1f17b1804b1-40c236624edso7548425e9.1 for ; Fri, 15 Dec 2023 06:18:59 -0800 (PST) Received: from localhost ([213.195.127.70]) by smtp.gmail.com with ESMTPSA id p8-20020a05600c468800b0040c488e4fb5sm19266019wmo.40.2023.12.15.06.18.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Dec 2023 06:18:57 -0800 (PST) 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: e3510af2-9b54-11ee-98ea-6d05b1d4d9a1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.com; s=google; t=1702649938; x=1703254738; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=AfxozcO3CAG7eR5+VWkDWdrPK7Br/PqDvBXsKNSGHKo=; b=QeqAM+z6Kt+A5yRh3kV/q5cJiSZyAwU6YwYuTdXlASdrviMXTHImN9Nc1B1gFeXsrR m1ZLgvxQqgXMPQ1t5huvkeWjiQWAVtCIdiq/IFif0IwC94vrfD7pHscuQjAOhG7R2hwS GjrsrUCuZBO2vD92tlWc3dJYs7pnezYy/hy7s= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702649938; x=1703254738; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=AfxozcO3CAG7eR5+VWkDWdrPK7Br/PqDvBXsKNSGHKo=; b=PaYC74MTyhaiqgS0WIDzGR0zFsQ4nfgXDylItjsL5CTF38Rd4ukEQCyrhZ53E33+f2 z7jCQg9wI4yKKQSJWYqZSYeBjiNViauE75LsjSPUwX9H/1WHB/F6cJV7+Cq4Yk88Rh5G +2p95g2+Rw2/RndZD2Tw45C5HsjEe1nExb0IGxtfQZCDQHDimhwWdKBC4IY0+zT99TGi yD+gCzrtNEkch3dubIJdWYZ3v1sQJtVVBMO5A+zxI910AfX9pDHumadxkU4vfA8GyHes M/1wwAWeVxB1buufw6LdFS0OQGHeXVH9uZj7KyTtUubmry9Y9SVVYO3RooIwqtjb6eTm D3Dg== X-Gm-Message-State: AOJu0YzW1S6VD67533KGVxUMNAjYu6DntzF6D8myf4mQxhFVlkZ7v/LL yXYC9zBrgW0POfzYh24CWGZ03M49fqj1wDoEQvI= X-Google-Smtp-Source: AGHT+IHUqRs+AdoriH7td6vOHiqYhpHsTg2itXwsLM+PX2tbjJTgM5u0HqcuKToJoxPHgO5/vzPsOQ== X-Received: by 2002:a05:600c:4f93:b0:40c:6b55:2a0e with SMTP id n19-20020a05600c4f9300b0040c6b552a0emr493672wmq.75.1702649938297; Fri, 15 Dec 2023 06:18:58 -0800 (PST) From: Roger Pau Monne To: xen-devel@lists.xenproject.org Cc: Roger Pau Monne , Paul Durrant , Jan Beulich , Andrew Cooper , Wei Liu , Lukasz Hawrylko , "Daniel P. Smith" , =?utf-8?q?Mateusz_M=C3=B3?= =?utf-8?q?wka?= Subject: [PATCH v3 7/7] x86/iommu: cleanup unused functions Date: Fri, 15 Dec 2023 15:18:32 +0100 Message-ID: <20231215141832.9492-8-roger.pau@citrix.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231215141832.9492-1-roger.pau@citrix.com> References: <20231215141832.9492-1-roger.pau@citrix.com> MIME-Version: 1.0 Remove xen_in_range() and vpci_is_mmcfg_address() now that hey are unused. Adjust comments to point to the new functions that replace the existing ones. No functional change. Signed-off-by: Roger Pau Monné Reviewed-by: Jan Beulich --- Changes since v2: - Do remove vpci_is_mmcfg_address(). --- Can be squashed with the previous patch if desired, split as a separate patch for clarity. --- xen/arch/x86/hvm/io.c | 5 --- xen/arch/x86/include/asm/hvm/io.h | 3 -- xen/arch/x86/include/asm/setup.h | 1 - xen/arch/x86/setup.c | 53 ++----------------------------- xen/arch/x86/tboot.c | 2 +- 5 files changed, 3 insertions(+), 61 deletions(-) diff --git a/xen/arch/x86/hvm/io.c b/xen/arch/x86/hvm/io.c index a42854c52b65..06283b41c463 100644 --- a/xen/arch/x86/hvm/io.c +++ b/xen/arch/x86/hvm/io.c @@ -364,11 +364,6 @@ static const struct hvm_mmcfg *vpci_mmcfg_find(const struct domain *d, return NULL; } -bool vpci_is_mmcfg_address(const struct domain *d, paddr_t addr) -{ - return vpci_mmcfg_find(d, addr); -} - int __hwdom_init vpci_subtract_mmcfg(const struct domain *d, struct rangeset *r) { const struct hvm_mmcfg *mmcfg; diff --git a/xen/arch/x86/include/asm/hvm/io.h b/xen/arch/x86/include/asm/hvm/io.h index e1e5e6fe7491..24d1b6134f02 100644 --- a/xen/arch/x86/include/asm/hvm/io.h +++ b/xen/arch/x86/include/asm/hvm/io.h @@ -153,9 +153,6 @@ int register_vpci_mmcfg_handler(struct domain *d, paddr_t addr, /* Destroy tracked MMCFG areas. */ void destroy_vpci_mmcfg(struct domain *d); -/* Check if an address is between a MMCFG region for a domain. */ -bool vpci_is_mmcfg_address(const struct domain *d, paddr_t addr); - /* Remove MMCFG regions from a given rangeset. */ int vpci_subtract_mmcfg(const struct domain *d, struct rangeset *r); diff --git a/xen/arch/x86/include/asm/setup.h b/xen/arch/x86/include/asm/setup.h index cd07d98101d8..1ced1299c77b 100644 --- a/xen/arch/x86/include/asm/setup.h +++ b/xen/arch/x86/include/asm/setup.h @@ -36,7 +36,6 @@ unsigned long initial_images_nrpages(nodeid_t node); void discard_initial_images(void); void *bootstrap_map(const module_t *mod); -int xen_in_range(unsigned long mfn); int remove_xen_ranges(struct rangeset *r); extern uint8_t kbd_shift_flags; diff --git a/xen/arch/x86/setup.c b/xen/arch/x86/setup.c index 71fa0b46f181..7d2cb61a2a4a 100644 --- a/xen/arch/x86/setup.c +++ b/xen/arch/x86/setup.c @@ -1343,7 +1343,7 @@ void asmlinkage __init noreturn __start_xen(unsigned long mbi_p) relocated = true; /* - * This needs to remain in sync with xen_in_range() and the + * This needs to remain in sync with remove_xen_ranges() and the * respective reserve_e820_ram() invocation below. No need to * query efi_boot_mem_unused() here, though. */ @@ -1495,7 +1495,7 @@ void asmlinkage __init noreturn __start_xen(unsigned long mbi_p) if ( using_2M_mapping() ) efi_boot_mem_unused(NULL, NULL); - /* This needs to remain in sync with xen_in_range(). */ + /* This needs to remain in sync with remove_xen_ranges(). */ if ( efi_boot_mem_unused(&eb_start, &eb_end) ) { reserve_e820_ram(&boot_e820, __pa(_stext), __pa(eb_start)); @@ -2087,55 +2087,6 @@ void arch_get_xen_caps(xen_capabilities_info_t *info) } } -int __hwdom_init xen_in_range(unsigned long mfn) -{ - paddr_t start, end; - int i; - - enum { region_s3, region_ro, region_rw, region_bss, nr_regions }; - static struct { - paddr_t s, e; - } xen_regions[nr_regions] __hwdom_initdata; - - /* initialize first time */ - if ( !xen_regions[0].s ) - { - /* S3 resume code (and other real mode trampoline code) */ - xen_regions[region_s3].s = bootsym_phys(trampoline_start); - xen_regions[region_s3].e = bootsym_phys(trampoline_end); - - /* - * This needs to remain in sync with the uses of the same symbols in - * - __start_xen() (above) - * - is_xen_fixed_mfn() - * - tboot_shutdown() - */ - - /* hypervisor .text + .rodata */ - xen_regions[region_ro].s = __pa(&_stext); - xen_regions[region_ro].e = __pa(&__2M_rodata_end); - /* hypervisor .data + .bss */ - xen_regions[region_rw].s = __pa(&__2M_rwdata_start); - xen_regions[region_rw].e = __pa(&__2M_rwdata_end); - if ( efi_boot_mem_unused(&start, &end) ) - { - ASSERT(__pa(start) >= xen_regions[region_rw].s); - ASSERT(__pa(end) <= xen_regions[region_rw].e); - xen_regions[region_rw].e = __pa(start); - xen_regions[region_bss].s = __pa(end); - xen_regions[region_bss].e = __pa(&__2M_rwdata_end); - } - } - - start = (paddr_t)mfn << PAGE_SHIFT; - end = start + PAGE_SIZE; - for ( i = 0; i < nr_regions; i++ ) - if ( (start < xen_regions[i].e) && (end > xen_regions[i].s) ) - return 1; - - return 0; -} - int __hwdom_init remove_xen_ranges(struct rangeset *r) { paddr_t start, end; diff --git a/xen/arch/x86/tboot.c b/xen/arch/x86/tboot.c index 86c4c22cacb8..4c254b4e34b4 100644 --- a/xen/arch/x86/tboot.c +++ b/xen/arch/x86/tboot.c @@ -321,7 +321,7 @@ void tboot_shutdown(uint32_t shutdown_type) /* * Xen regions for tboot to MAC. This needs to remain in sync with - * xen_in_range(). + * remove_xen_ranges(). */ g_tboot_shared->num_mac_regions = 3; /* S3 resume code (and other real mode trampoline code) */