From patchwork Fri Oct 14 09:01:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Zhang, Rui" X-Patchwork-Id: 2596 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp73874wrs; Fri, 14 Oct 2022 02:00:18 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7a4yZlC+eYhFxn4dZxle3XKgs1ii8ms/ca8dnHbMJnFaHnpGg9ngJIeS5xJR85RFmvkWSb X-Received: by 2002:aa7:cd92:0:b0:456:cbb5:2027 with SMTP id x18-20020aa7cd92000000b00456cbb52027mr3360265edv.384.1665738018459; Fri, 14 Oct 2022 02:00:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665738018; cv=none; d=google.com; s=arc-20160816; b=Vo7nkBo7WeD3rmy6F/yFZjP1e8xj37TVlIHPizz9Thpeua5UgKZY5ReDmD5UA8ggoo yX6tyFLHqTFvgsH47Ch0mt9g5VfF0/ramUHRUI0ZZ4G1yjdeWcuQZPohixjLZ2JcjV44 9fXQ0zc+sXoJDHVAo/CWZFH/O4BSv68mFH8IlNT2MWchMrouYVdVD9Z59WE9A4vN95lR CK0sfuDw3OARCwWkgw4i1W7oKkq32rpM5ChRIFVK9QgcLg0UgMca867V1EMhQKW62ZRC 9p9T0oGfsw1nlFhmjqpYIw7QuCBZh72xOnRASkTmxa4qbopIP0nq8KPfyBXyx4GB/2KN FcuA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from:dkim-signature; bh=Ag6H/DkHtIE33PpzSXUQ7CMh/Gv8eb3EWzpr2pElTEY=; b=h4m7NstcBi4L9hoXsh+pvsuMZQL0OMyILjCG70vowQ5huNz9Zu3WZT4UEuyDl4d3pm Whoe9NShEQN1CXUNsICpfk9OGt17dXAAAECsYYZdT2RM+Y2wTFjDxHNjUZUbkUYqWW0G +6k65McFiBgdnmvxYeBed883oKV6wNbskTliJX5JpoGtfvOiHuqpDyq9D1IsG0GYrLsG a0BocVvl+fL/kQuZu0JntieUTvqAN3hksrXqFvNuJ6aIkgNjI+85K56HuOEJAnDU5xvo CqECy1CVTvl5X70bry470JxYLXytSkJGN7tYm5t61asTttv2wlSm8Nz9Tfkm2ZyZ08Zh yLBA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=nk59jkXz; 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=intel.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g11-20020a17090669cb00b0073d710fec77si1772262ejs.251.2022.10.14.01.59.52; Fri, 14 Oct 2022 02:00:18 -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=@intel.com header.s=Intel header.b=nk59jkXz; 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=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230085AbiJNI7Q (ORCPT + 99 others); Fri, 14 Oct 2022 04:59:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36926 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230003AbiJNI7M (ORCPT ); Fri, 14 Oct 2022 04:59:12 -0400 Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 77EC315626F; Fri, 14 Oct 2022 01:59:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1665737951; x=1697273951; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=2LzFHhElpAS0tiULqCikh0gwGEfkJcjRgv1pg6Sxb14=; b=nk59jkXzKhRc9JREVnm/A8XueLeg1LhdRgiYSJ4IwpF6UthI1BbGO8zk 7o1kbeNeUbdECiR9AqohLMworOgGEZj2SpHBNb8FjE/AarOb/hWyouwpX vrrgfbdi/KqF6VQQ4kh4F8kuZquGLChMsE375lk7QPOsDGXZGV9Hmkjzj y+b6/ziX6gvBtAgLshbY23Rjr1Atyaon3FoTWUDc8UVxBWDjv12uHSAOy Kn8pM5LynD77RTfy9gaXQWjlz/PAKdkn4+oUqV3OFMC0iEawsxNN7Xjkx ks3KA8iNqcDkEoGIpOdkH2CTn+eQmzqO+mimvyuOYs6Vje9MRnGcZVqsS w==; X-IronPort-AV: E=McAfee;i="6500,9779,10499"; a="391635352" X-IronPort-AV: E=Sophos;i="5.95,182,1661842800"; d="scan'208";a="391635352" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Oct 2022 01:59:11 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10499"; a="696234495" X-IronPort-AV: E=Sophos;i="5.95,182,1661842800"; d="scan'208";a="696234495" Received: from power-sh.sh.intel.com ([10.239.183.122]) by fmsmga004.fm.intel.com with ESMTP; 14 Oct 2022 01:59:08 -0700 From: Zhang Rui To: linux-kernel@vger.kernel.org, x86@kernel.org, linux-hwmon@vger.kernel.org Cc: tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, hpa@zytor.com, peterz@infradead.org, jdelvare@suse.com, linux@roeck-us.net, len.brown@intel.com, rui.zhang@intel.com Subject: [PATCH V4 1/4] hwmon/coretemp: Rename indx to index Date: Fri, 14 Oct 2022 17:01:44 +0800 Message-Id: <20221014090147.1836-2-rui.zhang@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20221014090147.1836-1-rui.zhang@intel.com> References: <20221014090147.1836-1-rui.zhang@intel.com> X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1746652908450180111?= X-GMAIL-MSGID: =?utf-8?q?1746652908450180111?= Use variable name 'index' instead of 'indx' for the index in the core_data[] array. No functional change expected. Cc: stable@vger.kernel.org Suggested-by: Ingo Molnar Signed-off-by: Zhang Rui Acked-by: Guenter Roeck --- drivers/hwmon/coretemp.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/drivers/hwmon/coretemp.c b/drivers/hwmon/coretemp.c index ccf0af5b988a..bfdcfe8ccb34 100644 --- a/drivers/hwmon/coretemp.c +++ b/drivers/hwmon/coretemp.c @@ -515,15 +515,15 @@ coretemp_add_core(struct platform_device *pdev, unsigned int cpu, int pkg_flag) dev_err(&pdev->dev, "Adding Core %u failed\n", cpu); } -static void coretemp_remove_core(struct platform_data *pdata, int indx) +static void coretemp_remove_core(struct platform_data *pdata, int index) { - struct temp_data *tdata = pdata->core_data[indx]; + struct temp_data *tdata = pdata->core_data[index]; /* Remove the sysfs attributes */ sysfs_remove_group(&pdata->hwmon_dev->kobj, &tdata->attr_group); - kfree(pdata->core_data[indx]); - pdata->core_data[indx] = NULL; + kfree(pdata->core_data[index]); + pdata->core_data[index] = NULL; } static int coretemp_probe(struct platform_device *pdev) @@ -647,7 +647,7 @@ static int coretemp_cpu_offline(unsigned int cpu) struct platform_device *pdev = coretemp_get_pdev(cpu); struct platform_data *pd; struct temp_data *tdata; - int indx, target; + int index, target; /* * Don't execute this on suspend as the device remove locks @@ -661,12 +661,12 @@ static int coretemp_cpu_offline(unsigned int cpu) return 0; /* The core id is too big, just return */ - indx = TO_ATTR_NO(cpu); - if (indx > MAX_CORE_DATA - 1) + index = TO_ATTR_NO(cpu); + if (index > MAX_CORE_DATA - 1) return 0; pd = platform_get_drvdata(pdev); - tdata = pd->core_data[indx]; + tdata = pd->core_data[index]; cpumask_clear_cpu(cpu, &pd->cpumask); @@ -677,7 +677,7 @@ static int coretemp_cpu_offline(unsigned int cpu) */ target = cpumask_any_and(&pd->cpumask, topology_sibling_cpumask(cpu)); if (target >= nr_cpu_ids) { - coretemp_remove_core(pd, indx); + coretemp_remove_core(pd, index); } else if (tdata && tdata->cpu == cpu) { mutex_lock(&tdata->update_lock); tdata->cpu = target; From patchwork Fri Oct 14 09:01:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Zhang, Rui" X-Patchwork-Id: 2597 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp74001wrs; Fri, 14 Oct 2022 02:00:33 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4neUztR6kyKBnbKqIPJbQEyBU45ga7RGafERHeolimjrLnIRflGciEZ7EZ9MSBxw35F1Qb X-Received: by 2002:a17:907:3d8f:b0:78d:b46e:eadd with SMTP id he15-20020a1709073d8f00b0078db46eeaddmr2836006ejc.277.1665738032778; Fri, 14 Oct 2022 02:00:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665738032; cv=none; d=google.com; s=arc-20160816; b=sfyEP9EQphia1oeDIpa9nsttCWoTYQjHhUETLMKHQBn07GEY56zENBf6gg0s+CLMsK S/6qdo7ab/jbA1mLTs4UyUAB4fYQ4QuSpgJvhUAmZl/ff6W88YduQ4Jz/9vVQjYc+3zb zDR6l9u+ICM7Gu5UuV51GpD5CHrOIzOTDv6SK51MDx8Znj5rSdYUTnbxh8/qRAcrFdab Lh3a/2IXC5ZJ+0vqXaUT1AzEsdirJVPxmEYeXr4wvPPxRvGfwn7ybQoEgsI+d5AwEu9D aLyBrSY0HEHsYcv5jIP+y+9p7FOIl5otcVnj0raDYp032zsRcB/u7ZvcEbhmZ0zvZfYc nmtw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from:dkim-signature; bh=s8rsDSSRJDikNF0AEtnijM7zQrZ6ohiQmHPl81D7UIU=; b=U1BSKKrKIMOhQrtvPF6ecbtGLelXokyjrI567k3PuZHqq1qcBwGpZ+ZQ0ng6PXGUVM QzM0XdAfS1eXMwk3a8rBWFl5uf9QMJtXRqEHxkdKD4PCy9L0RCq9pcHl6mnvk6olNHdi baGjd+Xq7sTRNdh5O82VtYZjPcIX8tKEp5s9veB0gHpfiGHFUZCTf3bNtrbcEnlRpwso fF1MRrBFaBffZiNWT1CVQhYq8QwFPWM357X+ml+Q2eLBOHkQL/stsYYMxcYTsY69mg6F nUHAL4gOAnQf6D/ZBRZ6pWknrBlAraeMVNavRYc8oWyGSOQ4q7diPpjzYnM1u+G66F+y VbQQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=VSyHKXHK; 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=intel.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l8-20020a056402254800b0045d1a74b76fsi1522090edb.443.2022.10.14.02.00.05; Fri, 14 Oct 2022 02:00:32 -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=@intel.com header.s=Intel header.b=VSyHKXHK; 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=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230106AbiJNI7U (ORCPT + 99 others); Fri, 14 Oct 2022 04:59:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37054 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230004AbiJNI7Q (ORCPT ); Fri, 14 Oct 2022 04:59:16 -0400 Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9218114EC6A; Fri, 14 Oct 2022 01:59:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1665737954; x=1697273954; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=tT6GsCkKtFxZFwU3AnqBEMCkEq36qH77xhPKht8kymI=; b=VSyHKXHKHsWSC6w3OMMGUCCz03zvc8G5mSa3gpZlx3XTvZ2qr2eLsGab s7+depnHuiFLxVysbSsCrZ/Cuz21Hcwf2SMK6fQCa2qtq0+fy7hAVx6g4 VtRutGNl0D2nLaI5vCPDqIJR7rZnoGLwAnCLsTNj9C0w4tTS3ir82Vjip 3AMOFTZ7NhZRMNu05SQkxeXT5iBNB/CgoKTHsk+7dxMbJpkbV3n9E2Bfo +RJ5RUgGknFeLk31x/h65cdmybfNy7oc9AG97kmv226oC3hlbX1q8D0Z6 SVkH6pM/N301sFzUrrJiXho81zGqgBSVl5Wwtfmm6Il1ltNLzKWGtzTzI w==; X-IronPort-AV: E=McAfee;i="6500,9779,10499"; a="391635374" X-IronPort-AV: E=Sophos;i="5.95,182,1661842800"; d="scan'208";a="391635374" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Oct 2022 01:59:14 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10499"; a="696234521" X-IronPort-AV: E=Sophos;i="5.95,182,1661842800"; d="scan'208";a="696234521" Received: from power-sh.sh.intel.com ([10.239.183.122]) by fmsmga004.fm.intel.com with ESMTP; 14 Oct 2022 01:59:11 -0700 From: Zhang Rui To: linux-kernel@vger.kernel.org, x86@kernel.org, linux-hwmon@vger.kernel.org Cc: tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, hpa@zytor.com, peterz@infradead.org, jdelvare@suse.com, linux@roeck-us.net, len.brown@intel.com, rui.zhang@intel.com Subject: [PATCH V4 2/4] hwmon/coretemp: Handle large core ID value Date: Fri, 14 Oct 2022 17:01:45 +0800 Message-Id: <20221014090147.1836-3-rui.zhang@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20221014090147.1836-1-rui.zhang@intel.com> References: <20221014090147.1836-1-rui.zhang@intel.com> X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1746652923737750962?= X-GMAIL-MSGID: =?utf-8?q?1746652923737750962?= The coretemp driver supports up to a hard-coded limit of 128 cores. Today, the driver can not support a core with an ID above that limit. Yet, the encoding of core ID's is arbitrary (BIOS APIC-ID) and so they may be sparse and they may be large. Update the driver to map arbitrary core ID numbers into appropriate array indexes so that 128 cores can be supported, no matter the encoding of core ID's. Cc: stable@vger.kernel.org Signed-off-by: Zhang Rui Acked-by: Len Brown Acked-by: Guenter Roeck --- drivers/hwmon/coretemp.c | 56 +++++++++++++++++++++++++++++----------- 1 file changed, 41 insertions(+), 15 deletions(-) diff --git a/drivers/hwmon/coretemp.c b/drivers/hwmon/coretemp.c index bfdcfe8ccb34..291566aeb703 100644 --- a/drivers/hwmon/coretemp.c +++ b/drivers/hwmon/coretemp.c @@ -46,9 +46,6 @@ MODULE_PARM_DESC(tjmax, "TjMax value in degrees Celsius"); #define TOTAL_ATTRS (MAX_CORE_ATTRS + 1) #define MAX_CORE_DATA (NUM_REAL_CORES + BASE_SYSFS_ATTR_NO) -#define TO_CORE_ID(cpu) (cpu_data(cpu).cpu_core_id) -#define TO_ATTR_NO(cpu) (TO_CORE_ID(cpu) + BASE_SYSFS_ATTR_NO) - #ifdef CONFIG_SMP #define for_each_sibling(i, cpu) \ for_each_cpu(i, topology_sibling_cpumask(cpu)) @@ -91,6 +88,8 @@ struct temp_data { struct platform_data { struct device *hwmon_dev; u16 pkg_id; + u16 cpu_map[NUM_REAL_CORES]; + struct ida ida; struct cpumask cpumask; struct temp_data *core_data[MAX_CORE_DATA]; struct device_attribute name_attr; @@ -441,7 +440,7 @@ static struct temp_data *init_temp_data(unsigned int cpu, int pkg_flag) MSR_IA32_THERM_STATUS; tdata->is_pkg_data = pkg_flag; tdata->cpu = cpu; - tdata->cpu_core_id = TO_CORE_ID(cpu); + tdata->cpu_core_id = topology_core_id(cpu); tdata->attr_size = MAX_CORE_ATTRS; mutex_init(&tdata->update_lock); return tdata; @@ -454,7 +453,7 @@ static int create_core_data(struct platform_device *pdev, unsigned int cpu, struct platform_data *pdata = platform_get_drvdata(pdev); struct cpuinfo_x86 *c = &cpu_data(cpu); u32 eax, edx; - int err, attr_no; + int err, index, attr_no; /* * Find attr number for sysfs: @@ -462,14 +461,26 @@ static int create_core_data(struct platform_device *pdev, unsigned int cpu, * The attr number is always core id + 2 * The Pkgtemp will always show up as temp1_*, if available */ - attr_no = pkg_flag ? PKG_SYSFS_ATTR_NO : TO_ATTR_NO(cpu); + if (pkg_flag) { + attr_no = PKG_SYSFS_ATTR_NO; + } else { + index = ida_alloc(&pdata->ida, GFP_KERNEL); + if (index < 0) + return index; + pdata->cpu_map[index] = topology_core_id(cpu); + attr_no = index + BASE_SYSFS_ATTR_NO; + } - if (attr_no > MAX_CORE_DATA - 1) - return -ERANGE; + if (attr_no > MAX_CORE_DATA - 1) { + err = -ERANGE; + goto ida_free; + } tdata = init_temp_data(cpu, pkg_flag); - if (!tdata) - return -ENOMEM; + if (!tdata) { + err = -ENOMEM; + goto ida_free; + } /* Test if we can access the status register */ err = rdmsr_safe_on_cpu(cpu, tdata->status_reg, &eax, &edx); @@ -505,6 +516,9 @@ static int create_core_data(struct platform_device *pdev, unsigned int cpu, exit_free: pdata->core_data[attr_no] = NULL; kfree(tdata); +ida_free: + if (!pkg_flag) + ida_free(&pdata->ida, index); return err; } @@ -524,6 +538,9 @@ static void coretemp_remove_core(struct platform_data *pdata, int index) kfree(pdata->core_data[index]); pdata->core_data[index] = NULL; + + if (index >= BASE_SYSFS_ATTR_NO) + ida_free(&pdata->ida, index - BASE_SYSFS_ATTR_NO); } static int coretemp_probe(struct platform_device *pdev) @@ -537,6 +554,7 @@ static int coretemp_probe(struct platform_device *pdev) return -ENOMEM; pdata->pkg_id = pdev->id; + ida_init(&pdata->ida); platform_set_drvdata(pdev, pdata); pdata->hwmon_dev = devm_hwmon_device_register_with_groups(dev, DRVNAME, @@ -553,6 +571,7 @@ static int coretemp_remove(struct platform_device *pdev) if (pdata->core_data[i]) coretemp_remove_core(pdata, i); + ida_destroy(&pdata->ida); return 0; } @@ -647,7 +666,7 @@ static int coretemp_cpu_offline(unsigned int cpu) struct platform_device *pdev = coretemp_get_pdev(cpu); struct platform_data *pd; struct temp_data *tdata; - int index, target; + int i, index = -1, target; /* * Don't execute this on suspend as the device remove locks @@ -660,12 +679,19 @@ static int coretemp_cpu_offline(unsigned int cpu) if (!pdev) return 0; - /* The core id is too big, just return */ - index = TO_ATTR_NO(cpu); - if (index > MAX_CORE_DATA - 1) + pd = platform_get_drvdata(pdev); + + for (i = 0; i < NUM_REAL_CORES; i++) { + if (pd->cpu_map[i] == topology_core_id(cpu)) { + index = i + BASE_SYSFS_ATTR_NO; + break; + } + } + + /* Too many cores and this core is not populated, just return */ + if (index < 0) return 0; - pd = platform_get_drvdata(pdev); tdata = pd->core_data[index]; cpumask_clear_cpu(cpu, &pd->cpumask); From patchwork Fri Oct 14 09:01:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Zhang, Rui" X-Patchwork-Id: 2598 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp74882wrs; Fri, 14 Oct 2022 02:02:25 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5K5PiwTXg/K1dHsaI64JeJ4h9VewxSYHMirYaEeq1XjQKlu3nj1eXHQxaUv5aReW1s0dl4 X-Received: by 2002:a17:907:9717:b0:78d:9fb4:16dd with SMTP id jg23-20020a170907971700b0078d9fb416ddmr2868887ejc.720.1665738144740; Fri, 14 Oct 2022 02:02:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665738144; cv=none; d=google.com; s=arc-20160816; b=ZPWp8RUVsfkW03dj2mR9BKYpgHe6o5VklscER9zoV3sOpcHLc99S//S9gAGdI4/eXa LXpTXUFEXBfUbP2mPAyZQE9EzYaDsqLNx2mP5r9ZL8xFhL6i9+ptXbPe/iM6syiyLnNi 7TIEu78TCA3OHSto9dhqGHlAi19zocF99q0sj7jzci1+pIelLnqre2YLYqADBeVQ8+jF yPqdcOTDsb8Y2wMAjd3XXf2VLj8AQF5vRjy5oBKMlsbAfMsG3uUR+UMrxerk+QG0bdXh U4NlcsF6oUM+t+GsNLqrEH5uYp5ntQ70XTVqx2scUhCal4QAgxSXj8bfI04E2raGCAp3 p+SQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from:dkim-signature; bh=pI+4OtTrFFgq0X5iL8nqpI+MqkVUkBCH9IZR8gllswY=; b=oqk1vRCLjlkjpsmBml4rNuvg5Jquo/QC5aAfXKXcPLEl8adOvvM2Em9ukG6iyAWFlC Ve2a7RDbM5Y2tRXPiNK1KlEC0z0f5Ec1X4wzIG2qALo/spa9iVmKSV3JivIWNXBa8aPC xigOou7eWzVLhZ0Mgi6QR+7HA9rtH3xSuvQrjIdpSN0UO4jltnPlE7SCx8rxdLvQnt9p cYCfW1ag9FABUFb2iD5Bi21vIySV5rwhuW3rhNGzAIUp8izGkOssYbym7FzbTIMAvb4V O4Hcec0ZY933lKSJA2WhO5A5UZZ/78Mqv+saXL7SpstjtKjZ+kzyV32yBYzLE3BGRLWo 8N2g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=W+Jxm+eI; 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=intel.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h8-20020a056402280800b0045927324653si2446251ede.6.2022.10.14.02.01.58; Fri, 14 Oct 2022 02:02:24 -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=@intel.com header.s=Intel header.b=W+Jxm+eI; 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=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230129AbiJNI7a (ORCPT + 99 others); Fri, 14 Oct 2022 04:59:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37138 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230100AbiJNI7T (ORCPT ); Fri, 14 Oct 2022 04:59:19 -0400 Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C254C15626F; Fri, 14 Oct 2022 01:59:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1665737957; x=1697273957; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=OTbXSwCtr2+jExMCyp3avWcsWjg4MvtgqQG+iqEBjmI=; b=W+Jxm+eITlG7gqsUpl05SFdP4XCb+AQ8nY4tCK+0ErE27cK/bm6Jhfab lYZ8libwBUKnJ414ApFitSSGmW5raAGlBU8qFJFq6vbNxINb9UymBmrz5 1J3WiYXKE5Ddb8nRYKGq+A8cTTJqZ0OsHSi6oda1Dm+BXTn9ZYB2gbiEf HRNlP7YX+V6YOQFQmu/cUOzP+du7l4U+61k4nL1FEq0Pqppzkycg5xBRd Y1EACZXyiyol3Pgbs7DNzILFqNSFC6Dr0NgfaZNbQ48YeM5InR4g+2twB i07YcgBniZOX72BLFYyR5UYjC+w139SocJ2aqCHzcO9wuzAvbpfqJPsHr Q==; X-IronPort-AV: E=McAfee;i="6500,9779,10499"; a="391635386" X-IronPort-AV: E=Sophos;i="5.95,182,1661842800"; d="scan'208";a="391635386" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Oct 2022 01:59:17 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10499"; a="696234537" X-IronPort-AV: E=Sophos;i="5.95,182,1661842800"; d="scan'208";a="696234537" Received: from power-sh.sh.intel.com ([10.239.183.122]) by fmsmga004.fm.intel.com with ESMTP; 14 Oct 2022 01:59:14 -0700 From: Zhang Rui To: linux-kernel@vger.kernel.org, x86@kernel.org, linux-hwmon@vger.kernel.org Cc: tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, hpa@zytor.com, peterz@infradead.org, jdelvare@suse.com, linux@roeck-us.net, len.brown@intel.com, rui.zhang@intel.com Subject: [PATCH V4 3/4] x86/topology: Fix multiple packages shown on a single-package system Date: Fri, 14 Oct 2022 17:01:46 +0800 Message-Id: <20221014090147.1836-4-rui.zhang@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20221014090147.1836-1-rui.zhang@intel.com> References: <20221014090147.1836-1-rui.zhang@intel.com> X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1746653040835133902?= X-GMAIL-MSGID: =?utf-8?q?1746653040835133902?= CPUID.1F/B does not emumerate Package level explicitly, instead, all the APIC-ID bits above the enumerated levels are assumed to be package ID bits. Current code gets package ID by shifting out all the APIC-ID bits that Linux supports, rather than shifting out all the APIC-ID bits that CPUID.1F enumerates. This introduces problems when CPUID.1F enumerates a level that Linux does not support. For example, on a single package AlderLake-N, there are 2 Ecore Modules with 4 atom cores in each module. Linux does not support the Module level and interprets the Module ID bits as package ID and erroneously reports a multi module system as a multi-package system. Fix this by using APIC-ID bits above all the CPUID.1F enumerated levels as package ID. Fixes: 7745f03eb395 ("x86/topology: Add CPUID.1F multi-die/package support") Cc: stable@vger.kernel.org Suggested-by: Len Brown Signed-off-by: Zhang Rui Reviewed-by: Len Brown --- arch/x86/kernel/cpu/topology.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/arch/x86/kernel/cpu/topology.c b/arch/x86/kernel/cpu/topology.c index 132a2de44d2f..f7592814e5d5 100644 --- a/arch/x86/kernel/cpu/topology.c +++ b/arch/x86/kernel/cpu/topology.c @@ -96,6 +96,7 @@ int detect_extended_topology(struct cpuinfo_x86 *c) unsigned int ht_mask_width, core_plus_mask_width, die_plus_mask_width; unsigned int core_select_mask, core_level_siblings; unsigned int die_select_mask, die_level_siblings; + unsigned int pkg_mask_width; bool die_level_present = false; int leaf; @@ -111,10 +112,10 @@ int detect_extended_topology(struct cpuinfo_x86 *c) core_level_siblings = smp_num_siblings = LEVEL_MAX_SIBLINGS(ebx); core_plus_mask_width = ht_mask_width = BITS_SHIFT_NEXT_LEVEL(eax); die_level_siblings = LEVEL_MAX_SIBLINGS(ebx); - die_plus_mask_width = BITS_SHIFT_NEXT_LEVEL(eax); + pkg_mask_width = die_plus_mask_width = BITS_SHIFT_NEXT_LEVEL(eax); sub_index = 1; - do { + while (true) { cpuid_count(leaf, sub_index, &eax, &ebx, &ecx, &edx); /* @@ -132,8 +133,13 @@ int detect_extended_topology(struct cpuinfo_x86 *c) die_plus_mask_width = BITS_SHIFT_NEXT_LEVEL(eax); } + if (LEAFB_SUBTYPE(ecx) != INVALID_TYPE) + pkg_mask_width = BITS_SHIFT_NEXT_LEVEL(eax); + else + break; + sub_index++; - } while (LEAFB_SUBTYPE(ecx) != INVALID_TYPE); + } core_select_mask = (~(-1 << core_plus_mask_width)) >> ht_mask_width; die_select_mask = (~(-1 << die_plus_mask_width)) >> @@ -148,7 +154,7 @@ int detect_extended_topology(struct cpuinfo_x86 *c) } c->phys_proc_id = apic->phys_pkg_id(c->initial_apicid, - die_plus_mask_width); + pkg_mask_width); /* * Reinit the apicid, now that we have extended initial_apicid. */ From patchwork Fri Oct 14 09:01:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Zhang, Rui" X-Patchwork-Id: 2599 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp77340wrs; Fri, 14 Oct 2022 02:08:43 -0700 (PDT) X-Google-Smtp-Source: AMsMyM78aocmIDA8dR5wAqzhoVehiq1+LT4vh9dRS6vvZqw6Juo9F0M5akNrXiZL14ZCCn2bkga+ X-Received: by 2002:a17:906:99c3:b0:78d:9cc9:deda with SMTP id s3-20020a17090699c300b0078d9cc9dedamr2838974ejn.712.1665738523416; Fri, 14 Oct 2022 02:08:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665738523; cv=none; d=google.com; s=arc-20160816; b=LdMlF1l+gYwX3vyeN2xnRclj3taix8pLJ2h/mDmRiMn2rG4R10bDQM71x5B8acnAn8 Bo9bHh/hr3LHVi5SFPHN8AcqRDMvNVHePQ+23YMBTtxbq+3LVGnxPmFSvYi4mEESEtA6 f5dC6KvZN8w8DupkF/WFeOxZaLPVyHhrUZfH/Ixu3Jfk+HahkAfk6/Gyn9+6vn5g6y/z c+f0OKkGFMbn6pinOel0DjFhVw4ojAXPJOgU5zKymWFxjmOcgrwhHtLPxGVgKcLUYxK0 3Bm0XE/gkjClVzatMAUwOEH+TVZkHfgNZhhiVYRnpT+2pY3LN0qC9d+2bTsaIm3kVzhh nDVQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from:dkim-signature; bh=dRyYXEmc1wGjbTFgMzdK1xMsQi4IjpnWpFr+cY6Wchc=; b=wNqEKGLVyOU+kQ9GZK7O2U+ZG/xnwZVrB5nKeY+EwYJCwqurlGQRZkqvoE9Rij6Rcv xvlm2dmXtMO1XlL/3AQLrBKz7Q3eFKWXhszIRlZ4meQvVVUCLmZNe7tDKOLIYn8velYD //kjfKIZClaPQP/c5touKQzJdqfEUQWREAGuwX1uvyDfxBmUhHYx2CzHMU1+rn9QwiiT o1gb2jjSGO0ezTYHu+rnMLdqq6nQadGPh9EHlZklm6oBz0MwqU1CuWEJfgWtevDJ3Nn+ +YG3y0PegGA25lc4Tci5CO+06FAUycmLbZLTCXnLq0TsXhAY4YlvjT2IJiBBwtweq/jD e/wg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=nQrb5nbk; 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=intel.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id hp7-20020a1709073e0700b00780ec98afafsi1821021ejc.113.2022.10.14.02.08.15; Fri, 14 Oct 2022 02:08:43 -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=@intel.com header.s=Intel header.b=nQrb5nbk; 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=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230116AbiJNI7f (ORCPT + 99 others); Fri, 14 Oct 2022 04:59:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37430 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230125AbiJNI7a (ORCPT ); Fri, 14 Oct 2022 04:59:30 -0400 Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B1A4B1C6BF5; Fri, 14 Oct 2022 01:59:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1665737960; x=1697273960; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=K5xG36ypnLnEJBbjHMbm2yY0zZe4wUyw2jNVWuOtSRQ=; b=nQrb5nbkRRpo01T8XBUp60uOrEBYgIKAqShvUQU3TSGYkDVskpgJXwGX GdwLTpJrNZrEBWPh0zmOQf43jUDda1HaQpNzMfGxQ4x6efFVdfW9u/MfH J8Qh560vXWtbBDMPZB17i7LrGnGQLXGGDdv9IhAqvNJvV6Q/Uc4Kn9bFY EbXXh2jmMzIArY0Ls6q2wvVXOc0C2bBIvvkVLivj0v1Bzd4QegtLct76q SzPyJRneSEfwo7dDWvSY+MUKHvnsqLN1zOxFPT0X5vqjMZoTwAE9X0yJq 80LpbRfwuEUAnAi8EOvzv0sp1iALiRgk3rz3cEf+0q5rImZbdgC5imebb A==; X-IronPort-AV: E=McAfee;i="6500,9779,10499"; a="391635396" X-IronPort-AV: E=Sophos;i="5.95,182,1661842800"; d="scan'208";a="391635396" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Oct 2022 01:59:20 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10499"; a="696234549" X-IronPort-AV: E=Sophos;i="5.95,182,1661842800"; d="scan'208";a="696234549" Received: from power-sh.sh.intel.com ([10.239.183.122]) by fmsmga004.fm.intel.com with ESMTP; 14 Oct 2022 01:59:17 -0700 From: Zhang Rui To: linux-kernel@vger.kernel.org, x86@kernel.org, linux-hwmon@vger.kernel.org Cc: tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, hpa@zytor.com, peterz@infradead.org, jdelvare@suse.com, linux@roeck-us.net, len.brown@intel.com, rui.zhang@intel.com Subject: [PATCH V4 4/4] x86/topology: Fix duplicated core ID within a package Date: Fri, 14 Oct 2022 17:01:47 +0800 Message-Id: <20221014090147.1836-5-rui.zhang@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20221014090147.1836-1-rui.zhang@intel.com> References: <20221014090147.1836-1-rui.zhang@intel.com> X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1746653437935915887?= X-GMAIL-MSGID: =?utf-8?q?1746653437935915887?= Today, core ID is assumed to be unique within each package. But an AlderLake-N platform adds a Module level between core and package, Linux excludes the unknown modules bits from the core ID, resulting in duplicate core ID's. To keep core ID unique within a package, Linux must include all APIC-ID bits for known or un-known levels above the core and below the package in the core ID. It is important to understand that core ID's have always come directly from the APIC-ID encoding, which comes from the BIOS. Thus there is no guarantee that they start at 0, or that they are contiguous. As such, naively using them for array indexes can be problematic. Fixes: 7745f03eb395 ("x86/topology: Add CPUID.1F multi-die/package support") Cc: stable@vger.kernel.org Suggested-by: Len Brown Signed-off-by: Zhang Rui Reviewed-by: Len Brown --- arch/x86/kernel/cpu/topology.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/x86/kernel/cpu/topology.c b/arch/x86/kernel/cpu/topology.c index f7592814e5d5..5e868b62a7c4 100644 --- a/arch/x86/kernel/cpu/topology.c +++ b/arch/x86/kernel/cpu/topology.c @@ -141,7 +141,7 @@ int detect_extended_topology(struct cpuinfo_x86 *c) sub_index++; } - core_select_mask = (~(-1 << core_plus_mask_width)) >> ht_mask_width; + core_select_mask = (~(-1 << pkg_mask_width)) >> ht_mask_width; die_select_mask = (~(-1 << die_plus_mask_width)) >> core_plus_mask_width;