* [RFC PATCH 1/4] powerpc/pseries: Use macros for referring to the DTL enable mask
From: Naveen N. Rao @ 2018-09-19 8:08 UTC (permalink / raw)
To: Michael Ellerman, Nathan Fontenot, Michael Bringmann; +Cc: linuxppc-dev
In-Reply-To: <cover.1537343904.git.naveen.n.rao@linux.vnet.ibm.com>
Introduce macros to encode the DTL enable mask fields and use those
instead of hardcoding numbers.
Signed-off-by: Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com>
---
arch/powerpc/include/asm/lppaca.h | 11 +++++++++++
arch/powerpc/platforms/pseries/dtl.c | 8 +-------
arch/powerpc/platforms/pseries/lpar.c | 2 +-
arch/powerpc/platforms/pseries/setup.c | 2 +-
4 files changed, 14 insertions(+), 9 deletions(-)
diff --git a/arch/powerpc/include/asm/lppaca.h b/arch/powerpc/include/asm/lppaca.h
index 7c23ce8a5a4c..2c7e31187726 100644
--- a/arch/powerpc/include/asm/lppaca.h
+++ b/arch/powerpc/include/asm/lppaca.h
@@ -154,6 +154,17 @@ struct dtl_entry {
#define DISPATCH_LOG_BYTES 4096 /* bytes per cpu */
#define N_DISPATCH_LOG (DISPATCH_LOG_BYTES / sizeof(struct dtl_entry))
+/*
+ * Dispatch trace log event enable mask:
+ * 0x1: voluntary virtual processor waits
+ * 0x2: time-slice preempts
+ * 0x4: virtual partition memory page faults
+ */
+#define DTL_LOG_CEDE 0x1
+#define DTL_LOG_PREEMPT 0x2
+#define DTL_LOG_FAULT 0x4
+#define DTL_LOG_ALL (DTL_LOG_CEDE | DTL_LOG_PREEMPT | DTL_LOG_FAULT)
+
extern struct kmem_cache *dtl_cache;
/*
diff --git a/arch/powerpc/platforms/pseries/dtl.c b/arch/powerpc/platforms/pseries/dtl.c
index 18014cdeb590..e0421aa6eafa 100644
--- a/arch/powerpc/platforms/pseries/dtl.c
+++ b/arch/powerpc/platforms/pseries/dtl.c
@@ -40,13 +40,7 @@ struct dtl {
};
static DEFINE_PER_CPU(struct dtl, cpu_dtl);
-/*
- * Dispatch trace log event mask:
- * 0x7: 0x1: voluntary virtual processor waits
- * 0x2: time-slice preempts
- * 0x4: virtual partition memory page faults
- */
-static u8 dtl_event_mask = 0x7;
+static u8 dtl_event_mask = DTL_LOG_ALL;
/*
diff --git a/arch/powerpc/platforms/pseries/lpar.c b/arch/powerpc/platforms/pseries/lpar.c
index d3992ced0782..dd024a192512 100644
--- a/arch/powerpc/platforms/pseries/lpar.c
+++ b/arch/powerpc/platforms/pseries/lpar.c
@@ -125,7 +125,7 @@ void vpa_init(int cpu)
pr_err("WARNING: DTL registration of cpu %d (hw %d) "
"failed with %ld\n", smp_processor_id(),
hwcpu, ret);
- lppaca_of(cpu).dtl_enable_mask = 2;
+ lppaca_of(cpu).dtl_enable_mask = DTL_LOG_PREEMPT;
}
}
diff --git a/arch/powerpc/platforms/pseries/setup.c b/arch/powerpc/platforms/pseries/setup.c
index ba1791fd3234..a48cb9757be2 100644
--- a/arch/powerpc/platforms/pseries/setup.c
+++ b/arch/powerpc/platforms/pseries/setup.c
@@ -293,7 +293,7 @@ static int alloc_dispatch_logs(void)
pr_err("WARNING: DTL registration of cpu %d (hw %d) failed "
"with %d\n", smp_processor_id(),
hard_smp_processor_id(), ret);
- get_paca()->lppaca_ptr->dtl_enable_mask = 2;
+ get_paca()->lppaca_ptr->dtl_enable_mask = DTL_LOG_PREEMPT;
return 0;
}
--
2.18.0
^ permalink raw reply related
* [RFC PATCH 0/4] Add a tracepoint for DTL entries
From: Naveen N. Rao @ 2018-09-19 8:08 UTC (permalink / raw)
To: Michael Ellerman, Nathan Fontenot, Michael Bringmann; +Cc: linuxppc-dev
Add a tracepoint for the DTL entries to enable processing the DTL
entries via the kernel tracing infrastructure. In addition to that, the
tracpoint also exposes where a vcpu was dispatched in a SPLPAR
environment, relative to the Power Hypervisor's idea of that vcpu's home
node.
This is working fine for me, so posting this out to get some early
feedback. The one aspect I need to look into is in terms of updating the
pcpu associativity masks on appropriate events.
- Naveen
Naveen N. Rao (4):
powerpc/pseries: Use macros for referring to the DTL enable mask
powerpc/pseries: Do not save the previous DTL mask value
powerpc/pseries: Introduce helpers to change the DTL enable mask
powerpc/pseries: Introduce dtl_entry tracepoint
arch/powerpc/include/asm/lppaca.h | 15 ++++
arch/powerpc/include/asm/trace.h | 53 +++++++++++++++
arch/powerpc/kernel/time.c | 9 +++
arch/powerpc/mm/numa.c | 94 ++++++++++++++++++++++++--
arch/powerpc/platforms/pseries/dtl.c | 15 ++--
arch/powerpc/platforms/pseries/lpar.c | 64 +++++++++++++++++-
arch/powerpc/platforms/pseries/setup.c | 2 +-
7 files changed, 233 insertions(+), 19 deletions(-)
--
2.18.0
^ permalink raw reply
* [RFC PATCH 2/4] powerpc/pseries: Do not save the previous DTL mask value
From: Naveen N. Rao @ 2018-09-19 8:08 UTC (permalink / raw)
To: Michael Ellerman, Nathan Fontenot, Michael Bringmann; +Cc: linuxppc-dev
In-Reply-To: <cover.1537343904.git.naveen.n.rao@linux.vnet.ibm.com>
When CONFIG_VIRT_CPU_ACCOUNTING_NATIVE is enabled, we always initialize
DTL enable mask to DTL_LOG_PREEMPT (0x2). There are no other places
where the mask is changed. As such, when reading the DTL log buffer
through debugfs, there is no need to save and restore the previous mask
value.
We don't need to save and restore the earlier mask value if
CONFIG_VIRT_CPU_ACCOUNTING_NATIVE is not enabled. So, remove the field
from the structure as well.
Signed-off-by: Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com>
---
arch/powerpc/platforms/pseries/dtl.c | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/arch/powerpc/platforms/pseries/dtl.c b/arch/powerpc/platforms/pseries/dtl.c
index e0421aa6eafa..fe333c2525fb 100644
--- a/arch/powerpc/platforms/pseries/dtl.c
+++ b/arch/powerpc/platforms/pseries/dtl.c
@@ -55,7 +55,6 @@ struct dtl_ring {
struct dtl_entry *write_ptr;
struct dtl_entry *buf;
struct dtl_entry *buf_end;
- u8 saved_dtl_mask;
};
static DEFINE_PER_CPU(struct dtl_ring, dtl_rings);
@@ -105,7 +104,6 @@ static int dtl_start(struct dtl *dtl)
dtlr->write_ptr = dtl->buf;
/* enable event logging */
- dtlr->saved_dtl_mask = lppaca_of(dtl->cpu).dtl_enable_mask;
lppaca_of(dtl->cpu).dtl_enable_mask |= dtl_event_mask;
dtl_consumer = consume_dtle;
@@ -123,7 +121,7 @@ static void dtl_stop(struct dtl *dtl)
dtlr->buf = NULL;
/* restore dtl_enable_mask */
- lppaca_of(dtl->cpu).dtl_enable_mask = dtlr->saved_dtl_mask;
+ lppaca_of(dtl->cpu).dtl_enable_mask = DTL_LOG_PREEMPT;
if (atomic_dec_and_test(&dtl_count))
dtl_consumer = NULL;
--
2.18.0
^ permalink raw reply related
* [RFC PATCH 4/4] powerpc/pseries: Introduce dtl_entry tracepoint
From: Naveen N. Rao @ 2018-09-19 8:08 UTC (permalink / raw)
To: Michael Ellerman, Nathan Fontenot, Michael Bringmann; +Cc: linuxppc-dev
In-Reply-To: <cover.1537343904.git.naveen.n.rao@linux.vnet.ibm.com>
This tracepoint provides access to the fields of each DTL entry in the
Dispatch Trace Log buffer, and is hit when processing the DTL buffer for
accounting stolen time. As such, this tracepoint is only available when
CONFIG_VIRT_CPU_ACCOUNTING_NATIVE is enabled.
Apart from making the DTL entries available for processing through the
usual trace interface, this tracepoint also adds a new field 'distance'
to each DTL entry, enabling enhanced statistics around the vcpu dispatch
behavior of the hypervisor.
For Shared Processor LPARs, the POWER Hypervisor maintains a relatively
static mapping of LPAR vcpus to physical processor cores and tries to
always dispatch vcpus on their associated physical processor core. The
LPAR can discover this through the H_VPHN(flags=1) hcall to obtain the
associativity of the LPAR vcpus.
However, under certain scenarios, vcpus may be dispatched on a different
processor core. The actual physical processor number on which a certain
vcpu is dispatched is available to the LPAR in the 'processor_id' field
of each DTL entry. The LPAR can then discover the associativity of that
physical processor through the H_VPHN(flags=2) hcall. This can then be
compared to the home node associativity for that specific vcpu to
determine if the vcpu was dispatched on the same core or not. If the
vcpu was not dispatched on the home node, it is possible to determine if
the vcpu was dispatched in a different chip, socket or drawer.
The tracepoint field 'distance' encodes this information. If distance is
0, then the vcpu was dispatched on its home node. If not, increasing
values of 'distance' indicate a dispatch on a different core in the same
chip, different chip in a DCM, different socket or a different drawer.
Signed-off-by: Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com>
---
arch/powerpc/include/asm/trace.h | 53 ++++++++++++++++++
arch/powerpc/kernel/time.c | 9 +++
arch/powerpc/mm/numa.c | 94 ++++++++++++++++++++++++++++++--
3 files changed, 150 insertions(+), 6 deletions(-)
diff --git a/arch/powerpc/include/asm/trace.h b/arch/powerpc/include/asm/trace.h
index d018e8602694..27ccb2c8afc3 100644
--- a/arch/powerpc/include/asm/trace.h
+++ b/arch/powerpc/include/asm/trace.h
@@ -101,6 +101,59 @@ TRACE_EVENT_FN_COND(hcall_exit,
hcall_tracepoint_regfunc, hcall_tracepoint_unregfunc
);
+
+extern int dtl_entry_tracepoint_regfunc(void);
+extern void dtl_entry_tracepoint_unregfunc(void);
+extern u8 compute_dispatch_distance(unsigned int pcpu);
+
+TRACE_EVENT_FN(dtl_entry,
+
+ TP_PROTO(u8 dispatch_reason, u8 preempt_reason, u16 processor_id,
+ u32 enqueue_to_dispatch_time, u32 ready_to_enqueue_time,
+ u32 waiting_to_ready_time, u64 timebase, u64 fault_addr,
+ u64 srr0, u64 srr1),
+
+ TP_ARGS(dispatch_reason, preempt_reason, processor_id,
+ enqueue_to_dispatch_time, ready_to_enqueue_time,
+ waiting_to_ready_time, timebase, fault_addr,
+ srr0, srr1),
+
+ TP_STRUCT__entry(
+ __field(u8, dispatch_reason)
+ __field(u8, preempt_reason)
+ __field(u16, processor_id)
+ __field(u32, enqueue_to_dispatch_time)
+ __field(u32, ready_to_enqueue_time)
+ __field(u32, waiting_to_ready_time)
+ __field(u64, timebase)
+ __field(u64, fault_addr)
+ __field(u64, srr0)
+ __field(u64, srr1)
+ __field(u8, distance)
+ ),
+
+ TP_fast_assign(
+ __entry->dispatch_reason = dispatch_reason;
+ __entry->preempt_reason = preempt_reason;
+ __entry->processor_id = processor_id;
+ __entry->enqueue_to_dispatch_time = enqueue_to_dispatch_time;
+ __entry->ready_to_enqueue_time = ready_to_enqueue_time;
+ __entry->waiting_to_ready_time = waiting_to_ready_time;
+ __entry->timebase = timebase;
+ __entry->fault_addr = fault_addr;
+ __entry->srr0 = srr0;
+ __entry->srr1 = srr1;
+ __entry->distance = compute_dispatch_distance(processor_id);
+ ),
+
+ TP_printk("dispatch_reason=%u preempt_reason=%u processor_id=%u enq_to_disp=%u ready_to_enq=%u wait_to_ready=%u tb=%llu fault_addr=0x%llx srr0=0x%llx srr1=0x%llx distance=%u",
+ __entry->dispatch_reason, __entry->preempt_reason, __entry->processor_id,
+ __entry->enqueue_to_dispatch_time, __entry->ready_to_enqueue_time,
+ __entry->waiting_to_ready_time, __entry->timebase, __entry->fault_addr,
+ __entry->srr0, __entry->srr1, __entry->distance),
+
+ dtl_entry_tracepoint_regfunc, dtl_entry_tracepoint_unregfunc
+);
#endif
#ifdef CONFIG_PPC_POWERNV
diff --git a/arch/powerpc/kernel/time.c b/arch/powerpc/kernel/time.c
index 70f145e02487..94802fc22521 100644
--- a/arch/powerpc/kernel/time.c
+++ b/arch/powerpc/kernel/time.c
@@ -220,6 +220,15 @@ static u64 scan_dispatch_log(u64 stop_tb)
break;
if (dtl_consumer)
dtl_consumer(dtl, i);
+ trace_dtl_entry(dtl->dispatch_reason, dtl->preempt_reason,
+ be16_to_cpu(dtl->processor_id),
+ be32_to_cpu(dtl->enqueue_to_dispatch_time),
+ be32_to_cpu(dtl->ready_to_enqueue_time),
+ be32_to_cpu(dtl->waiting_to_ready_time),
+ be64_to_cpu(dtl->timebase),
+ be64_to_cpu(dtl->fault_addr),
+ be64_to_cpu(dtl->srr0),
+ be64_to_cpu(dtl->srr1));
stolen += tb_delta;
++i;
++dtl;
diff --git a/arch/powerpc/mm/numa.c b/arch/powerpc/mm/numa.c
index 35ac5422903a..b3fcdf6a8b4a 100644
--- a/arch/powerpc/mm/numa.c
+++ b/arch/powerpc/mm/numa.c
@@ -41,6 +41,7 @@
#include <asm/setup.h>
#include <asm/vdso.h>
#include <asm/drmem.h>
+#include <asm/trace.h>
static int numa_enabled = 1;
@@ -1078,6 +1079,9 @@ static int prrn_enabled;
static void reset_topology_timer(void);
static int topology_timer_secs = 1;
static int topology_inited;
+static __be32 vcpu_associativity[NR_CPUS][VPHN_ASSOC_BUFSIZE];
+static __be32 pcpu_associativity[NR_CPUS][VPHN_ASSOC_BUFSIZE];
+static unsigned int associativity_depth;
/*
* Change polling interval for associativity changes.
@@ -1157,14 +1161,12 @@ static int update_cpu_associativity_changes_mask(void)
* Retrieve the new associativity information for a virtual processor's
* home node.
*/
-static long hcall_vphn(unsigned long cpu, __be32 *associativity)
+static long hcall_vphn(unsigned long cpu, unsigned long flags, __be32 *associativity)
{
long rc;
long retbuf[PLPAR_HCALL9_BUFSIZE] = {0};
- u64 flags = 1;
- int hwcpu = get_hard_smp_processor_id(cpu);
- rc = plpar_hcall9(H_HOME_NODE_ASSOCIATIVITY, retbuf, flags, hwcpu);
+ rc = plpar_hcall9(H_HOME_NODE_ASSOCIATIVITY, retbuf, flags, cpu);
vphn_unpack_associativity(retbuf, associativity);
return rc;
@@ -1175,7 +1177,7 @@ static long vphn_get_associativity(unsigned long cpu,
{
long rc;
- rc = hcall_vphn(cpu, associativity);
+ rc = hcall_vphn(get_hard_smp_processor_id(cpu), 1, associativity);
switch (rc) {
case H_FUNCTION:
@@ -1200,7 +1202,7 @@ static long vphn_get_associativity(unsigned long cpu,
int find_and_online_cpu_nid(int cpu)
{
- __be32 associativity[VPHN_ASSOC_BUFSIZE] = {0};
+ __be32 *associativity = vcpu_associativity[cpu];
int new_nid;
/* Use associativity from first thread for all siblings */
@@ -1234,6 +1236,86 @@ int find_and_online_cpu_nid(int cpu)
return new_nid;
}
+static unsigned int find_possible_pcpus(void)
+{
+ struct device_node *rtas;
+ unsigned int max_depth, num_pcpus = 0;
+
+ rtas = of_find_node_by_path("/rtas");
+ if (min_common_depth <= 0 || !rtas)
+ return 0;
+
+ if (!of_property_read_u32(rtas,
+ "ibm,max-associativity-domains",
+ &max_depth))
+ of_property_read_u32_index(rtas,
+ "ibm,max-associativity-domains",
+ max_depth, &num_pcpus);
+
+ of_node_put(rtas);
+
+ return num_pcpus;
+}
+
+int dtl_entry_tracepoint_regfunc(void)
+{
+ unsigned int i, num_pcpus, pcpu_associativity_depth = 0;
+ long rc;
+
+ num_pcpus = find_possible_pcpus();
+ if (num_pcpus <= 0)
+ num_pcpus = NR_CPUS;
+ else
+ /*
+ * The OF property reports the maximum cpu number.
+ * We instead want the maximum number of cpus.
+ */
+ num_pcpus++;
+
+ for (i = 0; i < NR_CPUS; i++) {
+ pcpu_associativity[i][0] = NR_CPUS;
+ if (i < num_pcpus && vphn_enabled) {
+ rc = hcall_vphn(i, 2, pcpu_associativity[i]);
+ if (!pcpu_associativity_depth && rc == H_SUCCESS)
+ pcpu_associativity_depth = pcpu_associativity[i][0];
+ }
+ }
+
+ if (vphn_enabled)
+ associativity_depth = min(pcpu_associativity_depth,
+ vcpu_associativity[smp_processor_id()][0]);
+
+ if (set_dtl_mask(-1, DTL_LOG_ALL))
+ return -EBUSY;
+
+ return 0;
+}
+
+void dtl_entry_tracepoint_unregfunc(void)
+{
+ reset_dtl_mask(-1);
+}
+
+u8 compute_dispatch_distance(unsigned int pcpu)
+{
+ __be32 *pcpu_assoc, *vcpu_assoc;
+ unsigned int i, distance = associativity_depth;
+
+ vcpu_assoc = vcpu_associativity[smp_processor_id()];
+ pcpu_assoc = pcpu_associativity[pcpu];
+
+ if (!vphn_enabled || pcpu_assoc[0] == NR_CPUS)
+ return 255;
+
+ for (i = 1; i <= associativity_depth; i++)
+ if (vcpu_assoc[i] == pcpu_assoc[i])
+ distance--;
+ else
+ break;
+
+ return distance;
+}
+
/*
* Update the CPU maps and sysfs entries for a single CPU when its NUMA
* characteristics change. This function doesn't perform any locking and is
--
2.18.0
^ permalink raw reply related
* Re: [RFC PATCH 03/29] mm: remove CONFIG_HAVE_MEMBLOCK
From: Jonathan Cameron @ 2018-09-19 9:04 UTC (permalink / raw)
To: Mike Rapoport
Cc: linux-mm, Andrew Morton, David S. Miller, Greg Kroah-Hartman,
Ingo Molnar, Michael Ellerman, Michal Hocko, Paul Burton,
Thomas Gleixner, Tony Luck, linux-ia64, linux-mips, linuxppc-dev,
sparclinux, linux-kernel, linuxarm
In-Reply-To: <1536163184-26356-4-git-send-email-rppt@linux.vnet.ibm.com>
On Wed, 5 Sep 2018 18:59:18 +0300
Mike Rapoport <rppt@linux.vnet.ibm.com> wrote:
> All architecures use memblock for early memory management. There is no need
> for the CONFIG_HAVE_MEMBLOCK configuration option.
>
> Signed-off-by: Mike Rapoport <rppt@linux.vnet.ibm.com>
Hi Mike,
A minor editing issue in here that is stopping boot on arm64 platforms with latest
version of the mm tree.
> diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c
> index 76c83c1..bd841bb 100644
> --- a/drivers/of/fdt.c
> +++ b/drivers/of/fdt.c
> @@ -1115,13 +1115,11 @@ int __init early_init_dt_scan_chosen(unsigned long node, const char *uname,
> return 1;
> }
>
> -#ifdef CONFIG_HAVE_MEMBLOCK
> #ifndef MIN_MEMBLOCK_ADDR
> #define MIN_MEMBLOCK_ADDR __pa(PAGE_OFFSET)
> #endif
> #ifndef MAX_MEMBLOCK_ADDR
> #define MAX_MEMBLOCK_ADDR ((phys_addr_t)~0)
> -#endif
This isn't the right #endif. It is matching with the #ifndef MAX_MEMBLOCK_ADDR
not the intented #ifdef CONFIG_HAVE_MEMBLOCK.
Now I haven't chased through the exact reason this is causing my acpi
arm64 system not to boot on the basis it is obviously miss-matched anyway
and I'm inherently lazy. It's resulting in stubs replacing the following weak
functions.
early_init_dt_add_memory_arch
(this is defined elsewhere for some architectures but not arm)
early_init_dt_mark_hotplug_memory_arch
(there is only one definition of this in the kernel so it doesn't
need to be weak or in the header etc).
early_init_dt_reserve_memory_arch
(defined on mips but nothing else)
Taking out the right endif also lets you drop an #else removing some stub
functions further down in here.
Nice cleanup in general btw.
Thanks,
Jonathan
>
> void __init __weak early_init_dt_add_memory_arch(u64 base, u64 size)
> {
^ permalink raw reply
* [RFC PATCH 3/4] powerpc/pseries: Introduce helpers to change the DTL enable mask
From: Naveen N. Rao @ 2018-09-19 8:08 UTC (permalink / raw)
To: Michael Ellerman, Nathan Fontenot, Michael Bringmann; +Cc: linuxppc-dev
In-Reply-To: <cover.1537343904.git.naveen.n.rao@linux.vnet.ibm.com>
In a subsequent patch, we want to be able to change the DTL enable mask
globally for all cpus. This conflicts with the current debugfs interface
that provides access to the DTL buffer contents.
To ensure consistent behavior, we introduce helpers to change the DTL
enable mask on either a specific cpu, or globally for all cpus. Setting
the DTL enable mask globally prevents changes to cpu-specific DTL enable
mask, and vice versa. We also introduce 'dtl_mask' so that when the DTL
enable mask is changed globally, new cpus also honor that.
Signed-off-by: Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com>
---
arch/powerpc/include/asm/lppaca.h | 4 ++
arch/powerpc/platforms/pseries/dtl.c | 5 +-
arch/powerpc/platforms/pseries/lpar.c | 64 +++++++++++++++++++++++++-
arch/powerpc/platforms/pseries/setup.c | 2 +-
4 files changed, 71 insertions(+), 4 deletions(-)
diff --git a/arch/powerpc/include/asm/lppaca.h b/arch/powerpc/include/asm/lppaca.h
index 2c7e31187726..144862f86392 100644
--- a/arch/powerpc/include/asm/lppaca.h
+++ b/arch/powerpc/include/asm/lppaca.h
@@ -165,6 +165,10 @@ struct dtl_entry {
#define DTL_LOG_FAULT 0x4
#define DTL_LOG_ALL (DTL_LOG_CEDE | DTL_LOG_PREEMPT | DTL_LOG_FAULT)
+extern u8 dtl_mask;
+int set_dtl_mask(int cpu, int mask);
+void reset_dtl_mask(int cpu);
+
extern struct kmem_cache *dtl_cache;
/*
diff --git a/arch/powerpc/platforms/pseries/dtl.c b/arch/powerpc/platforms/pseries/dtl.c
index fe333c2525fb..3b98fc19c53f 100644
--- a/arch/powerpc/platforms/pseries/dtl.c
+++ b/arch/powerpc/platforms/pseries/dtl.c
@@ -104,7 +104,8 @@ static int dtl_start(struct dtl *dtl)
dtlr->write_ptr = dtl->buf;
/* enable event logging */
- lppaca_of(dtl->cpu).dtl_enable_mask |= dtl_event_mask;
+ if (set_dtl_mask(dtl->cpu, dtl_event_mask))
+ return -EBUSY;
dtl_consumer = consume_dtle;
atomic_inc(&dtl_count);
@@ -121,7 +122,7 @@ static void dtl_stop(struct dtl *dtl)
dtlr->buf = NULL;
/* restore dtl_enable_mask */
- lppaca_of(dtl->cpu).dtl_enable_mask = DTL_LOG_PREEMPT;
+ reset_dtl_mask(dtl->cpu);
if (atomic_dec_and_test(&dtl_count))
dtl_consumer = NULL;
diff --git a/arch/powerpc/platforms/pseries/lpar.c b/arch/powerpc/platforms/pseries/lpar.c
index dd024a192512..6563e7a782a3 100644
--- a/arch/powerpc/platforms/pseries/lpar.c
+++ b/arch/powerpc/platforms/pseries/lpar.c
@@ -58,12 +58,74 @@
#define HBR_AVPN 0x0200000000000000UL
#define HBR_ANDCOND 0x0100000000000000UL
+u8 dtl_mask = DTL_LOG_PREEMPT;
+static u8 dtl_mask_global_refctr, dtl_mask_percpu_inuse;
+static DEFINE_MUTEX(dtl_mask_mutex);
/* in hvCall.S */
EXPORT_SYMBOL(plpar_hcall);
EXPORT_SYMBOL(plpar_hcall9);
EXPORT_SYMBOL(plpar_hcall_norets);
+int set_dtl_mask(int cpu, int mask)
+{
+ int rc = 0;
+
+ mutex_lock(&dtl_mask_mutex);
+
+ if ((cpu == -1 && dtl_mask_percpu_inuse) ||
+ (cpu >= 0 && dtl_mask_global_refctr)) {
+ rc = -1;
+ goto out;
+ }
+
+ if (cpu >= 0) {
+ dtl_mask_percpu_inuse++;
+ lppaca_of(cpu).dtl_enable_mask = mask;
+ goto out;
+ }
+
+ if (dtl_mask_global_refctr && mask != dtl_mask) {
+ rc = -1;
+ goto out;
+ }
+
+ if (!dtl_mask_global_refctr) {
+ dtl_mask = mask;
+ for_each_present_cpu(cpu)
+ lppaca_of(cpu).dtl_enable_mask = mask;
+ }
+
+ dtl_mask_global_refctr++;
+
+out:
+ mutex_unlock(&dtl_mask_mutex);
+
+ return rc;
+}
+
+void reset_dtl_mask(int cpu)
+{
+ mutex_lock(&dtl_mask_mutex);
+
+ if (cpu >= 0) {
+ dtl_mask_percpu_inuse--;
+ lppaca_of(cpu).dtl_enable_mask = DTL_LOG_PREEMPT;
+ goto out;
+ }
+
+ dtl_mask_global_refctr--;
+
+ if (!dtl_mask_global_refctr) {
+ dtl_mask = DTL_LOG_PREEMPT;
+ for_each_present_cpu(cpu)
+ lppaca_of(cpu).dtl_enable_mask = dtl_mask;
+ }
+
+out:
+ mutex_unlock(&dtl_mask_mutex);
+}
+
void vpa_init(int cpu)
{
int hwcpu = get_hard_smp_processor_id(cpu);
@@ -125,7 +187,7 @@ void vpa_init(int cpu)
pr_err("WARNING: DTL registration of cpu %d (hw %d) "
"failed with %ld\n", smp_processor_id(),
hwcpu, ret);
- lppaca_of(cpu).dtl_enable_mask = DTL_LOG_PREEMPT;
+ lppaca_of(cpu).dtl_enable_mask = dtl_mask;
}
}
diff --git a/arch/powerpc/platforms/pseries/setup.c b/arch/powerpc/platforms/pseries/setup.c
index a48cb9757be2..285a35f32d3d 100644
--- a/arch/powerpc/platforms/pseries/setup.c
+++ b/arch/powerpc/platforms/pseries/setup.c
@@ -293,7 +293,7 @@ static int alloc_dispatch_logs(void)
pr_err("WARNING: DTL registration of cpu %d (hw %d) failed "
"with %d\n", smp_processor_id(),
hard_smp_processor_id(), ret);
- get_paca()->lppaca_ptr->dtl_enable_mask = DTL_LOG_PREEMPT;
+ get_paca()->lppaca_ptr->dtl_enable_mask = dtl_mask;
return 0;
}
--
2.18.0
^ permalink raw reply related
* How to define some additional KBUILD_CFLAGS after building include/generated/asm-offsets.h ?
From: Christophe Leroy @ 2018-09-18 23:41 UTC (permalink / raw)
To: linuxppc-dev, linux-kbuild, Masahiro Yamada, Michal Marek,
Segher Boessenkool
Cc: LKML
I'm trying to implement TLS based stack protector in the Linux Kernel.
For that I need to give to GCC the offset at which it will find the
canary (register r2 is pointing to the current task struct).
I have been able to do it with the below patch, but it only works when
include/generated/asm-offsets.h already exists from the start of the build.
Is there a way to evaluate CANARY_OFFSET and add the stack-protector
flags to KBUILD_FLAGS only after include/generated/asm-offsets.h is built ?
Or another way of add -mstack-protector-guard-offset=offsetof(struct
task_struct, stack_canary) ?
diff --git a/arch/powerpc/kernel/asm-offsets.c
b/arch/powerpc/kernel/asm-offsets.c
index 89cf15566c4e..b25483946921 100644
--- a/arch/powerpc/kernel/asm-offsets.c
+++ b/arch/powerpc/kernel/asm-offsets.c
@@ -89,6 +89,9 @@ int main(void)
DEFINE(THREAD_INFO_GAP, _ALIGN_UP(sizeof(struct thread_info), 16));
OFFSET(KSP_LIMIT, thread_struct, ksp_limit);
#endif /* CONFIG_PPC64 */
+#ifdef CONFIG_STACKPROTECTOR
+ DEFINE(TSK_STACK_CANARY, offsetof(struct task_struct,
stack_canary));
+#endif
#ifdef CONFIG_LIVEPATCH
OFFSET(TI_livepatch_sp, thread_info, livepatch_sp);
diff --git a/arch/powerpc/kernel/entry_32.S b/arch/powerpc/kernel/entry_32.S
index e58c3f467db5..051b907b5c02 100644
[root@pc16082vm linux-powerpc]# git diff
diff --git a/arch/powerpc/Makefile b/arch/powerpc/Makefile
index 748e34e81a03..7b5a23a8afe8 100644
--- a/arch/powerpc/Makefile
+++ b/arch/powerpc/Makefile
@@ -113,7 +113,8 @@ KBUILD_ARFLAGS += --target=elf$(BITS)-$(GNUTARGET)
endif
ifdef CONFIG_STACKPROTECTOR
-KBUILD_CFLAGS += -mstack-protector-guard=global
+CANARY_OFFSET := $(shell awk '{if ($$2 == "TSK_STACK_CANARY") print
$$3;}' include/generated/asm-offsets.h)
+KBUILD_CFLAGS += -mstack-protector-guard=tls
-mstack-protector-guard-reg=r2
-mstack-protector-guard-offset=$(CANARY_OFFSET)
endif
LDFLAGS_vmlinux-y := -Bstatic
Thanks
Christophe
^ permalink raw reply related
* [PATCH 2/2] iommu: Remove .domain_{get,set}_windows
From: Robin Murphy @ 2018-09-19 10:12 UTC (permalink / raw)
To: joro; +Cc: iommu, linuxppc-dev
In-Reply-To: <96e8371cc3143a58c7a142d9ff1134ba7331dd0a.1537351779.git.robin.murphy@arm.com>
Since these are trivially handled by the .domain_{get,set}_attr
callbacks when relevant, we can streamline struct iommu_ops for
everyone.
Signed-off-by: Robin Murphy <robin.murphy@arm.com>
---
drivers/iommu/fsl_pamu_domain.c | 125 +++++++++++++-------------------
include/linux/iommu.h | 6 --
2 files changed, 51 insertions(+), 80 deletions(-)
diff --git a/drivers/iommu/fsl_pamu_domain.c b/drivers/iommu/fsl_pamu_domain.c
index f83965ee3095..a906ce8cf83b 100644
--- a/drivers/iommu/fsl_pamu_domain.c
+++ b/drivers/iommu/fsl_pamu_domain.c
@@ -814,11 +814,59 @@ static int configure_domain_dma_state(struct fsl_dma_domain *dma_domain, bool en
return 0;
}
+static int fsl_pamu_set_windows(struct iommu_domain *domain, u32 w_count)
+{
+ struct fsl_dma_domain *dma_domain = to_fsl_dma_domain(domain);
+ unsigned long flags;
+ int ret;
+
+ spin_lock_irqsave(&dma_domain->domain_lock, flags);
+ /* Ensure domain is inactive i.e. DMA should be disabled for the domain */
+ if (dma_domain->enabled) {
+ pr_debug("Can't set geometry attributes as domain is active\n");
+ spin_unlock_irqrestore(&dma_domain->domain_lock, flags);
+ return -EBUSY;
+ }
+
+ /* Ensure that the geometry has been set for the domain */
+ if (!dma_domain->geom_size) {
+ pr_debug("Please configure geometry before setting the number of windows\n");
+ spin_unlock_irqrestore(&dma_domain->domain_lock, flags);
+ return -EINVAL;
+ }
+
+ /*
+ * Ensure we have valid window count i.e. it should be less than
+ * maximum permissible limit and should be a power of two.
+ */
+ if (w_count > pamu_get_max_subwin_cnt() || !is_power_of_2(w_count)) {
+ pr_debug("Invalid window count\n");
+ spin_unlock_irqrestore(&dma_domain->domain_lock, flags);
+ return -EINVAL;
+ }
+
+ ret = pamu_set_domain_geometry(dma_domain, &domain->geometry,
+ w_count > 1 ? w_count : 0);
+ if (!ret) {
+ kfree(dma_domain->win_arr);
+ dma_domain->win_arr = kcalloc(w_count,
+ sizeof(*dma_domain->win_arr),
+ GFP_ATOMIC);
+ if (!dma_domain->win_arr) {
+ spin_unlock_irqrestore(&dma_domain->domain_lock, flags);
+ return -ENOMEM;
+ }
+ dma_domain->win_cnt = w_count;
+ }
+ spin_unlock_irqrestore(&dma_domain->domain_lock, flags);
+
+ return ret;
+}
+
static int fsl_pamu_set_domain_attr(struct iommu_domain *domain,
enum iommu_attr attr_type, void *data)
{
struct fsl_dma_domain *dma_domain = to_fsl_dma_domain(domain);
- u32 *count;
int ret = 0;
switch (attr_type) {
@@ -832,13 +880,7 @@ static int fsl_pamu_set_domain_attr(struct iommu_domain *domain,
ret = configure_domain_dma_state(dma_domain, *(int *)data);
break;
case DOMAIN_ATTR_WINDOWS:
- count = data;
-
- if (domain->ops->domain_set_windows != NULL)
- ret = domain->ops->domain_set_windows(domain, *count);
- else
- ret = -ENODEV;
-
+ ret = fsl_pamu_set_windows(domain, *(u32 *)data);
break;
default:
pr_debug("Unsupported attribute type\n");
@@ -853,7 +895,6 @@ static int fsl_pamu_get_domain_attr(struct iommu_domain *domain,
enum iommu_attr attr_type, void *data)
{
struct fsl_dma_domain *dma_domain = to_fsl_dma_domain(domain);
- u32 *count;
int ret = 0;
switch (attr_type) {
@@ -868,13 +909,7 @@ static int fsl_pamu_get_domain_attr(struct iommu_domain *domain,
*(int *)data = DOMAIN_ATTR_FSL_PAMUV1;
break;
case DOMAIN_ATTR_WINDOWS:
- count = data;
-
- if (domain->ops->domain_get_windows != NULL)
- *count = domain->ops->domain_get_windows(domain);
- else
- ret = -ENODEV;
-
+ *(u32 *)data = dma_domain->win_cnt;
break;
default:
pr_debug("Unsupported attribute type\n");
@@ -1014,62 +1049,6 @@ static void fsl_pamu_remove_device(struct device *dev)
iommu_group_remove_device(dev);
}
-static int fsl_pamu_set_windows(struct iommu_domain *domain, u32 w_count)
-{
- struct fsl_dma_domain *dma_domain = to_fsl_dma_domain(domain);
- unsigned long flags;
- int ret;
-
- spin_lock_irqsave(&dma_domain->domain_lock, flags);
- /* Ensure domain is inactive i.e. DMA should be disabled for the domain */
- if (dma_domain->enabled) {
- pr_debug("Can't set geometry attributes as domain is active\n");
- spin_unlock_irqrestore(&dma_domain->domain_lock, flags);
- return -EBUSY;
- }
-
- /* Ensure that the geometry has been set for the domain */
- if (!dma_domain->geom_size) {
- pr_debug("Please configure geometry before setting the number of windows\n");
- spin_unlock_irqrestore(&dma_domain->domain_lock, flags);
- return -EINVAL;
- }
-
- /*
- * Ensure we have valid window count i.e. it should be less than
- * maximum permissible limit and should be a power of two.
- */
- if (w_count > pamu_get_max_subwin_cnt() || !is_power_of_2(w_count)) {
- pr_debug("Invalid window count\n");
- spin_unlock_irqrestore(&dma_domain->domain_lock, flags);
- return -EINVAL;
- }
-
- ret = pamu_set_domain_geometry(dma_domain, &domain->geometry,
- w_count > 1 ? w_count : 0);
- if (!ret) {
- kfree(dma_domain->win_arr);
- dma_domain->win_arr = kcalloc(w_count,
- sizeof(*dma_domain->win_arr),
- GFP_ATOMIC);
- if (!dma_domain->win_arr) {
- spin_unlock_irqrestore(&dma_domain->domain_lock, flags);
- return -ENOMEM;
- }
- dma_domain->win_cnt = w_count;
- }
- spin_unlock_irqrestore(&dma_domain->domain_lock, flags);
-
- return ret;
-}
-
-static u32 fsl_pamu_get_windows(struct iommu_domain *domain)
-{
- struct fsl_dma_domain *dma_domain = to_fsl_dma_domain(domain);
-
- return dma_domain->win_cnt;
-}
-
static const struct iommu_ops fsl_pamu_ops = {
.capable = fsl_pamu_capable,
.domain_alloc = fsl_pamu_domain_alloc,
@@ -1078,8 +1057,6 @@ static const struct iommu_ops fsl_pamu_ops = {
.detach_dev = fsl_pamu_detach_device,
.domain_window_enable = fsl_pamu_window_enable,
.domain_window_disable = fsl_pamu_window_disable,
- .domain_get_windows = fsl_pamu_get_windows,
- .domain_set_windows = fsl_pamu_set_windows,
.iova_to_phys = fsl_pamu_iova_to_phys,
.domain_set_attr = fsl_pamu_set_domain_attr,
.domain_get_attr = fsl_pamu_get_domain_attr,
diff --git a/include/linux/iommu.h b/include/linux/iommu.h
index 87994c265bf5..fd4ff4ff691d 100644
--- a/include/linux/iommu.h
+++ b/include/linux/iommu.h
@@ -181,8 +181,6 @@ struct iommu_resv_region {
* @apply_resv_region: Temporary helper call-back for iova reserved ranges
* @domain_window_enable: Configure and enable a particular window for a domain
* @domain_window_disable: Disable a particular window for a domain
- * @domain_set_windows: Set the number of windows for a domain
- * @domain_get_windows: Return the number of windows for a domain
* @of_xlate: add OF master IDs to iommu grouping
* @pgsize_bitmap: bitmap of all possible supported page sizes
*/
@@ -223,10 +221,6 @@ struct iommu_ops {
int (*domain_window_enable)(struct iommu_domain *domain, u32 wnd_nr,
phys_addr_t paddr, u64 size, int prot);
void (*domain_window_disable)(struct iommu_domain *domain, u32 wnd_nr);
- /* Set the number of windows per domain */
- int (*domain_set_windows)(struct iommu_domain *domain, u32 w_count);
- /* Get the number of windows per domain */
- u32 (*domain_get_windows)(struct iommu_domain *domain);
int (*of_xlate)(struct device *dev, struct of_phandle_args *args);
bool (*is_attach_deferred)(struct iommu_domain *domain, struct device *dev);
--
2.19.0.dirty
^ permalink raw reply related
* [PATCH 1/2] iommu: Tidy up window attributes
From: Robin Murphy @ 2018-09-19 10:12 UTC (permalink / raw)
To: joro; +Cc: iommu, linuxppc-dev
The external interface to get/set window attributes is already
abstracted behind iommu_domain_{get,set}_attr(), so there's no real
reason for the internal interface to be different. Since we only have
one window-based driver anyway, clean up the core code by just moving
the DOMAIN_ATTR_WINDOWS handling directly into the PAMU driver.
Signed-off-by: Robin Murphy <robin.murphy@arm.com>
---
Just a cleanup opportunity I spotted whilst poking around in the area.
drivers/iommu/fsl_pamu_domain.c | 20 ++++++++++++++++++++
drivers/iommu/iommu.c | 20 --------------------
2 files changed, 20 insertions(+), 20 deletions(-)
diff --git a/drivers/iommu/fsl_pamu_domain.c b/drivers/iommu/fsl_pamu_domain.c
index f089136e9c3f..f83965ee3095 100644
--- a/drivers/iommu/fsl_pamu_domain.c
+++ b/drivers/iommu/fsl_pamu_domain.c
@@ -818,6 +818,7 @@ static int fsl_pamu_set_domain_attr(struct iommu_domain *domain,
enum iommu_attr attr_type, void *data)
{
struct fsl_dma_domain *dma_domain = to_fsl_dma_domain(domain);
+ u32 *count;
int ret = 0;
switch (attr_type) {
@@ -829,6 +830,15 @@ static int fsl_pamu_set_domain_attr(struct iommu_domain *domain,
break;
case DOMAIN_ATTR_FSL_PAMU_ENABLE:
ret = configure_domain_dma_state(dma_domain, *(int *)data);
+ break;
+ case DOMAIN_ATTR_WINDOWS:
+ count = data;
+
+ if (domain->ops->domain_set_windows != NULL)
+ ret = domain->ops->domain_set_windows(domain, *count);
+ else
+ ret = -ENODEV;
+
break;
default:
pr_debug("Unsupported attribute type\n");
@@ -843,6 +853,7 @@ static int fsl_pamu_get_domain_attr(struct iommu_domain *domain,
enum iommu_attr attr_type, void *data)
{
struct fsl_dma_domain *dma_domain = to_fsl_dma_domain(domain);
+ u32 *count;
int ret = 0;
switch (attr_type) {
@@ -855,6 +866,15 @@ static int fsl_pamu_get_domain_attr(struct iommu_domain *domain,
break;
case DOMAIN_ATTR_FSL_PAMUV1:
*(int *)data = DOMAIN_ATTR_FSL_PAMUV1;
+ break;
+ case DOMAIN_ATTR_WINDOWS:
+ count = data;
+
+ if (domain->ops->domain_get_windows != NULL)
+ *count = domain->ops->domain_get_windows(domain);
+ else
+ ret = -ENODEV;
+
break;
default:
pr_debug("Unsupported attribute type\n");
diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
index 8c15c5980299..2faec6aa73c4 100644
--- a/drivers/iommu/iommu.c
+++ b/drivers/iommu/iommu.c
@@ -1796,7 +1796,6 @@ int iommu_domain_get_attr(struct iommu_domain *domain,
struct iommu_domain_geometry *geometry;
bool *paging;
int ret = 0;
- u32 *count;
switch (attr) {
case DOMAIN_ATTR_GEOMETRY:
@@ -1807,15 +1806,6 @@ int iommu_domain_get_attr(struct iommu_domain *domain,
case DOMAIN_ATTR_PAGING:
paging = data;
*paging = (domain->pgsize_bitmap != 0UL);
- break;
- case DOMAIN_ATTR_WINDOWS:
- count = data;
-
- if (domain->ops->domain_get_windows != NULL)
- *count = domain->ops->domain_get_windows(domain);
- else
- ret = -ENODEV;
-
break;
default:
if (!domain->ops->domain_get_attr)
@@ -1832,18 +1822,8 @@ int iommu_domain_set_attr(struct iommu_domain *domain,
enum iommu_attr attr, void *data)
{
int ret = 0;
- u32 *count;
switch (attr) {
- case DOMAIN_ATTR_WINDOWS:
- count = data;
-
- if (domain->ops->domain_set_windows != NULL)
- ret = domain->ops->domain_set_windows(domain, *count);
- else
- ret = -ENODEV;
-
- break;
default:
if (domain->ops->domain_set_attr == NULL)
return -EINVAL;
--
2.19.0.dirty
^ permalink raw reply related
* [PATCH net-next] net: toshiba: fix return type of ndo_start_xmit function
From: YueHaibing @ 2018-09-19 10:23 UTC (permalink / raw)
To: davem, geoff, benh, paulus, mpe, kou.ishizaki, andrew, f.fainelli
Cc: linux-kernel, netdev, linuxppc-dev, YueHaibing
The method ndo_start_xmit() is defined as returning an 'netdev_tx_t',
which is a typedef for an enum type, so make sure the implementation in
this driver has returns 'netdev_tx_t' value, and change the function
return type to netdev_tx_t.
Found by coccinelle.
Signed-off-by: YueHaibing <yuehaibing@huawei.com>
---
drivers/net/ethernet/toshiba/ps3_gelic_net.c | 4 ++--
drivers/net/ethernet/toshiba/ps3_gelic_net.h | 2 +-
drivers/net/ethernet/toshiba/spider_net.c | 4 ++--
drivers/net/ethernet/toshiba/tc35815.c | 6 ++++--
4 files changed, 9 insertions(+), 7 deletions(-)
diff --git a/drivers/net/ethernet/toshiba/ps3_gelic_net.c b/drivers/net/ethernet/toshiba/ps3_gelic_net.c
index 88d74ae..75237c8 100644
--- a/drivers/net/ethernet/toshiba/ps3_gelic_net.c
+++ b/drivers/net/ethernet/toshiba/ps3_gelic_net.c
@@ -845,9 +845,9 @@ static int gelic_card_kick_txdma(struct gelic_card *card,
* @skb: packet to send out
* @netdev: interface device structure
*
- * returns 0 on success, <0 on failure
+ * returns NETDEV_TX_OK on success, NETDEV_TX_BUSY on failure
*/
-int gelic_net_xmit(struct sk_buff *skb, struct net_device *netdev)
+netdev_tx_t gelic_net_xmit(struct sk_buff *skb, struct net_device *netdev)
{
struct gelic_card *card = netdev_card(netdev);
struct gelic_descr *descr;
diff --git a/drivers/net/ethernet/toshiba/ps3_gelic_net.h b/drivers/net/ethernet/toshiba/ps3_gelic_net.h
index 003d045..fbbf9b5 100644
--- a/drivers/net/ethernet/toshiba/ps3_gelic_net.h
+++ b/drivers/net/ethernet/toshiba/ps3_gelic_net.h
@@ -370,7 +370,7 @@ static inline void udbg_shutdown_ps3gelic(void) {}
void gelic_card_down(struct gelic_card *card);
int gelic_net_open(struct net_device *netdev);
int gelic_net_stop(struct net_device *netdev);
-int gelic_net_xmit(struct sk_buff *skb, struct net_device *netdev);
+netdev_tx_t gelic_net_xmit(struct sk_buff *skb, struct net_device *netdev);
void gelic_net_set_multi(struct net_device *netdev);
void gelic_net_tx_timeout(struct net_device *netdev);
int gelic_net_setup_netdev(struct net_device *netdev, struct gelic_card *card);
diff --git a/drivers/net/ethernet/toshiba/spider_net.c b/drivers/net/ethernet/toshiba/spider_net.c
index d925b82..2341726 100644
--- a/drivers/net/ethernet/toshiba/spider_net.c
+++ b/drivers/net/ethernet/toshiba/spider_net.c
@@ -880,9 +880,9 @@
* @skb: packet to send out
* @netdev: interface device structure
*
- * returns 0 on success, !0 on failure
+ * returns NETDEV_TX_OK on success, NETDEV_TX_BUSY on failure
*/
-static int
+static netdev_tx_t
spider_net_xmit(struct sk_buff *skb, struct net_device *netdev)
{
int cnt;
diff --git a/drivers/net/ethernet/toshiba/tc35815.c b/drivers/net/ethernet/toshiba/tc35815.c
index 7163a8d..6a71c2c 100644
--- a/drivers/net/ethernet/toshiba/tc35815.c
+++ b/drivers/net/ethernet/toshiba/tc35815.c
@@ -474,7 +474,8 @@ static void free_rxbuf_skb(struct pci_dev *hwdev, struct sk_buff *skb, dma_addr_
/* Index to functions, as function prototypes. */
static int tc35815_open(struct net_device *dev);
-static int tc35815_send_packet(struct sk_buff *skb, struct net_device *dev);
+static netdev_tx_t tc35815_send_packet(struct sk_buff *skb,
+ struct net_device *dev);
static irqreturn_t tc35815_interrupt(int irq, void *dev_id);
static int tc35815_rx(struct net_device *dev, int limit);
static int tc35815_poll(struct napi_struct *napi, int budget);
@@ -1248,7 +1249,8 @@ static void tc35815_tx_timeout(struct net_device *dev)
* invariant will hold if you make sure that the netif_*_queue()
* calls are done at the proper times.
*/
-static int tc35815_send_packet(struct sk_buff *skb, struct net_device *dev)
+static netdev_tx_t
+tc35815_send_packet(struct sk_buff *skb, struct net_device *dev)
{
struct tc35815_local *lp = netdev_priv(dev);
struct TxFD *txfd;
--
1.8.3.1
^ permalink raw reply related
* Re: [RFC PATCH 03/29] mm: remove CONFIG_HAVE_MEMBLOCK
From: Mike Rapoport @ 2018-09-19 10:34 UTC (permalink / raw)
To: Jonathan Cameron
Cc: linux-mm, Andrew Morton, David S. Miller, Greg Kroah-Hartman,
Ingo Molnar, Michael Ellerman, Michal Hocko, Paul Burton,
Thomas Gleixner, Tony Luck, linux-ia64, linux-mips, linuxppc-dev,
sparclinux, linux-kernel, linuxarm
In-Reply-To: <20180919100449.00006df9@huawei.com>
Hi Jonathan,
On Wed, Sep 19, 2018 at 10:04:49AM +0100, Jonathan Cameron wrote:
> On Wed, 5 Sep 2018 18:59:18 +0300
> Mike Rapoport <rppt@linux.vnet.ibm.com> wrote:
>
> > All architecures use memblock for early memory management. There is no need
> > for the CONFIG_HAVE_MEMBLOCK configuration option.
> >
> > Signed-off-by: Mike Rapoport <rppt@linux.vnet.ibm.com>
>
> Hi Mike,
>
> A minor editing issue in here that is stopping boot on arm64 platforms with latest
> version of the mm tree.
Can you please try the following patch:
>From 079bd5d24a01df3df9500d0a33d89cb9f7da4588 Mon Sep 17 00:00:00 2001
From: Mike Rapoport <rppt@linux.vnet.ibm.com>
Date: Wed, 19 Sep 2018 13:29:27 +0300
Subject: [PATCH] of/fdt: fixup #ifdefs after removal of HAVE_MEMBLOCK config
option
The removal of HAVE_MEMBLOCK configuration option, mistakenly dropped the
wrong #endif. This patch restores that #endif and removes the part that
should have been actually removed, starting from #else and up to the
correct #endif
Reported-by: Jonathan Cameron <jonathan.cameron@huawei.com>
Signed-off-by: Mike Rapoport <rppt@linux.vnet.ibm.com>
---
drivers/of/fdt.c | 21 +--------------------
1 file changed, 1 insertion(+), 20 deletions(-)
diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c
index 48314e9..bb532aa 100644
--- a/drivers/of/fdt.c
+++ b/drivers/of/fdt.c
@@ -1119,6 +1119,7 @@ int __init early_init_dt_scan_chosen(unsigned long node, const char *uname,
#endif
#ifndef MAX_MEMBLOCK_ADDR
#define MAX_MEMBLOCK_ADDR ((phys_addr_t)~0)
+#endif
void __init __weak early_init_dt_add_memory_arch(u64 base, u64 size)
{
@@ -1175,26 +1176,6 @@ int __init __weak early_init_dt_reserve_memory_arch(phys_addr_t base,
return memblock_reserve(base, size);
}
-#else
-void __init __weak early_init_dt_add_memory_arch(u64 base, u64 size)
-{
- WARN_ON(1);
-}
-
-int __init __weak early_init_dt_mark_hotplug_memory_arch(u64 base, u64 size)
-{
- return -ENOSYS;
-}
-
-int __init __weak early_init_dt_reserve_memory_arch(phys_addr_t base,
- phys_addr_t size, bool nomap)
-{
- pr_err("Reserved memory not supported, ignoring range %pa - %pa%s\n",
- &base, &size, nomap ? " (nomap)" : "");
- return -ENOSYS;
-}
-#endif
-
static void * __init early_init_dt_alloc_memory_arch(u64 size, u64 align)
{
return memblock_alloc(size, align);
--
2.7.4
> > diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c
> > index 76c83c1..bd841bb 100644
> > --- a/drivers/of/fdt.c
> > +++ b/drivers/of/fdt.c
> > @@ -1115,13 +1115,11 @@ int __init early_init_dt_scan_chosen(unsigned long node, const char *uname,
> > return 1;
> > }
> >
> > -#ifdef CONFIG_HAVE_MEMBLOCK
> > #ifndef MIN_MEMBLOCK_ADDR
> > #define MIN_MEMBLOCK_ADDR __pa(PAGE_OFFSET)
> > #endif
> > #ifndef MAX_MEMBLOCK_ADDR
> > #define MAX_MEMBLOCK_ADDR ((phys_addr_t)~0)
> > -#endif
>
> This isn't the right #endif. It is matching with the #ifndef MAX_MEMBLOCK_ADDR
> not the intented #ifdef CONFIG_HAVE_MEMBLOCK.
>
> Now I haven't chased through the exact reason this is causing my acpi
> arm64 system not to boot on the basis it is obviously miss-matched anyway
> and I'm inherently lazy. It's resulting in stubs replacing the following weak
> functions.
>
> early_init_dt_add_memory_arch
> (this is defined elsewhere for some architectures but not arm)
>
> early_init_dt_mark_hotplug_memory_arch
> (there is only one definition of this in the kernel so it doesn't
> need to be weak or in the header etc).
>
> early_init_dt_reserve_memory_arch
> (defined on mips but nothing else)
>
> Taking out the right endif also lets you drop an #else removing some stub
> functions further down in here.
>
> Nice cleanup in general btw.
>
> Thanks,
>
> Jonathan
> >
> > void __init __weak early_init_dt_add_memory_arch(u64 base, u64 size)
> > {
>
--
Sincerely yours,
Mike.
^ permalink raw reply related
* Re: [RFC PATCH 03/29] mm: remove CONFIG_HAVE_MEMBLOCK
From: Jonathan Cameron @ 2018-09-19 10:45 UTC (permalink / raw)
To: Mike Rapoport
Cc: linux-mm, Andrew Morton, David S. Miller, Greg Kroah-Hartman,
Ingo Molnar, Michael Ellerman, Michal Hocko, Paul Burton,
Thomas Gleixner, Tony Luck, linux-ia64, linux-mips, linuxppc-dev,
sparclinux, linux-kernel, linuxarm
In-Reply-To: <20180919103457.GA20545@rapoport-lnx>
On Wed, 19 Sep 2018 13:34:57 +0300
Mike Rapoport <rppt@linux.vnet.ibm.com> wrote:
> Hi Jonathan,
>
> On Wed, Sep 19, 2018 at 10:04:49AM +0100, Jonathan Cameron wrote:
> > On Wed, 5 Sep 2018 18:59:18 +0300
> > Mike Rapoport <rppt@linux.vnet.ibm.com> wrote:
> >
> > > All architecures use memblock for early memory management. There is no need
> > > for the CONFIG_HAVE_MEMBLOCK configuration option.
> > >
> > > Signed-off-by: Mike Rapoport <rppt@linux.vnet.ibm.com>
> >
> > Hi Mike,
> >
> > A minor editing issue in here that is stopping boot on arm64 platforms with latest
> > version of the mm tree.
>
> Can you please try the following patch:
>
>
> From 079bd5d24a01df3df9500d0a33d89cb9f7da4588 Mon Sep 17 00:00:00 2001
> From: Mike Rapoport <rppt@linux.vnet.ibm.com>
> Date: Wed, 19 Sep 2018 13:29:27 +0300
> Subject: [PATCH] of/fdt: fixup #ifdefs after removal of HAVE_MEMBLOCK config
> option
>
> The removal of HAVE_MEMBLOCK configuration option, mistakenly dropped the
> wrong #endif. This patch restores that #endif and removes the part that
> should have been actually removed, starting from #else and up to the
> correct #endif
>
> Reported-by: Jonathan Cameron <jonathan.cameron@huawei.com>
> Signed-off-by: Mike Rapoport <rppt@linux.vnet.ibm.com>
Hi Mike,
That's identical to the local patch I'm carrying to fix this so looks good to me.
For what it's worth given you'll probably fold this into the larger patch.
Tested-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Thanks for the quick reply.
Jonathan
> ---
> drivers/of/fdt.c | 21 +--------------------
> 1 file changed, 1 insertion(+), 20 deletions(-)
>
> diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c
> index 48314e9..bb532aa 100644
> --- a/drivers/of/fdt.c
> +++ b/drivers/of/fdt.c
> @@ -1119,6 +1119,7 @@ int __init early_init_dt_scan_chosen(unsigned long node, const char *uname,
> #endif
> #ifndef MAX_MEMBLOCK_ADDR
> #define MAX_MEMBLOCK_ADDR ((phys_addr_t)~0)
> +#endif
>
> void __init __weak early_init_dt_add_memory_arch(u64 base, u64 size)
> {
> @@ -1175,26 +1176,6 @@ int __init __weak early_init_dt_reserve_memory_arch(phys_addr_t base,
> return memblock_reserve(base, size);
> }
>
> -#else
> -void __init __weak early_init_dt_add_memory_arch(u64 base, u64 size)
> -{
> - WARN_ON(1);
> -}
> -
> -int __init __weak early_init_dt_mark_hotplug_memory_arch(u64 base, u64 size)
> -{
> - return -ENOSYS;
> -}
> -
> -int __init __weak early_init_dt_reserve_memory_arch(phys_addr_t base,
> - phys_addr_t size, bool nomap)
> -{
> - pr_err("Reserved memory not supported, ignoring range %pa - %pa%s\n",
> - &base, &size, nomap ? " (nomap)" : "");
> - return -ENOSYS;
> -}
> -#endif
> -
> static void * __init early_init_dt_alloc_memory_arch(u64 size, u64 align)
> {
> return memblock_alloc(size, align);
^ permalink raw reply
* Re: [RFC PATCH 03/29] mm: remove CONFIG_HAVE_MEMBLOCK
From: Mike Rapoport @ 2018-09-19 10:55 UTC (permalink / raw)
To: Jonathan Cameron
Cc: linux-mm, Andrew Morton, David S. Miller, Greg Kroah-Hartman,
Ingo Molnar, Michael Ellerman, Michal Hocko, Paul Burton,
Thomas Gleixner, Tony Luck, linux-ia64, linux-mips, linuxppc-dev,
sparclinux, linux-kernel, linuxarm
In-Reply-To: <20180919114507.000059f3@huawei.com>
On Wed, Sep 19, 2018 at 11:45:07AM +0100, Jonathan Cameron wrote:
> On Wed, 19 Sep 2018 13:34:57 +0300
> Mike Rapoport <rppt@linux.vnet.ibm.com> wrote:
>
> > Hi Jonathan,
> >
> > On Wed, Sep 19, 2018 at 10:04:49AM +0100, Jonathan Cameron wrote:
> > > On Wed, 5 Sep 2018 18:59:18 +0300
> > > Mike Rapoport <rppt@linux.vnet.ibm.com> wrote:
> > >
> > > > All architecures use memblock for early memory management. There is no need
> > > > for the CONFIG_HAVE_MEMBLOCK configuration option.
> > > >
> > > > Signed-off-by: Mike Rapoport <rppt@linux.vnet.ibm.com>
> > >
> > > Hi Mike,
> > >
> > > A minor editing issue in here that is stopping boot on arm64 platforms with latest
> > > version of the mm tree.
> >
> > Can you please try the following patch:
> >
> >
> > From 079bd5d24a01df3df9500d0a33d89cb9f7da4588 Mon Sep 17 00:00:00 2001
> > From: Mike Rapoport <rppt@linux.vnet.ibm.com>
> > Date: Wed, 19 Sep 2018 13:29:27 +0300
> > Subject: [PATCH] of/fdt: fixup #ifdefs after removal of HAVE_MEMBLOCK config
> > option
> >
> > The removal of HAVE_MEMBLOCK configuration option, mistakenly dropped the
> > wrong #endif. This patch restores that #endif and removes the part that
> > should have been actually removed, starting from #else and up to the
> > correct #endif
> >
> > Reported-by: Jonathan Cameron <jonathan.cameron@huawei.com>
> > Signed-off-by: Mike Rapoport <rppt@linux.vnet.ibm.com>
>
> Hi Mike,
>
> That's identical to the local patch I'm carrying to fix this so looks good to me.
>
> For what it's worth given you'll probably fold this into the larger patch.
>
> Tested-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Well, this is up to Andrew now, as the broken patch is already in the -mm
tree.
> Thanks for the quick reply.
>
> Jonathan
>
> > ---
> > drivers/of/fdt.c | 21 +--------------------
> > 1 file changed, 1 insertion(+), 20 deletions(-)
> >
> > diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c
> > index 48314e9..bb532aa 100644
> > --- a/drivers/of/fdt.c
> > +++ b/drivers/of/fdt.c
> > @@ -1119,6 +1119,7 @@ int __init early_init_dt_scan_chosen(unsigned long node, const char *uname,
> > #endif
> > #ifndef MAX_MEMBLOCK_ADDR
> > #define MAX_MEMBLOCK_ADDR ((phys_addr_t)~0)
> > +#endif
> >
> > void __init __weak early_init_dt_add_memory_arch(u64 base, u64 size)
> > {
> > @@ -1175,26 +1176,6 @@ int __init __weak early_init_dt_reserve_memory_arch(phys_addr_t base,
> > return memblock_reserve(base, size);
> > }
> >
> > -#else
> > -void __init __weak early_init_dt_add_memory_arch(u64 base, u64 size)
> > -{
> > - WARN_ON(1);
> > -}
> > -
> > -int __init __weak early_init_dt_mark_hotplug_memory_arch(u64 base, u64 size)
> > -{
> > - return -ENOSYS;
> > -}
> > -
> > -int __init __weak early_init_dt_reserve_memory_arch(phys_addr_t base,
> > - phys_addr_t size, bool nomap)
> > -{
> > - pr_err("Reserved memory not supported, ignoring range %pa - %pa%s\n",
> > - &base, &size, nomap ? " (nomap)" : "");
> > - return -ENOSYS;
> > -}
> > -#endif
> > -
> > static void * __init early_init_dt_alloc_memory_arch(u64 size, u64 align)
> > {
> > return memblock_alloc(size, align);
>
>
--
Sincerely yours,
Mike.
^ permalink raw reply
* [PATCH v2 1/2] sched: move stack_canary field at the top of task_struct
From: Christophe Leroy @ 2018-09-19 11:14 UTC (permalink / raw)
To: Benjamin Herrenschmidt, Paul Mackerras, Michael Ellerman,
Ingo Molnar, Peter Zijlstra, segher
Cc: linux-kernel, linuxppc-dev
In order to allow the use of non global stack protector canary,
the stack canary needs to be located at a know offset defined
in Makefile via -mstack-protector-guard-offset.
On powerpc/32, register r2 points to current task_struct at
all time, the stack_canary located inside task_struct can be
used directly if it is located in a known place.
In order to allow that, this patch moves the stack_canary field
out of the randomized area of task_struct.
Signed-off-by: Christophe Leroy <christophe.leroy@c-s.fr>
---
include/linux/sched.h | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/include/linux/sched.h b/include/linux/sched.h
index 977cb57d7bc9..1d977b8a4bac 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -601,6 +601,10 @@ struct task_struct {
/* -1 unrunnable, 0 runnable, >0 stopped: */
volatile long state;
+#ifdef CONFIG_STACKPROTECTOR
+ /* Canary value for the -fstack-protector GCC feature: */
+ unsigned long stack_canary;
+#endif
/*
* This begins the randomizable portion of task_struct. Only
* scheduling-critical items should be added above here.
@@ -746,10 +750,6 @@ struct task_struct {
pid_t pid;
pid_t tgid;
-#ifdef CONFIG_STACKPROTECTOR
- /* Canary value for the -fstack-protector GCC feature: */
- unsigned long stack_canary;
-#endif
/*
* Pointers to the (original) parent process, youngest child, younger sibling,
* older sibling, respectively. (p->father can be replaced with
--
2.13.3
^ permalink raw reply related
* [PATCH v2 2/2] powerpc/32: add stack protector support
From: Christophe Leroy @ 2018-09-19 11:14 UTC (permalink / raw)
To: Benjamin Herrenschmidt, Paul Mackerras, Michael Ellerman,
Ingo Molnar, Peter Zijlstra, segher
Cc: linux-kernel, linuxppc-dev
In-Reply-To: <d60ce7dd74704b0ca0a857186f30de4006b63534.1537355312.git.christophe.leroy@c-s.fr>
This functionality was tentatively added in the past
(commit 6533b7c16ee5 ("powerpc: Initial stack protector
(-fstack-protector) support")) but had to be reverted
(commit f2574030b0e3 ("powerpc: Revert the initial stack
protector support") because of GCC implementing it differently
whether it had been built with libc support or not.
Now, GCC offers the possibility to manually set the
stack-protector mode (global or tls) regardless of libc support.
This time, the patch selects HAVE_STACKPROTECTOR only if
-mstack-protector-guard=global is supported by GCC.
On PPC32, as register r2 points to current task_struct at
all time, the stack_canary located inside task_struct can be
used directly by using the following GCC options:
-mstack-protector-guard=tls
-mstack-protector-guard-reg=r2
-mstack-protector-guard-offset=4
(= offsetof(struct task_struct, stack_canary))
$ echo CORRUPT_STACK > /sys/kernel/debug/provoke-crash/DIRECT
[ 134.943666] Kernel panic - not syncing: stack-protector: Kernel stack is corrupted in: lkdtm_CORRUPT_STACK+0x64/0x64
[ 134.943666]
[ 134.955414] CPU: 0 PID: 283 Comm: sh Not tainted 4.18.0-s3k-dev-12143-ga3272be41209 #835
[ 134.963380] Call Trace:
[ 134.965860] [c6615d60] [c001f76c] panic+0x118/0x260 (unreliable)
[ 134.971775] [c6615dc0] [c001f654] panic+0x0/0x260
[ 134.976435] [c6615dd0] [c032c368] lkdtm_CORRUPT_STACK_STRONG+0x0/0x64
[ 134.982769] [c6615e00] [ffffffff] 0xffffffff
Signed-off-by: Christophe Leroy <christophe.leroy@c-s.fr>
---
arch/powerpc/Kconfig | 1 +
arch/powerpc/Makefile | 4 ++++
arch/powerpc/include/asm/stackprotector.h | 38 +++++++++++++++++++++++++++++++
arch/powerpc/kernel/Makefile | 4 ++++
4 files changed, 47 insertions(+)
create mode 100644 arch/powerpc/include/asm/stackprotector.h
diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
index a80669209155..538bb6e2fd70 100644
--- a/arch/powerpc/Kconfig
+++ b/arch/powerpc/Kconfig
@@ -180,6 +180,7 @@ config PPC
select HAVE_ARCH_SECCOMP_FILTER
select HAVE_ARCH_TRACEHOOK
select HAVE_CBPF_JIT if !PPC64
+ select HAVE_STACKPROTECTOR if PPC32 && $(cc-option,-mstack-protector-guard=tls)
select HAVE_CONTEXT_TRACKING if PPC64
select HAVE_DEBUG_KMEMLEAK
select HAVE_DEBUG_STACKOVERFLOW
diff --git a/arch/powerpc/Makefile b/arch/powerpc/Makefile
index 11a1acba164a..1108981292e9 100644
--- a/arch/powerpc/Makefile
+++ b/arch/powerpc/Makefile
@@ -112,6 +112,10 @@ KBUILD_LDFLAGS += -m elf$(BITS)$(LDEMULATION)
KBUILD_ARFLAGS += --target=elf$(BITS)-$(GNUTARGET)
endif
+cflags-$(CONFIG_STACKPROTECTOR) += -mstack-protector-guard=tls
+cflags-$(CONFIG_STACKPROTECTOR) += -mstack-protector-guard-reg=r2
+cflags-$(CONFIG_STACKPROTECTOR) += -mstack-protector-guard-offset=4
+
LDFLAGS_vmlinux-y := -Bstatic
LDFLAGS_vmlinux-$(CONFIG_RELOCATABLE) := -pie
LDFLAGS_vmlinux := $(LDFLAGS_vmlinux-y)
diff --git a/arch/powerpc/include/asm/stackprotector.h b/arch/powerpc/include/asm/stackprotector.h
new file mode 100644
index 000000000000..4fdecbdd78e7
--- /dev/null
+++ b/arch/powerpc/include/asm/stackprotector.h
@@ -0,0 +1,38 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * GCC stack protector support.
+ *
+ */
+
+#ifndef _ASM_STACKPROTECTOR_H
+#define _ASM_STACKPROTECTOR_H
+
+#include <linux/random.h>
+#include <linux/version.h>
+#include <asm/reg.h>
+
+/*
+ * Initialize the stackprotector canary value.
+ *
+ * NOTE: this must only be called from functions that never return,
+ * and it must always be inlined.
+ */
+static __always_inline void boot_init_stack_canary(void)
+{
+ unsigned long canary;
+
+ /*
+ * The stack_canary must be located at the offset given to
+ * -mstack-protector-guard-offset in the Makefile
+ */
+ BUILD_BUG_ON(offsetof(struct task_struct, stack_canary) != sizeof(long));
+
+ /* Try to get a semi random initial value. */
+ get_random_bytes(&canary, sizeof(canary));
+ canary ^= mftb();
+ canary ^= LINUX_VERSION_CODE;
+
+ current->stack_canary = canary;
+}
+
+#endif /* _ASM_STACKPROTECTOR_H */
diff --git a/arch/powerpc/kernel/Makefile b/arch/powerpc/kernel/Makefile
index 3b66f2c19c84..0556a7243d2a 100644
--- a/arch/powerpc/kernel/Makefile
+++ b/arch/powerpc/kernel/Makefile
@@ -20,6 +20,10 @@ CFLAGS_prom_init.o += $(DISABLE_LATENT_ENTROPY_PLUGIN)
CFLAGS_btext.o += $(DISABLE_LATENT_ENTROPY_PLUGIN)
CFLAGS_prom.o += $(DISABLE_LATENT_ENTROPY_PLUGIN)
+# -fstack-protector triggers protection checks in this code,
+# but it is being used too early to link to meaningful stack_chk logic.
+CFLAGS_prom_init.o += $(call cc-option, -fno-stack-protector)
+
ifdef CONFIG_FUNCTION_TRACER
# Do not trace early boot code
CFLAGS_REMOVE_cputable.o = -mno-sched-epilog $(CC_FLAGS_FTRACE)
--
2.13.3
^ permalink raw reply related
* Re: [PATCH v2 1/2] sched: move stack_canary field at the top of task_struct
From: Peter Zijlstra @ 2018-09-19 11:58 UTC (permalink / raw)
To: Christophe Leroy
Cc: Benjamin Herrenschmidt, Paul Mackerras, Michael Ellerman,
Ingo Molnar, segher, linux-kernel, linuxppc-dev
In-Reply-To: <d60ce7dd74704b0ca0a857186f30de4006b63534.1537355312.git.christophe.leroy@c-s.fr>
On Wed, Sep 19, 2018 at 11:14:43AM +0000, Christophe Leroy wrote:
> In order to allow the use of non global stack protector canary,
> the stack canary needs to be located at a know offset defined
> in Makefile via -mstack-protector-guard-offset.
>
> On powerpc/32, register r2 points to current task_struct at
> all time, the stack_canary located inside task_struct can be
> used directly if it is located in a known place.
>
> In order to allow that, this patch moves the stack_canary field
> out of the randomized area of task_struct.
And you cannot use something like asm-offsets to extract this?
> Signed-off-by: Christophe Leroy <christophe.leroy@c-s.fr>
> ---
> include/linux/sched.h | 8 ++++----
> 1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/include/linux/sched.h b/include/linux/sched.h
> index 977cb57d7bc9..1d977b8a4bac 100644
> --- a/include/linux/sched.h
> +++ b/include/linux/sched.h
> @@ -601,6 +601,10 @@ struct task_struct {
> /* -1 unrunnable, 0 runnable, >0 stopped: */
> volatile long state;
>
> +#ifdef CONFIG_STACKPROTECTOR
> + /* Canary value for the -fstack-protector GCC feature: */
> + unsigned long stack_canary;
> +#endif
> /*
> * This begins the randomizable portion of task_struct. Only
> * scheduling-critical items should be added above here.
Might as well put it before state, right after the task_info thing.
^ permalink raw reply
* Re: [PATCH v2 1/2] sched: move stack_canary field at the top of task_struct
From: Christophe LEROY @ 2018-09-19 12:25 UTC (permalink / raw)
To: Peter Zijlstra
Cc: Benjamin Herrenschmidt, Paul Mackerras, Michael Ellerman,
Ingo Molnar, segher, linux-kernel, linuxppc-dev
In-Reply-To: <20180919115836.GE24124@hirez.programming.kicks-ass.net>
Le 19/09/2018 à 13:58, Peter Zijlstra a écrit :
> On Wed, Sep 19, 2018 at 11:14:43AM +0000, Christophe Leroy wrote:
>> In order to allow the use of non global stack protector canary,
>> the stack canary needs to be located at a know offset defined
>> in Makefile via -mstack-protector-guard-offset.
>>
>> On powerpc/32, register r2 points to current task_struct at
>> all time, the stack_canary located inside task_struct can be
>> used directly if it is located in a known place.
>>
>> In order to allow that, this patch moves the stack_canary field
>> out of the randomized area of task_struct.
>
> And you cannot use something like asm-offsets to extract this?
I have not been able to find a way to define the compilation flags AFTER
building asm-offsets.h, see https://patchwork.ozlabs.org/patch/971521/
If you have a suggestion, it is welcomed.
>
>> Signed-off-by: Christophe Leroy <christophe.leroy@c-s.fr>
>> ---
>> include/linux/sched.h | 8 ++++----
>> 1 file changed, 4 insertions(+), 4 deletions(-)
>>
>> diff --git a/include/linux/sched.h b/include/linux/sched.h
>> index 977cb57d7bc9..1d977b8a4bac 100644
>> --- a/include/linux/sched.h
>> +++ b/include/linux/sched.h
>> @@ -601,6 +601,10 @@ struct task_struct {
>> /* -1 unrunnable, 0 runnable, >0 stopped: */
>> volatile long state;
>>
>> +#ifdef CONFIG_STACKPROTECTOR
>> + /* Canary value for the -fstack-protector GCC feature: */
>> + unsigned long stack_canary;
>> +#endif
>> /*
>> * This begins the randomizable portion of task_struct. Only
>> * scheduling-critical items should be added above here.
>
> Might as well put it before state, right after the task_info thing.
>
Yes, it doesn't make much difference, don't any arch expect state at
offset 0 ?
Christophe
^ permalink raw reply
* Re: [PATCH v2 1/2] sched: move stack_canary field at the top of task_struct
From: Peter Zijlstra @ 2018-09-19 12:52 UTC (permalink / raw)
To: Christophe LEROY
Cc: Benjamin Herrenschmidt, Paul Mackerras, Michael Ellerman,
Ingo Molnar, segher, linux-kernel, linuxppc-dev
In-Reply-To: <f6a36d25-ce19-5d56-69d9-198215a7b9e1@c-s.fr>
On Wed, Sep 19, 2018 at 02:25:00PM +0200, Christophe LEROY wrote:
> I have not been able to find a way to define the compilation flags AFTER
> building asm-offsets.h, see https://patchwork.ozlabs.org/patch/971521/
>
> If you have a suggestion, it is welcomed.
Not really; I always get lost in that stuff :/
> > Might as well put it before state, right after the task_info thing.
> >
>
> Yes, it doesn't make much difference, don't any arch expect state at offset
> 0 ?
Uhmm.. dunno. I would not expect so, but then I didn't check.
^ permalink raw reply
* Re: [PATCH v2 2/2] powerpc/32: add stack protector support
From: Segher Boessenkool @ 2018-09-19 13:26 UTC (permalink / raw)
To: Christophe Leroy
Cc: Benjamin Herrenschmidt, Paul Mackerras, Michael Ellerman,
Ingo Molnar, Peter Zijlstra, linux-kernel, linuxppc-dev
In-Reply-To: <ef8fcc7933d56db6f5f7251cb982ca7131f7408d.1537355312.git.christophe.leroy@c-s.fr>
On Wed, Sep 19, 2018 at 11:14:45AM +0000, Christophe Leroy wrote:
> --- a/arch/powerpc/Makefile
> +++ b/arch/powerpc/Makefile
> @@ -112,6 +112,10 @@ KBUILD_LDFLAGS += -m elf$(BITS)$(LDEMULATION)
> KBUILD_ARFLAGS += --target=elf$(BITS)-$(GNUTARGET)
> endif
>
> +cflags-$(CONFIG_STACKPROTECTOR) += -mstack-protector-guard=tls
> +cflags-$(CONFIG_STACKPROTECTOR) += -mstack-protector-guard-reg=r2
> +cflags-$(CONFIG_STACKPROTECTOR) += -mstack-protector-guard-offset=4
This last line is only correct if !CONFIG_THREAD_INFO_IN_TASK; is that
always true? Add an assert somewhere maybe?
> + /*
> + * The stack_canary must be located at the offset given to
> + * -mstack-protector-guard-offset in the Makefile
> + */
> + BUILD_BUG_ON(offsetof(struct task_struct, stack_canary) != sizeof(long));
Well this will help :-)
It looks like it will be easy to enable on 64 bit as well.
> + /* Try to get a semi random initial value. */
> + get_random_bytes(&canary, sizeof(canary));
> + canary ^= mftb();
> + canary ^= LINUX_VERSION_CODE;
These last two lines are useless (or worse, they may give people the idea
that they are not!)
You should use wait_for_random_bytes I think.
Segher
^ permalink raw reply
* Re: [PATCH v2 2/2] powerpc/32: add stack protector support
From: Christophe LEROY @ 2018-09-19 14:22 UTC (permalink / raw)
To: Segher Boessenkool
Cc: Benjamin Herrenschmidt, Paul Mackerras, Michael Ellerman,
Ingo Molnar, Peter Zijlstra, linux-kernel, linuxppc-dev
In-Reply-To: <20180919132618.GX23155@gate.crashing.org>
Le 19/09/2018 à 15:26, Segher Boessenkool a écrit :
> On Wed, Sep 19, 2018 at 11:14:45AM +0000, Christophe Leroy wrote:
>> --- a/arch/powerpc/Makefile
>> +++ b/arch/powerpc/Makefile
>> @@ -112,6 +112,10 @@ KBUILD_LDFLAGS += -m elf$(BITS)$(LDEMULATION)
>> KBUILD_ARFLAGS += --target=elf$(BITS)-$(GNUTARGET)
>> endif
>>
>> +cflags-$(CONFIG_STACKPROTECTOR) += -mstack-protector-guard=tls
>> +cflags-$(CONFIG_STACKPROTECTOR) += -mstack-protector-guard-reg=r2
>> +cflags-$(CONFIG_STACKPROTECTOR) += -mstack-protector-guard-offset=4
>
> This last line is only correct if !CONFIG_THREAD_INFO_IN_TASK; is that
> always true? Add an assert somewhere maybe?
At the time being powerpc doesn't select CONFIG_THREAD_INFO_IN_TASK.
A BUILD_BUG_ON() is added in stackprotector.h
>
>> + /*
>> + * The stack_canary must be located at the offset given to
>> + * -mstack-protector-guard-offset in the Makefile
>> + */
>> + BUILD_BUG_ON(offsetof(struct task_struct, stack_canary) != sizeof(long));
>
> Well this will help :-)
>
> It looks like it will be easy to enable on 64 bit as well.
Will it ? It seems that PPC64 doesn't have r2 pointing to current task
struct, but instead it has r13 pointing to the paca struct. Which means
we should add a canary in the paca struct, and populate it at task
switch from current->stack_canary. Or am I missing something ?
>
>> + /* Try to get a semi random initial value. */
>> + get_random_bytes(&canary, sizeof(canary));
>> + canary ^= mftb();
>> + canary ^= LINUX_VERSION_CODE;
>
> These last two lines are useless (or worse, they may give people the idea
> that they are not!)
Well, the last line is in all arches except x86
The mftb() was suggested by Michael to add some entropy.
x86 does the same sort of thing with their rdtsc()
>
> You should use wait_for_random_bytes I think.
On the 8xx, it takes several minutes before crnd_is_ready(), while
boot_init_stack_canary() is called quite early in start_kernel()
Christophe
^ permalink raw reply
* Re: [PATCH v2 2/2] powerpc/32: add stack protector support
From: Segher Boessenkool @ 2018-09-19 14:32 UTC (permalink / raw)
To: Christophe LEROY
Cc: Benjamin Herrenschmidt, Paul Mackerras, Michael Ellerman,
Ingo Molnar, Peter Zijlstra, linux-kernel, linuxppc-dev
In-Reply-To: <3f5d1937-393c-1105-30a0-72d568a1c190@c-s.fr>
On Wed, Sep 19, 2018 at 04:22:52PM +0200, Christophe LEROY wrote:
> >It looks like it will be easy to enable on 64 bit as well.
>
> Will it ? It seems that PPC64 doesn't have r2 pointing to current task
> struct, but instead it has r13 pointing to the paca struct. Which means
> we should add a canary in the paca struct, and populate it at task
> switch from current->stack_canary. Or am I missing something ?
No, I am just forgetting things :-)
> >>+ /* Try to get a semi random initial value. */
> >>+ get_random_bytes(&canary, sizeof(canary));
> >>+ canary ^= mftb();
> >>+ canary ^= LINUX_VERSION_CODE;
> >
> >These last two lines are useless (or worse, they may give people the idea
> >that they are not!)
>
> Well, the last line is in all arches except x86
> The mftb() was suggested by Michael to add some entropy.
> x86 does the same sort of thing with their rdtsc()
>
> >
> >You should use wait_for_random_bytes I think.
>
> On the 8xx, it takes several minutes before crnd_is_ready(), while
> boot_init_stack_canary() is called quite early in start_kernel()
If you do not provide real entropy to the canary, the canary doesn't help
providing protection as much as you may hope.
Segher
^ permalink raw reply
* Re: [PATCH net-next] net: toshiba: fix return type of ndo_start_xmit function
From: Geoff Levand @ 2018-09-19 16:10 UTC (permalink / raw)
To: YueHaibing, davem, benh, paulus, mpe, kou.ishizaki, andrew,
f.fainelli
Cc: linux-kernel, netdev, linuxppc-dev
In-Reply-To: <20180919102339.13988-1-yuehaibing@huawei.com>
Hi Yue,
On 09/19/2018 03:23 AM, YueHaibing wrote:
> The method ndo_start_xmit() is defined as returning an 'netdev_tx_t',
> which is a typedef for an enum type, so make sure the implementation in
> this driver has returns 'netdev_tx_t' value, and change the function
> return type to netdev_tx_t.
>
> Found by coccinelle.
>
> Signed-off-by: YueHaibing <yuehaibing@huawei.com>
I tested this against Linux-4.19-rc4, and it seemed to work OK.
Please remove the irrelevant line 'Found by coccinelle.' from the
commit message. With that change:
Acked-by: Geoff Levand <geoff@infradead.org>
-Geoff
^ permalink raw reply
* Re: [PATCH] MAINTAINERS: Add PPC contacts for PCI core error handling
From: Bjorn Helgaas @ 2018-09-19 22:14 UTC (permalink / raw)
To: Russell Currey
Cc: linux-pci, linuxppc-dev, Benjamin Herrenschmidt, Paul Mackerras,
Michael Ellerman, linux-kernel, oohall, sbobroff
In-Reply-To: <1020abbb3d8a8f121d25da7327e296cfa1aaa698.camel@russell.cc>
On Wed, Sep 19, 2018 at 11:49:26AM +1000, Russell Currey wrote:
> On Tue, 2018-09-18 at 16:58 -0500, Bjorn Helgaas wrote:
> > On Wed, Sep 12, 2018 at 11:55:26AM -0500, Bjorn Helgaas wrote:
> > > From: Bjorn Helgaas <bhelgaas@google.com>
> > >
> > > The original PCI error recovery functionality was for the powerpc-specific
> > > IBM EEH feature. PCIe subsequently added some similar features, including
> > > AER and DPC, that can be used on any architecture.
> > >
> > > We want the generic PCI core error handling support to work with all of
> > > these features. Driver error recovery callbacks should be independent of
> > > which feature the platform provides.
> > >
> > > Add the generic PCI core error recovery files to the powerpc EEH
> > > MAINTAINERS entry so the powerpc folks will be copied on changes to the
> > > generic PCI error handling strategy.
> > >
> > > Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
> >
> > I applied the following to for-linus for v4.19. Russell, if you want
> > to be removed, let me know and I'll do that.
>
> Oliver's email address for kernel stuff is oohall@gmail.com, I think benh has been
> CCing his IBM address. But other than that,
>
> Acked-by: Russell Currey <ruscur@russell.cc>
I updated Oliver's email address and added your ack, thanks!
^ permalink raw reply
* Re: [PATCH] MAINTAINERS: Add PPC contacts for PCI core error handling
From: Michael Ellerman @ 2018-09-19 23:46 UTC (permalink / raw)
To: Bjorn Helgaas, linux-pci, Russell Currey, linuxppc-dev
Cc: Benjamin Herrenschmidt, Paul Mackerras, linux-kernel
In-Reply-To: <20180912165846.GH118330@bhelgaas-glaptop.roam.corp.google.com>
Bjorn Helgaas <helgaas@kernel.org> writes:
> On Wed, Sep 12, 2018 at 11:55:26AM -0500, Bjorn Helgaas wrote:
>> From: Bjorn Helgaas <bhelgaas@google.com>
>>
>> The original PCI error recovery functionality was for the powerpc-specific
>> IBM EEH feature. PCIe subsequently added some similar features, including
>> AER and DPC, that can be used on any architecture.
>>
>> We want the generic PCI core error handling support to work with all of
>> these features. Driver error recovery callbacks should be independent of
>> which feature the platform provides.
>>
>> Add the generic PCI core error recovery files to the powerpc EEH
>> MAINTAINERS entry so the powerpc folks will be copied on changes to the
>> generic PCI error handling strategy.
>
> I really want to make sure the powerpc folks are plugged into any PCI core
> error handling discussions. Please let me know if there's a better way
> than this patch, or if there are other people who should be added.
Yeah this is a good option.
We powerpc folks also need to do a better job of keeping an eye on PCI
patches, I've asked more of us to subscribe to linux-pci.
cheers
^ permalink raw reply
* Re: [PATCH v2 1/2] sched: move stack_canary field at the top of task_struct
From: Michael Ellerman @ 2018-09-19 23:54 UTC (permalink / raw)
To: Christophe LEROY, Peter Zijlstra
Cc: Benjamin Herrenschmidt, Paul Mackerras, Ingo Molnar, segher,
linux-kernel, linuxppc-dev
In-Reply-To: <f6a36d25-ce19-5d56-69d9-198215a7b9e1@c-s.fr>
Christophe LEROY <christophe.leroy@c-s.fr> writes:
> Le 19/09/2018 =C3=A0 13:58, Peter Zijlstra a =C3=A9crit=C2=A0:
>> On Wed, Sep 19, 2018 at 11:14:43AM +0000, Christophe Leroy wrote:
>>> In order to allow the use of non global stack protector canary,
>>> the stack canary needs to be located at a know offset defined
>>> in Makefile via -mstack-protector-guard-offset.
>>>
>>> On powerpc/32, register r2 points to current task_struct at
>>> all time, the stack_canary located inside task_struct can be
>>> used directly if it is located in a known place.
>>>
>>> In order to allow that, this patch moves the stack_canary field
>>> out of the randomized area of task_struct.
>>=20
>> And you cannot use something like asm-offsets to extract this?
>
> I have not been able to find a way to define the compilation flags AFTER=
=20
> building asm-offsets.h, see https://patchwork.ozlabs.org/patch/971521/
>
> If you have a suggestion, it is welcomed.
Hmm, that's something of a hard problem.
But the stack canary is one of the things we really *do* want to be
randomised, so we should probably try to come up with a solution.
cheers
^ permalink raw reply
page: next (older) | prev (newer) | latest
- recent:[subjects (threaded)|topics (new)|topics (active)]
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox