Re: [PATCH 4/4] powerpc: Allow LD_DEAD_CODE_DATA_ELIMINATION to be selected

2018-04-20 Thread Nicholas Piggin
On Fri, 20 Apr 2018 22:08:27 +0200
Mathieu Malaterre  wrote:

> On Fri, Apr 20, 2018 at 12:41 PM, Nicholas Piggin  wrote:
> > On Fri, 20 Apr 2018 12:00:49 +0200
> > Mathieu Malaterre  wrote:
> >  
> >> On Fri, Apr 20, 2018 at 9:34 AM, Nicholas Piggin  
> >> wrote:  
> >> > This requires further changes to linker script to KEEP some tables
> >> > and wildcard compiler generated sections into the right place. This
> >> > includes pp32 modifications from Christophe Leroy.
> >> >
> >> > When compiling powernv_defconfig with this option:
> >> >
> >> > text   data  bss   decfilename
> >> > 11827621   4810490   1341080   17979191   vmlinux
> >> > 11752437   4598858   1338776   17690071   vmlinux.dcde
> >> >
> >> > Resulting kernel is almost 400kB smaller (and still boots).
> >> >
> >> > [ppc32 numbers here]  
> >>
> >> ^^^
> >>
> >> Do you want somebody else to provide those numbers ?  
> >
> > If you have a booting kernel, yes some more numbers would be good.  
> 
> I've used /boot/config-4.15.0-2-powerpc from my current debian
> package. Rebuild master with and without option, boot ok, load/unload
> module ok.
> 
> $ size nick/vmlinux.with*
>textdata bss dec hex filename
> 7386425 2364370 1425432 11176227 aa8923 nick/vmlinux.with
> 7461457 2475122 1428064 11364643 ad6923 nick/vmlinux.without
> 
> This is not clear why with option the size of kernel is slightly bigger:
> 
> $ du -sk nick/vmlinux.with*
> 124488 nick/vmlinux.with
> 124004 nick/vmlinux.without

Not sure. readelf -S vmlinux may show something.

To really get lots of detail, you can add to the top level Makefile:

LDFLAGS_vmlinux += -M

Then it will print the link map for you and other details. Actually
it will output several times because we link vmlinux 2-3 times, so
just take the last one. There is a lot of data there.



Re: [PATCH v2] powerpc: platform: cell: spufs: Change return type to vm_fault_t

2018-04-20 Thread Matthew Wilcox
On Fri, Apr 20, 2018 at 11:02:39PM +0530, Souptick Joarder wrote:
> Use new return type vm_fault_t for fault handler. For
> now, this is just documenting that the function returns
> a VM_FAULT value rather than an errno. Once all instances
> are converted, vm_fault_t will become a distinct type.
> 
> Reference id -> 1c8f422059ae ("mm: change return type to
> vm_fault_t")
> 
> We are fixing a minor bug, that the error from vm_insert_
> pfn() was being ignored and the effect of this is likely
> to be only felt in OOM situations.
> 
> Signed-off-by: Souptick Joarder 

Reviewed-by: Matthew Wilcox 


[PATCH] pseries/memory-hotplug: Only update DT once per memory DLPAR request

2018-04-20 Thread Nathan Fontenot
The updates to powerpc numa and memory hotplug code now use the
in-kernel LMB array instead of the device tree. This change
allows the pseries memory DLPAR code to only update the device
tree once after successfully handling a DLPAR request.

Prior to the in-kernel LMB array, the numa code looked up the
affinity for memory being added in the device tree, the code
now looks this up in the LMB array. This change means the
memory hotplug code can just update the affinity for an LMB
in the LMB array instead of updating the device tree.

This also provides a savings in kernel memory. When updating the
device tree old properties are never free'ed since there is no
usecount on properties. This behavior leads to a new copy of the
property being allocated every time a LMB is added or removed
(i.e. a request to add 100 LMBs creates 100 new copies of the
property). With this update only a single new property is created
when a DLPAR request completes successfully.

Signed-off-by: Nathan Fontenot 
---
 arch/powerpc/include/asm/drmem.h|5 ++
 arch/powerpc/platforms/pseries/hotplug-memory.c |   55 +++
 2 files changed, 21 insertions(+), 39 deletions(-)

diff --git a/arch/powerpc/include/asm/drmem.h b/arch/powerpc/include/asm/drmem.h
index ce242b9ea8c6..7c1d8e74b25d 100644
--- a/arch/powerpc/include/asm/drmem.h
+++ b/arch/powerpc/include/asm/drmem.h
@@ -99,4 +99,9 @@ void __init walk_drmem_lmbs_early(unsigned long node,
void (*func)(struct drmem_lmb *, const __be32 **));
 #endif
 
+static inline void invalidate_lmb_associativity_index(struct drmem_lmb *lmb)
+{
+   lmb->aa_index = 0x;
+}
+
 #endif /* _ASM_POWERPC_LMB_H */
diff --git a/arch/powerpc/platforms/pseries/hotplug-memory.c 
b/arch/powerpc/platforms/pseries/hotplug-memory.c
index c1578f54c626..9a15d39995e5 100644
--- a/arch/powerpc/platforms/pseries/hotplug-memory.c
+++ b/arch/powerpc/platforms/pseries/hotplug-memory.c
@@ -163,7 +163,7 @@ static u32 find_aa_index(struct device_node *dr_node,
return aa_index;
 }
 
-static u32 lookup_lmb_associativity_index(struct drmem_lmb *lmb)
+static int update_lmb_associativity_index(struct drmem_lmb *lmb)
 {
struct device_node *parent, *lmb_node, *dr_node;
struct property *ala_prop;
@@ -203,43 +203,14 @@ static u32 lookup_lmb_associativity_index(struct 
drmem_lmb *lmb)
aa_index = find_aa_index(dr_node, ala_prop, lmb_assoc);
 
dlpar_free_cc_nodes(lmb_node);
-   return aa_index;
-}
-
-static int dlpar_add_device_tree_lmb(struct drmem_lmb *lmb)
-{
-   int rc, aa_index;
-
-   lmb->flags |= DRCONF_MEM_ASSIGNED;
 
-   aa_index = lookup_lmb_associativity_index(lmb);
if (aa_index < 0) {
-   pr_err("Couldn't find associativity index for drc index %x\n",
-  lmb->drc_index);
-   return aa_index;
+   pr_err("Could not find LMB associativity\n");
+   return -1;
}
 
lmb->aa_index = aa_index;
-
-   rtas_hp_event = true;
-   rc = drmem_update_dt();
-   rtas_hp_event = false;
-
-   return rc;
-}
-
-static int dlpar_remove_device_tree_lmb(struct drmem_lmb *lmb)
-{
-   int rc;
-
-   lmb->flags &= ~DRCONF_MEM_ASSIGNED;
-   lmb->aa_index = 0x;
-
-   rtas_hp_event = true;
-   rc = drmem_update_dt();
-   rtas_hp_event = false;
-
-   return rc;
+   return 0;
 }
 
 static struct memory_block *lmb_to_memblock(struct drmem_lmb *lmb)
@@ -428,7 +399,9 @@ static int dlpar_remove_lmb(struct drmem_lmb *lmb)
/* Update memory regions for memory remove */
memblock_remove(lmb->base_addr, block_sz);
 
-   dlpar_remove_device_tree_lmb(lmb);
+   invalidate_lmb_associativity_index(lmb);
+   lmb->flags &= ~DRCONF_MEM_ASSIGNED;
+
return 0;
 }
 
@@ -688,10 +661,8 @@ static int dlpar_add_lmb(struct drmem_lmb *lmb)
if (lmb->flags & DRCONF_MEM_ASSIGNED)
return -EINVAL;
 
-   rc = dlpar_add_device_tree_lmb(lmb);
+   rc = update_lmb_associativity_index(lmb);
if (rc) {
-   pr_err("Couldn't update device tree for drc index %x\n",
-  lmb->drc_index);
dlpar_release_drc(lmb->drc_index);
return rc;
}
@@ -704,14 +675,14 @@ static int dlpar_add_lmb(struct drmem_lmb *lmb)
/* Add the memory */
rc = add_memory(nid, lmb->base_addr, block_sz);
if (rc) {
-   dlpar_remove_device_tree_lmb(lmb);
+   invalidate_lmb_associativity_index(lmb);
return rc;
}
 
rc = dlpar_online_lmb(lmb);
if (rc) {
remove_memory(nid, lmb->base_addr, block_sz);
-   dlpar_remove_device_tree_lmb(lmb);
+   invalidate_lmb_associativity_index(lmb);
} else {
lmb->flags |= DRCONF_MEM_ASSIGNED;
}
@@ -958,6 +929,12 @@ int 

Re: [PATCH 4/4] powerpc: Allow LD_DEAD_CODE_DATA_ELIMINATION to be selected

2018-04-20 Thread Mathieu Malaterre
On Fri, Apr 20, 2018 at 12:41 PM, Nicholas Piggin  wrote:
> On Fri, 20 Apr 2018 12:00:49 +0200
> Mathieu Malaterre  wrote:
>
>> On Fri, Apr 20, 2018 at 9:34 AM, Nicholas Piggin  wrote:
>> > This requires further changes to linker script to KEEP some tables
>> > and wildcard compiler generated sections into the right place. This
>> > includes pp32 modifications from Christophe Leroy.
>> >
>> > When compiling powernv_defconfig with this option:
>> >
>> > text   data  bss   decfilename
>> > 11827621   4810490   1341080   17979191   vmlinux
>> > 11752437   4598858   1338776   17690071   vmlinux.dcde
>> >
>> > Resulting kernel is almost 400kB smaller (and still boots).
>> >
>> > [ppc32 numbers here]
>>
>> ^^^
>>
>> Do you want somebody else to provide those numbers ?
>
> If you have a booting kernel, yes some more numbers would be good.

I've used /boot/config-4.15.0-2-powerpc from my current debian
package. Rebuild master with and without option, boot ok, load/unload
module ok.

$ size nick/vmlinux.with*
   textdata bss dec hex filename
7386425 2364370 1425432 11176227 aa8923 nick/vmlinux.with
7461457 2475122 1428064 11364643 ad6923 nick/vmlinux.without

This is not clear why with option the size of kernel is slightly bigger:

$ du -sk nick/vmlinux.with*
124488 nick/vmlinux.with
124004 nick/vmlinux.without


> Thanks,
> Nick


[PATCH net] ibmvnic: Clean actual number of RX or TX pools

2018-04-20 Thread Thomas Falcon
Avoid using value stored in the login response buffer when
cleaning TX and RX buffer pools since these could be inconsistent
depending on the device state. Instead use the field in the driver's
private data that tracks the number of active pools.

Signed-off-by: Thomas Falcon 
---
 drivers/net/ethernet/ibm/ibmvnic.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/ibm/ibmvnic.c 
b/drivers/net/ethernet/ibm/ibmvnic.c
index 2df01ad..6e8d6a6 100644
--- a/drivers/net/ethernet/ibm/ibmvnic.c
+++ b/drivers/net/ethernet/ibm/ibmvnic.c
@@ -1128,7 +1128,7 @@ static void clean_rx_pools(struct ibmvnic_adapter 
*adapter)
if (!adapter->rx_pool)
return;
 
-   rx_scrqs = be32_to_cpu(adapter->login_rsp_buf->num_rxadd_subcrqs);
+   rx_scrqs = adapter->num_active_rx_pools;
rx_entries = adapter->req_rx_add_entries_per_subcrq;
 
/* Free any remaining skbs in the rx buffer pools */
@@ -1177,7 +1177,7 @@ static void clean_tx_pools(struct ibmvnic_adapter 
*adapter)
if (!adapter->tx_pool || !adapter->tso_pool)
return;
 
-   tx_scrqs = be32_to_cpu(adapter->login_rsp_buf->num_txsubm_subcrqs);
+   tx_scrqs = adapter->num_active_tx_pools;
 
