From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B236376413; Mon, 8 Apr 2024 13:19:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712582398; cv=none; b=uHDgRf6WIVleQoqJwCeJzqOxyCfDZ4PUuzci+jKmL2Q5mmHVX2vx/AvsucJQksMheMyNZRNOMAxKPUJ+oNAroE3IFCURU4CPvNxnhvOfd+ahtCiu/KWZ/yKMi7cIWNwLqEnwqSa2kkilt7C6IMC2YlI2QEq+iolkIRiX6CXMpB4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712582398; c=relaxed/simple; bh=Nyrey9Gwv3foM57Y+pF3CuY0RVm5EHjZqS35yOa31YQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=VJkkfgixOXLALnM8q0RvYzOCaqeKGEtYi3kwajkq/MxMhf45P2fZcdezqwvdfDUKTDAdAUMH4BfJxqxigGx/R/8ulYcT5DOT0Rw8U5zEqX44r1xq110LekPZFOrlMRywjQOZvekzFHrIpgxYH41L/8DWpPxqYuw4TJByEJYKojk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=hwJpp5YI; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="hwJpp5YI" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3270BC433C7; Mon, 8 Apr 2024 13:19:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1712582398; bh=Nyrey9Gwv3foM57Y+pF3CuY0RVm5EHjZqS35yOa31YQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hwJpp5YIQTpJuD4uwf3817+wss2/4J8NO72F4a4Ki8XZi/XCMwlSTG8BN2zpoYsq5 hbgQ64bZYqu5/UXSTPAq/ZlrfERAfOJrx2wtmHAU/5D1iih5NGJm2V19RfzLeXy3ay huUn/vJdB8LhOg5GyMoYly7iPibRFW/HNRNQGlBY= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Sandipan Das , Sean Christopherson , Dave Hansen , Linus Torvalds Subject: [PATCH 6.8 071/273] x86/cpufeatures: Add CPUID_LNX_5 to track recently added Linux-defined word Date: Mon, 8 Apr 2024 14:55:46 +0200 Message-ID: <20240408125311.507161910@linuxfoundation.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240408125309.280181634@linuxfoundation.org> References: <20240408125309.280181634@linuxfoundation.org> User-Agent: quilt/0.67 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.8-stable review patch. If anyone has any objections, please let me know. ------------------ From: Sean Christopherson commit 8cb4a9a82b21623dbb4b3051dd30d98356cf95bc upstream. Add CPUID_LNX_5 to track cpufeatures' word 21, and add the appropriate compile-time assert in KVM to prevent direct lookups on the features in CPUID_LNX_5. KVM uses X86_FEATURE_* flags to manage guest CPUID, and so must translate features that are scattered by Linux from the Linux-defined bit to the hardware-defined bit, i.e. should never try to directly access scattered features in guest CPUID. Opportunistically add NR_CPUID_WORDS to enum cpuid_leafs, along with a compile-time assert in KVM's CPUID infrastructure to ensure that future additions update cpuid_leafs along with NCAPINTS. No functional change intended. Fixes: 7f274e609f3d ("x86/cpufeatures: Add new word for scattered features") Cc: Sandipan Das Signed-off-by: Sean Christopherson Acked-by: Dave Hansen Signed-off-by: Linus Torvalds Signed-off-by: Greg Kroah-Hartman --- arch/x86/include/asm/cpufeature.h | 2 ++ arch/x86/kvm/reverse_cpuid.h | 2 ++ 2 files changed, 4 insertions(+) --- a/arch/x86/include/asm/cpufeature.h +++ b/arch/x86/include/asm/cpufeature.h @@ -33,6 +33,8 @@ enum cpuid_leafs CPUID_7_EDX, CPUID_8000_001F_EAX, CPUID_8000_0021_EAX, + CPUID_LNX_5, + NR_CPUID_WORDS, }; #define X86_CAP_FMT_NUM "%d:%d" --- a/arch/x86/kvm/reverse_cpuid.h +++ b/arch/x86/kvm/reverse_cpuid.h @@ -102,10 +102,12 @@ static const struct cpuid_reg reverse_cp */ static __always_inline void reverse_cpuid_check(unsigned int x86_leaf) { + BUILD_BUG_ON(NR_CPUID_WORDS != NCAPINTS); BUILD_BUG_ON(x86_leaf == CPUID_LNX_1); BUILD_BUG_ON(x86_leaf == CPUID_LNX_2); BUILD_BUG_ON(x86_leaf == CPUID_LNX_3); BUILD_BUG_ON(x86_leaf == CPUID_LNX_4); + BUILD_BUG_ON(x86_leaf == CPUID_LNX_5); BUILD_BUG_ON(x86_leaf >= ARRAY_SIZE(reverse_cpuid)); BUILD_BUG_ON(reverse_cpuid[x86_leaf].function == 0); }