Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id F2C82CA101F for ; Fri, 12 Sep 2025 12:19:56 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.1121902.1465899 (Exim 4.92) (envelope-from ) id 1ux2kT-0007j3-St; Fri, 12 Sep 2025 12:19:29 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 1121902.1465899; Fri, 12 Sep 2025 12:19:29 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ux2kT-0007iw-Ng; Fri, 12 Sep 2025 12:19:29 +0000 Received: by outflank-mailman (input) for mailman id 1121902; Fri, 12 Sep 2025 12:19:27 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ux2kR-0007iq-OT for xen-devel@lists.xenproject.org; Fri, 12 Sep 2025 12:19:27 +0000 Received: from mail-ej1-x635.google.com (mail-ej1-x635.google.com [2a00:1450:4864:20::635]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id b89a7495-8fd2-11f0-9809-7dc792cee155; Fri, 12 Sep 2025 14:19:25 +0200 (CEST) Received: by mail-ej1-x635.google.com with SMTP id a640c23a62f3a-b07c38680b3so123672066b.1 for ; Fri, 12 Sep 2025 05:19:25 -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 4fb4d7f45d1cf-62ee1fd6c0fsm1400841a12.5.2025.09.12.05.19.17 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 12 Sep 2025 05:19:21 -0700 (PDT) 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" X-Inumbo-ID: b89a7495-8fd2-11f0-9809-7dc792cee155 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1757679565; x=1758284365; darn=lists.xenproject.org; h=content-transfer-encoding:in-reply-to:autocrypt:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:from:to:cc:subject:date:message-id:reply-to; bh=Ah9BmBT3PRBdzAisUp3GUqiyxcVdWnMdjbSEzd+vKNI=; b=fTbBrC/2y7kplqO7F4szVFrLVhbC3p9LEn4sVOV/g+T0BQJIrUcR+KyuWVKuNA6hKT eLBKE4SSrIEBJNP274y8M/1FRs3mzwFvJ48EKnmZJA9f47vPlaeOek+0wwcdU6Kq96K3 /uV0mW0MSg38a4IEkOn2bRzmkade4/BAqXaife4q5E0ZT1bS6s0OuwfKvTdCFxp8Q4Nv sG6en8LKc5rSjPBEYbUPfqKS2Xa6iN0Wl3bM3Lk5BECZhyib7P+J3eWcnp1m1c4Mpmvw MqPYZc2bQgo8MFgDIaLsfptc5g/jj1QOwY12TqbdZG2D7cF9yjo7UP/99IYOS/TEDuJl u7Gw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1757679565; x=1758284365; h=content-transfer-encoding:in-reply-to:autocrypt:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=Ah9BmBT3PRBdzAisUp3GUqiyxcVdWnMdjbSEzd+vKNI=; b=acxT7riFlnRsF0pV7OwM52pDq07eXc5Gxj8juDGfT762Bq6R+kH+PzIxX1Wkyo3ebm Xb6tjTkNE1L/cIi4q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YaGiacg+zAw== X-Received: by 2002:a17:907:96a9:b0:afa:1d2c:2dc7 with SMTP id a640c23a62f3a-b07c3a7a7d2mr286829666b.57.1757679564614; Fri, 12 Sep 2025 05:19:24 -0700 (PDT) Message-ID: Date: Fri, 12 Sep 2025 14:19:15 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2 1/2] libacpi: Prevent CPU hotplug AML from corrupting memory To: Alejandro Vallejo Cc: Anthony PERARD , Grygorii Strashko , xen-devel@lists.xenproject.org References: <20250911162336.23887-1-alejandro.garciavallejo@amd.com> <20250911162336.23887-2-alejandro.garciavallejo@amd.com> <4b958afe-dfcd-4ac0-bc09-468e2b9b2710@suse.com> Content-Language: en-US From: Jan Beulich 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: 7bit On 12.09.2025 11:32, Alejandro Vallejo wrote: > On Fri Sep 12, 2025 at 8:40 AM CEST, Jan Beulich wrote: >> On 11.09.2025 18:23, Alejandro Vallejo wrote: >>> CPU hotplug relies on the online CPU bitmap being provided on PIO 0xaf00 >>> by the device model. The GPE handler checks this and compares it against >>> the "online" flag on each MADT LAPIC entry, setting the flag to its >>> related bit in the bitmap and adjusting the table's checksum. >>> >>> The bytecode doesn't, however, stop at NCPUS. It keeps comparing until it >>> reaches 128, even if that overflows the MADT into some other (hopefully >>> mapped) memory. The reading isn't as problematic as the writing though. >>> >>> If an "entry" outside the MADT is deemed to disagree with the CPU bitmap >>> then the bit where the "online" flag would be is flipped, thus >>> corrupting that memory. And the MADT checksum gets adjusted for a flip >>> that happened outside its range. It's all terrible. >>> >>> Note that this corruption happens regardless of the device-model being >>> present or not, because even if the bitmap holds 0s, the overflowed >>> memory might not at the bits corresponding to the "online" flag. >>> >>> This patch adjusts the DSDT so entries >=NCPUS are skipped. >>> >>> Fixes: 087543338924("hvmloader: limit CPUs exposed to guests") >>> Reported-by: Grygorii Strashko >>> Signed-off-by: Alejandro Vallejo >> >> In principle: >> Reviewed-by: Jan Beulich > > Cheers, > >> >> However, ... >> >>> --- a/tools/libacpi/mk_dsdt.c >>> +++ b/tools/libacpi/mk_dsdt.c >>> @@ -231,6 +231,20 @@ int main(int argc, char **argv) >>> stmt("Store", "ToBuffer(PRS), Local0"); >>> for ( cpu = 0; cpu < max_cpus; cpu++ ) >>> { >>> + if ( cpu ) >>> + { >>> + /* >>> + * Check if we're still within the MADT bounds >>> + * >>> + * LLess() takes one byte, but LLessEqual() takes two. Increase >>> + * `cpu` by 1, so we can avoid it. It does add up once you do it >>> + * 127 times! >>> + */ >>> + push_block("If", "LLess(\\_SB.NCPU, %d)", 1 + cpu); >>> + stmt("Return", "One"); >> >> ... if you already care about size bloat in the conditional, why are the two >> bytes per instance that this extra return requires not relevant? They too >> add up, and they can be avoided by wrapping the If around the rest of the >> code. I didn't count it, but I expect the If encoding to grow by at most one >> byte, perhaps none at all. > > I don't mind either way. Removing the "return" statement and the pop_block() > would save 254 bytes in tota at most. I don't think the conditional would grow > because the there wouldn't be that much contained within, but regardless the > early return is in the spirit of not going through 127 conditionals on every > GPE handle when you typically only have a handful of CPUs. The sooner we drop > out of AML, the better. > > In due time I want to shrink this to be an AML loop in dsdt.asl so it can > be taken out of mk_dsdt.c. That will both shrink the DSDT (a ton) and accelerate > GPE handling, but I don't have time to do it at the moment. > > Do you have a preference in table size vs execution-time? Personally I'd favor table size. The AML interpreter is slow anyway. Jan