/* Free any remaining skbs in the tx buffer pools */
for (i = 0; i < tx_scrqs; i++) {
-- 
1.8.3.1



[PATCH v2] powerpc: platform: cell: spufs: Change return type to vm_fault_t

2018-04-20 Thread Souptick Joarder
Use new return type vm_fault_t for fault handler. For
now, this is just documenting that the function returns
a VM_FAULT value rather than an errno. Once all instances
are converted, vm_fault_t will become a distinct type.

Reference id -> 1c8f422059ae ("mm: change return type to
vm_fault_t")

We are fixing a minor bug, that the error from vm_insert_
pfn() was being ignored and the effect of this is likely
to be only felt in OOM situations.

Signed-off-by: Souptick Joarder 
---
 arch/powerpc/platforms/cell/spufs/file.c | 33 +---
 1 file changed, 18 insertions(+), 15 deletions(-)

diff --git a/arch/powerpc/platforms/cell/spufs/file.c 
b/arch/powerpc/platforms/cell/spufs/file.c
index 469bdd0..43e7b93 100644
--- a/arch/powerpc/platforms/cell/spufs/file.c
+++ b/arch/powerpc/platforms/cell/spufs/file.c
@@ -232,12 +232,13 @@ static ssize_t spufs_attr_write(struct file *file, const 
char __user *buf,
return size;
 }
 
-static int
+static vm_fault_t
 spufs_mem_mmap_fault(struct vm_fault *vmf)
 {
struct vm_area_struct *vma = vmf->vma;
struct spu_context *ctx = vma->vm_file->private_data;
unsigned long pfn, offset;
+   vm_fault_t ret;
 
offset = vmf->pgoff << PAGE_SHIFT;
if (offset >= LS_SIZE)
@@ -256,11 +257,11 @@ static ssize_t spufs_attr_write(struct file *file, const 
char __user *buf,
vma->vm_page_prot = pgprot_noncached_wc(vma->vm_page_prot);
pfn = (ctx->spu->local_store_phys + offset) >> PAGE_SHIFT;
}
-   vm_insert_pfn(vma, vmf->address, pfn);
+   ret = vmf_insert_pfn(vma, vmf->address, pfn);
 
spu_release(ctx);
 
-   return VM_FAULT_NOPAGE;
+   return ret;
 }
 
 static int spufs_mem_mmap_access(struct vm_area_struct *vma,
@@ -312,13 +313,14 @@ static int spufs_mem_mmap(struct file *file, struct 
vm_area_struct *vma)
.mmap   = spufs_mem_mmap,
 };
 
-static int spufs_ps_fault(struct vm_fault *vmf,
+static vm_fault_t spufs_ps_fault(struct vm_fault *vmf,
unsigned long ps_offs,
unsigned long ps_size)
 {
struct spu_context *ctx = vmf->vma->vm_file->private_data;
unsigned long area, offset = vmf->pgoff << PAGE_SHIFT;
-   int ret = 0;
+   int err = 0;
+   vm_fault_t ret = VM_FAULT_NOPAGE;
 
spu_context_nospu_trace(spufs_ps_fault__enter, ctx);
 
@@ -349,25 +351,26 @@ static int spufs_ps_fault(struct vm_fault *vmf,
if (ctx->state == SPU_STATE_SAVED) {
up_read(>mm->mmap_sem);
spu_context_nospu_trace(spufs_ps_fault__sleep, ctx);
-   ret = spufs_wait(ctx->run_wq, ctx->state == SPU_STATE_RUNNABLE);
+   err = spufs_wait(ctx->run_wq, ctx->state == SPU_STATE_RUNNABLE);
spu_context_trace(spufs_ps_fault__wake, ctx, ctx->spu);
down_read(>mm->mmap_sem);
} else {
area = ctx->spu->problem_phys + ps_offs;
-   vm_insert_pfn(vmf->vma, vmf->address, (area + offset) >> 
PAGE_SHIFT);
+   ret = vmf_insert_pfn(vmf->vma, vmf->address,
+   (area + offset) >> PAGE_SHIFT);
spu_context_trace(spufs_ps_fault__insert, ctx, ctx->spu);
}
 
-   if (!ret)
+   if (!err)
spu_release(ctx);
 
 refault:
put_spu_context(ctx);
-   return VM_FAULT_NOPAGE;
+   return ret;
 }
 
 #if SPUFS_MMAP_4K
-static int spufs_cntl_mmap_fault(struct vm_fault *vmf)
+static vm_fault_t spufs_cntl_mmap_fault(struct vm_fault *vmf)
 {
return spufs_ps_fault(vmf, 0x4000, SPUFS_CNTL_MAP_SIZE);
 }
@@ -1040,7 +1043,7 @@ static ssize_t spufs_signal1_write(struct file *file, 
const char __user *buf,
return 4;
 }
 
-static int
+static vm_fault_t
 spufs_signal1_mmap_fault(struct vm_fault *vmf)
 {
 #if SPUFS_SIGNAL_MAP_SIZE == 0x1000
@@ -1178,7 +1181,7 @@ static ssize_t spufs_signal2_write(struct file *file, 
const char __user *buf,
 }
 
 #if SPUFS_MMAP_4K
-static int
+static vm_fault_t
 spufs_signal2_mmap_fault(struct vm_fault *vmf)
 {
 #if SPUFS_SIGNAL_MAP_SIZE == 0x1000
@@ -1307,7 +1310,7 @@ static u64 spufs_signal2_type_get(struct spu_context *ctx)
   spufs_signal2_type_set, "%llu\n", SPU_ATTR_ACQUIRE);
 
 #if SPUFS_MMAP_4K
-static int
+static vm_fault_t
 spufs_mss_mmap_fault(struct vm_fault *vmf)
 {
return spufs_ps_fault(vmf, 0x, SPUFS_MSS_MAP_SIZE);
@@ -1369,7 +1372,7 @@ static int spufs_mss_open(struct inode *inode, struct 
file *file)
.llseek  = no_llseek,
 };
 
-static int
+static vm_fault_t
 spufs_psmap_mmap_fault(struct vm_fault *vmf)
 {
return spufs_ps_fault(vmf, 0x, SPUFS_PS_MAP_SIZE);
@@ -1429,7 +1432,7 @@ static int spufs_psmap_open(struct inode *inode, struct 
file *file)
 
 
 #if SPUFS_MMAP_4K
-static int
+static vm_fault_t
 spufs_mfc_mmap_fault(struct vm_fault *vmf)
 {

Re: [PATCH] x86: ipc: fix x32 version of shmid64_ds and msqid64_ds

2018-04-20 Thread Arnd Bergmann
On Fri, Apr 20, 2018 at 3:53 PM, Jeffrey Walton  wrote:
>> +#if !defined(__x86_64__) || !defined(__ilp32__)
>>  #include 
>> +#else
>
> I understand there's some progress having Clang compile the kernel.
> Clang treats __ILP32__ and friends differently than GCC. I believe
> ILP32 shows up just about everywhere there are 32-bit ints, longs and
> pointers. You might find it on Aarch64 or you might find it on MIPS64
> when using Clang.
>
> I think that means this may be a little suspicious:
>
> > +#if !defined(__x86_64__) || !defined(__ilp32__)
>
> I kind of felt LLVM was wandering away from the x32 ABI, but the LLVM
> devs insisted they were within their purview. Also see
> https://lists.llvm.org/pipermail/cfe-dev/2015-December/046300.html.
>
> Sorry about the top-post. I just wanted to pick out that one piece.

It seems I made a typo and it needs to be __ILP32__ rather than
__ilp32__ (corrected that locally, will resend once we have resolved
this).

Aside from that, the #if check seems to be correct to me: this
is an x86-specific header, so it won't ever be seen on other
architectures. On x86-32, __x86_64__ isn't set, so we don't care
about whether __ilp32__ is set or not, and on x86-64 (lp64),
__ilp32__ is never set, so we still get the asm-generic header.

  Arnd


Re: [PATCH] x86: ipc: fix x32 version of shmid64_ds and msqid64_ds

2018-04-20 Thread Jeffrey Walton
Hi Arnd,

One comment here:

> +#if !defined(__x86_64__) || !defined(__ilp32__)
>  #include 
> +#else

I understand there's some progress having Clang compile the kernel.
Clang treats __ILP32__ and friends differently than GCC. I believe
ILP32 shows up just about everywhere there are 32-bit ints, longs and
pointers. You might find it on Aarch64 or you might find it on MIPS64
when using Clang.

I think that means this may be a little suspicious:

> +#if !defined(__x86_64__) || !defined(__ilp32__)

I kind of felt LLVM was wandering away from the x32 ABI, but the LLVM
devs insisted they were within their purview. Also see
https://lists.llvm.org/pipermail/cfe-dev/2015-December/046300.html.

Sorry about the top-post. I just wanted to pick out that one piece.

Jeff

On Fri, Apr 20, 2018 at 9:03 AM, Arnd Bergmann  wrote:
> A bugfix broke the x32 shmid64_ds and msqid64_ds data structure layout
> (as seen from user space)  a few years ago: Originally, __BITS_PER_LONG
> was defined as 64 on x32, so we did not have padding after the 64-bit
> __kernel_time_t fields, After __BITS_PER_LONG got changed to 32,
> applications would observe extra padding.
>
> In other parts of the uapi headers we seem to have a mix of those
> expecting either 32 or 64 on x32 applications, so we can't easily revert
> the path that broke these two structures.
>
> Instead, this patch decouples x32 from the other architectures and moves
> it back into arch specific headers, partially reverting the even older
> commit 73a2d096fdf2 ("x86: remove all now-duplicate header files").
>
> It's not clear whether this ever made any difference, since at least
> glibc carries its own (correct) copy of both of these header files,
> so possibly no application has ever observed the definitions here.
>
> There are other UAPI interfaces that depend on __BITS_PER_LONG and
> that might suffer from the same problem on x32, but I have not tried to
> analyse them in enough detail to be sure. If anyone still cares about x32,
> that may be a useful thing to do.
>
> Fixes: f4b4aae18288 ("x86/headers/uapi: Fix __BITS_PER_LONG value for x32 
> builds")
> Cc: sta...@vger.kernel.org
> Signed-off-by: Arnd Bergmann 
> ---
> This came out of the y2038 ipc syscall series but can be applied
> and backported independently.
> ---
>  arch/x86/include/uapi/asm/msgbuf.h | 29 +++
>  arch/x86/include/uapi/asm/shmbuf.h | 40 
> ++
>  2 files changed, 69 insertions(+)
>
> diff --git a/arch/x86/include/uapi/asm/msgbuf.h 
> b/arch/x86/include/uapi/asm/msgbuf.h
> index 809134c644a6..5f1604961e6d 100644
> --- a/arch/x86/include/uapi/asm/msgbuf.h
> +++ b/arch/x86/include/uapi/asm/msgbuf.h
> @@ -1 +1,30 @@
> +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
> +#ifndef __ASM_X64_MSGBUF_H
> +#define __ASM_X64_MSGBUF_H
> +
> +#if !defined(__x86_64__) || !defined(__ilp32__)
>  #include 
> +#else
> +/*
> + * The msqid64_ds structure for x86 architecture with x32 ABI.
> + *
> + * On x86-32 and x86-64 we can just use the generic definition, but
> + * x32 uses the same binary layout as x86_64, which is differnet
> + * from other 32-bit architectures.
> + */
> +
> +struct msqid64_ds {
> +   struct ipc64_perm msg_perm;
> +   __kernel_time_t msg_stime;  /* last msgsnd time */
> +   __kernel_time_t msg_rtime;  /* last msgrcv time */
> +   __kernel_time_t msg_ctime;  /* last change time */
> +   __kernel_ulong_t msg_cbytes;/* current number of bytes on queue */
> +   __kernel_ulong_t msg_qnum;  /* number of messages in queue */
> +   __kernel_ulong_t msg_qbytes;/* max number of bytes on queue */
> +   __kernel_pid_t msg_lspid;   /* pid of last msgsnd */
> +   __kernel_pid_t msg_lrpid;   /* last receive pid */
> +   __kernel_ulong_t __unused4;
> +   __kernel_ulong_t __unused5;
> +};
> +
> +#endif /* __ASM_GENERIC_MSGBUF_H */
> diff --git a/arch/x86/include/uapi/asm/shmbuf.h 
> b/arch/x86/include/uapi/asm/shmbuf.h
> index 83c05fc2de38..cdd7eec878fa 100644
> --- a/arch/x86/include/uapi/asm/shmbuf.h
> +++ b/arch/x86/include/uapi/asm/shmbuf.h
> @@ -1 +1,41 @@
> +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
> +#ifndef __ASM_X86_SHMBUF_H
> +#define __ASM_X86_SHMBUF_H
> +
> +#if !defined(__x86_64__) || !defined(__ilp32__)
>  #include 
> +#else
> +/*
> + * The shmid64_ds structure for x86 architecture with x32 ABI.
> + *
> + * On x86-32 and x86-64 we can just use the generic definition, but
> + * x32 uses the same binary layout as x86_64, which is differnet
> + * from other 32-bit architectures.
> + */
> +
> +struct shmid64_ds {
> +   struct ipc64_perm   shm_perm;   /* operation perms */
> +   size_t  shm_segsz;  /* size of segment (bytes) */
> +   __kernel_time_t shm_atime;  /* last attach time */
> +   __kernel_time_t shm_dtime;  /* last detach 

[GIT PULL] Please pull powerpc/linux.git powerpc-4.17-3 tag

2018-04-20 Thread Michael Ellerman
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA256

Hi Linus,

Please pull some more powerpc fixes for 4.17:

The following changes since commit 60cc43fc888428bb2f18f08997432d426a243338:

  Linux 4.17-rc1 (2018-04-15 18:24:20 -0700)

are available in the git repository at:

  https://git.kernel.org/pub/scm/linux/kernel/git/powerpc/linux.git 
tags/powerpc-4.17-3

for you to fetch changes up to 56376c5864f8ff4ba7c78a80ae857eee3b1d23d8:

  powerpc/kvm: Fix lockups when running KVM guests on Power8 (2018-04-19 
16:22:20 +1000)

- 
powerpc fixes for 4.17 #3

Fix an off-by-one bug in our alternative asm patching which leads to incorrectly
patched code. This bug lay dormant for nearly 10 years but we finally hit it
due to a recent change.

Fix lockups when running KVM guests on Power8 due to a missing check when a
thread that's running KVM comes out of idle.

Fix an out-of-spec behaviour in the XIVE code (P9 interrupt controller).

Fix EEH handling of bridge MMIO windows.

Prevent crashes in our RFI fallback flush handler if firmware didn't tell us the
size of the L1 cache (only seen on simulators).

Thanks to:
  Benjamin Herrenschmidt, Madhavan Srinivasan, Michael Neuling.

- 
Benjamin Herrenschmidt (1):
  powerpc/xive: Fix trying to "push" an already active pool VP

Madhavan Srinivasan (1):
  powerpc/64s: Default l1d_size to 64K in RFI fallback flush

Michael Ellerman (2):
  powerpc/lib: Fix off-by-one in alternate feature patching
  powerpc/kvm: Fix lockups when running KVM guests on Power8

Michael Neuling (1):
  powerpc/eeh: Fix enabling bridge MMIO windows

 arch/powerpc/kernel/eeh_pe.c  |  3 ++-
 arch/powerpc/kernel/idle_book3s.S |  4 ++--
 arch/powerpc/kernel/setup_64.c| 11 +++
 arch/powerpc/lib/feature-fixups.c |  2 +-
 arch/powerpc/sysdev/xive/native.c |  4 
 5 files changed, 20 insertions(+), 4 deletions(-)
-BEGIN PGP SIGNATURE-

iQIcBAEBCAAGBQJa2er8AAoJEFHr6jzI4aWAnc4P/2uaDmQ4NN9ETvsn11Ii6y9B
umuQ/TnFmS8piP9LrLyh5A0DNEheEizLf44qJDaXfgnJtV2+ZgKeW8kyzpdOYH1F
B6+Rq25gZ2ItBrKv8vrcfGyBFplVfSfg3KO/NC2tBoB/COCKA2lj6lxo1CvZ8BLq
Ov05mm2grmQ20XJgFQjAiK+GT6JKsra5Vc8WcpX3xj4DOP9yXvJpm5Ui+1RpqK0U
ZuKHocSKUQdIvQBuPcrqU6IVHN51lQLtvb//s3TUpMRS7sb7/y4VHBou93FsT8LZ
rjNKM4104u79ZN7SERRF17bqdY0fgmqHeAB1U8lxP8QvYo14z5ix99d9KjunDHt2
IRI25AhgHo4dfdcFr7sl3fg+85/Njwj4T7a2KPGw0FW4dIwPklodYzxnlVpbBQMB
92J8fKC6G0UsVza2KLySuGY1AO1FvAXw+84JfeqpBsShpH7op2QSa7GjxgF7YeXz
w0guFuUKBOlmiyuuTaq7HPGNVZBqmyAIpTaTKmv/L7pnaOY/fL14y4zPyKDav9VN
E6wLxqh0b1kOMaOzZelps8Isrd/5LCx9wmv6TnZCjGazoy6GtV0NTt4Nl8l0wjJW
uvDm8h6MOnwLG282OyKBJee79vBxKUey3cl41Y5DCkqJDmymnqTCCn/lF24zJ3nf
qpYttmW/n2nfdR/VSEZM
=UKi3
-END PGP SIGNATURE-


Re: [PATCH 4/4] powerpc: Allow LD_DEAD_CODE_DATA_ELIMINATION to be selected

2018-04-20 Thread Christophe LEROY



Le 20/04/2018 à 12:36, Nicholas Piggin a écrit :

On Fri, 20 Apr 2018 12:01:34 +0200
Christophe LEROY  wrote:


Le 20/04/2018 à 09:34, Nicholas Piggin a écrit :

This requires further changes to linker script to KEEP some tables
and wildcard compiler generated sections into the right place. This
includes pp32 modifications from Christophe Leroy.

When compiling powernv_defconfig with this option:

text   data  bss   decfilename
11827621   4810490   1341080   17979191   vmlinux
11752437   4598858   1338776   17690071   vmlinux.dcde

Resulting kernel is almost 400kB smaller (and still boots).

[ppc32 numbers here]


Here a few results, obtained with readelf -l vmlinux | grep LOAD

First val is filesz, second is memsz, for each config you get the size 
before and after activation of LD_DCDE, and the difference between the two.


mpc83xx_defconfig:
Before: 0x5ecfe0 0x60b69c
After:  0x5d2fe0 0x5f04a4
Diff:   0x01a000 0x01b4c8

mpc83xx_defconfig without CONFIG_MODULE:
Before: 0x5c1040 0x5e0614
After:  0x55f040 0x57d314
Diff:   0x062000 0x063300

mpc885_ads_defconfig:
Before: 0x36eda4 0x38da04
After:  0x316da4 0x333764
Diff:   0x058000 0x05a2a0

Custom mpc885 config:
Before: 0x719948 0x78bc34
After:  0x6b9948 0x72a99c
Diff:   0x06 0x061298

Custom mpc8321 config:
Before: 0x70f714 0x7d766c
After:  0x6af714 0x7763ec
Diff:   0x06 0x061280





Signed-off-by: Nicholas Piggin 
---
   arch/powerpc/Kconfig  |  1 +
   arch/powerpc/kernel/vmlinux.lds.S | 22 +++---
   2 files changed, 12 insertions(+), 11 deletions(-)

diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
index c32a181a7cbb..ee6dbe2efc8b 100644
--- a/arch/powerpc/Kconfig
+++ b/arch/powerpc/Kconfig
@@ -205,6 +205,7 @@ config PPC
select HAVE_KPROBES
select HAVE_KPROBES_ON_FTRACE
select HAVE_KRETPROBES
+   select HAVE_LD_DEAD_CODE_DATA_ELIMINATION
select HAVE_LIVEPATCH   if HAVE_DYNAMIC_FTRACE_WITH_REGS
select HAVE_MEMBLOCK
select HAVE_MEMBLOCK_NODE_MAP
diff --git a/arch/powerpc/kernel/vmlinux.lds.S 
b/arch/powerpc/kernel/vmlinux.lds.S
index c8af90ff49f0..89381dc959ce 100644
--- a/arch/powerpc/kernel/vmlinux.lds.S
+++ b/arch/powerpc/kernel/vmlinux.lds.S
@@ -89,7 +89,7 @@ SECTIONS
 */
.text BLOCK(0) : AT(ADDR(.text) - LOAD_OFFSET) {
   #ifdef CONFIG_LD_HEAD_STUB_CATCH
-   *(.linker_stub_catch);
+   KEEP(*(.linker_stub_catch));
. = . ;
   #endif
   
@@ -98,7 +98,7 @@ SECTIONS

ALIGN_FUNCTION();
   #endif
/* careful! __ftr_alt_* sections need to be close to .text */
-   *(.text.hot .text .text.fixup .text.unlikely .fixup __ftr_alt_* 
.ref.text);
+   *(.text.hot .text .text.[0-9a-zA-Z_]* .text.fixup 
.text.unlikely .fixup __ftr_alt_* .ref.text);


Why not use TEXT_MAIN here instead of .text .text.[0-9a-zA-Z_]* ?


It's from my early patch before we added those in the generic linker
script. Yes your version looks nicer.

Thanks,
Nick



[PATCH] x86: ipc: fix x32 version of shmid64_ds and msqid64_ds

2018-04-20 Thread Arnd Bergmann
A bugfix broke the x32 shmid64_ds and msqid64_ds data structure layout
(as seen from user space)  a few years ago: Originally, __BITS_PER_LONG
was defined as 64 on x32, so we did not have padding after the 64-bit
__kernel_time_t fields, After __BITS_PER_LONG got changed to 32,
applications would observe extra padding.

In other parts of the uapi headers we seem to have a mix of those
expecting either 32 or 64 on x32 applications, so we can't easily revert
the path that broke these two structures.

Instead, this patch decouples x32 from the other architectures and moves
it back into arch specific headers, partially reverting the even older
commit 73a2d096fdf2 ("x86: remove all now-duplicate header files").

It's not clear whether this ever made any difference, since at least
glibc carries its own (correct) copy of both of these header files,
so possibly no application has ever observed the definitions here.

There are other UAPI interfaces that depend on __BITS_PER_LONG and
that might suffer from the same problem on x32, but I have not tried to
analyse them in enough detail to be sure. If anyone still cares about x32,
that may be a useful thing to do.

Fixes: f4b4aae18288 ("x86/headers/uapi: Fix __BITS_PER_LONG value for x32 
builds")
Cc: sta...@vger.kernel.org
Signed-off-by: Arnd Bergmann 
---
This came out of the y2038 ipc syscall series but can be applied
and backported independently.
---
 arch/x86/include/uapi/asm/msgbuf.h | 29 +++
 arch/x86/include/uapi/asm/shmbuf.h | 40 ++
 2 files changed, 69 insertions(+)

diff --git a/arch/x86/include/uapi/asm/msgbuf.h 
b/arch/x86/include/uapi/asm/msgbuf.h
index 809134c644a6..5f1604961e6d 100644
--- a/arch/x86/include/uapi/asm/msgbuf.h
+++ b/arch/x86/include/uapi/asm/msgbuf.h
@@ -1 +1,30 @@
+/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
+#ifndef __ASM_X64_MSGBUF_H
+#define __ASM_X64_MSGBUF_H
+
+#if !defined(__x86_64__) || !defined(__ilp32__)
 #include 
+#else
+/*
+ * The msqid64_ds structure for x86 architecture with x32 ABI.
+ *
+ * On x86-32 and x86-64 we can just use the generic definition, but
+ * x32 uses the same binary layout as x86_64, which is differnet
+ * from other 32-bit architectures.
+ */
+
+struct msqid64_ds {
+   struct ipc64_perm msg_perm;
+   __kernel_time_t msg_stime;  /* last msgsnd time */
+   __kernel_time_t msg_rtime;  /* last msgrcv time */
+   __kernel_time_t msg_ctime;  /* last change time */
+   __kernel_ulong_t msg_cbytes;/* current number of bytes on queue */
+   __kernel_ulong_t msg_qnum;  /* number of messages in queue */
+   __kernel_ulong_t msg_qbytes;/* max number of bytes on queue */
+   __kernel_pid_t msg_lspid;   /* pid of last msgsnd */
+   __kernel_pid_t msg_lrpid;   /* last receive pid */
+   __kernel_ulong_t __unused4;
+   __kernel_ulong_t __unused5;
+};
+
+#endif /* __ASM_GENERIC_MSGBUF_H */
diff --git a/arch/x86/include/uapi/asm/shmbuf.h 
b/arch/x86/include/uapi/asm/shmbuf.h
index 83c05fc2de38..cdd7eec878fa 100644
--- a/arch/x86/include/uapi/asm/shmbuf.h
+++ b/arch/x86/include/uapi/asm/shmbuf.h
@@ -1 +1,41 @@
+/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
+#ifndef __ASM_X86_SHMBUF_H
+#define __ASM_X86_SHMBUF_H
+
+#if !defined(__x86_64__) || !defined(__ilp32__)
 #include 
+#else
+/*
+ * The shmid64_ds structure for x86 architecture with x32 ABI.
+ *
+ * On x86-32 and x86-64 we can just use the generic definition, but
+ * x32 uses the same binary layout as x86_64, which is differnet
+ * from other 32-bit architectures.
+ */
+
+struct shmid64_ds {
+   struct ipc64_perm   shm_perm;   /* operation perms */
+   size_t  shm_segsz;  /* size of segment (bytes) */
+   __kernel_time_t shm_atime;  /* last attach time */
+   __kernel_time_t shm_dtime;  /* last detach time */
+   __kernel_time_t shm_ctime;  /* last change time */
+   __kernel_pid_t  shm_cpid;   /* pid of creator */
+   __kernel_pid_t  shm_lpid;   /* pid of last operator */
+   __kernel_ulong_tshm_nattch; /* no. of current attaches */
+   __kernel_ulong_t__unused4;
+   __kernel_ulong_t__unused5;
+};
+
+struct shminfo64 {
+   __kernel_ulong_tshmmax;
+   __kernel_ulong_tshmmin;
+   __kernel_ulong_tshmmni;
+   __kernel_ulong_tshmseg;
+   __kernel_ulong_tshmall;
+   __kernel_ulong_t__unused1;
+   __kernel_ulong_t__unused2;
+   __kernel_ulong_t__unused3;
+   __kernel_ulong_t__unused4;
+};
+
+#endif /* __ASM_X86_SHMBUF_H */
-- 
2.9.0



Re: [PATCH 4/4] powerpc: Allow LD_DEAD_CODE_DATA_ELIMINATION to be selected

2018-04-20 Thread Nicholas Piggin
On Fri, 20 Apr 2018 12:00:49 +0200
Mathieu Malaterre  wrote:

> On Fri, Apr 20, 2018 at 9:34 AM, Nicholas Piggin  wrote:
> > This requires further changes to linker script to KEEP some tables
> > and wildcard compiler generated sections into the right place. This
> > includes pp32 modifications from Christophe Leroy.
> >
> > When compiling powernv_defconfig with this option:
> >
> > text   data  bss   decfilename
> > 11827621   4810490   1341080   17979191   vmlinux
> > 11752437   4598858   1338776   17690071   vmlinux.dcde
> >
> > Resulting kernel is almost 400kB smaller (and still boots).
> >
> > [ppc32 numbers here]  
> 
> ^^^
> 
> Do you want somebody else to provide those numbers ?

If you have a booting kernel, yes some more numbers would be good.

Thanks,
Nick


Re: [PATCH 4/4] powerpc: Allow LD_DEAD_CODE_DATA_ELIMINATION to be selected

2018-04-20 Thread Christophe LEROY



Le 20/04/2018 à 09:34, Nicholas Piggin a écrit :

This requires further changes to linker script to KEEP some tables
and wildcard compiler generated sections into the right place. This
includes pp32 modifications from Christophe Leroy.

When compiling powernv_defconfig with this option:

text   data  bss   decfilename
11827621   4810490   1341080   17979191   vmlinux
11752437   4598858   1338776   17690071   vmlinux.dcde

Resulting kernel is almost 400kB smaller (and still boots).

[ppc32 numbers here]

Signed-off-by: Nicholas Piggin 


Tested-by: Christophe Leroy 

Tested on MPC885 and MPC8321E, CONFIG_MODULE unset.

Christophe


---
  arch/powerpc/Kconfig  |  1 +
  arch/powerpc/kernel/vmlinux.lds.S | 22 +++---
  2 files changed, 12 insertions(+), 11 deletions(-)

diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
index c32a181a7cbb..ee6dbe2efc8b 100644
--- a/arch/powerpc/Kconfig
+++ b/arch/powerpc/Kconfig
@@ -205,6 +205,7 @@ config PPC
select HAVE_KPROBES
select HAVE_KPROBES_ON_FTRACE
select HAVE_KRETPROBES
+   select HAVE_LD_DEAD_CODE_DATA_ELIMINATION
select HAVE_LIVEPATCH   if HAVE_DYNAMIC_FTRACE_WITH_REGS
select HAVE_MEMBLOCK
select HAVE_MEMBLOCK_NODE_MAP
diff --git a/arch/powerpc/kernel/vmlinux.lds.S 
b/arch/powerpc/kernel/vmlinux.lds.S
index c8af90ff49f0..89381dc959ce 100644
--- a/arch/powerpc/kernel/vmlinux.lds.S
+++ b/arch/powerpc/kernel/vmlinux.lds.S
@@ -89,7 +89,7 @@ SECTIONS
 */
.text BLOCK(0) : AT(ADDR(.text) - LOAD_OFFSET) {
  #ifdef CONFIG_LD_HEAD_STUB_CATCH
-   *(.linker_stub_catch);
+   KEEP(*(.linker_stub_catch));
. = . ;
  #endif
  
@@ -98,7 +98,7 @@ SECTIONS

ALIGN_FUNCTION();
  #endif
/* careful! __ftr_alt_* sections need to be close to .text */
-   *(.text.hot .text .text.fixup .text.unlikely .fixup __ftr_alt_* 
.ref.text);
+   *(.text.hot .text .text.[0-9a-zA-Z_]* .text.fixup 
.text.unlikely .fixup __ftr_alt_* .ref.text);
SCHED_TEXT
CPUIDLE_TEXT
LOCK_TEXT
@@ -170,10 +170,10 @@ SECTIONS
.init.data : AT(ADDR(.init.data) - LOAD_OFFSET) {
INIT_DATA
__vtop_table_begin = .;
-   *(.vtop_fixup);
+   KEEP(*(.vtop_fixup));
__vtop_table_end = .;
__ptov_table_begin = .;
-   *(.ptov_fixup);
+   KEEP(*(.ptov_fixup));
__ptov_table_end = .;
}
  
@@ -194,26 +194,26 @@ SECTIONS

. = ALIGN(8);
__ftr_fixup : AT(ADDR(__ftr_fixup) - LOAD_OFFSET) {
__start___ftr_fixup = .;
-   *(__ftr_fixup)
+   KEEP(*(__ftr_fixup))
__stop___ftr_fixup = .;
}
. = ALIGN(8);
__mmu_ftr_fixup : AT(ADDR(__mmu_ftr_fixup) - LOAD_OFFSET) {
__start___mmu_ftr_fixup = .;
-   *(__mmu_ftr_fixup)
+   KEEP(*(__mmu_ftr_fixup))
__stop___mmu_ftr_fixup = .;
}
. = ALIGN(8);
__lwsync_fixup : AT(ADDR(__lwsync_fixup) - LOAD_OFFSET) {
__start___lwsync_fixup = .;
-   *(__lwsync_fixup)
+   KEEP(*(__lwsync_fixup))
__stop___lwsync_fixup = .;
}
  #ifdef CONFIG_PPC64
. = ALIGN(8);
__fw_ftr_fixup : AT(ADDR(__fw_ftr_fixup) - LOAD_OFFSET) {
__start___fw_ftr_fixup = .;
-   *(__fw_ftr_fixup)
+   KEEP(*(__fw_ftr_fixup))
__stop___fw_ftr_fixup = .;
}
  #endif
@@ -226,7 +226,7 @@ SECTIONS
. = ALIGN(8);
.machine.desc : AT(ADDR(.machine.desc) - LOAD_OFFSET) {
__machine_desc_start = . ;
-   *(.machine.desc)
+   KEEP(*(.machine.desc))
__machine_desc_end = . ;
}
  #ifdef CONFIG_RELOCATABLE
@@ -274,7 +274,7 @@ SECTIONS
.data : AT(ADDR(.data) - LOAD_OFFSET) {
DATA_DATA
*(.data.rel*)
-   *(.sdata)
+   *(SDATA_MAIN)
*(.sdata2)
*(.got.plt) *(.got)
*(.plt)
@@ -289,7 +289,7 @@ SECTIONS
  
  	.opd : AT(ADDR(.opd) - LOAD_OFFSET) {

__start_opd = .;
-   *(.opd)
+   KEEP(*(.opd))
__end_opd = .;
}
  



Re: [PATCH 4/4] powerpc: Allow LD_DEAD_CODE_DATA_ELIMINATION to be selected

2018-04-20 Thread Nicholas Piggin
On Fri, 20 Apr 2018 12:01:34 +0200
Christophe LEROY  wrote:

> Le 20/04/2018 à 09:34, Nicholas Piggin a écrit :
> > This requires further changes to linker script to KEEP some tables
> > and wildcard compiler generated sections into the right place. This
> > includes pp32 modifications from Christophe Leroy.
> > 
> > When compiling powernv_defconfig with this option:
> > 
> > text   data  bss   decfilename
> > 11827621   4810490   1341080   17979191   vmlinux
> > 11752437   4598858   1338776   17690071   vmlinux.dcde
> > 
> > Resulting kernel is almost 400kB smaller (and still boots).
> > 
> > [ppc32 numbers here]
> > 
> > Signed-off-by: Nicholas Piggin 
> > ---
> >   arch/powerpc/Kconfig  |  1 +
> >   arch/powerpc/kernel/vmlinux.lds.S | 22 +++---
> >   2 files changed, 12 insertions(+), 11 deletions(-)
> > 
> > diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
> > index c32a181a7cbb..ee6dbe2efc8b 100644
> > --- a/arch/powerpc/Kconfig
> > +++ b/arch/powerpc/Kconfig
> > @@ -205,6 +205,7 @@ config PPC
> > select HAVE_KPROBES
> > select HAVE_KPROBES_ON_FTRACE
> > select HAVE_KRETPROBES
> > +   select HAVE_LD_DEAD_CODE_DATA_ELIMINATION
> > select HAVE_LIVEPATCH   if HAVE_DYNAMIC_FTRACE_WITH_REGS
> > select HAVE_MEMBLOCK
> > select HAVE_MEMBLOCK_NODE_MAP
> > diff --git a/arch/powerpc/kernel/vmlinux.lds.S 
> > b/arch/powerpc/kernel/vmlinux.lds.S
> > index c8af90ff49f0..89381dc959ce 100644
> > --- a/arch/powerpc/kernel/vmlinux.lds.S
> > +++ b/arch/powerpc/kernel/vmlinux.lds.S
> > @@ -89,7 +89,7 @@ SECTIONS
> >  */
> > .text BLOCK(0) : AT(ADDR(.text) - LOAD_OFFSET) {
> >   #ifdef CONFIG_LD_HEAD_STUB_CATCH
> > -   *(.linker_stub_catch);
> > +   KEEP(*(.linker_stub_catch));
> > . = . ;
> >   #endif
> >   
> > @@ -98,7 +98,7 @@ SECTIONS
> > ALIGN_FUNCTION();
> >   #endif
> > /* careful! __ftr_alt_* sections need to be close to .text */
> > -   *(.text.hot .text .text.fixup .text.unlikely .fixup __ftr_alt_* 
> > .ref.text);
> > +   *(.text.hot .text .text.[0-9a-zA-Z_]* .text.fixup 
> > .text.unlikely .fixup __ftr_alt_* .ref.text);  
> 
> Why not use TEXT_MAIN here instead of .text .text.[0-9a-zA-Z_]* ?

It's from my early patch before we added those in the generic linker
script. Yes your version looks nicer.

Thanks,
Nick


Re: [PATCH 0/4] LD_DEAD_CODE_DATA_ELIMINATION fixes and enabling for powerpc

2018-04-20 Thread Christophe LEROY



Le 20/04/2018 à 09:34, Nicholas Piggin a écrit :

A few people have been interested in this again. And I promised
if it remains dead code it should be removed, so I would like to
have another try.

I think I got snagged on the modules problem last time and did
not take the time to work it out, this time I just turned off the
compile options for modules (the linker option was never set anyway
so no loss).

This includes some linker script catches and ideas from others, I
didn't documnt them all, but thanks for looking.


Thanks a lot.

It works well on both my 8xx and 83xx targets. I don't have 
CONFIG_MODULE set.


Christophe



I would be interested to help other archs get this working too, if
anybody needs some help.

Thanks,
Nick

Nicholas Piggin (4):
   kbuild: Fix asm-generic/vmlinux.lds.h for
 LD_DEAD_CODE_DATA_ELIMINATION
   kbuild: LD_DEAD_CODE_DATA_ELIMINATION no
 -ffunction-sections/-fdata-sections for module build
   kbuild: Allow LD_DEAD_CODE_DATA_ELIMINATION to be selectable if
 enabled
   powerpc: Allow LD_DEAD_CODE_DATA_ELIMINATION to be selected

  Makefile  |  4 +--
  arch/Kconfig  | 15 --
  arch/powerpc/Kconfig  |  1 +
  arch/powerpc/kernel/vmlinux.lds.S | 22 +++---
  include/asm-generic/vmlinux.lds.h | 49 ++-
  init/Kconfig  | 27 +
  6 files changed, 70 insertions(+), 48 deletions(-)



Re: [PATCH 4/4] powerpc: Allow LD_DEAD_CODE_DATA_ELIMINATION to be selected

2018-04-20 Thread Christophe LEROY



Le 20/04/2018 à 09:34, Nicholas Piggin a écrit :

This requires further changes to linker script to KEEP some tables
and wildcard compiler generated sections into the right place. This
includes pp32 modifications from Christophe Leroy.

When compiling powernv_defconfig with this option:

text   data  bss   decfilename
11827621   4810490   1341080   17979191   vmlinux
11752437   4598858   1338776   17690071   vmlinux.dcde

Resulting kernel is almost 400kB smaller (and still boots).

[ppc32 numbers here]

Signed-off-by: Nicholas Piggin 
---
  arch/powerpc/Kconfig  |  1 +
  arch/powerpc/kernel/vmlinux.lds.S | 22 +++---
  2 files changed, 12 insertions(+), 11 deletions(-)

diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
index c32a181a7cbb..ee6dbe2efc8b 100644
--- a/arch/powerpc/Kconfig
+++ b/arch/powerpc/Kconfig
@@ -205,6 +205,7 @@ config PPC
select HAVE_KPROBES
select HAVE_KPROBES_ON_FTRACE
select HAVE_KRETPROBES
+   select HAVE_LD_DEAD_CODE_DATA_ELIMINATION
select HAVE_LIVEPATCH   if HAVE_DYNAMIC_FTRACE_WITH_REGS
select HAVE_MEMBLOCK
select HAVE_MEMBLOCK_NODE_MAP
diff --git a/arch/powerpc/kernel/vmlinux.lds.S 
b/arch/powerpc/kernel/vmlinux.lds.S
index c8af90ff49f0..89381dc959ce 100644
--- a/arch/powerpc/kernel/vmlinux.lds.S
+++ b/arch/powerpc/kernel/vmlinux.lds.S
@@ -89,7 +89,7 @@ SECTIONS
 */
.text BLOCK(0) : AT(ADDR(.text) - LOAD_OFFSET) {
  #ifdef CONFIG_LD_HEAD_STUB_CATCH
-   *(.linker_stub_catch);
+   KEEP(*(.linker_stub_catch));
. = . ;
  #endif
  
@@ -98,7 +98,7 @@ SECTIONS

ALIGN_FUNCTION();
  #endif
/* careful! __ftr_alt_* sections need to be close to .text */
-   *(.text.hot .text .text.fixup .text.unlikely .fixup __ftr_alt_* 
.ref.text);
+   *(.text.hot .text .text.[0-9a-zA-Z_]* .text.fixup 
.text.unlikely .fixup __ftr_alt_* .ref.text);


Why not use TEXT_MAIN here instead of .text .text.[0-9a-zA-Z_]* ?

Christophe


SCHED_TEXT
CPUIDLE_TEXT
LOCK_TEXT
@@ -170,10 +170,10 @@ SECTIONS
.init.data : AT(ADDR(.init.data) - LOAD_OFFSET) {
INIT_DATA
__vtop_table_begin = .;
-   *(.vtop_fixup);
+   KEEP(*(.vtop_fixup));
__vtop_table_end = .;
__ptov_table_begin = .;
-   *(.ptov_fixup);
+   KEEP(*(.ptov_fixup));
__ptov_table_end = .;
}
  
@@ -194,26 +194,26 @@ SECTIONS

. = ALIGN(8);
__ftr_fixup : AT(ADDR(__ftr_fixup) - LOAD_OFFSET) {
__start___ftr_fixup = .;
-   *(__ftr_fixup)
+   KEEP(*(__ftr_fixup))
__stop___ftr_fixup = .;
}
. = ALIGN(8);
__mmu_ftr_fixup : AT(ADDR(__mmu_ftr_fixup) - LOAD_OFFSET) {
__start___mmu_ftr_fixup = .;
-   *(__mmu_ftr_fixup)
+   KEEP(*(__mmu_ftr_fixup))
__stop___mmu_ftr_fixup = .;
}
. = ALIGN(8);
__lwsync_fixup : AT(ADDR(__lwsync_fixup) - LOAD_OFFSET) {
__start___lwsync_fixup = .;
-   *(__lwsync_fixup)
+   KEEP(*(__lwsync_fixup))
__stop___lwsync_fixup = .;
}
  #ifdef CONFIG_PPC64
. = ALIGN(8);
__fw_ftr_fixup : AT(ADDR(__fw_ftr_fixup) - LOAD_OFFSET) {
__start___fw_ftr_fixup = .;
-   *(__fw_ftr_fixup)
+   KEEP(*(__fw_ftr_fixup))
__stop___fw_ftr_fixup = .;
}
  #endif
@@ -226,7 +226,7 @@ SECTIONS
. = ALIGN(8);
.machine.desc : AT(ADDR(.machine.desc) - LOAD_OFFSET) {
__machine_desc_start = . ;
-   *(.machine.desc)
+   KEEP(*(.machine.desc))
__machine_desc_end = . ;
}
  #ifdef CONFIG_RELOCATABLE
@@ -274,7 +274,7 @@ SECTIONS
.data : AT(ADDR(.data) - LOAD_OFFSET) {
DATA_DATA
*(.data.rel*)
-   *(.sdata)
+   *(SDATA_MAIN)
*(.sdata2)
*(.got.plt) *(.got)
*(.plt)
@@ -289,7 +289,7 @@ SECTIONS
  
  	.opd : AT(ADDR(.opd) - LOAD_OFFSET) {

__start_opd = .;
-   *(.opd)
+   KEEP(*(.opd))
__end_opd = .;
}
  



Re: [PATCH 4/4] powerpc: Allow LD_DEAD_CODE_DATA_ELIMINATION to be selected

2018-04-20 Thread Mathieu Malaterre
On Fri, Apr 20, 2018 at 9:34 AM, Nicholas Piggin  wrote:
> This requires further changes to linker script to KEEP some tables
> and wildcard compiler generated sections into the right place. This
> includes pp32 modifications from Christophe Leroy.
>
> When compiling powernv_defconfig with this option:
>
> text   data  bss   decfilename
> 11827621   4810490   1341080   17979191   vmlinux
> 11752437   4598858   1338776   17690071   vmlinux.dcde
>
> Resulting kernel is almost 400kB smaller (and still boots).
>
> [ppc32 numbers here]

^^^

Do you want somebody else to provide those numbers ?

> Signed-off-by: Nicholas Piggin 
> ---
>  arch/powerpc/Kconfig  |  1 +
>  arch/powerpc/kernel/vmlinux.lds.S | 22 +++---
>  2 files changed, 12 insertions(+), 11 deletions(-)
>
> diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
> index c32a181a7cbb..ee6dbe2efc8b 100644
> --- a/arch/powerpc/Kconfig
> +++ b/arch/powerpc/Kconfig
> @@ -205,6 +205,7 @@ config PPC
> select HAVE_KPROBES
> select HAVE_KPROBES_ON_FTRACE
> select HAVE_KRETPROBES
> +   select HAVE_LD_DEAD_CODE_DATA_ELIMINATION
> select HAVE_LIVEPATCH   if 
> HAVE_DYNAMIC_FTRACE_WITH_REGS
> select HAVE_MEMBLOCK
> select HAVE_MEMBLOCK_NODE_MAP
> diff --git a/arch/powerpc/kernel/vmlinux.lds.S 
> b/arch/powerpc/kernel/vmlinux.lds.S
> index c8af90ff49f0..89381dc959ce 100644
> --- a/arch/powerpc/kernel/vmlinux.lds.S
> +++ b/arch/powerpc/kernel/vmlinux.lds.S
> @@ -89,7 +89,7 @@ SECTIONS
>  */
> .text BLOCK(0) : AT(ADDR(.text) - LOAD_OFFSET) {
>  #ifdef CONFIG_LD_HEAD_STUB_CATCH
> -   *(.linker_stub_catch);
> +   KEEP(*(.linker_stub_catch));
> . = . ;
>  #endif
>
> @@ -98,7 +98,7 @@ SECTIONS
> ALIGN_FUNCTION();
>  #endif
> /* careful! __ftr_alt_* sections need to be close to .text */
> -   *(.text.hot .text .text.fixup .text.unlikely .fixup 
> __ftr_alt_* .ref.text);
> +   *(.text.hot .text .text.[0-9a-zA-Z_]* .text.fixup 
> .text.unlikely .fixup __ftr_alt_* .ref.text);
> SCHED_TEXT
> CPUIDLE_TEXT
> LOCK_TEXT
> @@ -170,10 +170,10 @@ SECTIONS
> .init.data : AT(ADDR(.init.data) - LOAD_OFFSET) {
> INIT_DATA
> __vtop_table_begin = .;
> -   *(.vtop_fixup);
> +   KEEP(*(.vtop_fixup));
> __vtop_table_end = .;
> __ptov_table_begin = .;
> -   *(.ptov_fixup);
> +   KEEP(*(.ptov_fixup));
> __ptov_table_end = .;
> }
>
> @@ -194,26 +194,26 @@ SECTIONS
> . = ALIGN(8);
> __ftr_fixup : AT(ADDR(__ftr_fixup) - LOAD_OFFSET) {
> __start___ftr_fixup = .;
> -   *(__ftr_fixup)
> +   KEEP(*(__ftr_fixup))
> __stop___ftr_fixup = .;
> }
> . = ALIGN(8);
> __mmu_ftr_fixup : AT(ADDR(__mmu_ftr_fixup) - LOAD_OFFSET) {
> __start___mmu_ftr_fixup = .;
> -   *(__mmu_ftr_fixup)
> +   KEEP(*(__mmu_ftr_fixup))
> __stop___mmu_ftr_fixup = .;
> }
> . = ALIGN(8);
> __lwsync_fixup : AT(ADDR(__lwsync_fixup) - LOAD_OFFSET) {
> __start___lwsync_fixup = .;
> -   *(__lwsync_fixup)
> +   KEEP(*(__lwsync_fixup))
> __stop___lwsync_fixup = .;
> }
>  #ifdef CONFIG_PPC64
> . = ALIGN(8);
> __fw_ftr_fixup : AT(ADDR(__fw_ftr_fixup) - LOAD_OFFSET) {
> __start___fw_ftr_fixup = .;
> -   *(__fw_ftr_fixup)
> +   KEEP(*(__fw_ftr_fixup))
> __stop___fw_ftr_fixup = .;
> }
>  #endif
> @@ -226,7 +226,7 @@ SECTIONS
> . = ALIGN(8);
> .machine.desc : AT(ADDR(.machine.desc) - LOAD_OFFSET) {
> __machine_desc_start = . ;
> -   *(.machine.desc)
> +   KEEP(*(.machine.desc))
> __machine_desc_end = . ;
> }
>  #ifdef CONFIG_RELOCATABLE
> @@ -274,7 +274,7 @@ SECTIONS
> .data : AT(ADDR(.data) - LOAD_OFFSET) {
> DATA_DATA
> *(.data.rel*)
> -   *(.sdata)
> +   *(SDATA_MAIN)
> *(.sdata2)
> *(.got.plt) *(.got)
> *(.plt)
> @@ -289,7 +289,7 @@ SECTIONS
>
> .opd : AT(ADDR(.opd) - LOAD_OFFSET) {
> __start_opd = .;
> -   *(.opd)
> +   KEEP(*(.opd))
> __end_opd = .;
> }
>
> --
> 2.17.0
>


Re: [PATCH 0/4] LD_DEAD_CODE_DATA_ELIMINATION fixes and enabling for powerpc

2018-04-20 Thread Mathieu Malaterre
On Fri, Apr 20, 2018 at 9:34 AM, Nicholas Piggin  wrote:
> A few people have been interested in this again. And I promised
> if it remains dead code it should be removed, so I would like to
> have another try.
>
> I think I got snagged on the modules problem last time and did
> not take the time to work it out, this time I just turned off the
> compile options for modules (the linker option was never set anyway
> so no loss).
>
> This includes some linker script catches and ideas from others, I
> didn't documnt them all, but thanks for looking.

This series works for me. v2 from Christophe was triggering a kernel
panic (call stack mentioned set_pte_at...).

So if needed:

Tested-by: Mathieu Malaterre 

Env: Mac Mini G4, with custom config.

> I would be interested to help other archs get this working too, if
> anybody needs some help.
>
> Thanks,
> Nick
>
> Nicholas Piggin (4):
>   kbuild: Fix asm-generic/vmlinux.lds.h for
> LD_DEAD_CODE_DATA_ELIMINATION
>   kbuild: LD_DEAD_CODE_DATA_ELIMINATION no
> -ffunction-sections/-fdata-sections for module build
>   kbuild: Allow LD_DEAD_CODE_DATA_ELIMINATION to be selectable if
> enabled
>   powerpc: Allow LD_DEAD_CODE_DATA_ELIMINATION to be selected
>
>  Makefile  |  4 +--
>  arch/Kconfig  | 15 --
>  arch/powerpc/Kconfig  |  1 +
>  arch/powerpc/kernel/vmlinux.lds.S | 22 +++---
>  include/asm-generic/vmlinux.lds.h | 49 ++-
>  init/Kconfig  | 27 +
>  6 files changed, 70 insertions(+), 48 deletions(-)
>
> --
> 2.17.0
>


Re: [PATCH v3 01/17] y2038: asm-generic: Extend sysvipc data structures

2018-04-20 Thread Arnd Bergmann
On Fri, Apr 20, 2018 at 12:12 AM, Eric W. Biederman
 wrote:
> Arnd Bergmann  writes:
>
>> On Thu, Apr 19, 2018 at 5:20 PM, Arnd Bergmann  wrote:
>>> On Thu, Apr 19, 2018 at 4:59 PM, Eric W. Biederman  
>>> wrote:
 I suspect you want to use __kernel_ulong_t here instead of a raw
 unsigned long.  If nothing else it seems inconsistent to use typedefs
 in one half of the structure and no typedefs in the other half.
>>>
>>> Good catch, there is definitely something wrong here, but I think using
>>> __kernel_ulong_t for all members would also be wrong, as that
>>> still changes the layout on x32, which effectively is
>>>
>>> struct msqid64_ds {
>>>  ipc64_perm msg_perm;
>>>  u64 msg_stime;
>>>  u32 __unused1;
>>>  /* 32 bit implict padding */
>>>  u64 msg_rtime;
>>>  u32 __unused2;
>>>  /* 32 bit implict padding */
>>>  u64 msg_ctime;
>>>  u32 __unused3;
>>>  /* 32 bit implict padding */
>>>  __kernel_pid_t  shm_cpid;   /* pid of creator */
>>>  __kernel_pid_t  shm_lpid;   /* pid of last operator */
>>>  
>>> };
>>>
>>> The choices here would be to either use a mix of
>>> __kernel_ulong_t and unsigned long, or taking the x32
>>> version back into arch/x86/include/uapi/asm/ so the
>>> generic version at least makes some sense.
>>>
>>> I can't use __kernel_time_t for the lower half on 32-bit
>>> since it really should be unsigned.
>>
>> After thinking about it some more, I conclude that the structure is simply
>> incorrect on x32: The __kernel_ulong_t usage was introduced in 2013
>> in commit b9cd5ca22d67 ("uapi: Use __kernel_ulong_t in struct
>> msqid64_ds") and apparently was correct initially as __BITS_PER_LONG
>> evaluated to 64, but it broke with commit f4b4aae18288 ("x86/headers/uapi:
>> Fix __BITS_PER_LONG value for x32 builds") that changed the value
>> of __BITS_PER_LONG and introduced the extra padding in 2015.
>>
>> The same change apparently also broke a lot of other definitions, e.g.
>>
>> $ echo "#include " | gcc -mx32 -E -xc - | grep -A3
>> __kernel_size_t
>> typedef unsigned int __kernel_size_t;
>> typedef int __kernel_ssize_t;
>> typedef int __kernel_ptrdiff_t;
>>
>> Those used to be defined as 'unsigned long long' and 'long long'
>> respectively, so now all kernel interfaces using those on x32
>> became incompatible!
>
> Is this just for the uapi header as seen by userspace?  I expect we are
> using the a normal kernel interface with 64bit longs and 64bit pointers
> when we build the kernel.

Yes, that patch shouldn't have changed anything in the kernel, which
continues to be built with __BITS_PER_LONG=64. I haven't
checked the vdso, which is the only bit of the kernel that gets built
with -mx32, but I assume it's fine as well.

> If this is just a header as seen from userspace mess it seems
> unfortunate but fixable.

Right. I'll fix the IPC stuff for this series to make it work with
any value of __BITS_PER_LONG on x32, but I don't plan to
do anything about the rest of x32. The patch that caused the
problem was intended as a bugfix, so we can't just revert it
without first understanding how to properly fix the original bug,
and which other interfaces have now come to rely on
__BITS_PER_LONG=32 for x32.

Adding a few other folks that have been involved in the x32
kernel support or the Debian port in the past. Maybe one of
them is motivated to figure out how to fix this properly.

   Arnd


Re: [PATCH v2 3/7] powerpc: use task_pid_nr() for TID allocation

2018-04-20 Thread Andrew Donnellan

[+ Sukadev, Christophe]

On 18/04/18 11:08, Alastair D'Silva wrote:

From: Alastair D'Silva 

The current implementation of TID allocation, using a global IDR, may
result in an errant process starving the system of available TIDs.
Instead, use task_pid_nr(), as mentioned by the original author. The
scenario described which prevented it's use is not applicable, as
set_thread_tidr can only be called after the task struct has been
populated.

Signed-off-by: Alastair D'Silva 


So it's too late in the evening for me to completely get my head around 
what's going on here enough to give my Reviewed-by:, but my current 
thinking is:


- In the first version of the patch to add TIDR support 
(https://patchwork.ozlabs.org/patch/799494/), it was originally proposed 
to call assign_thread_id() (as it was then called) from copy_thread()


- The comment block documents the reason why we can't use task_pid_nr() 
but assumes that we're trying to assign a TIDR from within copy_thread()


- The final patch that was accepted 
(https://patchwork.ozlabs.org/patch/835552/, 
ec233ede4c8654894610ea54f4dae7adc954ac62) instead sets the TIDR to 0 
from copy_thread(), so the original reasoning regarding not using 
task_pid_nr() within copy_thread() is no longer applicable.


Sukadev: does this sound right?


Andrew



---
  arch/powerpc/include/asm/switch_to.h |  1 -
  arch/powerpc/kernel/process.c| 97 +---
  2 files changed, 1 insertion(+), 97 deletions(-)

diff --git a/arch/powerpc/include/asm/switch_to.h 
b/arch/powerpc/include/asm/switch_to.h
index be8c9fa23983..5b03d8a82409 100644
--- a/arch/powerpc/include/asm/switch_to.h
+++ b/arch/powerpc/include/asm/switch_to.h
@@ -94,6 +94,5 @@ static inline void clear_task_ebb(struct task_struct *t)
  extern int set_thread_uses_vas(void);
  
  extern int set_thread_tidr(struct task_struct *t);

-extern void clear_thread_tidr(struct task_struct *t);
  
  #endif /* _ASM_POWERPC_SWITCH_TO_H */

diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
index 3b00da47699b..87f047fd2762 100644
--- a/arch/powerpc/kernel/process.c
+++ b/arch/powerpc/kernel/process.c
@@ -1496,103 +1496,12 @@ int set_thread_uses_vas(void)
  }
  
  #ifdef CONFIG_PPC64

-static DEFINE_SPINLOCK(vas_thread_id_lock);
-static DEFINE_IDA(vas_thread_ida);
-
-/*
- * We need to assign a unique thread id to each thread in a process.
- *
- * This thread id, referred to as TIDR, and separate from the Linux's tgid,
- * is intended to be used to direct an ASB_Notify from the hardware to the
- * thread, when a suitable event occurs in the system.
- *
- * One such event is a "paste" instruction in the context of Fast Thread
- * Wakeup (aka Core-to-core wake up in the Virtual Accelerator Switchboard
- * (VAS) in POWER9.
- *
- * To get a unique TIDR per process we could simply reuse task_pid_nr() but
- * the problem is that task_pid_nr() is not yet available copy_thread() is
- * called. Fixing that would require changing more intrusive arch-neutral
- * code in code path in copy_process()?.
- *
- * Further, to assign unique TIDRs within each process, we need an atomic
- * field (or an IDR) in task_struct, which again intrudes into the arch-
- * neutral code. So try to assign globally unique TIDRs for now.
- *
- * NOTE: TIDR 0 indicates that the thread does not need a TIDR value.
- *  For now, only threads that expect to be notified by the VAS
- *  hardware need a TIDR value and we assign values > 0 for those.
- */
-#define MAX_THREAD_CONTEXT ((1 << 16) - 1)
-static int assign_thread_tidr(void)
-{
-   int index;
-   int err;
-   unsigned long flags;
-
-again:
-   if (!ida_pre_get(_thread_ida, GFP_KERNEL))
-   return -ENOMEM;
-
-   spin_lock_irqsave(_thread_id_lock, flags);
-   err = ida_get_new_above(_thread_ida, 1, );
-   spin_unlock_irqrestore(_thread_id_lock, flags);
-
-   if (err == -EAGAIN)
-   goto again;
-   else if (err)
-   return err;
-
-   if (index > MAX_THREAD_CONTEXT) {
-   spin_lock_irqsave(_thread_id_lock, flags);
-   ida_remove(_thread_ida, index);
-   spin_unlock_irqrestore(_thread_id_lock, flags);
-   return -ENOMEM;
-   }
-
-   return index;
-}
-
-static void free_thread_tidr(int id)
-{
-   unsigned long flags;
-
-   spin_lock_irqsave(_thread_id_lock, flags);
-   ida_remove(_thread_ida, id);
-   spin_unlock_irqrestore(_thread_id_lock, flags);
-}
-
-/*
- * Clear any TIDR value assigned to this thread.
- */
-void clear_thread_tidr(struct task_struct *t)
-{
-   if (!t->thread.tidr)
-   return;
-
-   if (!cpu_has_feature(CPU_FTR_P9_TIDR)) {
-   WARN_ON_ONCE(1);
-   return;
-   }
-
-   mtspr(SPRN_TIDR, 0);
-   free_thread_tidr(t->thread.tidr);
-   t->thread.tidr = 0;
-}
-
-void 

Re: [PATCH v3 04/17] y2038: s390: Remove unneeded ipc uapi header files

2018-04-20 Thread Arnd Bergmann
On Fri, Apr 20, 2018 at 9:54 AM, Heiko Carstens
 wrote:
> On Thu, Apr 19, 2018 at 04:37:24PM +0200, Arnd Bergmann wrote:
>> The s390 msgbuf/sembuf/shmbuf header files are all identical to the
>> version from asm-generic.
>>
>> This patch removes the files and replaces them with 'generic-y'
>> statements, to avoid having to modify each copy when we extend sysvipc
>> to deal with 64-bit time_t in 32-bit user space.
>>
>> Note that unlike alpha and ia64, the ipcbuf.h header file is slightly
>> different here, so I'm leaving the private copy.
>>
>> To deal with 32-bit compat tasks, we also have to adapt the definitions
>> of compat_{shm,sem,msg}id_ds to match the changes to the respective
>> asm-generic files.
>>
>> Signed-off-by: Arnd Bergmann 
>> ---
>>  arch/s390/include/asm/compat.h  | 32 
>>  arch/s390/include/uapi/asm/Kbuild   |  3 +++
>>  arch/s390/include/uapi/asm/msgbuf.h | 38 
>>  arch/s390/include/uapi/asm/sembuf.h | 30 ---
>>  arch/s390/include/uapi/asm/shmbuf.h | 49 
>> -
>>  5 files changed, 19 insertions(+), 133 deletions(-)
>>  delete mode 100644 arch/s390/include/uapi/asm/msgbuf.h
>>  delete mode 100644 arch/s390/include/uapi/asm/sembuf.h
>>  delete mode 100644 arch/s390/include/uapi/asm/shmbuf.h
>
> FWIW,
>
> Acked-by: Heiko Carstens 

Thanks, added to the patch.

 Arnd


Re: [PATCH v3 04/17] y2038: s390: Remove unneeded ipc uapi header files

2018-04-20 Thread Heiko Carstens
On Thu, Apr 19, 2018 at 04:37:24PM +0200, Arnd Bergmann wrote:
> The s390 msgbuf/sembuf/shmbuf header files are all identical to the
> version from asm-generic.
> 
> This patch removes the files and replaces them with 'generic-y'
> statements, to avoid having to modify each copy when we extend sysvipc
> to deal with 64-bit time_t in 32-bit user space.
> 
> Note that unlike alpha and ia64, the ipcbuf.h header file is slightly
> different here, so I'm leaving the private copy.
> 
> To deal with 32-bit compat tasks, we also have to adapt the definitions
> of compat_{shm,sem,msg}id_ds to match the changes to the respective
> asm-generic files.
> 
> Signed-off-by: Arnd Bergmann 
> ---
>  arch/s390/include/asm/compat.h  | 32 
>  arch/s390/include/uapi/asm/Kbuild   |  3 +++
>  arch/s390/include/uapi/asm/msgbuf.h | 38 
>  arch/s390/include/uapi/asm/sembuf.h | 30 ---
>  arch/s390/include/uapi/asm/shmbuf.h | 49 
> -
>  5 files changed, 19 insertions(+), 133 deletions(-)
>  delete mode 100644 arch/s390/include/uapi/asm/msgbuf.h
>  delete mode 100644 arch/s390/include/uapi/asm/sembuf.h
>  delete mode 100644 arch/s390/include/uapi/asm/shmbuf.h

FWIW,

Acked-by: Heiko Carstens 



[PATCH 4/4] powerpc: Allow LD_DEAD_CODE_DATA_ELIMINATION to be selected

2018-04-20 Thread Nicholas Piggin
This requires further changes to linker script to KEEP some tables
and wildcard compiler generated sections into the right place. This
includes pp32 modifications from Christophe Leroy.

When compiling powernv_defconfig with this option:

text   data  bss   decfilename
11827621   4810490   1341080   17979191   vmlinux
11752437   4598858   1338776   17690071   vmlinux.dcde

Resulting kernel is almost 400kB smaller (and still boots).

[ppc32 numbers here]

Signed-off-by: Nicholas Piggin 
---
 arch/powerpc/Kconfig  |  1 +
 arch/powerpc/kernel/vmlinux.lds.S | 22 +++---
 2 files changed, 12 insertions(+), 11 deletions(-)

diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
index c32a181a7cbb..ee6dbe2efc8b 100644
--- a/arch/powerpc/Kconfig
+++ b/arch/powerpc/Kconfig
@@ -205,6 +205,7 @@ config PPC
select HAVE_KPROBES
select HAVE_KPROBES_ON_FTRACE
select HAVE_KRETPROBES
+   select HAVE_LD_DEAD_CODE_DATA_ELIMINATION
select HAVE_LIVEPATCH   if HAVE_DYNAMIC_FTRACE_WITH_REGS
select HAVE_MEMBLOCK
select HAVE_MEMBLOCK_NODE_MAP
diff --git a/arch/powerpc/kernel/vmlinux.lds.S 
b/arch/powerpc/kernel/vmlinux.lds.S
index c8af90ff49f0..89381dc959ce 100644
--- a/arch/powerpc/kernel/vmlinux.lds.S
+++ b/arch/powerpc/kernel/vmlinux.lds.S
@@ -89,7 +89,7 @@ SECTIONS
 */
.text BLOCK(0) : AT(ADDR(.text) - LOAD_OFFSET) {
 #ifdef CONFIG_LD_HEAD_STUB_CATCH
-   *(.linker_stub_catch);
+   KEEP(*(.linker_stub_catch));
. = . ;
 #endif
 
@@ -98,7 +98,7 @@ SECTIONS
ALIGN_FUNCTION();
 #endif
/* careful! __ftr_alt_* sections need to be close to .text */
-   *(.text.hot .text .text.fixup .text.unlikely .fixup __ftr_alt_* 
.ref.text);
+   *(.text.hot .text .text.[0-9a-zA-Z_]* .text.fixup 
.text.unlikely .fixup __ftr_alt_* .ref.text);
SCHED_TEXT
CPUIDLE_TEXT
LOCK_TEXT
@@ -170,10 +170,10 @@ SECTIONS
.init.data : AT(ADDR(.init.data) - LOAD_OFFSET) {
INIT_DATA
__vtop_table_begin = .;
-   *(.vtop_fixup);
+   KEEP(*(.vtop_fixup));
__vtop_table_end = .;
__ptov_table_begin = .;
-   *(.ptov_fixup);
+   KEEP(*(.ptov_fixup));
__ptov_table_end = .;
}
 
@@ -194,26 +194,26 @@ SECTIONS
. = ALIGN(8);
__ftr_fixup : AT(ADDR(__ftr_fixup) - LOAD_OFFSET) {
__start___ftr_fixup = .;
-   *(__ftr_fixup)
+   KEEP(*(__ftr_fixup))
__stop___ftr_fixup = .;
}
. = ALIGN(8);
__mmu_ftr_fixup : AT(ADDR(__mmu_ftr_fixup) - LOAD_OFFSET) {
__start___mmu_ftr_fixup = .;
-   *(__mmu_ftr_fixup)
+   KEEP(*(__mmu_ftr_fixup))
__stop___mmu_ftr_fixup = .;
}
. = ALIGN(8);
__lwsync_fixup : AT(ADDR(__lwsync_fixup) - LOAD_OFFSET) {
__start___lwsync_fixup = .;
-   *(__lwsync_fixup)
+   KEEP(*(__lwsync_fixup))
__stop___lwsync_fixup = .;
}
 #ifdef CONFIG_PPC64
. = ALIGN(8);
__fw_ftr_fixup : AT(ADDR(__fw_ftr_fixup) - LOAD_OFFSET) {
__start___fw_ftr_fixup = .;
-   *(__fw_ftr_fixup)
+   KEEP(*(__fw_ftr_fixup))
__stop___fw_ftr_fixup = .;
}
 #endif
@@ -226,7 +226,7 @@ SECTIONS
. = ALIGN(8);
.machine.desc : AT(ADDR(.machine.desc) - LOAD_OFFSET) {
__machine_desc_start = . ;
-   *(.machine.desc)
+   KEEP(*(.machine.desc))
__machine_desc_end = . ;
}
 #ifdef CONFIG_RELOCATABLE
@@ -274,7 +274,7 @@ SECTIONS
.data : AT(ADDR(.data) - LOAD_OFFSET) {
DATA_DATA
*(.data.rel*)
-   *(.sdata)
+   *(SDATA_MAIN)
*(.sdata2)
*(.got.plt) *(.got)
*(.plt)
@@ -289,7 +289,7 @@ SECTIONS
 
.opd : AT(ADDR(.opd) - LOAD_OFFSET) {
__start_opd = .;
-   *(.opd)
+   KEEP(*(.opd))
__end_opd = .;
}
 
-- 
2.17.0



[PATCH 3/4] kbuild: Allow LD_DEAD_CODE_DATA_ELIMINATION to be selectable if enabled

2018-04-20 Thread Nicholas Piggin
Architectures that are capable can select
HAVE_LD_DEAD_CODE_DATA_ELIMINATION to enable selection of that
option (as an EXPERT kernel option).

Signed-off-by: Nicholas Piggin 
---
 arch/Kconfig | 15 ---
 init/Kconfig | 27 +++
 2 files changed, 27 insertions(+), 15 deletions(-)

diff --git a/arch/Kconfig b/arch/Kconfig
index 8e0d665c8d53..3234b73d4626 100644
--- a/arch/Kconfig
+++ b/arch/Kconfig
@@ -596,21 +596,6 @@ config CC_STACKPROTECTOR_AUTO
 
 endchoice
 
-config LD_DEAD_CODE_DATA_ELIMINATION
-   bool
-   help
- Select this if the architecture wants to do dead code and
- data elimination with the linker by compiling with
- -ffunction-sections -fdata-sections and linking with
- --gc-sections.
-
- This requires that the arch annotates or otherwise protects
- its external entry points from being discarded. Linker scripts
- must also merge .text.*, .data.*, and .bss.* correctly into
- output sections. Care must be taken not to pull in unrelated
- sections (e.g., '.text.init'). Typically '.' in section names
- is used to distinguish them from label names / C identifiers.
-
 config HAVE_ARCH_WITHIN_STACK_FRAMES
bool
help
diff --git a/init/Kconfig b/init/Kconfig
index f013afc74b11..1706d963766b 100644
--- a/init/Kconfig
+++ b/init/Kconfig
@@ -1038,6 +1038,33 @@ config CC_OPTIMIZE_FOR_SIZE
 
 endchoice
 
+config HAVE_LD_DEAD_CODE_DATA_ELIMINATION
+   bool
+   help
+ This requires that the arch annotates or otherwise protects
+ its external entry points from being discarded. Linker scripts
+ must also merge .text.*, .data.*, and .bss.* correctly into
+ output sections. Care must be taken not to pull in unrelated
+ sections (e.g., '.text.init'). Typically '.' in section names
+ is used to distinguish them from label names / C identifiers.
+
+config LD_DEAD_CODE_DATA_ELIMINATION
+   bool "Dead code and data elimination (EXPERIMENTAL)"
+   depends on HAVE_LD_DEAD_CODE_DATA_ELIMINATION
+   depends on EXPERT
+   help
+ Select this if the architecture wants to do dead code and
+ data elimination with the linker by compiling with
+ -ffunction-sections -fdata-sections, and linking with
+ --gc-sections.
+
+ This can reduce on disk and in-memory size of the kernel
+ code and static data, particularly for small configs and
+ on small systems. This has the possibility of introducing
+ silently broken kernel if the required annotations are not
+ present. This option is not well tested yet, so use at your
+ own risk.
+
 config SYSCTL
bool
 
-- 
2.17.0



[PATCH 2/4] kbuild: LD_DEAD_CODE_DATA_ELIMINATION no -ffunction-sections/-fdata-sections for module build

2018-04-20 Thread Nicholas Piggin
Modules do not tend to cope with -ffunction-sections, even though they
do not link with -gc-sections. It may be possible for unused symbols to
be trimmed from modules, but in general that would take much more work
in architecture module linker scripts.

For now, enable these only for kernel build.

Signed-off-by: Nicholas Piggin 
---
 Makefile | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/Makefile b/Makefile
index e811e0c509c5..2ed651403bb4 100644
--- a/Makefile
+++ b/Makefile
@@ -799,8 +799,8 @@ KBUILD_CFLAGS += $(call cc-option, 
-fno-inline-functions-called-once)
 endif
 
 ifdef CONFIG_LD_DEAD_CODE_DATA_ELIMINATION
-KBUILD_CFLAGS  += $(call cc-option,-ffunction-sections,)
-KBUILD_CFLAGS  += $(call cc-option,-fdata-sections,)
+KBUILD_CFLAGS_KERNEL   += $(call cc-option,-ffunction-sections,)
+KBUILD_CFLAGS_KERNEL   += $(call cc-option,-fdata-sections,)
 endif
 
 # arch Makefile may override CC so keep this after arch Makefile is included
-- 
2.17.0



[PATCH 1/4] kbuild: Fix asm-generic/vmlinux.lds.h for LD_DEAD_CODE_DATA_ELIMINATION

2018-04-20 Thread Nicholas Piggin
KEEP more tables, and add the function/data section wildcard to more
section selections.

This is a little ad-hoc at the moment, but kernel code should be moved
to consistently use .text..x (note: double dots) for explicit sections
and all references to it in the linker script can be made with
TEXT_MAIN, and similarly for other sections.

For now, let's see if major architectures move to enabling this option
then we can do some refactoring passes. Otherwise if it remains unused
or superseded by LTO, this may not be required.

Signed-off-by: Nicholas Piggin 
---
 include/asm-generic/vmlinux.lds.h | 49 ++-
 1 file changed, 29 insertions(+), 20 deletions(-)

diff --git a/include/asm-generic/vmlinux.lds.h 
b/include/asm-generic/vmlinux.lds.h
index 278841c75b97..23f5f8d22f56 100644
--- a/include/asm-generic/vmlinux.lds.h
+++ b/include/asm-generic/vmlinux.lds.h
@@ -64,15 +64,24 @@
  * generates .data.identifier sections, which need to be pulled in with
  * .data. We don't want to pull in .data..other sections, which Linux
  * has defined. Same for text and bss.
+ *
+ * RODATA_MAIN is not used because existing code already defines .rodata.x
+ * sections to be brought in with rodata.
  */
 #ifdef CONFIG_LD_DEAD_CODE_DATA_ELIMINATION
 #define TEXT_MAIN .text .text.[0-9a-zA-Z_]*
 #define DATA_MAIN .data .data.[0-9a-zA-Z_]*
+#define SDATA_MAIN .sdata .sdata.[0-9a-zA-Z_]*
+#define RODATA_MAIN .rodata .rodata.[0-9a-zA-Z_]*
 #define BSS_MAIN .bss .bss.[0-9a-zA-Z_]*
+#define SBSS_MAIN .sbss .sbss.[0-9a-zA-Z_]*
 #else
 #define TEXT_MAIN .text
 #define DATA_MAIN .data
+#define SDATA_MAIN .sdata
+#define RODATA_MAIN .rodata
 #define BSS_MAIN .bss
+#define SBSS_MAIN .sbss
 #endif
 
 /*
@@ -105,7 +114,7 @@
 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
 #define MCOUNT_REC()   . = ALIGN(8);   \
VMLINUX_SYMBOL(__start_mcount_loc) = .; \
-   *(__mcount_loc) \
+   KEEP(*(__mcount_loc))   \
VMLINUX_SYMBOL(__stop_mcount_loc) = .;
 #else
 #define MCOUNT_REC()
@@ -113,7 +122,7 @@
 
 #ifdef CONFIG_TRACE_BRANCH_PROFILING
 #define LIKELY_PROFILE()   
VMLINUX_SYMBOL(__start_annotated_branch_profile) = .; \
-   *(_ftrace_annotated_branch) 
  \
+   KEEP(*(_ftrace_annotated_branch))   
  \
VMLINUX_SYMBOL(__stop_annotated_branch_profile) 
= .;
 #else
 #define LIKELY_PROFILE()
@@ -121,7 +130,7 @@
 
 #ifdef CONFIG_PROFILE_ALL_BRANCHES
 #define BRANCH_PROFILE()   VMLINUX_SYMBOL(__start_branch_profile) = .;   \
-   *(_ftrace_branch) \
+   KEEP(*(_ftrace_branch))   \
VMLINUX_SYMBOL(__stop_branch_profile) = .;
 #else
 #define BRANCH_PROFILE()
@@ -238,8 +247,8 @@
*(DATA_MAIN)\
*(.ref.data)\
*(.data..shared_aligned) /* percpu related */   \
-   MEM_KEEP(init.data) \
-   MEM_KEEP(exit.data) \
+   MEM_KEEP(init.data*)\
+   MEM_KEEP(exit.data*)\
*(.data.unlikely)   \
VMLINUX_SYMBOL(__start_once) = .;   \
*(.data.once)   \
@@ -289,8 +298,8 @@
VMLINUX_SYMBOL(__start_init_task) = .;  \
VMLINUX_SYMBOL(init_thread_union) = .;  \
VMLINUX_SYMBOL(init_stack) = .; \
-   *(.data..init_task) \
-   *(.data..init_thread_info)  \
+   KEEP(*(.data..init_task))   \
+   KEEP(*(.data..init_thread_info))\
. = VMLINUX_SYMBOL(__start_init_task) + THREAD_SIZE;\
VMLINUX_SYMBOL(__end_init_task) = .;
 
@@ -487,8 +496,8 @@
*(.text.hot TEXT_MAIN .text.fixup .text.unlikely)   \
*(.text..refcount)  \
*(.ref.text)\
-   MEM_KEEP(init.text) \
-   MEM_KEEP(exit.text) \
+   MEM_KEEP(init.text*)\
+   MEM_KEEP(exit.text*)\
 
 
 /* sched.text is aling to 

[PATCH 0/4] LD_DEAD_CODE_DATA_ELIMINATION fixes and enabling for powerpc

2018-04-20 Thread Nicholas Piggin
A few people have been interested in this again. And I promised
if it remains dead code it should be removed, so I would like to
have another try.

I think I got snagged on the modules problem last time and did
not take the time to work it out, this time I just turned off the
compile options for modules (the linker option was never set anyway
so no loss).

This includes some linker script catches and ideas from others, I
didn't documnt them all, but thanks for looking.

I would be interested to help other archs get this working too, if
anybody needs some help.

Thanks,
Nick

Nicholas Piggin (4):
  kbuild: Fix asm-generic/vmlinux.lds.h for
LD_DEAD_CODE_DATA_ELIMINATION
  kbuild: LD_DEAD_CODE_DATA_ELIMINATION no
-ffunction-sections/-fdata-sections for module build
  kbuild: Allow LD_DEAD_CODE_DATA_ELIMINATION to be selectable if
enabled
  powerpc: Allow LD_DEAD_CODE_DATA_ELIMINATION to be selected

 Makefile  |  4 +--
 arch/Kconfig  | 15 --
 arch/powerpc/Kconfig  |  1 +
 arch/powerpc/kernel/vmlinux.lds.S | 22 +++---
 include/asm-generic/vmlinux.lds.h | 49 ++-
 init/Kconfig  | 27 +
 6 files changed, 70 insertions(+), 48 deletions(-)

-- 
2.17.0



Re: [PATCH v2 6/7] ocxl: Add an IOCTL so userspace knows what CPU features are available

2018-04-20 Thread Andrew Donnellan

On 18/04/18 11:08, Alastair D'Silva wrote:

From: Alastair D'Silva 

In order for a userspace AFU driver to call the Power9 specific
OCXL_IOCTL_ENABLE_P9_WAIT, it needs to verify that it can actually
make that call.

Signed-off-by: Alastair D'Silva 


Looks good to me

Acked-by: Andrew Donnellan 


---
  Documentation/accelerators/ocxl.rst |  1 -
  drivers/misc/ocxl/file.c| 25 +
  include/uapi/misc/ocxl.h|  4 
  3 files changed, 29 insertions(+), 1 deletion(-)

diff --git a/Documentation/accelerators/ocxl.rst 
b/Documentation/accelerators/ocxl.rst
index ddcc58d01cfb..7904adcc07fd 100644
--- a/Documentation/accelerators/ocxl.rst
+++ b/Documentation/accelerators/ocxl.rst
@@ -157,7 +157,6 @@ OCXL_IOCTL_GET_METADATA:
Obtains configuration information from the card, such at the size of
MMIO areas, the AFU version, and the PASID for the current context.
  
-


This is stray


--
Andrew Donnellan  OzLabs, ADL Canberra
andrew.donnel...@au1.ibm.com  IBM Australia Limited



Re: [PATCH v5 06/10] powerpc64/ftrace: Disable ftrace during kvm entry/exit

2018-04-20 Thread Naveen N. Rao

Steven Rostedt wrote:

On Thu, 19 Apr 2018 12:34:05 +0530
"Naveen N. Rao"  wrote:


2. If we are a secondary thread in Power8, then we would be in nap due
to SMT being disabled. We are woken up by an IPI to enter the guest. In
this scenario, we enter the guest through kvm_start_guest(). We disable
ftrace at this point. In this scenario, ftrace would only get re-enabled
on the secondary thread when SMT is re-enabled (via start_secondary()).


trace_hardirqs_off();

diff --git a/arch/powerpc/kvm/book3s_hv_rmhandlers.S 
b/arch/powerpc/kvm/book3s_hv_rmhandlers.S
index bd63fa8a08b5..2c3cbe0067b2 100644
--- a/arch/powerpc/kvm/book3s_hv_rmhandlers.S
+++ b/arch/powerpc/kvm/book3s_hv_rmhandlers.S
@@ -342,6 +342,9 @@ kvm_start_guest:
 
 	ld	r2,PACATOC(r13)
 


You may want to add a comment here about where ftrace gets re-enabled.


Sure. That would be:

/*
* If this is the primary thread, ftrace will get re-enabled when we
* go back to the hypervisor in kvmppc_run_core(). For secondary threads 
* on Power8, ftrace will get enabled when SMT is re-enabled through the 
* start_secondary() cpu bringup path.

*/

- Naveen