From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pg1-f202.google.com (mail-pg1-f202.google.com [209.85.215.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 469712E8B80 for ; Fri, 6 Feb 2026 16:04:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.202 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770393840; cv=none; b=gyL0c72D/TliNzFsGnVW1kTUcOpq8h+Koioo9eR8HCWXSRWIxIC2sq1Q0fO1EbV724Qnn4DDterEc8uYrc62KaxQT7TxsvZmpQtZB1S3Sm/N701O286eAYUUMtMfOLIy7AhWqqO6IVuUBLLcitAzIYS0fRKdpbuK0XHKj72q3TA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770393840; c=relaxed/simple; bh=3raR9XQBcm6pX1dp9l802LPULeByXkutMSrcWOv542Q=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=RroaUwuK+mpbAxAnD8DzYibhvJR1rhJWC8qAhkz8eLSJBYlt7BJcJee0REbPFatNrRNne/biVOGw9TKKTCWaHVUelmx7vUUX7RK0avcvqdhMBhXSdMyTdie+yqr+p8MRWJ2qvw+W02HxJurhOzxfreurUN4KlJpiU2sx54LWa7E= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=fwISnHxL; arc=none smtp.client-ip=209.85.215.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="fwISnHxL" Received: by mail-pg1-f202.google.com with SMTP id 41be03b00d2f7-c6310f81285so3826899a12.0 for ; Fri, 06 Feb 2026 08:04:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1770393839; x=1770998639; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=6W5ywYYSvCRSPwqFTbeco0aLvB9nOdCSyf5b4W1ZEGc=; b=fwISnHxLUHvTJxXPPImFixXw/KAxi7FQo0otgOhlgSXwvyd9QUn0x81chIcWRTHC1z im6Jr8ulBYBMS6Gs3cBBMjhqSxL0RMXN11CijNs13K1rKvJZQXbnpS+ylcsjkyFYfnqg i+rcK+n/nsPvKE9TUG908/DhEo/VfC52Dk7AlTuMYwrT0pdkd1DsmEkePzP/KJC+tSfw 4YfJAgd9xboRoOSOd05FVpB+1JI+yU+fKn3BAgXoKS4UY8dAUQ0mjwvLUzfZYI//Ruqg r39v9Jpim1VdwuDQVgaRhWCaO8/D45Du3ozhLL1jznY13SsNStKNsXzarkGgVPRyroAk ruNw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770393839; x=1770998639; h=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; bh=6W5ywYYSvCRSPwqFTbeco0aLvB9nOdCSyf5b4W1ZEGc=; b=XVLgXTsNLiBoMTIdGwJRp1AK7L6LMhJKT4D+SSXuBlpf7NOAJNzm+sQrUfT31Vkis8 af5BmZR9ioow5NtN3ubt7ZKV6UCZYdeukGT02fbzEkAC4TKyfBJU/FDetei5GEScwO6Q DetudvEQKMCMEI/jGtAYGh7YUzRwf7JXZq54UpAaBA+UCQOhcsCqCUPR0e5889aVkMcc fiVkgZCy6Yuz1+PfIln+irnJzpV6TukMDZWa0vCMvMQ4uZ/tYX0RGWbvuKO25QnaIwbN bFT9qMEqSX1ep/l0GWQqsYbFjuDGiU4n7HdGLvMDxXWVptzZjJpvTlDBlTJ+IJtzDI88 Jh1A== X-Forwarded-Encrypted: i=1; AJvYcCX3vbCPxaHG66puABf2/4AU0uJnukl42hd2SKfHYjOZDiQh8e8ptSf/ymk5vkWC+dOAZEmukwGaLZoAxws=@vger.kernel.org X-Gm-Message-State: AOJu0YwfSF4w0kni/ZwLr69CHq0Kfj++oIotpeAgsFqO6jYFX8J24tYk qbJQnkBTDYMTQlrGE0NCsd/c+E43gXTCMTff1EHnooKx1OyozHyM4ekG3AVNF8cWTJhXozHVKLj maBkl/g== X-Received: from pjbss7.prod.google.com ([2002:a17:90b:2ec7:b0:34c:37db:8f1b]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a21:3290:b0:393:8afb:3559 with SMTP id adf61e73a8af0-393ad0265a9mr3268415637.32.1770393839552; Fri, 06 Feb 2026 08:03:59 -0800 (PST) Date: Fri, 6 Feb 2026 08:03:57 -0800 In-Reply-To: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260129011517.3545883-1-seanjc@google.com> <20260129011517.3545883-23-seanjc@google.com> Message-ID: Subject: Re: [RFC PATCH v5 22/45] KVM: TDX: Get/put PAMT pages when (un)mapping private memory From: Sean Christopherson To: Yan Zhao Cc: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, Kiryl Shutsemau , Paolo Bonzini , linux-kernel@vger.kernel.org, linux-coco@lists.linux.dev, kvm@vger.kernel.org, Kai Huang , Rick Edgecombe , Vishal Annapurve , Ackerley Tng , Sagi Shahar , Binbin Wu , Xiaoyao Li , Isaku Yamahata Content-Type: text/plain; charset="us-ascii" On Fri, Feb 06, 2026, Yan Zhao wrote: > On Wed, Jan 28, 2026 at 05:14:54PM -0800, Sean Christopherson wrote: > > diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h > > index 6e84dbc89e79..a6e4ab76b1b2 100644 > > --- a/arch/x86/include/asm/kvm_host.h > > +++ b/arch/x86/include/asm/kvm_host.h > > @@ -1863,6 +1863,7 @@ struct kvm_x86_ops { > > struct kvm_mmu_page *sp); > > void (*remove_external_spte)(struct kvm *kvm, gfn_t gfn, enum pg_level level, > > u64 mirror_spte); > > + int (*topup_external_cache)(struct kvm_vcpu *vcpu, int min); > > > > > > bool (*has_wbinvd_exit)(void); > > diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c > > index 9b5a6861e2a4..4ecbf216d96f 100644 > > --- a/arch/x86/kvm/mmu/mmu.c > > +++ b/arch/x86/kvm/mmu/mmu.c > > @@ -605,6 +605,10 @@ static int mmu_topup_memory_caches(struct kvm_vcpu *vcpu, bool maybe_indirect) > > PT64_ROOT_MAX_LEVEL); > > if (r) > > return r; > > + > > + r = kvm_x86_call(topup_external_cache)(vcpu, PT64_ROOT_MAX_LEVEL); > If this external cache is for PAMT pages allocation for guest pages only, here > the min count should be 1 instead of PT64_ROOT_MAX_LEVEL? Oh! Right. Hmm, with that in mind, it seems like topup_external_cache() isn't quite the right interace. It's not at all clear that, unlike the other caches, the DPAMT cache isn't tied to the page tables, it's tied to the physical memory being mapped into the guest. At the very least, it seems like we should drop the @min parameter? int (*topup_external_cache)(struct kvm *kvm, struct kvm_vcpu *vcpu); Though if someone has a name that better captures what the cache is used for, without bleeding too many details into common x86...