Skip to content

Commit

Permalink
Automatic merge of 'next' into merge (2024-06-24 12:09)
Browse files Browse the repository at this point in the history
  • Loading branch information
mpe committed Jun 24, 2024
2 parents e9a8aee + 932bed4 commit 18bc7f1
Show file tree
Hide file tree
Showing 8 changed files with 93 additions and 83 deletions.
1 change: 0 additions & 1 deletion arch/powerpc/configs/ppc6xx_defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ CONFIG_TASK_XACCT=y
CONFIG_TASK_IO_ACCOUNTING=y
CONFIG_CGROUPS=y
CONFIG_CGROUP_SCHED=y
CONFIG_RT_GROUP_SCHED=y
CONFIG_CGROUP_DEVICE=y
CONFIG_CGROUP_CPUACCT=y
CONFIG_USER_NS=y
Expand Down
6 changes: 2 additions & 4 deletions arch/powerpc/include/asm/kexec.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,8 @@ int load_crashdump_segments_ppc64(struct kimage *image,
int setup_purgatory_ppc64(struct kimage *image, const void *slave_code,
const void *fdt, unsigned long kernel_load_addr,
unsigned long fdt_load_addr);
unsigned int kexec_extra_fdt_size_ppc64(struct kimage *image);
int setup_new_fdt_ppc64(const struct kimage *image, void *fdt,
unsigned long initrd_load_addr,
unsigned long initrd_len, const char *cmdline);
unsigned int kexec_extra_fdt_size_ppc64(struct kimage *image, struct crash_mem *rmem);
int setup_new_fdt_ppc64(const struct kimage *image, void *fdt, struct crash_mem *rmem);
#endif /* CONFIG_PPC64 */

#endif /* CONFIG_KEXEC_FILE */
Expand Down
3 changes: 2 additions & 1 deletion arch/powerpc/include/asm/perf_event_server.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ struct power_pmu {
#define PPMU_NO_SIAR 0x00000100 /* Do not use SIAR */
#define PPMU_ARCH_31 0x00000200 /* Has MMCR3, SIER2 and SIER3 */
#define PPMU_P10_DD1 0x00000400 /* Is power10 DD1 processor version */
#define PPMU_HAS_ATTR_CONFIG1 0x00000800 /* Using config1 attribute */
#define PPMU_P10 0x00000800 /* For power10 pmu */
#define PPMU_HAS_ATTR_CONFIG1 0x00001000 /* Using config1 attribute */

/*
* Values for flags to get_alternatives()
Expand Down
53 changes: 37 additions & 16 deletions arch/powerpc/kexec/core_64.c
Original file line number Diff line number Diff line change
Expand Up @@ -456,9 +456,15 @@ static int add_node_props(void *fdt, int node_offset, const struct device_node *
* @fdt: Flattened device tree of the kernel.
*
* Returns 0 on success, negative errno on error.
*
* Note: expecting no subnodes under /cpus/<node> with device_type == "cpu".
* If this changes, update this function to include them.
*/
int update_cpus_node(void *fdt)
{
int prev_node_offset;
const char *device_type;
const struct fdt_property *prop;
struct device_node *cpus_node, *dn;
int cpus_offset, cpus_subnode_offset, ret = 0;

Expand All @@ -469,30 +475,44 @@ int update_cpus_node(void *fdt)
return cpus_offset;
}

if (cpus_offset > 0) {
ret = fdt_del_node(fdt, cpus_offset);
prev_node_offset = cpus_offset;
/* Delete sub-nodes of /cpus node with device_type == "cpu" */
for (cpus_subnode_offset = fdt_first_subnode(fdt, cpus_offset); cpus_subnode_offset >= 0;) {
/* Ignore nodes that do not have a device_type property or device_type != "cpu" */
prop = fdt_get_property(fdt, cpus_subnode_offset, "device_type", NULL);
if (!prop || strcmp(prop->data, "cpu")) {
prev_node_offset = cpus_subnode_offset;
goto next_node;
}

ret = fdt_del_node(fdt, cpus_subnode_offset);
if (ret < 0) {
pr_err("Error deleting /cpus node: %s\n", fdt_strerror(ret));
return -EINVAL;
pr_err("Failed to delete a cpus sub-node: %s\n", fdt_strerror(ret));
return ret;
}
next_node:
if (prev_node_offset == cpus_offset)
cpus_subnode_offset = fdt_first_subnode(fdt, cpus_offset);
else
cpus_subnode_offset = fdt_next_subnode(fdt, prev_node_offset);
}

/* Add cpus node to fdt */
cpus_offset = fdt_add_subnode(fdt, fdt_path_offset(fdt, "/"), "cpus");
if (cpus_offset < 0) {
pr_err("Error creating /cpus node: %s\n", fdt_strerror(cpus_offset));
cpus_node = of_find_node_by_path("/cpus");
/* Fail here to avoid kexec/kdump kernel boot hung */
if (!cpus_node) {
pr_err("No /cpus node found\n");
return -EINVAL;
}

/* Add cpus node properties */
cpus_node = of_find_node_by_path("/cpus");
ret = add_node_props(fdt, cpus_offset, cpus_node);
of_node_put(cpus_node);
if (ret < 0)
return ret;
/* Add all /cpus sub-nodes of device_type == "cpu" to FDT */
for_each_child_of_node(cpus_node, dn) {
/* Ignore device nodes that do not have a device_type property
* or device_type != "cpu".
*/
device_type = of_get_property(dn, "device_type", NULL);
if (!device_type || strcmp(device_type, "cpu"))
continue;

/* Loop through all subnodes of cpus and add them to fdt */
for_each_node_by_type(dn, "cpu") {
cpus_subnode_offset = fdt_add_subnode(fdt, cpus_offset, dn->full_name);
if (cpus_subnode_offset < 0) {
pr_err("Unable to add %s subnode: %s\n", dn->full_name,
Expand All @@ -506,6 +526,7 @@ int update_cpus_node(void *fdt)
goto out;
}
out:
of_node_put(cpus_node);
of_node_put(dn);
return ret;
}
Expand Down
12 changes: 9 additions & 3 deletions arch/powerpc/kexec/elf_64.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <linux/of_fdt.h>
#include <linux/slab.h>
#include <linux/types.h>
#include <asm/kexec_ranges.h>

static void *elf64_load(struct kimage *image, char *kernel_buf,
unsigned long kernel_len, char *initrd,
Expand All @@ -36,6 +37,7 @@ static void *elf64_load(struct kimage *image, char *kernel_buf,
const void *slave_code;
struct elfhdr ehdr;
char *modified_cmdline = NULL;
struct crash_mem *rmem = NULL;
struct kexec_elf_info elf_info;
struct kexec_buf kbuf = { .image = image, .buf_min = 0,
.buf_max = ppc64_rma_size };
Expand Down Expand Up @@ -102,17 +104,20 @@ static void *elf64_load(struct kimage *image, char *kernel_buf,
kexec_dprintk("Loaded initrd at 0x%lx\n", initrd_load_addr);
}

ret = get_reserved_memory_ranges(&rmem);
if (ret)
goto out;

fdt = of_kexec_alloc_and_setup_fdt(image, initrd_load_addr,
initrd_len, cmdline,
kexec_extra_fdt_size_ppc64(image));
kexec_extra_fdt_size_ppc64(image, rmem));
if (!fdt) {
pr_err("Error setting up the new device tree.\n");
ret = -EINVAL;
goto out;
}

ret = setup_new_fdt_ppc64(image, fdt, initrd_load_addr,
initrd_len, cmdline);
ret = setup_new_fdt_ppc64(image, fdt, rmem);
if (ret)
goto out_free_fdt;

Expand Down Expand Up @@ -146,6 +151,7 @@ static void *elf64_load(struct kimage *image, char *kernel_buf,
out_free_fdt:
kvfree(fdt);
out:
kfree(rmem);
kfree(modified_cmdline);
kexec_free_elf_info(&elf_info);

Expand Down
53 changes: 22 additions & 31 deletions arch/powerpc/kexec/file_load_64.c
Original file line number Diff line number Diff line change
Expand Up @@ -803,10 +803,9 @@ static unsigned int cpu_node_size(void)
return size;
}

static unsigned int kdump_extra_fdt_size_ppc64(struct kimage *image)
static unsigned int kdump_extra_fdt_size_ppc64(struct kimage *image, unsigned int cpu_nodes)
{
unsigned int cpu_nodes, extra_size = 0;
struct device_node *dn;
unsigned int extra_size = 0;
u64 usm_entries;
#ifdef CONFIG_CRASH_HOTPLUG
unsigned int possible_cpu_nodes;
Expand All @@ -826,18 +825,6 @@ static unsigned int kdump_extra_fdt_size_ppc64(struct kimage *image)
extra_size += (unsigned int)(usm_entries * sizeof(u64));
}

/*
* Get the number of CPU nodes in the current DT. This allows to
* reserve places for CPU nodes added since the boot time.
*/
cpu_nodes = 0;
for_each_node_by_type(dn, "cpu") {
cpu_nodes++;
}

if (cpu_nodes > boot_cpu_node_count)
extra_size += (cpu_nodes - boot_cpu_node_count) * cpu_node_size();

#ifdef CONFIG_CRASH_HOTPLUG
/*
* Make sure enough space is reserved to accommodate possible CPU nodes
Expand All @@ -861,16 +848,30 @@ static unsigned int kdump_extra_fdt_size_ppc64(struct kimage *image)
*
* Returns the estimated extra size needed for kexec/kdump kernel FDT.
*/
unsigned int kexec_extra_fdt_size_ppc64(struct kimage *image)
unsigned int kexec_extra_fdt_size_ppc64(struct kimage *image, struct crash_mem *rmem)
{
unsigned int extra_size = 0;
struct device_node *dn;
unsigned int cpu_nodes = 0, extra_size = 0;

// Budget some space for the password blob. There's already extra space
// for the key name
if (plpks_is_available())
extra_size += (unsigned int)plpks_get_passwordlen();

return extra_size + kdump_extra_fdt_size_ppc64(image);
/* Get the number of CPU nodes in the current device tree */
for_each_node_by_type(dn, "cpu") {
cpu_nodes++;
}

/* Consider extra space for CPU nodes added since the boot time */
if (cpu_nodes > boot_cpu_node_count)
extra_size += (cpu_nodes - boot_cpu_node_count) * cpu_node_size();

/* Consider extra space for reserved memory ranges if any */
if (rmem->nr_ranges > 0)
extra_size += sizeof(struct fdt_reserve_entry) * rmem->nr_ranges;

return extra_size + kdump_extra_fdt_size_ppc64(image, cpu_nodes);
}

static int copy_property(void *fdt, int node_offset, const struct device_node *dn,
Expand Down Expand Up @@ -924,18 +925,13 @@ static int update_pci_dma_nodes(void *fdt, const char *dmapropname)
* being loaded.
* @image: kexec image being loaded.
* @fdt: Flattened device tree for the next kernel.
* @initrd_load_addr: Address where the next initrd will be loaded.
* @initrd_len: Size of the next initrd, or 0 if there will be none.
* @cmdline: Command line for the next kernel, or NULL if there will
* be none.
* @rmem: Reserved memory ranges.
*
* Returns 0 on success, negative errno on error.
*/
int setup_new_fdt_ppc64(const struct kimage *image, void *fdt,
unsigned long initrd_load_addr,
unsigned long initrd_len, const char *cmdline)
int setup_new_fdt_ppc64(const struct kimage *image, void *fdt, struct crash_mem *rmem)
{
struct crash_mem *umem = NULL, *rmem = NULL;
struct crash_mem *umem = NULL;
int i, nr_ranges, ret;

#ifdef CONFIG_CRASH_DUMP
Expand Down Expand Up @@ -991,10 +987,6 @@ int setup_new_fdt_ppc64(const struct kimage *image, void *fdt,
goto out;

/* Update memory reserve map */
ret = get_reserved_memory_ranges(&rmem);
if (ret)
goto out;

nr_ranges = rmem ? rmem->nr_ranges : 0;
for (i = 0; i < nr_ranges; i++) {
u64 base, size;
Expand All @@ -1014,7 +1006,6 @@ int setup_new_fdt_ppc64(const struct kimage *image, void *fdt,
ret = plpks_populate_fdt(fdt);

out:
kfree(rmem);
kfree(umem);
return ret;
}
Expand Down
45 changes: 19 additions & 26 deletions arch/powerpc/perf/core-book3s.c
Original file line number Diff line number Diff line change
Expand Up @@ -266,51 +266,44 @@ static inline u32 perf_flags_from_msr(struct pt_regs *regs)
static inline u32 perf_get_misc_flags(struct pt_regs *regs)
{
bool use_siar = regs_use_siar(regs);
unsigned long mmcra = regs->dsisr;
int marked = mmcra & MMCRA_SAMPLE_ENABLE;
unsigned long siar;
unsigned long addr;

if (!use_siar)
return perf_flags_from_msr(regs);

/*
* Check the address in SIAR to identify the
* privilege levels since the SIER[MSR_HV, MSR_PR]
* bits are not set for marked events in power10
* DD1.
*/
if (marked && (ppmu->flags & PPMU_P10_DD1)) {
unsigned long siar = mfspr(SPRN_SIAR);
if (siar) {
if (is_kernel_addr(siar))
return PERF_RECORD_MISC_KERNEL;
return PERF_RECORD_MISC_USER;
} else {
if (is_kernel_addr(regs->nip))
return PERF_RECORD_MISC_KERNEL;
return PERF_RECORD_MISC_USER;
}
}

/*
* If we don't have flags in MMCRA, rather than using
* the MSR, we intuit the flags from the address in
* SIAR which should give slightly more reliable
* results
*/
if (ppmu->flags & PPMU_NO_SIPR) {
unsigned long siar = mfspr(SPRN_SIAR);
siar = mfspr(SPRN_SIAR);
if (is_kernel_addr(siar))
return PERF_RECORD_MISC_KERNEL;
return PERF_RECORD_MISC_USER;
}

/* PR has priority over HV, so order below is important */
if (regs_sipr(regs))
return PERF_RECORD_MISC_USER;

if (regs_sihv(regs) && (freeze_events_kernel != MMCR0_FCHV))
if (regs_sipr(regs)) {
if (!(ppmu->flags & PPMU_P10))
return PERF_RECORD_MISC_USER;
} else if (regs_sihv(regs) && (freeze_events_kernel != MMCR0_FCHV))
return PERF_RECORD_MISC_HYPERVISOR;

/*
* Check the address in SIAR to identify the
* privilege levels since the SIER[MSR_HV, MSR_PR]
* bits are not set correctly in power10 sometimes
*/
if (ppmu->flags & PPMU_P10) {
siar = mfspr(SPRN_SIAR);
addr = siar ? siar : regs->nip;
if (!is_kernel_addr(addr))
return PERF_RECORD_MISC_USER;
}

return PERF_RECORD_MISC_KERNEL;
}

Expand Down
3 changes: 2 additions & 1 deletion arch/powerpc/perf/power10-pmu.c
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,8 @@ static struct power_pmu power10_pmu = {
.get_mem_weight = isa207_get_mem_weight,
.disable_pmc = isa207_disable_pmc,
.flags = PPMU_HAS_SIER | PPMU_ARCH_207S |
PPMU_ARCH_31 | PPMU_HAS_ATTR_CONFIG1,
PPMU_ARCH_31 | PPMU_HAS_ATTR_CONFIG1 |
PPMU_P10,
.n_generic = ARRAY_SIZE(power10_generic_events),
.generic_events = power10_generic_events,
.cache_events = &power10_cache_events,
Expand Down

0 comments on commit 18bc7f1

Please sign in to comment.