From patchwork Thu Aug 2 13:42:38 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pingfan Liu X-Patchwork-Id: 952738 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 41hBKw2BTFz9s3q for ; Thu, 2 Aug 2018 23:46:44 +1000 (AEST) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="sfP03gyi"; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 41hBKv74vJzF2F1 for ; Thu, 2 Aug 2018 23:46:43 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="sfP03gyi"; dkim-atps=neutral X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:400e:c01::243; helo=mail-pl0-x243.google.com; envelope-from=kernelfans@gmail.com; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="sfP03gyi"; dkim-atps=neutral Received: from mail-pl0-x243.google.com (mail-pl0-x243.google.com [IPv6:2607:f8b0:400e:c01::243]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 41hBFb0pHwzF22V for ; Thu, 2 Aug 2018 23:42:59 +1000 (AEST) Received: by mail-pl0-x243.google.com with SMTP id s17-v6so1051082plp.7 for ; Thu, 02 Aug 2018 06:42:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=mtWU64ivVoZeMEbDQ1KOBT4vm1AMXNECKE32Wg7rcPw=; b=sfP03gyipSUXSJE40AhcPmG1EMvACvjuiVlkSIXBR0OjBJUcTriuK+AcndKySh+808 2ArdK50tCibtzzJSFJQ4MeZ/+9H+YcMm4f9+CIrgJDiIrXa4wF8qXqyRo75CO1XWLq0d XX8WstvwLJAbsOmIhBHN4eisGFgsKO/IbghnYuhbMJIJCKxf/w6xHMl8xndz42y+Bx6Z g0LdCr3aS4x8wts9IHvLhkXrxyMuoayHncX7stywQFQgBPjouQn2PcZ5oxTZ0gyMb6Bh x4CVwAQDq6fEvmTL/ef8b/oE3yRXS4rC6Wh2gcf1gpWfb87nkDnNETi6cmqWnAKgTdVx fHaQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=mtWU64ivVoZeMEbDQ1KOBT4vm1AMXNECKE32Wg7rcPw=; b=pltrVcSBSTHBI15/FfeQbWzGn0vDfVr8D1QeI1R7CVIfA8dAWpj8BMebiciq4LKI25 vqXUv5d5Boe0CvyfdLAy4lX1bqLtYLdtkPjj/EBFgMrwisoGX39Ee0Aa2yaBKuMQtqY7 f3JhFz0B3h+tXefR1UFZy5NPcE9VDCJo1zH76SGt2oogG+hRaL8P3wWzKt++T2su8fVR COQjoqKHRBM04E9CJWyX3CpqdIjACAtCgIU4X4CUegiIsXNGwBOacWEk7sC1RCZQUZVe rLTsXdzI/DXAoVkOWmXnjPlBrE8e5BsafVxQJqZla+hnoQC486b6C8Rgg4k0xsSgp+1T 0dYQ== X-Gm-Message-State: AOUpUlFjXVgOGWHzA9goDeALcbWQl0nyU7NM1acyY1ISZcDTd5FvKM4H tVCfvHOFBJI3n1NdnQDw7EiInHI= X-Google-Smtp-Source: AAOMgpe++7n3kvFfOUpUa3twMYE/fT07IndhNTAXwcU4UJ8KPuQKiNKamoz7MELeh9FWoWmANtaDFw== X-Received: by 2002:a17:902:4d45:: with SMTP id o5-v6mr2450949plh.78.1533217377237; Thu, 02 Aug 2018 06:42:57 -0700 (PDT) Received: from mylaptop.redhat.com ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id m81-v6sm5664113pfa.188.2018.08.02.06.42.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 02 Aug 2018 06:42:56 -0700 (PDT) From: Pingfan Liu To: linuxppc-dev@lists.ozlabs.org Subject: [PATCH 1/2] powerpc/cpuidle: dynamically register/unregister cpuidle_device during hotplug Date: Thu, 2 Aug 2018 21:42:38 +0800 Message-Id: <1533217359-11420-1-git-send-email-kernelfans@gmail.com> X-Mailer: git-send-email 2.7.4 X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-pm@vger.kernel.org, "Rafael J. Wysocki" , Pingfan Liu , Tyrel Datwyler Errors-To: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" cpuidle_device is touched during the cpu hotplug. At present, ppc64 just online/offline cpu during hotplug/unplug. But if using the register_cpu/unregister_cpu() API to implement the hotplug, the dir /sys/../cpuX is created/destroyed during hotplug, hence we also need to create the file cpuX/cpuidle dynamically. Cc: Benjamin Herrenschmidt Cc: Michael Ellerman Cc: "Rafael J. Wysocki" Cc: Tyrel Datwyler Cc: linux-pm@vger.kernel.org Signed-off-by: Pingfan Liu --- drivers/cpuidle/cpuidle-powernv.c | 2 ++ drivers/cpuidle/cpuidle-pseries.c | 2 ++ 2 files changed, 4 insertions(+) diff --git a/drivers/cpuidle/cpuidle-powernv.c b/drivers/cpuidle/cpuidle-powernv.c index d29e4f0..94d0def 100644 --- a/drivers/cpuidle/cpuidle-powernv.c +++ b/drivers/cpuidle/cpuidle-powernv.c @@ -166,6 +166,7 @@ static int powernv_cpuidle_cpu_online(unsigned int cpu) struct cpuidle_device *dev = per_cpu(cpuidle_devices, cpu); if (dev && cpuidle_get_driver()) { + cpuidle_register_device(dev); cpuidle_pause_and_lock(); cpuidle_enable_device(dev); cpuidle_resume_and_unlock(); @@ -181,6 +182,7 @@ static int powernv_cpuidle_cpu_dead(unsigned int cpu) cpuidle_pause_and_lock(); cpuidle_disable_device(dev); cpuidle_resume_and_unlock(); + cpuidle_unregister_device(dev); } return 0; } diff --git a/drivers/cpuidle/cpuidle-pseries.c b/drivers/cpuidle/cpuidle-pseries.c index 9e56bc4..a53be8a 100644 --- a/drivers/cpuidle/cpuidle-pseries.c +++ b/drivers/cpuidle/cpuidle-pseries.c @@ -193,6 +193,7 @@ static int pseries_cpuidle_cpu_online(unsigned int cpu) struct cpuidle_device *dev = per_cpu(cpuidle_devices, cpu); if (dev && cpuidle_get_driver()) { + cpuidle_register_device(dev); cpuidle_pause_and_lock(); cpuidle_enable_device(dev); cpuidle_resume_and_unlock(); @@ -208,6 +209,7 @@ static int pseries_cpuidle_cpu_dead(unsigned int cpu) cpuidle_pause_and_lock(); cpuidle_disable_device(dev); cpuidle_resume_and_unlock(); + cpuidle_unregister_device(dev); } return 0; } From patchwork Thu Aug 2 13:42:39 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pingfan Liu X-Patchwork-Id: 952739 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 41hBPw1LgCz9s3q for ; Thu, 2 Aug 2018 23:50:12 +1000 (AEST) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="lCPjdv6w"; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 41hBPv62s8zF2DG for ; Thu, 2 Aug 2018 23:50:11 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="lCPjdv6w"; dkim-atps=neutral X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::541; helo=mail-pg1-x541.google.com; envelope-from=kernelfans@gmail.com; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="lCPjdv6w"; dkim-atps=neutral Received: from mail-pg1-x541.google.com (mail-pg1-x541.google.com [IPv6:2607:f8b0:4864:20::541]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 41hBFg0XTmzF27H for ; Thu, 2 Aug 2018 23:43:02 +1000 (AEST) Received: by mail-pg1-x541.google.com with SMTP id h12-v6so1225309pgs.3 for ; Thu, 02 Aug 2018 06:43:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=qzPirI8N8zVst+x+skpD7tC+tAjwoNw5SknUHq6uZsc=; b=lCPjdv6wSrbf1OwRWLCH/DjgZgHvoCDnvoLzdBpQl/BOZfB4RIqy2sexvcGnk19btT a8QkWb9nSaXmgrN545kbwIiba7qFEGjf78aqGoV4Hs67u1GKjI52mnSS5NrEq+B8cCFL eLHYWKEnTXzRsnt3fUjE+a0xrEudiCj96O68xRnezcqtTJZb+9FaUjajwfg4GLDTVvzz rbdMYCn4NKHPd3oH/I2Y7lz4DPkRWk3T1sMMYfX4kL3UqJ0X3Efkin/4VEaXJjrnagDe 93ZtJsylHnQYTIVnYnuTvmV0wrtr+O9QAitqinDM+Oq7cvE4/JXxUgqjcmYJ3iObUAPJ lUWg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=qzPirI8N8zVst+x+skpD7tC+tAjwoNw5SknUHq6uZsc=; b=fjbH/2Sr4oLGuSGkBbQ496M/uxJNrMDB55lUxdSWNS0X/HnmtVP/470TXAtJ5La1pP xvoLYlGbIBcJujMFnChIfIytc6uDNy6H/KrHF0s7ovXr3OZavh2x29vD5jTeEihNDCJY ednzbdQgB8Rw+TeWoPvRislSxnqwehLXX32HAK1j0uMKRVjdHzSYeOUxJZlZ+gLvMCS6 Dzuq1oT9DOjsadPEf1W4aEuBRBK7zAwxYlijJOKDKPaELfoDGk7jBZHNUpvJhwOY/sfv 3xmZj4TSzgFmCrNf4UcdGBJX+CmSD8Nfxf15VpGUv/hL5R8DdmVhiAoHmezSQ7y4KA5K 8vIQ== X-Gm-Message-State: AOUpUlHEmr8ZdPVTc9BU4mtZaWtq3sXoqmqYS4EapS9efE8X6bhTDOBx NA8FC2KJZzghfydZOYZ+fAO/Z+0= X-Google-Smtp-Source: AAOMgpd3pa6orjAnP+jOUtOEUvgR7UDixClC2e4ua47ZDkGlJkbu8JNI6LveG/AqZLl9OXTliES8dA== X-Received: by 2002:a63:7a0a:: with SMTP id v10-v6mr2804865pgc.444.1533217380568; Thu, 02 Aug 2018 06:43:00 -0700 (PDT) Received: from mylaptop.redhat.com ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id m81-v6sm5664113pfa.188.2018.08.02.06.42.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 02 Aug 2018 06:42:59 -0700 (PDT) From: Pingfan Liu To: linuxppc-dev@lists.ozlabs.org Subject: [PATCH 2/2] powerpc/cpu: post the event cpux add/remove instead of online/offline during hotplug Date: Thu, 2 Aug 2018 21:42:39 +0800 Message-Id: <1533217359-11420-2-git-send-email-kernelfans@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1533217359-11420-1-git-send-email-kernelfans@gmail.com> References: <1533217359-11420-1-git-send-email-kernelfans@gmail.com> X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-pm@vger.kernel.org, "Rafael J. Wysocki" , Pingfan Liu , Tyrel Datwyler Errors-To: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" Technically speaking, echo 1/0 > cpuX/online is only a subset of cpu hotplug/unplug, i.e. add/remove. The latter one includes the physical adding/removing of a cpu device. Some user space tools such as kexec-tools resort to the event add/remove to automatically rebuild dtb. If the dtb is not rebuilt correctly, we may hang on 2nd kernel due to lack the info of boot-cpu-hwid in dtb. The steps to trigger the bug: (suppose 8 threads/core) drmgr -c cpu -r -q 1 systemctl restart kdump.service drmgr -c cpu -a -q 1 taskset -c 11 sh -c "echo c > /proc/sysrq-trigger" Then, failure info: [ 205.299528] SysRq : Trigger a crash [ 205.299551] Unable to handle kernel paging request for data at address 0x00000000 [ 205.299558] Faulting instruction address: 0xc0000000006001a0 [ 205.299564] Oops: Kernel access of bad area, sig: 11 [#1] [ 205.299569] SMP NR_CPUS=2048 NUMA pSeries [ 205.299575] Modules linked in: macsec sctp_diag sctp tcp_diag udp_diag inet_diag unix_diag af_packet_diag netlink_diag ip6t_rpfilter ipt_REJECT nf_reject_ipv4 ip6t_REJECT nf_reject_ipv6 xt_conntrack ip_set nfnetlink ebtable_nat ebtable_broute bridge stp llc ip6table_nat nf_conntrack_ipv6 nf_defrag_ipv6 nf_nat_ipv6 ip6table_mangle ip6table_security ip6table_raw iptable_nat nf_conntrack_ipv4 nf_defrag_ipv4 nf_nat_ipv4 nf_nat nf_conntrack iptable_mangle iptable_security iptable_raw ebtable_filter ebtables ip6table_filter ip6_tables iptable_filter xfs libcrc32c sg pseries_rng binfmt_misc ip_tables ext4 mbcache jbd2 sd_mod crc_t10dif crct10dif_generic crct10dif_common ibmvscsi scsi_transport_srp ibmveth scsi_tgt dm_mirror dm_region_hash dm_log dm_mod [ 205.299658] CPU: 11 PID: 2521 Comm: bash Not tainted 3.10.0-799.el7.ppc64le #1 [ 205.299664] task: c00000017bcd15e0 ti: c00000014f410000 task.ti: c00000014f410000 [ 205.299670] NIP: c0000000006001a0 LR: c000000000600ddc CTR: c000000000600180 [ 205.299676] REGS: c00000014f413a70 TRAP: 0300 Not tainted (3.10.0-799.el7.ppc64le) [ 205.299681] MSR: 8000000000009033 CR: 28222822 XER: 00000001 [ 205.299696] CFAR: c000000000009368 DAR: 0000000000000000 DSISR: 42000000 SOFTE: 1 GPR00: c000000000600dbc c00000014f413cf0 c000000001263200 0000000000000063 GPR04: c0000000019ca818 c0000000019db5f8 00000000000000c2 c00000000140aa30 GPR08: 0000000000000007 0000000000000001 0000000000000000 c00000000140fc60 GPR12: c000000000600180 c000000007b36300 0000000010139e58 0000000040000000 GPR16: 000000001013b5d0 0000000000000000 00000000101306fc 0000000010139de4 GPR20: 0000000010139de8 0000000010093150 0000000000000000 0000000000000000 GPR24: 000000001013b5e0 00000000100fa0e8 0000000000000007 c0000000011af1c8 GPR28: 0000000000000063 c0000000011af588 c000000001179ba8 0000000000000002 [ 205.299770] NIP [c0000000006001a0] sysrq_handle_crash+0x20/0x30 [ 205.299776] LR [c000000000600ddc] write_sysrq_trigger+0x10c/0x230 [ 205.299781] Call Trace: [ 205.299786] [c00000014f413cf0] [c000000000600dbc] write_sysrq_trigger+0xec/0x230 (unreliable) [ 205.299794] [c00000014f413d90] [c0000000003eb2c4] proc_reg_write+0x84/0x120 [ 205.299801] [c00000014f413dd0] [c000000000330a80] SyS_write+0x150/0x400 [ 205.299808] [c00000014f413e30] [c00000000000a184] system_call+0x38/0xb4 [ 205.299813] Instruction dump: [ 205.299816] 409effb8 7fc3f378 4bfff381 4bffffac 3c4c00c6 38423080 3d42fff1 394a6930 [ 205.299827] 39200001 912a0000 7c0004ac 39400000 <992a0000> 4e800020 60000000 60420000 [ 205.299838] ---[ end trace f590a5dbd3f63aab ]--- [ 205.301812] [ 205.301829] Sending IPI to other CPUs [ 205.302846] IPI complete I'm in purgatory -- > hang up here This patch uses the interface register_/unregister_cpu to fix the problem. Test the compatibility with ppc64_cpu on a powerKVM guest, with the following topo: Thread(s) per core: 8 Core(s) per socket: 2 Socket(s): 2 NUMA node(s): 1 and the following instructions: ppc64_cpu --smt=off drmgr -c cpu -r 1 drmgr -c cpu -a 1 ppc64_cpu --smt=on or drmgr -c cpu -r 1 ppc64_cpu --smt=off drmgr -c cpu -a 1 ppc64_cpu --smt=on Cc: Benjamin Herrenschmidt Cc: Michael Ellerman Cc: "Rafael J. Wysocki" Cc: Tyrel Datwyler Cc: linux-pm@vger.kernel.org Signed-off-by: Pingfan Liu --- v2 -> v3 create sysfs file "dev_attr_physical_id" before cpu online callbacks, hence it can work with ppc64_cpu --- arch/powerpc/include/asm/setup.h | 4 +++ arch/powerpc/include/asm/smp.h | 1 + arch/powerpc/kernel/sysfs.c | 38 +++++++++++++++++++++++----- arch/powerpc/platforms/pseries/hotplug-cpu.c | 16 +++++++++++- 4 files changed, 52 insertions(+), 7 deletions(-) diff --git a/arch/powerpc/include/asm/setup.h b/arch/powerpc/include/asm/setup.h index 8721fd0..e0597f2 100644 --- a/arch/powerpc/include/asm/setup.h +++ b/arch/powerpc/include/asm/setup.h @@ -40,6 +40,10 @@ static inline void pseries_big_endian_exceptions(void) {} static inline void pseries_little_endian_exceptions(void) {} #endif /* CONFIG_PPC_PSERIES */ +extern bool cpudev_is_dummy(int cpu); +extern int register_ppc_cpu(int cpu); +extern int unregister_ppc_cpu(int cpu); + void rfi_flush_enable(bool enable); /* These are bit flags */ diff --git a/arch/powerpc/include/asm/smp.h b/arch/powerpc/include/asm/smp.h index 29ffaab..344180a 100644 --- a/arch/powerpc/include/asm/smp.h +++ b/arch/powerpc/include/asm/smp.h @@ -36,6 +36,7 @@ extern u32 *cpu_to_phys_id; extern void cpu_die(void); extern int cpu_to_chip_id(int cpu); +DECLARE_PER_CPU(struct cpu, cpu_devices); #ifdef CONFIG_SMP struct smp_ops_t { diff --git a/arch/powerpc/kernel/sysfs.c b/arch/powerpc/kernel/sysfs.c index 755dc98..2f6c9f9 100644 --- a/arch/powerpc/kernel/sysfs.c +++ b/arch/powerpc/kernel/sysfs.c @@ -27,7 +27,7 @@ #include #endif -static DEFINE_PER_CPU(struct cpu, cpu_devices); +DEFINE_PER_CPU(struct cpu, cpu_devices); /* * SMT snooze delay stuff, 64-bit only for now @@ -1025,6 +1025,35 @@ static ssize_t show_physical_id(struct device *dev, } static DEVICE_ATTR(physical_id, 0444, show_physical_id, NULL); +/* unplugged cpu is true */ +bool cpudev_is_dummy(int cpu) +{ + struct cpu *c = &per_cpu(cpu_devices, cpu); + + return !kref_read(&c->dev.kobj.kref); +} + +/* create all files in sysfs, which can not be postponed till cpu online + * callbacks + */ +int register_ppc_cpu(int cpu) +{ + struct cpu *c = &per_cpu(cpu_devices, cpu); + + register_cpu(c, cpu); + device_create_file(&c->dev, &dev_attr_physical_id); + return 0; +} + +int unregister_ppc_cpu(int cpu) +{ + device_remove_file(&per_cpu(cpu_devices, cpu).dev, + &dev_attr_physical_id); + unregister_cpu(container_of(get_cpu_device(cpu), + struct cpu, dev)); + return 0; +} + static int __init topology_init(void) { int cpu, r; @@ -1044,11 +1073,8 @@ static int __init topology_init(void) if (ppc_md.cpu_die) c->hotpluggable = 1; - if (cpu_online(cpu) || c->hotpluggable) { - register_cpu(c, cpu); - - device_create_file(&c->dev, &dev_attr_physical_id); - } + if (cpu_online(cpu) || c->hotpluggable) + register_ppc_cpu(cpu); } r = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "powerpc/topology:online", register_cpu_online, unregister_cpu_online); diff --git a/arch/powerpc/platforms/pseries/hotplug-cpu.c b/arch/powerpc/platforms/pseries/hotplug-cpu.c index 6ef77ca..f361fc8 100644 --- a/arch/powerpc/platforms/pseries/hotplug-cpu.c +++ b/arch/powerpc/platforms/pseries/hotplug-cpu.c @@ -37,6 +37,7 @@ #include #include #include +#include #include "pseries.h" #include "offline_states.h" @@ -367,6 +368,11 @@ static int dlpar_online_cpu(struct device_node *dn) cpu_maps_update_done(); timed_topology_update(1); find_and_online_cpu_nid(cpu); + /* protect against the offline's failure, + * then re-online + */ + if (cpudev_is_dummy(cpu)) + register_ppc_cpu(cpu); rc = device_online(get_cpu_device(cpu)); if (rc) goto out; @@ -530,8 +536,12 @@ static int dlpar_offline_cpu(struct device_node *dn) if (get_hard_smp_processor_id(cpu) != thread) continue; - if (get_cpu_current_state(cpu) == CPU_STATE_OFFLINE) + if (get_cpu_current_state(cpu) == CPU_STATE_OFFLINE) { + cpu_maps_update_done(); + unregister_ppc_cpu(cpu); + cpu_maps_update_begin(); break; + } if (get_cpu_current_state(cpu) == CPU_STATE_ONLINE) { set_preferred_offline_state(cpu, @@ -541,6 +551,7 @@ static int dlpar_offline_cpu(struct device_node *dn) rc = device_offline(get_cpu_device(cpu)); if (rc) goto out; + unregister_ppc_cpu(cpu); cpu_maps_update_begin(); break; @@ -554,6 +565,9 @@ static int dlpar_offline_cpu(struct device_node *dn) BUG_ON(plpar_hcall_norets(H_PROD, thread) != H_SUCCESS); __cpu_die(cpu); + cpu_maps_update_done(); + unregister_ppc_cpu(cpu); + cpu_maps_update_begin(); break; } if (cpu == num_possible_cpus())