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 D49B41BBBFC for ; Thu, 29 Jan 2026 15:12:03 +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=1769699525; cv=none; b=UUHwNnAPyEKGSDPJsxkohlG/7UjjSxnZN3vU6TgIfBzLeo2BtRcRQuzCyunz1kInHlEeiJPMAi9Np4XY/hqgp/cl5ffcOWVy4FlXHwr0stkVXPhD52eOZ0SGRgx7n8Oast496NBPdJ5Mv9P/rxViWcEwlNl3GDvQwxvOV9ycNPE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769699525; c=relaxed/simple; bh=sA5T9gW0TAD5jrJgR0Anj1Ohz7jzIcsd3GswmubIOXE=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=NCo2CWPfCQuq9ZT1wgO3pQtCq+GB5Y/AaOs/+ZJDX2NxseU3HOHco7MBWBFWqVtVDxhdYhDtK2UWbL4QzJysFX1FnPPRH81V/jIqsBXu3rOvw1yDCwdf/uAD63/ZTwCaU/CLWBfIauGzCTE2SGDoGu2MIu5sz6MP/7eYYzVOkbI= 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=NrL+KWb4; 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="NrL+KWb4" Received: by mail-pg1-f202.google.com with SMTP id 41be03b00d2f7-c634b862fcfso717654a12.2 for ; Thu, 29 Jan 2026 07:12:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1769699523; x=1770304323; 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=s9kHKjSq4qleJmEsJAzaJ+D2RjwhSg1oHgKsobJdsyg=; b=NrL+KWb4njsBPnR7kR8MqHF+2WRog92yzafMnnn/VB3AlO4Il1PeJ10yWk7VjfDaNc mjMY6+qcKbtpd9C/FS9rd8cA0ri1SyGofWMGXwEs0OEWXi6kmPbwyFtkffkM8EPRYKBy x4EOEWElM3P2UVws+mOQWG+bPFCnowbPtgWo0Ocwh3jSaMMQVfH9zaOHt4IOrZ7DhzpO LvpqWczuyatoYUVmAc3Y12JQYlhLDtUcMecMbhHAGveYQwKl5Y+Gy2vpkB0wQ2InwFe3 epy+1RgeRQn/iBfJk1W2wX3duxJ1IfUh2zPkOFhOtoOJPcoblyzA5Uy77ebNiqbjxoli Dbqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1769699523; x=1770304323; 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=s9kHKjSq4qleJmEsJAzaJ+D2RjwhSg1oHgKsobJdsyg=; b=IfZYudYKSWRQZc9ZbX2Zv+kowsu1hpWULKqybyCUdBMK0HFE5/TL098yG8A2HEFO4K vQ9Yd0JKDd9Myw7/AnAyb4XeNDTfZUuVxJX7tqoAwppzqa38wF5N+iPBgcFb4pEZQ2ND A7dcXif7YkWa61whlzXM9fJnVAMlz2fgWrZ7Wr3hzNMN2asy0caCMBrzBPQYHwpbwPC5 JAnYgh3ktMmvNlo2N0+iZugm3veLFcK3Ot1Dzw2CA9cWRsM4BrTvDV6verD21Rdvn4RF M27s9yLl8JYO9fHskrp+W6yt5z6tPI8iOG3MvsVpsKc5zeVJw/Lg3JlYVc7SEHOMUTt2 0ywQ== X-Forwarded-Encrypted: i=1; AJvYcCX4UJt6zM9Z44Pk/NV9ON5xRwK5PnZLKo/qhRlkcz8og8pO8k4vYWxRkBTQkDsOpr91rpul9ZEnBD+PJF8=@vger.kernel.org X-Gm-Message-State: AOJu0Yw9O6b2Nkqsn80GCMqmQTYYwWdIhyiAn9xNp6eTOKM8D8oNFHxz zgtUX+NQVuI2NIBzAviOFXhZCfsum6dghV9foT6vHfGDGP/UZjM6oFYpkwnkPq+D8x9lUiNo4vP x87OdUw== X-Received: from pglq12.prod.google.com ([2002:a63:504c:0:b0:c5e:eb90:df6e]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6300:95:b0:38e:5f46:bdfb with SMTP id adf61e73a8af0-38ec657fe37mr9054043637.73.1769699523234; Thu, 29 Jan 2026 07:12:03 -0800 (PST) Date: Thu, 29 Jan 2026 07:12:01 -0800 In-Reply-To: <7f045418-6ce4-4f2f-a3ee-4ddc3cf2fda5@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260128014310.3255561-1-seanjc@google.com> <20260128014310.3255561-3-seanjc@google.com> <7f045418-6ce4-4f2f-a3ee-4ddc3cf2fda5@intel.com> Message-ID: Subject: Re: [PATCH v2 2/3] KVM: x86: Harden against unexpected adjustments to kvm_cpu_caps From: Sean Christopherson To: Xiaoyao Li Cc: Paolo Bonzini , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Mathias Krause , John Allen , Rick Edgecombe , Chao Gao , Binbin Wu , Jim Mattson Content-Type: text/plain; charset="us-ascii" On Thu, Jan 29, 2026, Xiaoyao Li wrote: > On 1/28/2026 9:43 AM, Sean Christopherson wrote: > > Add a flag to track when KVM is actively configuring its CPU caps, and > > WARN if a cap is set or cleared if KVM isn't in its configuration stage. > > Modifying CPU caps after {svm,vmx}_set_cpu_caps() can be fatal to KVM, as > > vendor setup code expects the CPU caps to be frozen at that point, e.g. > > will do additional configuration based on the caps. > > > > Rename kvm_set_cpu_caps() to kvm_initialize_cpu_caps() to pair with the > > new "finalize", and to make it more obvious that KVM's CPU caps aren't > > fully configured within the function. > > > > Signed-off-by: Sean Christopherson > > --- > > arch/x86/kvm/cpuid.c | 10 ++++++++-- > > arch/x86/kvm/cpuid.h | 12 +++++++++++- > > arch/x86/kvm/svm/svm.c | 4 +++- > > arch/x86/kvm/vmx/vmx.c | 4 +++- > > 4 files changed, 25 insertions(+), 5 deletions(-) > > > > diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c > > index 575244af9c9f..7fe4e58a6ebf 100644 > > --- a/arch/x86/kvm/cpuid.c > > +++ b/arch/x86/kvm/cpuid.c > > @@ -36,6 +36,9 @@ > > u32 kvm_cpu_caps[NR_KVM_CPU_CAPS] __read_mostly; > > EXPORT_SYMBOL_FOR_KVM_INTERNAL(kvm_cpu_caps); > > +bool kvm_is_configuring_cpu_caps __read_mostly; > > I prefer the name, kvm_cpu_caps_finalized. But not strongly, so "finalized" reads too much like the helper queries if the caps are already finalized, i.e. like an accessor.