[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH v2 17/18] AMD/IOMMU: free all-empty page tables
- To: Jan Beulich <jbeulich@xxxxxxxx>
- From: Roger Pau Monné <roger.pau@xxxxxxxxxx>
- Date: Wed, 15 Dec 2021 16:14:38 +0100
- 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=o9SMaDTnxsGI2iay8CBbhBdAFcma89TZhFlhp9GfPEU=; b=VIJcpj3R5EdbREj6H54OZQ4dCvscXskn76+brnP3dXKi2KhRpwK6XLIca8N/TsdtZBEVGmUi7obc0+CcyXw0W7sV8M/R/xRvh+e/V/IkuetsQZiclh95feovLPXQa4ywry1CdZhk/TCaG4PKZ4RXzOqyRuhVvNS4I+ZTqtChGS8F71flIid643MqIJ/F3AYnR3fwn+vsdf3tiVc/FvMnevneT2oJ9kK32Jst5lQMaw7AC+lggNouXFZCZEZjDBYHmiumY+R0qeb/w56JEpu32KSd9taH1qAdSe61EqhcijqKGhCJA8am88WCakWUptrhPc4/gLljrNUDUrb5A1e1Pw==
- Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=QOFYT4UJ3xGBaI4CQjkEHnYhENi/zx0zEhvvap0sDCawt/oUODItLGZwAcrGdjgGX4hGylbYi2uKrGCO5yAaOjQ0xbq9wsNcYvbpBeJ0qV84K76UvA4/uwYdcIIQv4Ex1RdtwzRNa8ZHYQDv0HvU9OkwWdgZOioPewI+QEq5C8xp/wi7MXn44m+E1qZ//V6zUiMKZBtEnbrIWkyxF6L3t0LWVtwICT+iINfJVDruffxhFi86ILEmhrsPWje7S+DMSzYk70NBVpn95gEjrpfCzOJrsYF7PNEV1NQRtnXlPLOYKH1G3XcJFA2yY1xlcSWBKVewkqjZwso9BkYBQC3AIw==
- Authentication-results: esa5.hc3370-68.iphmx.com; dkim=pass (signature verified) header.i=@citrix.onmicrosoft.com
- Cc: "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>, Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Paul Durrant <paul@xxxxxxx>
- Delivery-date: Wed, 15 Dec 2021 15:15:10 +0000
- Ironport-data: A9a23:qu95OKiGnPVldbqSOyyMl1tzX161uBcKZh0ujC45NGQN5FlHY01je htvWWDVO6mPZDahc9h0ao7j9kMPvZSDyoRnTwdo/iw2Qyob9cadCdqndUqhZCn6wu8v7a5EA 2fyTvGacajYm1eF/k/F3oAMKRCQ7InQLlbGILes1htZGEk0GE/NtTo5w7Rg29Qx3IDja++wk YiaT/P3aQfNNwFcagr424rbwP+4lK2v0N+wlgVWicFj5DcypVFMZH4sDfjZw0/DaptVBoaHq 9Prl9lVyI97EyAFUbtJmp6jGqEDryW70QKm0hK6UID66vROS7BbPg/W+5PwZG8O4whlkeydx /1rmK2oWwoMAZTB27QaYSl0MhBiEp1JreqvzXiX6aR/zmXDenrohf5vEFs3LcsT/eMf7WNmr KJCbmpXN1ba2rzwkOnTpupE36zPKOHxO4wSoDd4xCzxBvc6W5HTBa7N4Le02R9t150fRKqDO 6L1bxJCT0mZY0VCJ240Fc0xscajvEfEaR9x/Qf9Sa0fvDGIkV0ZPKLWGMLcZ9iiVchT2EGCq Qru72n/Rx0XKtGb4T6E6W63wP/CmzvhX4AfH6H+8eRl6HWRzGEODBwdVXOgvOK0zEW5Xrpix 1c8o3R06/JorQryE4e7D0bQTGO4UgA0ffdhC/83zT60x+mE5DSpKkk1UhFxZ4lz3CMpfgAC2 liMltLvIDVgtryJVH6QnoupQSOO1Ts9djF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egAUdAH0+4WMHf+LqUgLzM2eabRWa DsrvZvln6FQzA6f867Dn4KU6zqoMDKrovvZVojCwQ84AeDoDu04PqieiLolCs2Yndq+/MP4G LFmwv26uGKtOy68AbV0yv2445NkNXs59NfDIini9QTKB/rlgG0Db4REIGqjXQQmqWC+VwqmN 7Dr1MJONly0WrYeiWPrR7ky2DboUETwk6n7WXdrWrooMT/Sj5/IdFGn5hlfhzQ7FdllM1g0Y pQtljp+KZ/PFflpmDQ9tLIXxZlmg6funw5i9MeiHRZTM83dKJRl4oC50lYea1wUB4S0LpXUd WGMfuspMq/KTihHjPkVyhUsZGRt00Ib1m7qhNogL3W79BU9EoJu3fwivZv20voz6hNO6Ws0d 60R5iApIs+P/P+UpgNd9vpYfHHfFAlEii8eV57HzzcZdM60jT22trK3Ik=
- Ironport-sdr: yomYvrEkLaTc1eHITXkFgo3403Cs+eq2keBG9LxC+SXj/vHjHrw5iKjJag1ALjRWRxkclEFW9m kd5gYNS7wRdMsMHk71rBbDrOJQ7/3EpIc3D11c9WC3YmGc8St2Z0lPxVRLKHKyLwzAFSY7Tb5X zoOwaVTzOKVH2PhwZdnITGY7SsXtmXzTK669M2QH3gDRT+G7pHK6rcmfrz48CMpv+/bmcaZoY2 OUqHmwoOma7z61Q42FA9bXtkdwioGVKAf7Vw26wYm+6PbhOxwYCLdX/v3KGbhOAWXqVgYnbnyC vV+4werdhhvkKonpd/i9TrxG
- List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
On Fri, Sep 24, 2021 at 11:55:57AM +0200, Jan Beulich wrote:
> When a page table ends up with no present entries left, it can be
> replaced by a non-present entry at the next higher level. The page table
> itself can then be scheduled for freeing.
>
> Note that while its output isn't used there yet, update_contig_markers()
> right away needs to be called in all places where entries get updated,
> not just the one where entries get cleared.
Couldn't you also coalesce all contiguous page tables into a
super-page entry at the higher level? (not that should be done here,
it's just that I'm not seeing any patch to that effect in the series)
> Signed-off-by: Jan Beulich <jbeulich@xxxxxxxx>
> ---
> v2: New.
>
> --- a/xen/drivers/passthrough/amd/iommu_map.c
> +++ b/xen/drivers/passthrough/amd/iommu_map.c
> @@ -21,6 +21,9 @@
>
> #include "iommu.h"
>
> +#define CONTIG_MASK IOMMU_PTE_CONTIG_MASK
> +#include <asm/contig-marker.h>
> +
> /* Given pfn and page table level, return pde index */
> static unsigned int pfn_to_pde_idx(unsigned long pfn, unsigned int level)
> {
> @@ -33,16 +36,20 @@ static unsigned int pfn_to_pde_idx(unsig
>
> static union amd_iommu_pte clear_iommu_pte_present(unsigned long l1_mfn,
> unsigned long dfn,
> - unsigned int level)
> + unsigned int level,
> + bool *free)
> {
> union amd_iommu_pte *table, *pte, old;
> + unsigned int idx = pfn_to_pde_idx(dfn, level);
>
> table = map_domain_page(_mfn(l1_mfn));
> - pte = &table[pfn_to_pde_idx(dfn, level)];
> + pte = &table[idx];
> old = *pte;
>
> write_atomic(&pte->raw, 0);
>
> + *free = update_contig_markers(&table->raw, idx, level, PTE_kind_null);
> +
> unmap_domain_page(table);
>
> return old;
> @@ -85,7 +92,11 @@ static union amd_iommu_pte set_iommu_pte
> if ( !old.pr || old.next_level ||
> old.mfn != next_mfn ||
> old.iw != iw || old.ir != ir )
> + {
> set_iommu_pde_present(pde, next_mfn, 0, iw, ir);
> + update_contig_markers(&table->raw, pfn_to_pde_idx(dfn, level), level,
> + PTE_kind_leaf);
> + }
> else
> old.pr = false; /* signal "no change" to the caller */
>
> @@ -259,6 +270,9 @@ static int iommu_pde_from_dfn(struct dom
> smp_wmb();
> set_iommu_pde_present(pde, next_table_mfn, next_level, true,
> true);
> + update_contig_markers(&next_table_vaddr->raw,
> + pfn_to_pde_idx(dfn, level),
> + level, PTE_kind_table);
>
> *flush_flags |= IOMMU_FLUSHF_modified;
> }
> @@ -284,6 +298,9 @@ static int iommu_pde_from_dfn(struct dom
> next_table_mfn = mfn_x(page_to_mfn(table));
> set_iommu_pde_present(pde, next_table_mfn, next_level, true,
> true);
> + update_contig_markers(&next_table_vaddr->raw,
> + pfn_to_pde_idx(dfn, level),
> + level, PTE_kind_table);
Would be nice if we could pack the update_contig_markers in
set_iommu_pde_present (like you do for clear_iommu_pte_present).
Thanks, Roger.
|