From patchwork Mon Apr 25 08:43:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Beulich X-Patchwork-Id: 12825411 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 65B39C433F5 for ; Mon, 25 Apr 2022 08:44:12 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.312588.529907 (Exim 4.92) (envelope-from ) id 1niuK0-0006wu-U9; Mon, 25 Apr 2022 08:43:52 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 312588.529907; Mon, 25 Apr 2022 08:43:52 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1niuK0-0006wn-Po; Mon, 25 Apr 2022 08:43:52 +0000 Received: by outflank-mailman (input) for mailman id 312588; Mon, 25 Apr 2022 08:43:51 +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 1niuJy-0005as-Th for xen-devel@lists.xenproject.org; Mon, 25 Apr 2022 08:43:51 +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 d3cfee6a-c473-11ec-8fc2-03012f2f19d4; Mon, 25 Apr 2022 10:43:49 +0200 (CEST) Received: from EUR01-DB5-obe.outbound.protection.outlook.com (mail-db5eur01lp2054.outbound.protection.outlook.com [104.47.2.54]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id de-mta-6-KWNPR1rNMOqmff3-3asZWQ-1; Mon, 25 Apr 2022 10:43:46 +0200 Received: from DU2PR04MB8616.eurprd04.prod.outlook.com (2603:10a6:10:2db::16) by AM5PR04MB2977.eurprd04.prod.outlook.com (2603:10a6:206:a::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5186.21; Mon, 25 Apr 2022 08:43:44 +0000 Received: from DU2PR04MB8616.eurprd04.prod.outlook.com ([fe80::5cb0:5195:4203:7c2f]) by DU2PR04MB8616.eurprd04.prod.outlook.com ([fe80::5cb0:5195:4203:7c2f%9]) with mapi id 15.20.5186.021; Mon, 25 Apr 2022 08:43:44 +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: d3cfee6a-c473-11ec-8fc2-03012f2f19d4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=mimecast20200619; t=1650876229; 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=2Ab4csObLsDUSWIHGU1Rqn2fo95dC4MwB105VQU6jBM=; b=kn/O4h13ccJFKgaYAjqdu5fZJ84HjjJ6DUjM69fBlyBzHxPTfaVvqNRSHylPD2P0b5nyjk snmaxc895CHDlCHzMIW7m+E9chm+9/oqQ1VuLcWVzUA31JaWipQJU62Uo5FJKHCCLVhGVs nB7yKUpDzmY+ObDwAN9JnpHfGpOHRz4= X-MC-Unique: KWNPR1rNMOqmff3-3asZWQ-1 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=c3sSYpQUGEe8oMQuLwpvxYE7IALALsYNSrxzciq44FAKisvIRZ21WAj4BL4oTKi8QCpEWU0nnfwqf2ofQVeAE2LWvgTcKUNpoII0ZDez+rWwtJz9dsY1WlciEu+eB1oSXMlwnQUQFX3g3bE7qqtWz9MQM6aVJ5+bfv2Z8gvFEmcq8RPw11SsYprDCRHsQrERLK8IHEO3SIsxvg/lbca+BxO4AcwSBSnqbIy76ZvoBFh65yKuEwwYPVYJVa5hhSfNO9q+rXZGAB6/Y7P+NHdWP6n9O3suJZWmRWm9CTfZOVpvqIHpsTrUSTeZxz+Rr8bBNU0BU67xRIctdAP4V1+ivw== 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=2Ab4csObLsDUSWIHGU1Rqn2fo95dC4MwB105VQU6jBM=; b=jtjTfb2Xv1Lwdusn/BqZi1ZpIp9lm18sqYVKaQv1dFoH9nReYaLSGs6LLAVl09Ywaz+i+PaPCtDXT4oIVCaTdgbvfkoj09R1xV3tNDujoh74pI8lfwszPjf4uSbo5+dwl6ycQrzh0lL2w50jbEp3JzXksnhBenr3bsHUFaThNk+IhD/vES4jpSXNdLEEx5eSgjUwigMS+yBeMX4QWMH36BOIvIKfGdCEgMc5TOxoGgZJYQbQlMku6KYnONiZAz0ABzv1YbDB8MklTazAukg5pELcBGh7bCH3f4vMmMZLvbfd0ajb8C0kDb6Xq3N2hXApCEEYkhiFTht+DCP1HVNdKg== 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: <98553b89-6296-9e4c-4677-9201cd7cdeef@suse.com> Date: Mon, 25 Apr 2022 10:43:45 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.8.1 Subject: [PATCH v4 18/21] 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?= , Kevin Tian References: In-Reply-To: X-ClientProxiedBy: AM7PR02CA0025.eurprd02.prod.outlook.com (2603:10a6:20b:100::35) To DU2PR04MB8616.eurprd04.prod.outlook.com (2603:10a6:10:2db::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 31b50537-6199-46fd-b8f1-08da2697b4e7 X-MS-TrafficTypeDiagnostic: AM5PR04MB2977: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: nzZBCILlrNZDOJWCc8bd7Frfg87ffeUqCgCeHxSU/SOuETRVFnnxO26+GxIkSky9IMiWMcK+y7GaRJ7ULk+3kuZSoacbqSbNGrH9MhbvNnuBGm8tf/0DTPoQDd0Z+lWEZ+dnDOd7OmPL0mxBW5eQNWu269Ls0lQv6Tob7hx5iyBN5sbCdUjrzD+n61lMJiJndDYvitL1MkyKTn0K4gEqQrprtsD80KyzRSJxmrQQYDNSWQ/u59BJi8pRQsplCgE9ADDnNoT1S98r+zjmSPEb1+DIh/ypwcTLSBngctxh3vvCRqKHG/hefKf+VM0vIhtFDmoBcLsG4mP3AAaC9dneR7VxN4O6pKLk5AVyIJzAfeK/pwNdjXq+pa8mF3wEur6MRXOELIYiKhVAdZdopgtizEXeFTZMErC4itRFj0DsHBSloL/Yb3cJ/CxyxhdR/a/m6jEo+ZZayo1AlG1Wo8LPEDX4afM/L3z3zs0vM4/Wqgl4WIp3J+cNk3Nmf8UswRdY3XLfwmyX5091J18OoB3h15dSgTJPhYW6+ZUcjvdIyVZK7oB/zGp5Fft1xDIwVgSzCePAZ2WbaCEcjpki4OGfN/ZLwxhVEmN+CziKKWjw0/opH2mbM8fAmSFocUANfoDHCaJ3hyYKULCo6Ma08ETTiDZ9TdDf52jMArHSo64hxkeOH0sikZV76kVDocybJW9RkX4XZ427fHe4itvTvXhZHnZoX1Syb/1Laj3FcX4vBuc= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DU2PR04MB8616.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230001)(366004)(316002)(6916009)(508600001)(38100700002)(26005)(6512007)(6486002)(31696002)(5660300002)(83380400001)(36756003)(86362001)(8936002)(31686004)(2616005)(2906002)(66476007)(66556008)(54906003)(8676002)(4326008)(6506007)(186003)(66946007)(45980500001)(43740500002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?oEAb4d+VhUrsgvquzv5Z6vrWScYo?= =?utf-8?q?FlKX7ZeNP7OBLMzKFrhvPrh7WOPcN2wGwot9vEVZbJrVAqJwRBUNZdPTC9Ajcsp95?= =?utf-8?q?YoMfsWsr5UF1zP3yYTS8PCUEpMS0MX2+15P8BnbwbhPhDFFcrOj/1cwlPkmn6ogCK?= =?utf-8?q?xhbaH2/MUPekEMatq5OdVZA6jQL3m7iCitURc0Oo/0CIl5VtVPw0G2U80Yvn6BtnS?= =?utf-8?q?hla/lt2ecpN43DWfdXf3SGb/RKQ0eP+pM9ifRtzP2MyQZYjyNFF0ZHivwG59JkDsf?= =?utf-8?q?NfIYzs24cPilD5ORzBWII5drREyMbgNq8doOalKpUVCMk3qSBpC4vFevodcdbuUsb?= =?utf-8?q?o71tjh5nCBThaRsHHjrWJ6K/3emv7dj98cf1psOxjIguzonuoVQBnXDW1rZyHbeXN?= =?utf-8?q?zzJ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ccT/1taPtN8SMjlQ7D7w4w+aGx8BCw36R7J4p9iyISAlrbtjNaVV+?= =?utf-8?q?911m+go5Akm/roNvK4Hw/LD/6nSnFTGayv4E2N1vwESg+Mh/H0XkzQjYz0UPKhWuL?= =?utf-8?q?e8HOOj9xlBi7D6YVcL7/0i4mFQ7kz64jtcczeEPCcKwSOE516Ned2V/yGWTdD2hg0?= =?utf-8?q?qJf0F4CsAcNy22JVFf4KmlYFe1p50Dmb7fpu/Lc/Pv5kJ7420YiWJDqAWL1ymVNaK?= =?utf-8?q?0tRJ8XW5FLf/hOn2RXIr8TdslgMLmLZ/VN6KYp1Sq4cjdpy2TaTbkCK9NWdwO7yJ+?= =?utf-8?q?M5VuQIidS7emvLE4VDdbLkehQUlQCJq8QQAeoXE6y826zliHJ3advQ7K+COQuGTaN?= =?utf-8?q?qF0iUmGn9C9myRAOncRPSHP0HzY/XHCw=3D=3D?= X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: 31b50537-6199-46fd-b8f1-08da2697b4e7 X-MS-Exchange-CrossTenant-AuthSource: DU2PR04MB8616.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Apr 2022 08:43:44.4286 (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: QnGPBIna7w5QCA+on4z0BrWmh88J8zzk6jnLn8NuK7xx2FVT0XPddEUHzw6i8DuoGABAlL7oU1NzJe5kpb99OQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM5PR04MB2977 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. Signed-off-by: Jan Beulich Reviewed-by: Kevin Tian --- 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 @@ -2216,14 +2216,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)