From patchwork Thu Jun 30 16:34:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Roger_Pau_Monn=C3=A9?= X-Patchwork-Id: 12902023 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E45EAC43334 for ; Thu, 30 Jun 2022 16:35:48 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.358603.587871 (Exim 4.92) (envelope-from ) id 1o6x8L-0001Fl-Fq; Thu, 30 Jun 2022 16:35:13 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 358603.587871; Thu, 30 Jun 2022 16:35:13 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1o6x8L-0001Fe-CC; Thu, 30 Jun 2022 16:35:13 +0000 Received: by outflank-mailman (input) for mailman id 358603; Thu, 30 Jun 2022 16:35:11 +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 1o6x8J-0001FY-TK for xen-devel@lists.xenproject.org; Thu, 30 Jun 2022 16:35:11 +0000 Received: from esa4.hc3370-68.iphmx.com (esa4.hc3370-68.iphmx.com [216.71.155.144]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 9afe375e-f892-11ec-bd2d-47488cf2e6aa; Thu, 30 Jun 2022 18:35:10 +0200 (CEST) Received: from mail-bn8nam12lp2173.outbound.protection.outlook.com (HELO NAM12-BN8-obe.outbound.protection.outlook.com) ([104.47.55.173]) by ob1.hc3370-68.iphmx.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 30 Jun 2022 12:35:04 -0400 Received: from DS7PR03MB5608.namprd03.prod.outlook.com (2603:10b6:5:2c9::18) by DM6PR03MB5370.namprd03.prod.outlook.com (2603:10b6:5:249::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5395.15; Thu, 30 Jun 2022 16:35:02 +0000 Received: from DS7PR03MB5608.namprd03.prod.outlook.com ([fe80::40af:d5f4:95eb:d534]) by DS7PR03MB5608.namprd03.prod.outlook.com ([fe80::40af:d5f4:95eb:d534%7]) with mapi id 15.20.5395.015; Thu, 30 Jun 2022 16:35:02 +0000 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: 9afe375e-f892-11ec-bd2d-47488cf2e6aa DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1656606910; h=from:to:cc:subject:date:message-id: content-transfer-encoding:mime-version; bh=X+eLrljL64bpjt76Hwz9sQQv29FUkblb4AZb55DcfGI=; b=R9y3WVGd/qsMN5mp3WeGX0cdrMshS8VyA6Il8oAg8d+j2NczSiDmjSSl oNxYZPvVX1jOteRBFGW/KNXDLYcgtPaEsMscv/QQEVm/reBIHPLCbgaBj CISIhR/0GpGtvAxFwd1f1AbUMb7IbqWfK8shfwijKDU33U9VmLaRMT2Dh 8=; X-IronPort-RemoteIP: 104.47.55.173 X-IronPort-MID: 77384588 X-IronPort-Reputation: None X-IronPort-Listener: OutboundMail X-IronPort-SenderGroup: RELAY_O365 X-IronPort-MailFlowPolicy: $RELAYED IronPort-Data: A9a23:luvlyq82OP4WBDwf/I4xDrUDqH+TJUtcMsCJ2f8bNWPcYEJGY0x3x 2oaUDjXOayJYWryedt+bY218x8F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7qHml/2g0BfT20La8pwTstr8zdloAtCKl6EuW0PRozftQL4kd6yJvTgzru3qwFE2kO PUqxNlBMh342O5RBDGnTLdny3blBo+4X7rzlGVxVH5p9bieT48A81dwapEbxrw8SMbzZxB+Z MO+1jcm4tcDBvGkii4zcPPTQtWmk29pmdnufIPjkZYTZAVZNZq3MYiFXtuYdg99R/Bmc4a+L EENrCc2B8WSyLQU5nhhBgi/DT2NU5DXitvQSA5y7+oOnZt7TNEJnAjtbMid0c7he4AoqZ/lp r529xT5ddzp+8tHNdA7bQ6ML+KI12IZy7wG0SvBnmiPJ07Ghv22u7KCfMOlamXRKA= X-IronPort-AV: E=Sophos;i="5.92,234,1650945600"; d="scan'208";a="77384588" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=EC8QX6v46FoxLNJJ68ax0EsV9P8VoD2CwDV2BxqZvtquGdlhtx4S4f0ylz0GCWBnZ2G767vLHcBQcEJZpqCjqPSvwhGWYWKtj/plI7SIKSMd5E45pCh/doRTinzppV6QaasvLJGK90pgPECcq42dRAD/bRiPELH1m0AUWyV27Q2RmX4AVTV8n0ck/7v5NSL7uvzeRQiGKMY/7+NySOszLOcy7+MZsRhMl3LsaKvYNntoBXrJdhYHqKCromuPa7eIkdE8KZepeOUJSXVi6QSJG0s+/aomCmaKVJO4mgNT5yv+I35ajabxEIciHOWgxOcn+bZqZKT/H++Ks+zY5ZstEw== 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=oX3URqPsbJ7y/iaNrL25B7p6kAIWUNzEoNnUrhhwRG8=; b=VPO5AEl7M9pWP6UfA66+ZeVqreWI8of5TutfyQMxIHAQTOdma0gEGQKwMU8VjwsjBdZ95wQtj7sdwk5lszFGzbfBV1Oaa1hy2ky24ZL/wl//HZVo1EWzpViHe9C4QECHInOhCyqInXuv5PXFYz4dE9dw0OwskOB2zJR+pnfEMVzZf5brgIkUjKk1t/JaK4cu+H3Tgrlfpc2vd5loNKGf5wcGkdhSi/fhx0KBvHpVhjlyHDbW3Biu+PjxaMGEX5xtwJuDegGEsWt4z2hwu35EweQc4Mz75aCRgXWV6UlrBXrRcLoITsbrpIiSS0qb1ZFz+x/3Pdh3kjdpVwmmIN90nQ== 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 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.onmicrosoft.com; s=selector2-citrix-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=oX3URqPsbJ7y/iaNrL25B7p6kAIWUNzEoNnUrhhwRG8=; b=GNmMoqEXNMk4AUOMGdlTFYaTjtTUpUqzxxUpljvuRf5Fnjy8Y71XYov/geUJzh6LsxfkTlNGS8Rcw0klo1IbBWINiJxuFXArBTvkHe0xAR1JTG9FBMIxN3SdT+WAIrE4a1/jj1OFgxOK0aOuESbpk200tjDRYRUUoYQb6/rNo3Y= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=citrix.com; From: Roger Pau Monne To: xen-devel@lists.xenproject.org Cc: Roger Pau Monne , Jun Nakajima , Kevin Tian , Jan Beulich , Andrew Cooper , George Dunlap , Wei Liu , Paul Durrant Subject: [PATCH v2] x86/ept: fix shattering of special pages Date: Thu, 30 Jun 2022 18:34:49 +0200 Message-Id: <20220630163449.18714-1-roger.pau@citrix.com> X-Mailer: git-send-email 2.37.0 X-ClientProxiedBy: LO2P265CA0348.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:d::24) To DS7PR03MB5608.namprd03.prod.outlook.com (2603:10b6:5:2c9::18) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 758738ce-329b-4c36-bd2b-08da5ab67b13 X-MS-TrafficTypeDiagnostic: DM6PR03MB5370:EE_ X-LD-Processed: 335836de-42ef-43a2-b145-348c2ee9ca5b,ExtAddr X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ziep0BtSR7V/e/WhIAxnBOwoeBc+jq6mwQGe4QaAQThJEzt1N+hQW3P2yPq+44f6uJnMNPH6lIAquQRTJlRfSyaJ9x/agrziWaTeUVcfa77y4e6545LXCoWhOSzQgE6xfpFiSILhg/81Icw42xFat4aMn3jgWf5qQFn15yndEQdhdComm3tpb8n/zj47aWOEyM5AS+oub2vpUcZxDNbVDwEpfu+YC8k3APau6/OfzRee6vfC5GAbipMikwIUvxnHt3zbpNs1+wcimM3plWmRUeat4WiQCVrue//7XHxb58ajymrr55kX6xAmpl9KZpFasc6TY3a7Fb4nZ1Ne7wvaW5v22Urm4vP+DSKL3o4aog8PlC8XuvHVw8vZ6vXlk8wg2Tyd+1Ngjh4WrqYY+i1VJbv92mpIUyMGdRKwn/n9EEmgUHlT5tgyCVjGPtTY8/Gil4tWL2ai9Xll5KBauMCgSuDpbZsNDxaluWsxA49PAfSDJtt151zoPWZ76/iQFjhYGQ9UC2UnKmF2COhQPILjNifdTXYzul6Nstc0MnFXgQAhxX3QPAoNlofUNDF1zSF2HjjDirhSUF3z5dguh1k1TTSJLp+c2BaXEF4Z874niqFtFyOoBhqxXb2Ucqof77QPNbMa/ncUraPnwbzIwzJjreRSCCsfHR7XP/JKKWH3hY+neRuZ84jzr+DJeTU6AoJllSjMUVVHryH9CpSgBgUgxct+MWuhM2SrWVtA+OEKMhbHJ5HmvQYN5M+CH0vkji2w X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DS7PR03MB5608.namprd03.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230016)(4636009)(346002)(366004)(396003)(136003)(39860400002)(376002)(186003)(6486002)(478600001)(83380400001)(82960400001)(38100700002)(2616005)(54906003)(8676002)(4326008)(6916009)(1076003)(316002)(66556008)(66476007)(66946007)(5660300002)(6506007)(6512007)(26005)(8936002)(41300700001)(86362001)(6666004)(2906002)(36756003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?t1OFQ03RKxTF/Vr3ayACcs5Hkp/p?= =?utf-8?q?yeH+sqzLXhLBdsSEoWiXIn9vcMwmhG7aQWHJw+Y6Lsj0zF7QPDVvrZy3jflBzlLCZ?= =?utf-8?q?kSffqR6iLwGb2z5i2tFi0QXQ1W1f79BLcgIUekaduYbHH3MzWvU+20a9N+5CZUDK9?= =?utf-8?q?dC68kScfR8XzvVyH35MYcEn8krkRWAt7gExZfZV3vyZWUCf4fPH1+Umh/h5s5CKMA?= =?utf-8?q?m1gAMOMtzDK3A21CiyUzHdFEsD3InB8/PdYCbMhQkVU2vfFDC5OaQz/YY/VpH+Dk2?= =?utf-8?q?wdE00sLgVlkn51mZ9seGvoh4iG/BEYv/ruRABaTxlgeYmtwnMwGjTphLdZ1SqZvi8?= =?utf-8?q?r4pGQTV+AkIvn0H0acJRGrfEczMV7f4CRUPOdNF2zQXYCMtV1qPLws7haTrBYR0KJ?= =?utf-8?q?wByGXVQim/qsesVUv1nBYcQ5mU8eu9PBFv97AXceEo9uzarkFP3Z4PVqPXAwHhNyU?= =?utf-8?q?BLbYZAOxbSOb6ytiIC6SOZLTygoWLP7lganxHC4NbLXlu8kMxG4lJcbXxPRtzaheY?= =?utf-8?q?hhWip+VFA+X/ijOelpNPS0jTj6Nx0CatN3tjqLngPtuutPf4o8nmUIhUJMmgG06XS?= =?utf-8?q?BnTCd856eC4ys4Fk9mIUD1/lMo0/lZpoq5/EOG8xT/rXnct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fr3HyTXoS5y00sdkD?= =?utf-8?q?HWJPhr86n9SSSAWp6I6VQhR5GnKwTBJ2kw=3D=3D?= X-OriginatorOrg: citrix.com X-MS-Exchange-CrossTenant-Network-Message-Id: 758738ce-329b-4c36-bd2b-08da5ab67b13 X-MS-Exchange-CrossTenant-AuthSource: DS7PR03MB5608.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Jun 2022 16:35:02.4128 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 335836de-42ef-43a2-b145-348c2ee9ca5b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: GbneLPYMsstoEqJvWgUGpjAk1QTEIJ93PTKXObv8v6hkFfUivRTtL4M2+mR/O0P62y3Gs3//iFBdsGNVkEO84A== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR03MB5370 The current logic in epte_get_entry_emt() will split any page marked as special with order greater than zero, without checking whether the super page is all special. Fix this by only splitting the page only if it's not all marked as special, in order to prevent unneeded super page shuttering. The unconditional special super page shattering has caused a performance regression on some XenServer GPU pass through workloads. Signed-off-by: Roger Pau Monné Reviewed-by: Jan Beulich Reviewed-by: Kevin Tian --- Cc: Paul Durrant --- xen/arch/x86/mm/p2m-ept.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/xen/arch/x86/mm/p2m-ept.c b/xen/arch/x86/mm/p2m-ept.c index b04ca6dbe8..b4919bad51 100644 --- a/xen/arch/x86/mm/p2m-ept.c +++ b/xen/arch/x86/mm/p2m-ept.c @@ -491,7 +491,7 @@ 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; + unsigned long i, special_pgs; *ipat = false; @@ -525,15 +525,17 @@ int epte_get_entry_emt(struct domain *d, gfn_t gfn, mfn_t mfn, return MTRR_TYPE_WRBACK; } - for ( i = 0; i < (1ul << order); i++ ) - { + for ( special_pgs = i = 0; i < (1ul << order); i++ ) if ( is_special_page(mfn_to_page(mfn_add(mfn, i))) ) - { - if ( order ) - return -1; - *ipat = true; - return MTRR_TYPE_WRBACK; - } + special_pgs++; + + if ( special_pgs ) + { + if ( special_pgs != (1ul << order) ) + return -1; + + *ipat = true; + return MTRR_TYPE_WRBACK; } switch ( type )