Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp1342479lqp; Fri, 22 Mar 2024 11:57:26 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUiA1xPGHjIMAMenqWMaxet2gn1ubV0bPzQ/ZqUGoOiZ1zQdypB7tgINi3fyznLSz927c7HwR83QTC4RD/+GGkXXBcNK5eR5vpGuLVfkg== X-Google-Smtp-Source: AGHT+IHHN+DDS9/Q9B6OFWOb5L26/REw+y2aTD8sZ/GVd56h343ZiJkszwWVtV3Ots5JwGmA5sl1 X-Received: by 2002:a05:6a20:3ca7:b0:1a3:6ec2:d23b with SMTP id b39-20020a056a203ca700b001a36ec2d23bmr647939pzj.15.1711133845998; Fri, 22 Mar 2024 11:57:25 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711133845; cv=pass; d=google.com; s=arc-20160816; b=NBUP9v8Vtx8A0g+9+GB+eCVMweT1KqTdfDMecP9GdYCY/7OiPRMDNj+XsHHuDheKF/ Ndu64Xx5odQ1348VB5m8LzlPb5NOWPCvf3f4sXZxJMj8CSbErJiorfwe9rWfdUEhvJX/ Febxki5qGC8/xRqgaA/KiIvr5I02APnVmnz6JayxPGLtX5womAzjFIWpW+dh6M+onw0O O0naqhobNd2YDsTRsI9NYTBAaJF9BAmio1vJRNSPsAhFxS09JcsdQAD+MYusxOFT38bu V2NAmkkZic0YVM6LC3wbLg0bEpcMAaZREBXk/3fLhHr0Q7+wpEGrgsl7sfwtsBEVPJ8p O/Rw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=date:mime-version:list-unsubscribe:list-subscribe:list-id :precedence:references:subject:cc:to:from:dkim-signature :dkim-signature:message-id; bh=F9V0IxYCTPGSFuwQFMSNoPs52bG6JRRxyPm5uFAUn8U=; fh=tUdGdByweHVV+wXw6qzBGm3LKsVsTQuKsQmaC89g1W4=; b=NL4uaMdKlrUIYZ0K7ZbfM+W16fUPFeB962dsFi+NXlD+izFTheQlqp4H3UEZCnGHew A0JFgoWrPc8kIqfIfgkcaWKw8r0Io2M28ijvZ7e96iWseGOLaskkKavH3SrlLiKIzHJU lbPOArmlbYEJoBoMZMo5NkHc56nceeWHaSwviLY5KkbmgKp4yWhL3zT2hegr7f6zQR+G ar3V62D+d5ngUN21+UgW7rJBrQCbQFcMp20BVB+jBTCAxPmM6rsGLwZDVP8QcQcyLSUG rDn38CZQjKZd6nGo1iLcGdHsqGnPUjmcdAdqb/lqEi9CDFa7ATnO72Oy+NnCEJP1PXjG IxAA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=uiIBhr9y; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-111971-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-111971-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id y29-20020a63b51d000000b005dc4fda246esi2403993pge.615.2024.03.22.11.57.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Mar 2024 11:57:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-111971-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=@linutronix.de header.s=2020 header.b=uiIBhr9y; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-111971-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-111971-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de 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 A29A4284CE7 for ; Fri, 22 Mar 2024 18:57:25 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B005F64CC6; Fri, 22 Mar 2024 18:56:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="uiIBhr9y"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="0gKMb9Va" Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (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 7048376415 for ; Fri, 22 Mar 2024 18:56:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711133801; cv=none; b=QSt8925rqsRLEcZoPmulO/4Najp3AyEqQEvxcy5fyPnYyA0vdxnXB4BHAL6ULukiw7ocj2wU/rwGXugEHkZC1EtB1yg2JHDLueeSQM2FdYAhC1lBrVB7SwpJ0oxphf7BC9tenQ1fvgLlVmflhhgGYyrXA/7TfV9W2jTRZ9+4dQA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711133801; c=relaxed/simple; bh=2taPJHOiUv/DAFMUWH9H9i9kQDcuxfAzzvyte2WXhQ8=; h=Message-ID:From:To:Cc:Subject:References:MIME-Version: Content-Type:Date; b=o///lbmdEQOJFHMzZDYbeWj5NOZxptiPqWCdlsfWc9f5gsS9w3MmQAru/CxFZqXHN3FSocrB+HQ3Imi18flhvVXGTi0+vsmsgJ2eaAx2tOmn7Kg7fvgLxGTqd9G1NMG84vGi6gKAJ2v2MHOF7s1rYToKXJkA+bfZTgPDB4IbZBc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=uiIBhr9y; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=0gKMb9Va; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Message-ID: <20240322185305.242709302@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1711133798; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=F9V0IxYCTPGSFuwQFMSNoPs52bG6JRRxyPm5uFAUn8U=; b=uiIBhr9ydVyjgRnnGPTqiRyTZDn8UB7WLShGLsdP9OAqZW2oaTAgzZVnFbMWwB2IEuKJFn N2JKvnjwY/8rR6eIXBGjztKHFUkk1cBSI9Tt26WsN/8kjfGHgqwUDl2MIOJMAsYhCpR8bz Mtq0vAJfqDz4HKM28ZFoMzDT0FnKDjLsOJ0ZRzyDzb94KCUF8b5s6/PjBtB0ie+ajBqdEM iBcBECcAJL1k7ZaWVbZOdVDt5lXgthsTnflj3gZuvPuz1m5rmVz/dl9ggOk+ApXPzCSEz3 xV3bJWchCmkL2oC7UIcy0zKUnq6k0YYynCf3WDYjzjc4sNut5qmswBFHQ1vvgw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1711133798; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=F9V0IxYCTPGSFuwQFMSNoPs52bG6JRRxyPm5uFAUn8U=; b=0gKMb9VaYDmYuY4kuOtoCiP4T+llBQ63vyYcHAi9L8qfzeKaoHcoIr7xU6GayFbfWzLR4Z nGy3m1sk7I/+3lBg== From: Thomas Gleixner To: LKML Cc: x86@kernel.org, Guenter Roeck , Linus Torvalds Subject: [patch 3/4] x86/topology: Handle the !APIC case gracefully References: <20240322184944.141421692@linutronix.de> 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=UTF-8 Date: Fri, 22 Mar 2024 19:56:38 +0100 (CET) If there is no local APIC enumerated and registered then the topology bitmaps are empty. Therefore topology_init_possible_cpus() will die with a division by zero exception. Prevent this by registering a fake APIC id to populate the topology bitmap. This also allows to use all topology query interfaces unconditionally. It does not affect the actual APIC code because either the local APIC address was not registered or no local APIC could be detected. Fixes: f1f758a80516 ("x86/topology: Add a mechanism to track topology via APIC IDs") Reported-by: Guenter Roeck Reported-by: Linus Torvalds Signed-off-by: Thomas Gleixner --- arch/x86/kernel/cpu/topology.c | 11 +++++++++++ 1 file changed, 11 insertions(+) --- a/arch/x86/kernel/cpu/topology.c +++ b/arch/x86/kernel/cpu/topology.c @@ -415,6 +415,17 @@ void __init topology_init_possible_cpus( unsigned int total = assigned + disabled; u32 apicid, firstid; + /* + * If there was no APIC registered, then fake one so that the + * topology bitmap is populated. That ensures that the code below + * is valid and the various query interfaces can be used + * unconditionally. This does not affect the actual APIC code in + * any way because either the local APIC address has not been + * registered or the local APIC was disabled on the command line. + */ + if (topo_info.boot_cpu_apic_id == BAD_APICID) + topology_register_boot_apic(0); + if (!restrict_to_up()) { if (WARN_ON_ONCE(assigned > nr_cpu_ids)) { disabled += assigned - nr_cpu_ids;