Received: by 2002:ab2:6486:0:b0:1ef:eae8:a797 with SMTP id de6csp73672lqb; Fri, 15 Mar 2024 15:55:54 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUyil1cplu/+gra4ylBF4YMkvgzmpqsyokUa9SOfXFDIQCPrbsUjJh7k7fDxI53/XIk1qOVd2L+Ca88n4BKCZPMQv5uge+lcl/MdpqvCA== X-Google-Smtp-Source: AGHT+IEQmBMQzJSPDfpecMdnolpYRtk1vADWoqdhhZ81j/ETczR5TuvkiH3myaj+AMlNza+Fo1Ji X-Received: by 2002:a17:902:ef91:b0:1dd:50f0:3e72 with SMTP id iz17-20020a170902ef9100b001dd50f03e72mr5914470plb.26.1710543354107; Fri, 15 Mar 2024 15:55:54 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710543354; cv=pass; d=google.com; s=arc-20160816; b=coZmyWafl3xlvTgzj/OU9ulqbTjg2YgNzl8olcUrGlu1OLpJvj0GRxQdFUc3WrQ9eH e5ejHcbs90TVn51KD5CREsMG1BhXfrcBjcKWIPu1XxLvME2h421gDq7154csULmLpf0+ MXQAymQQlxmu7d3LaLAFADgP/iRB+zd1eg4lEqs9+4IjUXPTv1czgatYE2bBBY6v9Xu7 d4CAhmcb/wTT2LknFukmdZ21+eyEGwvKUxLuCeRsuXY+zgdcD118FcWArCzzmNH359qC ce67eendAkoGPlW40Mt5JQ+aX1F79p8XlnaP2qcD8sG1EMkfXcdWIHNcJjvCPv5NEoNK liLA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :message-id:date:references:in-reply-to:subject:cc:to:dkim-signature :dkim-signature:from; bh=Tc/I/k/ZfzmyvgN+5eD3gfox+0pZdAK/4qXTdx0YhS4=; fh=u8tKDPTAmozbTgsIBlo5k2Guko7aWab/Dg0Y+4+O2so=; b=g63qUdUYqLqQzIExxQ0IBIOFiKseQISQDHgb2XlWoc47GxKygyRHJDcwaDWFc2i25e c0JL2bS3z7EY6KkNb8/tueU+Rn8qduQcxH2Vx7ygkipqdEQ8FtaWuTl/n6YhX+uHBtNo F3Lx7/5gYdKQ53BbCV8pfqjL6zl4jji7+LBIhogGps0GQj1TBoRQ0/Ur9I4F4IKI006A 0Vu2/oRv97Ea79vF6ElmLnG4U0I6RVksMRfqGtU9mwRAJ563QiOc50aXAUnNFByYKJNg 6mSRGs96oCB7Hf0pZEJW9W4XjmZZEJ94gPLM4TKLY/Il1BFqPbMw1QE6LsgvJ0I7nsxQ lBNw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b="NmQShR6/"; 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-104973-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-104973-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id c12-20020a170903234c00b001dcc17d6eedsi4511943plh.449.2024.03.15.15.55.53 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Mar 2024 15:55:54 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-104973-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b="NmQShR6/"; 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-104973-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-104973-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id E1828B2131C for ; Fri, 15 Mar 2024 22:55:50 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5C6B55A0F0; Fri, 15 Mar 2024 22:55:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="NmQShR6/"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="PcbOpbRi" 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 5D45154BF7; Fri, 15 Mar 2024 22:55: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=1710543344; cv=none; b=MJCNcMuKN4M+vzV4UYPJItQhpeKxoFoer9SERS7IXXCXCQV8KP48KUKTvbpWY+nh5ZNnoeAxvZ1aTjryJNJIuXhL3tuJ1cgKVLoE5GBaVVq8HVUfWLjQP7ZPZt7TW5AVZLwy2T+DIyHBftIG3Bna9huKR6STS2kRRj7ySkTjqRM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710543344; c=relaxed/simple; bh=0/VOjcMaYIEC1VaXonbBm81DGBQ87M/ir9auh4I+oPU=; h=From:To:Cc:Subject:In-Reply-To:References:Date:Message-ID: MIME-Version:Content-Type; b=qru5GJcDLbivemTdNLr8P7/VAsa4OEhxG8TSR/Suc1ebXV3g+6v0C0/peiLgg9o6taAes2NwM2zfYwxaCkFQH9gLSHG8innhQvmRnvfqWDt5wsfUzSCL6koJomBC9Xx8YZ/vBCjteu2Ry0DHuV8UZfnLZ/HzAfjpuJCkYZGWp5U= 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=NmQShR6/; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=PcbOpbRi; 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 From: Thomas Gleixner DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1710543338; 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: in-reply-to:in-reply-to:references:references; bh=Tc/I/k/ZfzmyvgN+5eD3gfox+0pZdAK/4qXTdx0YhS4=; b=NmQShR6/W1Tuq2M0iBem82+tc+bPYx++QmA5N28Ht4EbfMpY19HkTCfwRqHkAH0OQE9W6r BEsRu/dnWEcLEFS93Qv0toFPzYuS2cOdyvYy8Uos139eYv6RDXyUovOuaBBcFHr+RZCU5g sm1IhvOkWF0YETTJ0t9khcvBGhzVdIBF1h8HXot311q6bi5Yb1onKlv3RsEMZuFQN6u6mK 2uYF5Jq1aOwcza+LoOrhWDLon7Z15Dfxi3Frtni62wVJ+pJWv7tQaYtsur02GpvE9HVpkj hSoSq4Q+pY+FJJDb74dhhrJJ8YXIgCLMDFQ+gKqE3hjW3nCCdXGPsycBeVDTvg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1710543338; 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: in-reply-to:in-reply-to:references:references; bh=Tc/I/k/ZfzmyvgN+5eD3gfox+0pZdAK/4qXTdx0YhS4=; b=PcbOpbRiXsbU5KC+U7WjkwiHm9oOKmFNBC5aWpcC934jLu8yLBRIpDgl+j70Z+2EAiJJ7U tOd6HY6UGXkmEtCA== To: Linus Torvalds , Guenter Roeck Cc: LKML , x86@kernel.org, Uros Bizjak , linux-sparse@vger.kernel.org, lkp@intel.com, oe-kbuild-all@lists.linux.dev Subject: Re: [patch 5/9] x86: Cure per CPU madness on UP In-Reply-To: <87y1ajjsv9.ffs@tglx> References: <20240303235029.555787150@linutronix.de> <20240304005104.622511517@linutronix.de> <87y1ajjsv9.ffs@tglx> Date: Fri, 15 Mar 2024 23:55:37 +0100 Message-ID: <87o7bfjeae.ffs@tglx> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain On Fri, Mar 15 2024 at 18:40, Thomas Gleixner wrote: > On Fri, Mar 15 2024 at 09:42, Linus Torvalds wrote: >> On Fri, 15 Mar 2024 at 09:17, Guenter Roeck wrote: >> Thomas, over to you. I wonder if maybe all those topology macros >> should just return 0 on an UP build, but that >> topology_get_logical_id() thing looks a bit wrong regardless. >> >> It really shouldn't depend on local apic data for configs that may not >> *have* a local apic. > > Right. Let me look. Not really. The problem is that a SMP build can run on a UP machine w/o APIC or command line disables the APIC and will run into the exactly same problem. The only case where we know that it is impossible is when APIC support is disabled, which is silly but topic for a different discussion. So the proper thing to do is to check for num_possible_cpus() == 1 in that function. Sure you can argue that we could avoid it for SMP=n builds completely, but I think the right thing to do is to aim for removing CONFIG_SMP and make the UP build a subset of a generic SMP capable build which has CONFIG_NR_CPUS=1, i.e. num_possible_cpus() = 1. Why? Because it consolidates the code and makes UP use exactly the same mechanisms as SMP which pretty much avoids the problem we see today that UP lacks test coverage and becomes more esoteric and untested over time. The downside is a slightly larger kernel image for such a build. Though if we pretend that we seriously care about that 10% larger memory footprint or about the marginal performance benefit of SMP=n on dead hardware, then we are just taking the wrong pills. The point is that this very commit in question was heading deliberately into the direction of removing the by now silly differences of UP/SMP for correctness sake. It just happened to unearth the missing check in topology_get_logical_id(), but that check is required independent of SMP=y/n as I pointed out above. Thanks, tglx --- diff --git a/arch/x86/kernel/cpu/topology.c b/arch/x86/kernel/cpu/topology.c index 3259b1d4fefe..118d9f7792ee 100644 --- a/arch/x86/kernel/cpu/topology.c +++ b/arch/x86/kernel/cpu/topology.c @@ -279,6 +279,15 @@ int topology_get_logical_id(u32 apicid, enum x86_topology_domains at_level) if (lvlid >= MAX_LOCAL_APIC) return -ERANGE; + /* + * Spare the exercise on UP as there is only one instance at any + * level and the map check below might fail because the CPU does + * not have a local APIC or local APIC has been disabled on the + * kernel command line. + */ + if (num_possible_cpus() == 1) + return 0; + if (!test_bit(lvlid, apic_maps[at_level].map)) return -ENODEV; /* Get the number of set bits before @lvlid. */