Received: by 2002:ab2:3141:0:b0:1ed:23cc:44d1 with SMTP id i1csp1742027lqg; Mon, 4 Mar 2024 02:15:03 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVmLf1j+J/+wsnNMH876x490I9m67ds2tJhUfAJ5XGMb8z0Oa701Rkq8ZpJwPRPXJgqZ7IqqjljheKjbdm/NcToYIHwnihbKdLw58olhQ== X-Google-Smtp-Source: AGHT+IE1pytIY97+xHAOAtRXck0CW2VS6Gavd4hfVL/8n7XeL4TvIO2OWmiAGTWvgQKkWrL5M837 X-Received: by 2002:a17:90a:c402:b0:29b:3cae:c50d with SMTP id i2-20020a17090ac40200b0029b3caec50dmr2570679pjt.0.1709547303252; Mon, 04 Mar 2024 02:15:03 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709547303; cv=pass; d=google.com; s=arc-20160816; b=HTPO55eS1VxFgsj4kyFdNq2KD3jAtOUdYqmyMFB+4cFk5a/9Axy7yxb18PXZ9Vanqt I5qMXeUWTYYLR8BpwKyJo9i0vMe2XsURBycALSgkkYYMikJD4DDYg2VgtNIYUvUsJ4BY unPQfyBwUqkLAW1+GPU/B4OkPD1Vdz9mWN8m0aDQLLLMpYc73zQnsXrSiGy0+nlFBtlY 1wseSQ+DkSCu7pBLCRVTQYaqm6jjBRtlM9WQ88/XjW/S8UYtQdWjRstvff1N5PlT9x3l MmdNKqyPgCRV5Iotm8erpzqhbAIGge4PrQf5Az+pRCfikLgmhzgxS0FYSQT4mcTewUXS ljYg== 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=waWca13nkXlTk1KdzjjO2eUHwkXJkPInhR1X09TJX+0=; fh=XPJs5ZGCvlB7w9yfpC1hED1EJsKLDZjsVhRhMNCPkns=; b=PAjbuZD5ecpX6Pq6j1TJWdpTzb8ZkS1dArOhhl9HOHSW+5MOFNa84NXuI5WfoeK+aY 7UYH+BvaDeH2jAUx08fhmHIJf5NuGIP1qn59byc49Ay0IDn1CIU3ECvuGP4xIGmd5Qtr AWjtn+J35AI7NE6kH64nVDXP5HbboHwnKXSHsxC6x/X7Pe0DBn0bLya+fn02VYm0NOja +OCKqeM9xkRUMNvx0Ytxgc/nNwkFws4OYWKHTNy9KswK1eHibIo0PjzIXB3+q8PL7pgB 8XzqP8V0o6GTVuFXiD8r6mJ1fO5xg2QEj1GWWurwCONhzCuHNOmq5QW1Gu/fX8hWHc3w fl+Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b="IENSuJ/e"; 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-90394-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-90394-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. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id mq7-20020a17090b380700b0029b578e7053si563677pjb.91.2024.03.04.02.15.03 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Mar 2024 02:15:03 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-90394-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b="IENSuJ/e"; 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-90394-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-90394-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 EB9C6281B2B for ; Mon, 4 Mar 2024 10:15:02 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1D6C83B790; Mon, 4 Mar 2024 10:12:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="IENSuJ/e"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="DybwRAza" 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 BA8053A1B5; Mon, 4 Mar 2024 10:12:25 +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=1709547147; cv=none; b=mPnDZOgV5JpEz+4SHTJwuvbXaxBy3e08V50qehPEd5W/hVdr3kFcIU+fvUhE71GG00mVCaI4mSkbAwJg1TsOF0DEi1plhZqcyrQ3OONlQE+QQkAjsnadw4Cx6rAkLsUB4OCl+SMeSjcxIShcnTrCJWMuc0zBJUH4vNvtKgtunBA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709547147; c=relaxed/simple; bh=WnYEq+v+uffBZEOPsnlQcrlcLI+VPrV3Dcry/HVzvlk=; h=Message-ID:From:To:Cc:Subject:References:MIME-Version: Content-Type:Date; b=pufusesBf8RQ1S+O5ERiNyRG1r5IJfypJKuUBWliTHre5XRcfFuoNDWlktqwA09Q3SJ72h5XIfCLbOXIzqHNhOWb2dhnz4+cnL9MZZgg0WqfBPEEnkp39u3T3aLQCwRaDQ5prewRivlyNwhXrN6Dcb0ClYaQVx9z3GP/77dmj4Y= 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=IENSuJ/e; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=DybwRAza; 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: <20240304005104.622511517@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1709547144; 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=waWca13nkXlTk1KdzjjO2eUHwkXJkPInhR1X09TJX+0=; b=IENSuJ/e6a+O59bFfGCzBu967ngLsRmjlrdNl9Yj+0nWcQ2bC0X2PFYcW/Ogp06sGMJLIB ELnjGItFWtLl/DhXffYbhfYuZWdTuAHy8P8NVHuKbhqqPd+K6BZJft2vySb2+rum2C09Aq cWLbAXlF9oprSMGGqHOjLNW9tMb08579es9MRNnrISA4hAX/P0g8vPVJRs53u0MiCEmg6E uPe2Xr/qEg48MKdoe0aRLao5JNxk0MSqCCwClODcnS+OboqfNXt0nkNhir9tdrbcBn9GiL H2I7NG7MHqA3R/H+15AKqhR+hAQvt2gdQuqJz62UKfwqHFHBPFCLeUK+U6W0Iw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1709547144; 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=waWca13nkXlTk1KdzjjO2eUHwkXJkPInhR1X09TJX+0=; b=DybwRAzaUVoj3GiTZNCzx4w9/5h1J6i6awKRx6ALpGlnYu7RBOoHK+EpiWo6GAfyzSUvKj 08Qabz6R7eWQ3kBw== From: Thomas Gleixner To: LKML Cc: x86@kernel.org, Linus Torvalds , Uros Bizjak , linux-sparse@vger.kernel.org, lkp@intel.com, oe-kbuild-all@lists.linux.dev Subject: [patch 5/9] x86: Cure per CPU madness on UP References: <20240303235029.555787150@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: Mon, 4 Mar 2024 11:12:23 +0100 (CET) On UP builds sparse complains rightfully about accesses to cpu_info with per CPU accessors: cacheinfo.c:282:30: sparse: warning: incorrect type in initializer (different address spaces) cacheinfo.c:282:30: sparse: expected void const [noderef] __percpu *__vpp_verify cacheinfo.c:282:30: sparse: got unsigned int * The reason is that on UP builds cpu_info which is a per CPU variable on SMP is mapped to boot_cpu_info which is a regular variable. There is a hideous accessor cpu_data() which tries to hide this, but it's not sufficient as some places require raw accessors and generates worse code than the regular per CPU accessors. Waste sizeof(struct x86_cpuinfo) memory on UP and provide the per CPU cpu_info unconditionally. This requires to update the CPU info on the boot CPU as SMP does. (Ab)use the weakly defined smp_prepare_boot_cpu() function and implement exactly that. This allows to use regular per CPU accessors uncoditionally and paves the way to remove the cpu_data() hackery. Signed-off-by: Thomas Gleixner --- arch/x86/include/asm/processor.h | 5 ----- arch/x86/kernel/cpu/common.c | 3 +++ arch/x86/kernel/setup.c | 10 ++++++++++ arch/x86/kernel/smpboot.c | 4 ---- 4 files changed, 13 insertions(+), 9 deletions(-) --- a/arch/x86/include/asm/processor.h +++ b/arch/x86/include/asm/processor.h @@ -185,13 +185,8 @@ extern struct cpuinfo_x86 new_cpu_data; extern __u32 cpu_caps_cleared[NCAPINTS + NBUGINTS]; extern __u32 cpu_caps_set[NCAPINTS + NBUGINTS]; -#ifdef CONFIG_SMP DECLARE_PER_CPU_READ_MOSTLY(struct cpuinfo_x86, cpu_info); #define cpu_data(cpu) per_cpu(cpu_info, cpu) -#else -#define cpu_info boot_cpu_data -#define cpu_data(cpu) boot_cpu_data -#endif extern const struct seq_operations cpuinfo_op; --- a/arch/x86/kernel/cpu/common.c +++ b/arch/x86/kernel/cpu/common.c @@ -70,6 +70,9 @@ #include "cpu.h" +DEFINE_PER_CPU_READ_MOSTLY(struct cpuinfo_x86, cpu_info); +EXPORT_PER_CPU_SYMBOL(cpu_info); + u32 elf_hwcap2 __read_mostly; /* Number of siblings per CPU package */ --- a/arch/x86/kernel/setup.c +++ b/arch/x86/kernel/setup.c @@ -1211,6 +1211,16 @@ void __init i386_reserve_resources(void) #endif /* CONFIG_X86_32 */ +#ifndef CONFIG_SMP +void __init smp_prepare_boot_cpu(void) +{ + struct cpuinfo_x86 *c = &cpu_data(0); + + *c = boot_cpu_data; + c->initialized = true; +} +#endif + static struct notifier_block kernel_offset_notifier = { .notifier_call = dump_kernel_offset }; --- a/arch/x86/kernel/smpboot.c +++ b/arch/x86/kernel/smpboot.c @@ -101,10 +101,6 @@ EXPORT_PER_CPU_SYMBOL(cpu_core_map); DEFINE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_die_map); EXPORT_PER_CPU_SYMBOL(cpu_die_map); -/* Per CPU bogomips and other parameters */ -DEFINE_PER_CPU_READ_MOSTLY(struct cpuinfo_x86, cpu_info); -EXPORT_PER_CPU_SYMBOL(cpu_info); - /* CPUs which are the primary SMT threads */ struct cpumask __cpu_primary_thread_mask __read_mostly;