From nobody Sun May 19 01:26:50 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; dmarc=pass(p=reject dis=none) header.from=citrix.com ARC-Seal: i=1; a=rsa-sha256; t=1703079878; cv=none; d=zohomail.com; s=zohoarc; b=XqeUut2Wuz7leNMtZcn9MPcPts0h/Z8IA2HfcWsK9XK3aARtv/CJnwi1Ar7M0RVopmcLLGZgbjGONI5bwA3T++UaueK3F4eFNTFOtx35KGNpY0KQlDqesfUotgPe2pmgi/N5sHrUYJlksYQ4iEQRRUTlry3W2Tdb0xyR2tw1J5g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1703079878; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=Zpl/pvdAy8I8bWYC4wJLs2ijp/eL3QlGcKk+qyRQerA=; b=KcZ66yeEpHklL7DIMDVku9YVi+N2VlQkwW8kxWANxVL1yTsG+8FdZ+oEXgHA1tgaN8SSISIgfijRBen+3ojvIXzA9IKmHtpt+Zm+/HP385TNsxGsZR/xD+bQ1AsOFJBQ968ldGlji047/R0f7FvnY8gbwxRdAjLgdj4r9XHf17U= ARC-Authentication-Results: i=1; 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; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1703079878088479.46603086464586; Wed, 20 Dec 2023 05:44:38 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.657803.1026911 (Exim 4.92) (envelope-from ) id 1rFws1-0003WF-QT; Wed, 20 Dec 2023 13:44:21 +0000 Received: by outflank-mailman (output) from mailman id 657803.1026911; Wed, 20 Dec 2023 13:44:21 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rFws1-0003W8-Ng; Wed, 20 Dec 2023 13:44:21 +0000 Received: by outflank-mailman (input) for mailman id 657803; Wed, 20 Dec 2023 13:44:20 +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 1rFws0-0003Gg-41 for xen-devel@lists.xenproject.org; Wed, 20 Dec 2023 13:44:20 +0000 Received: from mail-wm1-x332.google.com (mail-wm1-x332.google.com [2a00:1450:4864:20::332]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id dff00579-9f3d-11ee-98eb-6d05b1d4d9a1; Wed, 20 Dec 2023 14:44:19 +0100 (CET) Received: by mail-wm1-x332.google.com with SMTP id 5b1f17b1804b1-40c3f68b69aso52860885e9.1 for ; Wed, 20 Dec 2023 05:44:19 -0800 (PST) Received: from localhost ([213.195.127.70]) by smtp.gmail.com with ESMTPSA id j7-20020a05600c190700b0040c31bb66dcsm7358017wmq.20.2023.12.20.05.44.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Dec 2023 05:44:18 -0800 (PST) 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: dff00579-9f3d-11ee-98eb-6d05b1d4d9a1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.com; s=google; t=1703079859; x=1703684659; 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=Zpl/pvdAy8I8bWYC4wJLs2ijp/eL3QlGcKk+qyRQerA=; b=kDQlau0wZiiBYgVozWyESQ92D6TBhtDU8WSUeJI0QMfPNJEb7IMSN3HUmdwkBwIU+U SkeyR1Jermk4WppxRFWJDESdXbUFUs1jr1qLRaV+xcJ/OKf9c/p4zNGe5gkccZ5nB/Nw hd8JaSnPDtRbnidsPOVAtesmKze87YrXkqeJY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703079859; x=1703684659; 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=Zpl/pvdAy8I8bWYC4wJLs2ijp/eL3QlGcKk+qyRQerA=; b=n2Ax0z5gvdwBlTjUR8TSu8JIRcwAgnRpkjpy6ywLM8iXZFATOYzmPKuC8kMwi0818w 47PTkVaTd3u18wMvWaZ05T3RUIB4p/i67o1ID4a9xGN59fQtXTYIUlfIv5DlUl147T1u +J1rm3U2M1TLC+1PC0C3/cS0quJLOTvDs9E8o3fzd1dqcHawbRnnUNbrKEdMm09kZ2pG jyD/aSX+n9OWh6pm6bwRVFVAS8avv8CrV3D+XHoz4EnG+3aXb9bKUnBCOYhjxaypbZLH 47KRjlmxkQxhY7vD3e6k+CTOouaPAskXvuZC3DQLqDUwpnrqjmJ7taxC32qbzDOShdpq SfbQ== X-Gm-Message-State: AOJu0YznZtIDAveDsfyzbNCxkpIddksl1bv3UZaOoTPzHVg1Frj06IB9 P9+dAmMTFMR68uPw8N/JFvj2daf8czZGEwVXmno= X-Google-Smtp-Source: AGHT+IGaL4PDOlk862SoqaXg6gAIMGnT4q/dB5L8eKzSmHI0ZJOyu/L0M49PPpwy3+Z2dV1dCBMSHw== X-Received: by 2002:a05:600c:3411:b0:409:79df:7f9c with SMTP id y17-20020a05600c341100b0040979df7f9cmr13537926wmp.36.1703079858702; Wed, 20 Dec 2023 05:44:18 -0800 (PST) From: Roger Pau Monne To: xen-devel@lists.xenproject.org Cc: Roger Pau Monne , Jan Beulich , Andrew Cooper , Wei Liu Subject: [PATCH v4 1/6] x86/p2m: move and rename paging_max_paddr_bits() Date: Wed, 20 Dec 2023 14:43:41 +0100 Message-ID: <20231220134346.22430-2-roger.pau@citrix.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231220134346.22430-1-roger.pau@citrix.com> References: <20231220134346.22430-1-roger.pau@citrix.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @citrix.com) X-ZM-MESSAGEID: 1703079879849100003 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 declare= d in p2m.h. There's no performance reason for the function being inline. Note the function is safe to use against PV or system domains, as it does c= heck whether the domain is using external paging, and if not the returned physic= al address width is the host (native) value. No functional change intended. Signed-off-by: Roger Pau Monn=C3=A9 Reviewed-by: Jan Beulich --- Changes since v3: - Expand changelog. 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) =20 p->extd.maxphysaddr =3D min(p->extd.maxphysaddr, max->extd.maxphysaddr= ); p->extd.maxphysaddr =3D min_t(uint8_t, p->extd.maxphysaddr, - paging_max_paddr_bits(d)); + domain_max_paddr_bits(d)); p->extd.maxphysaddr =3D max_t(uint8_t, p->extd.maxphysaddr, (p->basic.pae || p->basic.pse36) ? 36 : 32= ); =20 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(vo= id) } __initcall(init_vcpu_kick_softirq); =20 +unsigned int domain_max_paddr_bits(const struct domain *d) +{ + unsigned int bits =3D 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 =3D min(bits, 32U + PAGE_SHIFT); + } + else + { + /* Both p2m-ept and p2m-pt only support 4-level page tables. */ + bits =3D 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/d= omain.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 { }; =20 +/* Maxphysaddr supportable by the paging infrastructure. */ +unsigned int domain_max_paddr_bits(const struct domain *d); + #endif /* __ASM_DOMAIN_H__ */ =20 /* diff --git a/xen/arch/x86/include/asm/paging.h b/xen/arch/x86/include/asm/p= aging.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, g= fn_t gfn) return !(gfn_x(gfn) >> (d->arch.cpuid->extd.maxphysaddr - PAGE_SHIFT)); } =20 -/* Maxphysaddr supportable by the paging infrastructure. */ -static always_inline unsigned int paging_max_paddr_bits(const struct domai= n *d) -{ - unsigned int bits =3D 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 =3D min(bits, 32U + PAGE_SHIFT); - } - else - { - /* Both p2m-ept and p2m-pt only support 4-level page tables. */ - bits =3D min(bits, 48U); - } - } - - return bits; -} - #endif /* XEN_PAGING_H */ =20 /* --=20 2.43.0 From nobody Sun May 19 01:26:50 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; dmarc=pass(p=reject dis=none) header.from=citrix.com ARC-Seal: i=1; a=rsa-sha256; t=1703079880; cv=none; d=zohomail.com; s=zohoarc; b=UMYoe3mvr/hX/WokAy33vh9zifTXWEeLv+v7QUK/pctpTjO2gAOh00Q8loxgxE/W+TpdMCJZLJpiNAA6zE/9efXwTmNS7oN8mch19hQrsMn1jdbLSW/aD54Bbuwbe74eCGf8fDkZ3OEUQuaPA07Ng5yVqExIxHylXy0JNV1qoPQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1703079880; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=sUEnh4ySfa83i4PpobooNYikWrP4B6C0g81JCycd+/A=; b=T6TFUgH72Ma8hvGzvswK50pHa5o+TeECNhXM5z18Ru1JaaCT1j13J2foL6BJk3lL6RWloD9bX1W46JY53U40+tF/c6w7jqcHGdI+N0kFOBJiBZILAJsVijELjECCh72OIgFgYl/+yCzweFusKkYyCZsYusH+jEioHrzoyUtQRtc= ARC-Authentication-Results: i=1; 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; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1703079880886202.69585884388368; Wed, 20 Dec 2023 05:44:40 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.657804.1026922 (Exim 4.92) (envelope-from ) id 1rFws4-0003nN-5R; Wed, 20 Dec 2023 13:44:24 +0000 Received: by outflank-mailman (output) from mailman id 657804.1026922; Wed, 20 Dec 2023 13:44: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 1rFws4-0003nE-0d; Wed, 20 Dec 2023 13:44:24 +0000 Received: by outflank-mailman (input) for mailman id 657804; Wed, 20 Dec 2023 13:44:22 +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 1rFws2-0003i3-Qx for xen-devel@lists.xenproject.org; Wed, 20 Dec 2023 13:44:22 +0000 Received: from mail-wm1-x32c.google.com (mail-wm1-x32c.google.com [2a00:1450:4864:20::32c]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id e0ba08ec-9f3d-11ee-9b0f-b553b5be7939; Wed, 20 Dec 2023 14:44:20 +0100 (CET) Received: by mail-wm1-x32c.google.com with SMTP id 5b1f17b1804b1-40c6ea99429so58016745e9.3 for ; Wed, 20 Dec 2023 05:44:20 -0800 (PST) Received: from localhost ([213.195.127.70]) by smtp.gmail.com with ESMTPSA id w20-20020a05600c475400b0040b4fca8620sm7448052wmo.37.2023.12.20.05.44.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Dec 2023 05:44:19 -0800 (PST) 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: e0ba08ec-9f3d-11ee-9b0f-b553b5be7939 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.com; s=google; t=1703079860; x=1703684660; 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=sUEnh4ySfa83i4PpobooNYikWrP4B6C0g81JCycd+/A=; b=ZeDLtGY4YI/tDOV+sfLBFFXoOQ3bFeRAvnhAbVVhTbvDmWW/MMOLLaBFWHfJEKwX0T 6L4WMnATH6sWDDi8wAk0ZrQ9VNZqhpSBZdiolgL47XnpWrhpLDBR7vRmcmDhzZNV+UWw H0qzUvjDtR4IfilaDjO9RWcLgIuFC13L5yTuo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703079860; x=1703684660; 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=sUEnh4ySfa83i4PpobooNYikWrP4B6C0g81JCycd+/A=; b=sD6CAqghNmJ6Ot1DLrsbiPZB+F4+Lp6q6Pr1ibwPgHR/7JmzcE08K2KgAnEb1+TAqq PYg0MdnOcc/cZCpMNrs87Tc09ch2xaGgZq+b1P6JHXLyp3St9bypD6vMjLp2lE9r7Ox4 bmzbfCqZP/bDXTmwEh/SDPBoBTRFIy3DDYKV7lvoR2YX5F38Mdl/di1ass4SvktglRLK f5OdeLNed2/XIucDZ6eW40UcxaEWVpm9RAX3VFN/Um6m8Ab+NcBcNkAkqaen6xeom0PP VrPtPwGrkcYkzjOeuhOSoXbym+JH53fPJmALpAXIyIEnFZdakszZzIuQp3Od5j8pPfxU /tNg== X-Gm-Message-State: AOJu0YwygrjQyNTncQB8I18+jFYg3vTu3CzATs6ixfYirocGdFQVntL2 Duvo8ps/Yl5bk/XxDtq2JCB89Dpi4H6MKHKR+8M= X-Google-Smtp-Source: AGHT+IFgkqe7gQD+UyN1PxMXVqucq08UDnelSZ/xbqtJuMa2X3dBbXZzvpJzuUkoCZOVF0KuQN2Nqg== X-Received: by 2002:a05:600c:3c8e:b0:40c:617b:16ae with SMTP id bg14-20020a05600c3c8e00b0040c617b16aemr3893367wmb.67.1703079860193; Wed, 20 Dec 2023 05:44:20 -0800 (PST) From: Roger Pau Monne To: xen-devel@lists.xenproject.org Cc: Roger Pau Monne , Jan Beulich , Andrew Cooper Subject: [PATCH v4 2/6] amd-vi: set IOMMU page table levels based on guest reported paddr width Date: Wed, 20 Dec 2023 14:43:42 +0100 Message-ID: <20231220134346.22430-3-roger.pau@citrix.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231220134346.22430-1-roger.pau@citrix.com> References: <20231220134346.22430-1-roger.pau@citrix.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @citrix.com) X-ZM-MESSAGEID: 1703079882023100001 However take into account the minimum number of levels required by unity ma= ps 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 t= he 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 uni= ty 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=C3=A9 Reviewed-by: Jan Beulich --- Changes since v3: - Avoid possible UB if domain_max_paddr_bits() ever returns 64. 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/pass= through/amd/pci_amd_iommu.c index 6bc73dc21052..146cf60084f4 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 =3D 1; static int cf_check amd_iommu_domain_init(struct domain *d) { struct domain_iommu *hd =3D dom_iommu(d); + int pglvl =3D amd_iommu_get_paging_mode( + 1UL << (domain_max_paddr_bits(d) - PAGE_SHIFT)); + + if ( pglvl < 0 ) + return pglvl; =20 /* - * Choose the number of levels for the IOMMU page tables. - * - PV needs 3 or 4, depending on whether there is RAM (including hot= plug - * 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 us= e 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 =3D 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 =3D max(pglvl, amd_iommu_min_paging_mode); =20 return 0; } --=20 2.43.0 From nobody Sun May 19 01:26:50 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; dmarc=pass(p=reject dis=none) header.from=citrix.com ARC-Seal: i=1; a=rsa-sha256; t=1703079885; cv=none; d=zohomail.com; s=zohoarc; b=OWhQhg8kLpRO4sqDl2MGF5uY4KV7Zsfb4NbJlu8QoF1T2zOh+C8oeHAoZEoa6fXjPFxYifMlRaD9w3SsbSKtmjBiWpBLU0p8cNmMjNTKRjx93cRqv8VcYgyT7vg9Hk3CLNd/J/giVZlBnsah8+6+MLDosgmmKHR8gEdrMWVPuDY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1703079885; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=kcflDR0c/PkDOoqkRYMUGNCU9Eem4zvQx0D8NuPEX+c=; b=KEF4/aR04+dgoqZ0HETsUtk1BiCJjFCKk2b15fG6d9YIG3EMN9CxT0YB4fa3CdVZ7zOTO4bQ0CDvG+HUeFcq3slb2bobNnJ8y7iejuwl/wcK6m9mvDdDV/Xmopth2W7xbpMR7K6AV87H1YNp+SayNjvIFZGAVOoq7Q7YcJ5SrDA= ARC-Authentication-Results: i=1; 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; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1703079885620393.3300880722462; Wed, 20 Dec 2023 05:44:45 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.657805.1026932 (Exim 4.92) (envelope-from ) id 1rFws5-00043u-Cv; Wed, 20 Dec 2023 13:44:25 +0000 Received: by outflank-mailman (output) from mailman id 657805.1026932; Wed, 20 Dec 2023 13:44:25 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rFws5-00043g-8T; Wed, 20 Dec 2023 13:44:25 +0000 Received: by outflank-mailman (input) for mailman id 657805; Wed, 20 Dec 2023 13:44:23 +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 1rFws3-0003Gg-BD for xen-devel@lists.xenproject.org; Wed, 20 Dec 2023 13:44:23 +0000 Received: from mail-wm1-x32f.google.com (mail-wm1-x32f.google.com [2a00:1450:4864:20::32f]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id e1d27ec8-9f3d-11ee-98eb-6d05b1d4d9a1; Wed, 20 Dec 2023 14:44:22 +0100 (CET) Received: by mail-wm1-x32f.google.com with SMTP id 5b1f17b1804b1-40c3fe6c1b5so61762575e9.2 for ; Wed, 20 Dec 2023 05:44:22 -0800 (PST) Received: from localhost ([213.195.127.70]) by smtp.gmail.com with ESMTPSA id k2-20020a05600c1c8200b0040b3867a297sm7383756wms.36.2023.12.20.05.44.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Dec 2023 05:44:20 -0800 (PST) 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: e1d27ec8-9f3d-11ee-98eb-6d05b1d4d9a1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.com; s=google; t=1703079861; x=1703684661; 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=kcflDR0c/PkDOoqkRYMUGNCU9Eem4zvQx0D8NuPEX+c=; b=AqR+YDNvx5ALTt95GNoLqdUanGate8CrmdrloXWjwtoGH8WcBVuG8/WZULNfjR2bWI aNHMjti4Wt39EjvEMFXljysD1LqcJ4QRZk6/ojMwEOetEL2gBdPOUrgXEezY9sNj1IWq Y38hkJMyZTkmwg1p/9lHuvewDHqXAjvtg3ub0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703079861; x=1703684661; 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=kcflDR0c/PkDOoqkRYMUGNCU9Eem4zvQx0D8NuPEX+c=; b=juPe0K1oe1SXSjAWTQsQEONdpunJXn5uQLCLShn8RUu+Ma+MaXkVm1o0txbcZNY5Kn eaexihce8TMeQp0u4u2FC5MLJz/WQ59ery4plE3uGVrCluNiueOMgSqsDezQNkf80rAO qpVyJhRTHbYKj/RCQHC/9zUkaJ+ez3aAK9I9xTmcdx9jKkfh9fYQqWm1VpzCAGbQhhAn WJW84lRQ2hKzsrXbG/18K7sNxbrO9Pk/slyJpOOIAwP4Tka+KjpnsOJeupSf0EryFg6e aloR4qQvliPUTERUO9fdTT/emNIX18K6PLCHCeSpXABFJkfM2fCEpgEtthTxpqeHSDZ7 B0RA== X-Gm-Message-State: AOJu0YzZIFvJOcEbNp2e3JPRPdVMY5AYXzt9us0sqQyQg8wUJsr77Iz3 XfmyNEna6a0OsH1OZqCAP6CdtUSaFXRS6NB0sGw= X-Google-Smtp-Source: AGHT+IGlYhIcislbaDTsllDLbIkpsrmeutmcKq++WkDEcQ/sFfAlRnNhMNzM+7URPTflZl6Hc4VmMQ== X-Received: by 2002:a05:600c:204b:b0:40c:38dc:f6c8 with SMTP id p11-20020a05600c204b00b0040c38dcf6c8mr10116139wmg.172.1703079861392; Wed, 20 Dec 2023 05:44:21 -0800 (PST) From: Roger Pau Monne To: xen-devel@lists.xenproject.org Cc: Roger Pau Monne , Jan Beulich , Paul Durrant Subject: [PATCH v4 3/6] x86/iommu: introduce a rangeset to perform hwdom IOMMU setup Date: Wed, 20 Dec 2023 14:43:43 +0100 Message-ID: <20231220134346.22430-4-roger.pau@citrix.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231220134346.22430-1-roger.pau@citrix.com> References: <20231220134346.22430-1-roger.pau@citrix.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @citrix.com) X-ZM-MESSAGEID: 1703079885926100001 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 mapp= ings 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 th= ere are no such mappings created for PVH dom0 in arch_iommu_hwdom_init(). Signed-off-by: Roger Pau Monn=C3=A9 Reviewed-by: Jan Beulich --- Changes since v3: - Fix one style issue and one typo in a comment. - Use map_data.flush_flags in replacement of flush_flags. - Return -EOPNOTSUPP on failure to create RO mappings for HVM. - Do not panic if mapping of ranges fails, print an error message. 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 on= ly take effect after later changes. Changes since v1: - Split from bigger patch. --- xen/drivers/passthrough/x86/iommu.c | 103 +++++++++++++++++++++++++++- 1 file changed, 100 insertions(+), 3 deletions(-) diff --git a/xen/drivers/passthrough/x86/iommu.c b/xen/drivers/passthrough/= x86/iommu.c index 857dccb6a465..59b0c7e980ca 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(cons= t struct domain *d, return perms; } =20 +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 lo= ng e, + void *data) +{ + struct map_data *info =3D data; + struct domain *d =3D 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(); + /* End the rangeset iteration, as other regions will also fail= . */ + return -EOPNOTSUPP; + } + while ( (rc =3D map_mmio_regions(d, _gfn(s), e - s + 1, _mfn(s))) = > 0 ) + { + s +=3D rc; + process_pending_softirqs(); + } + } + else + { + const unsigned int perms =3D IOMMUF_readable | IOMMUF_preempt | + (info->mmio_ro ? 0 : IOMMUF_writable); + + /* + * Read-only ranges are strictly MMIO and need an additional iomem + * permissions check. + */ + while ( info->mmio_ro && s <=3D e && !iomem_access_permitted(d, s,= e) ) + { + /* + * Consume a frame per iteration until the remainder is access= ible + * or there's nothing left to map. + */ + if ( iomem_access_permitted(d, s, s) ) + { + rc =3D 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 =3D=3D 1); + process_pending_softirqs(); + } + s++; + } + while ( (rc =3D iommu_map(d, _dfn(s), _mfn(s), e - s + 1, + perms, &info->flush_flags)) > 0 ) + { + s +=3D rc; + process_pending_softirqs(); + } + } + ASSERT(rc <=3D 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 =3D 0, start_perms =3D 0; + unsigned int start_perms =3D 0; + struct rangeset *map; + struct map_data map_data =3D { .d =3D d }; + int rc; =20 BUG_ON(!is_hardware_domain(d)); =20 @@ -397,6 +475,10 @@ void __hwdom_init arch_iommu_hwdom_init(struct domain = *d) if ( iommu_hwdom_passthrough ) return; =20 + map =3D rangeset_new(NULL, NULL, 0); + if ( !map ) + panic("IOMMU init: unable to allocate rangeset\n"); + max_pfn =3D (GB(4) >> PAGE_SHIFT) - 1; top =3D max(max_pdx, pfn_to_pdx(max_pfn) + 1); =20 @@ -427,7 +509,7 @@ void __hwdom_init arch_iommu_hwdom_init(struct domain *= d) commit: while ( (rc =3D iommu_map(d, _dfn(start), _mfn(start), count, start_perms | IOMMUF_preempt, - &flush_flags)) > 0 ) + &map_data.flush_flags)) > 0 ) { start +=3D rc; count -=3D rc; @@ -451,8 +533,23 @@ void __hwdom_init arch_iommu_hwdom_init(struct domain = *d) goto commit; } =20 + if ( iommu_verbose ) + printk(XENLOG_INFO "%pd: identity mappings for IOMMU:\n", d); + + rc =3D rangeset_report_ranges(map, 0, ~0UL, identity_map, &map_data); + rangeset_destroy(map); + if ( !rc && is_pv_domain(d) ) + { + map_data.mmio_ro =3D true; + rc =3D rangeset_report_ranges(mmio_ro_ranges, 0, ~0UL, identity_ma= p, + &map_data); + } + if ( rc ) + printk(XENLOG_WARNING "IOMMU unable to create %smappings: %d\n", + map_data.mmio_ro ? "read-only " : "", rc); + /* 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; } =20 --=20 2.43.0 From nobody Sun May 19 01:26:50 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; dmarc=pass(p=reject dis=none) header.from=citrix.com ARC-Seal: i=1; a=rsa-sha256; t=1703079887; cv=none; d=zohomail.com; s=zohoarc; b=nN7vRaqghQcmgDXiBAFPBVbL83X6jRXasAVYdD9MvUNMabyr72Q/x5C7Fo9U9vJJ4sr/uIz2w8uGX0Dh/u6yPGop83J58S3RuPPzDa/wteI0F81MlMxzTjc6/Q/+capzZiVUCWDVX53fMYmeIJBZdNDBCgtPuWxZg6XI8xsBlwY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1703079887; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=EGH9gStiPjZ0prtaKEVJp5+Oj1/6oICv4rkdA08vqzg=; b=ESS89gFX0xZnoM6+16/mzdDJEb5rSTGFxcxDUXeSuyVWyzZvudToFSCu8QkJkxRPR/ytHpsSeiiVifwe3rFTT3hD6h97PrNBKPgRP94NXaJt3ZyyGPDT+nIwg46FbcPubPOsD20sFtfFrvZoudrcTXmKGWKqqR9E//ffOXt0k+o= ARC-Authentication-Results: i=1; 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; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1703079887477136.3241894031894; Wed, 20 Dec 2023 05:44:47 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.657806.1026938 (Exim 4.92) (envelope-from ) id 1rFws5-00047w-Qe; Wed, 20 Dec 2023 13:44:25 +0000 Received: by outflank-mailman (output) from mailman id 657806.1026938; Wed, 20 Dec 2023 13:44:25 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rFws5-00047E-J3; Wed, 20 Dec 2023 13:44:25 +0000 Received: by outflank-mailman (input) for mailman id 657806; Wed, 20 Dec 2023 13:44:24 +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 1rFws4-0003Gg-Lp for xen-devel@lists.xenproject.org; Wed, 20 Dec 2023 13:44:24 +0000 Received: from mail-wr1-x435.google.com (mail-wr1-x435.google.com [2a00:1450:4864:20::435]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id e290390a-9f3d-11ee-98eb-6d05b1d4d9a1; Wed, 20 Dec 2023 14:44:24 +0100 (CET) Received: by mail-wr1-x435.google.com with SMTP id ffacd0b85a97d-3367a304091so700416f8f.3 for ; Wed, 20 Dec 2023 05:44:23 -0800 (PST) Received: from localhost ([213.195.127.70]) by smtp.gmail.com with ESMTPSA id c9-20020a056000104900b0033667867a66sm8611589wrx.101.2023.12.20.05.44.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Dec 2023 05:44:22 -0800 (PST) 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: e290390a-9f3d-11ee-98eb-6d05b1d4d9a1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.com; s=google; t=1703079863; x=1703684663; 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=EGH9gStiPjZ0prtaKEVJp5+Oj1/6oICv4rkdA08vqzg=; b=YO5GEIBNXeFD0JllQxx4+ekkmQh+fnjGzfKARLVY6vJYDUhyBaguX15+T63FMIflDm wGGnrvWOAB2Dukc4rL1P3m7+Rv6wCaPV+b1BU6MumOafgczQ+gDQ5LzzfuJu8JMCjJ3Y igQ0t2cKmZQ4UGuRigIKKCdo873W2j12aIVb0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703079863; x=1703684663; 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=EGH9gStiPjZ0prtaKEVJp5+Oj1/6oICv4rkdA08vqzg=; b=AfAzZtR3JvEPoJU35ssb/MMnrjHEPmm5fPnXCOElYhPYPUsiQBUvAeD1jNnntcjvWj MV9cf2PNXoddOaVZQb5C5otKHhWb3mAH4W59lZgREolCMIxKm21kXxIGvLklud/ZPRvS t/WtTOi0B6G2LOED9ZJ2sRD9IQopgoFK5uVxuKzvv3eXJEgqZE5+2wX2RDq3dTFvb30k OeT38g+q1iYaPzwYadNVQ8LmktT3VtHVsFKae/7WPrFs+U3Y8eBGW/W5sg2ZycjJUEmx q1GYUfKZarN1yR+Mt5IPytKLkMlg+QiGSjtPfcfmgghsye8tZJB7qUqGUKRVSt5psAvX /yag== X-Gm-Message-State: AOJu0YxP5SpyBE8qYyegi21CbeWpBRikXrneKaWR5ysoFbTv31KzRyyP +zZk8T3BJrxNYea0SSUg9hQ1tJXYrsggTWJ+7pk= X-Google-Smtp-Source: AGHT+IFd3yeWJruQdo46zT5R+FKWKF/sJjnLVY0qeKLVTjg7W1H5izJcYpIKikXvJdlZp7WbuNsoBw== X-Received: by 2002:a5d:404c:0:b0:336:74e3:63cc with SMTP id w12-20020a5d404c000000b0033674e363ccmr909790wrp.209.1703079862758; Wed, 20 Dec 2023 05:44:22 -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 v4 4/6] x86/iommu: remove regions not to be mapped Date: Wed, 20 Dec 2023 14:43:44 +0100 Message-ID: <20231220134346.22430-5-roger.pau@citrix.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231220134346.22430-1-roger.pau@citrix.com> References: <20231220134346.22430-1-roger.pau@citrix.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @citrix.com) X-ZM-MESSAGEID: 1703079887883100003 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 other= wise be intercepted by the original functions. Note that the rangeset is still not populated. Signed-off-by: Roger Pau Monn=C3=A9 Reviewed-by: Jan Beulich --- Changes since v3: - Remove unnecessary line wrapping. 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 | 61 +++++++++++++++++++++++++++++ 5 files changed, 129 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, pad= dr_t addr) return vpci_mmcfg_find(d, addr); } =20 +int __hwdom_init vpci_subtract_mmcfg(const struct domain *d, struct ranges= et *r) +{ + const struct hvm_mmcfg *mmcfg; + + list_for_each_entry ( mmcfg, &d->arch.hvm.mmcfg_regions, next ) + { + int rc =3D 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/h= vm/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); =20 +/* Remove MMCFG regions from a given rangeset. */ +int vpci_subtract_mmcfg(const struct domain *d, struct rangeset *r); + #endif /* __ASM_X86_HVM_IO_H__ */ =20 =20 diff --git a/xen/arch/x86/include/asm/setup.h b/xen/arch/x86/include/asm/se= tup.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); =20 int xen_in_range(unsigned long mfn); +int remove_xen_ranges(struct rangeset *r); =20 extern uint8_t kbd_shift_flags; =20 diff --git a/xen/arch/x86/setup.c b/xen/arch/x86/setup.c index 897b7e92082e..ba6fe9afe5e6 100644 --- a/xen/arch/x86/setup.c +++ b/xen/arch/x86/setup.c @@ -2138,6 +2138,54 @@ int __hwdom_init xen_in_range(unsigned long mfn) return 0; } =20 +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 =3D 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 =3D 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) >=3D __pa(&__2M_rwdata_start)); + rc =3D rangeset_remove_range(r, PFN_DOWN(__pa(&__2M_rwdata_start)), + PFN_DOWN(__pa(start))); + if ( rc ) + return rc; + ASSERT(__pa(end) <=3D __pa(&__2M_rwdata_end)); + rc =3D rangeset_remove_range(r, PFN_DOWN(__pa(end)), + PFN_DOWN(__pa(&__2M_rwdata_end))); + if ( rc ) + return rc; + } + else + { + rc =3D 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 59b0c7e980ca..fc5215a9dc40 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; } =20 +static int __hwdom_init cf_check map_subtract(unsigned long s, unsigned lo= ng e, + void *data) +{ + struct rangeset *map =3D data; + + return rangeset_remove_range(map, s, e); +} + struct map_data { struct domain *d; unsigned int flush_flags; @@ -533,6 +541,59 @@ void __hwdom_init arch_iommu_hwdom_init(struct domain = *d) goto commit; } =20 + /* Remove any areas in-use by Xen. */ + rc =3D 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 =3D 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 =3D 0; i < d->arch.hvm.nr_vioapics; i++ ) + { + rc =3D 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 be= low + * in read-only mode. + */ + rc =3D rangeset_report_ranges(mmio_ro_ranges, 0, ~0UL, map_subtrac= t, 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 trap= ping. + */ + rc =3D 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 =3D rangeset_remove_range(map, PFN_DOWN(1UL << domain_max_paddr_bit= s(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); =20 --=20 2.43.0 From nobody Sun May 19 01:26:50 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; dmarc=pass(p=reject dis=none) header.from=citrix.com ARC-Seal: i=1; a=rsa-sha256; t=1703079891; cv=none; d=zohomail.com; s=zohoarc; b=DjYGJ+3Fan4aHarwZeHvkHa3FmQ86XmF0QL5Xe0XQyY7EI/p5oggtPn6WC98gqWNDvovoRrSm13kh3p2RWcDsQ7szY2Gt2mmzDYgePbSC0QjqgmKMY9qsU1G+PELg+2/11ieDA0UTTMFrpFb+myxJVFeGrJ7ytd2z2U7yMCJOl8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1703079891; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=mWt46NsSUJyLU20AyZjHFmWq2XJnJH2+S6s1Ntby1hw=; b=dTBwMSL7EUJi1hBh2fQAKQAAcL/MJSgkuGtsqV+Yzdthv/+DnPxipHrvOUpZ1T4lqfOgBuxbF0kPtO5A9BePcEXetAAiM758fYQuxfFgrRV7F/aSr0uyCnvF7CgEpDWm1zLDSEzAOxIw862AQjvxKK1XecNFKm0ozgoqIhF+OPY= ARC-Authentication-Results: i=1; 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; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1703079891819538.0652687295045; Wed, 20 Dec 2023 05:44:51 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.657807.1026952 (Exim 4.92) (envelope-from ) id 1rFws7-0004bc-BM; Wed, 20 Dec 2023 13:44:27 +0000 Received: by outflank-mailman (output) from mailman id 657807.1026952; Wed, 20 Dec 2023 13:44:27 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rFws7-0004bL-7r; Wed, 20 Dec 2023 13:44:27 +0000 Received: by outflank-mailman (input) for mailman id 657807; Wed, 20 Dec 2023 13:44:25 +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 1rFws5-0003Gg-OO for xen-devel@lists.xenproject.org; Wed, 20 Dec 2023 13:44:25 +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 e338167e-9f3d-11ee-98eb-6d05b1d4d9a1; Wed, 20 Dec 2023 14:44:25 +0100 (CET) Received: by mail-wm1-x32a.google.com with SMTP id 5b1f17b1804b1-40d31116dbeso10164885e9.3 for ; Wed, 20 Dec 2023 05:44:25 -0800 (PST) Received: from localhost ([213.195.127.70]) by smtp.gmail.com with ESMTPSA id g3-20020a05600c310300b0040c6b2c8fa9sm7534047wmo.41.2023.12.20.05.44.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Dec 2023 05:44:23 -0800 (PST) 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: e338167e-9f3d-11ee-98eb-6d05b1d4d9a1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.com; s=google; t=1703079864; x=1703684664; 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=mWt46NsSUJyLU20AyZjHFmWq2XJnJH2+S6s1Ntby1hw=; b=qjhO1MG41VBsM7xXQGAX0V8GIxEmJhe1m2so9pgNWXOgsXP0YQg4Rgmq4XKIM6hdec AFXm+/XZSYQqo/fGbyTnrxgLq3HcyJb67wDmCRV/+23j05vHG47UexPwPuAPDXI0cDmH 5dnJ0yKfYMHuRIKyHSUR0gffvPDJXcWdxCnvo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703079864; x=1703684664; 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=mWt46NsSUJyLU20AyZjHFmWq2XJnJH2+S6s1Ntby1hw=; b=Te8GVtXP/dDkFYV8P4gw0hQmSfhjhfxS9vJSBNe+0jIXGn1cqCnyGRZrTKEOlNr+Za GpuxAiY4zBSpxqrBtQfm0De7SUvhzWfrCBmd8JgZSqYIn6IAOkIDyW3dhRBl/ojDTZ5J HlagFarrrr5PIHDXJyUyiU1/4TIzFn/P+7HMmJZEUgsDboyY0nYTvnBCgwyy3ti6FaOW OFwlK48rd/RvYvw4jMwNkAhXwaTzowPsbx+lv/Ve1SK9g8KTok01xYcUnfaf7oosjqGZ oZCmowjSF+2fDkRk7BfLe+09Ov5vrDtW6XgEVlBiccbvnQGVR6dzfVXGdElN3v6J/XA1 Q/dg== X-Gm-Message-State: AOJu0YwqaEI0N05vBSpdWLdWtsM5XZPn+2ueRi4hGyLbFW/IVBODZ/q/ uv5RE+rNft4lqUJqc+edxbXOhQI+VQiI2ZLQwOc= X-Google-Smtp-Source: AGHT+IFycwDdamjev+bQnA6qnvOOkI3hdQyGyVjc+8n4o5Q2o2hNk0XRxgQWwfPcJJ1KH36ifDqFYg== X-Received: by 2002:a05:600c:1913:b0:40c:a12:d626 with SMTP id j19-20020a05600c191300b0040c0a12d626mr10854085wmq.103.1703079864334; Wed, 20 Dec 2023 05:44:24 -0800 (PST) From: Roger Pau Monne To: xen-devel@lists.xenproject.org Cc: Roger Pau Monne , Jan Beulich , Paul Durrant Subject: [PATCH v4 5/6] x86/iommu: switch hwdom IOMMU to use a rangeset Date: Wed, 20 Dec 2023 14:43:45 +0100 Message-ID: <20231220134346.22430-6-roger.pau@citrix.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231220134346.22430-1-roger.pau@citrix.com> References: <20231220134346.22430-1-roger.pau@citrix.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @citrix.com) X-ZM-MESSAGEID: 1703079894023100001 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 reg= ions and use a rangeset in order to keep track of which ranges need to be identi= ty 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 =3D 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 functi= on 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=C3=A9 Reviewed-by: Jan Beulich --- Changes since v3: - Remove unnecessary line wraps. Changes since v2: - Simplify a bit the logic related to inclusive option, at the cost of mak= ing some no-op calls on some cases. Changes since v1: - Split from bigger patch. - Remove unneeded default case. --- xen/drivers/passthrough/x86/iommu.c | 146 ++++++---------------------- 1 file changed, 30 insertions(+), 116 deletions(-) diff --git a/xen/drivers/passthrough/x86/iommu.c b/xen/drivers/passthrough/= x86/iommu.c index fc5215a9dc40..8e764e0afb31 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) } } =20 -static unsigned int __hwdom_init hwdom_iommu_map(const struct domain *d, - unsigned long pfn, - unsigned long max_pfn) -{ - mfn_t mfn =3D _mfn(pfn); - unsigned int i, type, perms =3D IOMMUF_readable | IOMMUF_writable; - - /* - * Set up 1:1 mapping for dom0. Default to include only conventional R= AM - * areas and let RMRRs include needed reserved regions. When set, the - * inclusive mapping additionally maps in every pfn up to 4GB except t= hose - * that fall in unusable ranges for PV Dom0. - */ - if ( (pfn > max_pfn && !mfn_valid(mfn)) || xen_in_range(pfn) ) - return 0; - - switch ( type =3D 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 =3D 0; - } - else if ( is_hvm_domain(d) ) - return 0; - else if ( !iommu_hwdom_inclusive || pfn > max_pfn ) - perms =3D 0; - } - - /* Check that it doesn't overlap with the Interrupt Address Range. */ - if ( pfn >=3D 0xfee00 && pfn <=3D 0xfeeff ) - return 0; - /* ... or the IO-APIC */ - if ( has_vioapic(d) ) - { - for ( i =3D 0; i < d->arch.hvm.nr_vioapics; i++ ) - if ( pfn =3D=3D 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 =3D 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 lo= ng e, void *data) { @@ -455,8 +385,7 @@ static int __hwdom_init cf_check identity_map(unsigned = long s, unsigned long e, =20 void __hwdom_init arch_iommu_hwdom_init(struct domain *d) { - unsigned long i, top, max_pfn, start, count; - unsigned int start_perms =3D 0; + unsigned int i; struct rangeset *map; struct map_data map_data =3D { .d =3D d }; int rc; @@ -487,58 +416,43 @@ void __hwdom_init arch_iommu_hwdom_init(struct domain= *d) if ( !map ) panic("IOMMU init: unable to allocate rangeset\n"); =20 - max_pfn =3D (GB(4) >> PAGE_SHIFT) - 1; - top =3D 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 =3D rangeset_add_range(map, 0, PFN_DOWN(GB(4)) - 1); + if ( rc ) + panic("IOMMU inclusive mappings can't be added: %d\n", rc); + } =20 - for ( i =3D 0, start =3D 0, count =3D 0; i < top; ) + for ( i =3D 0; i < e820.nr_map; i++ ) { - unsigned long pfn =3D pdx_to_pfn(i); - unsigned int perms =3D hwdom_iommu_map(d, pfn, max_pfn); + const struct e820entry entry =3D e820.map[i]; =20 - if ( !perms ) - /* nothing */; - else if ( paging_mode_translate(d) ) + switch ( entry.type ) { - int rc; - - rc =3D p2m_add_identity_entry(d, pfn, - perms & IOMMUF_writable ? p2m_acce= ss_rw - : p2m_acce= ss_r, - 0); + case E820_UNUSABLE: + /* Only relevant for inclusive mode, otherwise this is a no-op= . */ + rc =3D 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 !=3D start + count || perms !=3D start_perms ) - { - long rc; + panic("IOMMU failed to remove unusable memory: %d\n", rc); + continue; =20 - commit: - while ( (rc =3D iommu_map(d, _dfn(start), _mfn(start), count, - start_perms | IOMMUF_preempt, - &map_data.flush_flags)) > 0 ) - { - start +=3D rc; - count -=3D 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 =3D pfn; - count =3D 1; - start_perms =3D perms; - } - else - ++count; + case E820_RESERVED: + if ( !iommu_hwdom_inclusive && !iommu_hwdom_reserved ) + continue; + break; =20 - if ( !(++i & 0xfffff) ) - process_pending_softirqs(); + case E820_RAM: + if ( iommu_hwdom_strict ) + continue; + break; + } =20 - if ( i =3D=3D top && count ) - goto commit; + rc =3D 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); } =20 /* Remove any areas in-use by Xen. */ --=20 2.43.0 From nobody Sun May 19 01:26:50 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; dmarc=pass(p=reject dis=none) header.from=citrix.com ARC-Seal: i=1; a=rsa-sha256; t=1703079891; cv=none; d=zohomail.com; s=zohoarc; b=eQGQeiMFqWTkS/fiuTb54TbLKV/QdIu/i1ahY+uTLnqvsp0RR60GKNySlIybkWYi1OZg7T4W8XR6y11J9ekE7XZbstUJL83+D/dfTllO5opKSjb6Iya0chCTOEq3fqavtz6jVVjcTWDD+BuaeK2I/XLZSLaUrVIOENf+7PQTDsc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1703079891; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=xAlY4C0HQDzoSCwoi4E+eaPx6lrWU2JEHIBeS4B9AY0=; b=dsEKmb0TaCDTADdEojfmP1ceLya2Uct/KF8h5EjDi5lji/V5Dwzc7sa8L3vEamzMatS7lphEFdBtVaW+vAFVxTvmiVSYbDbbbNj0zFs1gpquzy6Ck2r5iUIOEjXr24acOrrLUDFrOQF88c7D+/9xLyWZ4oLM3mmCjd00/84ZDEw= ARC-Authentication-Results: i=1; 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; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1703079891184575.1858379992499; Wed, 20 Dec 2023 05:44:51 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.657808.1026959 (Exim 4.92) (envelope-from ) id 1rFws7-0004fw-TL; Wed, 20 Dec 2023 13:44:27 +0000 Received: by outflank-mailman (output) from mailman id 657808.1026959; Wed, 20 Dec 2023 13:44:27 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rFws7-0004eC-IY; Wed, 20 Dec 2023 13:44:27 +0000 Received: by outflank-mailman (input) for mailman id 657808; Wed, 20 Dec 2023 13:44:26 +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 1rFws6-0003Gg-OR for xen-devel@lists.xenproject.org; Wed, 20 Dec 2023 13:44:26 +0000 Received: from mail-wm1-x332.google.com (mail-wm1-x332.google.com [2a00:1450:4864:20::332]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id e3e73017-9f3d-11ee-98eb-6d05b1d4d9a1; Wed, 20 Dec 2023 14:44:26 +0100 (CET) Received: by mail-wm1-x332.google.com with SMTP id 5b1f17b1804b1-40d2e56f3a6so4697155e9.1 for ; Wed, 20 Dec 2023 05:44:26 -0800 (PST) Received: from localhost ([213.195.127.70]) by smtp.gmail.com with ESMTPSA id v8-20020a05600c444800b0040d2e37c06dsm5317599wmn.20.2023.12.20.05.44.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Dec 2023 05:44:25 -0800 (PST) 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: e3e73017-9f3d-11ee-98eb-6d05b1d4d9a1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.com; s=google; t=1703079865; x=1703684665; 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=xAlY4C0HQDzoSCwoi4E+eaPx6lrWU2JEHIBeS4B9AY0=; b=heQerYOhOz4OM30QeMY6cHkbgQU+ZdI01c025Be68wn0jB3Xa0Zf4rfHO9UNWHCo7S f7u21pUTPQepdolqQ1b/GPBYNdCozaIukFHOHmv/PWINBLx+YKcgAUTQaBOfoj6muOAt o4KeSV4tGt81l0aewnY93sQhVf5qA3343oG9g= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703079865; x=1703684665; 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=xAlY4C0HQDzoSCwoi4E+eaPx6lrWU2JEHIBeS4B9AY0=; b=dvYmi2DORn3Mmk7gnRUWCCJ+xmKjxUgt8ScjdlBe8zkbOXR7aGP9bcSw7UTMEt94ky lrqeIQcYXNbkPKvi2NAjLT6E6WFnXiJBYX2ySRy1AcPLXVswmx35kOGKY5Wmw4PsU7+z aI65s4jnCE5lbK4Q0Abn/BAxfdWsNLnKZIP/Goh9eAae354ocSlPIS/oF7yGSa1LotR7 IOSM0+9PP3MJwjrgOsaJP1MX8/rh4l14xY78+0BLj2XZ5KGizovTAAC/UBUe0bx1sc7q PFOBMMne2WE5QR4z9g0X5k3M9QTRLkqw6a9nXGNHeS7PjY+P7n2kWsd9NNE8UC8l+Lo+ YE8w== X-Gm-Message-State: AOJu0YyB3WFjra5RksFxWZdpgmbG9U7/mYPwbGzzfzGCgjlPE6heF0VL THD4SolOLoquhloycOKAhCVV2bW4riO/Cs8jm8o= X-Google-Smtp-Source: AGHT+IGE7T54g7A2QSyHEI437s+5UNPHgj+iWpog6Qs0TeFPOUp+WcO4VvQ6OQFeiPX9ikmthQgmwQ== X-Received: by 2002:a7b:c409:0:b0:40b:5e26:236e with SMTP id k9-20020a7bc409000000b0040b5e26236emr1629550wmi.31.1703079865538; Wed, 20 Dec 2023 05:44:25 -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=20M=C3=B3wka?= Subject: [PATCH v4 6/6] x86/iommu: cleanup unused functions Date: Wed, 20 Dec 2023 14:43:46 +0100 Message-ID: <20231220134346.22430-7-roger.pau@citrix.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231220134346.22430-1-roger.pau@citrix.com> References: <20231220134346.22430-1-roger.pau@citrix.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @citrix.com) X-ZM-MESSAGEID: 1703079891922100001 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 one= s. No functional change. Signed-off-by: Roger Pau Monn=C3=A9 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 pat= ch 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 s= truct domain *d, return NULL; } =20 -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 ranges= et *r) { const struct hvm_mmcfg *mmcfg; diff --git a/xen/arch/x86/include/asm/hvm/io.h b/xen/arch/x86/include/asm/h= vm/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); =20 -/* 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); =20 diff --git a/xen/arch/x86/include/asm/setup.h b/xen/arch/x86/include/asm/se= tup.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); =20 -int xen_in_range(unsigned long mfn); int remove_xen_ranges(struct rangeset *r); =20 extern uint8_t kbd_shift_flags; diff --git a/xen/arch/x86/setup.c b/xen/arch/x86/setup.c index ba6fe9afe5e6..f52fc3f63cb0 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 =3D true; =20 /* - * 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); =20 - /* 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)); @@ -2089,55 +2089,6 @@ void arch_get_xen_caps(xen_capabilities_info_t *info) } } =20 -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 =3D bootsym_phys(trampoline_start); - xen_regions[region_s3].e =3D 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 =3D __pa(&_stext); - xen_regions[region_ro].e =3D __pa(&__2M_rodata_end); - /* hypervisor .data + .bss */ - xen_regions[region_rw].s =3D __pa(&__2M_rwdata_start); - xen_regions[region_rw].e =3D __pa(&__2M_rwdata_end); - if ( efi_boot_mem_unused(&start, &end) ) - { - ASSERT(__pa(start) >=3D xen_regions[region_rw].s); - ASSERT(__pa(end) <=3D xen_regions[region_rw].e); - xen_regions[region_rw].e =3D __pa(start); - xen_regions[region_bss].s =3D __pa(end); - xen_regions[region_bss].e =3D __pa(&__2M_rwdata_end); - } - } - - start =3D (paddr_t)mfn << PAGE_SHIFT; - end =3D start + PAGE_SIZE; - for ( i =3D 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) =20 /* * 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 =3D 3; /* S3 resume code (and other real mode trampoline code) */ --=20 2.43.0 From nobody Sun May 19 01:26:50 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; dmarc=pass(p=reject dis=none) header.from=citrix.com ARC-Seal: i=1; a=rsa-sha256; t=1703153601; cv=none; d=zohomail.com; s=zohoarc; b=Q9m5LniJRbVvcv8ivFXhjHWTHCv2KEsb3NcMkN3wNoV+JlCE05ZEwZMynyR6Wv6skpjpfAvJis/Z8pBktRqfs4Gd0j4A1whyBiWfi5u7tuUKLe5h+PfsaGCeOXCuJI+0q7itsfjGtP1Y0js/L4TCO3POTiq+EhgS+S+/SW/WFAQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1703153601; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=FJqk6Pur9dOADqhhWPpTnn4CtiAiEvc3SjgIBFQKraw=; b=dZhiIajP0GIviRRYti5grZXGbWsSPXkB4Do6BgKEp4CGOY6Er1cyF8/2sPNjoN8eW8YY0MdKf6JOmlm+eGkP+YqcDz9LK9o1Xo94tvI5jwGZv2o2i8H1ZtOhERYQv7Dt5NcCYhKp8ycvqwrvJ/+SnABXpBfMrvLukgD6JpabrEA= ARC-Authentication-Results: i=1; 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; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 170315360165334.555604663913755; Thu, 21 Dec 2023 02:13:21 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.658743.1028068 (Exim 4.92) (envelope-from ) id 1rGG32-0008DX-2z; Thu, 21 Dec 2023 10:13:00 +0000 Received: by outflank-mailman (output) from mailman id 658743.1028068; Thu, 21 Dec 2023 10:13:00 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rGG32-0008DQ-0G; Thu, 21 Dec 2023 10:13:00 +0000 Received: by outflank-mailman (input) for mailman id 658743; Thu, 21 Dec 2023 10:12:58 +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 1rGG30-0008C4-IY for xen-devel@lists.xenproject.org; Thu, 21 Dec 2023 10:12:58 +0000 Received: from mail-wm1-x335.google.com (mail-wm1-x335.google.com [2a00:1450:4864:20::335]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 82b6c410-9fe9-11ee-9b0f-b553b5be7939; Thu, 21 Dec 2023 11:12:56 +0100 (CET) Received: by mail-wm1-x335.google.com with SMTP id 5b1f17b1804b1-40c29f7b068so6278355e9.0 for ; Thu, 21 Dec 2023 02:12:56 -0800 (PST) Received: from localhost ([213.195.127.70]) by smtp.gmail.com with ESMTPSA id b6-20020a5d6346000000b0033683574772sm1614863wrw.65.2023.12.21.02.12.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Dec 2023 02:12:55 -0800 (PST) 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: 82b6c410-9fe9-11ee-9b0f-b553b5be7939 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.com; s=google; t=1703153576; x=1703758376; 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=FJqk6Pur9dOADqhhWPpTnn4CtiAiEvc3SjgIBFQKraw=; b=oC6IIaRxVQ4lzsxNlvEvNYbNj8W0MTlzWp2SNrUJXhdURwrwb8cPdwWpVvCjzTRGit 24yg3q2oITEjgyJNfj6UrSZlVXS+JUO+IRIdn12BJbIgMiF8w38LCmDqb3tcWZfunzWi UlLsTTnBU5C16NsVaIJlDRKL8BzCxy3wz/enw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703153576; x=1703758376; 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=FJqk6Pur9dOADqhhWPpTnn4CtiAiEvc3SjgIBFQKraw=; b=DZPdlKvEHEvwYtxgwU2TOmNLNj1FKc++POviKu4yUYnY7sSLdS08B4//ZIXy7WreKI zlTByabTCuOWMSoo2+WqcVfn06eGBANAfAuGUkeQRK8BgIPK6CNXT7k5qu4vDbFthyBO T8C3UmNI3123/oQHsYOAvGif5rsQQEvs7CMuyflqzPfofHM+3+3i+gQkwU5bftsFxMmq w4cS98KBX6JtYoaCYEY3tgdjDP2se8bd/QK/Dj3bG5z2kCx3heF6Vr7Pprk3NvMyzEeN fkcyEW7C138YUamvVUJnu2Mkct7yl9sJTKcs7Cyyj1g/7UQXqx4GjGKDmn3vx2kPnTOc APzQ== X-Gm-Message-State: AOJu0YyPVYzZ6Qb3rMHlkyC1bVAX+senEb3mJctrfl6eZ0i6gUzdZuLl acBj9IbAFP5IAwNKafp9vun1b0287dFmfJpRgKI= X-Google-Smtp-Source: AGHT+IG9z2zfstjFpXvpIHNBwwSnDwJqoftYl1oFCffwk7ZuleQ/h3y8lZP0YuTuMFamDZ61rLPPdQ== X-Received: by 2002:a05:600c:4fc7:b0:40b:4476:cd31 with SMTP id o7-20020a05600c4fc700b0040b4476cd31mr561970wmq.13.1703153575885; Thu, 21 Dec 2023 02:12:55 -0800 (PST) From: Roger Pau Monne To: xen-devel@lists.xenproject.org Cc: Roger Pau Monne , Oleksii Kurochko , Community Manager Subject: [PATCH] x86/iommu: add CHANGELOG entry for hwdom setup time improvements Date: Thu, 21 Dec 2023 11:12:44 +0100 Message-ID: <20231221101244.25650-1-roger.pau@citrix.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231220134346.22430-1-roger.pau@citrix.com> References: <20231220134346.22430-1-roger.pau@citrix.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @citrix.com) X-ZM-MESSAGEID: 1703153602425100001 Signed-off-by: Roger Pau Monn=C3=A9 --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5ee5d41fc933..52484c047bd1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,8 @@ The format is based on [Keep a Changelog](https://keepachan= gelog.com/en/1.0.0/) ### Changed - Changed flexible array definitions in public I/O interface headers to n= ot use "1" as the number of array elements. + - On x86: + - Reduce IOMMU setup time for hardware domain. =20 ### Added - On x86: --=20 2.43.0