POWER8 Coherent Accelerator device driver
Subsystems (5)
v2 cover POWER8 Coherent Accelerator device driver
v2:
- Updates based on comments from, Anton, Gavin, Aneesh, jk and offline reviews
- Simplified copro_data_segment() and merged code with hash_page_mm()
(New patch 10/17)
- PCIe code simplifications based on Gavin's review
- Removed redundant comment in msi_bitmap_alloc_hwirqs()
- Fix for locking in idr_remove in core driver
- Ensure PSL is enabled when PHB is flipped to CXL mode
- Added CONFIG_PPC_COPRO_BASE to compile copro_fault.c
- Merged SPU and cxl slb flushing calls into copro_flush_all_slbs()
(New patch 03/17) - Moved slb_vsid_shift() to static inline from #define
- Don't write paca->context when demoting segments and mm != current
- Fix minor typos in documentation
v1:
- Initial post
This add support for the Coherent Accelerator (cxl) attached to POWER8 processors. This coherent accelerator interface is designed to allow the coherent connection of FPGA based accelerators (and other devices) to a POWER systems.
IBM refers to this as the Coherent Accelerator Processor Interface or CAPI. In this driver it's referred to by the name cxl to avoid confusion with the ISDN CAPI subsystem.
An overview of the patches:
Patches 1-3: Split some of the old Cell co-processor code out so it can be
reused.
Patches 4-11: Add infrastructure to arch/powerpc needed by cxl. Patches 12: Add call backs needed for invalidating cxl mm contexts. Patch 13: Add cxl specific support that needs to be built in to the
kernel (can't be a module).
Patches 14-16: Add the majority of the device driver and API header.
Patch 17: Documentation.
The documentation in this last patch gives an overview of the hardware architecture as well as the userspace API.
The cxl driver has a user-space interface described in include/uapi/misc/cxl.h and Documentation/powerpc/cxl.txt. There are two ioctls which can be used to talk to the driver once the new /dev/cxl/afu0.0 device is opened. This device can also be read and mmaped.
There's also sysfs entries used to communicate information about the cxl configuration to userspace. These are documented in Documentation/ABI/testing/sysfs-class-cxl.
Many contributed to this device driver but Ian Munsie is the principal author.
Driver can also be found here (based on 3.17-rc5):
git://github.com/mikey/linux.git cxl
https://github.com/mikey/linux/commits/cxl
(Series rebases on recent linux-next with one trivial include file conflict)
Please consider for inclusion. Feedback welcome!
Regards,
Mikey
Documentation/ABI/testing/sysfs-class-cxl | 125 ++++ Documentation/ioctl/ioctl-number.txt | 1 + Documentation/powerpc/00-INDEX | 2 + Documentation/powerpc/cxl.txt | 310 ++++++++ MAINTAINERS | 7 + arch/powerpc/Kconfig | 4 + arch/powerpc/include/asm/copro.h | 24 + arch/powerpc/include/asm/mmu-hash64.h | 10 +- arch/powerpc/include/asm/opal.h | 2 + arch/powerpc/include/asm/pnv-pci.h | 27 + arch/powerpc/include/asm/spu.h | 5 +- arch/powerpc/mm/Makefile | 1 + arch/powerpc/mm/copro_fault.c | 124 ++++ arch/powerpc/mm/hash_native_64.c | 6 +- arch/powerpc/mm/hash_utils_64.c | 95 ++- arch/powerpc/mm/slb.c | 3 - arch/powerpc/mm/slice.c | 10 +- arch/powerpc/platforms/cell/Kconfig | 1 + arch/powerpc/platforms/cell/Makefile | 2 +- arch/powerpc/platforms/cell/spu_base.c | 41 +- arch/powerpc/platforms/cell/spu_fault.c | 94 --- arch/powerpc/platforms/cell/spufs/fault.c | 4 +- arch/powerpc/platforms/powernv/opal-wrappers.S | 1 + arch/powerpc/platforms/powernv/pci-ioda.c | 204 +++++- arch/powerpc/sysdev/msi_bitmap.c | 23 +- drivers/misc/Kconfig | 1 + drivers/misc/Makefile | 1 + drivers/misc/cxl/Kconfig | 26 + drivers/misc/cxl/Makefile | 4 + drivers/misc/cxl/base.c | 102 +++ drivers/misc/cxl/context.c | 171 +++++ drivers/misc/cxl/cxl-pci.c | 964 +++++++++++++++++++++++++ drivers/misc/cxl/cxl.h | 605 ++++++++++++++++ drivers/misc/cxl/debugfs.c | 116 +++ drivers/misc/cxl/fault.c | 298 ++++++++ drivers/misc/cxl/file.c | 503 +++++++++++++ drivers/misc/cxl/irq.c | 405 +++++++++++ drivers/misc/cxl/main.c | 238 ++++++ drivers/misc/cxl/native.c | 649 +++++++++++++++++ drivers/misc/cxl/sysfs.c | 348 +++++++++ include/misc/cxl.h | 34 + include/uapi/Kbuild | 1 + include/uapi/misc/Kbuild | 2 + include/uapi/misc/cxl.h | 88 +++ 44 files changed, 5469 insertions(+), 213 deletions(-)
PATCH v2 1/17 powerpc/cell: Move spu_handle_mm_fault() out of cell platform
From: Ian Munsie <[email protected]>
Currently spu_handle_mm_fault() is in the cell platform.
This code is generically useful for other non-cell co-processors on powerpc.
This patch moves this function out of the cell platform into arch/powerpc/mm so that others may use it.
---
arch/powerpc/Kconfig | 4 ++++
arch/powerpc/include/asm/copro.h | 18 ++++++++++++++++++
arch/powerpc/include/asm/spu.h | 5 ++---
arch/powerpc/mm/Makefile | 1 +
.../{platforms/cell/spu_fault.c => mm/copro_fault.c} | 14 ++++++--------
arch/powerpc/platforms/cell/Kconfig | 1 +
arch/powerpc/platforms/cell/Makefile | 2 +-
arch/powerpc/platforms/cell/spufs/fault.c | 4 ++--
8 files changed, 35 insertions(+), 14 deletions(-)
create mode 100644 arch/powerpc/include/asm/copro.h
rename arch/powerpc/{platforms/cell/spu_fault.c => mm/copro_fault.c} (89%)arch/powerpc/Kconfig +4 -0
@@ -603,6 +603,10 @@ config PPC_SUBPAGE_PROT to set access permissions (read/write, readonly, or no access) on the 4k subpages of each 64k page. +config PPC_COPRO_BASE + bool + default n + config SCHED_SMT bool "SMT (Hyperthreading) scheduler support" depends on PPC64 && SMP
arch/powerpc/include/asm/copro.h new file +18 -0
@@ -0,0 +1,18 @@ +/* +* Copyright 2014 IBM Corp. +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation; either version +* 2 of the License, or (at your option) any later version. +*/ + +#ifndef _ASM_POWERPC_COPRO_H +#define _ASM_POWERPC_COPRO_H + +int copro_handle_mm_fault (struct mm_struct *mm,unsigned long ea, +unsigned long dsisr,unsigned *flt); + +int copro_data_segment (struct mm_struct *mm,u64 ea,u64 *esid,u64 *vsid); + +#endif /* _ASM_POWERPC_COPRO_H */
arch/powerpc/include/asm/spu.h +2 -3
@@ -27,6 +27,8 @@#include <linux/workqueue.h> #include <linux/device.h> #include <linux/mutex.h> +#include <asm/reg.h> +#include <asm/copro.h> #define LS_SIZE (256 * 1024)#define LS_ADDR_MASK (LS_SIZE - 1)
@@ -277,9 +279,6 @@ void spu_remove_dev_attr(struct device_attribute *attr);int spu_add_dev_attr_group (struct attribute_group *attrs);void spu_remove_dev_attr_group (struct attribute_group *attrs); -int spu_handle_mm_fault (struct mm_struct *mm,unsigned long ea, -unsigned long dsisr,unsigned *flt); -/* * Notifier blocks: *
arch/powerpc/mm/Makefile +1 -0
@@ -34,3 +34,4 @@ obj-$(CONFIG_TRANSPARENT_HUGEPAGE) += hugepage-hash64.o obj-$(CONFIG_PPC_SUBPAGE_PROT) += subpage-prot.o obj-$(CONFIG_NOT_COHERENT_CACHE) += dma-noncoherent.o obj-$(CONFIG_HIGHMEM) += highmem.o +obj-$(CONFIG_PPC_COPRO_BASE) += copro_fault.o
arch/powerpc/mm/copro_fault.c renamed from arch/powerpc/platforms/cell/spu_fault.c +6 -8
@@ -1,5 +1,5 @@/* -* SPU mm fault handler +* CoProcessor (SPU/AFU) mm fault handler * * (C) Copyright IBM Deutschland Entwicklung GmbH 2007 *
@@ -23,16 +23,14 @@#include <linux/sched.h> #include <linux/mm.h> #include <linux/export.h> - -#include <asm/spu.h> -#include <asm/spu_csa.h> +#include <asm/reg.h> /* * This ought to be kept in sync with the powerpc specific do_page_fault * function. Currently, there are a few corner cases that we haven't had * to handle fortunately. */ -int spu_handle_mm_fault (struct mm_struct *mm,unsigned long ea, +int copro_handle_mm_fault (struct mm_struct *mm,unsigned long ea,unsigned long dsisr,unsigned *flt) {struct vm_area_struct *vma;
@@ -58,12 +56,12 @@ int spu_handle_mm_fault(struct mm_struct *mm, unsigned long ea, goto out_unlock; } - is_write = dsisr &MFC_DSISR_ACCESS_PUT ; + is_write = dsisr &DSISR_ISSTORE ;if (is_write) {if (!(vma->vm_flags &VM_WRITE )) goto out_unlock; }else { -if (dsisr &MFC_DSISR_ACCESS_DENIED ) +if (dsisr &DSISR_PROTFAULT ) goto out_unlock;if (!(vma->vm_flags & (VM_READ |VM_EXEC ))) goto out_unlock;
@@ -91,4 +89,4 @@ out_unlock:up_read (&mm->mmap_sem);return ret; } -EXPORT_SYMBOL_GPL (spu_handle_mm_fault); +EXPORT_SYMBOL_GPL (copro_handle_mm_fault);
arch/powerpc/platforms/cell/Kconfig +1 -0
@@ -86,6 +86,7 @@ config SPU_FS_64K_LS config SPU_BASE bool default n + select PPC_COPRO_BASE config CBE_RAS bool "RAS features for bare metal Cell BE"
arch/powerpc/platforms/cell/Makefile +1 -1
@@ -20,7 +20,7 @@ spu-manage-$(CONFIG_PPC_CELL_COMMON) += spu_manage.o obj-$(CONFIG_SPU_BASE) += spu_callbacks.o spu_base.o \ spu_notify.o \ - spu_syscalls.o spu_fault.o \ + spu_syscalls.o \ $(spu-priv1-y) \ $(spu-manage-y) \ spufs/
arch/powerpc/platforms/cell/spufs/fault.c +2 -2
@@ -138,7 +138,7 @@ int spufs_handle_class1(struct spu_context *ctx)if (ctx->state ==SPU_STATE_RUNNABLE ) ctx->spu->stats.hash_flt++; -/* we must not hold the lock when entering spu_handle_mm_fault */ +/* we must not hold the lock when entering copro_handle_mm_fault */ spu_release (ctx); access = (_PAGE_PRESENT | _PAGE_USER);
@@ -149,7 +149,7 @@ int spufs_handle_class1(struct spu_context *ctx)/* hashing failed, so try the actual fault handler */ if (ret) - ret =spu_handle_mm_fault (current->mm, ea, dsisr, &flt); + ret =copro_handle_mm_fault (current->mm, ea, dsisr, &flt);/* * This is nasty: we need the state_mutex for all the bookkeeping even
Signature · 1 line
1.9.1
PATCH v2 2/17 powerpc/cell: Move data segment faulting code out of cell platform
In reply to Michael NeulingFrom: Ian Munsie <[email protected]>
__spu_trap_data_seg() currently contains code to determine the VSID and ESID required for a particular EA and mm struct.
This code is generically useful for other co-processors. This moves the code of the cell platform so it can be used by other powerpc code. It also adds 1TB segment handling which Cell didn't have.
--- arch/powerpc/include/asm/mmu-hash64.h | 7 ++++- arch/powerpc/mm/copro_fault.c | 48 ++++++++++++++++++++++++++++++++++ arch/powerpc/mm/slb.c | 3 --- arch/powerpc/platforms/cell/spu_base.c | 41 +++-------------------------- 4 files changed, 58 insertions(+), 41 deletions(-)
arch/powerpc/include/asm/mmu-hash64.h +6 -1
@@ -189,7 +189,12 @@ static inline unsigned int mmu_psize_to_shift(unsigned int mmu_psize)#define LP_MASK (i) ((0xFF >> (i)) << LP_SHIFT)#ifndef __ASSEMBLY__ - +static inline int slb_vsid_shift (int ssize) +{ +if (ssize ==MMU_SEGSIZE_256M ) +return SLB_VSID_SHIFT ; +return SLB_VSID_SHIFT_1T ; +}static inline int segment_shift (int ssize) {if (ssize ==MMU_SEGSIZE_256M )
arch/powerpc/mm/copro_fault.c +48 -0
51 lines not on this page · raw message
arch/powerpc/mm/slb.c +0 -3
@@ -46,9 +46,6 @@ static inline unsigned long mk_esid_data(unsigned long ea, int ssize,return (ea &slb_esid_mask (ssize)) |SLB_ESID_V | slot; } -#define slb_vsid_shift (ssize) \ - ((ssize) == MMU_SEGSIZE_256M? SLB_VSID_SHIFT: SLB_VSID_SHIFT_1T) -static inline unsigned long mk_vsid_data (unsigned long ea,int ssize,unsigned long flags) {
arch/powerpc/platforms/cell/spu_base.c +4 -37
49 lines not on this page · raw message
Signature · 1 line
1.9.1
Michael Ellerman
reviewerRe: [PATCH v2 02/17] powerpc/cell: Move data segment faulting code out of cell platform
Quoted 8 lines · Michael Neuling
From: Ian Munsie <[email protected]>
__spu_trap_data_seg()currently contains code to determine the VSID and ESID required for a particular EA and mm struct.This code is generically useful for other co-processors. This moves the code of the cell platform so it can be used by other powerpc code. It also adds 1TB segment handling which Cell didn't have.
I'm not loving this.
For starters the name "copro_data_segment()" doesn't contain any verbs, and it doesn't tell me what it does.
If we give it a name that says what it does, we get copro_get_ea_esid_and_vsid(). Or something equally ugly.
And then in patch 10 you move the bulk of the logic into calculate_vsid().
So instead can we:
- add a small helper that does the esid calculation, eg. calculate_esid() ?
- factor out the vsid logic into a helper, calculate_vsid() ?
- rework the spu code to use those, dropping __spu_trap_data_seg()
- use the helpers in the cxl code
cheers
Re: [PATCH v2 02/17] powerpc/cell: Move data segment faulting code out of cell platform
Quoted 4 lines · Michael Ellerman
If we give it a name that says what it does, we get
copro_get_ea_esid_and_vsid().
Or something equally ugly.
copro_calc_full_va() ?
Ben.
Re: [PATCH v2 02/17] powerpc/cell: Move data segment faulting code out of cell platform
In reply to Michael EllermanQuoted 4 lines · Michael Ellerman
Quoted 3 lines · Michael Neuling
From: Ian Munsie <[email protected]>
=20__spu_trap_data_seg()currently contains code to determine the VSID and=
ESID
Quoted 3 lines
Quoted 3 lines
required for a particular EA and mm struct.
=20
This code is generically useful for other co-processors. This moves th=
e code
Quoted 1 line
Quoted 1 line
of the cell platform so it can be used by other powerpc code. It also =
adds 1TB
Quoted 5 lines
Quoted 1 line
segment handling which Cell didn't have.
=20
I'm not loving this.
=20
For starters the name "copro_data_segment()" doesn't contain any verbs, a=
nd it
Quoted 1 line
doesn't tell me what it does.
Ok.
Quoted 1 line
If we give it a name that says what it does, we get copro_get_ea_esid_and=
_vsid().
Quoted 1 line
Or something equally ugly.
Ok
Quoted 1 line
And then in patch 10 you move the bulk of the logic into calculate_vsid()=
.
That was intentional on my part. I want this patch to be clear that we're moving this code out of cell. Then I wanted the optimisations to be in a separate patch. It does mean we touch the code twice in this series, but I was hoping it would make it easier to review. Alas. :-)
Quoted 2 lines
So instead can we:
- add a small helper that does the esid calculation, eg. calculate_esid(=
) ?
Quoted 3 lines
- factor out the vsid logic into a helper,
calculate_vsid()?
- rework the spu code to use those, dropping__spu_trap_data_seg()
- use the helpers in the cxl code
OK, I think I can do that. I might change the name to something better in this patch, but I'll leave these cleanups to the later patch 10.
Mikey
Re: [PATCH v2 02/17] powerpc/cell: Move data segment faulting code out of cell platform
In reply to Michael NeulingQuoted 49 lines · Michael Neuling
From: Ian Munsie <[email protected]>
__spu_trap_data_seg()currently contains code to determine the VSID and ESID required for a particular EA and mm struct.This code is generically useful for other co-processors. This moves the code of the cell platform so it can be used by other powerpc code. It also adds 1TB segment handling which Cell didn't have.
Signed-off-by Ian Munsie <[email protected]>Signed-off-by Michael Neuling <[email protected]>--- arch/powerpc/include/asm/mmu-hash64.h | 7 ++++- arch/powerpc/mm/copro_fault.c | 48 ++++++++++++++++++++++++++++++++++ arch/powerpc/mm/slb.c | 3 --- arch/powerpc/platforms/cell/spu_base.c | 41 +++-------------------------- 4 files changed, 58 insertions(+), 41 deletions(-)arch/powerpc/include/asm/mmu-hash64.h +6
-1@@ -189,7 +189,12 @@ static inline unsigned int mmu_psize_to_shift(unsigned int mmu_psize)#define LP_MASK (i) ((0xFF >> (i)) << LP_SHIFT)#ifndef __ASSEMBLY__ - +static inline int slb_vsid_shift (int ssize) +{ +if (ssize ==MMU_SEGSIZE_256M ) +return SLB_VSID_SHIFT ; +return SLB_VSID_SHIFT_1T ; +}static inline int segment_shift (int ssize) {if (ssize ==MMU_SEGSIZE_256M )arch/powerpc/mm/copro_fault.c +5
-0@@ -90,3 +90,51 @@ out_unlock:return ret; }EXPORT_SYMBOL_GPL (copro_handle_mm_fault); + +int copro_data_segment (struct mm_struct *mm,u64 ea,u64 *esid,u64 *vsid) +{ +int psize, ssize; +
arch/powerpc/mm/copro_fault.c out_unlock: · line 107
Quoted 10 lines
arch/powerpc/mm/copro_fault.c +10
-0+ *esid = (ea &ESID_MASK ) |SLB_ESID_V ; + +switch (REGION_ID (ea)) { +case USER_REGION_ID : +pr_devel ("copro_data_segment: 0x%llx -- USER_REGION_ID\n" , ea); +#ifdef CONFIG_PPC_MM_SLICES + psize =get_slice_psize (mm, ea); +#else + psize = mm->context.user_psize; +#endif
We don't really need that as explained in last review.
-aneesh
Re: [PATCH v2 02/17] powerpc/cell: Move data segment faulting code out of cell platform
Quoted 5 lines · Aneesh Kumar K.V
Michael Neuling <[email protected]> writes:
=20Quoted 3 lines
From: Ian Munsie <[email protected]>
__spu_trap_data_seg()currently contains code to determine the VSID and=
ESID
Quoted 3 lines
Quoted 3 lines
required for a particular EA and mm struct.
This code is generically useful for other co-processors. This moves th=
e code
Quoted 1 line
Quoted 1 line
of the cell platform so it can be used by other powerpc code. It also =
adds 1TB
Quoted 7 lines
Quoted 7 lines
segment handling which Cell didn't have.
Signed-off-by Ian Munsie <[email protected]>Signed-off-by Michael Neuling <[email protected]>--- arch/powerpc/include/asm/mmu-hash64.h | 7 ++++-
arch/powerpc/mm/copro_fault.c| 48 ++++++++++++++++++++++++++=
++++++++
Quoted 2 lines
Quoted 2 lines
arch/powerpc/mm/slb.c | 3 ---
arch/powerpc/platforms/cell/spu_base.c| 41 +++-----------------------=
---
Quoted 3 lines
arch/powerpc/inclu=
Quoted 3 lines
4 files changed, 58 insertions(+), 41 deletions(-)arch/powerpc/inclu= renamed from arch/powerpc/include/asm/mmu-hash64.h +0
-0
de/asm/mmu-hash64.h
Quoted 4 lines
arch/powerpc/include/asm/mmu-hash64.h static inline unsigned int mmu_psize_to_shift(unsi=
Quoted 4 lines
index d765144..6d0b7a2 100644
arch/powerpc/include/asm/mmu-hash64.h +0
-0@@ -189,7 +189,12 @@ static inline unsigned int mmu_psize_to_shift(unsi=
gned int mmu_psize)
Quoted 6 lines
Quoted 6 lines
arch/powerpc/include/asm/mmu-hash64.h +0
-0#define LP_MASK (i) ((0xFF >> (i)) << LP_SHIFT)=20
#ifndef__ASSEMBLY__arch/powerpc/include/asm/mmu-hash64.h +2
-1- +static inline int slb_vsid_shift (int ssize) +{
Quoted 8 lines
arch/powerpc/mm/copro_faul=
Quoted 8 lines
arch/powerpc/include/asm/mmu-hash64.h +4
-0+ if (ssize =3D=3D MMU_SEGSIZE_256M) +return SLB_VSID_SHIFT ; +return SLB_VSID_SHIFT_1T ; +}static inline int segment_shift (int ssize) { if (ssize =3D=3D MMU_SEGSIZE_256M)arch/powerpc/mm/copro_faul= renamed from arch/powerpc/mm/copro_fault.c +0
-0
t.c
Quoted 9 lines
arch/powerpc/mm/copro_fault.c out_unlock: · line 94
Quoted 9 lines
index ba7df14..b865697 100644
arch/powerpc/mm/copro_fault.c +2
-0@@ -90,3 +90,51 @@ out_unlock:return ret; }EXPORT_SYMBOL_GPL (copro_handle_mm_fault); + +int copro_data_segment(struct mm_struct *mm, u64 ea, u64 *esid, u64 *v=
sid)
Quoted 7 lines
Quoted 7 lines
arch/powerpc/mm/copro_fault.c +7
-0+{ +int psize, ssize; + + *esid =3D (ea &ESID_MASK ) |SLB_ESID_V ; + +switch (REGION_ID (ea)) { +case USER_REGION_ID :
Quoted 8 lines
arch/powerpc/mm/copro_fault.c out_unlock: · line 107
Quoted 6 lines
arch/powerpc/mm/copro_fault.c +6
-0+pr_devel ("copro_data_segment: 0x%llx -- USER_REGION_ID\n" , ea); +#ifdef CONFIG_PPC_MM_SLICES + psize =3D get_slice_psize(mm, ea); +#else + psize =3D mm->context.user_psize; +#endif =20
We don't really need that as explained in last review.
That cleanup is in patch 10. I avoided changing it here so it's clearer that what is being removed is the same as what is being added.
Mikey
Re: [PATCH v2 02/17] powerpc/cell: Move data segment faulting code out of cell platform
In reply to Michael NeulingQuoted 62 lines · Michael Neuling
From: Ian Munsie <[email protected]>
__spu_trap_data_seg()currently contains code to determine the VSID and ESID required for a particular EA and mm struct.This code is generically useful for other co-processors. This moves the code of the cell platform so it can be used by other powerpc code. It also adds 1TB segment handling which Cell didn't have.
Signed-off-by Ian Munsie <[email protected]>Signed-off-by Michael Neuling <[email protected]>--- arch/powerpc/include/asm/mmu-hash64.h | 7 ++++- arch/powerpc/mm/copro_fault.c | 48 ++++++++++++++++++++++++++++++++++ arch/powerpc/mm/slb.c | 3 --- arch/powerpc/platforms/cell/spu_base.c | 41 +++-------------------------- 4 files changed, 58 insertions(+), 41 deletions(-)arch/powerpc/include/asm/mmu-hash64.h +6
-1@@ -189,7 +189,12 @@ static inline unsigned int mmu_psize_to_shift(unsigned int mmu_psize)#define LP_MASK (i) ((0xFF >> (i)) << LP_SHIFT)#ifndef __ASSEMBLY__ - +static inline int slb_vsid_shift (int ssize) +{ +if (ssize ==MMU_SEGSIZE_256M ) +return SLB_VSID_SHIFT ; +return SLB_VSID_SHIFT_1T ; +}static inline int segment_shift (int ssize) {if (ssize ==MMU_SEGSIZE_256M )arch/powerpc/mm/copro_fault.c +18
-0@@ -90,3 +90,51 @@ out_unlock:return ret; }EXPORT_SYMBOL_GPL (copro_handle_mm_fault); + +int copro_data_segment (struct mm_struct *mm,u64 ea,u64 *esid,u64 *vsid) +{ +int psize, ssize; + + *esid = (ea &ESID_MASK ) |SLB_ESID_V ; + +switch (REGION_ID (ea)) { +case USER_REGION_ID : +pr_devel ("copro_data_segment: 0x%llx -- USER_REGION_ID\n" , ea); +#ifdef CONFIG_PPC_MM_SLICES + psize =get_slice_psize (mm, ea); +#else + psize = mm->context.user_psize; +#endif + ssize =user_segment_size (ea); + *vsid = (get_vsid (mm->context.id, ea, ssize) + <<slb_vsid_shift (ssize)) |SLB_VSID_USER ;
arch/powerpc/mm/copro_fault.c out_unlock: · line 120
Quoted 10 lines
arch/powerpc/mm/copro_fault.c +10
-0+break ; +case VMALLOC_REGION_ID : +pr_devel ("copro_data_segment: 0x%llx -- VMALLOC_REGION_ID\n" , ea); +if (ea <VMALLOC_END ) + psize = mmu_vmalloc_psize; +else + psize = mmu_io_psize; + ssize = mmu_kernel_ssize; + *vsid = (get_kernel_vsid (ea, mmu_kernel_ssize) + <<SLB_VSID_SHIFT ) |SLB_VSID_KERNEL ;
why not
*vsid = (get_kernel_vsid(ea, mmu_kernel_ssize) << slb_vsid_shift(ssize)) | SLB_VSID_KERNEL;
for vmalloc and kernel region ? We could end up using 1T segments for kernel mapping too.
-aneesh
Re: [PATCH v2 02/17] powerpc/cell: Move data segment faulting code out of cell platform
Quoted 5 lines · Aneesh Kumar K.V
Michael Neuling <[email protected]> writes:
=20Quoted 3 lines
From: Ian Munsie <[email protected]>
__spu_trap_data_seg()currently contains code to determine the VSID and=
ESID
Quoted 3 lines
Quoted 3 lines
required for a particular EA and mm struct.
This code is generically useful for other co-processors. This moves th=
e code
Quoted 1 line
Quoted 1 line
of the cell platform so it can be used by other powerpc code. It also =
adds 1TB
Quoted 7 lines
Quoted 7 lines
segment handling which Cell didn't have.
Signed-off-by Ian Munsie <[email protected]>Signed-off-by Michael Neuling <[email protected]>--- arch/powerpc/include/asm/mmu-hash64.h | 7 ++++-
arch/powerpc/mm/copro_fault.c| 48 ++++++++++++++++++++++++++=
++++++++
Quoted 2 lines
Quoted 2 lines
arch/powerpc/mm/slb.c | 3 ---
arch/powerpc/platforms/cell/spu_base.c| 41 +++-----------------------=
---
Quoted 3 lines
arch/powerpc/inclu=
Quoted 3 lines
4 files changed, 58 insertions(+), 41 deletions(-)arch/powerpc/inclu= renamed from arch/powerpc/include/asm/mmu-hash64.h +0
-0
de/asm/mmu-hash64.h
Quoted 4 lines
arch/powerpc/include/asm/mmu-hash64.h static inline unsigned int mmu_psize_to_shift(unsi=
Quoted 4 lines
index d765144..6d0b7a2 100644
arch/powerpc/include/asm/mmu-hash64.h +0
-0@@ -189,7 +189,12 @@ static inline unsigned int mmu_psize_to_shift(unsi=
gned int mmu_psize)
Quoted 6 lines
Quoted 6 lines
arch/powerpc/include/asm/mmu-hash64.h +0
-0#define LP_MASK (i) ((0xFF >> (i)) << LP_SHIFT)=20
#ifndef__ASSEMBLY__arch/powerpc/include/asm/mmu-hash64.h +2
-1- +static inline int slb_vsid_shift (int ssize) +{
Quoted 8 lines
arch/powerpc/mm/copro_faul=
Quoted 8 lines
arch/powerpc/include/asm/mmu-hash64.h +4
-0+ if (ssize =3D=3D MMU_SEGSIZE_256M) +return SLB_VSID_SHIFT ; +return SLB_VSID_SHIFT_1T ; +}static inline int segment_shift (int ssize) { if (ssize =3D=3D MMU_SEGSIZE_256M)arch/powerpc/mm/copro_faul= renamed from arch/powerpc/mm/copro_fault.c +0
-0
t.c
Quoted 9 lines
arch/powerpc/mm/copro_fault.c out_unlock: · line 94
Quoted 9 lines
index ba7df14..b865697 100644
arch/powerpc/mm/copro_fault.c +2
-0@@ -90,3 +90,51 @@ out_unlock:return ret; }EXPORT_SYMBOL_GPL (copro_handle_mm_fault); + +int copro_data_segment(struct mm_struct *mm, u64 ea, u64 *esid, u64 *v=
sid)
Quoted 28 lines
Quoted 16 lines
arch/powerpc/mm/copro_fault.c +16
-0+{ +int psize, ssize; + + *esid =3D (ea &ESID_MASK ) |SLB_ESID_V ; + +switch (REGION_ID (ea)) { +case USER_REGION_ID : +pr_devel ("copro_data_segment: 0x%llx -- USER_REGION_ID\n" , ea); +#ifdef CONFIG_PPC_MM_SLICES + psize =3D get_slice_psize(mm, ea); +#else + psize =3D mm->context.user_psize; +#endif + ssize =3D user_segment_size(ea); + *vsid =3D (get_vsid (mm->context.id, ea, ssize) + <<slb_vsid_shift (ssize)) |SLB_VSID_USER ;arch/powerpc/mm/copro_fault.c out_unlock: · line 120
Quoted 10 lines
arch/powerpc/mm/copro_fault.c +10
-0+break ; +case VMALLOC_REGION_ID : +pr_devel ("copro_data_segment: 0x%llx -- VMALLOC_REGION_ID\n" , ea); +if (ea <VMALLOC_END ) + psize =3D mmu_vmalloc_psize; +else + psize =3D mmu_io_psize; + ssize =3D mmu_kernel_ssize; + *vsid =3D (get_kernel_vsid (ea, mmu_kernel_ssize) + <<SLB_VSID_SHIFT ) |SLB_VSID_KERNEL ;=20
why not
Quoted 4 lines
*vsid =3D (get_kernel_vsid(ea, mmu_kernel_ssize) << slb_vsid_shift(ssize)) | SLB_VSID_KERNEL;=20
for vmalloc and kernel region ? We could end up using 1T segments for ker=
nel mapping too.
Yep, but I'm going to do this in patch 10 where the other optimisations are for this.
Mikey
PATCH v2 3/17 powerpc/cell: Make spu_flush_all_slbs() generic
In reply to Michael NeulingFrom: Ian Munsie <[email protected]>
This moves spu_flush_all_slbs() into a generic call copro_flush_all_slbs().
This will be useful when we add cxl which also needs a similar SLB flush call.
--- arch/powerpc/include/asm/copro.h | 6 ++++++ arch/powerpc/mm/copro_fault.c | 9 +++++++++ arch/powerpc/mm/hash_utils_64.c | 10 +++------- arch/powerpc/mm/slice.c | 10 +++------- 4 files changed, 21 insertions(+), 14 deletions(-)
arch/powerpc/include/asm/copro.h +6 -0
@@ -15,4 +15,10 @@ int copro_handle_mm_fault(struct mm_struct *mm, unsigned long ea,int copro_data_segment (struct mm_struct *mm,u64 ea,u64 *esid,u64 *vsid); + +#ifdef CONFIG_PPC_COPRO_BASE +void copro_flush_all_slbs (struct mm_struct *mm); +#else +#define copro_flush_all_slbs (mm) do {} while(0) +#endif #endif /* _ASM_POWERPC_COPRO_H */
arch/powerpc/mm/copro_fault.c +9 -0
@@ -24,6 +24,7 @@#include <linux/mm.h> #include <linux/export.h> #include <asm/reg.h> +#include <asm/spu.h> /* * This ought to be kept in sync with the powerpc specific do_page_fault
@@ -138,3 +139,11 @@ int copro_data_segment(struct mm_struct *mm, u64 ea, u64 *esid, u64 *vsid)return 0 ; }EXPORT_SYMBOL_GPL (copro_data_segment); + +void copro_flush_all_slbs (struct mm_struct *mm) +{ +#ifdef CONFIG_SPU_BASE +spu_flush_all_slbs (mm); +#endif +} +EXPORT_SYMBOL_GPL (copro_flush_all_slbs);
arch/powerpc/mm/hash_utils_64.c +3 -7
@@ -51,7 +51,7 @@#include <asm/cacheflush.h> #include <asm/cputable.h> #include <asm/sections.h> -#include <asm/spu.h> +#include <asm/copro.h> #include <asm/udbg.h> #include <asm/code-patching.h> #include <asm/fadump.h>
@@ -901,9 +901,7 @@ void demote_segment_4k(struct mm_struct *mm, unsigned long addr)if (get_slice_psize (mm, addr) ==MMU_PAGE_4K )return ;slice_set_range_psize (mm, addr,1 ,MMU_PAGE_4K ); -#ifdef CONFIG_SPU_BASE -spu_flush_all_slbs (mm); -#endif +copro_flush_all_slbs (mm);if (get_paca_psize (addr) !=MMU_PAGE_4K ) {get_paca ()->context = mm->context;slb_flush_and_rebolt ();
@@ -1141,9 +1139,7 @@ int hash_page(unsigned long ea, unsigned long access, unsigned long trap)"to 4kB pages because of " "non-cacheable mapping\n"); psize = mmu_vmalloc_psize =MMU_PAGE_4K ; -#ifdef CONFIG_SPU_BASE -spu_flush_all_slbs (mm); -#endif +copro_flush_all_slbs (mm); } }
arch/powerpc/mm/slice.c +3 -7
@@ -32,7 +32,7 @@#include <linux/export.h> #include <asm/mman.h> #include <asm/mmu.h> -#include <asm/spu.h> +#include <asm/copro.h> /* some sanity checks */ #if (PGTABLE_RANGE >>43 ) >SLICE_MASK_SIZE
@@ -232,9 +232,7 @@ static void slice_convert(struct mm_struct *mm, struct slice_mask mask, int psizspin_unlock_irqrestore (&slice_convert_lock, flags); -#ifdef CONFIG_SPU_BASE -spu_flush_all_slbs (mm); -#endif +copro_flush_all_slbs (mm); }/*
@@ -671,9 +669,7 @@ void slice_set_psize(struct mm_struct *mm, unsigned long address,spin_unlock_irqrestore (&slice_convert_lock, flags); -#ifdef CONFIG_SPU_BASE -spu_flush_all_slbs (mm); -#endif +copro_flush_all_slbs (mm); } void slice_set_range_psize(struct mm_struct *mm, unsigned long start,
Signature · 1 line
1.9.1
Re: [PATCH v2 03/17] powerpc/cell: Make spu_flush_all_slbs() generic
Quoted 9 lines · On Tuesday 30 September 2014 20:34:52 Michael Neuling wrote:
From: Ian Munsie <[email protected]>
This moves
spu_flush_all_slbs()into a generic callcopro_flush_all_slbs().This will be useful when we add cxl which also needs a similar SLB flush call.
Signed-off-by Ian Munsie <[email protected]>Signed-off-by Michael Neuling <[email protected]>
Very nice!
Michael Ellerman
reviewerRe: [PATCH v2 03/17] powerpc/cell: Make spu_flush_all_slbs() generic
In reply to Michael Neulingarch/powerpc/include/asm/copro.h int copro_handle_mm_fault(struct mm_struct *mm, unsigned long ea, · line 22
Quoted 13 lines · Michael Neuling
arch/powerpc/include/asm/copro.h +5
-0@@ -15,4 +15,10 @@ int copro_handle_mm_fault(struct mm_struct *mm, unsigned long ea,int copro_data_segment (struct mm_struct *mm,u64 ea,u64 *esid,u64 *vsid); + +#ifdef CONFIG_PPC_COPRO_BASE +void copro_flush_all_slbs (struct mm_struct *mm); +#else +#define copro_flush_all_slbs (mm) do {} while(0)
This can be a static inline, so it should be. That way you get type checking on the argument for CONFIG_PPC_COPRO_BASE=n.
cheers
Re: [PATCH v2 03/17] powerpc/cell: Make spu_flush_all_slbs() generic
Quoted 2 lines · Michael Ellerman
arch/powerpc/include/as=
Quoted 1 line · Michael Neuling
arch/powerpc/include/as= renamed from arch/powerpc/include/asm/copro.h +0
-0
m/copro.h
Quoted 4 lines
arch/powerpc/include/asm/copro.h int copro_handle_mm_fault(struct mm_struct *mm, unsi=
Quoted 4 lines
index 2858108..f3d338f 100644
arch/powerpc/include/asm/copro.h +0
-0@@ -15,4 +15,10 @@ int copro_handle_mm_fault(struct mm_struct *mm, unsi=
gned long ea,
Quoted 2 lines
Quoted 2 lines
=20
int copro_data_segment(structmm_struct*mm, u64 ea, u64 *esid, u64 *v=
sid);
Quoted 8 lines
arch/powerpc/include/asm/copro.h int copro_handle_mm_fault(struct mm_struct *mm, unsigned long ea, · line 22
Quoted 6 lines
=20
arch/powerpc/include/asm/copro.h +5
-0+ +#ifdef CONFIG_PPC_COPRO_BASE +void copro_flush_all_slbs (struct mm_struct *mm); +#else +#define copro_flush_all_slbs (mm) do {} while(0)=20
This can be a static inline, so it should be. That way you get type check=
ing on
Quoted 1 line
the argument for
CONFIG_PPC_COPRO_BASE=3Dn.
OK, I'll update.
Mikey
PATCH v2 4/17 powerpc/msi: Improve IRQ bitmap allocator
In reply to Michael NeulingFrom: Ian Munsie <[email protected]>
Currently msi_bitmap_alloc_hwirqs() will round up any IRQ allocation requests to the nearest power of 2. eg. ask for 5 IRQs and you'll get 8. This wastes a lot of IRQs which can be a scarce resource.
For cxl we can require multiple IRQs for every contexts that is attached to the accelerator. For AFU directed accelerators, there may be 1000s of contexts attached, hence we can easily run out of IRQs, especially if we are needlessly wasting them.
This changes the msi_bitmap_alloc_hwirqs() to allocate only the required number of IRQs, hence avoiding this wastage.
--- arch/powerpc/sysdev/msi_bitmap.c | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-)
arch/powerpc/sysdev/msi_bitmap.c +14 -9
@@ -20,32 +20,37 @@ int msi_bitmap_alloc_hwirqs(struct msi_bitmap *bmp, int num)int offset, order =get_count_order (num);spin_lock_irqsave (&bmp->lock, flags); -/* -* This is fast, but stricter than we need. We might want to add -* a fallback routine which does a linear search with no alignment. -*/ - offset =bitmap_find_free_region (bmp->bitmap, bmp->irq_count, order); + + offset =bitmap_find_next_zero_area (bmp->bitmap, bmp->irq_count,0 , + num, (1 << order) -1 ); +if (offset > bmp->irq_count) + goto err; +bitmap_set (bmp->bitmap, offset, num);spin_unlock_irqrestore (&bmp->lock, flags);pr_debug ("msi_bitmap: allocated 0x%x (2^%d) at offset 0x%x\n" , num, order, offset);return offset; +err: +spin_unlock_irqrestore (&bmp->lock, flags); +return -ENOMEM ; } +EXPORT_SYMBOL (msi_bitmap_alloc_hwirqs);void msi_bitmap_free_hwirqs (struct msi_bitmap *bmp,unsigned int offset,unsigned int num) {unsigned long flags; -int order =get_count_order (num); -pr_debug ("msi_bitmap: freeing 0x%x (2^%d) at offset 0x%x\n" , - num, order, offset); +pr_debug ("msi_bitmap: freeing 0x%x at offset 0x%x\n" , + num, offset);spin_lock_irqsave (&bmp->lock, flags); -bitmap_release_region (bmp->bitmap, offset, order); +bitmap_clear (bmp->bitmap, offset, num);spin_unlock_irqrestore (&bmp->lock, flags); } +EXPORT_SYMBOL (msi_bitmap_free_hwirqs);void msi_bitmap_reserve_hwirq (struct msi_bitmap *bmp,unsigned int hwirq) {
Signature · 1 line
1.9.1
Michael Ellerman
reviewerRe: [PATCH v2 04/17] powerpc/msi: Improve IRQ bitmap allocator
Quoted 3 lines · Michael Neuling
From: Ian Munsie <[email protected]>
Currently
msi_bitmap_alloc_hwirqs()will round up any IRQ allocation requests
request
Quoted 1 line
to the nearest power of 2. eg. ask for 5 IRQs and you'll get 8. This wastes a
^ one space after a period, or die!
Quoted 3 lines
lot of IRQs which can be a scarce resource.
For cxl we can require multiple IRQs for every contexts that is attached to the
context
Quoted 1 line
accelerator. For AFU directed accelerators, there may be 1000s of contexts
What is an AFU directed accelerator?
Quoted 4 lines
attached, hence we can easily run out of IRQs, especially if we are needlessly wasting them.
This changes the
msi_bitmap_alloc_hwirqs()to allocate only the required number
x
Quoted 1 line
of IRQs, hence avoiding this wastage.
The crucial detail you failed to mention is that you maintain the behaviour that allocations are naturally aligned.
Can you add a check in the test code at the bottom of the file to confirm that please?
Quoted 8 lines
arch/powerpc/sysdev/msi_bitmap.c +0
-0@@ -20,32 +20,37 @@ int msi_bitmap_alloc_hwirqs(struct msi_bitmap *bmp, int num)int offset, order =get_count_order (num);spin_lock_irqsave (&bmp->lock, flags);
arch/powerpc/sysdev/msi_bitmap.c int msi_bitmap_alloc_hwirqs(struct msi_bitmap *bmp, int num) · line 27
Quoted 10 lines
arch/powerpc/sysdev/msi_bitmap.c +5
-5-/* -* This is fast, but stricter than we need. We might want to add -* a fallback routine which does a linear search with no alignment. -*/ - offset =bitmap_find_free_region (bmp->bitmap, bmp->irq_count, order); + + offset =bitmap_find_next_zero_area (bmp->bitmap, bmp->irq_count,0 , + num, (1 << order) -1 ); +if (offset > bmp->irq_count) + goto err;
Can we get a newline here :)
arch/powerpc/sysdev/msi_bitmap.c int msi_bitmap_alloc_hwirqs(struct msi_bitmap *bmp, int num) · line 32
Quoted 5 lines
arch/powerpc/sysdev/msi_bitmap.c +1
-0+bitmap_set (bmp->bitmap, offset, num);spin_unlock_irqrestore (&bmp->lock, flags);pr_debug ("msi_bitmap: allocated 0x%x (2^%d) at offset 0x%x\n" , num, order, offset);
This print out is a bit confusing now, should probably just drop the order.
cheers
Re: [PATCH v2 04/17] powerpc/msi: Improve IRQ bitmap allocator
Quoted 4 lines · Michael Ellerman
Quoted 3 lines · Michael Neuling
From: Ian Munsie <[email protected]>
=20
Currentlymsi_bitmap_alloc_hwirqs()will round up any IRQ allocation re=
quests
Quoted 1 line
re=
quest
Quoted 1 line
Quoted 1 line
to the nearest power of 2. eg. ask for 5 IRQs and you'll get 8. This =
wastes a
Quoted 5 lines
^ one space after a period, or die!
=20Quoted 3 lines
lot of IRQs which can be a scarce resource.
=20
For cxl we can require multiple IRQs for every contexts that is attache=
d to the
Quoted 2 lines
context
Quoted 1 line
accelerator. For AFU directed accelerators, there may be 1000s of cont=
exts
Quoted 2 lines
=20
What is an AFU directed accelerator?
=46rom the documentation in the last patch:
AFU Models
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
There are two programming models supported by the AFU. Dedicated and AFU directed. AFU may support one or both models.
In dedicated model only one MMU context is supported. In this model, only one userspace process can use the accelerator at time.
In AFU directed model, up to 16K simultaneous contexts can be supported. This means up to 16K simultaneous userspace applications may use the accelerator (although specific AFUs may support less). In this mode, the AFU sends a 16 bit context ID with each of its requests. This tells the PSL which context is associated with this operation. If the PSL can't translate a request, the ID can also be accessed by the kernel so it can determine the associated userspace context to service this translation with.
Quoted 2 lines
=20Quoted 1 line
attached, hence we can easily run out of IRQs, especially if we are nee=
dlessly
Quoted 3 lines
Quoted 3 lines
wasting them.
=20
This changes themsi_bitmap_alloc_hwirqs()to allocate only the require=
d number
Quoted 4 lines
x
Quoted 1 line
of IRQs, hence avoiding this wastage.
=20
The crucial detail you failed to mention is that you maintain the behavio=
ur that
Quoted 1 line
allocations are naturally aligned.
ok, I'll add that.
Quoted 1 line
Can you add a check in the test code at the bottom of the file to confirm=
that
Quoted 1 line
please?
Yep
Quoted 2 lines
=20
arch/powerpc/sysdev/msi=
Quoted 1 line
arch/powerpc/sysdev/msi= renamed from arch/powerpc/sysdev/msi_bitmap.c +0
-0
_bitmap.c
Quoted 4 lines
arch/powerpc/sysdev/msi_bitmap.c int msi_bitmap_alloc_hwirqs(struct msi_bitmap *bmp,=
Quoted 4 lines
index 2ff6302..961a358 100644
arch/powerpc/sysdev/msi_bitmap.c +0
-0@@ -20,32 +20,37 @@ int msi_bitmap_alloc_hwirqs(struct msi_bitmap *bmp,=
int num)
Quoted 8 lines
arch/powerpc/sysdev/msi_bitmap.c int msi_bitmap_alloc_hwirqs(struct msi_bitmap *bmp, int num)
Quoted 8 lines
arch/powerpc/sysdev/msi_bitmap.c +0
-0int offset, order =3D get_count_order(num);=20
arch/powerpc/sysdev/msi_bitmap.c +0
-5spin_lock_irqsave (&bmp->lock, flags); -/* -* This is fast, but stricter than we need. We might want to add -* a fallback routine which does a linear search with no alignment. -*/ - offset =3D bitmap_find_free_region(bmp->bitmap, bmp->irq_count, order=
);
Quoted 7 lines
arch/powerpc/sysdev/msi_bitmap.c int msi_bitmap_alloc_hwirqs(struct msi_bitmap *bmp, int num) · line 27
Quoted 5 lines
arch/powerpc/sysdev/msi_bitmap.c +5
-0+ + offset =3D bitmap_find_next_zero_area(bmp->bitmap, bmp->irq_count, 0, + num, (1 << order) -1 ); +if (offset > bmp->irq_count) + goto err;=20
Can we get a newline here :)
Ok.
Quoted 8 lines
=20
arch/powerpc/sysdev/msi_bitmap.c int msi_bitmap_alloc_hwirqs(struct msi_bitmap *bmp, int num) · line 32
Quoted 5 lines
arch/powerpc/sysdev/msi_bitmap.c +1
-0+bitmap_set (bmp->bitmap, offset, num);spin_unlock_irqrestore (&bmp->lock, flags);=20
arch/powerpc/sysdev/msi_bitmap.c +0
-0pr_debug ("msi_bitmap: allocated 0x%x (2^%d) at offset 0x%x\n" , num, order, offset);=20
This print out is a bit confusing now, should probably just drop the orde=
r.
Arrh, yep.
Thanks,
Mikey
PATCH v2 5/17 powerpc/mm: Export mmu_kernel_ssize and mmu_linear_psize
In reply to Michael NeulingFrom: Ian Munsie <[email protected]>
--- arch/powerpc/mm/hash_utils_64.c | 2 ++ 1 file changed, 2 insertions(+)
arch/powerpc/mm/hash_utils_64.c +2 -0
@@ -98,6 +98,7 @@ unsigned long htab_size_bytes;unsigned long htab_hash_mask;EXPORT_SYMBOL_GPL (htab_hash_mask);int mmu_linear_psize =MMU_PAGE_4K ; +EXPORT_SYMBOL_GPL (mmu_linear_psize);int mmu_virtual_psize =MMU_PAGE_4K ;int mmu_vmalloc_psize =MMU_PAGE_4K ;#ifdef CONFIG_SPARSEMEM_VMEMMAP
@@ -105,6 +106,7 @@ int mmu_vmemmap_psize = MMU_PAGE_4K;#endif int mmu_io_psize =MMU_PAGE_4K ;int mmu_kernel_ssize =MMU_SEGSIZE_256M ; +EXPORT_SYMBOL_GPL (mmu_kernel_ssize);int mmu_highuser_ssize =MMU_SEGSIZE_256M ;u16 mmu_slb_size =64 ;EXPORT_SYMBOL_GPL (mmu_slb_size);
Signature · 1 line
1.9.1
Michael Ellerman
reviewerRe: [PATCH v2 05/17] powerpc/mm: Export mmu_kernel_ssize and mmu_linear_psize
Re: [PATCH v2 05/17] powerpc/mm: Export mmu_kernel_ssize and mmu_linear_psize
Quoted 4 lines · Michael Ellerman
Quoted 1 line · Michael Neuling
From: Ian Munsie <[email protected]>
=20
Mind explaining why ? :)
Sure.
Mikey
PATCH v2 6/17 powerpc/powernv: Split out set MSI IRQ chip code
In reply to Michael NeulingFrom: Ian Munsie <[email protected]>
Some of the MSI IRQ code in pnv_pci_ioda_msi_setup() is generically useful so split it out.
This will be used by some of the cxl PCIe code later.
--- arch/powerpc/platforms/powernv/pci-ioda.c | 43 ++++++++++++++++++------------- 1 file changed, 25 insertions(+), 18 deletions(-)
arch/powerpc/platforms/powernv/pci-ioda.c +25 -18
@@ -1306,14 +1306,36 @@ static void pnv_ioda2_msi_eoi(struct irq_data *d)icp_native_eoi (d); } + +static void set_msi_irq_chip (struct pnv_phb *phb,unsigned int virq) +{ +struct irq_data *idata; +struct irq_chip *ichip; + +if (phb->type !=PNV_PHB_IODA2 ) +return ; + +/* +* Change the IRQ chip for the MSI interrupts on PHB3. +* The corresponding IRQ chip should be populated for +* the first time. +*/ +if (!phb->ioda.irq_chip_init) { + idata =irq_get_irq_data (virq); + ichip =irq_data_get_irq_chip (idata); + phb->ioda.irq_chip_init =1 ; + phb->ioda.irq_chip = *ichip; + phb->ioda.irq_chip.irq_eoi = pnv_ioda2_msi_eoi; + } +irq_set_chip (virq, &phb->ioda.irq_chip); +} +static int pnv_pci_ioda_msi_setup (struct pnv_phb *phb,struct pci_dev *dev,unsigned int hwirq,unsigned int virq,unsigned int is_64,struct msi_msg *msg) {struct pnv_ioda_pe *pe =pnv_ioda_get_pe (dev);struct pci_dn *pdn =pci_get_pdn (dev); -struct irq_data *idata; -struct irq_chip *ichip;unsigned int xive_num = hwirq - phb->msi_base;__be32 data;int rc;
@@ -1365,22 +1387,7 @@ static int pnv_pci_ioda_msi_setup(struct pnv_phb *phb, struct pci_dev *dev, } msg->data =be32_to_cpu (data); -/* -* Change the IRQ chip for the MSI interrupts on PHB3. -* The corresponding IRQ chip should be populated for -* the first time. -*/ -if (phb->type ==PNV_PHB_IODA2 ) { -if (!phb->ioda.irq_chip_init) { - idata =irq_get_irq_data (virq); - ichip =irq_data_get_irq_chip (idata); - phb->ioda.irq_chip_init =1 ; - phb->ioda.irq_chip = *ichip; - phb->ioda.irq_chip.irq_eoi = pnv_ioda2_msi_eoi; - } - -irq_set_chip (virq, &phb->ioda.irq_chip); - } +set_msi_irq_chip (phb, virq); pr_devel("%s: %s-bit MSI on hwirq %x (xive #%d)," " address=%x_%08x data=%x PE# %d\n",
Signature · 1 line
1.9.1
Michael Ellerman
reviewerRe: [PATCH v2 06/17] powerpc/powernv: Split out set MSI IRQ chip code
Quoted 18 lines · Michael Neuling
From: Ian Munsie <[email protected]>
Some of the MSI IRQ code in
pnv_pci_ioda_msi_setup()is generically useful so split it out.This will be used by some of the cxl PCIe code later.
arch/powerpc/platforms/powernv/pci-ioda.c +3
-0@@ -1306,14 +1306,36 @@ static void pnv_ioda2_msi_eoi(struct irq_data *d)icp_native_eoi (d); } + +static void set_msi_irq_chip (struct pnv_phb *phb,unsigned int virq) +{
arch/powerpc/platforms/powernv/pci-ioda.c static void pnv_ioda2_msi_eoi(struct irq_data *d) · line 1321
Quoted 10 lines
arch/powerpc/platforms/powernv/pci-ioda.c +10
-0+struct irq_data *idata; +struct irq_chip *ichip; + +if (phb->type !=PNV_PHB_IODA2 ) +return ; + +/* +* Change the IRQ chip for the MSI interrupts on PHB3. +* The corresponding IRQ chip should be populated for +* the first time.
Seeing as you're moving this comment can you clarify the wording.
cheers
Re: [PATCH v2 06/17] powerpc/powernv: Split out set MSI IRQ chip code
Quoted 4 lines · Michael Ellerman
Quoted 3 lines · Michael Neuling
From: Ian Munsie <[email protected]>
=20
Some of the MSI IRQ code inpnv_pci_ioda_msi_setup()is generically use=
ful so
Quoted 5 lines
arch/powerpc/p=
Quoted 5 lines
split it out.
=20
This will be used by some of the cxl PCIe code later. =20arch/powerpc/p= renamed from arch/powerpc/platforms/powernv/pci-ioda.c +0
-0
latforms/powernv/pci-ioda.c
Quoted 4 lines
arch/powerpc/platforms/powernv/pci-ioda.c static void pnv_ioda2_msi_eoi(struct irq_data *=
Quoted 4 lines
index df241b1..329164f 100644
arch/powerpc/platforms/powernv/pci-ioda.c +0
-0@@ -1306,14 +1306,36 @@ static void pnv_ioda2_msi_eoi(struct irq_data *=
d)
Quoted 10 lines
Quoted 10 lines
arch/powerpc/platforms/powernv/pci-ioda.c +0
-0icp_native_eoi (d); }=20
arch/powerpc/platforms/powernv/pci-ioda.c +7
-0+ +static void set_msi_irq_chip (struct pnv_phb *phb,unsigned int virq) +{ +struct irq_data *idata; +struct irq_chip *ichip; + + if (phb->type !=3D PNV_PHB_IODA2)
Quoted 8 lines
arch/powerpc/platforms/powernv/pci-ioda.c static void pnv_ioda2_msi_eoi(struct irq_data *d) · line 1321
Quoted 6 lines
arch/powerpc/platforms/powernv/pci-ioda.c +6
-0+return ; + +/* +* Change the IRQ chip for the MSI interrupts on PHB3. +* The corresponding IRQ chip should be populated for +* the first time. =20
Seeing as you're moving this comment can you clarify the wording.
Ok.
Mikey
PATCH v2 7/17 cxl: Add new header for call backs and structs
In reply to Michael NeulingFrom: Ian Munsie <[email protected]>
This new header add defines for callbacks and structs needed by the rest of the kernel to hook into the cxl infrastructure.
Empty functions are provided when CONFIG CXL_BASE is not enabled.
--- include/misc/cxl.h | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 include/misc/cxl.h
include/misc/cxl.h new file +34 -0
@@ -0,0 +1,34 @@ +/* +* Copyright 2014 IBM Corp. +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation; either version +* 2 of the License, or (at your option) any later version. +*/ + +#ifndef _MISC_ASM_CXL_H +#define _MISC_ASM_CXL_H + +#define CXL_IRQ_RANGES 4 + +struct cxl_irq_ranges { +irq_hw_number_t offset[CXL_IRQ_RANGES ]; +irq_hw_number_t range[CXL_IRQ_RANGES ]; +}; + +#ifdef CONFIG_CXL_BASE + +void cxl_slbia (struct mm_struct *mm); +void cxl_ctx_get (void ); +void cxl_ctx_put (void ); +bool cxl_ctx_in_use (void ); + +#else /* CONFIG_CXL_BASE */ + +#define cxl_slbia (...) do { } while (0) +#define cxl_ctx_in_use (...) false + +#endif /* CONFIG_CXL_BASE */ + +#endif
Signature · 1 line
1.9.1
Michael Ellerman
reviewerRe: [PATCH v2 07/17] cxl: Add new header for call backs and structs
Quoted 3 lines · Michael Neuling
From: Ian Munsie <[email protected]>
This new header add defines for callbacks and structs needed by the rest of the
adds
Quoted 8 lines
kernel to hook into the cxl infrastructure.
Empty functions are provided when CONFIG
CXL_BASEis not enabled.Signed-off-by Ian Munsie <[email protected]>Signed-off-by Michael Neuling <[email protected]>--- include/misc/cxl.h | 34 ++++++++++++++++++++++++++++++++++
include/misc is kind of weird. I guess it's a misc device.
Any reason not to have it in arch/powerpc/include ?
Quoted 6 lines
include/misc/cxl.h new file +0
-0
include/misc/cxl.h line 10
Quoted 10 lines
include/misc/cxl.h new file +10
-0@@ -0,0 +1,34 @@ +/* +* Copyright 2014 IBM Corp. +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation; either version +* 2 of the License, or (at your option) any later version. +*/ + +#ifndef _MISC_ASM_CXL_H
No ASM.
Quoted 10 lines
include/misc/cxl.h new file +10
-0+#define _MISC_ASM_CXL_H + +#define CXL_IRQ_RANGES 4 + +struct cxl_irq_ranges { +irq_hw_number_t offset[CXL_IRQ_RANGES ]; +irq_hw_number_t range[CXL_IRQ_RANGES ]; +}; + +#ifdef CONFIG_CXL_BASE
include/misc/cxl.h line 30
Quoted 10 lines
include/misc/cxl.h new file +10
-0+ +void cxl_slbia (struct mm_struct *mm); +void cxl_ctx_get (void ); +void cxl_ctx_put (void ); +bool cxl_ctx_in_use (void ); + +#else /* CONFIG_CXL_BASE */ + +#define cxl_slbia (...) do { } while (0) +#define cxl_ctx_in_use (...) false
Any reason these shouldn't be static inlines?
cheers
Re: [PATCH v2 07/17] cxl: Add new header for call backs and structs
Quoted 4 lines · Michael Ellerman
Quoted 3 lines · Michael Neuling
From: Ian Munsie <[email protected]>
=20
This new header add defines for callbacks and structs needed by the res=
t of the
Quoted 9 lines
adds
Quoted 8 lines
kernel to hook into the cxl infrastructure.
=20
Empty functions are provided when CONFIGCXL_BASEis not enabled. =20Signed-off-by Ian Munsie <[email protected]>Signed-off-by Michael Neuling <[email protected]>--- include/misc/cxl.h | 34 ++++++++++++++++++++++++++++++++++
Quoted 4 lines
=20
include/miscis kind of weird. I guess it's a misc device. =20
Any reason not to have it inarch/powerpc/include?
We can do either way. We did consider it a driver so putting it in arch/powerpc didn't seem quite right.
I might leave it here unless you really object.
Quoted 11 lines
=20
Quoted 10 lines
include/misc/cxl.h new file +4
-0@@ -0,0 +1,34 @@ +/* +* Copyright 2014 IBM Corp. +* +* This program is free software; you can redistribute it and/or
Quoted 8 lines
include/misc/cxl.h line 10
Quoted 6 lines
include/misc/cxl.h new file +6
-0+* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation; either version +* 2 of the License, or (at your option) any later version. +*/ + +#ifndef _MISC_ASM_CXL_H=20
No ASM.
Oops, yes.
Quoted 15 lines
=20
Quoted 14 lines
include/misc/cxl.h new file +14
-0+#define _MISC_ASM_CXL_H + +#define CXL_IRQ_RANGES 4 + +struct cxl_irq_ranges { +irq_hw_number_t offset[CXL_IRQ_RANGES ]; +irq_hw_number_t range[CXL_IRQ_RANGES ]; +}; + +#ifdef CONFIG_CXL_BASE + +void cxl_slbia (struct mm_struct *mm); +void cxl_ctx_get (void ); +void cxl_ctx_put (void );
Quoted 8 lines
include/misc/cxl.h line 30
Quoted 6 lines
include/misc/cxl.h new file +6
-0+bool cxl_ctx_in_use (void ); + +#else /* CONFIG_CXL_BASE */ + +#define cxl_slbia (...) do { } while (0) +#define cxl_ctx_in_use (...) false=20
Any reason these shouldn't be static inlines?
No, I'll change.
Mikey
PATCH v2 8/17 powerpc/powerpc: Add new PCIe functions for allocating cxl interrupts
In reply to Michael NeulingFrom: Ian Munsie <[email protected]>
This adds a number of functions for allocating IRQs under powernv PCIe for cxl.
--- arch/powerpc/include/asm/pnv-pci.h | 27 +++++ arch/powerpc/platforms/powernv/pci-ioda.c | 161 ++++++++++++++++++++++++++++++ 2 files changed, 188 insertions(+) create mode 100644 arch/powerpc/include/asm/pnv-pci.h
arch/powerpc/include/asm/pnv-pci.h new file +27 -0
@@ -0,0 +1,27 @@ +/* +* Copyright 2014 IBM Corp. +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation; either version +* 2 of the License, or (at your option) any later version. +*/ + +#ifndef _ASM_PNV_PCI_H +#define _ASM_PNV_PCI_H + +#include <linux/pci.h> +#include <misc/cxl.h> + +int pnv_phb_to_cxl (struct pci_dev *dev); +int pnv_cxl_ioda_msi_setup (struct pci_dev *dev,unsigned int hwirq, +unsigned int virq); +int pnv_cxl_alloc_hwirqs (struct pci_dev *dev,int num); +void pnv_cxl_release_hwirqs (struct pci_dev *dev,int hwirq,int num); +int pnv_cxl_alloc_hwirq_ranges (struct cxl_irq_ranges *irqs, +struct pci_dev *dev,int num); +void pnv_cxl_release_hwirq_ranges (struct cxl_irq_ranges *irqs, +struct pci_dev *dev); +int pnv_cxl_get_irq_count (struct pci_dev *dev); + +#endif
arch/powerpc/platforms/powernv/pci-ioda.c +161 -0
179 lines not on this page · raw message
Signature · 1 line
1.9.1
Michael Ellerman
reviewerRe: [PATCH v2 08/17] powerpc/powerpc: Add new PCIe functions for allocating cxl interrupts
Quoted 23 lines · Michael Neuling
From: Ian Munsie <[email protected]>
This adds a number of functions for allocating IRQs under powernv PCIe for cxl.
arch/powerpc/platforms/powernv/pci-ioda.c +11
-0@@ -503,6 +505,138 @@ static struct pnv_ioda_pe *pnv_ioda_get_pe(struct pci_dev *dev)return NULL ;return &phb->ioda.pe_array[pdn->pe_number]; } + +struct device_node *pnv_pci_to_phb_node (struct pci_dev *dev) +{ +struct pci_controller *hose =pci_bus_to_host (dev->bus); + +return hose->dn; +} +EXPORT_SYMBOL (pnv_pci_to_phb_node); + +#ifdef CONFIG_CXL_BASE +int pnv_phb_to_cxl (struct pci_dev *dev)
arch/powerpc/platforms/powernv/pci-ioda.c static struct pnv_ioda_pe *pnv_ioda_get_pe(struct pci_dev *dev) · line 528
Quoted 10 lines
arch/powerpc/platforms/powernv/pci-ioda.c +10
-0+{ +struct pci_controller *hose =pci_bus_to_host (dev->bus); +struct pnv_phb *phb = hose->private_data; +struct pnv_ioda_pe *pe; +int rc; + +if (!(pe =pnv_ioda_get_pe (dev))) { + rc = -ENODEV ; + goto out; + }
That'd be a lot simpler as:
pe = pnv_ioda_get_pe(dev); if (!pe) return -ENODEV;
arch/powerpc/platforms/powernv/pci-ioda.c static struct pnv_ioda_pe *pnv_ioda_get_pe(struct pci_dev *dev) · line 531
Quoted 3 lines
arch/powerpc/platforms/powernv/pci-ioda.c +3
-0+pe_info (pe,"switch PHB to CXL\n" ); +pe_info (pe,"PHB-ID : 0x%016llx\n" , phb->opal_id); +pe_info (pe," pe : %i\n" , pe->pe_number);
Spacing is a bit weird but maybe it matches something else?
arch/powerpc/platforms/powernv/pci-ioda.c static struct pnv_ioda_pe *pnv_ioda_get_pe(struct pci_dev *dev) · line 534
Quoted 3 lines
arch/powerpc/platforms/powernv/pci-ioda.c +3
-0+ +if ((rc =opal_pci_set_phb_cxl_mode (phb->opal_id,1 , pe->pe_number))) +dev_err (&dev->dev,"opal_pci_set_phb_cxl_mode failed: %i\n" , rc);
Again why not:
rc = opal_pci_set_phb_cxl_mode(phb->opal_id, 1, pe->pe_number); if (rc) dev_err(&dev->dev, "opal_pci_set_phb_cxl_mode failed: %i\n", rc);
arch/powerpc/platforms/powernv/pci-ioda.c static struct pnv_ioda_pe *pnv_ioda_get_pe(struct pci_dev *dev) · line 567
Quoted 8 lines
arch/powerpc/platforms/powernv/pci-ioda.c +7
-0+out: +return rc; +} +EXPORT_SYMBOL (pnv_phb_to_cxl); + +int pnv_cxl_alloc_hwirq_ranges (struct cxl_irq_ranges *irqs, +struct pci_dev *dev,int num)
This could use some documentation.
It seems to be that it allocates num irqs in some number of ranges, up to CXL_IRQ_RANGES?
arch/powerpc/platforms/powernv/pci-ioda.c static struct pnv_ioda_pe *pnv_ioda_get_pe(struct pci_dev *dev) · line 571
Quoted 4 lines
arch/powerpc/platforms/powernv/pci-ioda.c +4
-0+{ +struct pci_controller *hose =pci_bus_to_host (dev->bus); +struct pnv_phb *phb = hose->private_data; +int range =0 ;
You reinitialise to 1 below?
arch/powerpc/platforms/powernv/pci-ioda.c static struct pnv_ioda_pe *pnv_ioda_get_pe(struct pci_dev *dev) · line 573
Quoted 2 lines
arch/powerpc/platforms/powernv/pci-ioda.c +2
-0+int hwirq; +int try;
So these can be:
int hwirq, try, range;
arch/powerpc/platforms/powernv/pci-ioda.c static struct pnv_ioda_pe *pnv_ioda_get_pe(struct pci_dev *dev) · line 577
Quoted 3 lines
arch/powerpc/platforms/powernv/pci-ioda.c +3
-0+memset (irqs,0 ,sizeof (struct cxl_irq_ranges )); + +for (range =1 ; range <CXL_IRQ_RANGES && num; range++) {
I think this would be clearer if range was just called "i" as usual.
Why does it start at 1 ?
arch/powerpc/platforms/powernv/pci-ioda.c static struct pnv_ioda_pe *pnv_ioda_get_pe(struct pci_dev *dev) · line 589
Quoted 12 lines
arch/powerpc/platforms/powernv/pci-ioda.c +12
-0+ try = num; +while (try) { + hwirq =msi_bitmap_alloc_hwirqs (&phb->msi_bmp, try); +if (hwirq >=0 ) +break ; + try /=2 ; + } +if (!try) + goto fail; + + irqs->offset[range] = phb->msi_base + hwirq; + irqs->range[range] = try;
irqs->range is irq_hw_number_t but looks like it should just be uint.
Quoted 5 lines
arch/powerpc/platforms/powernv/pci-ioda.c +5
-0+pr_devel ("cxl alloc irq range 0x%x: offset: 0x%lx limit: %li\n" , + range, irqs->offset[range], irqs->range[range]); + num -= try; + } +if (num)
arch/powerpc/platforms/powernv/pci-ioda.c static struct pnv_ioda_pe *pnv_ioda_get_pe(struct pci_dev *dev) · line 604
Quoted 10 lines
arch/powerpc/platforms/powernv/pci-ioda.c +10
-0+ goto fail; + +return 0 ; +fail: +for (range--; range >=0 ; range--) { + hwirq = irqs->offset[range] - phb->msi_base; +msi_bitmap_free_hwirqs (&phb->msi_bmp, hwirq, + irqs->range[range]); + irqs->range[range] =0 ; + }
Because you zero ranges at the top I think you can replace all of the fail logic with a call to pnv_cxl_release_hwirq_ranges().
arch/powerpc/platforms/powernv/pci-ioda.c static struct pnv_ioda_pe *pnv_ioda_get_pe(struct pci_dev *dev) · line 614
Quoted 10 lines
arch/powerpc/platforms/powernv/pci-ioda.c +10
-0+return -ENOSPC ; +} +EXPORT_SYMBOL (pnv_cxl_alloc_hwirq_ranges); + +void pnv_cxl_release_hwirq_ranges (struct cxl_irq_ranges *irqs, +struct pci_dev *dev) +{ +struct pci_controller *hose =pci_bus_to_host (dev->bus); +struct pnv_phb *phb = hose->private_data; +int range =0 ;
Unnecessary init again.
arch/powerpc/platforms/powernv/pci-ioda.c static struct pnv_ioda_pe *pnv_ioda_get_pe(struct pci_dev *dev) · line 617
Quoted 3 lines
arch/powerpc/platforms/powernv/pci-ioda.c +3
-0+int hwirq; + +for (range =0 ; range <4 ; range++) {
Shouldn't 4 be CXL_IRQ_RANGES ?
arch/powerpc/platforms/powernv/pci-ioda.c static struct pnv_ioda_pe *pnv_ioda_get_pe(struct pci_dev *dev) · line 592
Quoted 1 line
arch/powerpc/platforms/powernv/pci-ioda.c +1
-0+ hwirq = irqs->offset[range] - phb->msi_base;
That should be inside the if.
Or better do:
if (!irqs->range[range]) continue; ...
Quoted 5 lines
arch/powerpc/platforms/powernv/pci-ioda.c +5
-0+if (irqs->range[range]) { +pr_devel ("cxl release irq range 0x%x: offset: 0x%lx limit: %ld\n" , + range, irqs->offset[range], + irqs->range[range]); + msi_bitmap_free_hwirqs(&phb->msi_bmp, hwirq,
arch/powerpc/platforms/powernv/pci-ioda.c static struct pnv_ioda_pe *pnv_ioda_get_pe(struct pci_dev *dev) · line 633
Quoted 10 lines
arch/powerpc/platforms/powernv/pci-ioda.c +10
-0+ irqs->range[range]); + } + } +} +EXPORT_SYMBOL (pnv_cxl_release_hwirq_ranges); + +int pnv_cxl_get_irq_count (struct pci_dev *dev) +{ +struct pci_controller *hose =pci_bus_to_host (dev->bus); +struct pnv_phb *phb = hose->private_data;
Indentation is fubar.
arch/powerpc/platforms/powernv/pci-ioda.c static void set_msi_irq_chip(struct pnv_phb *phb, unsigned int virq) · line 1467
Quoted 13 lines
arch/powerpc/platforms/powernv/pci-ioda.c +6
-0+return phb->msi_bmp.irq_count; +} +EXPORT_SYMBOL (pnv_cxl_get_irq_count); + +#endif /* CONFIG_CXL_BASE */ #endif /* CONFIG_PCI_MSI */ static int pnv_ioda_configure_pe (struct pnv_phb *phb,struct pnv_ioda_pe *pe)@@ -1330,6 +1464,33 @@ static void set_msi_irq_chip(struct pnv_phb *phb, unsigned int virq)irq_set_chip (virq, &phb->ioda.irq_chip); } +#ifdef CONFIG_CXL_BASE
Why is this here and not in the previous #ifdef CONFIG_CXL_BASE block ?
Quoted 7 lines
arch/powerpc/platforms/powernv/pci-ioda.c +7
-0+int pnv_cxl_ioda_msi_setup (struct pci_dev *dev,unsigned int hwirq, +unsigned int virq) +{ +struct pci_controller *hose =pci_bus_to_host (dev->bus); +struct pnv_phb *phb = hose->private_data; +unsigned int xive_num = hwirq - phb->msi_base; +struct pnv_ioda_pe *pe;
arch/powerpc/platforms/powernv/pci-ioda.c static void set_msi_irq_chip(struct pnv_phb *phb, unsigned int virq) · line 1484
Quoted 10 lines
arch/powerpc/platforms/powernv/pci-ioda.c +10
-0+int rc; + +if (!(pe =pnv_ioda_get_pe (dev))) +return -ENODEV ; + +/* Assign XIVE to PE */ + rc =opal_pci_set_xive_pe (phb->opal_id, pe->pe_number, xive_num); +if (rc) { +pr_warn ("%s: OPAL error %d setting msi_base 0x%x hwirq 0x%x XIVE 0x%x PE\n" , +pci_name (dev), rc, phb->msi_base, hwirq, xive_num);
dev_warn() ?
cheers
Re: [PATCH v2 08/17] powerpc/powerpc: Add new PCIe functions for allocating cxl interrupts
Quoted 4 lines · Michael Ellerman
Quoted 3 lines · Michael Neuling
From: Ian Munsie <[email protected]>
=20
This adds a number of functions for allocating IRQs under powernv PCIe =
for cxl.
Quoted 2 lines
arch/powerpc/p=
Quoted 2 lines
=20
arch/powerpc/p= renamed from arch/powerpc/platforms/powernv/pci-ioda.c +0
-0
latforms/powernv/pci-ioda.c
Quoted 4 lines
arch/powerpc/platforms/powernv/pci-ioda.c static struct pnv_ioda_pe *pnv_ioda_get_pe(struct=
Quoted 4 lines
index 329164f..b0b96f0 100644
arch/powerpc/platforms/powernv/pci-ioda.c +0
-0@@ -503,6 +505,138 @@ static struct pnv_ioda_pe *pnv_ioda_get_pe(struct=
pci_dev *dev)
Quoted 27 lines
Quoted 14 lines
arch/powerpc/platforms/powernv/pci-ioda.c +11
-0return NULL ;return &phb->ioda.pe_array[pdn->pe_number]; } + +struct device_node *pnv_pci_to_phb_node (struct pci_dev *dev) +{ + struct pci_controller *hose =3D pci_bus_to_host(dev->bus); + +return hose->dn; +} +EXPORT_SYMBOL (pnv_pci_to_phb_node); + +#ifdef CONFIG_CXL_BASE +int pnv_phb_to_cxl (struct pci_dev *dev)arch/powerpc/platforms/powernv/pci-ioda.c static struct pnv_ioda_pe *pnv_ioda_get_pe(struct pci_dev *dev) · line 528
Quoted 10 lines
arch/powerpc/platforms/powernv/pci-ioda.c +10
-0+{ + struct pci_controller *hose =3D pci_bus_to_host(dev->bus); + struct pnv_phb *phb =3D hose->private_data; +struct pnv_ioda_pe *pe; +int rc; + + if (!(pe =3D pnv_ioda_get_pe(dev))) { + rc =3D -ENODEV ; + goto out; + }=20
That'd be a lot simpler as:
=20
Quoted 3 lines
pe =3D pnv_ioda_get_pe(dev); if (!pe) return -ENODEV;
OK
Quoted 5 lines
arch/powerpc/platforms/powernv/pci-ioda.c static struct pnv_ioda_pe *pnv_ioda_get_pe(struct pci_dev *dev) · line 531
Quoted 3 lines
arch/powerpc/platforms/powernv/pci-ioda.c +3
-0+pe_info (pe,"switch PHB to CXL\n" ); +pe_info (pe,"PHB-ID : 0x%016llx\n" , phb->opal_id); +pe_info (pe," pe : %i\n" , pe->pe_number);=20
Spacing is a bit weird but maybe it matches something else?
Actually, we switched this to pe_info() based on one of Gavin's reviews, so the pe_number and opal_id being printed here are not needed anymore. I'm simplifying this into one line.
pe_info(pe, "Switching PHB to CXL\n");
Quoted 3 lines
=20
arch/powerpc/platforms/powernv/pci-ioda.c static struct pnv_ioda_pe *pnv_ioda_get_pe(struct= · line 533
Quoted 2 lines
arch/powerpc/platforms/powernv/pci-ioda.c +2
-0+ + if ((rc =3D opal_pci_set_phb_cxl_mode(phb->opal_id, 1, pe->pe_number)=
))
Quoted 7 lines
arch/powerpc/platforms/powernv/pci-ioda.c static struct pnv_ioda_pe *pnv_ioda_get_pe(struct pci_dev *dev) · line 534
Quoted 1 line
arch/powerpc/platforms/powernv/pci-ioda.c +1
-0+dev_err (&dev->dev,"opal_pci_set_phb_cxl_mode failed: %i\n" , rc);=20
Again why not:
=20rc =3D opal_pci_set_phb_cxl_mode(phb->opal_id, 1, pe->pe_number); if (rc) dev_err(&dev->dev, "opal_pci_set_phb_cxl_mode failed: %i\n", rc);
Ok.
Quoted 6 lines
arch/powerpc/platforms/powernv/pci-ioda.c static struct pnv_ioda_pe *pnv_ioda_get_pe(struct pci_dev *dev) · line 540
Quoted 5 lines
arch/powerpc/platforms/powernv/pci-ioda.c +5
-0+out: +return rc; +} +EXPORT_SYMBOL (pnv_phb_to_cxl); +=20
Quoted 7 lines
arch/powerpc/platforms/powernv/pci-ioda.c static struct pnv_ioda_pe *pnv_ioda_get_pe(struct pci_dev *dev) · line 567
Quoted 2 lines
arch/powerpc/platforms/powernv/pci-ioda.c +2
-0+int pnv_cxl_alloc_hwirq_ranges (struct cxl_irq_ranges *irqs, +struct pci_dev *dev,int num)=20
This could use some documentation.
=20
It seems to be that it allocates num irqs in some number of ranges, up toCXL_IRQ_RANGES?
OK
Quoted 7 lines
=20
arch/powerpc/platforms/powernv/pci-ioda.c static struct pnv_ioda_pe *pnv_ioda_get_pe(struct= · line 545
Quoted 4 lines
arch/powerpc/platforms/powernv/pci-ioda.c +4
-0+{ + struct pci_controller *hose =3D pci_bus_to_host(dev->bus); + struct pnv_phb *phb =3D hose->private_data; + int range =3D 0;=20
You reinitialise to 1 below?
Oops
Quoted 6 lines
=20
arch/powerpc/platforms/powernv/pci-ioda.c static struct pnv_ioda_pe *pnv_ioda_get_pe(struct pci_dev *dev) · line 573
Quoted 2 lines
arch/powerpc/platforms/powernv/pci-ioda.c +2
-0+int hwirq; +int try;=20
So these can be:
=20
Quoted 7 lines
int hwirq, try, range;=20
arch/powerpc/platforms/powernv/pci-ioda.c static struct pnv_ioda_pe *pnv_ioda_get_pe(struct pci_dev *dev)
Quoted 3 lines
arch/powerpc/platforms/powernv/pci-ioda.c +3
-0+memset (irqs,0 ,sizeof (struct cxl_irq_ranges )); + + for (range =3D 1; range < CXL_IRQ_RANGES && num; range++) {=20
I think this would be clearer if range was just called "i" as usual.
OK
Quoted 1 line
Why does it start at 1 ?
0 is used by the data storage interrupt. I'll add a comment to clarify.
Quoted 25 lines
=20
arch/powerpc/platforms/powernv/pci-ioda.c static struct pnv_ioda_pe *pnv_ioda_get_pe(struct pci_dev *dev)
Quoted 12 lines
arch/powerpc/platforms/powernv/pci-ioda.c +12
-0+ try =3D num; +while (try) { + hwirq =3D msi_bitmap_alloc_hwirqs(&phb->msi_bmp, try); + if (hwirq >=3D 0) +break ; + try /=3D 2; + } +if (!try) + goto fail; + + irqs->offset[range] =3D phb->msi_base + hwirq; + irqs->range[range] =3D try;=20
irqs->rangeisirq_hw_number_tbut looks like it should just be uint. =20Quoted 9 lines
arch/powerpc/platforms/powernv/pci-ioda.c +9
-0+pr_devel ("cxl alloc irq range 0x%x: offset: 0x%lx limit: %li\n" , + range, irqs->offset[range], irqs->range[range]); + num -=3D try; + } +if (num) + goto fail; + +return 0 ; +fail:
Quoted 8 lines
arch/powerpc/platforms/powernv/pci-ioda.c static struct pnv_ioda_pe *pnv_ioda_get_pe(struct pci_dev *dev) · line 604
Quoted 6 lines
arch/powerpc/platforms/powernv/pci-ioda.c +6
-0+ for (range--; range >=3D 0; range--) { + hwirq =3D irqs->offset[range] - phb->msi_base; +msi_bitmap_free_hwirqs (&phb->msi_bmp, hwirq, + irqs->range[range]); + irqs->range[range] =3D 0; + }=20
Because you zero ranges at the top I think you can replace all of the fai=
l
Quoted 1 line
logic with a call to
pnv_cxl_release_hwirq_ranges().
Nice. Will change.
Quoted 14 lines
=20
=20arch/powerpc/platforms/powernv/pci-ioda.c static struct pnv_ioda_pe *pnv_ioda_get_pe(struct pci_dev *dev)
Quoted 10 lines
arch/powerpc/platforms/powernv/pci-ioda.c +10
-0+return -ENOSPC ; +} +EXPORT_SYMBOL (pnv_cxl_alloc_hwirq_ranges); + +void pnv_cxl_release_hwirq_ranges (struct cxl_irq_ranges *irqs, +struct pci_dev *dev) +{ + struct pci_controller *hose =3D pci_bus_to_host(dev->bus); + struct pnv_phb *phb =3D hose->private_data; + int range =3D 0;=20
Unnecessary init again.
Yep. I'll change to 'i' too.
Quoted 5 lines
arch/powerpc/platforms/powernv/pci-ioda.c static struct pnv_ioda_pe *pnv_ioda_get_pe(struct pci_dev *dev)
Quoted 3 lines
arch/powerpc/platforms/powernv/pci-ioda.c +3
-0+int hwirq; + + for (range =3D 0; range < 4; range++) {=20
Shouldn't 4 beCXL_IRQ_RANGES?
Yep.
Quoted 4 lines
=20
arch/powerpc/platforms/powernv/pci-ioda.c static struct pnv_ioda_pe *pnv_ioda_get_pe(struct= · line 591
Quoted 1 line
arch/powerpc/platforms/powernv/pci-ioda.c +1
-0+ hwirq =3D irqs->offset[range] - phb->msi_base;=20
That should be inside the if.
Yep.
Quoted 5 lines
=20
Or better do:if (!irqs->range[range]) continue; ...
Nice.
Quoted 10 lines
=20
Quoted 9 lines
arch/powerpc/platforms/powernv/pci-ioda.c +9
-0+if (irqs->range[range]) { +pr_devel ("cxl release irq range 0x%x: offset: 0x%lx limit: %ld\n" , + range, irqs->offset[range], + irqs->range[range]); +msi_bitmap_free_hwirqs (&phb->msi_bmp, hwirq, + irqs->range[range]); + } + } +}
Quoted 8 lines
arch/powerpc/platforms/powernv/pci-ioda.c static struct pnv_ioda_pe *pnv_ioda_get_pe(struct pci_dev *dev)
Quoted 6 lines
arch/powerpc/platforms/powernv/pci-ioda.c +6
-0+EXPORT_SYMBOL (pnv_cxl_release_hwirq_ranges); + +int pnv_cxl_get_irq_count (struct pci_dev *dev) +{ + struct pci_controller *hose =3D pci_bus_to_host(dev->bus); + struct pnv_phb *phb =3D hose->private_data;=20
Indentation is fubar.
OK
Quoted 9 lines
=20
Quoted 8 lines
arch/powerpc/platforms/powernv/pci-ioda.c +5
-0+return phb->msi_bmp.irq_count; +} +EXPORT_SYMBOL (pnv_cxl_get_irq_count); + +#endif /* CONFIG_CXL_BASE */ #endif /* CONFIG_PCI_MSI */ =20
static int pnv_ioda_configure_pe(structpnv_phb*phb, struct pnv_ioda_=
pe *pe)
Quoted 1 line
arch/powerpc/platforms/powernv/pci-ioda.c static void set_msi_irq_chip(struct pnv_phb *phb=
Quoted 1 line
arch/powerpc/platforms/powernv/pci-ioda.c +0
-0@@ -1330,6 +1464,33 @@ static void set_msi_irq_chip(struct pnv_phb *phb=
, unsigned int virq)
Quoted 6 lines
Quoted 4 lines
arch/powerpc/platforms/powernv/pci-ioda.c +0
-0irq_set_chip (virq, &phb->ioda.irq_chip); }=20
+#ifdefCONFIG_CXL_BASE=20
Why is this here and not in the previous #ifdefCONFIG_CXL_BASEblock ?
I can actually move the rest of the cxl code down here too. So I'll do that.
Quoted 17 lines
=20
Quoted 6 lines
arch/powerpc/platforms/powernv/pci-ioda.c +6
-0+int pnv_cxl_ioda_msi_setup (struct pci_dev *dev,unsigned int hwirq, +unsigned int virq) +{ + struct pci_controller *hose =3D pci_bus_to_host(dev->bus); + struct pnv_phb *phb =3D hose->private_data; + unsigned int xive_num =3D hwirq - phb->msi_base;arch/powerpc/platforms/powernv/pci-ioda.c static void set_msi_irq_chip(struct pnv_phb *phb, unsigned int virq)
Quoted 10 lines
arch/powerpc/platforms/powernv/pci-ioda.c +10
-0+struct pnv_ioda_pe *pe; +int rc; + + if (!(pe =3D pnv_ioda_get_pe(dev))) +return -ENODEV ; + +/* Assign XIVE to PE */ + rc =3D opal_pci_set_xive_pe(phb->opal_id, pe->pe_number, xive_num); +if (rc) { + pr_warn("%s: OPAL error %d setting msi_base 0x%x hwirq 0x%x XIVE 0x%=
x PE\n",
Quoted 3 lines
arch/powerpc/platforms/powernv/pci-ioda.c static void set_msi_irq_chip(struct pnv_phb *phb, unsigned int virq) · line 1484
Quoted 1 line
arch/powerpc/platforms/powernv/pci-ioda.c +1
-0+ pci_name(dev), rc, phb->msi_base, hwirq, xive_num);=20
dev_warn()?
I'm going to move it to the pe_warn() we have here.
Cheers,
Mikey
PATCH v2 9/17 powerpc/mm: Add new hash_page_mm()
In reply to Michael NeulingFrom: Ian Munsie <[email protected]>
This adds a new function hash_page_mm() based on the existing hash_page(). This version allows any struct mm to be passed in, rather than assuming current. This is useful for servicing co-processor faults which are not in the context of the current running process.
We need to be careful here as the current hash_page() assumes current in a few places.
--- arch/powerpc/include/asm/mmu-hash64.h | 1 + arch/powerpc/mm/hash_utils_64.c | 22 ++++++++++++++-------- 2 files changed, 15 insertions(+), 8 deletions(-)
arch/powerpc/include/asm/mmu-hash64.h +1 -0
@@ -322,6 +322,7 @@ extern int __hash_page_64K(unsigned long ea, unsigned long access, unsigned int local, int ssize);struct mm_struct ;unsigned int hash_page_do_lazy_icache (unsigned int pp,pte_t pte,int trap); +extern int hash_page_mm (struct mm_struct *mm,unsigned long ea,unsigned long access,unsigned long trap);extern int hash_page (unsigned long ea,unsigned long access,unsigned long trap); int __hash_page_huge(unsigned long ea, unsigned long access, unsigned long vsid, pte_t *ptep, unsigned long trap, int local, int ssize,
arch/powerpc/mm/hash_utils_64.c +14 -8
@@ -904,7 +904,7 @@ void demote_segment_4k(struct mm_struct *mm, unsigned long addr)return ;slice_set_range_psize (mm, addr,1 ,MMU_PAGE_4K );copro_flush_all_slbs (mm); -if (get_paca_psize (addr) !=MMU_PAGE_4K ) { +if ((get_paca_psize (addr) !=MMU_PAGE_4K ) && (current->mm == mm)) {get_paca ()->context = mm->context;slb_flush_and_rebolt (); }
@@ -989,26 +989,24 @@ static void check_paca_psize(unsigned long ea, struct mm_struct *mm,* -1 - critical hash insertion error * -2 - access not permitted by subpage protection mechanism */ -int hash_page (unsigned long ea,unsigned long access,unsigned long trap) +int hash_page_mm (struct mm_struct *mm,unsigned long ea,unsigned long access,unsigned long trap) {enum ctx_state prev_state =exception_enter ();pgd_t *pgdir;unsigned long vsid; -struct mm_struct *mm;pte_t *ptep;unsigned hugeshift;const struct cpumask *tmp;int rc, user_region =0 , local =0 ;int psize, ssize; -DBG_LOW ("hash_page(ea=%016lx, access=%lx, trap=%lx\n" , - ea, access, trap); +DBG_LOW ("%s(ea=%016lx, access=%lx, trap=%lx\n" , + __func__, ea, access, trap);/* Get region & vsid */ switch (REGION_ID (ea)) {case USER_REGION_ID : user_region =1 ; - mm = current->mm;if (! mm) {DBG_LOW (" user region with no mm !\n" ); rc =1 ;
@@ -1104,7 +1102,8 @@ int hash_page(unsigned long ea, unsigned long access, unsigned long trap) WARN_ON(1); }#endif -check_paca_psize (ea, mm, psize, user_region); +if (current->mm == mm) +check_paca_psize (ea, mm, psize, user_region); goto bail; }
@@ -1145,7 +1144,8 @@ int hash_page(unsigned long ea, unsigned long access, unsigned long trap) } } -check_paca_psize (ea, mm, psize, user_region); +if (current->mm == mm) +check_paca_psize (ea, mm, psize, user_region);#endif /* CONFIG_PPC_64K_PAGES */ #ifdef CONFIG_PPC_HAS_HASH_64K
@@ -1180,6 +1180,12 @@ bail:exception_exit (prev_state);return rc; } +EXPORT_SYMBOL_GPL (hash_page_mm); + +int hash_page (unsigned long ea,unsigned long access,unsigned long trap) +{ +return hash_page_mm (current->mm, ea, access, trap); +}EXPORT_SYMBOL_GPL (hash_page); void hash_preload(struct mm_struct *mm, unsigned long ea,
Signature · 1 line
1.9.1
Re: [PATCH v2 09/17] powerpc/mm: Add new hash_page_mm()
Quoted 9 lines · Michael Neuling
From: Ian Munsie <[email protected]>
This adds a new function
hash_page_mm()based on the existinghash_page(). This version allows any struct mm to be passed in, rather than assuming current. This is useful for servicing co-processor faults which are not in the context of the current running process.We need to be careful here as the current
hash_page()assumes current in a few places.
It would be nice to document the rules here. So when we try to add a hash page entry, and if that result in demotion of the segment are we suppose to flush slbs ? Also why would one want to hash anything other than current->mm ? How will this get called ?
May be they are explained in later patches. But can we also explain it here.
Quoted 104 lines
Signed-off-by Ian Munsie <[email protected]>Signed-off-by Michael Neuling <[email protected]>--- arch/powerpc/include/asm/mmu-hash64.h | 1 + arch/powerpc/mm/hash_utils_64.c | 22 ++++++++++++++-------- 2 files changed, 15 insertions(+), 8 deletions(-)arch/powerpc/include/asm/mmu-hash64.h +1
-0@@ -322,6 +322,7 @@ extern int __hash_page_64K(unsigned long ea, unsigned long access, unsigned int local, int ssize);struct mm_struct ;unsigned int hash_page_do_lazy_icache (unsigned int pp,pte_t pte,int trap); +extern int hash_page_mm (struct mm_struct *mm,unsigned long ea,unsigned long access,unsigned long trap);extern int hash_page (unsigned long ea,unsigned long access,unsigned long trap); int __hash_page_huge(unsigned long ea, unsigned long access, unsigned long vsid, pte_t *ptep, unsigned long trap, int local, int ssize,arch/powerpc/mm/hash_utils_64.c +14
-8@@ -904,7 +904,7 @@ void demote_segment_4k(struct mm_struct *mm, unsigned long addr)return ;slice_set_range_psize (mm, addr,1 ,MMU_PAGE_4K );copro_flush_all_slbs (mm); -if (get_paca_psize (addr) !=MMU_PAGE_4K ) { +if ((get_paca_psize (addr) !=MMU_PAGE_4K ) && (current->mm == mm)) {get_paca ()->context = mm->context;slb_flush_and_rebolt (); }@@ -989,26 +989,24 @@ static void check_paca_psize(unsigned long ea, struct mm_struct *mm,* -1 - critical hash insertion error * -2 - access not permitted by subpage protection mechanism */ -int hash_page (unsigned long ea,unsigned long access,unsigned long trap) +int hash_page_mm (struct mm_struct *mm,unsigned long ea,unsigned long access,unsigned long trap) {enum ctx_state prev_state =exception_enter ();pgd_t *pgdir;unsigned long vsid; -struct mm_struct *mm;pte_t *ptep;unsigned hugeshift;const struct cpumask *tmp;int rc, user_region =0 , local =0 ;int psize, ssize; -DBG_LOW ("hash_page(ea=%016lx, access=%lx, trap=%lx\n" , - ea, access, trap); +DBG_LOW ("%s(ea=%016lx, access=%lx, trap=%lx\n" , + __func__, ea, access, trap);/* Get region & vsid */ switch (REGION_ID (ea)) {case USER_REGION_ID : user_region =1 ; - mm = current->mm;if (! mm) {DBG_LOW (" user region with no mm !\n" ); rc =1 ;@@ -1104,7 +1102,8 @@ int hash_page(unsigned long ea, unsigned long access, unsigned long trap) WARN_ON(1); }#endif -check_paca_psize (ea, mm, psize, user_region); +if (current->mm == mm) +check_paca_psize (ea, mm, psize, user_region); goto bail; }@@ -1145,7 +1144,8 @@ int hash_page(unsigned long ea, unsigned long access, unsigned long trap) } } -check_paca_psize (ea, mm, psize, user_region); +if (current->mm == mm) +check_paca_psize (ea, mm, psize, user_region);#endif /* CONFIG_PPC_64K_PAGES */ #ifdef CONFIG_PPC_HAS_HASH_64K @@ -1180,6 +1180,12 @@ bail:exception_exit (prev_state);return rc; } +EXPORT_SYMBOL_GPL (hash_page_mm); + +int hash_page (unsigned long ea,unsigned long access,unsigned long trap) +{ +return hash_page_mm (current->mm, ea, access, trap); +}EXPORT_SYMBOL_GPL (hash_page); void hash_preload(struct mm_struct *mm, unsigned long ea,Signature · 7 lines
1.9.1 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
Re: [PATCH v2 09/17] powerpc/mm: Add new hash_page_mm()
Quoted 5 lines · Aneesh Kumar K.V
Michael Neuling <[email protected]> writes:
=20Quoted 3 lines
From: Ian Munsie <[email protected]>
This adds a new function
hash_page_mm()based on the existing hash_page=
().
Quoted 2 lines
Quoted 2 lines
This version allows any struct mm to be passed in, rather than assuming current. This is useful for servicing co-processor faults which are no=
t in the
Quoted 3 lines
Quoted 3 lines
context of the current running process.
We need to be careful here as the current
hash_page()assumes current i=
n a few
Quoted 4 lines
Quoted 1 line
places.
=20
It would be nice to document the rules here. So when we try to add a hash page entry, and if that result in demotion of the segment are we suppose =
to
Quoted 1 line
flush slbs ?=20
Yeah, we found it sucky to understand. The current documentation is "buy benh a beer and ask him" which doesn't scale very well unless you're benh and you like beer.
Quoted 2 lines
Also why would one want to hash anything other
thancurrent->mm? How will this get called ?=20
We are calling this on behalf of a co-processor (eg cxl). The mm this is currently associated with may not be running on a cpu. =20
Quoted 2 lines
May be they are explained in later patches. But can we also explain it here.=20
Ok, I'll add something (mpe had the same question).
Mikey
Quoted 10 lines
=20
arch/powerpc/inclu=
Quoted 9 lines
Signed-off-by Ian Munsie <[email protected]>Signed-off-by Michael Neuling <[email protected]>--- arch/powerpc/include/asm/mmu-hash64.h | 1 + arch/powerpc/mm/hash_utils_64.c | 22 ++++++++++++++-------- 2 files changed, 15 insertions(+), 8 deletions(-)arch/powerpc/inclu= renamed from arch/powerpc/include/asm/mmu-hash64.h +0
-0
de/asm/mmu-hash64.h
Quoted 4 lines
arch/powerpc/include/asm/mmu-hash64.h extern int __hash_page_64K(unsigned long ea, unsign=
Quoted 4 lines
index 6d0b7a2..f84e5a5 100644
arch/powerpc/include/asm/mmu-hash64.h +0
-0@@ -322,6 +322,7 @@ extern int __hash_page_64K(unsigned long ea, unsign=
ed long access,
Quoted 3 lines
arch/powerpc/include/asm/mmu-hash64.h extern int __hash_page_64K(unsigned long ea, unsigned long access,
Quoted 3 lines
arch/powerpc/include/asm/mmu-hash64.h +0
-0unsigned int local, int ssize);struct mm_struct ; unsigned int hash_page_do_lazy_icache(unsigned int pp, pte_t pte, int =
trap);
Quoted 1 line
arch/powerpc/include/asm/mmu-hash64.h extern int __hash_page_64K(unsigned long ea, unsign= · line 325
Quoted 1 line
arch/powerpc/include/asm/mmu-hash64.h +1
-0+extern int hash_page_mm(struct mm_struct *mm, unsigned long ea, unsign=
ed long access, unsigned long trap);
Quoted 1 line
arch/powerpc/include/asm/mmu-hash64.h extern int __hash_page_64K(unsigned long ea, unsign= · line 326
Quoted 1 line
arch/powerpc/include/asm/mmu-hash64.h +0
-0extern int hash_page(unsigned long ea, unsigned long access, unsigned =
long trap);
Quoted 1 line
arch/powerpc/include/asm/mmu-hash64.h extern int __hash_page_64K(unsigned long ea, unsign= · line 327
Quoted 1 line
arch/powerpc/include/asm/mmu-hash64.h +0
-0int __hash_page_huge(unsigned long ea, unsigned long access, unsigned =
long vsid,
Quoted 2 lines
arch/powerpc/mm/hash_uti=
Quoted 2 lines
arch/powerpc/include/asm/mmu-hash64.h +0
-0pte_t *ptep, unsigned long trap, int local, int ssize,arch/powerpc/mm/hash_uti= renamed from arch/powerpc/mm/hash_utils_64.c +0
-0
ls_64.c
Quoted 4 lines
arch/powerpc/mm/hash_utils_64.c void demote_segment_4k(struct mm_struct *mm, unsign=
Quoted 4 lines
index bbdb054..0a5c8c0 100644
arch/powerpc/mm/hash_utils_64.c +0
-0@@ -904,7 +904,7 @@ void demote_segment_4k(struct mm_struct *mm, unsign=
ed long addr)
Quoted 5 lines
arch/powerpc/mm/hash_utils_64.c void demote_segment_4k(struct mm_struct *mm, unsigned long addr)
Quoted 5 lines
arch/powerpc/mm/hash_utils_64.c +1
-1return ;slice_set_range_psize (mm, addr,1 ,MMU_PAGE_4K );copro_flush_all_slbs (mm); - if (get_paca_psize(addr) !=3D MMU_PAGE_4K) { + if ((get_paca_psize(addr) !=3D MMU_PAGE_4K) && (current->mm =3D=3D mm=
)) {
Quoted 4 lines
arch/powerpc/mm/hash_utils_64.c static void check_paca_psize(unsigned long ea, st=
Quoted 4 lines
arch/powerpc/mm/hash_utils_64.c +0
-0get_paca()->context =3D mm->context;slb_flush_and_rebolt (); }@@ -989,26 +989,24 @@ static void check_paca_psize(unsigned long ea, st=
ruct mm_struct *mm,
Quoted 4 lines
arch/powerpc/mm/hash_utils_64.c static void check_paca_psize(unsigned long ea, struct mm_struct *mm,
Quoted 4 lines
arch/powerpc/mm/hash_utils_64.c +0
-1* -1 - critical hash insertion error * -2 - access not permitted by subpage protection mechanism */ -int hash_page(unsigned long ea, unsigned long access, unsigned long tr=
ap)
Quoted 1 line
arch/powerpc/mm/hash_utils_64.c static void check_paca_psize(unsigned long ea, st= · line 992
Quoted 1 line
arch/powerpc/mm/hash_utils_64.c +1
-0+int hash_page_mm(struct mm_struct *mm, unsigned long ea, unsigned long=
access, unsigned long trap)
Quoted 17 lines
Quoted 17 lines
arch/powerpc/mm/hash_utils_64.c +0
-1{ enum ctx_state prev_state =3D exception_enter();pgd_t *pgdir;unsigned long vsid; -struct mm_struct *mm;pte_t *ptep;unsigned hugeshift;const struct cpumask *tmp; int rc, user_region =3D 0, local =3D 0;int psize, ssize;=20
arch/powerpc/mm/hash_utils_64.c +2
-2-DBG_LOW ("hash_page(ea=3D%016lx, access=3D%lx, trap=3D%lx\n" , - ea, access, trap); +DBG_LOW ("%s(ea=3D%016lx, access=3D%lx, trap=3D%lx\n" , + __func__, ea, access, trap);=20
/* Get region & vsid */
Quoted 8 lines
arch/powerpc/mm/hash_utils_64.c int hash_page(unsigned long ea, unsigned long acc=
Quoted 8 lines
switch (REGION_ID(ea)) {arch/powerpc/mm/hash_utils_64.c +0
-1case USER_REGION_ID : user_region =3D 1; - mm =3D current->mm;if (! mm) {DBG_LOW (" user region with no mm !\n" ); rc =3D 1;@@ -1104,7 +1102,8 @@ int hash_page(unsigned long ea, unsigned long acc=
ess, unsigned long trap)
Quoted 10 lines
arch/powerpc/mm/hash_utils_64.c int hash_page(unsigned long ea, unsigned long acc=
Quoted 10 lines
arch/powerpc/mm/hash_utils_64.c +2
-1WARN_ON (1 ); }#endif -check_paca_psize (ea, mm, psize, user_region); + if (current->mm =3D=3D mm) +check_paca_psize (ea, mm, psize, user_region);=20
arch/powerpc/mm/hash_utils_64.c +0
-0goto bail; }@@ -1145,7 +1144,8 @@ int hash_page(unsigned long ea, unsigned long acc=
ess, unsigned long trap)
Quoted 8 lines
Quoted 8 lines
arch/powerpc/mm/hash_utils_64.c +0
-0} }=20
arch/powerpc/mm/hash_utils_64.c +2
-1-check_paca_psize (ea, mm, psize, user_region); + if (current->mm =3D=3D mm) +check_paca_psize (ea, mm, psize, user_region);#endif /* CONFIG_PPC_64K_PAGES */ =20
Quoted 8 lines
arch/powerpc/mm/hash_utils_64.c bail: · line 1185
Quoted 8 lines
#ifdef
CONFIG_PPC_HAS_HASH_64Karch/powerpc/mm/hash_utils_64.c +3
-0@@ -1180,6 +1180,12 @@ bail:exception_exit (prev_state);return rc; } +EXPORT_SYMBOL_GPL (hash_page_mm); + +int hash_page(unsigned long ea, unsigned long access, unsigned long tr=
ap)
Quoted 11 lines
Quoted 11 lines
arch/powerpc/mm/hash_utils_64.c +3
-0+{ +return hash_page_mm (current->mm, ea, access, trap); +}EXPORT_SYMBOL_GPL (hash_page);=20
void hash_preload(structmm_struct*mm, unsigned long ea,
--=20
1.9.1--
To unsubscribe from this list: send the line "unsubscribe linux-kernel"=
in
Quoted 4 lines
Quoted 3 lines
the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/=20
Michael Ellerman
reviewerRe: [PATCH v2 09/17] powerpc/mm: Add new hash_page_mm()
In reply to Michael NeulingQuoted 6 lines · Michael Neuling
From: Ian Munsie <[email protected]>
This adds a new function
hash_page_mm()based on the existinghash_page(). This version allows any struct mm to be passed in, rather than assuming current. This is useful for servicing co-processor faults which are not in the context of the current running process.
I'm not a big fan. hash_page() is already a train wreck, and this doesn't make it any better.
arch/powerpc/mm/hash_utils_64.c void demote_segment_4k(struct mm_struct *mm, unsigned long addr) · line 909
Quoted 12 lines
arch/powerpc/mm/hash_utils_64.c +1
-1@@ -904,7 +904,7 @@ void demote_segment_4k(struct mm_struct *mm, unsigned long addr)return ;slice_set_range_psize (mm, addr,1 ,MMU_PAGE_4K );copro_flush_all_slbs (mm); -if (get_paca_psize (addr) !=MMU_PAGE_4K ) { +if ((get_paca_psize (addr) !=MMU_PAGE_4K ) && (current->mm == mm)) {get_paca ()->context = mm->context;slb_flush_and_rebolt ();
This is a bit fishy.
If that mm is currently running on another cpu you just failed to update it's paca. But I think the call to check_paca_psize() in hash_page() will save you on that cpu.
In fact we might be able to remove that synchronisation from demote_segment_4k() and always leave it up to check_paca_psize()?
Quoted 20 lines
arch/powerpc/mm/hash_utils_64.c +2
-4@@ -989,26 +989,24 @@ static void check_paca_psize(unsigned long ea, struct mm_struct *mm,* -1 - critical hash insertion error * -2 - access not permitted by subpage protection mechanism */ -int hash_page (unsigned long ea,unsigned long access,unsigned long trap) +int hash_page_mm (struct mm_struct *mm,unsigned long ea,unsigned long access,unsigned long trap) {enum ctx_state prev_state =exception_enter ();pgd_t *pgdir;unsigned long vsid; -struct mm_struct *mm;pte_t *ptep;unsigned hugeshift;const struct cpumask *tmp;int rc, user_region =0 , local =0 ;int psize, ssize; -DBG_LOW ("hash_page(ea=%016lx, access=%lx, trap=%lx\n" , - ea, access, trap); + DBG_LOW("%s(ea=%016lx, access=%lx, trap=%lx\n",
arch/powerpc/mm/hash_utils_64.c static void check_paca_psize(unsigned long ea, struct mm_struct *mm, · line 1012
Quoted 10 lines
arch/powerpc/mm/hash_utils_64.c +1
-1+ __func__, ea, access, trap);/* Get region & vsid */ switch (REGION_ID (ea)) {case USER_REGION_ID : user_region =1 ; - mm = current->mm;if (! mm) {DBG_LOW (" user region with no mm !\n" ); rc =1 ;
What about the VMALLOC case where we do:
mm = &init_mm;
Is that what you want? It seems odd that you pass an mm to the routine, but then potentially it ends up using a different mm after all depending on the address.
cheers
Re: [PATCH v2 09/17] powerpc/mm: Add new hash_page_mm()
Quoted 4 lines · Michael Ellerman
Quoted 3 lines · Michael Neuling
From: Ian Munsie <[email protected]>
=20
This adds a new functionhash_page_mm()based on the existing hash_page=
().
Quoted 2 lines
Quoted 2 lines
This version allows any struct mm to be passed in, rather than assuming current. This is useful for servicing co-processor faults which are no=
t in the
Quoted 3 lines
Quoted 1 line
context of the current running process.
=20
I'm not a big fan.hash_page()is already a train wreck, and this doesn't=
make
Quoted 1 line
it any better.
I can document it to make the situation a bit better. It's certainly not clear which one to use here and under what circumstances. It's basically ask benh territory. =20
Quoted 1 line
arch/powerpc/mm/hash_uti=
Quoted 1 line
arch/powerpc/mm/hash_uti= renamed from arch/powerpc/mm/hash_utils_64.c +0
-0
ls_64.c
Quoted 4 lines
arch/powerpc/mm/hash_utils_64.c void demote_segment_4k(struct mm_struct *mm, unsign=
Quoted 4 lines
index bbdb054..0a5c8c0 100644
arch/powerpc/mm/hash_utils_64.c +0
-0@@ -904,7 +904,7 @@ void demote_segment_4k(struct mm_struct *mm, unsign=
ed long addr)
Quoted 5 lines
arch/powerpc/mm/hash_utils_64.c void demote_segment_4k(struct mm_struct *mm, unsigned long addr)
Quoted 5 lines
arch/powerpc/mm/hash_utils_64.c +1
-1return ;slice_set_range_psize (mm, addr,1 ,MMU_PAGE_4K );copro_flush_all_slbs (mm); - if (get_paca_psize(addr) !=3D MMU_PAGE_4K) { + if ((get_paca_psize(addr) !=3D MMU_PAGE_4K) && (current->mm =3D=3D mm=
)) {
Quoted 6 lines
arch/powerpc/mm/hash_utils_64.c void demote_segment_4k(struct mm_struct *mm, unsign= · line 909
Quoted 2 lines
arch/powerpc/mm/hash_utils_64.c +0
-0get_paca()->context =3D mm->context;slb_flush_and_rebolt ();=20
This is a bit fishy.
=20
If that mm is currently running on another cpu you just failed to update =
it's
Quoted 1 line
paca. But I think the call to
check_paca_psize()inhash_page()will save=
you
Quoted 4 lines
on that cpu.
=20
In fact we might be able to remove that synchronisation fromdemote_segment_4k()and always leave it up tocheck_paca_psize()?
Aneesh asked the same thing for v1 and we convinced ourselves it was ok. I said this at the time...
I had a chat to benh offline about this and he thinks it's fine. A running process in the same mm context will either have hit this mapping or not. If it's hit it, the page will be invalidated and it'll come in via hash_page and have it's segment demoted also (and paca updated). If it hasn't hit, again it'll come into hash_page() and get demoted also.
Quoted 1 line
arch/powerpc/mm/hash_utils_64.c static void check_paca_psize(unsigned long ea, st=
Quoted 1 line
arch/powerpc/mm/hash_utils_64.c +0
-0@@ -989,26 +989,24 @@ static void check_paca_psize(unsigned long ea, st=
ruct mm_struct *mm,
Quoted 4 lines
arch/powerpc/mm/hash_utils_64.c static void check_paca_psize(unsigned long ea, struct mm_struct *mm,
Quoted 4 lines
arch/powerpc/mm/hash_utils_64.c +0
-1* -1 - critical hash insertion error * -2 - access not permitted by subpage protection mechanism */ -int hash_page(unsigned long ea, unsigned long access, unsigned long tr=
ap)
Quoted 1 line
arch/powerpc/mm/hash_utils_64.c static void check_paca_psize(unsigned long ea, st= · line 992
Quoted 1 line
arch/powerpc/mm/hash_utils_64.c +1
-0+int hash_page_mm(struct mm_struct *mm, unsigned long ea, unsigned long=
access, unsigned long trap)
Quoted 26 lines
Quoted 16 lines
arch/powerpc/mm/hash_utils_64.c +0
-1{ enum ctx_state prev_state =3D exception_enter();pgd_t *pgdir;unsigned long vsid; -struct mm_struct *mm;pte_t *ptep;unsigned hugeshift;const struct cpumask *tmp; int rc, user_region =3D 0, local =3D 0;int psize, ssize;=20
arch/powerpc/mm/hash_utils_64.c +2
-2-DBG_LOW ("hash_page(ea=3D%016lx, access=3D%lx, trap=3D%lx\n" , - ea, access, trap); +DBG_LOW ("%s(ea=3D%016lx, access=3D%lx, trap=3D%lx\n" , + __func__, ea, access, trap);=20
arch/powerpc/mm/hash_utils_64.c static void check_paca_psize(unsigned long ea, struct mm_struct *mm,
Quoted 8 lines
arch/powerpc/mm/hash_utils_64.c +0
-1/* Get region & vsid */ switch (REGION_ID (ea)) {case USER_REGION_ID : user_region =3D 1; - mm =3D current->mm;if (! mm) {DBG_LOW (" user region with no mm !\n" ); rc =3D 1;=20
What about the VMALLOC case where we do:
Quoted 3 lines
mm =3D &init_mm; =09Is that what you want? It seems odd that you pass an mm to the routine, b=
ut
Quoted 1 line
then potentially it ends up using a different mm after all depending on t=
he
Quoted 1 line
address.
Good point. We have hash_page() still. I can make that check in there
and decide which mm to use and pass that to hash_page_mm(). Then we
always use mm in hash_page_mm(). hash_page() will then look like this:=20
int hash_page(unsigned long ea, unsigned long access, unsigned long trap)
{
struct mm_struct *mm =3D current->mm;
if (REGION_ID(ea) =3D=3D VMALLOC_REGION_ID)
mm =3D &init_mm;
return hash_page_mm(mm, ea, access, trap);
}Mikey
PATCH v2 10/17 powerpc/mm: Merge vsid calculation in hash_page() and copro_data_segment()
In reply to Michael NeulingFrom: Ian Munsie <[email protected]>
The vsid calculation between hash_page() and copro_data_segment() are very similar. This merges these two different versions.
--- arch/powerpc/include/asm/mmu-hash64.h | 2 ++ arch/powerpc/mm/copro_fault.c | 45 ++++++-------------------- arch/powerpc/mm/hash_utils_64.c | 61 ++++++++++++++++++++++------------- 3 files changed, 50 insertions(+), 58 deletions(-)
arch/powerpc/include/asm/mmu-hash64.h +2 -0
@@ -322,6 +322,8 @@ extern int __hash_page_64K(unsigned long ea, unsigned long access, unsigned int local, int ssize);struct mm_struct ;unsigned int hash_page_do_lazy_icache (unsigned int pp,pte_t pte,int trap); +int calculate_vsid (struct mm_struct *mm,u64 ea, +u64 *vsid,int *psize,int *ssize);extern int hash_page_mm (struct mm_struct *mm,unsigned long ea,unsigned long access,unsigned long trap);extern int hash_page (unsigned long ea,unsigned long access,unsigned long trap); int __hash_page_huge(unsigned long ea, unsigned long access, unsigned long vsid,
arch/powerpc/mm/copro_fault.c +9 -36
54 lines not on this page · raw message
arch/powerpc/mm/hash_utils_64.c +39 -22
87 lines not on this page · raw message
Signature · 1 line
1.9.1
Re: [PATCH v2 10/17] powerpc/mm: Merge vsid calculation in hash_page() and copro_data_segment()
Quoted 161 lines · Michael Neuling
From: Ian Munsie <[email protected]>
The vsid calculation between
hash_page()andcopro_data_segment()are very similar. This merges these two different versions.Signed-off-by Ian Munsie <[email protected]>Signed-off-by Michael Neuling <[email protected]>--- arch/powerpc/include/asm/mmu-hash64.h | 2 ++ arch/powerpc/mm/copro_fault.c | 45 ++++++-------------------- arch/powerpc/mm/hash_utils_64.c | 61 ++++++++++++++++++++++------------- 3 files changed, 50 insertions(+), 58 deletions(-)arch/powerpc/include/asm/mmu-hash64.h +2
-0@@ -322,6 +322,8 @@ extern int __hash_page_64K(unsigned long ea, unsigned long access, unsigned int local, int ssize);struct mm_struct ;unsigned int hash_page_do_lazy_icache (unsigned int pp,pte_t pte,int trap); +int calculate_vsid (struct mm_struct *mm,u64 ea, +u64 *vsid,int *psize,int *ssize);extern int hash_page_mm (struct mm_struct *mm,unsigned long ea,unsigned long access,unsigned long trap);extern int hash_page (unsigned long ea,unsigned long access,unsigned long trap); int __hash_page_huge(unsigned long ea, unsigned long access, unsigned long vsid,arch/powerpc/mm/copro_fault.c +9
-36@@ -94,45 +94,18 @@ EXPORT_SYMBOL_GPL(copro_handle_mm_fault);int copro_data_segment (struct mm_struct *mm,u64 ea,u64 *esid,u64 *vsid) { -int psize, ssize; +int psize, ssize, rc; *esid = (ea &ESID_MASK ) |SLB_ESID_V ; -switch (REGION_ID (ea)) { -case USER_REGION_ID : -pr_devel ("copro_data_segment: 0x%llx -- USER_REGION_ID\n" , ea); -#ifdef CONFIG_PPC_MM_SLICES - psize =get_slice_psize (mm, ea); -#else - psize = mm->context.user_psize; -#endif - ssize =user_segment_size (ea); - *vsid = (get_vsid (mm->context.id, ea, ssize) - <<slb_vsid_shift (ssize)) |SLB_VSID_USER ; -break ; -case VMALLOC_REGION_ID : -pr_devel ("copro_data_segment: 0x%llx -- VMALLOC_REGION_ID\n" , ea); -if (ea <VMALLOC_END ) - psize = mmu_vmalloc_psize; -else - psize = mmu_io_psize; - ssize = mmu_kernel_ssize; - *vsid = (get_kernel_vsid (ea, mmu_kernel_ssize) - <<SLB_VSID_SHIFT ) |SLB_VSID_KERNEL ; -break ; -case KERNEL_REGION_ID : -pr_devel ("copro_data_segment: 0x%llx -- KERNEL_REGION_ID\n" , ea); - psize = mmu_linear_psize; - ssize = mmu_kernel_ssize; - *vsid = (get_kernel_vsid (ea, mmu_kernel_ssize) - <<SLB_VSID_SHIFT ) |SLB_VSID_KERNEL ; -break ; -default : -/* Future: support kernel segments so that drivers can use the -* CoProcessors */ -pr_debug ("invalid region access at %016llx\n" , ea); -return 1 ; - } + rc =calculate_vsid (mm, ea, vsid, &psize, &ssize); +if (rc) +return rc; +if (REGION_ID (ea) ==USER_REGION_ID ) + *vsid = (*vsid <<slb_vsid_shift (ssize)) |SLB_VSID_USER ; +else + *vsid = (*vsid <<SLB_VSID_SHIFT ) |SLB_VSID_KERNEL ; + *vsid |= mmu_psize_defs[psize].sllp | ((ssize ==MMU_SEGSIZE_1T ) ?SLB_VSID_B_1T :0 );arch/powerpc/mm/hash_utils_64.c +36
-11@@ -983,6 +983,38 @@ static void check_paca_psize(unsigned long ea, struct mm_struct *mm, } } +int calculate_vsid (struct mm_struct *mm,u64 ea, +u64 *vsid,int *psize,int *ssize) +{ +switch (REGION_ID (ea)) { +case USER_REGION_ID : +pr_devel ("%s: 0x%llx -- USER_REGION_ID\n" , __func__, ea); + *psize =get_slice_psize (mm, ea); + *ssize =user_segment_size (ea); + *vsid =get_vsid (mm->context.id, ea, *ssize); +return 0 ; +case VMALLOC_REGION_ID : +pr_devel ("%s: 0x%llx -- VMALLOC_REGION_ID\n" , __func__, ea); +if (ea <VMALLOC_END ) + *psize = mmu_vmalloc_psize; +else + *psize = mmu_io_psize; + *ssize = mmu_kernel_ssize; + *vsid =get_kernel_vsid (ea, mmu_kernel_ssize); +return 0 ; +case KERNEL_REGION_ID : +pr_devel ("%s: 0x%llx -- KERNEL_REGION_ID\n" , __func__, ea); + *psize = mmu_linear_psize; + *ssize = mmu_kernel_ssize; + *vsid =get_kernel_vsid (ea, mmu_kernel_ssize); +return 0 ; +default : +pr_debug ("%s: invalid region access at %016llx\n" , __func__, ea); +return 1 ; + } +} +EXPORT_SYMBOL_GPL (calculate_vsid); +/* Result code is: * 0 - handled * 1 - normal page fault @@ -993,7 +1025,7 @@ int hash_page_mm(struct mm_struct *mm, unsigned long ea, unsigned long access, u {enum ctx_state prev_state =exception_enter ();pgd_t *pgdir; -unsigned long vsid; +u64 vsid;pte_t *ptep;unsigned hugeshift;const struct cpumask *tmp;@@ -1003,35 +1035,20 @@ int hash_page_mm(struct mm_struct *mm, unsigned long ea, unsigned long access, uDBG_LOW ("%s(ea=%016lx, access=%lx, trap=%lx\n" , __func__, ea, access, trap); -/* Get region & vsid */ -switch (REGION_ID (ea)) { -case USER_REGION_ID : +/* Get region */ +if (REGION_ID (ea) ==USER_REGION_ID ) { user_region =1 ;if (! mm) {DBG_LOW (" user region with no mm !\n" ); rc =1 ; goto bail; } - psize =get_slice_psize (mm, ea); - ssize =user_segment_size (ea); - vsid =get_vsid (mm->context.id, ea, ssize); -break ; -case VMALLOC_REGION_ID : + }else mm = &init_mm; - vsid =get_kernel_vsid (ea, mmu_kernel_ssize); -if (ea <VMALLOC_END )
arch/powerpc/mm/hash_utils_64.c int hash_page_mm(struct mm_struct *mm, unsigned long ea, unsigned long access, u · line 1032
Quoted 10 lines
arch/powerpc/mm/hash_utils_64.c +0
-10- psize = mmu_vmalloc_psize; - else - psize = mmu_io_psize; - ssize = mmu_kernel_ssize; -break ; -default : -/* Not a valid range -* Send the problem up to do_page_fault -*/ - rc =1 ;
That part is different now. We now handle kernel_region_id in case of hash_page. Earlier we used consider it a problem.
Quoted 16 lines
arch/powerpc/mm/hash_utils_64.c +3
-1+ rc =calculate_vsid (mm, ea, &vsid, &psize, &ssize); +if (rc) goto bail; - } +DBG_LOW (" mm=%p, mm->pgdir=%p, vsid=%016lx\n" , mm, mm->pgd, vsid);/* Bad address. */ Signature · 7 lines
1.9.1 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
Re: [PATCH v2 10/17] powerpc/mm: Merge vsid calculation in hash_page() and copro_data_segment()
Quoted 5 lines · Aneesh Kumar K.V
Michael Neuling <[email protected]> writes:
=20Quoted 3 lines
From: Ian Munsie <[email protected]>
The vsid calculation between
hash_page()andcopro_data_segment()are v=
ery
Quoted 8 lines
Quoted 8 lines
similar. This merges these two different versions.
Signed-off-by Ian Munsie <[email protected]>Signed-off-by Michael Neuling <[email protected]>--- arch/powerpc/include/asm/mmu-hash64.h | 2 ++ arch/powerpc/mm/copro_fault.c | 45 ++++++--------------------
arch/powerpc/mm/hash_utils_64.c| 61 ++++++++++++++++++++++-----=
--------
Quoted 3 lines
arch/powerpc/inclu=
Quoted 3 lines
3 files changed, 50 insertions(+), 58 deletions(-)arch/powerpc/inclu= renamed from arch/powerpc/include/asm/mmu-hash64.h +0
-0
de/asm/mmu-hash64.h
Quoted 4 lines
arch/powerpc/include/asm/mmu-hash64.h extern int __hash_page_64K(unsigned long ea, unsign=
Quoted 4 lines
index f84e5a5..bf43fb0 100644
arch/powerpc/include/asm/mmu-hash64.h +0
-0@@ -322,6 +322,8 @@ extern int __hash_page_64K(unsigned long ea, unsign=
ed long access,
Quoted 3 lines
arch/powerpc/include/asm/mmu-hash64.h extern int __hash_page_64K(unsigned long ea, unsigned long access,
Quoted 3 lines
arch/powerpc/include/asm/mmu-hash64.h +0
-0unsigned int local, int ssize);struct mm_struct ; unsigned int hash_page_do_lazy_icache(unsigned int pp, pte_t pte, int =
trap);
Quoted 3 lines
arch/powerpc/include/asm/mmu-hash64.h extern int __hash_page_64K(unsigned long ea, unsigned long access,
Quoted 3 lines
arch/powerpc/include/asm/mmu-hash64.h +2
-0+int calculate_vsid (struct mm_struct *mm,u64 ea, +u64 *vsid,int *psize,int *ssize); extern int hash_page_mm(struct mm_struct *mm, unsigned long ea, unsign=
ed long access, unsigned long trap);
Quoted 1 line
arch/powerpc/include/asm/mmu-hash64.h extern int __hash_page_64K(unsigned long ea, unsign= · line 328
Quoted 1 line
arch/powerpc/include/asm/mmu-hash64.h +0
-0extern int hash_page(unsigned long ea, unsigned long access, unsigned =
long trap);
Quoted 1 line
arch/powerpc/include/asm/mmu-hash64.h extern int __hash_page_64K(unsigned long ea, unsign= · line 329
Quoted 1 line
arch/powerpc/include/asm/mmu-hash64.h +0
-0int __hash_page_huge(unsigned long ea, unsigned long access, unsigned =
long vsid,
Quoted 1 line
arch/powerpc/mm/copro_faul=
Quoted 1 line
arch/powerpc/mm/copro_faul= renamed from arch/powerpc/mm/copro_fault.c +0
-0
t.c
Quoted 6 lines
Quoted 6 lines
index 939abdf..ba8bf8e 100644
arch/powerpc/mm/copro_fault.c +0
-0@@ -94,45 +94,18 @@ EXPORT_SYMBOL_GPL(copro_handle_mm_fault);=20
int copro_data_segment(structmm_struct*mm, u64 ea, u64 *esid, u64 *v=
sid)
Quoted 45 lines
Quoted 45 lines
{
arch/powerpc/mm/copro_fault.c +1
-1-int psize, ssize; +int psize, ssize, rc;=20
*esid =3D (ea &ESID_MASK) |SLB_ESID_V;
=20arch/powerpc/mm/copro_fault.c +4
-35-switch (REGION_ID (ea)) { -case USER_REGION_ID : -pr_devel ("copro_data_segment: 0x%llx -- USER_REGION_ID\n" , ea); -#ifdef CONFIG_PPC_MM_SLICES - psize =3D get_slice_psize(mm, ea); -#else - psize =3D mm->context.user_psize; -#endif - ssize =3D user_segment_size(ea); - *vsid =3D (get_vsid (mm->context.id, ea, ssize) - <<slb_vsid_shift (ssize)) |SLB_VSID_USER ; -break ; -case VMALLOC_REGION_ID : -pr_devel ("copro_data_segment: 0x%llx -- VMALLOC_REGION_ID\n" , ea); -if (ea <VMALLOC_END ) - psize =3D mmu_vmalloc_psize; -else - psize =3D mmu_io_psize; - ssize =3D mmu_kernel_ssize; - *vsid =3D (get_kernel_vsid (ea, mmu_kernel_ssize) - <<SLB_VSID_SHIFT ) |SLB_VSID_KERNEL ; -break ; -case KERNEL_REGION_ID : -pr_devel ("copro_data_segment: 0x%llx -- KERNEL_REGION_ID\n" , ea); - psize =3D mmu_linear_psize; - ssize =3D mmu_kernel_ssize; - *vsid =3D (get_kernel_vsid (ea, mmu_kernel_ssize) - <<SLB_VSID_SHIFT ) |SLB_VSID_KERNEL ; -break ; -default : -/* Future: support kernel segments so that drivers can use the -* CoProcessors */ -pr_debug ("invalid region access at %016llx\n" , ea); -return 1 ; - } + rc =3D calculate_vsid(mm, ea, vsid, &psize, &ssize); +if (rc) +return rc; + if (REGION_ID(ea) =3D=3D USER_REGION_ID)
Quoted 8 lines
arch/powerpc/mm/hash_uti=
Quoted 8 lines
arch/powerpc/mm/copro_fault.c +4
-0+ *vsid =3D (*vsid <<slb_vsid_shift (ssize)) |SLB_VSID_USER ; + else + *vsid =3D (*vsid <<SLB_VSID_SHIFT ) |SLB_VSID_KERNEL ; + *vsid |=3D mmu_psize_defs[psize].sllp | ((ssize =3D=3D MMU_SEGSIZE_1T) ? SLB_VSID_B_1T : 0);=20
arch/powerpc/mm/hash_uti= renamed from arch/powerpc/mm/hash_utils_64.c +0
-0
ls_64.c
Quoted 4 lines
arch/powerpc/mm/hash_utils_64.c static void check_paca_psize(unsigned long ea, str=
Quoted 4 lines
index 0a5c8c0..3fa81ca 100644
arch/powerpc/mm/hash_utils_64.c +0
-0@@ -983,6 +983,38 @@ static void check_paca_psize(unsigned long ea, str=
uct mm_struct *mm,
Quoted 31 lines
Quoted 31 lines
arch/powerpc/mm/hash_utils_64.c +0
-0} }=20
arch/powerpc/mm/hash_utils_64.c +28
-0+int calculate_vsid (struct mm_struct *mm,u64 ea, +u64 *vsid,int *psize,int *ssize) +{ +switch (REGION_ID (ea)) { +case USER_REGION_ID : +pr_devel ("%s: 0x%llx -- USER_REGION_ID\n" , __func__, ea); + *psize =3D get_slice_psize(mm, ea); + *ssize =3D user_segment_size(ea); + *vsid =3D get_vsid(mm->context.id, ea, *ssize); +return 0 ; +case VMALLOC_REGION_ID : +pr_devel ("%s: 0x%llx -- VMALLOC_REGION_ID\n" , __func__, ea); +if (ea <VMALLOC_END ) + *psize =3D mmu_vmalloc_psize; +else + *psize =3D mmu_io_psize; + *ssize =3D mmu_kernel_ssize; + *vsid =3D get_kernel_vsid(ea, mmu_kernel_ssize); +return 0 ; +case KERNEL_REGION_ID : +pr_devel ("%s: 0x%llx -- KERNEL_REGION_ID\n" , __func__, ea); + *psize =3D mmu_linear_psize; + *ssize =3D mmu_kernel_ssize; + *vsid =3D get_kernel_vsid(ea, mmu_kernel_ssize); +return 0 ; +default : +pr_debug ("%s: invalid region access at %016llx\n" , __func__, ea); +return 1 ;
Quoted 8 lines
arch/powerpc/mm/hash_utils_64.c int hash_page_mm(struct mm_struct *mm, unsigned lo=
Quoted 8 lines
arch/powerpc/mm/hash_utils_64.c +4
-0+ } +} +EXPORT_SYMBOL_GPL (calculate_vsid); +/* Result code is: * 0 - handled * 1 - normal page fault @@ -993,7 +1025,7 @@ int hash_page_mm(struct mm_struct *mm, unsigned lo=
ng ea, unsigned long access, u
Quoted 9 lines
arch/powerpc/mm/hash_utils_64.c int hash_page_mm(struct mm_struct *mm, unsigned=
Quoted 9 lines
arch/powerpc/mm/hash_utils_64.c +1
-1{ enum ctx_state prev_state =3D exception_enter();pgd_t *pgdir; -unsigned long vsid; +u64 vsid;pte_t *ptep;unsigned hugeshift;const struct cpumask *tmp;@@ -1003,35 +1035,20 @@ int hash_page_mm(struct mm_struct *mm, unsigned=
long ea, unsigned long access, u
Quoted 29 lines
Quoted 29 lines
arch/powerpc/mm/hash_utils_64.c +0
-0DBG_LOW ("%s(ea=3D%016lx, access=3D%lx, trap=3D%lx\n" , __func__, ea, access, trap);=20
arch/powerpc/mm/hash_utils_64.c +3
-16-/* Get region & vsid */ -switch (REGION_ID (ea)) { -case USER_REGION_ID : +/* Get region */ + if (REGION_ID(ea) =3D=3D USER_REGION_ID) { user_region =3D 1;if (! mm) {DBG_LOW (" user region with no mm !\n" ); rc =3D 1; goto bail; } - psize =3D get_slice_psize(mm, ea); - ssize =3D user_segment_size(ea); - vsid =3D get_vsid(mm->context.id, ea, ssize); -break ; -case VMALLOC_REGION_ID : + }else mm =3D &init_mm; - vsid =3D get_kernel_vsid(ea, mmu_kernel_ssize); -if (ea <VMALLOC_END ) - psize =3D mmu_vmalloc_psize; -else - psize =3D mmu_io_psize; - ssize =3D mmu_kernel_ssize; -break ; -default :
Quoted 8 lines
arch/powerpc/mm/hash_utils_64.c int hash_page_mm(struct mm_struct *mm, unsigned long ea, unsigned long access, u
Quoted 4 lines
arch/powerpc/mm/hash_utils_64.c +0
-4-/* Not a valid range -* Send the problem up to do_page_fault=20 -*/ - rc =3D 1;=20
=20
That part is different now. We now handlekernel_region_idin case ofhash_page. Earlier we used consider it a problem.=20
Yeah, that's going to be the kernel linear mapping. We should probably continue to barf as we shouldn't fault on that. Thanks.
I'll fix.
Mikey
Quoted 7 lines
=20
arch/powerpc/mm/hash_utils_64.c int hash_page_mm(struct mm_struct *mm, unsigned long ea, unsigned long access, u
Quoted 6 lines
arch/powerpc/mm/hash_utils_64.c +3
-1+ rc =3D calculate_vsid(mm, ea, &vsid, &psize, &ssize); +if (rc) goto bail; - } + DBG_LOW(" mm=3D%p, mm->pgdir=3D%p, vsid=3D%016lx\n", mm, mm->pgd, vsi=
d);
Quoted 7 lines
Quoted 7 lines
=20
/* Bad address. */
--=20
1.9.1--
To unsubscribe from this list: send the line "unsubscribe linux-kernel"=
in
Quoted 4 lines
Quoted 3 lines
the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/=20
PATCH v2 11/17 powerpc/opal: Add PHB to cxl mode call
In reply to Michael NeulingFrom: Ian Munsie <[email protected]>
This adds the OPAL call to change a PHB into cxl mode.
--- arch/powerpc/include/asm/opal.h | 2 ++ arch/powerpc/platforms/powernv/opal-wrappers.S | 1 + 2 files changed, 3 insertions(+)
arch/powerpc/include/asm/opal.h +2 -0
@@ -146,6 +146,7 @@ struct opal_sg_list {#define OPAL_GET_PARAM 89#define OPAL_SET_PARAM 90#define OPAL_DUMP_RESEND 91 +#define OPAL_PCI_SET_PHB_CXL_MODE 93#define OPAL_DUMP_INFO2 94#define OPAL_PCI_EEH_FREEZE_SET 97#define OPAL_HANDLE_HMI 98
@@ -924,6 +925,7 @@ int64_t opal_sensor_read(uint32_t sensor_hndl, int token, __be32 *sensor_data);int64_t opal_handle_hmi (void );int64_t opal_register_dump_region (uint32_t id,uint64_t start,uint64_t end);int64_t opal_unregister_dump_region (uint32_t id); +int64_t opal_pci_set_phb_cxl_mode (uint64_t phb_id,uint64_t mode,uint64_t pe_number);/* Internal functions */ extern int early_init_dt_scan_opal(unsigned long node, const char *uname,
arch/powerpc/platforms/powernv/opal-wrappers.S +1 -0
@@ -247,3 +247,4 @@ OPAL_CALL(opal_set_param, OPAL_SET_PARAM); OPAL_CALL(opal_handle_hmi, OPAL_HANDLE_HMI); OPAL_CALL(opal_register_dump_region, OPAL_REGISTER_DUMP_REGION); OPAL_CALL(opal_unregister_dump_region, OPAL_UNREGISTER_DUMP_REGION); +OPAL_CALL(opal_pci_set_phb_cxl_mode, OPAL_PCI_SET_PHB_CXL_MODE);
Signature · 1 line
1.9.1
PATCH v2 12/17 powerpc/mm: Add hooks for cxl
In reply to Michael NeulingFrom: Ian Munsie <[email protected]>
This add a hook into tlbie() so that we use global invalidations when there are cxl contexts active.
Normally cxl snoops broadcast tlbie. cxl can have TLB entries invalidated via MMIO, but we aren't doing that yet. So for now we are just disabling local tlbies when cxl contexts are active. In future we can make tlbie() local mode smarter so that it invalidates cxl contexts explicitly when it needs to.
This also adds a hooks for when SLBs are invalidated to ensure any corresponding SLBs in cxl are also invalidated at the same time.
--- arch/powerpc/mm/copro_fault.c | 2 ++ arch/powerpc/mm/hash_native_64.c | 6 +++++- 2 files changed, 7 insertions(+), 1 deletion(-)
arch/powerpc/mm/copro_fault.c +2 -0
@@ -25,6 +25,7 @@#include <linux/export.h> #include <asm/reg.h> #include <asm/spu.h> +#include <misc/cxl.h> /* * This ought to be kept in sync with the powerpc specific do_page_fault
@@ -118,5 +119,6 @@ void copro_flush_all_slbs(struct mm_struct *mm)#ifdef CONFIG_SPU_BASE spu_flush_all_slbs (mm);#endif +cxl_slbia (mm); }EXPORT_SYMBOL_GPL (copro_flush_all_slbs);
arch/powerpc/mm/hash_native_64.c +5 -1
@@ -29,6 +29,8 @@#include <asm/kexec.h> #include <asm/ppc-opcode.h> +#include <misc/cxl.h> +#ifdef DEBUG_LOW #define DBG_LOW(fmt...) udbg_printf(fmt)#else
@@ -149,9 +151,11 @@ static inline void __tlbiel(unsigned long vpn, int psize, int apsize, int ssize)static inline void tlbie (unsigned long vpn,int psize,int apsize,int ssize,int local) { -unsigned int use_local = local &&mmu_has_feature (MMU_FTR_TLBIEL ); +unsigned int use_local;int lock_tlbie = !mmu_has_feature (MMU_FTR_LOCKLESS_TLBIE ); + use_local = local &&mmu_has_feature (MMU_FTR_TLBIEL ) && !cxl_ctx_in_use (); +if (use_local) use_local = mmu_psize_defs[psize].tlbiel;if (lock_tlbie && !use_local)
Signature · 1 line
1.9.1
PATCH v2 13/17 cxl: Add base builtin support
In reply to Michael NeulingFrom: Ian Munsie <[email protected]>
This adds the base cxl support that needs to be build into the kernel to use cxl as a module. This is needed so that the cxl call backs from the core powerpc mm code always exist irrespective of if the cxl module is loaded or not. This is similar to how cell works with CONFIG_SPU_BASE.
This adds a cxl_slbia() call (similar to spu_flush_all_slbs()) which checks for the cxl module being loaded. If the modules is not loaded we return, otherwise we call into the cxl SLB invalidation code.
This also adds the cxl_ctx_in_use() function for use in the mm code to see if any cxl contexts are currently in use. This is used by the tlbie() to determine if it can do local TLB invalidations or not. This also adds get/put calls for the cxl driver module to refcount the active cxl contexts.
--- drivers/misc/Kconfig | 1 + drivers/misc/Makefile | 1 + drivers/misc/cxl/Kconfig | 8 ++++ drivers/misc/cxl/Makefile | 1 + drivers/misc/cxl/base.c | 102 ++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 113 insertions(+) create mode 100644 drivers/misc/cxl/Kconfig create mode 100644 drivers/misc/cxl/Makefile create mode 100644 drivers/misc/cxl/base.c
drivers/misc/Kconfig +1 -0
@@ -527,4 +527,5 @@ source "drivers/misc/vmw_vmci/Kconfig" source "drivers/misc/mic/Kconfig" source "drivers/misc/genwqe/Kconfig" source "drivers/misc/echo/Kconfig" +source "drivers/misc/cxl/Kconfig" endmenu
drivers/misc/Makefile +1 -0
@@ -55,3 +55,4 @@ obj-y += mic/ obj-$(CONFIG_GENWQE) += genwqe/ obj-$(CONFIG_ECHO) += echo/ obj-$(CONFIG_VEXPRESS_SYSCFG) += vexpress-syscfg.o +obj-$(CONFIG_CXL_BASE) += cxl/
drivers/misc/cxl/Kconfig new file +8 -0
@@ -0,0 +1,8 @@ +# +# IBM Coherent Accelerator (CXL) compatible devices +# + +config CXL_BASE + bool + default n + select PPC_COPRO_BASE
drivers/misc/cxl/Makefile new file +1 -0
@@ -0,0 +1 @@ +obj-$(CONFIG_CXL_BASE) += base.o
drivers/misc/cxl/base.c new file +102 -0
102 lines not on this page · raw message
Signature · 1 line
1.9.1
Michael Ellerman
reviewerRe: [PATCH v2 13/17] cxl: Add base builtin support
Quoted 30 lines · Michael Neuling
This also adds the
cxl_ctx_in_use()function for use in the mm code to see if any cxl contexts are currently in use. This is used by thetlbie()to determine if it can do local TLB invalidations or not. This also adds get/put calls for the cxl driver module to refcount the active cxl contexts.drivers/misc/cxl/base.c new file +19
-0@@ -0,0 +1,102 @@ +/* +* Copyright 2014 IBM Corp. +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation; either version +* 2 of the License, or (at your option) any later version. +*/ + +#include <linux/module.h> +#include <linux/rcupdate.h> +#include <asm/errno.h> +#include <misc/cxl.h> +#include "cxl.h" + +/* protected by rcu */ +static struct cxl_calls *cxl_calls; + +static atomic_t use_count =ATOMIC_INIT (0 );
...
Quoted 7 lines
drivers/misc/cxl/base.c new file +7
-0+void cxl_ctx_get (void ) +{ +atomic_inc (&use_count); +} +EXPORT_SYMBOL (cxl_ctx_get); + +void cxl_ctx_put (void )
drivers/misc/cxl/base.c
Quoted 10 lines
drivers/misc/cxl/base.c new file +10
-0+{ +atomic_dec (&use_count); +} +EXPORT_SYMBOL (cxl_ctx_put); + +bool cxl_ctx_in_use (void ) +{ +return (atomic_read (&use_count) !=0 ); +} +EXPORT_SYMBOL (cxl_ctx_in_use);
So as written this results in a function call for every tlbie(), even when no one has ever used a CAPI adapter, or when none are even in the machine.
I think the patch below is a better trade off. It makes the use_count global, but that's not a biggy. The benefit is that the additional code in tlbie() becomes:
ld r10,-29112(r2) lwz r10,0(r10) cmpwi cr7,r10,0
Which is about as good as it can get.
cheers
drivers/misc/cxl/base.c +1 -19
@@ -16,7 +16,7 @@/* protected by rcu */ static struct cxl_calls *cxl_calls; -static atomic_t use_count =ATOMIC_INIT (0 ); +atomic_t cxl_use_count =ATOMIC_INIT (0 );#ifdef CONFIG_CXL_MODULE
@@ -65,24 +65,6 @@ void cxl_slbia(struct mm_struct *mm) }EXPORT_SYMBOL (cxl_slbia); -void cxl_ctx_get (void ) -{ -atomic_inc (&use_count); -} -EXPORT_SYMBOL (cxl_ctx_get); - -void cxl_ctx_put (void ) -{ -atomic_dec (&use_count); -} -EXPORT_SYMBOL (cxl_ctx_put); - -bool cxl_ctx_in_use (void ) -{ -return (atomic_read (&use_count) !=0 ); -} -EXPORT_SYMBOL (cxl_ctx_in_use); -int register_cxl_calls (struct cxl_calls *calls) {if (cxl_calls)
include/misc/cxl.h +15 -3
@@ -18,12 +18,24 @@ struct cxl_irq_ranges { };#ifdef CONFIG_CXL_BASE +extern atomic_t cxl_use_count;void cxl_slbia (struct mm_struct *mm); -void cxl_ctx_get (void ); -void cxl_ctx_put (void ); -bool cxl_ctx_in_use (void ); +static inline bool cxl_ctx_in_use (void ) +{ +return (atomic_read (&cxl_use_count) !=0 ); +} + +static inline void cxl_ctx_get (void ) +{ +atomic_inc (&cxl_use_count); +} + +static inline void cxl_ctx_put (void ) +{ +atomic_dec (&cxl_use_count); +}#else /* CONFIG_CXL_BASE */ #define cxl_slbia (...) do { } while (0)
Re: [PATCH v2 13/17] cxl: Add base builtin support
Quoted 2 lines · Michael Ellerman
Quoted 1 line · Michael Neuling
This also adds the
cxl_ctx_in_use()function for use in the mm code to =
see if
Quoted 2 lines
Quoted 2 lines
any cxl contexts are currently in use. This is used by the
tlbie()to determine if it can do local TLB invalidations or not. This also adds =
get/put
Quoted 40 lines
Quoted 1 line
calls for the cxl driver module to refcount the active cxl contexts.
=20
Quoted 15 lines
drivers/misc/cxl/base.c new file +9
-0@@ -0,0 +1,102 @@ +/* +* Copyright 2014 IBM Corp. +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation; either version +* 2 of the License, or (at your option) any later version. +*/ +drivers/misc/cxl/base.c line 19
Quoted 10 lines
drivers/misc/cxl/base.c new file +10
-0+#include <linux/module.h> +#include <linux/rcupdate.h> +#include <asm/errno.h> +#include <misc/cxl.h> +#include "cxl.h" + +/* protected by rcu */ +static struct cxl_calls *cxl_calls; + +static atomic_t use_count =3D ATOMIC_INIT(0);...
=20Quoted 11 lines
drivers/misc/cxl/base.c new file +11
-0+void cxl_ctx_get (void ) +{ +atomic_inc (&use_count); +} +EXPORT_SYMBOL (cxl_ctx_get); + +void cxl_ctx_put (void ) +{ +atomic_dec (&use_count); +} +EXPORT_SYMBOL (cxl_ctx_put);
Quoted 8 lines
drivers/misc/cxl/base.c line 36
Quoted 6 lines
drivers/misc/cxl/base.c new file +6
-0+ +bool cxl_ctx_in_use (void ) +{ + return (atomic_read(&use_count) !=3D 0); +} +EXPORT_SYMBOL (cxl_ctx_in_use);=20
So as written this results in a function call for everytlbie(), even whe=
n no
Quoted 1 line
one has ever used a CAPI adapter, or when none are even in the machine.
Yep.
Quoted 1 line
I think the patch below is a better trade off. It makes the
use_countglo=
bal,
Quoted 1 line
but that's not a biggy. The benefit is that the additional code in tlbie(=
)
Quoted 7 lines
becomes:
=20ld r10,-29112(r2) lwz r10,0(r10) cmpwi cr7,r10,0=20
Which is about as good as it can get.
Nice.. I'll add. Thanks.
Mikey
Quoted 75 lines
=20
cheers
=20
=20drivers/misc/cxl/base.c +0
-0@@ -16,7 +16,7 @@/* protected by rcu */ static struct cxl_calls *cxl_calls;=20
drivers/misc/cxl/base.c +1
-1-static atomic_t use_count =3D ATOMIC_INIT(0); +atomic_t cxl_use_count =3D ATOMIC_INIT(0);=20
#ifdefCONFIG_CXL_MODULE
=20drivers/misc/cxl/base.c +0
-0@@ -65,24 +65,6 @@ void cxl_slbia(struct mm_struct *mm) }EXPORT_SYMBOL (cxl_slbia);=20
drivers/misc/cxl/base.c +0
-18-void cxl_ctx_get (void ) -{ -atomic_inc (&use_count); -} -EXPORT_SYMBOL (cxl_ctx_get); - -void cxl_ctx_put (void ) -{ -atomic_dec (&use_count); -} -EXPORT_SYMBOL (cxl_ctx_put); - -bool cxl_ctx_in_use (void ) -{ - return (atomic_read(&use_count) !=3D 0); -} -EXPORT_SYMBOL (cxl_ctx_in_use); -int register_cxl_calls (struct cxl_calls *calls) {if (cxl_calls)include/misc/cxl.h +0
-0@@ -18,12 +18,24 @@ struct cxl_irq_ranges { };=20
#ifdefCONFIG_CXL_BASE
+externatomic_tcxl_use_count;
=20
voidcxl_slbia(struct mm_struct *mm);include/misc/cxl.h +0
-3-void cxl_ctx_get (void ); -void cxl_ctx_put (void ); -bool cxl_ctx_in_use (void );=20
include/misc/cxl.h +14
-0+static inline bool cxl_ctx_in_use (void ) +{ + return (atomic_read(&cxl_use_count) !=3D 0); +} + +static inline void cxl_ctx_get (void ) +{ +atomic_inc (&cxl_use_count); +} + +static inline void cxl_ctx_put (void ) +{ +atomic_dec (&cxl_use_count); +}#else /* CONFIG_CXL_BASE */ =20
#definecxl_slbia(...)do { } while (0)
=20
PATCH v2 14/17 cxl: Driver code for powernv PCIe based cards for userspace access
In reply to Michael NeulingFrom: Ian Munsie <[email protected]>
This is the core of the cxl driver.
It adds support for using cxl cards in the powernv environment only (no guest support). It allows access to cxl accelerators by userspace using /dev/cxl/afu0.0 char device.
The kernel driver has no knowledge of the acceleration function. It only provides services to userspace via the /dev/cxl/afu0.0 device.
This will compile to two modules. cxl.ko provides the core cxl functionality and userspace API. cxl-pci.ko provides the PCI driver driver functionality the powernv environment.
Documentation of the cxl hardware architecture and userspace API is provided in subsequent patches.
--- drivers/misc/cxl/context.c | 171 ++++++++ drivers/misc/cxl/cxl-pci.c | 964 +++++++++++++++++++++++++++++++++++++++++++++ drivers/misc/cxl/cxl.h | 605 ++++++++++++++++++++++++++++ drivers/misc/cxl/debugfs.c | 116 ++++++ drivers/misc/cxl/fault.c | 298 ++++++++++++++ drivers/misc/cxl/file.c | 503 +++++++++++++++++++++++ drivers/misc/cxl/irq.c | 405 +++++++++++++++++++ drivers/misc/cxl/main.c | 238 +++++++++++ drivers/misc/cxl/native.c | 649 ++++++++++++++++++++++++++++++ drivers/misc/cxl/sysfs.c | 348 ++++++++++++++++ 10 files changed, 4297 insertions(+) create mode 100644 drivers/misc/cxl/context.c create mode 100644 drivers/misc/cxl/cxl-pci.c create mode 100644 drivers/misc/cxl/cxl.h create mode 100644 drivers/misc/cxl/debugfs.c create mode 100644 drivers/misc/cxl/fault.c create mode 100644 drivers/misc/cxl/file.c create mode 100644 drivers/misc/cxl/irq.c create mode 100644 drivers/misc/cxl/main.c create mode 100644 drivers/misc/cxl/native.c create mode 100644 drivers/misc/cxl/sysfs.c
drivers/misc/cxl/context.c new file +171 -0
@@ -0,0 +1,171 @@ +/* +* Copyright 2014 IBM Corp. +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation; either version +* 2 of the License, or (at your option) any later version. +*/ + +#undef DEBUG + +#include <linux/module.h> +#include <linux/kernel.h> +#include <linux/bitmap.h> +#include <linux/sched.h> +#include <linux/pid.h> +#include <linux/fs.h> +#include <linux/mm.h> +#include <linux/debugfs.h> +#include <linux/slab.h> +#include <linux/idr.h> +#include <asm/cputable.h> +#include <asm/current.h> +#include <asm/copro.h> + +#include "cxl.h" + +/* +* Allocates space for a CXL context. +*/ +struct cxl_context_t *cxl_context_alloc (void ) +{ +return kzalloc (sizeof (struct cxl_context_t ),GFP_KERNEL ); +} + +/* +* Initialises a CXL context. +*/ +int cxl_context_init (struct cxl_context_t *ctx,struct cxl_afu_t *afu,bool master) +{ +int i; + +spin_lock_init (&ctx->sst_lock); + ctx->sstp =NULL ; + ctx->afu = afu; + ctx->master = master; + ctx->pid =get_pid (get_task_pid (current,PIDTYPE_PID )); + +INIT_WORK (&ctx->fault_work, cxl_handle_fault); + +init_waitqueue_head (&ctx->wq); +spin_lock_init (&ctx->lock); + + ctx->irq_bitmap =NULL ; + ctx->pending_irq = false; + ctx->pending_fault = false; + ctx->pending_afu_err = false; + + ctx->status =OPENED ; + +idr_preload (GFP_KERNEL ); +spin_lock (&afu->contexts_lock); + i =idr_alloc (&ctx->afu->contexts_idr, ctx,0 , + ctx->afu->num_procs,GFP_NOWAIT ); +spin_unlock (&afu->contexts_lock); +idr_preload_end (); +if (i <0 ) +return i; + + ctx->ph = i; + ctx->elem = &ctx->afu->spa[i]; + ctx->pe_inserted = false; +return 0 ; +} + +/* +* Map a per-context mmio space into the given vma. +*/ +int cxl_context_iomap (struct cxl_context_t *ctx,struct vm_area_struct *vma) +{ +u64 len = vma->vm_end - vma->vm_start; + len =min (len, ctx->psn_size); + +if (ctx->afu->current_model ==CXL_MODEL_DEDICATED ) { + vma->vm_page_prot =pgprot_noncached (vma->vm_page_prot); +return vm_iomap_memory (vma, ctx->afu->psn_phys, ctx->afu->adapter->ps_size); + } + +/* make sure there is a valid per process space for this AFU */ +if ((ctx->master && !ctx->afu->psa) || (!ctx->afu->pp_psa)) { +pr_devel ("AFU doesn't support mmio space\n" ); +return -EINVAL ; + } + +/* Can't mmap until the AFU is enabled */ +if (!ctx->afu->enabled) +return -EBUSY ; + +pr_devel ("%s: mmio physical: %llx pe: %i master:%i\n" , __func__, + ctx->psn_phys, ctx->ph , ctx->master); + + vma->vm_page_prot =pgprot_noncached (vma->vm_page_prot); +return vm_iomap_memory (vma, ctx->psn_phys, len); +} + +/* +* Detach a context from the hardware. This disables interrupts and doesn't +* return until all outstanding interrupts for this context have completed. The +* hardware should no longer access *ctx after this has returned. +*/ +static void __detach_context (struct cxl_context_t *ctx) +{ +unsigned long flags; +enum cxl_context_status status; + +spin_lock_irqsave (&ctx->sst_lock, flags); + status = ctx->status; + ctx->status =CLOSED ; +spin_unlock_irqrestore (&ctx->sst_lock, flags); +if (status !=STARTED ) +return ; + +WARN_ON (cxl_ops->detach_process (ctx)); +afu_release_irqs (ctx); +flush_work (&ctx->fault_work);/* Only needed for dedicated process */ +wake_up_all (&ctx->wq); +} + +/* +* Detach the given context from the AFU. This doesn't actually +* free the context but it should stop the context running in hardware +* (ie. prevent this context from generating any further interrupts +* so that it can be freed). +*/ +void cxl_context_detach (struct cxl_context_t *ctx) +{ +__detach_context (ctx); +} + +/* +* Detach all contexts on the given AFU. +*/ +void cxl_context_detach_all (struct cxl_afu_t *afu) +{ +struct cxl_context_t *ctx; +int tmp; + +rcu_read_lock (); +idr_for_each_entry (&afu->contexts_idr, ctx, tmp) +__detach_context (ctx); +rcu_read_unlock (); +} +EXPORT_SYMBOL (cxl_context_detach_all); + +void cxl_context_free (struct cxl_context_t *ctx) +{ +unsigned long flags; + +spin_lock (&ctx->afu->contexts_lock); +idr_remove (&ctx->afu->contexts_idr, ctx->ph); +spin_unlock (&ctx->afu->contexts_lock); +synchronize_rcu (); + +spin_lock_irqsave (&ctx->sst_lock, flags); +free_page ((u64 )ctx->sstp); + ctx->sstp =NULL ; +spin_unlock_irqrestore (&ctx->sst_lock, flags); + +put_pid (ctx->pid); +kfree (ctx); +}
drivers/misc/cxl/cxl-pci.c new file +964 -0
964 lines not on this page · raw message
drivers/misc/cxl/cxl.h new file +605 -0
605 lines not on this page · raw message
drivers/misc/cxl/debugfs.c new file +116 -0
116 lines not on this page · raw message
drivers/misc/cxl/fault.c new file +298 -0
298 lines not on this page · raw message
drivers/misc/cxl/file.c new file +503 -0
503 lines not on this page · raw message
drivers/misc/cxl/irq.c new file +405 -0
343 lines not on this page · raw message
drivers/misc/cxl/main.c new file +238 -0
238 lines not on this page · raw message
drivers/misc/cxl/native.c new file +649 -0
649 lines not on this page · raw message
drivers/misc/cxl/sysfs.c new file +348 -0
348 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
1.9.1
Part of the diff is not shown here. View the raw message.
Michael Ellerman
reviewerRe: [PATCH v2 14/17] cxl: Driver code for powernv PCIe based cards for userspace access
Quoted 6 lines · Michael Neuling
From: Ian Munsie <[email protected]>
This is the core of the cxl driver.
It adds support for using cxl cards in the powernv environment only (no guest support).
Which means on bare metal on power8 for the peanut gallery.
Quoted 2 lines
It allows access to cxl accelerators by userspace using
/dev/cxl/afu0.0char device.
devices ?
Quoted 1 line
The kernel driver has no knowledge of the acceleration function.
.. has no knowledge of the function implemented by the accelerator ?
Quoted 1 line
It only provides services to userspace via the
/dev/cxl/afu0.0device.
Provides what services?
Quoted 3 lines
This will compile to two modules. cxl.ko provides the core cxl functionality and userspace API. cxl-pci.ko provides the PCI driver driver functionality the powernv environment.
Last sentence doesn't hold together.
Quoted 2 lines
Documentation of the cxl hardware architecture and userspace API is provided in subsequent patches.
Partial review below.
So some meta comments.
Can you get rid of all the foo_t's. That should just be a search and replace.
Can we drop the indirection layers for now. They make it quite a bit harder to follow the code, and it sounds like you're not 100% sure they're the right abstraction anyway. When you add another backend/driver/whatever you can readd just the abstractions you need.
/*
* Block comments look like this.
*/
Quoted 6 lines
drivers/misc/cxl/context.c new file +0
-0
drivers/misc/cxl/context.c line 10
Quoted 10 lines
drivers/misc/cxl/context.c new file +10
-0@@ -0,0 +1,171 @@ +/* +* Copyright 2014 IBM Corp. +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation; either version +* 2 of the License, or (at your option) any later version. +*/ + +#undef DEBUG
Drop this please.
Instead can you add:
#define pr_fmt(fmt) "cxl: " fmt
To each file, so it's clear where your pr_xxxs() come from.
Quoted 65 lines
drivers/misc/cxl/context.c new file +64
-0+#include <linux/module.h> +#include <linux/kernel.h> +#include <linux/bitmap.h> +#include <linux/sched.h> +#include <linux/pid.h> +#include <linux/fs.h> +#include <linux/mm.h> +#include <linux/debugfs.h> +#include <linux/slab.h> +#include <linux/idr.h> +#include <asm/cputable.h> +#include <asm/current.h> +#include <asm/copro.h> + +#include "cxl.h" + +/* +* Allocates space for a CXL context. +*/ +struct cxl_context_t *cxl_context_alloc (void ) +{ +return kzalloc (sizeof (struct cxl_context_t ),GFP_KERNEL ); +} +/* +* Initialises a CXL context. +*/ +int cxl_context_init (struct cxl_context_t *ctx,struct cxl_afu_t *afu,bool master) +{ +int i; + +spin_lock_init (&ctx->sst_lock); + ctx->sstp =NULL ; + ctx->afu = afu; + ctx->master = master; + ctx->pid =get_pid (get_task_pid (current,PIDTYPE_PID )); + +INIT_WORK (&ctx->fault_work, cxl_handle_fault); + +init_waitqueue_head (&ctx->wq); +spin_lock_init (&ctx->lock); + + ctx->irq_bitmap =NULL ; + ctx->pending_irq = false; + ctx->pending_fault = false; + ctx->pending_afu_err = false; + + ctx->status =OPENED ; + +idr_preload (GFP_KERNEL ); +spin_lock (&afu->contexts_lock); + i =idr_alloc (&ctx->afu->contexts_idr, ctx,0 , + ctx->afu->num_procs,GFP_NOWAIT ); +spin_unlock (&afu->contexts_lock); +idr_preload_end (); +if (i <0 ) +return i; + + ctx->ph = i; + ctx->elem = &ctx->afu->spa[i]; + ctx->pe_inserted = false; +return 0 ; +} + +/*
drivers/misc/cxl/context.c line 86
Quoted 10 lines
drivers/misc/cxl/context.c new file +10
-0+* Map a per-context mmio space into the given vma. +*/ +int cxl_context_iomap (struct cxl_context_t *ctx,struct vm_area_struct *vma) +{ +u64 len = vma->vm_end - vma->vm_start; + len =min (len, ctx->psn_size); + +if (ctx->afu->current_model ==CXL_MODEL_DEDICATED ) { + vma->vm_page_prot =pgprot_noncached (vma->vm_page_prot); +return vm_iomap_memory (vma, ctx->afu->psn_phys, ctx->afu->adapter->ps_size);
Why don't we use len here?
drivers/misc/cxl/context.c line 90
Quoted 4 lines
drivers/misc/cxl/context.c new file +4
-0+ } + +/* make sure there is a valid per process space for this AFU */ +if ((ctx->master && !ctx->afu->psa) || (!ctx->afu->pp_psa)) {
What the hell are psa and pp_psa ?
drivers/misc/cxl/context.c line 97
Quoted 7 lines
drivers/misc/cxl/context.c new file +7
-0+pr_devel ("AFU doesn't support mmio space\n" ); +return -EINVAL ; + } + +/* Can't mmap until the AFU is enabled */ +if (!ctx->afu->enabled) +return -EBUSY ;
afu_mmap() already checked status == STARTED.
Is EBUSY the right return code?
Quoted 11 lines
drivers/misc/cxl/context.c new file +11
-0+pr_devel ("%s: mmio physical: %llx pe: %i master:%i\n" , __func__, + ctx->psn_phys, ctx->ph , ctx->master); + + vma->vm_page_prot =pgprot_noncached (vma->vm_page_prot); +return vm_iomap_memory (vma, ctx->psn_phys, len); +} + +/* +* Detach a context from the hardware. This disables interrupts and doesn't +* return until all outstanding interrupts for this context have completed. The +* hardware should no longer access *ctx after this has returned.
drivers/misc/cxl/context.c line 119
Quoted 10 lines
drivers/misc/cxl/context.c new file +10
-0+*/ +static void __detach_context (struct cxl_context_t *ctx) +{ +unsigned long flags; +enum cxl_context_status status; + +spin_lock_irqsave (&ctx->sst_lock, flags); + status = ctx->status; + ctx->status =CLOSED ; +spin_unlock_irqrestore (&ctx->sst_lock, flags);
You take sst_lock here, before manipulating ctx->status. But I see lots of places where you check status without taking any lock. So I'm a bit confused by that.
At first glance it looks like we could race with afu_ioctl_start_work(), which sets status to STARTED. But the only place we're called from is cxl_context_detach(), from afu_release(), and that should only run once the ioctl is finished AIUI. So that looks OK.
But some commentary would be good, especially if this is ever called via a different path.
drivers/misc/cxl/context.c line 123
Quoted 4 lines
drivers/misc/cxl/context.c new file +4
-0+if (status !=STARTED ) +return ; + +WARN_ON (cxl_ops->detach_process (ctx));
As discussed offline, this can fail, and the device might continue generating interrupts even though we asked it not to.
Once you release the irqs below you'll get warnings from the xics code. Until those virq numbers are handed out to someone else, at which point hilarity will ensue.
It might be better to just warn and bail if detach fails, and leave the ctx lying around?
Quoted 5 lines
drivers/misc/cxl/context.c new file +5
-0+afu_release_irqs (ctx); +flush_work (&ctx->fault_work);/* Only needed for dedicated process */ +wake_up_all (&ctx->wq); +} +
drivers/misc/cxl/context.c line 138
Quoted 10 lines
drivers/misc/cxl/context.c new file +10
-0+/* +* Detach the given context from the AFU. This doesn't actually +* free the context but it should stop the context running in hardware +* (ie. prevent this context from generating any further interrupts +* so that it can be freed). +*/ +void cxl_context_detach (struct cxl_context_t *ctx) +{ +__detach_context (ctx); +}
Why does this exist, or why does __detach_context() exist?
drivers/misc/cxl/context.c line 147
Quoted 9 lines
drivers/misc/cxl/context.c new file +9
-0+ +/* +* Detach all contexts on the given AFU. +*/ +void cxl_context_detach_all (struct cxl_afu_t *afu) +{ +struct cxl_context_t *ctx; +int tmp; +
Some commentary on why you're using rcu_read_lock() would be good. I know, but I'll have forgotten by next week.
Quoted 7 lines
drivers/misc/cxl/context.c new file +6
-0+rcu_read_lock (); +idr_for_each_entry (&afu->contexts_idr, ctx, tmp) +__detach_context (ctx); +rcu_read_unlock (); +} +EXPORT_SYMBOL (cxl_context_detach_all);
drivers/misc/cxl/context.c
Quoted 10 lines
drivers/misc/cxl/context.c new file +9
-0+static int afu_release (struct inode *inode,struct file *file) +{ +struct cxl_context_t *ctx = file->private_data; + +pr_devel ("%s: closing cxl file descriptor. pe: %i\n" , + __func__, ctx->ph); +cxl_context_detach (ctx); + +module_put (ctx->afu->adapter->driver->module);
This potentially drops the last reference on cxl-pci.ko.
cxl_remove() (in cxl-pci.ko) calls back into cxl_remove_afu() and cxl_remove_adapter().
I *think* that's OK, because you won't be able to finish cxl_remove() until you remove the afu cdev, and presumably that can't happen until you return from release.
drivers/misc/cxl/context.c
Quoted 4 lines
drivers/misc/cxl/context.c new file +4
-0+put_device (&ctx->afu->dev); + +/* It should be safe to remove the context now */ +cxl_context_free (ctx);
My other worry is that it's not until here that you remove the ctx from the idr. And so up until this point the ctx could be found in the idr and used by someone.
I think it would be better to remove the ctx from the idr earlier, before you start tearing things down. Perhaps even in cxl_context_detach().
Quoted 6 lines
drivers/misc/cxl/context.c new file +4
-0+cxl_ctx_put (); +return 0 ; +} +static ssize_t afu_read(struct file *file, char __user *buf, size_t count,
drivers/misc/cxl/context.c
Quoted 10 lines
drivers/misc/cxl/context.c new file +10
-0+ loff_t *off) +{ +struct cxl_context_t *ctx = file->private_data; +struct cxl_event event; +unsigned long flags; +ssize_t size; +DEFINE_WAIT (wait); + +if (count <sizeof (struct cxl_event_header )) +return -EINVAL ;
This could use some love. The locking in here is pretty funky, and not good funky.
Quoted 75 lines
drivers/misc/cxl/context.c new file +69
-0+while (1 ) { +spin_lock_irqsave (&ctx->lock, flags); +if (ctx->pending_irq || ctx->pending_fault || + ctx->pending_afu_err || (ctx->status ==CLOSED )) +break ; +spin_unlock_irqrestore (&ctx->lock, flags); + +if (file->f_flags &O_NONBLOCK ) +return -EAGAIN ; + +prepare_to_wait (&ctx->wq, &wait,TASK_INTERRUPTIBLE ); +if (!(ctx->pending_irq || ctx->pending_fault || + ctx->pending_afu_err || (ctx->status ==CLOSED ))) { +pr_devel ("afu_read going to sleep...\n" ); +schedule (); +pr_devel ("afu_read woken up\n" ); + } +finish_wait (&ctx->wq, &wait); + +if (signal_pending (current)) +return -ERESTARTSYS ; + } + +memset (&event,0 ,sizeof (event)); + event.header.process_element = ctx->ph; +if (ctx->pending_irq) { +pr_devel ("afu_read delivering AFU interrupt\n" ); + event.header.size =sizeof (struct cxl_event_afu_interrupt ); + event.header.type =CXL_EVENT_AFU_INTERRUPT ; + event.irq.irq =find_first_bit (ctx->irq_bitmap, ctx->irq_count) +1 ; + +/* Only clear the IRQ if we can send the whole event: */ +if (count >= event.header.size) { +clear_bit (event.irq.irq -1 , ctx->irq_bitmap); +if (bitmap_empty (ctx->irq_bitmap, ctx->irq_count)) + ctx->pending_irq = false; + } + }else if (ctx->pending_fault) { +pr_devel ("afu_read delivering data storage fault\n" ); + event.header.size =sizeof (struct cxl_event_data_storage ); + event.header.type =CXL_EVENT_DATA_STORAGE ; + event.fault.addr = ctx->fault_addr; + +/* Only clear the fault if we can send the whole event: */ +if (count >= event.header.size) + ctx->pending_fault = false; + }else if (ctx->pending_afu_err) { +pr_devel ("afu_read delivering afu error\n" ); + event.header.size =sizeof (struct cxl_event_afu_error ); + event.header.type =CXL_EVENT_AFU_ERROR ; + event.afu_err.err = ctx->afu_err; + +/* Only clear the fault if we can send the whole event: */ +if (count >= event.header.size) + ctx->pending_afu_err = false; + }else if (ctx->status ==CLOSED ) { +pr_devel ("afu_read fatal error\n" ); +spin_unlock_irqrestore (&ctx->lock, flags); +return -EIO ; + }else +WARN (1 ,"afu_read must be buggy\n" ); + +spin_unlock_irqrestore (&ctx->lock, flags); + + size =min_t (size_t, count, event.header.size); +copy_to_user (buf, &event, size); + +return size; +}drivers/misc/cxl/irq.c new file +0
-0
...
Quoted 7 lines
drivers/misc/cxl/irq.c new file +7
-0+ +void afu_release_irqs (struct cxl_context_t *ctx) +{ +irq_hw_number_t hwirq; +unsigned int virq; +int r, i; +
drivers/misc/cxl/irq.c line 404
Quoted 10 lines
drivers/misc/cxl/irq.c new file +10
-0+for (r =1 ; r <CXL_IRQ_RANGES ; r++) { + hwirq = ctx->irqs.offset[r]; +for (i =0 ; i < ctx->irqs.range[r]; hwirq++, i++) { + virq =irq_find_mapping (NULL , hwirq); +if (virq) +cxl_unmap_irq (virq, ctx); + } + } + + ctx->afu->adapter->driver->release_irq_ranges (&ctx->irqs, ctx->afu->adapter);
Do we need this many levels of indirection?
cheers
PATCH v2 15/17 cxl: Userspace header file.
In reply to Michael NeulingFrom: Ian Munsie <[email protected]>
This defines structs and magic numbers required for userspace to interact with the kernel cxl driver via /dev/cxl/afu0.0.
It adds this header file Kbuild so it's exported when doing make headers_installs.
--- include/uapi/Kbuild | 1 + include/uapi/misc/Kbuild | 2 ++ include/uapi/misc/cxl.h | 88 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 91 insertions(+) create mode 100644 include/uapi/misc/Kbuild create mode 100644 include/uapi/misc/cxl.h
include/uapi/Kbuild +1 -0
@@ -12,3 +12,4 @@ header-y += video/ header-y += drm/ header-y += xen/ header-y += scsi/ +header-y += misc/
include/uapi/misc/Kbuild new file +2 -0
@@ -0,0 +1,2 @@ +# misc Header export list +header-y += cxl.h
include/uapi/misc/cxl.h new file +88 -0
88 lines not on this page · raw message
Signature · 1 line
1.9.1
Michael Ellerman
reviewerRe: [PATCH v2 15/17] cxl: Userspace header file.
Quoted 28 lines · Michael Neuling
From: Ian Munsie <[email protected]>
This defines structs and magic numbers required for userspace to interact with the kernel cxl driver via
/dev/cxl/afu0.0.include/uapi/misc/cxl.h new file +17
-0@@ -0,0 +1,88 @@ +/* +* Copyright 2014 IBM Corp. +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation; either version +* 2 of the License, or (at your option) any later version. +*/ + +#ifndef _UAPI_ASM_CXL_H +#define _UAPI_ASM_CXL_H + +#include <linux/types.h> +#include <linux/ioctl.h> + +/* ioctls */ +struct cxl_ioctl_start_work {
include/uapi/misc/cxl.h line 27
Quoted 10 lines
include/uapi/misc/cxl.h new file +10
-0+__u64 wed; +__u64 amr; +__u64 reserved1; +__u32 reserved2; +__s16 num_interrupts;/* -1 = use value from afu descriptor */ +__u16 process_element;/* returned from kernel */ +__u64 reserved3; +__u64 reserved4; +__u64 reserved5; +__u64 reserved6;
Why so many reserved fields?
What mechanism is there that will allow you to ever unreserve them?
ie. how does a new userspace detect that the kernel it's running on supports new fields?
Or conversely how does a new kernel detect that userspace has passed it a meaningful value in one of the previously reserved fields?
include/uapi/misc/cxl.h line 31
Quoted 2 lines
include/uapi/misc/cxl.h new file +2
-0+#define CXL_MAGIC 0xCA +#define CXL_IOCTL_START_WORK _IOWR(CXL_MAGIC, 0x00, struct cxl_ioctl_start_work)
What happened to 0x1 ?
include/uapi/misc/cxl.h line 37
Quoted 6 lines
include/uapi/misc/cxl.h new file +6
-0+#define CXL_IOCTL_CHECK_ERROR _IO(CXL_MAGIC, 0x02) + +/* events from read() */ + +enum cxl_event_type { +CXL_EVENT_READ_FAIL =-1 ,
I don't see this used?
Quoted 4 lines
include/uapi/misc/cxl.h new file +4
-0+CXL_EVENT_RESERVED =0 , +CXL_EVENT_AFU_INTERRUPT =1 , +CXL_EVENT_DATA_STORAGE =2 , + CXL_EVENT_AFU_ERROR = 3,
include/uapi/misc/cxl.h line 51
Quoted 10 lines
include/uapi/misc/cxl.h new file +10
-0+}; + +struct cxl_event_header { +__u32 type; +__u16 size; +__u16 process_element; +__u64 reserved1; +__u64 reserved2; +__u64 reserved3; +};
Again lots of reserved fields?
Quoted 24 lines
include/uapi/misc/cxl.h new file +24
-0+struct cxl_event_afu_interrupt { +struct cxl_event_header header; +__u16 irq;/* Raised AFU interrupt number */ +__u16 reserved1; +__u32 reserved2; +__u64 reserved3; +__u64 reserved4; +__u64 reserved5; +}; + +struct cxl_event_data_storage { +struct cxl_event_header header; +__u64 addr; +__u64 reserved1; +__u64 reserved2; +__u64 reserved3; +}; + +struct cxl_event_afu_error { +struct cxl_event_header header; +__u64 err; +__u64 reserved1; +__u64 reserved2; +__u64 reserved3;
include/uapi/misc/cxl.h line 86
Quoted 10 lines
include/uapi/misc/cxl.h new file +10
-0+}; + +struct cxl_event { +union { +struct cxl_event_header header; +struct cxl_event_afu_interrupt irq; +struct cxl_event_data_storage fault; +struct cxl_event_afu_error afu_err; + }; +};
Rather than having the header included in every event, would it be clearer if the cxl_event was:
struct cxl_event {
struct cxl_event_header header;
union {
struct cxl_event_afu_interrupt irq;
struct cxl_event_data_storage fault;
struct cxl_event_afu_error afu_err;
};
};cheers
Re: [PATCH v2 15/17] cxl: Userspace header file.
Hey Michael,
Excerpts from Michael Ellerman's message of 2014-10-02 16:02:37 +1000:
Quoted 6 lines
Quoted 6 lines
include/uapi/misc/cxl.h new file +6
-0+/* ioctls */ +struct cxl_ioctl_start_work { +__u64 wed; +__u64 amr; +__u64 reserved1; +__u32 reserved2;
Quoted 8 lines
include/uapi/misc/cxl.h line 27
Quoted 6 lines
include/uapi/misc/cxl.h new file +6
-0+__s16 num_interrupts;/* -1 = use value from afu descriptor */ +__u16 process_element;/* returned from kernel */ +__u64 reserved3; +__u64 reserved4; +__u64 reserved5; +__u64 reserved6;Why so many reserved fields?
The first two are reserved for the context save area (reserved1) and size (reserved2) of the "shared" (AKA time sliced) virtualisation model, which we don't yet support. That only leaves us with four reserved fields for anything that we haven't thought of or that the hardware team hasn't come up with yet ;-)
Quoted 4 lines
What mechanism is there that will allow you to ever unreserve them?
ie. how does a new userspace detect that the kernel it's running on supports new fields?
The ioctl will return -EINVAL if any of them are set to non-zero values, so userspace can easily tell if it's running on an old kernel.
Quoted 2 lines
Or conversely how does a new kernel detect that userspace has passed it a meaningful value in one of the previously reserved fields?
They would have to be non-zero (certainly true of the context save area's size), or one could turn into a flags field or api version.
Quoted 4 lines
include/uapi/misc/cxl.h line 31
Quoted 2 lines
include/uapi/misc/cxl.h new file +2
-0+#define CXL_MAGIC 0xCA +#define CXL_IOCTL_START_WORK _IOWR(CXL_MAGIC, 0x00, struct cxl_ioctl_start_work)What happened to
0x1?
That was used to dynamically program the FPGA with a new AFU image, but we don't have anything to test it on yet and I'm not convinced that the procedure won't change by the time we do, so we pulled the code.
We can repack the ioctl numbers easily enough... Will do :)
Quoted 4 lines
include/uapi/misc/cxl.h line 37
Quoted 2 lines
include/uapi/misc/cxl.h new file +2
-0+enum cxl_event_type { +CXL_EVENT_READ_FAIL =-1 ,I don't see this used?
That was used in the userspace library to mark it's buffer as bad if the read() call failed for whatever reason... but you're right - it isn't used by the kernel and doesn't belong in this header. Will remove.
Quoted 10 lines
include/uapi/misc/cxl.h line 51
Quoted 8 lines
include/uapi/misc/cxl.h new file +8
-0+struct cxl_event_header { +__u32 type; +__u16 size; +__u16 process_element; +__u64 reserved1; +__u64 reserved2; +__u64 reserved3; +};Again lots of reserved fields?
Figured it was better to have a bit more than we expect we might need just in case... We can reduce this if you feel it is excessive?
In an earlier version of the code the kernel would fill out the header and not clear an event if a buffer was passed in that was too small, so userspace could realloc a larger buffer and try again. This made the API a bit more complex and our internal users weren't too keen on it, so we decided to use a fixed-size buffer and make it larger than we strictly needed so we have plenty of room for further expansion.
Quoted 11 lines
Rather than having the header included in every event, would it be clearer if the
cxl_eventwas:struct cxl_event { struct cxl_event_header header; union { struct cxl_event_afu_interrupt irq; struct cxl_event_data_storage fault; struct cxl_event_afu_error afu_err; }; };
Sounds like a good idea to me :)
Cheers,
-Ian
Re: [PATCH v2 15/17] cxl: Userspace header file.
Quoted 24 lines · Ian Munsie
Hey Michael,
Excerpts from Michael Ellerman's message of 2014-10-02 16:02:37 +1000:
Quoted 6 lines
Quoted 6 lines
include/uapi/misc/cxl.h new file +6
-0+/* ioctls */ +struct cxl_ioctl_start_work { +__u64 wed; +__u64 amr; +__u64 reserved1; +__u32 reserved2;Quoted 8 lines
include/uapi/misc/cxl.h line 27
Quoted 6 lines
include/uapi/misc/cxl.h new file +6
-0+__s16 num_interrupts;/* -1 = use value from afu descriptor */ +__u16 process_element;/* returned from kernel */ +__u64 reserved3; +__u64 reserved4; +__u64 reserved5; +__u64 reserved6;Why so many reserved fields?
The first two are reserved for the context save area (reserved1) and size (reserved2) of the "shared" (AKA time sliced) virtualisation model, which we don't yet support. That only leaves us with four reserved fields for anything that we haven't thought of or that the hardware team hasn't come up with yet ;-)
Quoted 7 lines
Quoted 4 lines
What mechanism is there that will allow you to ever unreserve them?
ie. how does a new userspace detect that the kernel it's running on supports new fields?
The ioctl will return
-EINVALif any of them are set to non-zero values, so userspace can easily tell if it's running on an old kernel.
Not good enough in my experience. Throw in a flags field I'd say..
Quoted 5 lines
Quoted 2 lines
Or conversely how does a new kernel detect that userspace has passed it a meaningful value in one of the previously reserved fields?
They would have to be non-zero (certainly true of the context save area's size), or one could turn into a flags field or api version.
If you go that way you need to negociate as well latest compatible etc...
Quoted 57 lines
Quoted 4 lines
include/uapi/misc/cxl.h line 31
Quoted 2 lines
include/uapi/misc/cxl.h new file +2
-0+#define CXL_MAGIC 0xCA +#define CXL_IOCTL_START_WORK _IOWR(CXL_MAGIC, 0x00, struct cxl_ioctl_start_work)What happened to
0x1?That was used to dynamically program the FPGA with a new AFU image, but we don't have anything to test it on yet and I'm not convinced that the procedure won't change by the time we do, so we pulled the code.
We can repack the ioctl numbers easily enough... Will do :)
Quoted 4 lines
include/uapi/misc/cxl.h line 37
Quoted 2 lines
include/uapi/misc/cxl.h new file +2
-0+enum cxl_event_type { +CXL_EVENT_READ_FAIL =-1 ,I don't see this used?
That was used in the userspace library to mark it's buffer as bad if the
read()call failed for whatever reason... but you're right - it isn't used by the kernel and doesn't belong in this header. Will remove.Quoted 10 lines
include/uapi/misc/cxl.h line 51
Quoted 8 lines
include/uapi/misc/cxl.h new file +8
-0+struct cxl_event_header { +__u32 type; +__u16 size; +__u16 process_element; +__u64 reserved1; +__u64 reserved2; +__u64 reserved3; +};Again lots of reserved fields?
Figured it was better to have a bit more than we expect we might need just in case... We can reduce this if you feel it is excessive?
In an earlier version of the code the kernel would fill out the header and not clear an event if a buffer was passed in that was too small, so userspace could realloc a larger buffer and try again. This made the API a bit more complex and our internal users weren't too keen on it, so we decided to use a fixed-size buffer and make it larger than we strictly needed so we have plenty of room for further expansion.
Quoted 11 lines
Rather than having the header included in every event, would it be clearer if the
cxl_eventwas:struct cxl_event { struct cxl_event_header header; union { struct cxl_event_afu_interrupt irq; struct cxl_event_data_storage fault; struct cxl_event_afu_error afu_err; }; };Sounds like a good idea to me :)
Cheers,
-Ian
PATCH v2 16/17 cxl: Add driver to Kbuild and Makefiles
In reply to Michael NeulingFrom: Ian Munsie <[email protected]>
--- drivers/misc/cxl/Kconfig | 18 ++++++++++++++++++ drivers/misc/cxl/Makefile | 3 +++ 2 files changed, 21 insertions(+)
drivers/misc/cxl/Kconfig +18 -0
@@ -6,3 +6,21 @@ config CXL_BASE bool default n select PPC_COPRO_BASE + +config CXL + tristate "Support for IBM Coherent Accelerators (CXL)" + depends on PPC_POWERNV && PCI_MSI + select CXL_BASE + default m + help + Select this option to enable userspace driver support for IBM + Coherent Accelerators (CXL). CXL is otherwise known as Coherent + Accelerator Processor Interface (CAPI). + +config CXL_PCI + tristate "Support for CXL devices via PCI" + depends on CXL && PPC_POWERNV + default y + help + Select this option to support CXL devices detected via PCI, e.g. + when running under powernv/OPAL.
drivers/misc/cxl/Makefile +3 -0
@@ -1 +1,4 @@ +cxl-y += main.o file.o irq.o fault.o native.o context.o sysfs.o debugfs.o +obj-$(CONFIG_CXL) += cxl.o +obj-$(CONFIG_CXL_PCI) += cxl-pci.o obj-$(CONFIG_CXL_BASE) += base.o
Signature · 1 line
1.9.1
PATCH v2 17/17 cxl: Add documentation for userspace APIs
In reply to Michael NeulingFrom: Ian Munsie <[email protected]>
This documentation gives an overview of the hardware architecture, userspace APIs via /dev/cxl/afu0.0 and the syfs files. It also adds a MAINTAINERS file entry for cxl.
--- Documentation/ABI/testing/sysfs-class-cxl | 125 ++++++++++++ Documentation/ioctl/ioctl-number.txt | 1 + Documentation/powerpc/00-INDEX | 2 + Documentation/powerpc/cxl.txt | 310 ++++++++++++++++++++++++++++++ MAINTAINERS | 7 + 5 files changed, 445 insertions(+) create mode 100644 Documentation/ABI/testing/sysfs-class-cxl create mode 100644 Documentation/powerpc/cxl.txt
Documentation/ABI/testing/sysfs-class-cxl new file +125 -0
@@ -0,0 +1,125 @@ +Slave contexts (eg. /sys/class/cxl/afu0.0): + +What: /sys/class/cxl/<afu>/irqs_max +Date: September 2014 +Contact: Ian Munsie <[email protected]>, + Michael Neuling <[email protected]> +Description: read/write + Maximum number of interrupts that can be requested by userspace. + The default on probe is the maximum that hardware can support + (eg. 2037). Write values will limit userspace applications to + that many userspace interrupts. Must be >= irqs_min. + +What: /sys/class/cxl/<afu>/irqs_min +Date: September 2014 +Contact: Ian Munsie <[email protected]>, + Michael Neuling <[email protected]> +Description: read_only + The minimum number of interrupts that userspace must request + on a CXL_START_WORK ioctl. Userspace may request -1 in the + START_WORK IOCTL to get this minimum automatically. + +What: /sys/class/cxl/<afu>/mmio_size +Date: September 2014 +Contact: Ian Munsie <[email protected]>, + Michael Neuling <[email protected]> +Description: read only + Size of the MMIO space that may be mmaped by userspace. + + +What: /sys/class/cxl/<afu>/models_supported +Date: September 2014 +Contact: Ian Munsie <[email protected]>, + Michael Neuling <[email protected]> +Description: read only + List of the models this AFU supports. + Valid entries are: "dedicated_process" and "afu_directed" + +What: /sys/class/cxl/<afu>/model +Date: September 2014 +Contact: Ian Munsie <[email protected]>, + Michael Neuling <[email protected]> +Description: read/write + The current model the AFU is using. Will be one of the models + given in models_supported. Writing will change the model but + no user contexts can be attached at this point. + + +What: /sys/class/cxl/<afu>/prefault_mode +Date: September 2014 +Contact: Ian Munsie <[email protected]>, + Michael Neuling <[email protected]> +Description: read/write + Set the mode for prefaulting in segments into the segment table + when performing the START_WORK ioctl. Possible values: + none: No prefaulting (default) + wed: Just prefault in the wed + all: all segments this process currently maps + +What: /sys/class/cxl/<afu>/reset +Date: September 2014 +Contact: Ian Munsie <[email protected]>, + Michael Neuling <[email protected]> +Description: write only + Reset the AFU. + + +Master contexts (eg. /sys/class/cxl/afu0.0m) + +What: /sys/class/cxl/<afu>m/mmio_size +Date: September 2014 +Contact: Ian Munsie <[email protected]>, + Michael Neuling <[email protected]> +Description: read only + Size of the MMIO space that may be mmaped by userspace. This + includes all slave contexts space also. + +What: /sys/class/cxl/<afu>m/pp_mmio_len +Date: September 2014 +Contact: Ian Munsie <[email protected]>, + Michael Neuling <[email protected]> +Description: read only + Per Process MMIO space length. + +What: /sys/class/cxl/<afu>m/pp_mmio_off +Date: September 2014 +Contact: Ian Munsie <[email protected]>, + Michael Neuling <[email protected]> +Description: read only + Per Process MMIO space offset. + + +Card info (eg. /sys/class/cxl/card0) + +What: /sys/class/cxl/<card>/caia_version +Date: September 2014 +Contact: Ian Munsie <[email protected]>, + Michael Neuling <[email protected]> +Description: read only + Identifies the CAIA Version the card implements. + +What: /sys/class/cxl/<card>/psl_version +Date: September 2014 +Contact: Ian Munsie <[email protected]>, + Michael Neuling <[email protected]> +Description: read only + Identifies the revision level of the PSL. + +What: /sys/class/cxl/<card>/base_image +Date: September 2014 +Contact: Ian Munsie <[email protected]>, + Michael Neuling <[email protected]> +Description: read only + Identifies the revision level of the base image for devices + that support load-able PSLs. For FPGAs this field identifies + the image contained in the on-adapter flash which is loaded + during the initial program load + +What: /sys/class/cxl/<card>/image_loaded +Date: September 2014 +Contact: Ian Munsie <[email protected]>, + Michael Neuling <[email protected]> +Description: read only + Will return "user" or "factory" depending on the image loaded + onto the card +
Documentation/ioctl/ioctl-number.txt +1 -0
@@ -313,6 +313,7 @@ Code Seq#(hex) Include File Comments 0xB1 00-1F PPPoX <mailto:[email protected]> 0xB3 00 linux/mmc/ioctl.h 0xC0 00-0F linux/usb/iowarrior.h +0xCA 00-0F uapi/misc/cxl.h 0xCB 00-1F CBM serial IEC bus in development: <mailto:[email protected]> 0xCD 01 linux/reiserfs_fs.h
Documentation/powerpc/00-INDEX +2 -0
@@ -28,3 +28,5 @@ ptrace.txt - Information on the ptrace interfaces for hardware debug registers. transactional_memory.txt - Overview of the Power8 transactional memory support. +cxl.txt + - Overview of the CXL driver.
Documentation/powerpc/cxl.txt new file +310 -0
310 lines not on this page · raw message
MAINTAINERS +7 -0
@@ -2711,6 +2711,13 @@ W: http://www.chelsio.com S: Supported F: drivers/net/ethernet/chelsio/cxgb4vf/ +CXL (IBM Coherent Accelerator Processor Interface CAPI) DRIVER +M: Ian Munsie <[email protected]> +M: Michael Neuling <[email protected]> +L: [email protected] +S: Supported +F: drivers/misc/cxl/ + STMMAC ETHERNET DRIVER M: Giuseppe Cavallaro <[email protected]> L: [email protected]
Signature · 1 line
1.9.1