From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 654EA606A325 for ; Mon, 30 Nov 2026 16:04:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=1ovHLs0o; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.a=rsa-sha256 header.s=desiato.20200630 header.b=AFKC3K7c; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=PJfEdMOg DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Type:Cc:To:From: Subject:Message-ID:References:Mime-Version:In-Reply-To:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Unsubscribe-Post:List-Owner; bh=/v6mfrzKDRLcuRWPVSIQ1cgv5BTM3yxgvw8b9HJ1+X4=; b=1ovHLs0o+XGiqIYP7aQwJujghN 1jpdbWRNdPNhXT65FmfsEEp3tGyn7iOsBbKBdo6pvjWDoCsHYfb2haDJ57qD6SKKGKadKEE+7k+pq oUfoP+FvoEux73kP0sir4fuFvXOMFQuxB7ZuYybE6r8pU4QPkn96xOW55r8taVgXXxnimkcdmCCZl ZWO/QvkF7nwcACsmggwNm0P/CPtMWmzLez+S3Y40EaMxO5F1C5Bw7vO9FB9IbkYJ8ABv9T9kYxjMB qgDngBM52Uk0JV55R98i27TzppPTKNjEmnv0+c8r4KaBKoQtT3Rr7svFiyYZOfHiKeSvAZzK9d2H4 XLBb1xQw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.100.1 #2 (Red Hat Linux)) id 1xY3ri-00000005Awr-3QTP; Mon, 30 Nov 2026 16:04:31 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.100.1 #2 (Red Hat Linux)) id 1xY3lL-0000000584l-1FDB for linux-arm-kernel@bombadil.infradead.org; Mon, 30 Nov 2026 15:57:55 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Type:Cc:To:From:Subject: Message-ID:References:Mime-Version:In-Reply-To:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=/v6mfrzKDRLcuRWPVSIQ1cgv5BTM3yxgvw8b9HJ1+X4=; b=AFKC3K7ch3mjs7i1ptO8JFz/kL y+x8TTHkSofV25m2IY3oelzMeek4dkrcWIqfdhmDjy9XFGFGKN50tUKO4laXc/3ykqDkxfD2jH38A wtqjxMTxKWynD7KCPS63r2cZ5xkRRoae+bFMdbZFO3OX/xZMxRTE2SkekBykeKWPVQXA9uSPqTWam wCgHhu+FnhYlYJ3XXBuKhhTjnYoAciULHbrCAGf1P59rfPfqKzj4jOy6Rz/8QfRrCIbW3Uc0RsDzA aK3p+koiDyttGMnCU+uwIdw9q9xUQbqiyAyH2c4KbU3VMj+Ax4q9Pm5+DUmP1Jz8DPc0Vwh9xRgzw vUHdRw3g==; Received: from mail-wm1-x348.google.com ([2a00:1450:4864:20::348]) by desiato.infradead.org with esmtps (Exim 4.100.1 #2 (Red Hat Linux)) id 1xY3lF-0000000A6DS-3wFr for linux-arm-kernel@lists.infradead.org; Mon, 30 Nov 2026 15:57:53 +0000 Received: by mail-wm1-x348.google.com with SMTP id 5b1f17b1804b1-49febef74e3so76498545e9.0 for ; Mon, 30 Nov 2026 07:57:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20260707; t=1796054268; x=1796659068; darn=lists.infradead.org; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=/v6mfrzKDRLcuRWPVSIQ1cgv5BTM3yxgvw8b9HJ1+X4=; b=PJfEdMOgHCifXqnqE81A/jCAfDoFlo51TAuqYgoJ/bGP+VoIP3wQ7pACZ2HG3RJNDG Poop+55+BeSAzbH9e5O8bL6K9MJEGJIIrZ6HUw1Mnn4zT0cvjG3qC9NfVQzoecudX4Xe taOpY+KRfttoz5+AJEdkV+C0dHHDFx723vd48gyY2rqFZuMNdaBkqBzsrPZoSbnQImta 8gSBdWy0giZ4q/yCgDNCSKQ2UNJh0brl2IN1AqiRAc4xPnX1iJIYOC0f38EXEFibKJeM kh8s1mPidjF0cbTd/VbKKupHnIGy5JLhvkRqZ1yhfOTDnw2+BTU7X24wRWo3foJoC7C9 Ajuw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796054268; x=1796659068; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=/v6mfrzKDRLcuRWPVSIQ1cgv5BTM3yxgvw8b9HJ1+X4=; b=kk+q2AJN21rVo2AKmkAV2ZYyHbJSpx0ZCHFVbd2F95WtzoaEF7b2+UWHYCTmhjUUJV FF46UaH+MZFN0kASga0zz4YU6up8UBSt0J0lvSGsb6zx9UcVOUx/tQRzM9F1+l3X17pa /Lz1QA2EP83SXPwaGUTNl33wbSrYJMtviLSwsh03sKi2NMs6XfYmHO6nto2lMFAk4rco tadOCprUX5uG6PCj5Yznv3f8v/Z1DyM3JliJHxrE/W0ziBgqjRBqcIRlVfji0aZkd2dd POb27JnJYgZbepOe0xXtyBP8B6D5lwmJmqUGt5A8jhGoeMzmtKG3WRsWqq6b0EZGnZYi pU2A== X-Forwarded-Encrypted: i=1; AL+hErEWuvsR8OTq9aDB6Dx0jOQqyslTjUo3pUrVsX2roM8ZjwFlr337QhqrOWfSFhYzUV0lnWvzdAMQno1/1Nxu4Bhi@lists.infradead.org X-Gm-Message-State: APuU4Z8Z9z0nGN+KmeZwjuYn+6cIRQ9NbpgmWvxg/Q/be/rPVw1bZExf FsWAZa2VM96AC9UgsUOqMpxdXZiMbBFrrKeOuGy6PDjuAXcYndIGELi8tvbF/DwpYqQaAtIXghK 7i0cYfoUcw4CzsedjoEZFCQ== X-Received: from wmbhb5.prod.google.com ([2002:a05:600c:8685:b0:4a2:df9b:ef74]) (user=vdonnefort job=prod-delivery.src-stubby-dispatcher) by 2002:a05:600c:6749:b0:4bb:5d38:259f with SMTP id 5b1f17b1804b1-4bb8881099cmr649584685e9.12.1796054266596; Mon, 30 Nov 2026 07:57:46 -0800 (PST) Date: Mon, 30 Nov 2026 15:57:02 +0000 In-Reply-To: <20261130155710.2371874-1-vdonnefort@google.com> X-Archived-By: Mime-Version: 1.0 References: <20261130155710.2371874-1-vdonnefort@google.com> X-Mailer: git-send-email 2.56.1.839.g22a8290db9-goog Message-ID: <20261130155710.2371874-19-vdonnefort@google.com> Subject: [PATCH v5 18/25] KVM: arm64: Introduce kvm_pgtable_stage2_table_install() From: Vincent Donnefort To: maz@kernel.org, oupton@kernel.org, kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org Cc: joey.gouly@arm.com, seiden@linux.ibm.com, suzuki.poulose@arm.com, yuzenghui@huawei.com, catalin.marinas@arm.com, will@kernel.org, kernel-team@android.com, fuad.tabba@linux.dev, qperret@google.com, weilin.chang@arm.com, Vincent Donnefort Content-Type: text/plain; charset="UTF-8" X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.9.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20261130_155751_772361_C80AB743 X-CRM114-Status: GOOD ( 18.52 ) X-Spam-Score: -7.6 (-------) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" X-Spam-Status: No, score=-26.4 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIMWL_WL_MED,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT, USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 The existing kvm_pgtable_stage2_split() is unfit for pKVM: it relies on kvm_mmu_memory_cache which pKVM doesn't use and has no easy way to handle pKVM-specific annotations. Add the pgtable helper kvm_pgtable_stage2_table_install() so pKVM can handle block splitting in mem_protect.c. That helper can take a table either populated with kvm_pgtable_stage2_create_unlinked() or one filled with annotations. Signed-off-by: Vincent Donnefort --- arch/arm64/include/asm/kvm_pgtable.h | 13 +++++ arch/arm64/kvm/hyp/pgtable.c | 86 ++++++++++++++++++++++++---- 2 files changed, 88 insertions(+), 11 deletions(-) diff --git a/arch/arm64/include/asm/kvm_pgtable.h b/arch/arm64/include/asm/kvm_pgtable.h index 1c9c57cd6ae4..5d5d2165dbec 100644 --- a/arch/arm64/include/asm/kvm_pgtable.h +++ b/arch/arm64/include/asm/kvm_pgtable.h @@ -835,6 +835,19 @@ int kvm_pgtable_stage2_flush(struct kvm_pgtable *pgt, u64 addr, u64 size); int kvm_pgtable_stage2_split(struct kvm_pgtable *pgt, u64 addr, u64 size, struct kvm_mmu_memory_cache *mc); +/** + * kvm_pgtable_stage2_table_install() - Replace a stage-2 leaf entry with a table. + * @pgt: Page-table structure initialised by kvm_pgtable_stage2_init*(). + * @table: Unlinked stage-2 paging structure to install, such as one + * created by kvm_pgtable_stage2_create_unlinked(). + * @addr: Address identifying the leaf entry to replace. + * @level: Level of the leaf entry to replace. + * + * Return: 0 on success, negative error code on failure. + */ +int kvm_pgtable_stage2_table_install(struct kvm_pgtable *pgt, kvm_pte_t *table, + u64 addr, s8 level); + /** * kvm_pgtable_walk() - Walk a page-table. * @pgt: Page-table structure initialised by kvm_pgtable_*_init(). diff --git a/arch/arm64/kvm/hyp/pgtable.c b/arch/arm64/kvm/hyp/pgtable.c index 0c82365ba54e..781c40092532 100644 --- a/arch/arm64/kvm/hyp/pgtable.c +++ b/arch/arm64/kvm/hyp/pgtable.c @@ -1538,18 +1538,38 @@ static int stage2_block_get_nr_page_tables(s8 level) }; } +static int stage2_table_install(const struct kvm_pgtable_visit_ctx *ctx, + struct kvm_s2_mmu *mmu, + kvm_pte_t *table) +{ + kvm_pte_t new; + + if (!stage2_try_break_pte(ctx, mmu)) + return -EAGAIN; + + /* + * Note, the contents of the page table are guaranteed to be made + * visible before the new PTE is assigned because stage2_make_pte() + * writes the PTE using smp_store_release(). + */ + new = kvm_init_table_pte(table, ctx->mm_ops); + stage2_make_pte(ctx, new); + return 0; +} + static int stage2_split_walker(const struct kvm_pgtable_visit_ctx *ctx, enum kvm_pgtable_walk_flags visit) { struct kvm_pgtable_mm_ops *mm_ops = ctx->mm_ops; struct kvm_mmu_memory_cache *mc = ctx->arg; - struct kvm_s2_mmu *mmu; - kvm_pte_t pte = ctx->old, new, *childp; + kvm_pte_t pte = ctx->old, *childp; enum kvm_pgtable_prot prot; + struct kvm_s2_mmu *mmu; s8 level = ctx->level; bool force_pte; int nr_pages; u64 phys; + int ret; /* No huge-pages exist at the last level */ if (level == KVM_PGTABLE_LAST_LEVEL) @@ -1591,18 +1611,12 @@ static int stage2_split_walker(const struct kvm_pgtable_visit_ctx *ctx, if (IS_ERR(childp)) return PTR_ERR(childp); - if (!stage2_try_break_pte(ctx, mmu)) { + ret = stage2_table_install(ctx, mmu, childp); + if (ret) { kvm_pgtable_stage2_free_unlinked(mm_ops, childp, level); - return -EAGAIN; + return ret; } - /* - * Note, the contents of the page table are guaranteed to be made - * visible before the new PTE is assigned because stage2_make_pte() - * writes the PTE using smp_store_release(). - */ - new = kvm_init_table_pte(childp, mm_ops); - stage2_make_pte(ctx, new); return 0; } @@ -1621,6 +1635,56 @@ int kvm_pgtable_stage2_split(struct kvm_pgtable *pgt, u64 addr, u64 size, return ret; } +struct stage2_table_install_data { + struct kvm_s2_mmu *mmu; + kvm_pte_t *table; + s8 level; +}; + +static int stage2_table_install_walker(const struct kvm_pgtable_visit_ctx *ctx, + enum kvm_pgtable_walk_flags visit) +{ + struct stage2_table_install_data *data = ctx->arg; + + if (ctx->level != data->level) + return -EINVAL; + + /* + * On success, return a positive value to prevent descending into the + * new table. + */ + return stage2_table_install(ctx, data->mmu, data->table) ?: 1; +} + +int kvm_pgtable_stage2_table_install(struct kvm_pgtable *pgt, kvm_pte_t *table, + u64 addr, s8 level) +{ + struct stage2_table_install_data data = { + .mmu = pgt->mmu, + .table = table, + .level = level, + }; + struct kvm_pgtable_walker walker = { + .cb = stage2_table_install_walker, + .flags = KVM_PGTABLE_WALK_LEAF, + .arg = &data, + }; + int ret; + + if (level < pgt->start_level || level >= KVM_PGTABLE_LAST_LEVEL) + return -EINVAL; + + if (!IS_ALIGNED(addr, kvm_granule_size(level))) + return -EINVAL; + + ret = kvm_pgtable_walk(pgt, addr, kvm_granule_size(level), &walker); + if (ret < 0) + return ret; + + dsb(ishst); + return 0; +} + int __kvm_pgtable_stage2_init(struct kvm_pgtable *pgt, struct kvm_s2_mmu *mmu, struct kvm_pgtable_mm_ops *mm_ops, enum kvm_pgtable_stage2_flags flags, -- 2.56.1.839.g22a8290db9-goog