Received: by 2002:a05:6500:1b8f:b0:1fa:5c73:8e2d with SMTP id df15csp1183075lqb; Thu, 30 May 2024 02:50:20 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUT5nsAtthk2hQjGlrCkC8HV1/fg8/DJtFkjZluN7Q8H05xkOnORoWqyiIfH51+v3zy5su/HRDL/hflgqpbmiZhzXBcZMwleFmLSKW2Dg== X-Google-Smtp-Source: AGHT+IGNC4tcRw59WygFkzUCyazPPGuWjrZCuPlIJsVPOu5qW5UFMzCJHaF3yU6BOSYjhc8ck+yo X-Received: by 2002:a17:90a:cf10:b0:2c1:9469:11bd with SMTP id 98e67ed59e1d1-2c1ab9da277mr1996937a91.3.1717062620557; Thu, 30 May 2024 02:50:20 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717062620; cv=pass; d=google.com; s=arc-20160816; b=QoXEp9BYq8JzVbx+5mz92DZ9z0RegG0MNPE5656FqIGi/we1uD3dzJVdQQ2kxKRuma 7SpuSs/G0q8BtzDVUAdqkkAbtDb6O/rcWTmabb0yNgSmvfPXgTCuXkaDBi0ufHtx+Lc8 Yqv/mJwRbb4bQGkMFcinSGfIOSN74y1eaoVU4hgrKHpcN+ULvOQyBAcCVNxyuirLrCjt 9Aup/da5UoLDwn70RM9d8EzYGP6gseDZ5ezrNDh3N0C/nBaPsGe95IIiOtzSEkfBlWm5 Kt5RAxtSOTF2A94z6FzeQARmLGoCcOfk/xtpaGEF6/DAxT0uDcjNNaeieXMNpRnYf/0h +XIA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=ui-outboundreport:content-transfer-encoding:in-reply-to :content-language:references:cc:to:subject:from:user-agent :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :date:message-id:dkim-signature; bh=dj5x0qPMNpYiNhks6W9RvrhVYROulCGUJxQMpvNOkNs=; fh=PYePk4uc5p8IbRku0XlkDOb+xED1rzjRF419Q0lRmQ0=; b=I3tuO+nOGOMRXnXk+aEqBoIBtUrfsIucosm9k3/eLSKqfI96D5fpfPyfkgLcTN9ZGw 8+C6RAqHrCTUKnIfWtRn20UVnuPtrIEgGrQ0tzXiTdhbekGV0voBm77mkeqai6C10bI9 O8vDQUubj7kou5l0kAnncw7k6G7KIgVCb2eyGOdpYER212B7HxZX7i3FPjKF0MXwGZnN t/Wa70UA00gHVGD38l3mFbGkCPhayCDy9eGI3z+9tfBPDlWgTiSuBJM8rxcWre3RTlC4 EHrflLVvkE100l9zDExCCswF071fvwzXr5iv9AepxbollE7+j/6Xl6dH4rBCbhfmvJ+N EIuA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@heusipp.de header.s=s1-ionos header.b=DsWAWnaw; arc=pass (i=1 spf=pass spfdomain=heusipp.de dkim=pass dkdomain=heusipp.de); spf=pass (google.com: domain of linux-kernel+bounces-195215-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-195215-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id 98e67ed59e1d1-2c1a74ef471si1396576a91.0.2024.05.30.02.50.20 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 May 2024 02:50:20 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-195215-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@heusipp.de header.s=s1-ionos header.b=DsWAWnaw; arc=pass (i=1 spf=pass spfdomain=heusipp.de dkim=pass dkdomain=heusipp.de); spf=pass (google.com: domain of linux-kernel+bounces-195215-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-195215-linux.lists.archive=gmail.com@vger.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 sv.mirrors.kernel.org (Postfix) with ESMTPS id BE0012860E8 for ; Thu, 30 May 2024 09:50:19 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0492F1586C8; Thu, 30 May 2024 09:50:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=heusipp.de header.i=osmanx@heusipp.de header.b="DsWAWnaw" Received: from mout.kundenserver.de (mout.kundenserver.de [212.227.126.135]) (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 8691318396D; Thu, 30 May 2024 09:50:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=212.227.126.135 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717062614; cv=none; b=FXVENgJTu+RCQvxI4qudR4+XqX4QjnZrfUEiE6eJa5Flgy7zABN583oMIWZqXPOFYPqLnvH/qTvaFzjA6suWAAUvujWNM9mJy/eFha1ZYgVbA2aUv9PTENhv1gMSMY4YpUxZc9KM5jK0yeQt+oKx+/5dbzx+ns5KcxUBaXizSVM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717062614; c=relaxed/simple; bh=rJtFgvYvWHNW5N6glbUkLYI5JWdxEzVApMNTJ75qYmA=; h=Message-ID:Date:MIME-Version:From:Subject:To:Cc:References: In-Reply-To:Content-Type; b=gZjbDB0HyMmTIIVqH/ozQO05CzCMIxjIcm7fRX3HfoIdACYWPMsQobFPkpgrJLNxQw/1y/gb0fj414Ue7k2vQH1+gt4VxjVGOXdcSRMRYVih1xpAkVrU6rtX2+004zDT/IYavCgD36BT4mYTiJpVc+FXNSuYvzeCZnj/crztLzk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=heusipp.de; spf=pass smtp.mailfrom=heusipp.de; dkim=pass (2048-bit key) header.d=heusipp.de header.i=osmanx@heusipp.de header.b=DsWAWnaw; arc=none smtp.client-ip=212.227.126.135 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=heusipp.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=heusipp.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=heusipp.de; s=s1-ionos; t=1717062591; x=1717667391; i=osmanx@heusipp.de; bh=dj5x0qPMNpYiNhks6W9RvrhVYROulCGUJxQMpvNOkNs=; h=X-UI-Sender-Class:Message-ID:Date:MIME-Version:From:Subject:To: Cc:References:In-Reply-To:Content-Type:Content-Transfer-Encoding: cc:content-transfer-encoding:content-type:date:from:message-id: mime-version:reply-to:subject:to; b=DsWAWnawpvwiMyCOqTAItI7GtFwqyNDy4GwntZWFxFwXywNlBLEEhWiSVre564e7 7xlqXEp7GJgoe9mHOvz6JkAMNhB+/qJ28vJ+CnWpB2CSOituZySJQckp+IYr6a/3T ez0v+6qQRYCjA8xNNXoL76Gezl+YzLWbLmOgsL5QPw2o0k9eqn+VjP9b46xqxk6+E sTFbPmlroJN56zMWydKlDnbHUR7I4dTPJp3+I3/ScWSV7EeeN6iSUdpfOxz8TUXAq s4ZVoyXnHfvw7Ic1dNecIb/J5+0UeoqRMBdXLzHYpCtxKK36aAg6WGzM+zAb4GLCG lo6VK3pF6lSzI7bO+w== X-UI-Sender-Class: 55c96926-9e95-11ee-ae09-1f7a4046a0f6 Received: from [192.168.178.90] ([91.62.108.110]) by mrelayeu.kundenserver.de (mreue009 [212.227.15.167]) with ESMTPSA (Nemesis) id 1MZCSn-1rzfzS1xhZ-00U3br; Thu, 30 May 2024 11:49:51 +0200 Message-ID: Date: Thu, 30 May 2024 11:47:52 +0200 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird From: =?UTF-8?Q?J=C3=B6rn_Heusipp?= Subject: Re: [PATCH] x86/cpu: Provide default cache line size if not enumerated To: dave.hansen@linux.intel.com Cc: andriy.shevchenko@linux.intel.com, bp@alien8.de, linux-kernel@vger.kernel.org, stable@vger.kernel.org, tglx@linutronix.de, x86@kernel.org References: <20240517200534.8EC5F33E@davehans-spike.ostc.intel.com> Content-Language: en-US In-Reply-To: <20240517200534.8EC5F33E@davehans-spike.ostc.intel.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: quoted-printable X-Provags-ID: V03:K1:I3To5N+GG4wJb7wdsTpIkMtlrr02CcHhd4jpviP6AdZr7mLuhgV 3GPf9v3Jn5LxO8uVsP15HupU39HtBEJ3QdH8edSnkMxreYwjSHnoOyEDC2mk0YC/fJihSRN lX1wRUfOPhl1ZaGm6y9YlBpYL5vSO7gSPwlPUpBg8bjsXeK1ji25YXd82wQCUnB0eUheL6U UgMT2bw0I5CCP0a+XP6wg== X-Spam-Flag: NO UI-OutboundReport: notjunk:1;M01:P0:A21ACE0awT8=;+WxS8Gk3pzlSMgHqO4tQHxZW+Pk irbpDGyh4mYLDGiUedcSzbYQsw8QIZgITR8uJROlefgFowpsZnRH2PsizspdupUk0dvodFceC fcacXVEBM+hm+ewRZbtIvIReL0lvWyF1efaPRLI/bVY1edUhR7WxbzqNZhbN5SbLGOOW7WVgq G/KqOY+UllmBXsCo2yW4MJrZdDm9gB2qSffRLtEL0OpEK81lkb08qlbjfNyefOG4gZRP31LTb sLVn8PnsTeseZBbddDkgW5UH+8VpSv258HLJ4ePsUlJWXT5xyqqjT6lqlNJBTNRbvU91sS8Zi 7oHzgTtvBo8YPt0+aPfQq//wjP+Jt7ZtPNqWjzyw8x6xcioGknw3iTljOZWKzMUHnopYWFX1B Nx+bQDuOTcBgJf8T2ME1B7AZ5qQM0Ykw1Od3vFl9Bn6NeCQJF577JUv/AHKQvskqjlP+krTuq EaRDoDVbCGPoCE+zsXhtVYTfYDJUkOz+LmSJ2lEu06se26LGxgZDSt5Ha7/O06/+gMPQPe57z hcyx3sTNYB+SfRYW6/ah4xgE1b/HE9xJIkCF60w++kt/jLPRBwje+Leykwd205yBzX84CNCu7 v7q5FNauVlWZ4h2/cIa3ANFh5KYtNPxivrdkzTsffdhjm9A6FWbI7UlH6X5g5F+ZQoowHv2gS PbNMTpEm5LAE3LtxioQfKsbeEhco97Uee2OxfsFi3/8UZ32wN1ypuGjjNi4y7g9aKxY1YGXpS vDfQ0NpSJtTJV0/S4vBTTDuNQwbLHbWLgkYMEcwDe6bBIkONrI2uF8= Hello! > From: Dave Hansen > > tl;dr: CPUs with CPUID.80000008H but without CPUID.01H:EDX[CLFSH] > will end up reporting cache_line_size()=3D=3D0 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 > 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 =3D ((misc >> 8) & 0xff) * 8; > > So they: land in get_cpu_address_sizes(), set vp_bits_from_cpuid=3D0 and > never fill in c->x86_clflush_size, assign c->x86_cache_alignment, and > hilarity ensues in code like: > > buffer =3D 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/Genuin= eIntel/GenuineIntel0000590_Clanton_03_CPUID.txt > 2. You can also get this behavior if you use "-cpu 486,+clzero" > in QEMU. Tested-by: J=C3=B6rn Heusipp See https://lore.kernel.org/lkml/5e31cad3-ad4d-493e-ab07-724cfbfaba44@heusipp.= de/ Best regards, J=C3=B6rn