From patchwork Fri May 27 11:19:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jan Beulich X-Patchwork-Id: 12863308 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 B05FDC433FE for ; Fri, 27 May 2022 11:21:54 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.338023.562783 (Exim 4.92) (envelope-from ) id 1nuY2B-0006tT-QV; Fri, 27 May 2022 11:21:35 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 338023.562783; Fri, 27 May 2022 11:21:35 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nuY2B-0006tE-MX; Fri, 27 May 2022 11:21:35 +0000 Received: by outflank-mailman (input) for mailman id 338023; Fri, 27 May 2022 11:21:34 +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 1nuY0j-0003mu-8i for xen-devel@lists.xenproject.org; Fri, 27 May 2022 11:20:05 +0000 Received: from de-smtp-delivery-102.mimecast.com (de-smtp-delivery-102.mimecast.com [194.104.111.102]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id f366a85b-ddae-11ec-837f-e5687231ffcc; Fri, 27 May 2022 13:20:02 +0200 (CEST) Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05lp2104.outbound.protection.outlook.com [104.47.17.104]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id de-mta-44-_zmL6YhwNZuTX0hg1el-9g-1; Fri, 27 May 2022 13:19:58 +0200 Received: from VE1PR04MB6560.eurprd04.prod.outlook.com (2603:10a6:803:122::25) by AM6PR04MB5831.eurprd04.prod.outlook.com (2603:10a6:20b:a8::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5293.13; Fri, 27 May 2022 11:19:57 +0000 Received: from VE1PR04MB6560.eurprd04.prod.outlook.com ([fe80::dfa:a64a:432f:e26b]) by VE1PR04MB6560.eurprd04.prod.outlook.com ([fe80::dfa:a64a:432f:e26b%7]) with mapi id 15.20.5293.013; Fri, 27 May 2022 11:19:56 +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: f366a85b-ddae-11ec-837f-e5687231ffcc DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=mimecast20200619; t=1653650401; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ccB0FqtHHL8l/2emiNG86bYyLELu/eicE503PEmq7h8=; b=WjtNNSvpY6yp+prMCXRILKROyfcjL4tXe0VB+hPcTFVjkTfW3jdXuirSKVghZEHoVdLFEg UuR0EDWa/+0kZOF7OeZ2LpfkQbiMMG8w/DHlw9iqs/nfoI+M7T+eF4M13DCjKer//l75pu 6idjsOhCierLIjThgA8W+F2hsmxW3UY= X-MC-Unique: _zmL6YhwNZuTX0hg1el-9g-1 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=hqcgB5aCd9CfB+WL5HOGL6Ua+tmEhP2YNYTgvtbV4alIZ+OZcYK3mUBuy8Hqd+3zhjB/b8PfCnGg7rZlkOTVDJucdOPfJMeK611Oq7DFaJA3zEn2jTj8cs5E1mgLbwLS+Zs8zgVo7BEJzQ+EpKZ83rRZnVyXHSknd/czI9joQB74mg2x4gqsT3hC84oati0FtEiKSVeVxNfIViMnjW3lHXLZ3k8Htk1GXw6814704dd4NEcIdZ72teIv8kQ5dlg2+1SBxPltuolMTCFD9rQHhC3OzyP/zzgPpruh4LhdKfmtEpd5vQUBizyN+PGlcWBkHo6Wi9+3seum3afkSfKYGg== 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=ccB0FqtHHL8l/2emiNG86bYyLELu/eicE503PEmq7h8=; b=nR2wIqM8czn0wSh7TaziZ3IEC04OaQprfOliqW78kHzM2XWN3CTwdZIBs1ygUI0Q0YOFiEEA9JYB+aGkAyx5t3zIz6F91ydM4NhL9lrvnvYMKBIUxsXDS/72BpNy5WOE1D6g6g8rTrhNfQi0AKveXbOsyfk4Lx+cLAsJ/HtdKxCuQ2yEN/ptzP8g7mbdMLZdmkDGBZkUFjm/77br35ZOmBhTsxcK2vZLiKs3qMI+JNuu/z1Ah1oscZEer4J6rC+0FjIFKSWkaJnNIYm5ElvCe4+kvb7kkFs0T5kqFgZ4lmB8pEkDeNp1FgEqWcTlyyLf7WHxO3yIu6d7H4v8n2b0kw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=suse.com; dmarc=pass action=none header.from=suse.com; dkim=pass header.d=suse.com; arc=none Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com; Message-ID: Date: Fri, 27 May 2022 13:19:55 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.9.1 Subject: [PATCH v5 12/15] VT-d: replace all-contiguous page tables by superpage mappings Content-Language: en-US From: Jan Beulich To: "xen-devel@lists.xenproject.org" Cc: Andrew Cooper , Paul Durrant , =?utf-8?q?Roger_Pau_Monn=C3=A9?= References: <80448822-bc1c-9f7d-ade5-fdf7c46421fe@suse.com> In-Reply-To: <80448822-bc1c-9f7d-ade5-fdf7c46421fe@suse.com> X-ClientProxiedBy: AS9PR06CA0249.eurprd06.prod.outlook.com (2603:10a6:20b:45f::22) To VE1PR04MB6560.eurprd04.prod.outlook.com (2603:10a6:803:122::25) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: d92381c6-47a4-4cb9-8c1b-08da3fd2d48a X-MS-TrafficTypeDiagnostic: AM6PR04MB5831:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: W44r6fVakDa+hkDWyb6nmGlaZsN51S5U0drRzYW05Np8DYGEmw6yRUDhKLxyguTCq0YV0+5z/3IOD7CPdRGWVTqIuJJAQw+DYtns5Lejd3zPt1yLgE4S3CwndfdeD1rxfvtBuw/Kld+iXG9Sp4HmF5iKaKEhrzhaWPQDA5xLXRzJu7yRdoGcV9OzT5R04gsOfPgRvJBlNmMMfh7gn5E4C66Fla9s7l6iP74/gf+HITnsQNzZ2ylij4OF2r1jYZsCqX7k2FdPrAy+gM7q2pIp0NgLpKk7iXjh9G3HtGVzzIZgx5T8YfvxC3HhKXJEKLktZ+mdKWjcJGf1ZlsUiFCfwsUJqIG5fo7LXcO/HudW8XItA8j3bL00PEFu+HgsCLlnL8VGNiP12qLI58oTrRJxGvpsufDVdMcJQWutRE6Rv3lRDAoj28qoE6Hn4519gQKJ8mp8SQCEZkaOCLoFvkxoROIa/pCycHIu09kHIEU/G+b/9C39TlFUmToe/3Jnew2M9TJkSbCF/VXJ71w5VAKq4a+TsvODxkn9mntGTBdmUrWcpD622bSyZdNOEK0Zwxb1K5oAjsKoLg996bHMy7zu3lEKoX8zjhmve6RsP/cwzw23fybi0R11ob+eUNcyEUgYePKAieTI2mpV4mj/N99oaAss5mYo2FkHBK6PyC7hjkh5nN8ZnRMofqFydXCGePB7JnOmgQdYq9lpxdcsDS0S27K9mJb1rIsdxoeICNOGGZF1U//db7NVWgJRu2/dOQpI X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:VE1PR04MB6560.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230001)(366004)(6512007)(2616005)(26005)(6506007)(316002)(66556008)(66946007)(54906003)(508600001)(8676002)(4326008)(66476007)(6486002)(86362001)(38100700002)(31696002)(186003)(83380400001)(5660300002)(31686004)(2906002)(8936002)(36756003)(6916009)(45980500001)(43740500002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?pcNZvsMv5L1vkCF5BbrCLpOXAxSD?= =?utf-8?q?jjQ2bxq8EgNbYQHxFqGVsrgTPiAZkTcLh4wdJPoNawoTdEXnxNwJzMUjBWX/JnAAv?= =?utf-8?q?z36IELYaGctrb4/okx6yWwqEDOzEbciLohgzqHRVJu21jeWzJzIE0560qJKHthFes?= =?utf-8?q?S1kWwo/7TA5GwkQDJEYIOvw41nFL3ijktOO90QbwbTwt23r+S531jYu2whHdYGDYa?= =?utf-8?q?wr9N0b14h+FYXWl4AFdcbtW68I2/hNlwsBVw43gRBPWhWa/Sj856uya0BwpVW+U+P?= =?utf-8?q?xgA7CvPDQjhsoXANIgFYlECAwp5TIGjbhpv9wdxjH9bEUiJiDorLccA/0XMUhY1ae?= =?utf-8?q?XvCC8QUgrlS5nabi1qKxpciZ14qZw/OoBVIL9v2ImR3l77vYcZ8zEgHVtvHjl83SZ?= =?utf-8?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BTUnAQhLulQgFAqqqTZa06PiO/iGTNwBtEAgArQhl64SuM15SQuYkd?= =?utf-8?q?64NHuEr24UYTKdw57D3Hg7qqaiqgfXu19wLtSdL4siwZqfNzESTX4PcY/VluvqzQQ?= =?utf-8?q?jrdTWfD0Bwpsouojnl8F7+44K4CgpnmE3mnTy6JT7nLr2vFq8Ubc+lMflkwAorQHf?= =?utf-8?q?Vj/GPRF2KSTe8ZyEf9KdETmybsP6N1RklNYTEkQZcAgMg+Pro8WxTTPrAmm28nDz6?= =?utf-8?q?OpNNmLfBcWIiwpnhXS/sMbf1SfcpO8tJ/excZClJX/am3h5M5BSLHcWxwRWQi2CtV?= =?utf-8?q?aPPZCxM3eRAvnzaQVXy+0H58fvs5SEqtf7FM6RLFhCdwbAcLwZ180GIEfLCvd8MCO?= =?utf-8?q?Cx4Ld5IdG1G3U1oTtwZRUuiM3YcSN5SQ=3D=3D?= X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: d92381c6-47a4-4cb9-8c1b-08da3fd2d48a X-MS-Exchange-CrossTenant-AuthSource: VE1PR04MB6560.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 May 2022 11:19:56.9284 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: f7a17af6-1c5c-4a36-aa8b-f5be247aa4ba X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 0eIXHQ41+V/iIoSnDGdl0bfuYbSg5pZi2H/B+o7H0ccnlnE3+CoGnm1PcdQWnEq3R+xppYpntTmnTNSudMnkOg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR04MB5831 When a page table ends up with all contiguous entries (including all identical attributes), it can be replaced by a superpage entry at the next higher level. The page table itself can then be scheduled for freeing. The adjustment to LEVEL_MASK is merely to avoid leaving a latent trap for whenever we (and obviously hardware) start supporting 512G mappings. Note that cache sync-ing is likely more strict than necessary. This is both to be on the safe side as well as to maintain the pattern of all updates of (potentially) live tables being accompanied by a flush (if so needed). Signed-off-by: Jan Beulich Reviewed-by: Kevin Tian Reviewed-by: Roger Pau Monné --- Unlike the freeing of all-empty page tables, this causes quite a bit of back and forth for PV domains, due to their mapping/unmapping of pages when they get converted to/from being page tables. It may therefore be worth considering to delay re-coalescing a little, to avoid doing so when the superpage would otherwise get split again pretty soon. But I think this would better be the subject of a separate change anyway. Of course this could also be helped by more "aware" kernel side behavior: They could avoid immediately mapping freed page tables writable again, in anticipation of re-using that same page for another page table elsewhere. --- v4: Re-base over changes earlier in the series. v3: New. --- a/xen/drivers/passthrough/vtd/iommu.c +++ b/xen/drivers/passthrough/vtd/iommu.c @@ -2219,14 +2219,35 @@ static int __must_check cf_check intel_i * While the (ab)use of PTE_kind_table here allows to save some work in * the function, the main motivation for it is that it avoids a so far * unexplained hang during boot (while preparing Dom0) on a Westmere - * based laptop. + * based laptop. This also has the intended effect of terminating the + * loop when super pages aren't supported anymore at the next level. */ - pt_update_contig_markers(&page->val, - address_level_offset(dfn_to_daddr(dfn), level), - level, - (hd->platform_ops->page_sizes & - (1UL << level_to_offset_bits(level + 1)) - ? PTE_kind_leaf : PTE_kind_table)); + while ( pt_update_contig_markers(&page->val, + address_level_offset(dfn_to_daddr(dfn), level), + level, + (hd->platform_ops->page_sizes & + (1UL << level_to_offset_bits(level + 1)) + ? PTE_kind_leaf : PTE_kind_table)) ) + { + struct page_info *pg = maddr_to_page(pg_maddr); + + unmap_vtd_domain_page(page); + + new.val &= ~(LEVEL_MASK << level_to_offset_bits(level)); + dma_set_pte_superpage(new); + + pg_maddr = addr_to_dma_page_maddr(d, dfn_to_daddr(dfn), ++level, + flush_flags, false); + BUG_ON(pg_maddr < PAGE_SIZE); + + page = map_vtd_domain_page(pg_maddr); + pte = &page[address_level_offset(dfn_to_daddr(dfn), level)]; + *pte = new; + iommu_sync_cache(pte, sizeof(*pte)); + + *flush_flags |= IOMMU_FLUSHF_modified | IOMMU_FLUSHF_all; + iommu_queue_free_pgtable(hd, pg); + } spin_unlock(&hd->arch.mapping_lock); unmap_vtd_domain_page(page); --- a/xen/drivers/passthrough/vtd/iommu.h +++ b/xen/drivers/passthrough/vtd/iommu.h @@ -232,7 +232,7 @@ struct context_entry { /* page table handling */ #define LEVEL_STRIDE (9) -#define LEVEL_MASK ((1 << LEVEL_STRIDE) - 1) +#define LEVEL_MASK (PTE_NUM - 1UL) #define PTE_NUM (1 << LEVEL_STRIDE) #define level_to_agaw(val) ((val) - 2) #define agaw_to_level(val) ((val) + 2)