[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH] x86/ept: simplify detection of special pages for EMT calculation
- To: xen-devel@xxxxxxxxxxxxxxxxxxxx
- From: Roger Pau Monne <roger.pau@xxxxxxxxxx>
- Date: Fri, 23 Sep 2022 12:56:48 +0200
- Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=citrix.com; dmarc=pass action=none header.from=citrix.com; dkim=pass header.d=citrix.com; arc=none
- Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=7fAJBf7y+p80xGCoM1HkmotHKEEUd2bdFx1zNnIlwxM=; b=SYs270M6XGeOMAjHhYcwg6w2eXPZRgiPxHDu/L2xzMu737Wfqbsh10y+MUmSMcjK0ypjTkiFqZQ4t2ux/tXzLhdokVDqmhfFiyf82GdUPySyye+a8l5bt9Yrd+3GsheWkLhmi2A0UItKy2kFjzNw5duuWCGZfJGyCCisnlBxB8TVl2seBDjuq0iGmB3S8K0P3dI7K/SEqkYJSQ4OU6p8nXiXNgl1jq1ZfFVh3PBwtoFeeNJW1fEBDbDCgBGbz4ZLwxIXh/RCx40l2bmoaNTnwi/SdpDQbgFL+o2Ev3J+NydhHnUbE1DJiA2KJkAEV/f6NVatQe1UcKDSesmi6n+m7A==
- Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Vkm30OQAaYK7L9W8ahCWPTC0gbc03Yz/ccPvoo8lwYGeT4Din71CQ49NZtYljuTDw6HjGhd+QDYZcSGStiRJXaSl3Pcn93jduYbswxruanZIU1VxdJCHz5Wmxf73Mn5Ls5CAXQys+LrVSGitwBMYrDUI9L61cJes3rkxNwmInXCt63lhFszyOeIylD4of/Fu9ST/Ui8HckXKmK+eVTyqrRSYU8yghhu5bkOxTswbGmam6hEYLPHcD+1eIrGnpawidkuasPKL23uKDwlZ9xtxve3aTFcwNZCMuZWy320NDCcthUSManpa0YeszKXzVceLWiCmaqeIEwzfWlkQESjh1w==
- Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=citrix.com;
- Cc: Roger Pau Monne <roger.pau@xxxxxxxxxx>, Jun Nakajima <jun.nakajima@xxxxxxxxx>, Kevin Tian <kevin.tian@xxxxxxxxx>, Jan Beulich <jbeulich@xxxxxxxx>, Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, George Dunlap <george.dunlap@xxxxxxxxxx>, Wei Liu <wl@xxxxxxx>
- Delivery-date: Fri, 23 Sep 2022 10:57:08 +0000
- Ironport-data: A9a23:h48JaKxnjH4TJCdi79R6t+f2xyrEfRIJ4+MujC+fZmUNrF6WrkUDy GsaUTiDMqmCYTagKtx+Oo7g8R4C6MfVm9AyGVNtrSAxQypGp/SeCIXCJC8cHc8zwu4v7q5Dx 59DAjUVBJlsFhcwnj/0bv676yEUOZigHtLUEPTDNj16WThqQSIgjQMLs+Mii8tjjMPR7zml4 LsemOWCfg7+s9JIGjhMsfjb+Uk05K6aVA4w5TTSW9ga5DcyqFFNZH4vDfnZB2f1RIBSAtm7S 47rpF1u1jqEl/uFIorNfofTKiXmcJaLVeS9oiM+t5yZqgpDvkQPPpMTb5LwX6v1ZwKhxLidw P0V3XC5pJxA0qfkwIzxWDEAe81y0DEvFBYq7hFTvOTKp3AqfUcAzN1MKlEWErQo+NwnOnBKr NsoKh8GazKq0rfeLLKTEoGAh+wFBeyyZsY6hSslyjvUS/E7XZrEXqPGo8dC2ys9jdxPGvCYY NcFbT1ob1LLZBgn1lU/Ucpi2rv3wCehNWEFwL6WjfNfD2z71gt+3aKrKNPIUteLWd9UjgCTo WeuE2HRUkhEb4TBlWHtHnSEgs2RtiL/Wq0oKqzkxs9G3F694GgsB0hDPbe8ibzj4qKkYPpPJ kpR9icwoKwa8E2wUsK7TxC+uGSDvBMXR5xXCeJSwAOQzOzS6gWQBGkBRxZAbsArsIk9QjlC/ lyEgdLvQyBuubu9SHSB+7PSpjS3UQAXJ2IfYS4PTSMe/sLu5oo0i3rnUdJLAKOzyNrvFlnNL yuiqSE/g/AWkpQN3qDip1Tf2Wrw+97OUxI/4RjRUiS99ARlaYW5Zouur1/G8fJHK4XfRV6E1 JQZp/WjACk1JcnlvESwrC8lR9lFO97t3OXgvGNS
- Ironport-hdrordr: A9a23:Fc6o6qzEH5O4Vk+VTtd9KrPxyuskLtp133Aq2lEZdPULSKGlfp GV9sjziyWetN9wYh4dcB67Scu9qBTnhOZICOgqTM6ftWzd1FdAQ7sSibcKrweBJ8SczJ8h6U 4fSdkYNDSYNzET46fHCWGDYqwdKbK8gcWVbInlvhRQpVYAUdAa0+41MHftLqUwLzM2dKYRJd 653I5qtjCgcXMYYoCSAWQEZfHKo5numIj9aRALKhY74E3W5AnYoYLSIly95FMzQjlPybAt/S zslBH43Lyqt7WexgXH32HewpxKkJ/Ky8dFBuaLls8JQw+c/DqAVcBEYfmvrTo1qOag5BIDl8 TNmQ4pO4BJ53bYbgiO0GnQ8jil9Axrx27pyFeej3emi9f+XigGB81Igp8cWgfF6mI71esMnZ 5j7ia8jd56HBnAlCPy65zjTBdxjHe5pnIkjKo6k2Ffa40Dc7VcxLZvtn+9KK1wUx4S1bpXXt WHVKrnlbdrmBKhHjvkV1BUsZCRti9ZJGbHfqAA0vbloAS+0koJjHfw//Zv4EvoxKhNN6Ws2N 60TZiA7Is+KPP+TZgNcdvpEvHHflDlcFbrDF+4B2jBOeUuB0/twqSHkIndotvaMKA18A==
- List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
The current way to detect whether a page handled to
epte_get_entry_emt() is special and needs a forced write-back cache
attribute involves iterating over all the smaller 4K pages for
superpages.
Such loop consumes a high amount of CPU time for 1GiB pages (order
18): on a Xeon® Silver 4216 (Cascade Lake) at 2GHz this takes an
average amount of time of 1.5ms. Note that this figure just accounts
for the is_special_page() loop, and not the whole code of
epte_get_entry_emt(). Also the resolve_misconfig() operation that
calls into epte_get_entry_emt() is done while holding the p2m lock in
write (exclusive) mode, which blocks concurrent EPT_MISCONFIG faults
and prevents most guest hypercalls for progressing due to the need to
take the p2m lock in read mode to access any guest provided hypercall
buffers.
Simplify the checking in epte_get_entry_emt() and remove the loop,
assuming that there won't be superpages being only partially special.
So far we have no special superpages added to the guest p2m, and in
any case the forcing of the write-back cache attribute is a courtesy
to the guest to avoid such ranges being accessed as uncached when not
really needed. It's not acceptable for such assistance to tax the
system so badly.
Fixes: 60d1adfa18 ('x86/ept: fix shattering of special pages')
Fixes: ca24b2ffdb ('x86/hvm: set 'ipat' in EPT for special pages')
Signed-off-by: Roger Pau Monné <roger.pau@xxxxxxxxxx>
---
xen/arch/x86/mm/p2m-ept.c | 24 ++++++++----------------
1 file changed, 8 insertions(+), 16 deletions(-)
diff --git a/xen/arch/x86/mm/p2m-ept.c b/xen/arch/x86/mm/p2m-ept.c
index b4919bad51..d0e1c31612 100644
--- a/xen/arch/x86/mm/p2m-ept.c
+++ b/xen/arch/x86/mm/p2m-ept.c
@@ -491,7 +491,6 @@ int epte_get_entry_emt(struct domain *d, gfn_t gfn, mfn_t
mfn,
{
int gmtrr_mtype, hmtrr_mtype;
struct vcpu *v = current;
- unsigned long i, special_pgs;
*ipat = false;
@@ -518,26 +517,19 @@ int epte_get_entry_emt(struct domain *d, gfn_t gfn, mfn_t
mfn,
return MTRR_TYPE_UNCACHABLE;
}
- if ( type != p2m_mmio_direct && !is_iommu_enabled(d) &&
- !cache_flush_permitted(d) )
+ if ( (type != p2m_mmio_direct && !is_iommu_enabled(d) &&
+ !cache_flush_permitted(d)) ||
+ /*
+ * Assume the whole page to be special if the first 4K chunk is:
+ * iterating over all possible 4K sub-pages for higher order pages is
+ * too expensive.
+ */
+ is_special_page(mfn_to_page(mfn)) )
{
*ipat = true;
return MTRR_TYPE_WRBACK;
}
- for ( special_pgs = i = 0; i < (1ul << order); i++ )
- if ( is_special_page(mfn_to_page(mfn_add(mfn, i))) )
- special_pgs++;
-
- if ( special_pgs )
- {
- if ( special_pgs != (1ul << order) )
- return -1;
-
- *ipat = true;
- return MTRR_TYPE_WRBACK;
- }
-
switch ( type )
{
case p2m_mmio_direct:
--
2.37.3
|