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 71CA22E093A for ; Wed, 11 Mar 2026 13:31:06 +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=1773235867; cv=none; b=I/c24WVjT3slTNgOFK03hEiqEUEP4vAEJMsJinE9PNkRpxSif6vk+KsL5W/UW1NbG6k/p699oUVftPq8RoarEnznZnfTlPf8qP5wF6r/etQMv5l675Y28LE6vYgZS+d553QviWYC5YyQbh5bBe30io42qcCClzRbXR8aQxEiEu0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773235867; c=relaxed/simple; bh=/ZCHNQR0K/KHtlF/tI4c3P2/31qh0EwZ5OC2MqCjQzo=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=bE1BhmYuHK9wDLfwjNPCqJMyJ4f2mh07FDnv7MMgo9yTAJAXVhSC4fLzWYv9eYnKHgeoxUjoy3ksG+WbXKm0FmDt64Ff1qx2fnawLUNmBVoayZsxygKvu3FNd+WxGKHYAI1GBbPGHPYrpgyOqoAAiYkqM6XHXJR+3dNccf7R/5I= 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=ipioCNx5; 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="ipioCNx5" Received: by mail-pg1-f202.google.com with SMTP id 41be03b00d2f7-c739120475fso3832284a12.3 for ; Wed, 11 Mar 2026 06:31:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1773235866; x=1773840666; 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=GZLhg+7nDQkz8+/rpm0J7Hm6SsaOjD5Jd9IV860eNcY=; b=ipioCNx5IgOM1fQBuQHAJ0oQ66Ds/02ZYFnsR5erXlHAtMqmkzI5UFJnSTpO4w165E dQewrLI70BjNRkUp/oamvLZDIIgwwxTwDHq+BT6/MCddm+f4Xx43aF0ZQNdyniITyGlM wKeKS1Mrfy2bsXzaJC3bXirRBXIrvnjbijDBGz7ofeEFrCmQ2gsJ4X4Eyz13WjOCPH3L JQJSZlSLtBaPBn5peQUQJEoAM57u+UrMEIpz/qkHSA7s6V9qoDUB6J4kD9U5u2/92DAA pu7U1vlRrGpySP2+F9GI6QywSd0Kx36D65Ed726HosKZvPrKeCtpMRfB2CrsZ0IWxjlR zdpg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1773235866; x=1773840666; 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=GZLhg+7nDQkz8+/rpm0J7Hm6SsaOjD5Jd9IV860eNcY=; b=OqXxScviU8RQkEnRsZXgRinJQt4TrvPqt+AsOZLWkb1xbYWmwLV7e5w1EpIv7B54KJ hiTzOUPoN6/B1v6kAjS+UBoXsPt8UbZwqSgXwmPKqQ3ioyqdy0L1T6tX8DXQbkkmX0fR /tuQvTfUhwFtRrk+YSUkq+QLdNaXSqQ2shlXA8zjA5jQiGZ+lR5vY9/RCaPXHxjCGc9A Df2pmkiQKIIEyZT70tKsxbsGDcqgRrD6+Iw6rn/adzd4z9HsY4QU3KeHNvFtjtyjKeZ7 BLZHGiumfGkBYmIBnm+9EK0n4D02H2ifcINmqov6zMzx8BIy0X59ZhEcPgcO+IhJ6RT0 9vOw== X-Forwarded-Encrypted: i=1; AJvYcCUqvAGSkyz5zcW0ihx3itawtbsk/qkwbBHT9AO6IWbo5MPPAVfLKv9dDkJcJmOkns5gtgBNh9YqwJG/rtk=@vger.kernel.org X-Gm-Message-State: AOJu0Yx1ivuOYQM3imR5NPERyE5xVXumzH+AJYtD3f3sXNpB7pM7yXzX PgsojUGVWVFQ2AtD724NXn5k+TYLiHRzngURVaE6gsGH4a18YeVtfz1Zd5XJCKRPrJr9DKDZ4LA tPT9Vjw== X-Received: from pgjc17.prod.google.com ([2002:a63:d151:0:b0:c70:ab5b:1db6]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a21:a94:b0:398:9bb1:ad07 with SMTP id adf61e73a8af0-398c5f3d48cmr2534716637.22.1773235865707; Wed, 11 Mar 2026 06:31:05 -0700 (PDT) Date: Wed, 11 Mar 2026 06:31:03 -0700 In-Reply-To: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260311003346.2626238-1-seanjc@google.com> <20260311003346.2626238-5-seanjc@google.com> Message-ID: Subject: Re: [PATCH 4/7] KVM: x86: Add wrapper APIs to reset dirty/available register masks From: Sean Christopherson To: Yosry Ahmed Cc: Paolo Bonzini , Kiryl Shutsemau , kvm@vger.kernel.org, x86@kernel.org, linux-coco@lists.linux.dev, linux-kernel@vger.kernel.org, "Chang S . Bae" Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable On Tue, Mar 10, 2026, Yosry Ahmed wrote: > On Tue, Mar 10, 2026 at 5:34=E2=80=AFPM Sean Christopherson wrote: > > > > Add wrappers for setting regs_{avail,dirty} in anticipation of turning = the > > fields into proper bitmaps, at which point direct writes won't work so > > well. > > > > Deliberately leave the initialization in kvm_arch_vcpu_create() as-is, > > because the regs_avail logic in particular is special in that it's the = one > > and only place where KVM marks eagerly synchronized registers as availa= ble. > > > > No functional change intended. > > > > Signed-off-by: Sean Christopherson > > --- > > arch/x86/kvm/kvm_cache_regs.h | 19 +++++++++++++++++++ > > arch/x86/kvm/svm/svm.c | 4 ++-- > > arch/x86/kvm/vmx/nested.c | 4 ++-- > > arch/x86/kvm/vmx/tdx.c | 2 +- > > arch/x86/kvm/vmx/vmx.c | 4 ++-- > > 5 files changed, 26 insertions(+), 7 deletions(-) > > > > diff --git a/arch/x86/kvm/kvm_cache_regs.h b/arch/x86/kvm/kvm_cache_reg= s.h > > index ac1f9867a234..94e31cf38cb8 100644 > > --- a/arch/x86/kvm/kvm_cache_regs.h > > +++ b/arch/x86/kvm/kvm_cache_regs.h > > @@ -105,6 +105,25 @@ static __always_inline bool kvm_register_test_and_= mark_available(struct kvm_vcpu > > return arch___test_and_set_bit(reg, (unsigned long *)&vcpu->arc= h.regs_avail); > > } > > > > +static __always_inline void kvm_reset_available_registers(struct kvm_v= cpu *vcpu, > > + u32 available= _mask) >=20 > Not closely following this series and don't know this code well, but > this API is very confusing for me tbh. Especially in comparison with > kvm_reset_dirty_registers(). >=20 > Maybe rename this to kvm_clear_available_registers(), and pass in a > "clear_mask", then reverse the polarity: >=20 > vcpu->arch.regs_avail &=3D ~clear_mask; Oh, yeah, I can do something like that. I originally misread the TDX code = and thought it was explicitly setting regs_avail, and so came up with a roundab= out name. I didn't revisit the naming or the polarity of the param once I real= ized all callers could use the same scheme. No small part of me is tempted to turn it into a straigh "set" though, unle= ss I'm missing something, the whole &=3D business is an implementation quirk. > Most callers are already passing in an inverse of a mask, so might as > well pass the mask as-is and invert it here, and it helps make the > name clear, we're passing in a bitmask to clear from regs_avail.