From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pg1-f201.google.com (mail-pg1-f201.google.com [209.85.215.201]) (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 1284C1DBB3A for ; Tue, 28 Oct 2025 00:29:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761611386; cv=none; b=RjsC5x44DkDa4BFVMxbzUo2187z7JXf3MdymyL4rRSvwPhA4D04AfB+Tg5qi6iyr/RShu953ct5GNWuyirKZfmktE2gEOqx4V+OKqep8sWAbo6TZmyScHkZjC0FEVAemoMBO2RvT2WbgM3NVyFMnQ+sASw7Km7xoVX3kktd7L1Y= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761611386; c=relaxed/simple; bh=qyo5vYPBXQcSiICdjzpbw4YoCeaDaAVfCf6SQjhOYiM=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=W+RIihrgKV5KASddBVrEkzFMy2alL8WFTJObD9IxCczEON42VBL5tWvMMkLrAL9KHgDs57NJAuubTpDlKiiIxa7QETXDzQyg2lHUveX20ZsPc4KY9gK8bnARtPorKkTAAmi/4C/dFxMc1v0vYx/sohtCIKgMN4XOkemEoA/Ns/c= 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=ItOS988E; arc=none smtp.client-ip=209.85.215.201 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="ItOS988E" Received: by mail-pg1-f201.google.com with SMTP id 41be03b00d2f7-b55283ff3fcso3354695a12.3 for ; Mon, 27 Oct 2025 17:29:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1761611384; x=1762216184; darn=lists.linux.dev; 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=3fZq3tbinLN9iV6tR9wh+L1TcJJLRbds3pWQbE4SVPQ=; b=ItOS988Eyy5FQEAEIKgERADi2ctK2M6Zn7iRYVK+5rpuzUVcpteufnhreQL0EoQqhx swAvPJ1N4Na1uAswSaSPKDbWxybh1w5clrHRitXdakBsm89n36+Bjxaei4ToW90YbCs2 O7GT0nNxvsvsOGdHdqrYIPW6/JPNiNHNLVxkMTLgX+ejqJCZE+JoZlSQRbbvcEub0s97 FSSHAzKBCz+B4UYhrRO0+h+5oRcl9UCMvFQPCNV638259/ESpskaFWRIM9ftrUNFUxdI EucP8w81eQnVjSL4vr1MWonxS/5sQI1NU0XU0UdAnbH52YTadfe/ZC1YCrXbBDr5/d7e dvlA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1761611384; x=1762216184; 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=3fZq3tbinLN9iV6tR9wh+L1TcJJLRbds3pWQbE4SVPQ=; b=WgOXtrB/1E28sykTdH1vAa/QMm3Be/8snWyx2AQuxftt3i2dVlDckm7E8rvhfSCR2p OGIx+ZQKkDO+7Hl73VlM/7ezpFhvt4dYUf6JQJLB9PuqpPZyLTb5YjYHQVzCAOijLPpl Odsuxau1VQnCyGSZpyAAl3sIBknUAI8wd4TXf1Kiq3pPQY8wM+Ydcmuw8BaC/C9nGWqm FoI3c1AADNTpmmU/tM1NPcCY8NOAF0+GhrVQpa0mnBdUYfsSm1uIdALV6H6457PUZq8N /cTA4QmzsvIsw4Rt0bdJiSsmu6lLLeYCJxXpDxL2bB/2HvE2mRBh+kypQWr2/WmzffCx jGaQ== X-Forwarded-Encrypted: i=1; AJvYcCU0Y6rs+UscbkGRhO1X3r7nNSyAruUQN9bHKtybUJwy0dmqbMOSzr8EzjuwgKbeZaIybiZKPskhlzau@lists.linux.dev X-Gm-Message-State: AOJu0Yx2fm2j6cswHrnZtqCbTtOsbFtGYJWTmIXnWwjIb7BYdMoNvHEQ NpD/fs0NjecjRi5aRSyTMIsKVTPIuvPInk+dXpm2zIbrJFMZ7D9t/85xM+PAEr6L9/X6y3al13R OPtl8MQ== X-Google-Smtp-Source: AGHT+IEcbPffJX+DPzKHtANj5YoID2qTNS+wCvJIhOFTengBDdmvUTitjaF5SaOhKDAJ4Iu3BAJZiOrVVlg= X-Received: from pjqc14.prod.google.com ([2002:a17:90a:a60e:b0:33b:51fe:1a77]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:3d0f:b0:33e:30e8:81cb with SMTP id 98e67ed59e1d1-34027a0775bmr1898674a91.13.1761611384405; Mon, 27 Oct 2025 17:29:44 -0700 (PDT) Date: Mon, 27 Oct 2025 17:29:42 -0700 In-Reply-To: <59ae9957-88a8-4777-9bd2-196e8b4eb8ac@linux.intel.com> Precedence: bulk X-Mailing-List: linux-coco@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20251017003244.186495-1-seanjc@google.com> <20251017003244.186495-14-seanjc@google.com> <5dea4a3d-c7b7-48f0-b2d5-7597e0cd5f00@linux.intel.com> <59ae9957-88a8-4777-9bd2-196e8b4eb8ac@linux.intel.com> Message-ID: Subject: Re: [PATCH v3 13/25] KVM: TDX: Fold tdx_mem_page_record_premap_cnt() into its sole caller From: Sean Christopherson To: Binbin Wu Cc: 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 , Paolo Bonzini , "Kirill A. Shutemov" , 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 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable On Mon, Oct 27, 2025, Binbin Wu wrote: >=20 >=20 > On 10/25/2025 12:33 AM, Sean Christopherson wrote: > > On Fri, Oct 24, 2025, Binbin Wu wrote: > > >=20 > > > On 10/17/2025 8:32 AM, Sean Christopherson wrote: > > > > Fold tdx_mem_page_record_premap_cnt() into tdx_sept_set_private_spt= e() as > > > > providing a one-off helper for effectively three lines of code is a= t best a > > > > wash, and splitting the code makes the comment for smp_rmb() _extr= emely_ > > > > confusing as the comment talks about reading kvm->arch.pre_fault_al= lowed > > > > before kvm_tdx->state, but the immediately visible code does the ex= act > > > > opposite. > > > >=20 > > > > Opportunistically rewrite the comments to more explicitly explain w= ho is > > > > checking what, as well as _why_ the ordering matters. > > > >=20 > > > > No functional change intended. > > > >=20 > > > > Reviewed-by: Rick Edgecombe > > > > Signed-off-by: Sean Christopherson > > > Reviewed-by: Binbin Wu > > >=20 > > > One nit below. > > >=20 > > > [...] > > > > + /* > > > > + * If the TD isn't finalized/runnable, then userspace is initiali= zing > > > > + * the VM image via KVM_TDX_INIT_MEM_REGION. Increment the numbe= r of > > > > + * pages that need to be mapped and initialized via TDH.MEM.PAGE.= ADD. > > > > + * KVM_TDX_FINALIZE_VM checks the counter to ensure all mapped pa= ges > > > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0^ > > > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 Nit: Is pre-mapped better? > > Yeah, updated (and then it gets deleted a few commits later :-) ). > Oh, right, nr_premapped will be dropped later. >=20 > Since the whole nr_premapped will be dropped, do we still need a cleanup = patch > like patch 12 which will be dropped finally? We don't strictly "need" the cleanups, but IMO intermediate cleanups are of= ten worth doing even if they get thrown away, soo that the code is in a (hopefu= lly) better state when the "big" functional change comes along. I.e. if code 'X= ' is easier to understand than code 'Y', then theoretically/hopefully X=3D>Z is = also easier to understand than Y=3D>Z.