Received: by 2002:a05:6359:322:b0:b3:69d0:12d8 with SMTP id ef34csp367296rwb; Wed, 10 Aug 2022 09:27:49 -0700 (PDT) X-Google-Smtp-Source: AA6agR6bjYzxobzYEFBMcgj6MXMAEz723Ov/UXyXkTzktEC12XiIffEZRytjyZGmgIbKplsRCfhH X-Received: by 2002:a17:903:2601:b0:16d:b055:2985 with SMTP id jd1-20020a170903260100b0016db0552985mr28786517plb.161.1660148868892; Wed, 10 Aug 2022 09:27:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660148868; cv=none; d=google.com; s=arc-20160816; b=Xz9TN8WwWjwXrjmzlc5fUWKft0C8N4HnshPbZEU7/CqSDLoRQzwic8YBWquvGFFO7l dT5A5TNIo14TBi0rakcp7bYH5MR1QgHXIKgQjDVRcUwx1o41YtQthZQ+W8Sp+hmeds24 +9RMr9pChP45nyxfaUhMlt+rrVB2mjC41kb9oMVDGCRI5cWVrmYvtlNyNFXQHsS8laFd sNuu3EUJPKe0BQIwc0hABaAby9GlG1kto2qAD28vWtAyzlO8HZIS1IzpjM4EbsYWMcuM b7jCScolMRRQ/kZFFFFbvFUwfim0CoHG3ggg1VLAQQl4ZmCkmSaS0E2eJw5sM++Ow0/X 05ZA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:subject:to:from:dkim-signature :dkim-filter; bh=eLRZ89FweLs3mKAejSXm82Lf0LVTVfp7vtGx4U+EfJU=; b=cTo5yqwSXowej4g9O0565MZKiQpfNtyA9nBP32FRUDhp0VB2wAjteKe4CqYqqH7Mhk Zxcf4xtCcXDJ2vq6heRoAp1j83GtIKinjs7hUj+W+ECoNiFtqmwtPW4xqRd+j5T+Adfr iAb0OqlgzuXcQLggq/CQOdWucyCNVLmwuN8Lr7jlABaAoM+fNFUsq3QIkRGNXqG4OkXG qrwIf17MrWVJPCMb9I7t67VofAy/WfJvO60Q0HfjK+kWT/iHaI9GnwJ+4k8YK1yXN+Cu /W9R5FtV/uwABUD9ibjZHX7g94IIrporHZUHVmZQA3PaxvHLlJOdDdZgKdNu+itIxEV6 p5Jw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b="Z9/23526"; 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=linux.microsoft.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x4-20020a63db44000000b004121ba59eb5si9448291pgi.200.2022.08.10.09.27.10; Wed, 10 Aug 2022 09:27:48 -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=@linux.microsoft.com header.s=default header.b="Z9/23526"; 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=linux.microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232345AbiHJQPX (ORCPT + 99 others); Wed, 10 Aug 2022 12:15:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42954 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230000AbiHJQPW (ORCPT ); Wed, 10 Aug 2022 12:15:22 -0400 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id A12B02228B for ; Wed, 10 Aug 2022 09:15:21 -0700 (PDT) Received: from linuxonhyperv3.guj3yctzbm1etfxqx2vob5hsef.xx.internal.cloudapp.net (linux.microsoft.com [13.77.154.182]) by linux.microsoft.com (Postfix) with ESMTPSA id 3DC10210CB11; Wed, 10 Aug 2022 09:15:21 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 3DC10210CB11 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1660148121; bh=eLRZ89FweLs3mKAejSXm82Lf0LVTVfp7vtGx4U+EfJU=; h=From:To:Subject:Date:From; b=Z9/23526H5J2DCQyiuaAje86oqJurj1QE/YiTbxkOGuSD7cNwlk3UhqpmvctkgX7/ qEucWvbO9PAysXAjSUrnfDBnF3j49XZw6ArD/5Tn2UnioYsj8fZ86r8/PP3nOPlBCB D4itizPTf9F6XUJTMcmLV9crXvKGg0RzU6yRhQiU= From: Saurabh Sengar To: ssengar@microsoft.com, mikelley@microsoft.com, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, 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: Don't use cpu_llc_shared_map for !CONFIG_SMP Date: Wed, 10 Aug 2022 09:15:15 -0700 Message-Id: <1660148115-302-1-git-send-email-ssengar@linux.microsoft.com> X-Mailer: git-send-email 1.8.3.1 X-Spam-Status: No, score=-19.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_MED, SPF_HELO_PASS,SPF_PASS,T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL, USER_IN_DEF_SPF_WL 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 cpu_llc_shared_map is always declared and defined, but populated in arch/x86/kernel/smpboot.c which only builds for CONFIG_SMP=y. For UniProcessor builds this mask is never populated and hence invalid. Current code doesn't handle the case of AMD UniProcessor correctly, which results "shared_cpu_map" and "shared_cpu_list" files missing from sysfs entries for l3 cache. This patch fixes this issue. This code used to work because of a another bug in 'cpumask_next', where in the CONFIG_SMP=n case the cpumask_next() ignores empty mask that results as if CPU 0 was set. This bug in 'cpumask_next' was fixed by following commit, which exposes the cpu_llc_shared_map bug. b81dce77ced ("cpumask: Fix invalid uniprocessor mask assumption") Fixes: 2b83809a5e ("x86/cpu/amd: Derive L3 shared_cpu_map from cpu_llc_shared_mask") Signed-off-by: Saurabh Sengar --- arch/x86/kernel/cpu/cacheinfo.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/arch/x86/kernel/cpu/cacheinfo.c b/arch/x86/kernel/cpu/cacheinfo.c index 66556833d7af..8753bf33fec4 100644 --- a/arch/x86/kernel/cpu/cacheinfo.c +++ b/arch/x86/kernel/cpu/cacheinfo.c @@ -889,10 +889,12 @@ static int __cache_amd_cpumap_setup(unsigned int cpu, int index, int i, sibling; /* - * For L3, always use the pre-calculated cpu_llc_shared_mask - * to derive shared_cpu_map. + * For L3, in case of SMP systems use the pre-calculated + * cpu_llc_shared_mask to derive shared_cpu_map. In case + * of UP simply set the only cpu in mask. */ if (index == 3) { +#ifdef CONFIG_SMP for_each_cpu(i, cpu_llc_shared_mask(cpu)) { this_cpu_ci = get_cpu_cacheinfo(i); if (!this_cpu_ci->info_list) @@ -905,6 +907,14 @@ static int __cache_amd_cpumap_setup(unsigned int cpu, int index, &this_leaf->shared_cpu_map); } } +#else + this_cpu_ci = get_cpu_cacheinfo(cpu); + WARN_ON(!this_cpu_ci->info_list); + if (!this_cpu_ci->info_list) + return 0; + this_leaf = this_cpu_ci->info_list + index; + cpumask_set_cpu(cpu, &this_leaf->shared_cpu_map); +#endif } else if (boot_cpu_has(X86_FEATURE_TOPOEXT)) { unsigned int apicid, nshared, first, last; -- 2.25.1