From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pj1-f73.google.com (mail-pj1-f73.google.com [209.85.216.73]) (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 3735D1E1E12 for ; Tue, 28 Oct 2025 00:29:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.73 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761611387; cv=none; b=lvRtFQdqkFCKiwrMeYbeD1KKR+gXcPuCvtcvPT9RNSm+S1MuSpD+wVmUEY1CaUdtIgYP0Kdpcok0IzYjW7NPOBGQrGY7XRniddtdNpTDIHJxHiLUyUz7mNTeqe6HWrmzHc461BELTdysmzGyZgjM3ObddHUt6aPWYkEAuYh4qLM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761611387; c=relaxed/simple; bh=qyo5vYPBXQcSiICdjzpbw4YoCeaDaAVfCf6SQjhOYiM=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=Pp7u0Ycv8k4OPCxnEYd4aWXFIDiz0UDqMVjwP5G4Cm/F0PdawmYMzROfG7MqrJlXGJTRCJZdjpNHTxfX2KF4Cy0c1+zXHnCQgdiiBA+h+3Vzvd3mtcoZX9mhxBC4X1t4FJpKU53MejMk84p8xWtkqO7l3sGvmqwM74sPdroO+WQ= 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=0Qn5cXtj; arc=none smtp.client-ip=209.85.216.73 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="0Qn5cXtj" Received: by mail-pj1-f73.google.com with SMTP id 98e67ed59e1d1-32ee157b9c9so4077977a91.2 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=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=3fZq3tbinLN9iV6tR9wh+L1TcJJLRbds3pWQbE4SVPQ=; b=0Qn5cXtjMYcc6CIS2H+1Z74GJ2Jp6I330AeAsK9DA0QGAjHitp8PleqTjjq5SHtwBW X3TkCnWUkH+3mcXGED0VDYN52c8K3cbVb9vL64HYRyYfiMA5SX9KoQ9gk4hNvgA2UgCy xfw3WSILSBjcye1CfHBueOPfGQ6Bdxc9Tyj0b3IAhJGQPROAM8FvJutS4SnzMxG1jP+G mIGxPum8YQaHDI4U59yRipRLjLXdNGd0Ph9T87fnHeM/A57be2LkxC3QPnXB3GjUYp+V 27rPKJ4fjgRgiYmICJdxFuRjcgTMSflcJMczmosWgakqLLIiNU8LvX+USP6AyS0BlSGm xh5A== 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=Jankm6ytl/wN/dDoUJ6byD06nl2whUjoiNuaS2r6ailcbSF72OL+Xh/4VG+0M+qgY8 bswBNgq2kdvnp1Q7EGNRrEcFs66r9ePe/eKzaQjtH7gAGlwA+FMN0IWaEToTU5Ld9f1K Y83Do2RjQ0KjoWQ7rtt3cmIlOwHsQCuvLogsIfc7+TVcw/1MIw4ucHZRxSfWCcTv0Jyv 7UILOfMujxSnos+U6Eiw2fFCidnZUIvaENeGSVJ8ttt6+hZmT16xW2joiytIn4aP3Lt/ L3rv6aEWDb+UvtK9v8Pyt0F4XM9vyR7Ih+7vErUEy/C692kVJvmvNDoNXGbMaUspWQe/ PPKg== X-Forwarded-Encrypted: i=1; AJvYcCW1L9BK0R9Qq4HjExsagiy2W4eGwpiVqX8FTJqXZOpKXMBrTF5naRv+MBI6eUjJTmHGyc2QnzxBgRn0@vger.kernel.org X-Gm-Message-State: AOJu0YxS48PXpfaLVCJwM0h1gv84k3DHgUyogMGLVA7fj7XutOB8fbHs Paj8H4hBLo2S67OfRjccD/Er+A3DQKFEUsU+I+TVQNVp7kcv1EYlhpLje3S6LsJt9+2Km95taVj owB1Eqg== 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-mips@vger.kernel.org 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.