From nobody Wed Apr 24 19:17:57 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=fail; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1596205591; cv=none; d=zohomail.com; s=zohoarc; b=LXAyTtrDwvP6c3dlQvpoqkWcqaqrvvUixhaBMX7HBE3meIPzZI74eC2V8013zQugt1wuUa8QddgpPYSpxioTbNlb7Dkby+s/L54ZBONUSK2QuAsUoKP4QhLpK9EuFlHonINmfxrdBPOSK4jh5FDVVZN1keZdcFGkO6QiifmxneE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1596205591; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=0ELqKaNJTQk3GSaeAGwge8h9gTL67LFvh82JALfJSP0=; b=nBEOe6FBE6RAUk9eAiEu6NsMv/pI+XpVnvBfmnFalBws6Bz9WHArqhPbJDqx8Upwzuhqjfr4TFiTFljE0kvb6eXp9TLCOe8EkQCMtXPtoQM4664AVEa+3j9DBSu+p05Ywl4hkTE1/6hLtqCfFHsj8SzxJNmY18yh2G2EVt+e5UE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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 Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1596205591165885.1582687399123; Fri, 31 Jul 2020 07:26:31 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1k1VzC-00046v-Vt; Fri, 31 Jul 2020 14:26:14 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1k1VzB-00045J-PE for xen-devel@lists.xenproject.org; Fri, 31 Jul 2020 14:26:13 +0000 Received: from mail.xenproject.org (unknown [104.130.215.37]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id c63e343d-d339-11ea-abc3-12813bfff9fa; Fri, 31 Jul 2020 14:26:08 +0000 (UTC) Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1k1Vz6-0003Zz-E8; Fri, 31 Jul 2020 14:26:08 +0000 Received: from host86-143-223-30.range86-143.btcentralplus.com ([86.143.223.30] helo=u2f063a87eabd5f.home) by xenbits.xenproject.org with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1k1Vz6-0005vI-6D; Fri, 31 Jul 2020 14:26:08 +0000 X-Inumbo-ID: c63e343d-d339-11ea-abc3-12813bfff9fa DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org; s=20200302mail; h=Content-Transfer-Encoding:Content-Type:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=0ELqKaNJTQk3GSaeAGwge8h9gTL67LFvh82JALfJSP0=; b=bMipD4w6/T3x8nE1XEd3g37i7P x3fT0nfXiTGnbgsZOkLavc7KNBcEbHJrr4n3T5aiU/H6ltMXfoo5hLqjiCe5WS1eBHat5B6Uu1NKA ye9Kq7Kb6SmmC70x1dhXS8tq64LvBDx+42ir3a3jQWkopBYcNKzJLHfuqxG5skJY/gqE=; From: Paul Durrant To: xen-devel@lists.xenproject.org Subject: [PATCH v3 1/2] x86/hvm: set 'ipat' in EPT for special pages Date: Fri, 31 Jul 2020 15:26:03 +0100 Message-Id: <20200731142604.30149-2-paul@xen.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200731142604.30149-1-paul@xen.org> References: <20200731142604.30149-1-paul@xen.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Andrew Cooper , Paul Durrant , Wei Liu , Jan Beulich , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) From: Paul Durrant All non-MMIO ranges (i.e those not mapping real device MMIO regions) that map valid MFNs are normally marked MTRR_TYPE_WRBACK and 'ipat' is set. Hence when PV drivers running in a guest populate the BAR space of the Xen Platfo= rm PCI Device with pages such as the Shared Info page or Grant Table pages, accesses to these pages will be cachable. However, should IOMMU mappings be enabled be enabled for the guest then the= se accesses become uncachable. This has a substantial negative effect on I/O throughput of PV devices. Arguably PV drivers should bot be using BAR space= to host the Shared Info and Grant Table pages but it is currently commonplace = for them to do this and so this problem needs mitigation. Hence this patch makes sure the 'ipat' bit is set for any special page regardless of where in GFN space it is mapped. NOTE: Clearly this mitigation only applies to Intel EPT. It is not obvious that there is any similar mitigation possible for AMD NPT. Downstreams such as Citrix XenServer have been carrying a patch similar to this f= or several releases though. Signed-off-by: Paul Durrant --- Cc: Jan Beulich Cc: Andrew Cooper Cc: Wei Liu Cc: "Roger Pau Monn=C3=A9" v3: - dropping Jan's R-b - cope with order > 0 --- xen/arch/x86/hvm/mtrr.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/xen/arch/x86/hvm/mtrr.c b/xen/arch/x86/hvm/mtrr.c index 511c3be1c8..26721f6ee7 100644 --- a/xen/arch/x86/hvm/mtrr.c +++ b/xen/arch/x86/hvm/mtrr.c @@ -836,6 +836,17 @@ int epte_get_entry_emt(struct domain *d, unsigned long= gfn, mfn_t mfn, return MTRR_TYPE_WRBACK; } =20 + for ( i =3D 0; i < (1ul << order); i++ ) + { + if ( is_special_page(mfn_to_page(mfn_add(mfn, i))) ) + { + if ( order ) + return -1; + *ipat =3D 1; + return MTRR_TYPE_WRBACK; + } + } + gmtrr_mtype =3D hvm_get_mem_pinned_cacheattr(d, _gfn(gfn), order); if ( gmtrr_mtype >=3D 0 ) { --=20 2.20.1 From nobody Wed Apr 24 19:17:57 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=fail; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1596205597; cv=none; d=zohomail.com; s=zohoarc; b=I1p94g6wTeCGZCZoh04zSnZY3y1dnsud7a1q/LNAMay+teqy+vJHVSZ/06Xc9Fe6YmWxgU7NZ4Nai8grP/K6nAG7L2crees5A934th0LTz2aVd73Csr4A0Mgp1eOwki/eJcE3oFHKfyrm4xiVR5jj/zYpZR6v4gkNJfIArAwmZM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1596205597; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=TJaEXcctXRgjH3OlX3A2Uvf+yHvHz4k83Q2YxZ3EH7g=; b=gWyiY4KCUdcpXjrCGgM8pi0sT99BuLYIpn5IRpJr9KL7S2z0Mgk7999Qz2ZusGqEOB/E420b/O8lo/bS1fpuuyOytJCIYazLQa3YuIyI8yfhrnLdH6GroTNrw0EFFh6Pyyh36bRLJfjmtta27KonTSZIT+/XVPVeo/ptARrSKNM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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 Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1596205597525570.1921880832147; Fri, 31 Jul 2020 07:26:37 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1k1VzI-00048Y-7m; Fri, 31 Jul 2020 14:26:20 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1k1VzG-00045J-PQ for xen-devel@lists.xenproject.org; Fri, 31 Jul 2020 14:26:18 +0000 Received: from mail.xenproject.org (unknown [104.130.215.37]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id c63e343e-d339-11ea-abc3-12813bfff9fa; Fri, 31 Jul 2020 14:26:09 +0000 (UTC) Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1k1Vz7-0003a9-El; Fri, 31 Jul 2020 14:26:09 +0000 Received: from host86-143-223-30.range86-143.btcentralplus.com ([86.143.223.30] helo=u2f063a87eabd5f.home) by xenbits.xenproject.org with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1k1Vz7-0005vI-63; Fri, 31 Jul 2020 14:26:09 +0000 X-Inumbo-ID: c63e343e-d339-11ea-abc3-12813bfff9fa DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org; s=20200302mail; h=Content-Transfer-Encoding:Content-Type:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=TJaEXcctXRgjH3OlX3A2Uvf+yHvHz4k83Q2YxZ3EH7g=; b=b7Gkm1LV1B6caEeTpvHPEmpFVb 0pFIndce3oWA5jGg1QoCid1wIzUY9J+JVrP8t17/9ZHTpdaMHJAxMJi6g+S7HztB9vCpxTXFbmc/6 9Yz6Gc0kfObG8fbuXodKghyGExJSeB1ksYLSG7U5jc4/19G4oU29LjWmQtDkayU6Xdfo=; From: Paul Durrant To: xen-devel@lists.xenproject.org Subject: [PATCH v3 2/2] x86/hvm: simplify 'mmio_direct' check in epte_get_entry_emt() Date: Fri, 31 Jul 2020 15:26:04 +0100 Message-Id: <20200731142604.30149-3-paul@xen.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200731142604.30149-1-paul@xen.org> References: <20200731142604.30149-1-paul@xen.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Andrew Cooper , Paul Durrant , Wei Liu , Jan Beulich , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) From: Paul Durrant Re-factor the code to take advantage of the fact that the APIC access page = is a 'special' page. The VMX code is left alone and hence the APIC access page= is still inserted into the P2M with type p2m_mmio_direct. This is left alone a= s it is not obvious there is another suitable type to use, and the necessary re-ordering in epte_get_entry_emt() is straightforward. Suggested-by: Jan Beulich Signed-off-by: Paul Durrant --- Cc: Jan Beulich Cc: Andrew Cooper Cc: Wei Liu Cc: "Roger Pau Monn=C3=A9" v2: - New in v2 v3: - Re-base - Expand commit comment --- xen/arch/x86/hvm/mtrr.c | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/xen/arch/x86/hvm/mtrr.c b/xen/arch/x86/hvm/mtrr.c index 26721f6ee7..cfdbcbfef1 100644 --- a/xen/arch/x86/hvm/mtrr.c +++ b/xen/arch/x86/hvm/mtrr.c @@ -814,23 +814,13 @@ int epte_get_entry_emt(struct domain *d, unsigned lon= g gfn, mfn_t mfn, return -1; } =20 - if ( direct_mmio ) - { - if ( (mfn_x(mfn) ^ mfn_x(d->arch.hvm.vmx.apic_access_mfn)) >> orde= r ) - return MTRR_TYPE_UNCACHABLE; - if ( order ) - return -1; - *ipat =3D 1; - return MTRR_TYPE_WRBACK; - } - if ( !mfn_valid(mfn) ) { *ipat =3D 1; return MTRR_TYPE_UNCACHABLE; } =20 - if ( !is_iommu_enabled(d) && !cache_flush_permitted(d) ) + if ( !direct_mmio && !is_iommu_enabled(d) && !cache_flush_permitted(d)= ) { *ipat =3D 1; return MTRR_TYPE_WRBACK; @@ -847,6 +837,9 @@ int epte_get_entry_emt(struct domain *d, unsigned long = gfn, mfn_t mfn, } } =20 + if ( direct_mmio ) + return MTRR_TYPE_UNCACHABLE; + gmtrr_mtype =3D hvm_get_mem_pinned_cacheattr(d, _gfn(gfn), order); if ( gmtrr_mtype >=3D 0 ) { --=20 2.20.1