From nobody Sat Apr 20 01:35:17 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=1596206496; cv=none; d=zohomail.com; s=zohoarc; b=ehM/79NUUCXo6Puc350bdQSmTdsofQLO2bqr6Dzfl+dSCF5Sd5FYyIq+nHoykZ0EqhcHEhz2Q9PQ1x70TLznE7KbjbhZ4P/zPmW8J1crGxqOB3GmiBcSGVD13djyCNJ34U2KVDU/vsOefdB3+5XVng5V4XuFQIMUb5dhO1oBzfA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1596206496; 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=F+vgTGWDObAevSQByeyw/+lv31YkNMVYZOrPyWpXIeA=; b=b0c8vAX2TXKRQJKYesaz5+lJENerxZe4WH0RAlNbd7VvIcHxzDbh/sWBrmQHzbqFsQFtu3NrudyEJ2y5XcRrQliV+bVKz7U7q/7HZPlz5AMqzkb8x9mr3Uwx+xpGhrvYeir99CosNw4NfAdKR/XOQ6/0yY7p83NIEyZHcOM54CQ= 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 1596206496510710.9364155757249; Fri, 31 Jul 2020 07:41:36 -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 1k1WDm-0006Fu-Mp; Fri, 31 Jul 2020 14:41:18 +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 1k1WDl-0006FY-Fg for xen-devel@lists.xenproject.org; Fri, 31 Jul 2020 14:41:17 +0000 Received: from mail.xenproject.org (unknown [104.130.215.37]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id e3a77dd8-d33b-11ea-abc5-12813bfff9fa; Fri, 31 Jul 2020 14:41:16 +0000 (UTC) Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1k1WDj-0003vN-S1; Fri, 31 Jul 2020 14:41:15 +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 1k1WDj-0006lb-Io; Fri, 31 Jul 2020 14:41:15 +0000 X-Inumbo-ID: e3a77dd8-d33b-11ea-abc5-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=F+vgTGWDObAevSQByeyw/+lv31YkNMVYZOrPyWpXIeA=; b=ZLpOEHJ+BtbCrYYkYntQsixiu4 SyzK1qEal3meY6t1/Ol4ddHkSsfrkDvhR5a2VCdo8X3SexoGSV8bE81CQQ2jfqQD7Lj19y7By291x nLz8DVke/6iicZI8wGNKwoX+fs7f0eVjA4oPB3uM8C+wGcreqjIOvx+DNX070ZCPR3OQ=; From: Paul Durrant To: xen-devel@lists.xenproject.org Subject: [PATCH v4 1/2] x86/hvm: set 'ipat' in EPT for special pages Date: Fri, 31 Jul 2020 15:41:11 +0100 Message-Id: <20200731144112.12516-2-paul@xen.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200731144112.12516-1-paul@xen.org> References: <20200731144112.12516-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 Reviewed-by: Jan Beulich --- 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 v4: - Add missing hunk --- xen/arch/x86/hvm/mtrr.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/xen/arch/x86/hvm/mtrr.c b/xen/arch/x86/hvm/mtrr.c index 511c3be1c8..2bd64e8025 100644 --- a/xen/arch/x86/hvm/mtrr.c +++ b/xen/arch/x86/hvm/mtrr.c @@ -794,6 +794,7 @@ int epte_get_entry_emt(struct domain *d, unsigned long = gfn, mfn_t mfn, { int gmtrr_mtype, hmtrr_mtype; struct vcpu *v =3D current; + unsigned long i; =20 *ipat =3D 0; =20 @@ -836,6 +837,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 Sat Apr 20 01:35:17 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=1596206499; cv=none; d=zohomail.com; s=zohoarc; b=Bav6serrPqK7loEyTcyKCWlb/Heeo79avsOF8SVJEAuzHpjQ4kYtChSL69A53DSB7T2ru8W7TVDNY7agPC60DjXQkNv4gd3GjjK66sMKNSXtCOIVhBaJqWFGSZVwSI4sEK0FJQ5AJfifmVF1P1u4ocfG6clGv47kSJh8BF737hQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1596206499; 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=sRZ/84+z2kLbSeOy0XdjBV2qQku1iCduFJndgVP5MXY=; b=MK7Rmr05hGAW6Yqfi2VoX8GSfHUppqZkyceQiJDBtoxPgd3Kq1h0wn7yzh+eo7I9pzVgSndhrIgBQakFii/cTM2xUxtMYtXL2wsjD6+5HOCdflS1hLdZrLGLaCX78EtDvQ8u/VlDmYQo/7lhfxXw7z7yILhKXyHENOPnWWBDxwk= 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 1596206499521772.9076563393263; Fri, 31 Jul 2020 07:41:39 -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 1k1WDs-0006HE-0N; Fri, 31 Jul 2020 14:41:24 +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 1k1WDq-0006FY-EC for xen-devel@lists.xenproject.org; Fri, 31 Jul 2020 14:41:22 +0000 Received: from mail.xenproject.org (unknown [104.130.215.37]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id e3786e27-d33b-11ea-abc5-12813bfff9fa; Fri, 31 Jul 2020 14:41:17 +0000 (UTC) Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1k1WDk-0003vR-Ns; Fri, 31 Jul 2020 14:41:16 +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 1k1WDk-0006lb-Ga; Fri, 31 Jul 2020 14:41:16 +0000 X-Inumbo-ID: e3786e27-d33b-11ea-abc5-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=sRZ/84+z2kLbSeOy0XdjBV2qQku1iCduFJndgVP5MXY=; b=0LxHB8JSYw88f3jzZO6QHD4VOC qZWFFmlZuEr7nuZvOsT70QpeqFCcDq1bN1MMxZOPGh9nJNF+PIcO8sKA/HoPPux2OgIL+MY4eGv3F MHMnmTPGkAH62ccWYICnnETuVIN/oLCzNDJbvYlX5sMszXzxVAgU6kkGdIBE7nyFGRFQ=; From: Paul Durrant To: xen-devel@lists.xenproject.org Subject: [PATCH v4 2/2] x86/hvm: simplify 'mmio_direct' check in epte_get_entry_emt() Date: Fri, 31 Jul 2020 15:41:12 +0100 Message-Id: <20200731144112.12516-3-paul@xen.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200731144112.12516-1-paul@xen.org> References: <20200731144112.12516-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 Reviewed-by: Jan Beulich --- 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 2bd64e8025..fb051d59c3 100644 --- a/xen/arch/x86/hvm/mtrr.c +++ b/xen/arch/x86/hvm/mtrr.c @@ -815,23 +815,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; @@ -848,6 +838,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