From patchwork Mon Feb 5 12:01:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Gowans, James" X-Patchwork-Id: 13545355 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 70237C48291 for ; Mon, 5 Feb 2024 12:04:38 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0812F6B0081; Mon, 5 Feb 2024 07:04:38 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 008D66B009A; Mon, 5 Feb 2024 07:04:37 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E12966B009B; Mon, 5 Feb 2024 07:04:37 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id CF4F36B0081 for ; Mon, 5 Feb 2024 07:04:37 -0500 (EST) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 9A3EC40A1C for ; Mon, 5 Feb 2024 12:04:37 +0000 (UTC) X-FDA: 81757618194.12.941DD94 Received: from smtp-fw-9105.amazon.com (smtp-fw-9105.amazon.com [207.171.188.204]) by imf22.hostedemail.com (Postfix) with ESMTP id 88716C0024 for ; Mon, 5 Feb 2024 12:04:35 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=amazon.com header.s=amazon201209 header.b=hy6XIzRS; dmarc=pass (policy=quarantine) header.from=amazon.com; spf=pass (imf22.hostedemail.com: domain of "prvs=75897cb1d=jgowans@amazon.com" designates 207.171.188.204 as permitted sender) smtp.mailfrom="prvs=75897cb1d=jgowans@amazon.com" ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1707134675; a=rsa-sha256; cv=none; b=X9Q0N2zRzBPpC36Y9PBzZxv22VdAeyvgPqonTgHYVEcdRwpM1GdRDogWwKjncfF4uJ5iT/ SBW1j4Op4/Uhd+ZXWHDO/VfUxf7pC3fM9lEf0VdWAKDs2YlaiweNs69la4s9Oe/+6MA7TE XhAJiPGAJMpI/qrhF/jNHt0e0NtVrJs= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=amazon.com header.s=amazon201209 header.b=hy6XIzRS; dmarc=pass (policy=quarantine) header.from=amazon.com; spf=pass (imf22.hostedemail.com: domain of "prvs=75897cb1d=jgowans@amazon.com" designates 207.171.188.204 as permitted sender) smtp.mailfrom="prvs=75897cb1d=jgowans@amazon.com" ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1707134675; h=from:from:sender: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:dkim-signature; bh=TxdyyN106bvAzVLll6ZOpOdKPjlViDjzUv1y30GOivQ=; b=cgPDrfC6oIF6bS5JxzUlQPe8e4sGXEA4QTtBtG0D0c2MN9KvVvEXlJmJQTJrOk7tZSzbXL ihVJnC7cpV5/vVzOX7QT86MZRsAvaEdEFFobs58TSQWeS4DExrNTAq2LKHfcEfUHGcdi91 groa8mG2xKWZOyutUgwKxC0sIkq7CmA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1707134675; x=1738670675; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=TxdyyN106bvAzVLll6ZOpOdKPjlViDjzUv1y30GOivQ=; b=hy6XIzRScBH6TrmT7Oet0qjFGlbrDm9xVjz9St+6P9stWHiQ7/575o3A cL/90b2XJrWkWy50z+JirX0k5NxbuFPMennPaoyU8W68p6ihmtTO78OKo 0cCYfQc352c7SPIiQvg51/C87UguzBLH5F+LQ7VozBNfPTTq2VWGc41Le 8=; X-IronPort-AV: E=Sophos;i="6.05,245,1701129600"; d="scan'208";a="702759804" Received: from pdx4-co-svc-p1-lb2-vlan2.amazon.com (HELO smtpout.prod.us-east-1.prod.farcaster.email.amazon.dev) ([10.25.36.210]) by smtp-border-fw-9105.sea19.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Feb 2024 12:04:26 +0000 Received: from EX19MTAEUC001.ant.amazon.com [10.0.10.100:58296] by smtpin.naws.eu-west-1.prod.farcaster.email.amazon.dev [10.0.14.129:2525] with esmtp (Farcaster) id e132c2ad-2d34-4ccb-890d-621a7e0c08cd; Mon, 5 Feb 2024 12:04:25 +0000 (UTC) X-Farcaster-Flow-ID: e132c2ad-2d34-4ccb-890d-621a7e0c08cd Received: from EX19D014EUC004.ant.amazon.com (10.252.51.182) by EX19MTAEUC001.ant.amazon.com (10.252.51.155) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Mon, 5 Feb 2024 12:04:23 +0000 Received: from dev-dsk-jgowans-1a-a3faec1f.eu-west-1.amazon.com (172.19.112.191) by EX19D014EUC004.ant.amazon.com (10.252.51.182) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Mon, 5 Feb 2024 12:04:17 +0000 From: James Gowans To: CC: Eric Biederman , , "Joerg Roedel" , Will Deacon , , Alexander Viro , "Christian Brauner" , , Paolo Bonzini , Sean Christopherson , , Andrew Morton , , Alexander Graf , David Woodhouse , "Jan H . Schoenherr" , Usama Arif , Anthony Yznaga , Stanislav Kinsburskii , , , Subject: [RFC 09/18] intel-iommu: Use pkernfs for root/context pgtable pages Date: Mon, 5 Feb 2024 12:01:54 +0000 Message-ID: <20240205120203.60312-10-jgowans@amazon.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240205120203.60312-1-jgowans@amazon.com> References: <20240205120203.60312-1-jgowans@amazon.com> MIME-Version: 1.0 X-Originating-IP: [172.19.112.191] X-ClientProxiedBy: EX19D041UWA001.ant.amazon.com (10.13.139.124) To EX19D014EUC004.ant.amazon.com (10.252.51.182) X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 88716C0024 X-Stat-Signature: xukqs65mjjscthgmb9cjctcoxo6zw3wp X-HE-Tag: 1707134675-980747 X-HE-Meta: U2FsdGVkX19pgiXELRSH+Ml3BCAaZl6FQGvVtQUMzxA5wNg4LcPaH3uQn3tfn3pXjNNwRhIOP8oeHiLUNaYUsgx9hZz7MPmxf4Im6c3zjeNCcsSTxAb0F5qhaf3De8m5eSWO6GEDOc4mECMaIi7FLAtEaOPt1KiSJ+mCioOwyb3X+qTBKpipgGb6p2/8W8ly/TV9X2ZafTWUtHwoV9ECo9vwDuP5r/DCtNZiroDqoIUrSk7h9lRpGhUkMWp3dooxieMYKA1QmYGt0YSBhRamyy42i0fDWg+DSrezEaMxsx748rRQ1jhSsSwZrNmySRgsVoSV3L3lrMmpbt5FQWAZfoEs4Vl3EMKFnaWru6aucNfY6cnzFAKJgxwl8nkLasQc824+kbbpKQUmHg+66dCTsr3c7L7nd5BOZYbW5sAxjdsWYaiyMagJK4Bm3GUT4Yo7jqaMoGmInM1Vh0Eb9e2ImLW+q4l60IDpMVRfeYRklCXJB6PY5Gb87L+cvR3kIhtXXHgqkqeRjnXHzPpJuLsISXfNxPKw46NIuTrrXAof2K35FiA5//Na29MBq4ziTmYwR0WptaRlJ6dYSFfGU4/s1gj4US9nwOHtFEO878M2d1aem+Cu2DM7gTMegenh0PfMqSK548QHSqGU5fyiMpIbZslABs73IgmHceaonwXTc66EikV7HViOyNqUhewAYvTsS3PMrg0Qpe7qL7N0n4nj49TBv1fD4sSA90bO/NB3+6H8garE+jjkDlkrkzoYq6lJcrsVBFcbFzhQc5B75ziLuzGV+Upv86e6TIdt45WmpjNQ3K5nlxVtMlEnHKd+APArdHTtF3ZLU4kDmrKKRNvWwvTCtfBfOAiBnt86hzSFOxO3fdPxZnDS2YECddAbj3uKY79fXPWA/973d5F71ZchEdIOtyDXTT2mgzHm1vuSOMe23AgdYzldQj25zB+PZR6ScS65WWvhNLOEEx0uMvs HB+/SG+K Ux7gwYEzl9YzzjoU+wCZhs6RGzfB/ygbqPI0+LhWIH0ggHrgW/ckzZSamfBLsM25XRSxh60fDRQxSRsvCxRC0GjPfGwy8D383RXHuObJkfqS5co9lR3BPF+aS+yJVYVj2GWwtAH4F73wkwUxoczyJzUHO8oVhJ3KqzUycJxyT5tTwkg8DkjiER6f+FHQpkVGPLHTOpSTis1MZJVnyw1bpjCobiD+ijzHrxw7o27oEWv3MlFn0Y785vjwsI6ameTAXKpHgq2Fpby+5zBuwTz83MBlv89ANmGPC3ULn/rS97kQQQxk2uYvxCeqCOAvetMw84pBmBF1dC+oq1KN94wPzqgjAoXdqCYKeM+fnACoxjO+dR9Bi6depLNKlAIyMjquHMK4vgZzv6++dKzFZ6aGdWVIwWnehFTAlPDZP2JETJNYZVy6NjIbV9BFY7Cuj+qya7pd9MCD7fiP1GVkg7Pa+FIQoBzXRq366yBxdbjHTgOw3Rdt1C6HkgQVuv0aTgWEvDD+1zdSuCIV3ej3+NKZVc/CXkiyh/j71p6eoe0rLNBgBp/4= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: The previous commits were preparation for using pkernfs memory for IOMMU pgtables: a file in the filesystem is available and an allocator to allocate 4-KiB pages from that file is available. Now use those to actually use pkernfs memory for root and context pgtable pages. If pkernfs is enabled then a "region" (physical and virtual memory chunk) is fetch from pkernfs and used to drive the allocator. Should this rather just be a pointer to a pkernfs inode? That abstraction seems leaky but without having the ability to store struct files at this point it's probably the more accurate. The freeing still needs to be hooked into the allocator... --- drivers/iommu/intel/iommu.c | 24 ++++++++++++++++++++---- drivers/iommu/intel/iommu.h | 2 ++ 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c index 744e4e6b8d72..2dd3f055dbce 100644 --- a/drivers/iommu/intel/iommu.c +++ b/drivers/iommu/intel/iommu.c @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -28,6 +29,7 @@ #include "../dma-iommu.h" #include "../irq_remapping.h" #include "../iommu-sva.h" +#include "../pgtable_alloc.h" #include "pasid.h" #include "cap_audit.h" #include "perfmon.h" @@ -617,7 +619,12 @@ struct context_entry *iommu_context_addr(struct intel_iommu *iommu, u8 bus, if (!alloc) return NULL; - context = alloc_pgtable_page(iommu->node, GFP_ATOMIC); + if (pkernfs_enabled()) + iommu_alloc_page_from_region( + &iommu->pkernfs_region, + (void **) &context, NULL); + else + context = alloc_pgtable_page(iommu->node, GFP_ATOMIC); if (!context) return NULL; @@ -1190,7 +1197,15 @@ static int iommu_alloc_root_entry(struct intel_iommu *iommu) { struct root_entry *root; - root = alloc_pgtable_page(iommu->node, GFP_ATOMIC); + if (pkernfs_enabled()) { + pkernfs_alloc_iommu_root_pgtables(&iommu->pkernfs_region); + root = pgtable_get_root_page( + &iommu->pkernfs_region, + liveupdate); + } else { + root = alloc_pgtable_page(iommu->node, GFP_ATOMIC); + } + if (!root) { pr_err("Allocating root entry for %s failed\n", iommu->name); @@ -2790,7 +2805,7 @@ static int __init init_dmars(void) init_translation_status(iommu); - if (translation_pre_enabled(iommu) && !is_kdump_kernel()) { + if (translation_pre_enabled(iommu) && !is_kdump_kernel() && !liveupdate) { iommu_disable_translation(iommu); clear_translation_pre_enabled(iommu); pr_warn("Translation was enabled for %s but we are not in kdump mode\n", @@ -2806,7 +2821,8 @@ static int __init init_dmars(void) if (ret) goto free_iommu; - if (translation_pre_enabled(iommu)) { + /* For the live update case restore pgtables, don't copy */ + if (translation_pre_enabled(iommu) && !liveupdate) { pr_info("Translation already enabled - trying to copy translation structures\n"); ret = copy_translation_tables(iommu); diff --git a/drivers/iommu/intel/iommu.h b/drivers/iommu/intel/iommu.h index e6a3e7065616..a2338e398ba3 100644 --- a/drivers/iommu/intel/iommu.h +++ b/drivers/iommu/intel/iommu.h @@ -22,6 +22,7 @@ #include #include #include +#include #include #include @@ -672,6 +673,7 @@ struct intel_iommu { unsigned long *copied_tables; /* bitmap of copied tables */ spinlock_t lock; /* protect context, domain ids */ struct root_entry *root_entry; /* virtual address */ + struct pkernfs_region pkernfs_region; struct iommu_flush flush; #endif