From mboxrd@z Thu Jan 1 00:00:00 1970 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.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (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 95371CCD1A2 for ; Fri, 17 Oct 2025 00:32:54 +0000 (UTC) Received: from boromir.ozlabs.org (localhost [127.0.0.1]) by lists.ozlabs.org (Postfix) with ESMTP id 4cnm4j0pjwz30MY; Fri, 17 Oct 2025 11:32:53 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; arc=none smtp.remote-ip="2607:f8b0:4864:20::1049" ARC-Seal: i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1760661173; cv=none; b=nxJHBDgJ3I90VIM6u5lLc3x8TYt/1Exdy8SwB/fKhuT8o/ZXUYAv5Y07bs3+r3a5BgvSSzgIuCykPK5hNV6iMTm52KUp5TTer9J7oFqwcP+keVAALXeEOzQmiXMU4wltgD6p2MXZGkGaSfL7JSAHImTLmS5WXAJI2g8uhYFKF7z7Ia5PenCTAfujZqC2O/CkVmF/n2QsisVc/u2zTZGaseuXTTo8XJB15T+3s9tOFxSrAxHxboX6dwVgkb31+gc8NKoCZTN5aqQchNE2H1Vq1ZbFOJRyVXM0nIXxIvV36yczogIftaqGqGgwWr6MEJqHX9IdJjO1/7dJwb1iEtKeOg== ARC-Message-Signature: i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1760661173; c=relaxed/relaxed; bh=IUhhIOZQl1LmuwLSXSpqUy/3rFv/MJFTCRm/41SsmT4=; h=Date:Mime-Version:Message-ID:Subject:From:To:Cc:Content-Type; b=nlUDS8Mt92yTRFkxHEHovakzfr3vjRtsineLsvpDl719vLbntMvHdDZ9zZeeCg29wgnR+xIzPCvubSe7UlH212eqa7i8t4ta1QNsHKiB3LkLbXGBRZBwaVCWG03fb28icTr1UxHNymEQyvz0x1XdHC7vrolCms95CXQQHIu91cZoTGelGOH5YRvIrZ0yJkIh6/XW4Zb90vQh7RHCdEd8kFczu0O3yDCw889kS+KipENorSdgxS1M6DUUY9Eb98xqduUu4Ompm/jtuJUTW6hbFmI6pU+J/eSfqgR9AcKyAS4zcSxQeL8So60ZRnNE1j4sCYgdDzCEvetdaeXiyhQFIA== ARC-Authentication-Results: i=1; lists.ozlabs.org; dmarc=pass (p=reject dis=none) header.from=google.com; dkim=pass (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20230601 header.b=ZQfcIE6W; dkim-atps=neutral; spf=pass (client-ip=2607:f8b0:4864:20::1049; helo=mail-pj1-x1049.google.com; envelope-from=3si7xaaykdoevhdqmfjrrjoh.frpolqxassf-ghyolvwv.rcodev.ruj@flex--seanjc.bounces.google.com; receiver=lists.ozlabs.org) smtp.mailfrom=flex--seanjc.bounces.google.com Authentication-Results: lists.ozlabs.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20230601 header.b=ZQfcIE6W; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=flex--seanjc.bounces.google.com (client-ip=2607:f8b0:4864:20::1049; helo=mail-pj1-x1049.google.com; envelope-from=3si7xaaykdoevhdqmfjrrjoh.frpolqxassf-ghyolvwv.rcodev.ruj@flex--seanjc.bounces.google.com; receiver=lists.ozlabs.org) Received: from mail-pj1-x1049.google.com (mail-pj1-x1049.google.com [IPv6:2607:f8b0:4864:20::1049]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4cnm4g4LNGz2yqh for ; Fri, 17 Oct 2025 11:32:50 +1100 (AEDT) Received: by mail-pj1-x1049.google.com with SMTP id 98e67ed59e1d1-32ee4998c50so1124442a91.3 for ; Thu, 16 Oct 2025 17:32:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1760661168; x=1761265968; darn=lists.ozlabs.org; h=cc:to:from:subject:message-id:mime-version:date:reply-to:from:to:cc :subject:date:message-id:reply-to; bh=IUhhIOZQl1LmuwLSXSpqUy/3rFv/MJFTCRm/41SsmT4=; b=ZQfcIE6Wm+l1iZDRvl3A7AgPXChoUklu1MsyA+YqBz9g5kbEgi9sR7H+0M/cOU9DMk qRZgxkeIh/vtU34kzIU+xPKDzt172gJzUurxE61j0TPt+sBeoam6QU1aJnPAeMzeLrff pcXah7dBWGZ+7moJWUnnzlMBYOJFPUJyUUNNdcnboDsjWaLtOVBw/59KNHq4Ph9gNHRv ZN/mEhtc1Yb0naJIJW5H23RZWHMTVUycupyGP7F32G+NzWYwZ2xcbGLsce35KtRAdgWI YwB4IZCtTB9HyO6iM8BFGQMVHywDEX92tCFAQAnt1b6drKRusGAXXp8kmZCdtm1RemNI WEpw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1760661168; x=1761265968; h=cc:to:from:subject:message-id:mime-version:date:reply-to :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=IUhhIOZQl1LmuwLSXSpqUy/3rFv/MJFTCRm/41SsmT4=; b=Ij1AAjX2jKY4VBW3l3X3+7xgiFqBNG6Htk95dnCNWNylgUvtffmmKOJYLWTyDMk3uI 9b4H1IG94dKnytZ0cQbZH3RHm0iDWRXkc8apgwoeaQmTivinqQJkTqfJ2lN0WX5V65z7 SCqezvSHU5BSUaOtmlZU1X1ijm8IMpp5dAJobCYtBzsmvnSVu6397urNlmQBqWdC1UZI pUsWaDgrFucuyrHbR93Wu/j5HuZoMYU+FAf6qXscLZ935pAX/Pxo6h1IcVpjfsYRgVFc SfXoieHkwrE0co9vqiUnfNnUYv10R3PMkgX58nkT2vuY9miPDqkF/bjDFg4zltCnk/ml qcSA== X-Forwarded-Encrypted: i=1; AJvYcCWiEF+RE4diwT2KFFMdnVXqeB0qS9mxomWvY+kI82vLGgbUlX3f8qerFZRDaBo+npsX6EQLmk+g9daQVg0=@lists.ozlabs.org X-Gm-Message-State: AOJu0Yx9E+M2uvNFTlU4kvX6o6XmxW5AaJUDKQPv7cBASbBae9deHOCK Ibdg6RDNb5NLDt7h+8H26SZhyF3ItfAPAyA7qRoHBZgHvkv2VMUHwVsdeYkKIgTG36+w4jaJ/W1 DgQZSaQ== X-Google-Smtp-Source: AGHT+IGuHGQyD51mVtQEohHO8NdP+zAwWbn/b6u+mCKYmFM3Ij1iHsaMWgJCqF8QAg/mESpyN5uCXlDFqHE= X-Received: from pjblk6.prod.google.com ([2002:a17:90b:33c6:b0:33b:51fe:1a74]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:4a81:b0:32e:ddbc:9bd6 with SMTP id 98e67ed59e1d1-33bcf8f9431mr1768955a91.27.1760661168259; Thu, 16 Oct 2025 17:32:48 -0700 (PDT) Reply-To: Sean Christopherson Date: Thu, 16 Oct 2025 17:32:18 -0700 X-Mailing-List: linuxppc-dev@lists.ozlabs.org List-Id: List-Help: List-Owner: List-Post: List-Archive: , List-Subscribe: , , List-Unsubscribe: Precedence: list Mime-Version: 1.0 X-Mailer: git-send-email 2.51.0.858.gf9c4a03a3a-goog Message-ID: <20251017003244.186495-1-seanjc@google.com> Subject: [PATCH v3 00/25] KVM: x86/mmu: TDX post-populate cleanups From: Sean Christopherson To: Marc Zyngier , Oliver Upton , Tianrui Zhao , Bibo Mao , Huacai Chen , Madhavan Srinivasan , Anup Patel , Paul Walmsley , Palmer Dabbelt , Albert Ou , Christian Borntraeger , Janosch Frank , Claudio Imbrenda , Sean Christopherson , Paolo Bonzini , "Kirill A. Shutemov" Cc: linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, kvm@vger.kernel.org, loongarch@lists.linux.dev, linux-mips@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org, x86@kernel.org, linux-coco@lists.linux.dev, linux-kernel@vger.kernel.org, Ira Weiny , Kai Huang , Michael Roth , Yan Zhao , Vishal Annapurve , Rick Edgecombe , Ackerley Tng , Binbin Wu Content-Type: text/plain; charset="UTF-8" Non-x86 folks, patches 1 and 2 are likely the only thing of interest here. They make kvm_arch_vcpu_async_ioctl() mandatory and then rename it to kvm_arch_vcpu_unlocked_ioctl(). Hopefully they're boring? As for the x86 side... Clean up the TDX post-populate paths (and many tangentially related paths) to address locking issues between gmem and TDX's post-populate hook[*], and within KVM itself (KVM doesn't ensure full mutual exclusivity between paths that for all intents and purposes the TDX-Module requires to be serialized). Compile tested only again on my end, but Rick and Yan took v2 for a spin, so I dropped the RFC. [*] http://lore.kernel.org/all/aG_pLUlHdYIZ2luh@google.com v3: - Collect more reviews. - Add the async_ioctl() => unlocked_ioctl() patches, and use the "unlocked" variant in the TDX vCPU sub-ioctls so they can take kvm->lock outside of vcpu->mutex. - Add a patch to document that vcpu->mutex is taken *outside* kvm->slots_lock. - Add the tdx_vm_state_guard CLASS() to take kvm->lock, all vcpu->mutex locks, and kvm->slots_lock, in order to make tdx_td_init(), tdx_td_finalize(), tdx_vcpu_init_mem_region(), and tdx_vcpu_init() mutually exclusive with each other, and mutually exclusvie with basically anything that can result in contending one of the TDX-Module locks (can't remember which one). - Refine the changelog for the "Drop PROVE_MMU=y" patch. [Binbin] v2: - Collect a few reviews (and ignore some because the patches went away). [Rick, Kai, Ira] - Move TDH_MEM_PAGE_ADD under mmu_lock and drop nr_premapped. [Yan, Rick] - Force max_level = PG_LEVEL_4K straightaway. [Yan] - s/kvm_tdp_prefault_page/kvm_tdp_page_prefault. [Rick] - Use Yan's version of "Say no to pinning!". [Yan, Rick] - Tidy up helpers and macros to reduce boilerplate and copy+pate code, and to eliminate redundant/dead code (e.g. KVM_BUG_ON() the same error multiple times). - KVM_BUG_ON() if TDH_MR_EXTEND fails (I convinced myself it can't). v1: https://lore.kernel.org/all/20250827000522.4022426-1-seanjc@google.com Sean Christopherson (23): KVM: Make support for kvm_arch_vcpu_async_ioctl() mandatory KVM: Rename kvm_arch_vcpu_async_ioctl() to kvm_arch_vcpu_unlocked_ioctl() KVM: TDX: Drop PROVE_MMU=y sanity check on to-be-populated mappings KVM: x86/mmu: Add dedicated API to map guest_memfd pfn into TDP MMU Revert "KVM: x86/tdp_mmu: Add a helper function to walk down the TDP MMU" KVM: x86/mmu: Rename kvm_tdp_map_page() to kvm_tdp_page_prefault() KVM: TDX: Return -EIO, not -EINVAL, on a KVM_BUG_ON() condition KVM: TDX: Fold tdx_sept_drop_private_spte() into tdx_sept_remove_private_spte() KVM: x86/mmu: Drop the return code from kvm_x86_ops.remove_external_spte() KVM: TDX: Avoid a double-KVM_BUG_ON() in tdx_sept_zap_private_spte() KVM: TDX: Use atomic64_dec_return() instead of a poor equivalent KVM: TDX: Fold tdx_mem_page_record_premap_cnt() into its sole caller KVM: TDX: Bug the VM if extended the initial measurement fails KVM: TDX: ADD pages to the TD image while populating mirror EPT entries KVM: TDX: Fold tdx_sept_zap_private_spte() into tdx_sept_remove_private_spte() KVM: TDX: Combine KVM_BUG_ON + pr_tdx_error() into TDX_BUG_ON() KVM: TDX: Derive error argument names from the local variable names KVM: TDX: Assert that mmu_lock is held for write when removing S-EPT entries KVM: TDX: Add macro to retry SEAMCALLs when forcing vCPUs out of guest KVM: TDX: Add tdx_get_cmd() helper to get and validate sub-ioctl command KVM: TDX: Convert INIT_MEM_REGION and INIT_VCPU to "unlocked" vCPU ioctl KVM: TDX: Use guard() to acquire kvm->lock in tdx_vm_ioctl() KVM: TDX: Guard VM state transitions with "all" the locks Yan Zhao (2): KVM: TDX: Drop superfluous page pinning in S-EPT management KVM: TDX: Fix list_add corruption during vcpu_load() arch/arm64/kvm/arm.c | 6 + arch/loongarch/kvm/Kconfig | 1 - arch/loongarch/kvm/vcpu.c | 4 +- arch/mips/kvm/Kconfig | 1 - arch/mips/kvm/mips.c | 4 +- arch/powerpc/kvm/Kconfig | 1 - arch/powerpc/kvm/powerpc.c | 4 +- arch/riscv/kvm/Kconfig | 1 - arch/riscv/kvm/vcpu.c | 4 +- arch/s390/kvm/Kconfig | 1 - arch/s390/kvm/kvm-s390.c | 4 +- arch/x86/include/asm/kvm-x86-ops.h | 1 + arch/x86/include/asm/kvm_host.h | 5 +- arch/x86/kvm/mmu.h | 3 +- arch/x86/kvm/mmu/mmu.c | 66 ++- arch/x86/kvm/mmu/tdp_mmu.c | 45 +- arch/x86/kvm/vmx/main.c | 9 + arch/x86/kvm/vmx/tdx.c | 638 ++++++++++++++--------------- arch/x86/kvm/vmx/tdx.h | 8 +- arch/x86/kvm/vmx/x86_ops.h | 1 + arch/x86/kvm/x86.c | 13 + include/linux/kvm_host.h | 14 +- virt/kvm/Kconfig | 3 - virt/kvm/kvm_main.c | 6 +- 24 files changed, 422 insertions(+), 421 deletions(-) base-commit: f222788458c8a7753d43befef2769cd282dc008e -- 2.51.0.858.gf9c4a03a3a-goog