Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp2010085lqp; Sat, 23 Mar 2024 21:38:36 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWSkbFatRfE4wjuKhKr2T9eiK8dZOY49QCUcT5TcvYxHSyrXffa9UI+AtZyYnxML3LHnmfbcDBQ9t9O4pZyZegiww9zr8E6d8BUSh0CSQ== X-Google-Smtp-Source: AGHT+IHVlmufOiSv6C3nZmZWRg9rSMzsA/x1YfQXaNrPPSubOdic4x1BXOPRsQ6Aj63dqGuK2KlF X-Received: by 2002:a05:6358:560c:b0:17f:5ef7:1579 with SMTP id b12-20020a056358560c00b0017f5ef71579mr4390745rwf.12.1711255115676; Sat, 23 Mar 2024 21:38:35 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711255115; cv=pass; d=google.com; s=arc-20160816; b=bKp2wCy3f4qfIdeRVSqFr0xRum42hQFhwmbXKuHMeOvxJB5x2kh596N7O0HNEzPfFW iaW7MGpWV8hg3cfNk2WSbFdpgHpLBT/99WggdqDdAJTHnGJ4Zd7p5a+PHAViaicg40ru YEEAZAN9uQkw1CV4NobNh87tlYCO9/qjtFzOENabEXPXvXVq1z8hzNjEWJGwLAdPGYSn jZmkFtz+a1aRBY+eps7o8DZrTCLYG0W0esWIwem51kcHb3Mb2siXPqLrzWDK7/U2k8U1 1jNRyrDSAE5k+p5oVpJeC9XL4dJIibHAFpkioeUm537iDsnx23vv6eOoleHk8AHnSgJp cJiw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:sender:dkim-signature; bh=XfqfORZ3SpUnxkQFpfbZwZ033SwpXLSkD0EZp4G9OUY=; fh=BzFAPEWjU7uoDgOHhb1YFIQiKf464XBvf5czI9hAQXc=; b=sT0+jk5MnRmUKFsC41sHwkPRv27oKtLF+ewCZducp8EVKoEwPa+KNfA+o2mXkw9OBP KlarEvWqVLYHcHucAOA4qs9YQpTPEZ9OkZV1yvzIx9EK7YF4fXCJDb9DiStbGLjk/YMI CFNsbfjsIiCWL8X5mGUcnZyeg+3ntOPAgtsgRUdO/aBcmyIoFwkcDzpRWpaPFWvprc+m Xg2HuS7+4on83KXinQoup5Sp7k8ajzXgZ15huhM5h8kasc9bD5jVkGalNhyKL7djFeBP 6pB0UVNM3bu33Hu4q2xBmWafPz2rB3ua2hcLddOb+Stef/inALc8JMbIVm5pZ3T3l8dy /8lQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=J3uzB4+K; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-112582-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-112582-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id 11-20020a63174b000000b005dc6cbf8440si5317137pgx.99.2024.03.23.21.38.35 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 23 Mar 2024 21:38:35 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-112582-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=J3uzB4+K; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-112582-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-112582-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 86ABEB214DF for ; Sun, 24 Mar 2024 04:38:27 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B492B1401B; Sun, 24 Mar 2024 04:38:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="J3uzB4+K" Received: from mail-wm1-f48.google.com (mail-wm1-f48.google.com [209.85.128.48]) (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 13FB728F1 for ; Sun, 24 Mar 2024 04:38:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.48 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711255088; cv=none; b=bVylm2zTThS1BXqMhs9BUWlOF6WpFpKnjw7QoMmKViQYc7Hk3slAY/6F2TlMXFQoESJ6LhyFS5b26ggMQieG/0uvViyGPZKAhcw9cUxnxRaNrbwT/TdqtClfJW2Jx2Pv69b12m+wV0fdZtoj1H0t4XrmA3VSBCcvt3pGEkvEs68= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711255088; c=relaxed/simple; bh=cY0I4yvinqbpTlBh/88UJRdHedECFcvi1rqbqKFLi0M=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=ZRblbFqc+8l8z6DpZM6cR/8JYA0UiNG8ZShhwm/kvemqVorwDH1c2d+rDRsEMgIpoJUcYitM30vvO1Uj+qqX3dYgp5RaXvhV4ZfbFeIaVB39Qnyl6dhu7VXMRN5F0wikrCEh+GdOuFobgaqHki94zjm59QA+XTaafYzWux6JqP4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=J3uzB4+K; arc=none smtp.client-ip=209.85.128.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-wm1-f48.google.com with SMTP id 5b1f17b1804b1-4148678b526so934005e9.0 for ; Sat, 23 Mar 2024 21:38:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1711255085; x=1711859885; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:sender:from:to:cc:subject:date:message-id :reply-to; bh=XfqfORZ3SpUnxkQFpfbZwZ033SwpXLSkD0EZp4G9OUY=; b=J3uzB4+KR7gD5fg5EGNdsOJ1uYXnAwPl9OKCF6i4tmis+JCcLJoSfTBiKuQ8tATfVm ncZxRG21H+1RSg8NF+WgggJNMXF5RewOi/LY47X2Dcy/Ycu1Pcn8rurCafuvf4uSOXIP xLvcUksdcu+9yh69okOchWWgmFOLHV1w5sVtnqeAqVSQDfX1ntLjwP0oya+hpNSHv4Zk CLMbNjdrMD7y17/NUeIeJKnDUv1FSogmYpMo3RaEEa1HTScMvA9AMes6ktmVCZ5vG6br EeCUUUo3APxhN61k68b2LlUHprVmOdY3KAq2LfrPGxf+C+7vFhwmS4JssKSftYLK6heS Hf1w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711255085; x=1711859885; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:sender:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=XfqfORZ3SpUnxkQFpfbZwZ033SwpXLSkD0EZp4G9OUY=; b=eU+A6Kbj6RkPLsDa6ihL5H5G5gH9AeliATHPF5rJ6KPhebWwsJtxBd8ZJpXDqNHlh5 Z/3H9XdO55TwPaoktGJ3oM7f3Q5ZunGSuNHsticHPjsQzKFBOzz+qu4IodhgVYm9jR48 UbieL990NSiMDbachxo+1WnUISkzyS+nVaUfsMwHEE8WUXxbQ4rCQdWCs/MfaTDaxY3u OlLxLP9W77MFeF5k+x2YyYMnHvr8oVEoReUb+zTmvzBkNxs4qhxM8Zs29P2Ke54SbStD ny7FKcmz1KGrB9lt2v6b9M9f8tJBtpBvYkxC3TCsjvWyTK7cZGMeh9R7zYWq/qTiEz41 gnFQ== X-Gm-Message-State: AOJu0YwC3BxVUE6rP+PjCId/zUxofCRv1XcHLGbPflEjLnx7Te4bUBux PuNYL2fkK6Qzbg0BjL3tgDBRy+NWeM9uUuV31YUwp7uvmM0H8U+J X-Received: by 2002:a05:600c:1382:b0:414:c5d:8520 with SMTP id u2-20020a05600c138200b004140c5d8520mr2611355wmf.27.1711255085163; Sat, 23 Mar 2024 21:38:05 -0700 (PDT) Received: from gmail.com (195-38-112-2.pool.digikabel.hu. [195.38.112.2]) by smtp.gmail.com with ESMTPSA id g4-20020a05600c310400b0041462294fe3sm4153320wmo.42.2024.03.23.21.38.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 23 Mar 2024 21:38:04 -0700 (PDT) Sender: Ingo Molnar Date: Sun, 24 Mar 2024 05:38:02 +0100 From: Ingo Molnar To: Dave Hansen Cc: linux-kernel@vger.kernel.org, jgross@suse.com, tglx@linutronix.de, x86@kernel.org, bp@alien8.de Subject: Re: [PATCH 1/4] x86/cpu: Add and use new CPUID region helper Message-ID: References: <20240322175629.01E8B39D@davehans-spike.ostc.intel.com> <20240322175630.72CE974F@davehans-spike.ostc.intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240322175630.72CE974F@davehans-spike.ostc.intel.com> * Dave Hansen wrote: > > From: Dave Hansen > > There are some (before now) unwritten rules about CPUID "regions". > Basically, there is a 32-bit address space of CPUID leaves. The > top 16 bits address a "region" and the first leaf in a region > is special. > > The kernel only has a few spots that care about this, but it's > rather hard to make sense of the code as is. > > Add a helper that explains regions. Use it where applicable. > > Signed-off-by: Dave Hansen > Cc: Juergen Gross > --- > > b/arch/x86/include/asm/cpuid.h | 59 ++++++++++++++++++++++++++++++++++++++ > b/arch/x86/kernel/cpu/common.c | 13 +++----- > b/arch/x86/kernel/cpu/transmeta.c | 9 +---- > b/arch/x86/xen/enlighten_pv.c | 9 +---- > 4 files changed, 69 insertions(+), 21 deletions(-) > > diff -puN arch/x86/include/asm/cpuid.h~cpuid-regions arch/x86/include/asm/cpuid.h > --- a/arch/x86/include/asm/cpuid.h~cpuid-regions 2024-03-18 15:12:20.676308753 -0700 > +++ b/arch/x86/include/asm/cpuid.h 2024-03-22 09:17:13.296507986 -0700 > @@ -168,4 +168,63 @@ static inline uint32_t hypervisor_cpuid_ > return 0; > } > > +/* > + * By convention, CPUID is broken up into regions which each > + * have 2^16 leaves. EAX in the first leaf of each valid > + * region returns the maximum valid leaf in that region. > + * > + * The regions can be thought of as being vendor-specific > + * areas of CPUID, but that's imprecise because everybody > + * implements the "Intel" region and Intel implements the > + * AMD region. There are a few well-known regions: > + * - Intel (0x0000) > + * - AMD (0x8000) > + * - Transmeta (0x8086) > + * - Centaur (0xC000) > + * > + * Consider a CPU that where the maximum leaf in the Transmeta > + * region is 2. On such a CPU, leaf 0x80860000 would contain: > + * EAX==0x80860002. > + * region-^^^^ > + * max leaf-^^^^ Minor nit: s/a CPU that where the /a CPU where the > + * possible for the last basic leaf to _resemble_ a > + * valid first leaf from a region that doesn't exist. > + * But Intel at least seems to pad out the basic region > + * with 0's, possibly to avoid this. > + */ > + if ((eax >> 16) != region) > + return 0; > + > + return eax; There's whitespace damage at the 'if' line. Thanks, Ingo