Received: by 2002:a05:6358:5282:b0:b5:90e7:25cb with SMTP id g2csp191681rwa; Sat, 20 Aug 2022 01:44:02 -0700 (PDT) X-Google-Smtp-Source: AA6agR7gvmYw6dLKorjT7TzYsxjMnVFRjd3kYHebC6N85jELrowGjBEBU/uY0HO9yyehizQ2k/tu X-Received: by 2002:a05:6402:100c:b0:43d:9009:c705 with SMTP id c12-20020a056402100c00b0043d9009c705mr8686274edu.49.1660985041800; Sat, 20 Aug 2022 01:44:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660985041; cv=none; d=google.com; s=arc-20160816; b=unodvQmmKCxf1gJMS5KrdnIN9JV/lpD+DJ5jHE8EaSN+c9RZJfaGndAbIAexJRTs4v PQ2s1Q0TzGzh3/8Kn9TsLg2+V6W1bV9iGxHHb6yS2xGicnc8bOyXLM/t8bvV+GtpZO/J 2aqxq3A1kmXKPJ76uYzaCwpke8vG995w/JbOQRckCeYmQifkgdaT4SbwF+TrEBS/+YnY NR/QfPHWHPrwfSYSt34SL5azaidKAdsokdSIUHMxt8IeYRYjwPCayEzoxCMXsbzZsggd P+IPfpJDeIkiOtq6nKzU76mK4G3B1KRfxOcQUn25IMcLGxXwEbmouVe6JjTLMzPfU2BC ZCig== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=TD86MjNzNK/6ONxM4dB6JHGrVjxPZZILCR5gKUKE7pM=; b=Ig6peimGgHbSQfSr49ASxcc8me14E5PpkmvLXfsMuNGFO75nfvfgi2+DGgD27Xwg1n p8b0lkF2O/3CFUrUiz8ImztMo42U5bsy7+VkDKQC1d4CKwqL42jYYlq/zZGcDdW+YMPp BaErrDji9vQXGeRLMfGbU1ijkn1LV838HmELXMATohv1HJU5SfvS8t3KES1HANIbO8Yh ef49YiIkS+H3pfPRnOvIqurUfnuaBd4qrb/RIS6Jtd2ezMmbxqrVMRjcoYMLKaDrRtR8 hYg/SR4yRgga2nvfWZhCNGfCQzwpJUCzP2PCA9uqu+czG5vyrLOZNQHCPJCihYd5lkhZ t7bw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@alien8.de header.s=dkim header.b=hNu7J36b; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=alien8.de Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id hr39-20020a1709073fa700b0073d635877ffsi1440714ejc.478.2022.08.20.01.43.35; Sat, 20 Aug 2022 01:44:01 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@alien8.de header.s=dkim header.b=hNu7J36b; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=alien8.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344525AbiHTIjS (ORCPT + 99 others); Sat, 20 Aug 2022 04:39:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48502 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231132AbiHTIjQ (ORCPT ); Sat, 20 Aug 2022 04:39:16 -0400 Received: from mail.skyhub.de (mail.skyhub.de [IPv6:2a01:4f8:190:11c2::b:1457]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3ADE927B0F for ; Sat, 20 Aug 2022 01:39:14 -0700 (PDT) Received: from zn.tnic (p200300ea971b9849329c23fffea6a903.dip0.t-ipconnect.de [IPv6:2003:ea:971b:9849:329c:23ff:fea6:a903]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.skyhub.de (SuperMail on ZX Spectrum 128k) with ESMTPSA id 2A5E61EC0657; Sat, 20 Aug 2022 10:39:09 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=alien8.de; s=dkim; t=1660984749; 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: content-transfer-encoding:in-reply-to:in-reply-to: references:references; bh=TD86MjNzNK/6ONxM4dB6JHGrVjxPZZILCR5gKUKE7pM=; b=hNu7J36bytXQs7ZS+C9/PTH/fI17VsllEYVpvHmn0jY+W0vw3WHrqorUSwSzpVgrNEZmjx HnnQQd9pd6cXXY8Ht3Tj6CyIzAlhwLVn2QKzlQuiessE2vm44iSBYLX7jrqcIsX99Sw9w1 oCSJHlY6kYq6vJM0Fn+l5DiIMy4PypA= Date: Sat, 20 Aug 2022 10:39:03 +0200 From: Borislav Petkov To: Saurabh Singh Sengar Cc: ssengar@microsoft.com, mikelley@microsoft.com, tglx@linutronix.de, mingo@redhat.com, dave.hansen@linux.intel.com, x86@kernel.org, hpa@zytor.com, peterz@infradead.org, tim.c.chen@linux.intel.com, will@kernel.org, song.bao.hua@hisilicon.com, suravee.suthikulpanit@amd.com, linux-kernel@vger.kernel.org Subject: [PATCH] x86/cacheinfo: Add a cpu_llc_shared_mask() UP variant Message-ID: References: <1660148115-302-1-git-send-email-ssengar@linux.microsoft.com> <20220818045225.GA9054@linuxonhyperv3.guj3yctzbm1etfxqx2vob5hsef.xx.internal.cloudapp.net> <20220818122925.GA8507@linuxonhyperv3.guj3yctzbm1etfxqx2vob5hsef.xx.internal.cloudapp.net> <20220819174659.GA16818@linuxonhyperv3.guj3yctzbm1etfxqx2vob5hsef.xx.internal.cloudapp.net> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20220819174659.GA16818@linuxonhyperv3.guj3yctzbm1etfxqx2vob5hsef.xx.internal.cloudapp.net> X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Aug 19, 2022 at 10:46:59AM -0700, Saurabh Singh Sengar wrote: > Yes, this patch fixes this segfault. Thx! --- From: Borislav Petkov On a CONFIG_SMP=n kernel, the LLC shared mask is 0, which prevents __cache_amd_cpumap_setup() from doing the L3 masks setup, and more specifically from setting up the shared_cpu_map and shared_cpu_list files in sysfs, leading to lscpu from util-linux getting confused and segfaulting. Add a cpu_llc_shared_mask() UP variant which returns a mask with a single bit set, i.e., for CPU0. Fixes: 2b83809a5e6d ("x86/cpu/amd: Derive L3 shared_cpu_map from cpu_llc_shared_mask") Reported-by: Saurabh Sengar Signed-off-by: Borislav Petkov Cc: Link: https://lore.kernel.org/r/1660148115-302-1-git-send-email-ssengar@linux.microsoft.com --- arch/x86/include/asm/smp.h | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/arch/x86/include/asm/smp.h b/arch/x86/include/asm/smp.h index 81a0211a372d..a73bced40e24 100644 --- a/arch/x86/include/asm/smp.h +++ b/arch/x86/include/asm/smp.h @@ -21,16 +21,6 @@ DECLARE_PER_CPU_READ_MOSTLY(u16, cpu_llc_id); DECLARE_PER_CPU_READ_MOSTLY(u16, cpu_l2c_id); DECLARE_PER_CPU_READ_MOSTLY(int, cpu_number); -static inline struct cpumask *cpu_llc_shared_mask(int cpu) -{ - return per_cpu(cpu_llc_shared_map, cpu); -} - -static inline struct cpumask *cpu_l2c_shared_mask(int cpu) -{ - return per_cpu(cpu_l2c_shared_map, cpu); -} - DECLARE_EARLY_PER_CPU_READ_MOSTLY(u16, x86_cpu_to_apicid); DECLARE_EARLY_PER_CPU_READ_MOSTLY(u32, x86_cpu_to_acpiid); DECLARE_EARLY_PER_CPU_READ_MOSTLY(u16, x86_bios_cpu_apicid); @@ -172,6 +162,16 @@ extern int safe_smp_processor_id(void); # define safe_smp_processor_id() smp_processor_id() #endif +static inline struct cpumask *cpu_llc_shared_mask(int cpu) +{ + return per_cpu(cpu_llc_shared_map, cpu); +} + +static inline struct cpumask *cpu_l2c_shared_mask(int cpu) +{ + return per_cpu(cpu_l2c_shared_map, cpu); +} + #else /* !CONFIG_SMP */ #define wbinvd_on_cpu(cpu) wbinvd() static inline int wbinvd_on_all_cpus(void) @@ -179,6 +179,11 @@ static inline int wbinvd_on_all_cpus(void) wbinvd(); return 0; } + +static inline struct cpumask *cpu_llc_shared_mask(int cpu) +{ + return (struct cpumask *)cpumask_of(0); +} #endif /* CONFIG_SMP */ extern unsigned disabled_cpus; -- 2.35.1 -- Regards/Gruss, Boris. https://people.kernel.org/tglx/notes-about-netiquette