[PATCH] powerpc/pseries: export timebase register sample in lparcfg

2018-12-08 Thread Tyrel Datwyler
The Processor Utilzation of Resource Registers (PURR) provide an estimate of
resources used by a cpu thread. Section 7.6 in Book III of the ISA outlines
how to calculate the percentage of shared resources for threads using the
ratio of the PURR delta and Timebase Register delta for a sampled period.

This calculation is currently done erroneously by the lparstat tool from the
powerpc-utils package. This patch exports the current timebase value after
we sample the PURRs and exposes it to userspace accounting tools via
/proc/ppc64/lparcfg.

Signed-off-by: Tyrel Datwyler 
---
 arch/powerpc/platforms/pseries/lparcfg.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/powerpc/platforms/pseries/lparcfg.c 
b/arch/powerpc/platforms/pseries/lparcfg.c
index 7944873..1ea73ec 100644
--- a/arch/powerpc/platforms/pseries/lparcfg.c
+++ b/arch/powerpc/platforms/pseries/lparcfg.c
@@ -475,6 +475,7 @@ static int pseries_lparcfg_data(struct seq_file *m, void *v)
splpar_dispatch_data(m);
 
seq_printf(m, "purr=%ld\n", get_purr());
+seq_printf(m, "tbr=%ld\n", mftb());
} else {/* non SPLPAR case */
 
seq_printf(m, "system_active_processors=%d\n",
-- 
2.7.4



Re: [PATCH 1/2] um: remove -fno-unit-at-a-time workaround for pre-4.0 GCC

2018-12-08 Thread Masahiro Yamada
Hi Richard,

On Sat, Dec 8, 2018 at 5:55 PM Richard Weinberger  wrote:
>
> Am Samstag, 8. Dezember 2018, 07:35:47 CET schrieb Masahiro Yamada:
> > x86 maintainers,
> >
> >
> > Ping.
>
> I thought you carry this via your kbuild tree.
> That said, I can merge it also via the um tree.
> x86 is of course also fine. :-)


The second patch also touches x86 Makefiles.

So, I think both should be applied to x86 tree.

Thanks.




> >
> >
> > On Tue, Nov 13, 2018 at 6:48 PM Richard Weinberger  wrote:
> > >
> > > Am Montag, 12. November 2018, 03:35:19 CET schrieb Masahiro Yamada:
> > > > Commit cafa0010cd51 ("Raise the minimum required gcc version to 4.6")
> > > > bumped the minimum GCC version to 4.6 for all architectures.
> > > >
> > > > '$(call cc-option,-fno-unit-at-a-time)' is now dead code since
> > > > '$(cc-version) -lt 0400' is always false.
> > > >
> > > > Signed-off-by: Masahiro Yamada 
> > > > ---
> > > >
> > > >  arch/x86/Makefile.um | 8 ++--
> > > >  1 file changed, 2 insertions(+), 6 deletions(-)
> > > >
> > > > diff --git a/arch/x86/Makefile.um b/arch/x86/Makefile.um
> > > > index 91085a0..577976b 100644
> > > > --- a/arch/x86/Makefile.um
> > > > +++ b/arch/x86/Makefile.um
> > > > @@ -26,12 +26,8 @@ cflags-y += $(call 
> > > > cc-option,-mpreferred-stack-boundary=2)
> > > >  # an unresolved reference.
> > > >  cflags-y += -ffreestanding
> > > >
> > > > -# Disable unit-at-a-time mode on pre-gcc-4.0 compilers, it makes gcc 
> > > > use
> > > > -# a lot more stack due to the lack of sharing of stacklots.  Also, gcc
> > > > -# 4.3.0 needs -funit-at-a-time for extern inline functions.
> > > > -KBUILD_CFLAGS += $(shell if [ $(cc-version) -lt 0400 ] ; then \
> > > > - echo $(call cc-option,-fno-unit-at-a-time); \
> > > > - else echo $(call cc-option,-funit-at-a-time); fi 
> > > > ;)
> > > > +# gcc 4.3.0 needs -funit-at-a-time for extern inline functions.
> > > > +KBUILD_CFLAGS += $(call cc-option,-funit-at-a-time)
> > >
> > > Acked-by: Richard Weinberger 
>
> Thanks,
> //richard
>
>


-- 
Best Regards
Masahiro Yamada


Re: [PATCH 2/2] x86, powerpc: remove -funit-at-a-time compiler option entirely

2018-12-08 Thread Masahiro Yamada
Hi Borislav,


On Sat, Dec 8, 2018 at 8:34 PM Borislav Petkov  wrote:
>
> On Sat, Dec 08, 2018 at 03:36:52PM +0900, Masahiro Yamada wrote:
> > x86 maintainers,
> >
> > Ping.
>
> You got the required ACKs. If you want me to carry this one and the
> UML one through the tip tree, lemme know. Or you can do what Richard
> suggested. Your call.


Thank you for your help.
I expect both applied through the tip bot.

Thanks.





> Thx.
>
> --
> Regards/Gruss,
> Boris.
>
> Good mailing practices for 400: avoid top-posting and trim the reply.



-- 
Best Regards
Masahiro Yamada


Re: use generic DMA mapping code in powerpc V4

2018-12-08 Thread Christoph Hellwig
On Sun, Dec 02, 2018 at 05:11:02PM +1100, Benjamin Herrenschmidt wrote:
> Talking of which ... Christoph, not sure if we can do something about
> this at the DMA API level or keep hacks but some adapters such as the
> nVidia GPUs have a HW hack we can use to work around their limitations
> in that case.
> 
> They have a register that can program a fixed value for the top bits
> that they don't support.
> 
> This works fine for any linear mapping with an offset, provided they
> can program the offset in that register and they have enough DMA range
> to cover all memory from that offset.
> 
> I can probably get the info about this from them so we can exploit it
> in nouveau.

I think we can expose the direct mapping offset if people care enough,
we just have to be very careful designing the API.  I'll happily leave
that to those that actually want to use it, but I'll gladly help
reviewing it.


Re: [PATCH V4 0/3] * mm/kvm/vfio/ppc64: Migrate compound pages out of CMA region

2018-12-08 Thread Aneesh Kumar K.V

On 12/8/18 4:42 AM, Andrew Morton wrote:

On Wed, 21 Nov 2018 14:52:56 +0530 "Aneesh Kumar K.V" 
 wrote:


Subject: [PATCH V4 0/3] * mm/kvm/vfio/ppc64: Migrate compound pages out of CMA 
region


Asterisk in title is strange?


My mistake while editing git-format-patch cover-letter.




ppc64 use CMA area for the allocation of guest page table (hash page table). We 
won't
be able to start guest if we fail to allocate hash page table. We have observed
hash table allocation failure because we failed to migrate pages out of CMA 
region
because they were pinned. This happen when we are using VFIO. VFIO on ppc64 pins
the entire guest RAM. If the guest RAM pages get allocated out of CMA region, we
won't be able to migrate those pages. The pages are also pinned for the 
lifetime of the
guest.

Currently we support migration of non-compound pages. With THP and with the 
addition of
  hugetlb migration we can end up allocating compound pages from CMA region. 
This
patch series add support for migrating compound pages. The first path adds the 
helper
get_user_pages_cma_migrate() which pin the page making sure we migrate them out 
of
CMA region before incrementing the reference count.


Very little review activity.  Perhaps Andrey and/or Michal can find the
time..


mm/migrate.c| 108 


can we make this code disappear when CONFIG_CMA=n?




We can definitely do

static inline int get_user_pages_cma_migrate(unsigned long start, int 
nr_pages, int write,  struct page **pages)

{

return get_user_pages_fast(start, nr_pages, write, pages);
}

with #ifdef CONFIG_CMA around but that is unnecessary #ifdef in the 
code. If CMA config is disabled, we will not be doing any migrate. Hence 
wondering whether we need an alternative definition for CONFIG_CMA=n


-aneesh



Re: use generic DMA mapping code in powerpc V4

2018-12-08 Thread Christoph Hellwig
Just as a warning:  this series now has some conflicts with the dma
mapping tree due to the ->mapping_error removal, and there might be
some bigger ones if the direct calls for the direct mapping code series
goes ahead.  None of them affect the early part of the series that do
not touch the actual dma_map_ops instances, though.


[PATCH] powerpc/ptrace: Add prototype for function pt_regs_check

2018-12-08 Thread Mathieu Malaterre
`pt_regs_check` is a dummy function, its purpose is to break the build
if struct pt_regs and struct user_pt_regs don't match.

This function has no functionnal purpose, and will get eliminated at
link time or after init depending on CONFIG_LD_DEAD_CODE_DATA_ELIMINATION

This commit adds a prototype to fix warning at W=1:

  arch/powerpc/kernel/ptrace.c:3339:13: error: no previous prototype for 
‘pt_regs_check’ [-Werror=missing-prototypes]

Suggested-by: Christophe Leroy 
Signed-off-by: Mathieu Malaterre 
---
 arch/powerpc/kernel/ptrace.c | 4 
 1 file changed, 4 insertions(+)

diff --git a/arch/powerpc/kernel/ptrace.c b/arch/powerpc/kernel/ptrace.c
index a398999d0770..341c0060b4c8 100644
--- a/arch/powerpc/kernel/ptrace.c
+++ b/arch/powerpc/kernel/ptrace.c
@@ -3338,6 +3338,10 @@ void do_syscall_trace_leave(struct pt_regs *regs)
user_enter();
 }
 
