Received: by 2002:ab2:6816:0:b0:1f9:5764:f03e with SMTP id t22csp1173223lqo; Fri, 17 May 2024 13:05:45 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVXj6UshLh2XT2qyAvoMPjkmFYq/4oPei1x2JljqGDWZ3LqcE7ojyXOx6JniVOoHA20FENzqxu6y0P0U64i4/9zgBiEUxKEYppORdKG/g== X-Google-Smtp-Source: AGHT+IF/P0rZJGbGOcW9iWh+jwhxCYpI+ec1u/oLuP2fRFzpFS/eAv5DibMqKPDPPBYiEFTa0/oN X-Received: by 2002:a17:906:2c51:b0:a59:ca66:c8bf with SMTP id a640c23a62f3a-a5d5b11a8d0mr11146366b.18.1715976345052; Fri, 17 May 2024 13:05:45 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715976345; cv=pass; d=google.com; s=arc-20160816; b=iZQaV/eOv0Pzk6dfKtiwqZSOlXSBvzp5wyY0PUda2x6QqC2xqMghRZLEtW8zdVNi0i mqlr+59Z3568iEYbAMjq+PP69ljUMmcJ052B5JQxJ6stlNP6EbRW+Of6Pyn/Oyv4VgND pm7nXSPa3BeFu/ikgtON+QAxVahDrgty6unp+mUFOD5SSTf4YqCzPlQ1nE9wI1vgnZZQ +LpPQD5MxfmMTJDMdZKoVpsPXxomteSQ8RuxVv6ZvMUsI6T9BDENeY+eREAH3ZOYNquU i8mwaomXuC5VWYGQqPjfFHv+9aeVrVqREL4bkDCkp2Udm4x1ZXnto8eDE/AYFxKOJf97 2MnA== 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:date :from:cc:to:subject:dkim-signature; bh=Uv838Dw8BciPw6KZjPt7KATfghlxt+v0uQwbPXknrJc=; fh=QgIwfpmoOVnZY9VB74UuvbDTZJunMVAOi0y4yTLXkZo=; b=JPfQYKLGPFLZDAJT9c9KvJcXiLfurZZj42zgRGKi/oinQNYBSoazNet/9+YT3mwGx9 pWQdUJV9M2ejP+UqANfp/6vFkfkgsn9mkR3Q7obfz09HzTFmyLkw8yFLVyU7IVHfRbX+ JBxoHInq7kxeXvJr1AxVD09ZyH/RU0drCQUK4qbSXsbC2AF5QebFBUCcWIniuCJKk8zm zq6HSUtxqdbN8DN5FIhdqZ4KxOe4kbUHjmttvXsXE1HeMM3IVLQSJigJ5rk7xDKjwB0j 6LCfXDV5aNU0jk7doV3G7SP9DMUi1v9Zoh1/ggAOyO3WQDLgDm8E7HvHyz7qQnsfVILS XOTQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=fwt9qPb4; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-182604-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-182604-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id a640c23a62f3a-a5a17c04336si979499266b.901.2024.05.17.13.05.44 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 May 2024 13:05:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-182604-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=fwt9qPb4; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-182604-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-182604-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 am.mirrors.kernel.org (Postfix) with ESMTPS id C21131F20D6F for ; Fri, 17 May 2024 20:05:44 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 99292140384; Fri, 17 May 2024 20:05:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="fwt9qPb4" Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.19]) (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 31ACE65F; Fri, 17 May 2024 20:05:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.19 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715976336; cv=none; b=WWgDooKyZ3NYutiAMbrNU9YubbtMGbAyRvMc2XTpPJIIbPlHdbI5GBbRNzmrURjIQ/fFocY9897ZmRGiEoqYkeHWjLVu5NfkKc7/Ndk0UzuH+FEizyOP8AisRMtBNGefpGMDlcbiW5UDeQPGmH4hG937eI3fjgn7P68r5I5k+CQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715976336; c=relaxed/simple; bh=L4UHLoKNdvHEJ52gXHRJqvJH5NbwO+Do+x6c9RoKfa4=; h=Subject:To:Cc:From:Date:Message-Id; b=l1elmyI2P/yhG1omxukHmZDlzV+PP+3ovdSS+L6XNpKSnrRGCpP0QvMO02Aj0A0zONqyv5Ka2BwaCIzEr6e0GYvBDORIXwYtiG2RJrmYjeeFzHKAi6AVWk3PsKHuc0ocSdcE9gvOD/xro5DQJiNTgu+eY1gP8G6ZwuUL1BVaRz8= 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=fwt9qPb4; arc=none smtp.client-ip=198.175.65.19 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=1715976336; x=1747512336; h=subject:to:cc:from:date:message-id; bh=L4UHLoKNdvHEJ52gXHRJqvJH5NbwO+Do+x6c9RoKfa4=; b=fwt9qPb4kVc8gV+0tbb4TnZ/38AJc3tkvcr/M5Woxs9mkfRq/fWf5tcZ 5Zo0LPDA+GibK7cOeoK42qXrSEbXpVZb3lQQS4JhkKjmU+qn8lcUnLsuo TkQUYh/NyIIxVBIwFxtx60LizV++0Aop/82O5+oPRXEYU7gWgIP6SkP5b YdONsSnvBvUt+CYDFnz+shrxp0WfMt66yo1cPsGnIui1F4r8SrbRIebmJ bSM9s3FZ6yWf2Rq3Hx97YNa1DjBCs7Ena6tQfb1Iei8MycF5ohY0CHrYO 7ht2aTFJN/EE6hsLRkI4Hwgx8Q3wI9mN2Vx6qPBUSf9RoMLA1iXf/VLP6 A==; X-CSE-ConnectionGUID: ToER8IJ7TOOURuQsERfF5w== X-CSE-MsgGUID: nkdozRhpRMa7gjeVBs5arA== X-IronPort-AV: E=McAfee;i="6600,9927,11075"; a="12024949" X-IronPort-AV: E=Sophos;i="6.08,168,1712646000"; d="scan'208";a="12024949" Received: from orviesa006.jf.intel.com ([10.64.159.146]) by orvoesa111.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 May 2024 13:05:35 -0700 X-CSE-ConnectionGUID: Cam4j2YbRM+lHBAMBnOLVw== X-CSE-MsgGUID: R4YZAeCsTgWpVghNZicH7w== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,168,1712646000"; d="scan'208";a="32306903" Received: from davehans-spike.ostc.intel.com (HELO localhost.localdomain) ([10.165.164.11]) by orviesa006.jf.intel.com with ESMTP; 17 May 2024 13:05:34 -0700 Subject: [PATCH] x86/cpu: Provide default cache line size if not enumerated To: linux-kernel@vger.kernel.org Cc: tglx@linutronix.de,x86@kernel.org,bp@alien8.de,Dave Hansen ,andriy.shevchenko@linux.intel.com,stable@vger.kernel.org From: Dave Hansen Date: Fri, 17 May 2024 13:05:34 -0700 Message-Id: <20240517200534.8EC5F33E@davehans-spike.ostc.intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: 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 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. Signed-off-by: Dave Hansen Reported-by: Andy Shevchenko Fixes: fbf6449f84bf ("x86/sev-es: Set x86_virt_bits to the correct value straight away, instead of a two-phase approach") Link: https://lore.kernel.org/all/20240516173928.3960193-1-andriy.shevchenko@linux.intel.com/ Cc: stable@vger.kernel.org --- b/arch/x86/kernel/cpu/common.c | 4 ++++ 1 file changed, 4 insertions(+) diff -puN arch/x86/kernel/cpu/common.c~default-x86_clflush_size arch/x86/kernel/cpu/common.c --- a/arch/x86/kernel/cpu/common.c~default-x86_clflush_size 2024-05-17 12:51:25.886169008 -0700 +++ b/arch/x86/kernel/cpu/common.c 2024-05-17 13:03:09.761999885 -0700 @@ -1064,6 +1064,10 @@ void get_cpu_address_sizes(struct cpuinf c->x86_virt_bits = (eax >> 8) & 0xff; c->x86_phys_bits = eax & 0xff; + + /* Provide a sane default if not enumerated: */ + if (!c->x86_clflush_size) + c->x86_clflush_size = 32; } else { if (IS_ENABLED(CONFIG_X86_64)) { c->x86_clflush_size = 64; _