Received: by 2002:a05:7412:798b:b0:fc:a2b0:25d7 with SMTP id fb11csp586146rdb; Thu, 22 Feb 2024 12:49:14 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWgq+utQf4XFDi19rjeoUybIMPwAHnH+HQT2e16MSjuId+aqcOcK+VTtsQVcXpLhS7bxZwytFVyO2nDe+gteqEyxgQtGQKAraMzgSr8Ig== X-Google-Smtp-Source: AGHT+IE1RBR8u3TktjdPhljFt+GSAdf28FYg8Rl8NUhTR458Ds0BGTa8502FQ2EnJ+NhocISzv6i X-Received: by 2002:a05:6358:6f1f:b0:17a:e13b:3a4a with SMTP id r31-20020a0563586f1f00b0017ae13b3a4amr20568423rwn.29.1708634954690; Thu, 22 Feb 2024 12:49:14 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708634954; cv=pass; d=google.com; s=arc-20160816; b=y+7kfqFR/Elfp0TMvHayYWYHFOQBcS4rNFsxaaPOK1VUAaR5huvroYfocZrOAdAvE7 91Kp+k4gpMdyIgZFrpTwMOM+pMiPePTNHbUtOBoOY8KdB7i0e6P2bMhj4tBeRatr5Vid h0t4VCBDS8872RIkj0c3b47UdywIsXYPvv3H3w7yI2Yxe4j08A39b1KMhX0bZ96W16D/ 1sQ9v5vNQJXBLZZF4nT7pVvlEIp73qEjTXceWuxX2hpoZwQuK9AwrywMfKxhA3Cx4KNu RQrBrfMvTeyyncYl4GtpCDv2iS2faOEk7R6coVh6IW/TR37+JqFXn8bGOoaqrlpFTcI0 HNUA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-unsubscribe:list-subscribe:list-id:precedence:message-id :in-reply-to:references:date:from:cc:to:subject:dkim-signature; bh=V7Tt3E8FZI8GWpw2rG7tlfJSffk/MirrPljzDwtYrSs=; fh=HUgOPOMLUPcroonsK10/uEWpbBCP57e0QFUoVmMwghQ=; b=Fi13bhyC4KhFm1ed+BLYqWOwOeLw/i+3oAqNLOBYNLrQWAqdvXWYo3fJuQAT8gOhNw 3kXHfZgWhhu2YmV4Vt8gW6qz6QngxBAjNDrhMu1ZEUTN6doxmY/yu6ZFWSHnCMVvQDz6 U1XXzhUo5JapJagJgQnYgHPnyRk7ieo35bTRy0a0IiJB0WGCAL8oTn2rdSWQMnoWTZ37 mdynH2bK4YsCsR7SZWZetiw/gNh/q3DeZ5q40LtkOI7HWo7EJeXE2krlUvjf4AHdUkhD vzdTpijPpplWmGlvA8KbwESzU9lfh5NZlOQvSwTUdlSan2jqZaWFUc6Ktb6QmWke5fZb ppyA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Oj0twNyG; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-77175-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-77175-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id bx41-20020a056a02052900b005e43479dc38si4144548pgb.495.2024.02.22.12.49.13 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 12:49:14 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-77175-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=@intel.com header.s=Intel header.b=Oj0twNyG; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-77175-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-77175-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com 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 283FAB24A40 for ; Thu, 22 Feb 2024 18:48:01 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E732914CAA0; Thu, 22 Feb 2024 18:39:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="Oj0twNyG" Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.16]) (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 B7BE614938E for ; Thu, 22 Feb 2024 18:39:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.16 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708627196; cv=none; b=tjufXbFUmDQRFQzjZf2CTK+M4pWV8xFfhXDLGPgyinMSMLoguKV84s1N8FM5E8f/93FHnqgfvD1jljjJWAy/hkMti+2bTFplzhx+4pJGyaeqkPSKAQaOJXX+GNhLH1rMgS6sU9n4vqo0K06TKROJgrQc2jriqa4jDE4S8kd0vy8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708627196; c=relaxed/simple; bh=nx/rpbn5tIj5Y+XhodSjBqWfpjIWIvV6is8OneYevSs=; h=Subject:To:Cc:From:Date:References:In-Reply-To:Message-Id; b=Uu1QYc3UnCBO3ZOFRNsMTYDc1IzZ3ktQwkAQssJLX8GVl2JrrKP2B7a/mZyqsSKV+s1Nv0iD2HMcKpMnkpZMjIJRA6E5GnGnHuzuSQtqXABbUbMMJaMaIOHoLYLg5mnI/SCHefbpbhfgtnCpi8HDk5uEfgNK84aFU8G9DZzPWAI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=Oj0twNyG; arc=none smtp.client-ip=198.175.65.16 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1708627195; x=1740163195; h=subject:to:cc:from:date:references:in-reply-to: message-id; bh=nx/rpbn5tIj5Y+XhodSjBqWfpjIWIvV6is8OneYevSs=; b=Oj0twNyGf8Qgta8Naju5WFdpqHOinqn/x7Lbqb8unDinzAeW+PyxLSj+ 3JkTAl8HMYn3EHhgeiVYnwJe5i3OOUgI0LPtF6TmMil/XXK+LUn59qkKO gkN4fc/xlmuQsrepRc7PjS3mPLEEqvbclGoHSXXS7iP4Samz8P4+uzCky 89qBsQB/5U/AUTVBzuZYPCSZlyX18/fSyQgGBK8H31fI50zgUwUvYTFG0 6mnsHcfcW3I7dXSbPGMCCruUObWVMn6JEZvArL1uzW56xavqJT4Jy6UzR lLRMGcd+6I49SY5Ne6dG1UfHIpZCWr0xPoFsC+584rLruPyn2cjzaqxbL g==; X-IronPort-AV: E=McAfee;i="6600,9927,10992"; a="3031846" X-IronPort-AV: E=Sophos;i="6.06,179,1705392000"; d="scan'208";a="3031846" Received: from orviesa008.jf.intel.com ([10.64.159.148]) by orvoesa108.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Feb 2024 10:39:55 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.06,179,1705392000"; d="scan'208";a="5975588" Received: from davehans-spike.ostc.intel.com (HELO localhost.localdomain) ([10.165.164.11]) by orviesa008.jf.intel.com with ESMTP; 22 Feb 2024 10:39:55 -0800 Subject: [RFC][PATCH 21/34] x86/cpu: Consolidate CLFLUSH size setting. To: linux-kernel@vger.kernel.org Cc: kirill.shutemov@linux.intel.com,pbonzini@redhat.com,tglx@linutronix.de,x86@kernel.org,bp@alien8.de,Dave Hansen From: Dave Hansen Date: Thu, 22 Feb 2024 10:39:54 -0800 References: <20240222183926.517AFCD2@davehans-spike.ostc.intel.com> In-Reply-To: <20240222183926.517AFCD2@davehans-spike.ostc.intel.com> Message-Id: <20240222183954.9A6E5428@davehans-spike.ostc.intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: From: Dave Hansen Right now, cpu_detect() establishes ->x86_clflush_size on each CPU that. supports CLFLUSH. As you might have guessed, that per-cpu value is no longer used. Move the setting to get_cpu_address_sizes() which is only called on the boot CPU. Consolidate all of the ->x86_clflush_size logic into a single helper. This removes the (cap0 & (1<<19) aka X86_FEATURE_CLFLUSH check before reading the CLFLUSH size out of CPUID[1]. Those bits are presumably either 0 or have actual data about CLFLUSH in them. Signed-off-by: Dave Hansen --- b/arch/x86/kernel/cpu/common.c | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) diff -puN arch/x86/kernel/cpu/common.c~later-clflush_size-detect arch/x86/kernel/cpu/common.c --- a/arch/x86/kernel/cpu/common.c~later-clflush_size-detect 2024-02-22 10:08:58.728856457 -0800 +++ b/arch/x86/kernel/cpu/common.c 2024-02-22 10:08:58.732856614 -0800 @@ -935,6 +935,27 @@ static void get_cpu_vendor(struct cpuinf this_cpu = &default_cpu; } +static u16 detect_clflush_size(struct cpuinfo_x86 *c) +{ + u16 clflush_size = 0; + + if (c->cpuid_level >= 0x00000001) { + u32 eax, ebx, ecx, edx; + + cpuid(0x00000001, &eax, &ebx, &ecx, &edx); + + clflush_size = ((ebx >> 8) & 0xff) * 8; + } + + if (clflush_size) + return clflush_size; + + /* Return some mostly sane defaults: */ + if (IS_ENABLED(CONFIG_X86_64)) + return 64; + return 32; +} + void cpu_detect(struct cpuinfo_x86 *c) { /* Get vendor name */ @@ -952,11 +973,6 @@ void cpu_detect(struct cpuinfo_x86 *c) c->x86 = x86_family(tfms); c->x86_model = x86_model(tfms); c->x86_stepping = x86_stepping(tfms); - - if (cap0 & (1<<19)) { - if (c == &boot_cpu_data) - c->x86_clflush_size = ((misc >> 8) & 0xff) * 8; - } } } @@ -1111,17 +1127,17 @@ void get_cpu_address_sizes(struct cpuinf if (IS_ENABLED(CONFIG_X86_64)) { x86_config.phys_bits = 36; x86_config.virt_bits = 48; - c->x86_clflush_size = 64; } else { x86_config.phys_bits = 32; x86_config.virt_bits = 32; - c->x86_clflush_size = 32; if (cpu_has(c, X86_FEATURE_PAE) || cpu_has(c, X86_FEATURE_PSE36)) x86_config.phys_bits = 36; } } + c->x86_clflush_size = detect_clflush_size(c); + c->x86_cache_bits = x86_config.phys_bits; c->x86_cache_alignment = x86_clflush_size(); @@ -1827,11 +1843,8 @@ static void identify_cpu(struct cpuinfo_ c->topo.cu_id = 0xff; c->topo.llc_id = BAD_APICID; c->topo.l2c_id = BAD_APICID; -#ifdef CONFIG_X86_64 - c->x86_clflush_size = 64; -#else +#ifndef CONFIG_X86_64 c->cpuid_level = -1; /* CPUID not detected */ - c->x86_clflush_size = 32; #endif memset(&c->x86_capability, 0, sizeof(c->x86_capability)); #ifdef CONFIG_X86_VMX_FEATURE_NAMES _