From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pj1-f74.google.com (mail-pj1-f74.google.com [209.85.216.74]) (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 AD14133ADA0 for ; Tue, 20 Jan 2026 18:02:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.74 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768932166; cv=none; b=t43j6U90Jsxocl2gInRAamO7DNj1gHPU8h2OND6N/9djEuwGt0M8NcYeLYN5a6K1no7WQ/N6n3zYLuIuDuEM4wOJP/bGp+M+K0D0Rd0yEUnUzJ6yafbX5ZwZ8apQEy9lWxJ4V4sblRTQv6+6FzyrFx4HaT14zEqHF+UK2/nAoH4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768932166; c=relaxed/simple; bh=/FKHSebDh4uM8KRSgCLBh88kF8WNt9KU+H2XJiq5McI=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=VEZCJDDI2ggT6+OLB66Ene5ABTZYcGi1dzf4XYWYnwgMIjAXrAqzIZ9y3mxEOXgacFk16KdQX+zr5fRu8l8UFOf1EzS1nDjBuTaoPmIrwuBuAetoTcDSArQiiZIsF5VvCe17IFtu06L9CdKDzi7yT9542ISMrWk8gShTe+l1X7E= 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=gzNg/tko; arc=none smtp.client-ip=209.85.216.74 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="gzNg/tko" Received: by mail-pj1-f74.google.com with SMTP id 98e67ed59e1d1-34ab459c051so11292216a91.0 for ; Tue, 20 Jan 2026 10:02:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1768932164; x=1769536964; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:from:to:cc:subject:date:message-id :reply-to; bh=+J1fLKCCQrvMP0lE2vmpjO31unfE9EFowcfvxhsZP60=; b=gzNg/tkozXjXjM21iTaqMyS1inEAMBTDabPCBqA8EH32SNLfodWw2mbABqKLi5qDxN Jr9a8Xsv4p3rxd4OmlaaWVCHfxxeGFVKDEIv/Qsz4WzSofWfRGzU97ucz9kIyBKZeWHg fiDYl+ch1vXH79EIC/1YX9tSNEz5ktQdBtTKJY2fVphgiU6B6FZjBT5Fz0P7tkqb55M8 Psp3pU2qFfz2z4szXVorFVuCIIkBgRWCBiv7QR/xPQi+hXJnPj/WDYvsEBEjG10zEFLF jAE9cpK09vHrW1zL/B8Z+igGidB1Bja654vdnVPJTRIDDTJi7gvSWqiJ+jwGkRcTpL5k QnVA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1768932164; x=1769536964; h=content-transfer-encoding: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=+J1fLKCCQrvMP0lE2vmpjO31unfE9EFowcfvxhsZP60=; b=CBvFv3wLPJj/3190rzKqTGPyt74NyydjTmWUnSbpBw1H3WDiYt6sh2xLQEVlatPU3g FPiPM9eL5zvR9t417ZBm9QXzIFDJVkIRHfIOvXPGabQVHEZseuxfgniPO4m/G/wLwCm8 vF8hyeQzCYDwSAsDck/mroQMenYX6xjUhcTFM4p0P+Jk5+HwDcI43MUOvTEYGjLTU1PH YOUiyfcds1mYhj+TK0pjqmeli/GRjS51V5FFI7iY0ygplUJOFZqaw2Op1i+5qhUy4BNL MC5zOE0MyCLCnSX9cDGzQSp71ftuX8rafwL8gzG4v/H5P1EksqdR9YsffMplXramUg8r cMVw== X-Forwarded-Encrypted: i=1; AJvYcCVZRLPmiFaGKgRN03eVTa3ime4R7bvjXPWSZ7p+qiGzGRhn6fi4yAg6drVCV/ZP+rnC94EIfDECok4Yo3Y=@vger.kernel.org X-Gm-Message-State: AOJu0YyRhQjlJjrjGVBj/5GnR9FCb4BhU0/4wETGS2fT02zzaySThU0z bMsS0iIDDmdo/dJl1Od9B2PTkbQAF/djkLbfWq3ck5RlV/U2vrMFCsVq6DPZ4Y7rMRMHR33fW8m EhoIisg== X-Received: from plru11.prod.google.com ([2002:a17:902:b28b:b0:2a0:7fa1:b964]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a17:903:2f87:b0:2a7:63dd:3496 with SMTP id d9443c01a7336-2a763dd379fmr24866415ad.46.1768932163760; Tue, 20 Jan 2026 10:02:43 -0800 (PST) Date: Tue, 20 Jan 2026 10:02:41 -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: <20260106101646.24809-1-yan.y.zhao@intel.com> <20260106102136.25108-1-yan.y.zhao@intel.com> <2906b4d3b789985917a063d095c4063ee6ab7b72.camel@intel.com> Message-ID: Subject: Re: [PATCH v3 11/24] KVM: x86/mmu: Introduce kvm_split_cross_boundary_leafs() From: Sean Christopherson To: Vishal Annapurve Cc: Kai Huang , "pbonzini@redhat.com" , Yan Y Zhao , "kvm@vger.kernel.org" , Fan Du , Xiaoyao Li , Chao Gao , Dave Hansen , "thomas.lendacky@amd.com" , "vbabka@suse.cz" , "tabba@google.com" , "david@kernel.org" , "kas@kernel.org" , "michael.roth@amd.com" , Ira Weiny , "linux-kernel@vger.kernel.org" , "binbin.wu@linux.intel.com" , "ackerleytng@google.com" , "nik.borisov@suse.com" , Isaku Yamahata , Chao P Peng , "francescolavra.fl@gmail.com" , "sagis@google.com" , Rick P Edgecombe , Jun Miao , "jgross@suse.com" , "pgonda@google.com" , "x86@kernel.org" Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable On Tue, Jan 20, 2026, Vishal Annapurve wrote: > On Fri, Jan 16, 2026 at 3:39=E2=80=AFPM Sean Christopherson wrote: > > > > On Thu, Jan 15, 2026, Kai Huang wrote: > > > static int __kvm_tdp_mmu_split_huge_pages(struct kvm *kvm, > > > struct kvm_gfn_range *range, > > > int target_level, > > > bool shared, > > > bool cross_boundary_only) > > > { > > > ... > > > } > > > > > > And by using this helper, I found the name of the two wrapper functio= ns > > > are not ideal: > > > > > > kvm_tdp_mmu_try_split_huge_pages() is only for log dirty, and it shou= ld > > > not be reachable for TD (VM with mirrored PT). But currently it uses > > > KVM_VALID_ROOTS for root filter thus mirrored PT is also included. I > > > think it's better to rename it, e.g., at least with "log_dirty" in th= e > > > name so it's more clear this function is only for dealing log dirty (= at > > > least currently). We can also add a WARN() if it's called for VM wit= h > > > mirrored PT but it's a different topic. > > > > > > kvm_tdp_mmu_gfn_range_split_cross_boundary_leafs() doesn't have > > > "huge_pages", which isn't consistent with the other. And it is a bit > > > long. If we don't have "gfn_range" in __kvm_tdp_mmu_split_huge_pages= (), > > > then I think we can remove "gfn_range" from > > > kvm_tdp_mmu_gfn_range_split_cross_boundary_leafs() too to make it sho= rter. > > > > > > So how about: > > > > > > Rename kvm_tdp_mmu_try_split_huge_pages() to > > > kvm_tdp_mmu_split_huge_pages_log_dirty(), and rename > > > kvm_tdp_mmu_gfn_range_split_cross_boundary_leafs() to > > > kvm_tdp_mmu_split_huge_pages_cross_boundary() > > > > > > ? > > > > I find the "cross_boundary" termininology extremely confusing. I also = dislike > > the concept itself, in the sense that it shoves a weird, specific conce= pt into > > the guts of the TDP MMU. > > > > The other wart is that it's inefficient when punching a large hole. E.= g. say > > there's a 16TiB guest_memfd instance (no idea if that's even possible),= and then > > userpace punches a 12TiB hole. Walking all ~12TiB just to _maybe_ spli= t the head > > and tail pages is asinine. > > > > And once kvm_arch_pre_set_memory_attributes() is dropped, I'm pretty su= re the > > _only_ usage is for guest_memfd PUNCH_HOLE, because unless I'm misreadi= ng the > > code, the usage in tdx_honor_guest_accept_level() is superfluous and co= nfusing. > > > > For the EPT violation case, the guest is accepting a page. Just split = to the > > guest's accepted level, I don't see any reason to make things more comp= licated > > than that. > > > > And then for the PUNCH_HOLE case, do the math to determine which, if an= y, head > > and tail pages need to be split, and use the existing APIs to make that= happen. >=20 > Just a note: Through guest_memfd upstream syncs, we agreed that > guest_memfd will only allow the punch_hole operation for huge page > size-aligned ranges for hugetlb and thp backing. i.e. the PUNCH_HOLE > operation doesn't need to split any EPT mappings for foreseeable > future. Oh! Right, forgot about that. It's the conversion path that we need to so= rt out, not PUNCH_HOLE. Thanks for the reminder!