From nobody Thu Sep 24 20:22:22 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1787139960; cv=none; d=zohomail.com; s=zohoarc; b=Zz2JyzZmFm1IgkGrwDYZzmGqK0NntOtI8i99ViN5TbDrT7SfvzjLBeAnUVboJHxD/OHroDeLzXfifz7goR0b8qZEXpCfvkAIQn9OmvAoVHVlFpDtrlrUK6i3a3Fh4VmMJcBZu6Unl5qYykRtfobr6QgLlXuDBlXy6IOAJpjITHc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1787139960; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=JT+63WG7AsG4THCMk4W0hetRuXYQfuHtvo0ezhlRu24=; b=VkvYIr8c3XijWbg/T3LRO10PiwVVmyuugQT8ZtOh9VVVjSuXafSG/KxfuGQIE1GqbZ4JjFnIYAcqOt8njCjQ3Fcf2IcrBpDKPsBGpRZMjZ+Oi5AeLUB8eWfvOr19CFLkakZNqpxcu3EG1cFpNUQX+6mV3Yx64P5yLmKkfxJo+Xo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1787139960108421.4527527928807; Wed, 19 Aug 2026 04:46:00 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1395229.1633712 (Exim 4.92) (envelope-from ) id 1wweje-0006Tf-TB; Wed, 19 Aug 2026 11:45:34 +0000 Received: by outflank-mailman (output) from mailman id 1395229.1633712; Wed, 19 Aug 2026 11:45:34 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1wweje-0006TY-Qc; Wed, 19 Aug 2026 11:45:34 +0000 Received: by outflank-mailman (input) for mailman id 1395229; Wed, 19 Aug 2026 11:45:33 +0000 Received: from mx.expurgate.net ([195.190.135.20]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1wwejd-0006TS-MZ for xen-devel@lists.xenproject.org; Wed, 19 Aug 2026 11:45:33 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1wwejc-00Ec6G-SQ for xen-devel@lists.xenproject.org; Wed, 19 Aug 2026 13:45:32 +0200 Received: from [10.42.69.8] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 6a85974a-bab6-0a2a0a5309dd-0a2a4508d7fc-38 for ; Wed, 19 Aug 2026 13:45:32 +0200 Received: from [209.85.221.45] (helo=mail-wr1-f45.google.com) by tlsNG-c1860d.mxtls.expurgate.net with ESMTPS (eXpurgate 4.57.1) (envelope-from ) id 6a85975c-f659-0a2a45080019-d155dd2dac21-3 for ; Wed, 19 Aug 2026 13:45:32 +0200 Received: by mail-wr1-f45.google.com with SMTP id ffacd0b85a97d-47f703a9e5dso383641f8f.0 for ; Wed, 19 Aug 2026 04:45:32 -0700 (PDT) Received: from [10.156.60.236] (ip-037-024-206-209.um08.pools.vodafone-ip.de. [37.24.206.209]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-482b1441753sm5796968f8f.5.2026.08.19.04.45.31 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 19 Aug 2026 04:45:31 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" Authentication-Results: eu.smtp.expurgate.cloud; dkim=pass header.s=google header.d=suse.com header.i="@suse.com" header.h="Content-Transfer-Encoding:Content-Type:In-Reply-To:Autocrypt:Content-Language:References:Cc:To:From:Subject:User-Agent:MIME-Version:Date:Message-ID" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1787139932; x=1787744732; darn=lists.xenproject.org; h=content-transfer-encoding:content-type:in-reply-to:autocrypt :content-language:references:cc:to:from:subject:user-agent :mime-version:date:message-id:from:to:cc:subject:date:message-id :reply-to:content-type; bh=JT+63WG7AsG4THCMk4W0hetRuXYQfuHtvo0ezhlRu24=; b=OMIdv778QTHooAUND2yaz7kc6GaWhgswLfE0VxjyGzDzI7kjRTZF4mD6VSudZap6UO CaG54t5Bj50QpnuI6HVOgERBShHIByGKHDvG1lEcru2sh7R+Nodblj697n7WtkaEimUw etvZlcttZ55bNfn3fNjHmBMFEsdxZXkzQPH/sXs0h3wm2KvqOHBPc+wqJQMP1gim90CT 8TTKfAwGkzs3tzpspKKGerytDgkvNbJ4QuyGB+ajKbpoKxbUjO4kDcxqHDieA+Nd3zXU PrBQ1g9JJcO8XG812zc2UtB2o9ptACrz1VWDOUJF5oveTbqd0ZfG1GglYC41D8AIyyQe ezsw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1787139932; x=1787744732; h=content-transfer-encoding:content-type:in-reply-to:autocrypt :content-language:references:cc:to:from:subject:user-agent :mime-version:date:message-id:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to:content-type; bh=JT+63WG7AsG4THCMk4W0hetRuXYQfuHtvo0ezhlRu24=; b=JPb/W3+jWlRiXEpGoU5WZ6G0n2P0fJsE6DlPJZtu9oZM4UQl2rdThPrz8Y2CVH4iws Tq1QAql4TuTyazW5ApcYNwjp8CkBvI34Y4hIHrErigxDezGp4sVQVIdl8ndiKeNWUbpC WHl1owciPD70cDCd7I2diuF65q1Ch/UlotGaq3Kwo1AiytUYVuM43HKHXMAN89viyIrI rGxV4xWDVsC1X+OeOnJTFfyUKzkGgaaTm9qCuBuxuou1wJ0MkrHHAgop0Jug6swoOKes 4pShwat1InR35TctJFde7ENByw6IJs0hAl/uBxDnsTpbb4ZRhHJ28dNVTq8mGrau7kW1 gdww== X-Gm-Message-State: AFuF++mdTAC07om5/H8iyf4Y+3UoZhNQWjRR1qsBsrT2JplfcQMbM1ZR bQBmMq2yFa72Ujee2TZWZdAmvCzz4yDuuz8kMfVO+OKHciNO//HEjVlYrla69tFvloiUP0osyZL 2Obbk8Q== X-Gm-Gg: AR+sD111XPJKMWdKyuaOIph+FK6XdQmHYu5KcUnijZm08AM/YnoZzQM91fFPhK/e1IB WMay/E8ytvBBZbhGppVwfYpLZ23MOgalSPjb9SbcCQN20rErpDUw5DYWNXQ06M7wLb3J4esSula PcDbb2G0sygvR2ynUtiSv25xhSh093nyMBkamzxnvy3+fJzrTPkzTjAz6jmTeoC8uC075POqOvF xHUqv4SBzV9hg69dyZ+ZO7mMFTp/Wy3EkcHmKQefaj3wpxQMdj2s+mOPzdZhuy6qFHZQ4LSs7WL 4Eu2U6QtF/dcddlA1DgUNxlG9iB56d2HjwXTbxTfsPeGtzllOaqgyuQnJ7Y2zk1sfY4VxB86lPq MUhBawRnh8A03lstUHfoKE6Ba26TIhKIRgzlviW4tN+/jIFjfAj3F3iIA+3Gu5jvQCDpMxoLjIK F/xhHFa9+Z1z17vvore7wmjpsXGqH0ZFnROvEKcF5i55NNpLk9UzaiO+wAQX2mr0pQm8g86LsJf 5WiwR/OD1NhfxCgOSKXaCQjQ41iPbFJWK1OKTUYQgbQfnt27OJD X-Received: by 2002:a05:6000:2582:b0:47f:9022:8531 with SMTP id ffacd0b85a97d-482b1ffd7ebmr2141182f8f.22.1787139932128; Wed, 19 Aug 2026 04:45:32 -0700 (PDT) Message-ID: <347cd6bc-e10e-4696-a1d2-1aaa84811370@suse.com> Date: Wed, 19 Aug 2026 13:45:31 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: [PATCH v5 1/2] x86/CPU: re-arrange tail of early_cpu_init() From: Jan Beulich To: "xen-devel@lists.xenproject.org" Cc: Andrew Cooper , =?UTF-8?Q?Roger_Pau_Monn=C3=A9?= , Teddy Astie References: Content-Language: en-US Autocrypt: addr=jbeulich@suse.com; keydata= xsDiBFk3nEQRBADAEaSw6zC/EJkiwGPXbWtPxl2xCdSoeepS07jW8UgcHNurfHvUzogEq5xk hu507c3BarVjyWCJOylMNR98Yd8VqD9UfmX0Hb8/BrA+Hl6/DB/eqGptrf4BSRwcZQM32aZK 7Pj2XbGWIUrZrd70x1eAP9QE3P79Y2oLrsCgbZJfEwCgvz9JjGmQqQkRiTVzlZVCJYcyGGsD /0tbFCzD2h20ahe8rC1gbb3K3qk+LpBtvjBu1RY9drYk0NymiGbJWZgab6t1jM7sk2vuf0Py O9Hf9XBmK0uE9IgMaiCpc32XV9oASz6UJebwkX+zF2jG5I1BfnO9g7KlotcA/v5ClMjgo6Gl MDY4HxoSRu3i1cqqSDtVlt+AOVBJBACrZcnHAUSuCXBPy0jOlBhxPqRWv6ND4c9PH1xjQ3NP nxJuMBS8rnNg22uyfAgmBKNLpLgAGVRMZGaGoJObGf72s6TeIqKJo/LtggAS9qAUiuKVnygo 3wjfkS9A3DRO+SpU7JqWdsveeIQyeyEJ/8PTowmSQLakF+3fote9ybzd880fSmFuIEJldWxp Y2ggPGpiZXVsaWNoQHN1c2UuY29tPsJgBBMRAgAgBQJZN5xEAhsDBgsJCAcDAgQVAggDBBYC AwECHgECF4AACgkQoDSui/t3IH4J+wCfQ5jHdEjCRHj23O/5ttg9r9OIruwAn3103WUITZee e7Sbg12UgcQ5lv7SzsFNBFk3nEQQCACCuTjCjFOUdi5Nm244F+78kLghRcin/awv+IrTcIWF hUpSs1Y91iQQ7KItirz5uwCPlwejSJDQJLIS+QtJHaXDXeV6NI0Uef1hP20+y8qydDiVkv6l IreXjTb7DvksRgJNvCkWtYnlS3mYvQ9NzS9PhyALWbXnH6sIJd2O9lKS1Mrfq+y0IXCP10eS FFGg+Av3IQeFatkJAyju0PPthyTqxSI4lZYuJVPknzgaeuJv/2NccrPvmeDg6Coe7ZIeQ8Yj t0ARxu2xytAkkLCel1Lz1WLmwLstV30g80nkgZf/wr+/BXJW/oIvRlonUkxv+IbBM3dX2OV8 AmRv1ySWPTP7AAMFB/9PQK/VtlNUJvg8GXj9ootzrteGfVZVVT4XBJkfwBcpC/XcPzldjv+3 HYudvpdNK3lLujXeA5fLOH+Z/G9WBc5pFVSMocI71I8bT8lIAzreg0WvkWg5V2WZsUMlnDL9 mpwIGFhlbM3gfDMs7MPMu8YQRFVdUvtSpaAs8OFfGQ0ia3LGZcjA6Ik2+xcqscEJzNH+qh8V m5jjp28yZgaqTaRbg3M/+MTbMpicpZuqF4rnB0AQD12/3BNWDR6bmh+EkYSMcEIpQmBM51qM EKYTQGybRCjpnKHGOxG0rfFY1085mBDZCH5Kx0cl0HVJuQKC+dV2ZY5AqjcKwAxpE75MLFkr wkkEGBECAAkFAlk3nEQCGwwACgkQoDSui/t3IH7nnwCfcJWUDUFKdCsBH/E5d+0ZnMQi+G0A nAuWpQkjM1ASeQwSHEeAWPgskBQL In-Reply-To: Content-Transfer-Encoding: quoted-printable X-purgate-ID: tlsNG-c1860d/1787139932-D554C87B-7C7C47AA/0/0 X-purgate-type: clean X-purgate-size: 1141 X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1787139962259158500 Content-Type: text/plain; charset="utf-8" Some early setup doesn't need re-doing after ucode load. Move the call to initialize_cpu_data() slightly up and add a conditional return point. Signed-off-by: Jan Beulich Acked-by: Roger Pau Monn=C3=A9 --- The parameter being named "verbose" may be a little irritating for this use, yet renaming would incur extra churn. Clearly an alternative would be to split the function. I can't, however, seem to be able to think of a good name for the part that would be invoked post-ucode-loading. Maybe early_cpu_reinit(), except that calling that from early_cpu_init() then still feel somewhat odd. --- v5: New. --- a/xen/arch/x86/cpu/common.c +++ b/xen/arch/x86/cpu/common.c @@ -432,10 +432,18 @@ void __init early_cpu_init(bool verbose) paddr_bits -=3D (ebx >> 6) & 0x3f; } =20 + initialize_cpu_data(0); + + if (!verbose) + return; + + /* + * Work which doesn't need repeating after microcode load goes below + * here. + */ + if (!(c->vendor & (X86_VENDOR_AMD | X86_VENDOR_HYGON))) park_offline_cpus =3D opt_mce; - - initialize_cpu_data(0); } =20 void reset_cpuinfo(struct cpuinfo_x86 *c, bool keep_basic) From nobody Thu Sep 24 20:22:22 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1787139975; cv=none; d=zohomail.com; s=zohoarc; b=OjuDrZZgVK1V+E9LIzAb96RTpt3JA+/K+xmdTZzoH+SZ3S8Us6piEjN++UTpb9mkNPB8P0PF7lrt1xqRm1VasQ7icas4XjxTRRiVpyrwmfqRlCwjsCLPHkYFPfuuKIPy8KO4o1AF4T5x7ygak3i2Y1IqB0wexA5KEFvLlOFYkTA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1787139975; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=D6LUuo5zHGa6LkJrIlKdcQpNkQpydOsK91r6s2OSYDA=; b=Rsy0iaXbLw/bXNcHxn2Q9D/apdI9a1ix5kl2FfOLgOKcpWWSjMpLQVjaKJdhn1ZB9TJ92emIasaVIqrgHTt1L2+IwfRz6Sa376e7swy7ZQaPuP6FrzyamPeqHhB/yfZrm6LUejbxS6rzn79NeNXvZx1cymqNwKsr1bXXP9Ud6p4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 178713997580374.87225434307197; Wed, 19 Aug 2026 04:46:15 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1395235.1633722 (Exim 4.92) (envelope-from ) id 1wwek4-0006sq-40; Wed, 19 Aug 2026 11:46:00 +0000 Received: by outflank-mailman (output) from mailman id 1395235.1633722; Wed, 19 Aug 2026 11:46:00 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1wwek4-0006sj-1F; Wed, 19 Aug 2026 11:46:00 +0000 Received: by outflank-mailman (input) for mailman id 1395235; Wed, 19 Aug 2026 11:45:58 +0000 Received: from mx.expurgate.net ([195.190.135.10]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1wwek2-0006oh-J7 for xen-devel@lists.xenproject.org; Wed, 19 Aug 2026 11:45:58 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1wwek1-009yRN-Vq for xen-devel@lists.xenproject.org; Wed, 19 Aug 2026 13:45:57 +0200 Received: from [10.42.69.8] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 6a859767-8faa-0a2a0a5109dd-0a2a45089208-24 for ; Wed, 19 Aug 2026 13:45:57 +0200 Received: from [209.85.128.48] (helo=mail-wm1-f48.google.com) by tlsNG-c1860d.mxtls.expurgate.net with ESMTPS (eXpurgate 4.57.1) (envelope-from ) id 6a859775-f659-0a2a45080019-d1558030b414-3 for ; Wed, 19 Aug 2026 13:45:57 +0200 Received: by mail-wm1-f48.google.com with SMTP id 5b1f17b1804b1-4998590d392so8628595e9.0 for ; Wed, 19 Aug 2026 04:45:57 -0700 (PDT) Received: from [10.156.60.236] (ip-037-024-206-209.um08.pools.vodafone-ip.de. [37.24.206.209]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-482b14c33b3sm4839260f8f.27.2026.08.19.04.45.56 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 19 Aug 2026 04:45:57 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" Authentication-Results: eu.smtp.expurgate.cloud; dkim=pass header.s=google header.d=suse.com header.i="@suse.com" header.h="Content-Transfer-Encoding:Content-Type:In-Reply-To:Autocrypt:Content-Language:References:Cc:To:From:Subject:User-Agent:MIME-Version:Date:Message-ID" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1787139957; x=1787744757; darn=lists.xenproject.org; h=content-transfer-encoding:content-type:in-reply-to:autocrypt :content-language:references:cc:to:from:subject:user-agent :mime-version:date:message-id:from:to:cc:subject:date:message-id :reply-to:content-type; bh=D6LUuo5zHGa6LkJrIlKdcQpNkQpydOsK91r6s2OSYDA=; b=XImVF8rAkJMrXqQFY6SS011LItDlYlps2+B5ZOb7ru0eHaoyNdDf9/JZTsTzxnpVME OqH8pCOA6L/W+Nri4NlwukLDhnb9+DVI7oAH9o/yWdaga3dYTofDSK+2K9BGPbJ6MFWB hQQIMRO1lk0Ja246BY4gIBtIkDtsaVCnbZrZlXOZDQuBM7LWMtd8Hlqje83mvXg1Io26 esXKhHUaLdGtJ+USrsp+632Aj1kLPrfYxV+WOqX8s1bZmGJ46lkQDHhH3PYDOVDbe2bx XCeEcpeiP2o2M8T0DWRhbvlDrKszbhXxXh9Il8HaEB/CzKp2qrsCQem5DeOP6qf5aFr1 FR2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1787139957; x=1787744757; h=content-transfer-encoding:content-type:in-reply-to:autocrypt :content-language:references:cc:to:from:subject:user-agent :mime-version:date:message-id:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to:content-type; bh=D6LUuo5zHGa6LkJrIlKdcQpNkQpydOsK91r6s2OSYDA=; b=iXNH3cw0cIU9qBVk6wLcjyZTywrGbFhVi5G3FjN305MCktTTl0sHTXmusml2bt58Wc 5OhYJND7BBGvoQWKUhQulnJ2lS3FJZBrmY7F911IGn86CI30/D7ZU7qWfuhkZS4ANTEx mA3AneoP2tJkBzssXd3oDCvVZh8zg4ysxkVRXyRK1XGGIuj+b5lKp6ue0UJbU+pbgBl/ wdZPVcF1VfVq68wvipHvnNXaja+E/aCU4goNx5YLli9a632KrZ8aj4TfQKMjqsb+y5tJ Hit6QxqQON8QnX7/tx8RcEyyC6X0lBwulwMz7MlqoZAFqv92VgSGVJHCDSjBsKn+iTyN kOeQ== X-Gm-Message-State: AOJu0YzUasfXbJKZU8490FLIQc1fIHI0fi3K3czWFJ9EJkRxT7msxytl Cz++9DEAYVD+jbmr0uCQpFjCgiNTkbB1vJ2FOf+7sBDuJYyaYDi/3CGCBIO7K+n0smOGtAgK9Ol Hprk5oA== X-Gm-Gg: AR+sD10+R7TMcVznXu1Wfoozb7gpIdFHUbjoaUrAmCN836IbvBN8upErn8NqgAn3vbv +HXdV9jAW0w4zd1vlqQT6wRre199YiQF6osfyi1xJCNoGHbDiOb10m9q6kv8hvJmAGHwLMjJ3aO VljsAGSEJnfVmdLqk2Cb3rel/8m4hB3uxGkhIUJI3lX/LndHfomJkxm2ywcxXCyAcD21T4P8IlD xR/uTS+M2xl69JZ5TeLnZW2sWxpgy+NyUt/7GZkUNTOEYBUd6kzIWVGNkjMcC9HRsL+VzJAOYSK IQfFJeM/hT86G9bObTrDDU9m+nnOQPgP0u4X+JPUceeAbIeQDw4DaenByeL6b8ejjziUDfYrb9D qJBe+3jzHpvQip+BZDIO1ymlM1a73CGm1VCLMb98+oUvUrlN78s2ViMJtxT5FTnWox2C+aoo/Xl uARrfQdYjvaGuxzXRcfldzdw2SA1e9ClJchwbDfNsAmhrpx+S+9Xei3rH9vO11QX8wXJJuDYkmA +iDNmHMTBDE7jrygnuvvMG1OliVFHSNCKLmMN+Z2qHc2e/Xb+cE X-Received: by 2002:a05:600c:37c6:b0:499:9eb7:4558 with SMTP id 5b1f17b1804b1-499aa1e43b7mr77400005e9.10.1787139957333; Wed, 19 Aug 2026 04:45:57 -0700 (PDT) Message-ID: Date: Wed, 19 Aug 2026 13:45:56 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: [PATCH v5 2/2] x86/time: avoid early uses of NOW() to return zero From: Jan Beulich To: "xen-devel@lists.xenproject.org" Cc: Andrew Cooper , =?UTF-8?Q?Roger_Pau_Monn=C3=A9?= , Teddy Astie References: Content-Language: en-US Autocrypt: addr=jbeulich@suse.com; keydata= xsDiBFk3nEQRBADAEaSw6zC/EJkiwGPXbWtPxl2xCdSoeepS07jW8UgcHNurfHvUzogEq5xk hu507c3BarVjyWCJOylMNR98Yd8VqD9UfmX0Hb8/BrA+Hl6/DB/eqGptrf4BSRwcZQM32aZK 7Pj2XbGWIUrZrd70x1eAP9QE3P79Y2oLrsCgbZJfEwCgvz9JjGmQqQkRiTVzlZVCJYcyGGsD /0tbFCzD2h20ahe8rC1gbb3K3qk+LpBtvjBu1RY9drYk0NymiGbJWZgab6t1jM7sk2vuf0Py O9Hf9XBmK0uE9IgMaiCpc32XV9oASz6UJebwkX+zF2jG5I1BfnO9g7KlotcA/v5ClMjgo6Gl MDY4HxoSRu3i1cqqSDtVlt+AOVBJBACrZcnHAUSuCXBPy0jOlBhxPqRWv6ND4c9PH1xjQ3NP nxJuMBS8rnNg22uyfAgmBKNLpLgAGVRMZGaGoJObGf72s6TeIqKJo/LtggAS9qAUiuKVnygo 3wjfkS9A3DRO+SpU7JqWdsveeIQyeyEJ/8PTowmSQLakF+3fote9ybzd880fSmFuIEJldWxp Y2ggPGpiZXVsaWNoQHN1c2UuY29tPsJgBBMRAgAgBQJZN5xEAhsDBgsJCAcDAgQVAggDBBYC AwECHgECF4AACgkQoDSui/t3IH4J+wCfQ5jHdEjCRHj23O/5ttg9r9OIruwAn3103WUITZee e7Sbg12UgcQ5lv7SzsFNBFk3nEQQCACCuTjCjFOUdi5Nm244F+78kLghRcin/awv+IrTcIWF hUpSs1Y91iQQ7KItirz5uwCPlwejSJDQJLIS+QtJHaXDXeV6NI0Uef1hP20+y8qydDiVkv6l IreXjTb7DvksRgJNvCkWtYnlS3mYvQ9NzS9PhyALWbXnH6sIJd2O9lKS1Mrfq+y0IXCP10eS FFGg+Av3IQeFatkJAyju0PPthyTqxSI4lZYuJVPknzgaeuJv/2NccrPvmeDg6Coe7ZIeQ8Yj t0ARxu2xytAkkLCel1Lz1WLmwLstV30g80nkgZf/wr+/BXJW/oIvRlonUkxv+IbBM3dX2OV8 AmRv1ySWPTP7AAMFB/9PQK/VtlNUJvg8GXj9ootzrteGfVZVVT4XBJkfwBcpC/XcPzldjv+3 HYudvpdNK3lLujXeA5fLOH+Z/G9WBc5pFVSMocI71I8bT8lIAzreg0WvkWg5V2WZsUMlnDL9 mpwIGFhlbM3gfDMs7MPMu8YQRFVdUvtSpaAs8OFfGQ0ia3LGZcjA6Ik2+xcqscEJzNH+qh8V m5jjp28yZgaqTaRbg3M/+MTbMpicpZuqF4rnB0AQD12/3BNWDR6bmh+EkYSMcEIpQmBM51qM EKYTQGybRCjpnKHGOxG0rfFY1085mBDZCH5Kx0cl0HVJuQKC+dV2ZY5AqjcKwAxpE75MLFkr wkkEGBECAAkFAlk3nEQCGwwACgkQoDSui/t3IH7nnwCfcJWUDUFKdCsBH/E5d+0ZnMQi+G0A nAuWpQkjM1ASeQwSHEeAWPgskBQL In-Reply-To: Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-purgate-ID: tlsNG-c1860d/1787139957-D614687B-ED93BEB1/0/0 X-purgate-type: clean X-purgate-size: 6163 X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1787139976515158500 Waiting loops like the one in flush_command_buffer() will degenerate to infinite ones when used early enough for NOW() to still return constant zero. Make sure the returned value at least monotonically increases. When available, use nominal frequency values as initial approximation. Do this only in get_s_time(), as producing a sane value in get_s_time_fixed() for non-zero inputs won't be reasonably possible. Put an assertion there. Reported-by: Roger Pau Monn=C3=A9 Signed-off-by: Jan Beulich Acked-by: Roger Pau Monn=C3=A9 --- RFC: While generally the mentioned waiting loops will take longer to time out, on a very fast CPU tight loops may time out too early. With "x86/time: set AP's TSC scale estimate earlier" the counter update may not need to be atomic anymore, as then only the BSP can reasonably hit that path. I don't think Fixes: tags should be put here. If we did, we'd have to enumerate all introductions of early uses of NOW() (or get_s_time()), with the exception of those dealing with getting back 0 (which I expect is only printk_start_of_line()). Will want backporting nevertheless (unless deemed too risky). --- v5: Move addition to early_cpu_init() down. Adjust commentary there. v3: Use "high" / "max" freq if "nominal" isn't available. Set NOW_good. v2: Add assertion to get_s_time_fixed(). Use nominal frequencies for very early setting, if available. --- a/xen/arch/x86/cpu/common.c +++ b/xen/arch/x86/cpu/common.c @@ -19,6 +19,7 @@ #include #include #include +#include #include =20 #include @@ -444,6 +445,39 @@ void __init early_cpu_init(bool verbose) =20 if (!(c->vendor & (X86_VENDOR_AMD | X86_VENDOR_HYGON))) park_offline_cpus =3D opt_mce; + + /* + * If nominal freq isn't available, use highest, thus causing NOW() + * output to move more slowly. See preset_tsc_scale(). + */ + if (c->cpuid_level >=3D 0x15) { + cpuid(0x15, &eax, &ebx, &ecx, &edx); + + if (ecx && ebx && eax) + preset_tsc_scale(DIV_ROUND_UP(ecx * 1UL * ebx, eax)); + else if (c->cpuid_level >=3D 0x16) { + /* Assume CPU base freq =E2=89=88 TSC freq. */ + cpuid(0x16, &eax, &ebx, &ecx, &edx); + if (eax) + preset_tsc_scale(eax * 1000000UL); + else if (ebx) + preset_tsc_scale(ebx * 1000000UL); + } + } else if (c->vendor & (X86_VENDOR_AMD | X86_VENDOR_HYGON)) { + unsigned int nom_mhz =3D 0, hi_mhz =3D 0; + + amd_process_freq(c, NULL, &nom_mhz, &hi_mhz); + if (nom_mhz) + preset_tsc_scale(nom_mhz * 1000000UL); + else if (hi_mhz) + preset_tsc_scale(hi_mhz * 1000000UL); + } else if (c->vendor & X86_VENDOR_INTEL) { + unsigned int hi_mhz =3D 0; + + intel_process_freq(c, NULL, &hi_mhz); + if (hi_mhz) + preset_tsc_scale(hi_mhz * 1000000UL); + } } =20 void reset_cpuinfo(struct cpuinfo_x86 *c, bool keep_basic) --- a/xen/arch/x86/include/asm/time.h +++ b/xen/arch/x86/include/asm/time.h @@ -23,6 +23,7 @@ mktime (unsigned int year, unsigned int int time_suspend(void); int time_resume(void); =20 +void preset_tsc_scale(unsigned long freq); void init_percpu_time(void); void time_latch_stamps(void); =20 --- a/xen/arch/x86/cpu/intel.c +++ b/xen/arch/x86/cpu/intel.c @@ -476,8 +476,8 @@ static int num_cpu_cores(struct cpuinfo_ return 1; } =20 -static void intel_process_freq(const struct cpuinfo_x86 *c, - unsigned int *min_mhz, unsigned int *max_mh= z) +void intel_process_freq(const struct cpuinfo_x86 *c, + unsigned int *min_mhz, unsigned int *max_mhz) { uint64_t msrval; uint8_t max_ratio, min_ratio; --- a/xen/arch/x86/include/asm/processor.h +++ b/xen/arch/x86/include/asm/processor.h @@ -417,6 +417,9 @@ static inline uint8_t get_cpu_family(uin return fam; } =20 +void intel_process_freq(const struct cpuinfo_x86 *c, + unsigned int *min_mhz, unsigned int *max_mhz); + #ifdef CONFIG_INTEL extern int8_t opt_tsx; extern bool rtm_disabled; --- a/xen/arch/x86/time.c +++ b/xen/arch/x86/time.c @@ -1664,6 +1664,9 @@ s_time_t get_s_time_fixed(uint64_t at_ts const struct cpu_time *t =3D &this_cpu(cpu_time); uint64_t tsc, delta; =20 + /* scale_delta() degenerates when the scale wasn't set yet. */ + ASSERT(t->tsc_scale.mul_frac); + if ( at_tsc ) tsc =3D at_tsc; else @@ -1679,6 +1682,20 @@ s_time_t get_s_time_fixed(uint64_t at_ts =20 s_time_t get_s_time(void) { + /* + * Before the TSC scale is set, avoid returning constant 0 (or whatever + * this_cpu(cpu_time).stamp.local_stime is set to). While the returned + * value is in no way representing time, it at least increases + * monotonically, thus avoiding e.g. waiting loops to degenerate to + * entirely infinite ones. + */ + if ( unlikely(!this_cpu(cpu_time).tsc_scale.mul_frac) ) + { + static s_time_t counter; + + return arch_fetch_and_add(&counter, 1); + } + return get_s_time_fixed(0); } =20 @@ -2632,6 +2649,22 @@ int __init init_xen_time(void) return 0; } =20 +/* BSP-only function to pre-set an approximate TSC scale. */ +void __init preset_tsc_scale(unsigned long freq) +{ + struct cpu_time *t =3D &this_cpu(cpu_time); + + /* + * The incoming frequency is only approximate (nominal). Increase it = by + * 1% to make NOW() output rather a little too slow than too fast, thus + * avoiding a possible backwards jump once the final scale is set. + */ + freq +=3D DIV_ROUND_UP(freq, 100); + + set_time_scale(&t->tsc_scale, freq); + t->stamp.local_tsc =3D boot_tsc_stamp; + NOW_good =3D true; +} =20 /* Early init function. */ void __init early_time_init(void) @@ -2649,6 +2682,9 @@ void __init early_time_init(void) "TSC ADJUST set to %lx on boot CPU - clearing\n", tmp); wrmsrl(MSR_IA32_TSC_ADJUST, 0); boot_tsc_stamp -=3D tmp; + + if ( t->stamp.local_tsc ) + t->stamp.local_tsc -=3D tmp; } } =20