Received: by 2002:ab2:6816:0:b0:1f9:5764:f03e with SMTP id t22csp2365829lqo; Mon, 20 May 2024 03:43:56 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCX3+ZwlSAbBpHM2jCCBLjzQLIy65sjd11hTriO5HjHuvPkBq4Uz7R3VRVEFyJZbi77IQLtUMY5NNyUelRv8bVG1r7+ZuEFAfZ8lYRivTw== X-Google-Smtp-Source: AGHT+IGmnZcP+3XGpAqNfzbpi3bcjr61ofugjx6X/PUoSPJP56Ztn1x9Wsi8BRE78/bjNhVgEBIG X-Received: by 2002:a4a:4881:0:b0:5b2:ef4:873d with SMTP id 006d021491bc7-5b28196c378mr28926046eaf.4.1716201836621; Mon, 20 May 2024 03:43:56 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716201836; cv=pass; d=google.com; s=arc-20160816; b=nNlmFu/uR27qgOP0NaofyO3ZHf9I7hr0105chhGoNRL/+dg0JAH1ZlIqXfGiBSNpe3 BkQ2Y8DM0gY1LQkVZRwRZo8XKLdbAoe+bJpx8rKGRq70+59PUVWXVHeiaiUJ2n/7Fai+ AiAHQYfa47KmM1sd2FPHTMDSAG8ZRMH5KgwfxZyaItUmaIjEjQsELyS8mbzLKODWa9Co WwfHiNxuPphN0Dxb6aulohGqzuk9dFyinng4yTMpH7kP+9KZlkJOF21+qGcrbx3jB77p 1MMavSWYqFmu+mD71F8sAortidkvEx9e76fA3pzgQrmdiT9NQm49J6YphwMPZVIdaExc S8Hw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=organization:in-reply-to:content-disposition:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:references :message-id:subject:cc:to:from:date:dkim-signature; bh=hTxna1iTIvydfaSjv+vSg62DQyOmqexM6W0eK29U0+U=; fh=Qum7TmsMs8yROppWnP5CEi1baWLwZPZLYbm6tZNe7eY=; b=RLIql+yBEqa48QFKzS2kvMg/QGfUZk6ogCxk3f6VIfc9p3650hYeMYE6UJOiyAX2G3 Y1rnnnJaU5vtVg7Ce1Ejs20b1AVmJtxiFIppNiFH5mCfBqDkSntlaSCm1wE8F+vEJ7jE eFD1vnLugu+MEaSYOBe40q3f65I2acnLlJkjERieRrj7bnnnUR9ksLpdKRDvUUgxRSAo kYREmNRDk5Y4BbXaY9ScXDPsoA1U2+9MHVMFw467JQUdmBWiESKU7PYV2hbBlxdr5gGO x2N9DrsQELJQAitiHKlIVbV6cRrYNy0ruAUfC3m9s/y0cpbrrg0cg1sCLYBTmVq1HGrV Fv8A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=QLnA7NIZ; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-183623-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-183623-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id 41be03b00d2f7-669b6cc2465si2451789a12.531.2024.05.20.03.43.56 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 May 2024 03:43:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-183623-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=QLnA7NIZ; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-183623-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-183623-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 00B85281531 for ; Mon, 20 May 2024 10:43:56 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C492851C49; Mon, 20 May 2024 10:43:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="QLnA7NIZ" Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.20]) (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 A26304F5E6; Mon, 20 May 2024 10:43:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.20 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716201829; cv=none; b=hk528zaj7ExfI+0F1TSD3ftxWJR5tVUi8pXrBTv+dnMcx4hDhlccDpaJz6ByXtA3VwhdfZzlJxtHFfytdeE3AFdJCIyEnKgaAWCDQkzhDb2Zim4U/yTo65veKffoP6vOg/JJ17i/LiZsTEXE3UxzF088ZG/aYv/nNeaczapHfiI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716201829; c=relaxed/simple; bh=5+bbb1UczVvw6K+0nS9bOImpVZ8qu3hNkapBpWA73wo=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=dte93O2wKpxdLuY380TmnsNivGvjEPe+7VDu786WdwaNIEktqjBELEIw7MfpgB09rTAwWTx/8bYJHsgv/P3uppUMBTWHCuGMci4GgHucmp41AfAb2c1jxL/ItSQuyTghzhU+a7UJg9txSmL5XWfHBdh67OO3pi8Pq/8923AAN50= 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=QLnA7NIZ; arc=none smtp.client-ip=198.175.65.20 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=1716201828; x=1747737828; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=5+bbb1UczVvw6K+0nS9bOImpVZ8qu3hNkapBpWA73wo=; b=QLnA7NIZVeLc3tsj8RqFsSbFjDiCY+KZP/ZQAlvdI6iHhmKzh7juV/vT 1QOMaudCJ9qUKotHOIfztgNw9VnyjOd1Ged+HoMbWeAMW6hV98D6GHhpR B9yiVsCAHVTZw2wismrmyYN6HjmGFra/OVB6uLRJgJ5lOZtUMTtRcClqK 6dy/6DeMbABAND2Y2xX+IpLRZwn0NFiAEy8NsXhtxEhLMtaVlOgbvW6Gf JEyr3CJxeAviYHINo7YJJwU/fpFeVe77XW1dgKSheTCTc3UW4GgQoi/N/ PkymeghMQs++bl+z5/6IKRAH+fz781JIMhG3crfSyZkAeKh73+KcI/ozX g==; X-CSE-ConnectionGUID: 4S4EUtkSQCymJH0r3Lr3gA== X-CSE-MsgGUID: CYaY8Ha7RyeyJi+jFRNPnA== X-IronPort-AV: E=McAfee;i="6600,9927,11077"; a="12163853" X-IronPort-AV: E=Sophos;i="6.08,174,1712646000"; d="scan'208";a="12163853" Received: from orviesa004.jf.intel.com ([10.64.159.144]) by orvoesa112.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 May 2024 03:43:47 -0700 X-CSE-ConnectionGUID: iZNt5L4bSBCMya55eNWjmQ== X-CSE-MsgGUID: uqFEuioCQ02AyNpzDiKeLA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,174,1712646000"; d="scan'208";a="37435554" Received: from smile.fi.intel.com ([10.237.72.54]) by orviesa004.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 May 2024 03:43:45 -0700 Received: from andy by smile.fi.intel.com with local (Exim 4.97) (envelope-from ) id 1s90UY-00000009Htu-1RTD; Mon, 20 May 2024 13:43:42 +0300 Date: Mon, 20 May 2024 13:43:42 +0300 From: Andy Shevchenko To: Dave Hansen Cc: linux-kernel@vger.kernel.org, tglx@linutronix.de, x86@kernel.org, bp@alien8.de, stable@vger.kernel.org Subject: Re: [PATCH] x86/cpu: Provide default cache line size if not enumerated Message-ID: References: <20240517200534.8EC5F33E@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: <20240517200534.8EC5F33E@davehans-spike.ostc.intel.com> Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo On Fri, May 17, 2024 at 01:05:34PM -0700, Dave Hansen wrote: > > From: Dave Hansen > > tl;dr: CPUs with CPUID.80000008H but without CPUID.01H:EDX[CLFSH] > will end up reporting cache_line_size()==0 and bad things happen. > Fill in a default on those to avoid the problem. > > Long Story: > > The kernel dies a horrible death if c->x86_cache_alignment (aka. > cache_line_size() is 0. Normally, this value is populated from Missing ) ? > c->x86_clflush_size. > > Right now the code is set up to get c->x86_clflush_size from two > places. First, modern CPUs get it from CPUID. Old CPUs that don't > have leaf 0x80000008 (or CPUID at all) just get some sane defaults > from the kernel in get_cpu_address_sizes(). > > The vast majority of CPUs that have leaf 0x80000008 also get > ->x86_clflush_size from CPUID. But there are oddballs. > > Intel Quark CPUs[1] and others[2] have leaf 0x80000008 but don't set > CPUID.01H:EDX[CLFSH], so they skip over filling in ->x86_clflush_size: > > cpuid(0x00000001, &tfms, &misc, &junk, &cap0); > if (cap0 & (1<<19)) > c->x86_clflush_size = ((misc >> 8) & 0xff) * 8; > > So they: land in get_cpu_address_sizes(), set vp_bits_from_cpuid=0 and > never fill in c->x86_clflush_size, assign c->x86_cache_alignment, and > hilarity ensues in code like: > > buffer = kzalloc(ALIGN(sizeof(*buffer), cache_line_size()), > GFP_KERNEL); > > To fix this, always provide a sane value for ->x86_clflush_size. > > Big thanks to Andy Shevchenko for finding and reporting this and also > providing a first pass at a fix. But his fix was only partial and only > worked on the Quark CPUs. It would not, for instance, have worked on > the QEMU config. > > 1. https://raw.githubusercontent.com/InstLatx64/InstLatx64/master/GenuineIntel/GenuineIntel0000590_Clanton_03_CPUID.txt > 2. You can also get this behavior if you use "-cpu 486,+clzero" > in QEMU. Tested-by: Andy Shevchenko (as this obviously fixes the issue as it makes a partial revert of the culprit change). -- With Best Regards, Andy Shevchenko