Skip to content

Commit 999e2da

Browse files
nfontozbenh
authored andcommitted
powerpc/pseries: Create new device hotplug entry point
The current hotplug (or dlpar) of devices (the process is generally the same for memory, cpu, and pci) on PowerVM systems is initiated from the HMC, which communicates the request to the partitions through the RSCT framework. The RSCT framework then invokes the drmgr command. The drmgr command performs the hotplug operation by doing some pieces, such as most of the rtas calls and device tree parsing, in userspace and make requests to the kernel to online/offline the device, update the device tree and add/remove the device. For PowerKVM the approach for device hotplug is to follow what is currently being done for pci hotplug. A hotplug request is initiated from the host. QEMU then generates an EPOW interrupt to the guest which causes the guest to make the rtas,check-exception call. In QEMU, the rtas,check-exception call returns a rtas hotplug event to the guest. Please note that the current pci hotplug path for PowerKVM involves the kernel receiving the rtas hotplug event, passing it to rtas_errd in userspace, and having rtas_errd invoke drmgr. The drmgr command then handles the request as described above for PowerVM systems. There is no need for this circuitous route, we should just handle the entire hotplug of devices in the kernel. What I am planning is to enable this by moving the code to handle hotplug from drmgr into the kernel to provide a single path for handling device hotplug for both PowerVM and PowerKVM systems. This patch provides the common iframework and entry point. For PowerKVM a future update to the kernel rtas code will recognize rtas hotplug events returned from rtas,check-exception calls and use the common entry point to handle hotplug of the device. For PowerVM systems, This patch creates /sys/kernel/dlpar that can be used by the drmgr command to initiate hotplug requests. In order to do this a string of the format "<resource> <action> <id_type> <id>" is written to this file. The string consists of a resource (cpu, memory, pci, phb), an action (add or remove), an id_type (count, drc index, drc name), and the corresponding id. The kernel will parse the string and create a rtas hotplug section that can be passed to the common entry point for handling hotplug requests. It should be noted that there is no chance of updating how we receive hotplug (dlpar) requests from the HMC on PowerVM systems. Signed-off-by: Nathan Fontenot <[email protected]> Signed-off-by: Benjamin Herrenschmidt <[email protected]>
1 parent 5e51d3c commit 999e2da

File tree

3 files changed

+145
-2
lines changed

3 files changed

+145
-2
lines changed

arch/powerpc/platforms/pseries/dlpar.c

Lines changed: 116 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
* 2 as published by the Free Software Foundation.
1111
*/
1212

13+
#define pr_fmt(fmt) "dlpar: " fmt
14+
1315
#include <linux/kernel.h>
1416
#include <linux/notifier.h>
1517
#include <linux/spinlock.h>
@@ -535,13 +537,125 @@ static ssize_t dlpar_cpu_release(const char *buf, size_t count)
535537
return count;
536538
}
537539