+void __init pt_regs_check(void);
+/* dummy function, its purpose is to break the build if struct pt_regs and
+ * struct user_pt_regs don't match.
+ */
 void __init pt_regs_check(void)
 {
BUILD_BUG_ON(offsetof(struct pt_regs, gpr) !=
-- 
2.19.2



Re: [PATCH V3 1/5] mm: Update ptep_modify_prot_start/commit to take vm_area_struct as arg

2018-12-08 Thread Aneesh Kumar K.V
kbuild test robot  writes:

> Hi Aneesh,
>
> I love your patch! Yet something to improve:
>
> [auto build test ERROR on linus/master]
> [also build test ERROR on v4.20-rc5 next-20181206]
> [if your patch is applied to the wrong git tree, please drop us a note to 
> help improve the system]
>
> url:
> https://github.com/0day-ci/linux/commits/Aneesh-Kumar-K-V/NestMMU-pte-upgrade-workaround-for-mprotect/20181207-040417
> config: x86_64-allmodconfig (attached as .config)
> compiler: gcc-7 (Debian 7.3.0-1) 7.3.0
> reproduce:
> # save the attached .config to linux build tree
> make ARCH=x86_64 
>
> All errors (new ones prefixed by >>):
>
>In file included from arch/x86/include/asm/msr.h:246:0,
> from arch/x86/include/asm/processor.h:21,
> from arch/x86/include/asm/cpufeature.h:8,
> from arch/x86/include/asm/thread_info.h:53,
> from include/linux/thread_info.h:38,
> from arch/x86/include/asm/preempt.h:7,
> from include/linux/preempt.h:81,
> from include/linux/spinlock.h:51,
> from include/linux/mmzone.h:8,
> from include/linux/gfp.h:6,
> from include/linux/slab.h:15,
> from include/linux/crypto.h:24,
> from arch/x86/kernel/asm-offsets.c:9:
>arch/x86/include/asm/paravirt.h: In function 'ptep_modify_prot_start':
>>> arch/x86/include/asm/paravirt.h:424:28: error: dereferencing pointer to 
>>> incomplete type 'struct vm_area_struct'
>  struct mm_struct *mm = vma->vm_mm;
>^~
>make[2]: *** [arch/x86/kernel/asm-offsets.s] Error 1
>make[2]: Target '__build' not remade because of errors.
>make[1]: *** [prepare0] Error 2
>make[1]: Target 'prepare' not remade because of errors.
>make: *** [sub-make] Error 2
>

The fix turned out to be more code changes than what I expected. Instead
of adding mm_types.h to paravirt.h, I changed most of the related
functions to take vm_area_struct. That brings all ptep_modify_prot_start
variants to take vm_area_struct as arg and IMHO that is better. What do
you think?

diff --git a/arch/x86/include/asm/paravirt.h b/arch/x86/include/asm/paravirt.h
index 0d75a4f60500..28152236a65b 100644
--- a/arch/x86/include/asm/paravirt.h
+++ b/arch/x86/include/asm/paravirt.h
@@ -421,9 +421,8 @@ static inline pte_t ptep_modify_prot_start(struct 
vm_area_struct *vma, unsigned
   pte_t *ptep)
 {
pteval_t ret;
-   struct mm_struct *mm = vma->vm_mm;
 
-   ret = PVOP_CALL3(pteval_t, mmu.ptep_modify_prot_start, mm, addr, ptep);
+   ret = PVOP_CALL3(pteval_t, mmu.ptep_modify_prot_start, vma, addr, ptep);
 
return (pte_t) { .pte = ret };
 }
@@ -431,14 +430,13 @@ static inline pte_t ptep_modify_prot_start(struct 
vm_area_struct *vma, unsigned
 static inline void ptep_modify_prot_commit(struct vm_area_struct *vma, 
unsigned long addr,
   pte_t *ptep, pte_t old_pte, pte_t 
pte)
 {
-   struct mm_struct *mm = vma->vm_mm;
 
if (sizeof(pteval_t) > sizeof(long))
/* 5 arg words */
-   pv_ops.mmu.ptep_modify_prot_commit(mm, addr, ptep, pte);
+   pv_ops.mmu.ptep_modify_prot_commit(vma, addr, ptep, pte);
else
PVOP_VCALL4(mmu.ptep_modify_prot_commit,
-   mm, addr, ptep, pte.pte);
+   vma, addr, ptep, pte.pte);
 }
 
 static inline void set_pte(pte_t *ptep, pte_t pte)
diff --git a/arch/x86/include/asm/paravirt_types.h 
b/arch/x86/include/asm/paravirt_types.h
index 26942ad63830..609a728ec809 100644
--- a/arch/x86/include/asm/paravirt_types.h
+++ b/arch/x86/include/asm/paravirt_types.h
@@ -55,6 +55,7 @@ struct task_struct;
 struct cpumask;
 struct flush_tlb_info;
 struct mmu_gather;
+struct vm_area_struct;
 
 /*
  * Wrapper type for pointers to code which uses the non-standard
@@ -254,9 +255,9 @@ struct pv_mmu_ops {
   pte_t *ptep, pte_t pteval);
void (*set_pmd)(pmd_t *pmdp, pmd_t pmdval);
 
-   pte_t (*ptep_modify_prot_start)(struct mm_struct *mm, unsigned long 
addr,
+   pte_t (*ptep_modify_prot_start)(struct vm_area_struct *vma, unsigned 
long addr,
pte_t *ptep);
-   void (*ptep_modify_prot_commit)(struct mm_struct *mm, unsigned long 
addr,
+   void (*ptep_modify_prot_commit)(struct vm_area_struct *vma, unsigned 
long addr,
pte_t *ptep, pte_t pte);
 
struct paravirt_callee_save pte_val;
diff --git a/arch/x86/xen/mmu.h b/arch/x86/xen/mmu.h
index a7e47cf7ec6c..6e4c6bd62203 100644
--- a/arch/x86/xen/mmu.h
+++ b/arch/x86/xen/mmu.h
@@ -17,8 +17,8 @@ bool __set_phys_to_machine(unsigned long pfn, unsigned long 
mfn);
 
 void set_pte_mfn(unsigned long vaddr, 

Re: use generic DMA mapping code in powerpc V4

2018-12-08 Thread Christian Zigotzky
Next step: e15cd8173ef85e9cc3e2a9c7cc2982f5c1355615 (powerpc/dma: fix an 
off-by-one in dma_capable)


git checkout e15cd8173ef85e9cc3e2a9c7cc2982f5c1355615

The PASEMI onboard ethernet also works with this commit and the X5000 
boots without any problems.


-- Christian


On 08 December 2018 at 11:29AM, Christian Zigotzky wrote:
Next step: 7ebc44c535f6bd726d553756d38b137acc718443 (powerpc/dma: 
remove max_direct_dma_addr)


git checkout 7ebc44c535f6bd726d553756d38b137acc718443

OK, the PASEMI onboard ethernet works and the P5020 board boots.

-- Christian


On 07 December 2018 at 7:33PM, Christian Zigotzky wrote:
Next step: 13c1fdec5682b6e13257277fa16aa31f342d167d (powerpc/dma: 
move pci_dma_dev_setup_swiotlb to fsl_pci.c)


git checkout 13c1fdec5682b6e13257277fa16aa31f342d167d

Result: The PASEMI onboard ethernet works and the P5020 board boots.

— Christian








Re: [PATCH 2/2] x86, powerpc: remove -funit-at-a-time compiler option entirely

2018-12-08 Thread Borislav Petkov
On Sat, Dec 08, 2018 at 03:36:52PM +0900, Masahiro Yamada wrote:
> x86 maintainers,
> 
> Ping.

You got the required ACKs. If you want me to carry this one and the
UML one through the tip tree, lemme know. Or you can do what Richard
suggested. Your call.

Thx.

-- 
Regards/Gruss,
Boris.

Good mailing practices for 400: avoid top-posting and trim the reply.


Re: use generic DMA mapping code in powerpc V4

2018-12-08 Thread Christian Zigotzky
Next step: 7ebc44c535f6bd726d553756d38b137acc718443 (powerpc/dma: remove 
max_direct_dma_addr)


git checkout 7ebc44c535f6bd726d553756d38b137acc718443

OK, the PASEMI onboard ethernet works and the P5020 board boots.

-- Christian


On 07 December 2018 at 7:33PM, Christian Zigotzky wrote:

Next step: 13c1fdec5682b6e13257277fa16aa31f342d167d (powerpc/dma: move 
pci_dma_dev_setup_swiotlb to fsl_pci.c)

git checkout 13c1fdec5682b6e13257277fa16aa31f342d167d

Result: The PASEMI onboard ethernet works and the P5020 board boots.

— Christian





Re: use generic DMA mapping code in powerpc V4

2018-12-08 Thread Benjamin Herrenschmidt
On Tue, 2018-11-27 at 08:42 +0100, Christoph Hellwig wrote:
> Any comments?  I'd like to at least get the ball moving on the easy
> bits.

I completely missed your posting of V4 ! I was wondering what was
taking you so long :)

I'll give it a spin & send acks over the next 2 or 3 days.

Cheers,
Ben.

> On Wed, Nov 14, 2018 at 09:22:40AM +0100, Christoph Hellwig wrote:
> > Hi all,
> > 
> > this series switches the powerpc port to use the generic swiotlb and
> > noncoherent dma ops, and to use more generic code for the coherent
> > direct mapping, as well as removing a lot of dead code.
> > 
> > As this series is very large and depends on the dma-mapping tree I've
> > also published a git tree:
> > 
> > git://git.infradead.org/users/hch/misc.git powerpc-dma.4
> > 
> > Gitweb:
> > 
> > 
> > http://git.infradead.org/users/hch/misc.git/shortlog/refs/heads/powerpc-dma.4
> > 
> > Changes since v3:
> >  - rebase on the powerpc fixes tree
> >  - add a new patch to actually make the baseline amigaone config
> >configure without warnings
> >  - only use ZONE_DMA for 64-bit embedded CPUs, on pseries an IOMMU is
> >always present
> >  - fix compile in mem.c for one configuration
> >  - drop the full npu removal for now, will be resent separately
> >  - a few git bisection fixes
> > 
> > The changes since v1 are to big to list and v2 was not posted in public.
> > 
> > ___
> > iommu mailing list
> > io...@lists.linux-foundation.org
> > https://lists.linuxfoundation.org/mailman/listinfo/iommu
> ---end quoted text---



Re: error: no previous prototype for ‘pt_regs_check’

2018-12-08 Thread Christophe LEROY

Mathieu,

Le 07/12/2018 à 21:07, Mathieu Malaterre a écrit :

Michael,

I have been wondering for a while now, but I failed to make sense of
this function: pt_regs_check (commit 002af9391bfbe). What is this
function meant for ?


AFAICS this is a dummy function, its purpose is to break the build if 
struct pt_regs and struct user_pt_regs don't match.




Background, it breaks my W=1 build with:

../arch/powerpc/kernel/ptrace.c:3339:13: error: no previous prototype
for ‘pt_regs_check’ [-Werror=missing-prototypes]


What about adding a prototype for it on the line above ?



I failed to find a usage of it within the linux source tree... (git
grep pt_regs_check returns nothing).


This function has no functionnal purpose, and will get eliminated at 
link time or after init depending on CONFIG_LD_DEAD_CODE_DATA_ELIMINATION



Christophe


Thanks,



Re: [PATCH 1/2] um: remove -fno-unit-at-a-time workaround for pre-4.0 GCC

2018-12-08 Thread Richard Weinberger
Am Samstag, 8. Dezember 2018, 07:35:47 CET schrieb Masahiro Yamada:
> x86 maintainers,
> 
> 
> Ping.

I thought you carry this via your kbuild tree.
That said, I can merge it also via the um tree.
x86 is of course also fine. :-)

> 
> 
> On Tue, Nov 13, 2018 at 6:48 PM Richard Weinberger  wrote:
> >
> > Am Montag, 12. November 2018, 03:35:19 CET schrieb Masahiro Yamada:
> > > Commit cafa0010cd51 ("Raise the minimum required gcc version to 4.6")
> > > bumped the minimum GCC version to 4.6 for all architectures.
> > >
> > > '$(call cc-option,-fno-unit-at-a-time)' is now dead code since
> > > '$(cc-version) -lt 0400' is always false.
> > >
> > > Signed-off-by: Masahiro Yamada 
> > > ---
> > >
> > >  arch/x86/Makefile.um | 8 ++--
> > >  1 file changed, 2 insertions(+), 6 deletions(-)
> > >
> > > diff --git a/arch/x86/Makefile.um b/arch/x86/Makefile.um
> > > index 91085a0..577976b 100644
> > > --- a/arch/x86/Makefile.um
> > > +++ b/arch/x86/Makefile.um
> > > @@ -26,12 +26,8 @@ cflags-y += $(call 
> > > cc-option,-mpreferred-stack-boundary=2)
> > >  # an unresolved reference.
> > >  cflags-y += -ffreestanding
> > >
> > > -# Disable unit-at-a-time mode on pre-gcc-4.0 compilers, it makes gcc use
> > > -# a lot more stack due to the lack of sharing of stacklots.  Also, gcc
> > > -# 4.3.0 needs -funit-at-a-time for extern inline functions.
> > > -KBUILD_CFLAGS += $(shell if [ $(cc-version) -lt 0400 ] ; then \
> > > - echo $(call cc-option,-fno-unit-at-a-time); \
> > > - else echo $(call cc-option,-funit-at-a-time); fi ;)
> > > +# gcc 4.3.0 needs -funit-at-a-time for extern inline functions.
> > > +KBUILD_CFLAGS += $(call cc-option,-funit-at-a-time)
> >
> > Acked-by: Richard Weinberger 

Thanks,
//richard