540+
#endif /* CONFIG_ARCH_CPU_PROBE_RELEASE */
541+
542+
static int handle_dlpar_errorlog(struct pseries_hp_errorlog *hp_elog)
543+
{
544+
int rc;
545+
546+
/* pseries error logs are in BE format, convert to cpu type */
547+
switch (hp_elog->id_type) {
548+
case PSERIES_HP_ELOG_ID_DRC_COUNT:
549+
hp_elog->_drc_u.drc_count =
550+
be32_to_cpu(hp_elog->_drc_u.drc_count);
551+
break;
552+
case PSERIES_HP_ELOG_ID_DRC_INDEX:
553+
hp_elog->_drc_u.drc_index =
554+
be32_to_cpu(hp_elog->_drc_u.drc_index);
555+
}
556+
557+
switch (hp_elog->resource) {
558+
case PSERIES_HP_ELOG_RESOURCE_MEM:
559+
rc = dlpar_memory(hp_elog);
560+
break;
561+
default:
562+
pr_warn_ratelimited("Invalid resource (%d) specified\n",
563+
hp_elog->resource);
564+
rc = -EINVAL;
565+
}
566+
567+
return rc;
568+
}
569+
570+
static ssize_t dlpar_store(struct class *class, struct class_attribute *attr,
571+
const char *buf, size_t count)
572+
{
573+
struct pseries_hp_errorlog *hp_elog;
574+
const char *arg;
575+
int rc;
576+
577+
hp_elog = kzalloc(sizeof(*hp_elog), GFP_KERNEL);
578+
if (!hp_elog) {
579+
rc = -ENOMEM;
580+
goto dlpar_store_out;
581+
}
582+
583+
/* Parse out the request from the user, this will be in the form
584+
* <resource> <action> <id_type> <id>
585+
*/
586+
arg = buf;
587+
if (!strncmp(arg, "memory", 6)) {
588+
hp_elog->resource = PSERIES_HP_ELOG_RESOURCE_MEM;
589+
arg += strlen("memory ");
590+
} else {
591+
pr_err("Invalid resource specified: \"%s\"\n", buf);
592+
rc = -EINVAL;
593+
goto dlpar_store_out;
594+
}
595+
596+
if (!strncmp(arg, "add", 3)) {
597+
hp_elog->action = PSERIES_HP_ELOG_ACTION_ADD;
598+
arg += strlen("add ");
599+
} else if (!strncmp(arg, "remove", 6)) {
600+
hp_elog->action = PSERIES_HP_ELOG_ACTION_REMOVE;
601+
arg += strlen("remove ");
602+
} else {
603+
pr_err("Invalid action specified: \"%s\"\n", buf);
604+
rc = -EINVAL;
605+
goto dlpar_store_out;
606+
}
607+
608+
if (!strncmp(arg, "index", 5)) {
609+
u32 index;
610+
611+
hp_elog->id_type = PSERIES_HP_ELOG_ID_DRC_INDEX;
612+
arg += strlen("index ");
613+
if (kstrtou32(arg, 0, &index)) {
614+
rc = -EINVAL;
615+
pr_err("Invalid drc_index specified: \"%s\"\n", buf);
616+
goto dlpar_store_out;
617+
}
618+
619+
hp_elog->_drc_u.drc_index = cpu_to_be32(index);
620+
} else if (!strncmp(arg, "count", 5)) {
621+
u32 count;
622+
623+
hp_elog->id_type = PSERIES_HP_ELOG_ID_DRC_COUNT;
624+
arg += strlen("count ");
625+
if (kstrtou32(arg, 0, &count)) {
626+
rc = -EINVAL;
627+
pr_err("Invalid count specified: \"%s\"\n", buf);
628+
goto dlpar_store_out;
629+
}
630+
631+
hp_elog->_drc_u.drc_count = cpu_to_be32(count);
632+
} else {
633+
pr_err("Invalid id_type specified: \"%s\"\n", buf);
634+
rc = -EINVAL;
635+
goto dlpar_store_out;
636+
}
637+
638+
rc = handle_dlpar_errorlog(hp_elog);
639+
640+
dlpar_store_out:
641+
kfree(hp_elog);
642+
return rc ? rc : count;
643+
}
644+
645+
static CLASS_ATTR(dlpar, S_IWUSR, NULL, dlpar_store);
646+
538647
static int __init pseries_dlpar_init(void)
539648
{
649+
int rc;
650+
651+
#ifdef CONFIG_ARCH_CPU_PROBE_RELEASE
540652
ppc_md.cpu_probe = dlpar_cpu_probe;
541653
ppc_md.cpu_release = dlpar_cpu_release;
654+
#endif /* CONFIG_ARCH_CPU_PROBE_RELEASE */
542655

543-
return 0;
656+
rc = sysfs_create_file(kernel_kobj, &class_attr_dlpar.attr);
657+
658+
return rc;
544659
}
545660
machine_device_initcall(pseries, pseries_dlpar_init);
546661

547-
#endif /* CONFIG_ARCH_CPU_PROBE_RELEASE */

arch/powerpc/platforms/pseries/hotplug-memory.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
* 2 of the License, or (at your option) any later version.
1010
*/
1111

12+
#define pr_fmt(fmt) "pseries-hotplug-mem: " fmt
13+
1214
#include <linux/of.h>
1315
#include <linux/of_address.h>
1416
#include <linux/memblock.h>
@@ -134,6 +136,23 @@ static inline int pseries_remove_mem_node(struct device_node *np)
134136
}
135137
#endif /* CONFIG_MEMORY_HOTREMOVE */
136138

139+
int dlpar_memory(struct pseries_hp_errorlog *hp_elog)
140+
{
141+
int rc = 0;
142+
143+
lock_device_hotplug();
144+
145+
switch (hp_elog->action) {
146+
default:
147+
pr_err("Invalid action (%d) specified\n", hp_elog->action);
148+
rc = -EINVAL;
149+
break;
150+
}
151+
152+
unlock_device_hotplug();
153+
return rc;
154+
}
155+
137156
static int pseries_add_mem_node(struct device_node *np)
138157
{
139158
const char *type;

arch/powerpc/platforms/pseries/pseries.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#define _PSERIES_PSERIES_H
1212

1313
#include <linux/interrupt.h>
14+
#include <asm/rtas.h>
1415

1516
struct device_node;
1617

@@ -63,6 +64,15 @@ extern int dlpar_detach_node(struct device_node *);
6364
extern int dlpar_acquire_drc(u32 drc_index);
6465
extern int dlpar_release_drc(u32 drc_index);
6566

67+
#ifdef CONFIG_MEMORY_HOTPLUG
68+
int dlpar_memory(struct pseries_hp_errorlog *hp_elog);
69+
#else
70+
static inline int dlpar_memory(struct pseries_hp_errorlog *hp_elog)
71+
{
72+
return -EOPNOTSUPP;
73+
}
74+
#endif
75+
6676
/* PCI root bridge prepare function override for pseries */
6777
struct pci_host_bridge;
6878
int pseries_root_bridge_prepare(struct pci_host_bridge *bridge);

0 commit comments

Comments
 (0)