Re: [RFC PATCH 2/3] DMA, CMA: use general CMA reserved area management framework

2014-06-11 Thread Michal Nazarewicz
On Tue, Jun 10 2014, Joonsoo Kim iamjoonsoo@lge.com wrote:
 Without including device.h, build failure occurs.
 In dma-contiguous.h, we try to access to dev-cma_area, so we need
 device.h. In the past, we included it luckily by swap.h in
 drivers/base/dma-contiguous.c. Swap.h includes node.h and then node.h
 includes device.h, so we were happy. But, in this patch, I remove
 'include linux/swap.h' so we need to include device.h explicitly.

Ack.

-- 
Best regards, _ _
.o. | Liege of Serenely Enlightened Majesty of  o' \,=./ `o
..o | Computer Science,  Michał “mina86” Nazarewicz(o o)
ooo +--m...@google.com--xmpp:min...@jabber.org--ooO--(_)--Ooo--
--
To unsubscribe from this list: send the line unsubscribe kvm-ppc in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 0/6] KVM: PPC: Book3S HV: Enable on little endian hosts

2014-06-11 Thread Alexander Graf
So far we've been able to successfully run HV KVM on big endian hosts, but
once you dive into little endian land things start to fall apart.

This patch set enables HV KVM for little endian hosts. This should be the
final piece left missing to get little endian systems fully en par with big
endian ones in the KVM world.


Alex

Alexander Graf (6):
  PPC: Add asm helpers for BE 32bit load/store
  KVM: PPC: Book3S HV: Make HTAB code LE host aware
  KVM: PPC: Book3S HV: Access guest VPA in BE
  KVM: PPC: Book3S HV: Access host lppaca and shadow slb in BE
  KVM: PPC: Book3S HV: Access XICS in BE
  KVM: PPC: Book3S HV: Enable for little endian hosts

 arch/powerpc/include/asm/asm-compat.h|   4 ++
 arch/powerpc/include/asm/kvm_book3s_64.h |  14 +++-
 arch/powerpc/kvm/Kconfig |   1 -
 arch/powerpc/kvm/book3s_64_mmu_hv.c  |  95 +-
 arch/powerpc/kvm/book3s_hv.c |  16 ++---
 arch/powerpc/kvm/book3s_hv_ras.c |   6 +-
 arch/powerpc/kvm/book3s_hv_rm_mmu.c  | 111 ++-
 arch/powerpc/kvm/book3s_hv_rmhandlers.S  |  37 +++
 8 files changed, 166 insertions(+), 118 deletions(-)

-- 
1.8.1.4

--
To unsubscribe from this list: send the line unsubscribe kvm-ppc in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 1/6] PPC: Add asm helpers for BE 32bit load/store

2014-06-11 Thread Alexander Graf
From assembly code we might not only have to explicitly BE access 64bit values,
but sometimes also 32bit ones. Add helpers that allow for easy use of lwzx/stwx
in their respective byte-reverse or native form.

Signed-off-by: Alexander Graf ag...@suse.de
CC: Benjamin Herrenschmidt b...@kernel.crashing.org
---
 arch/powerpc/include/asm/asm-compat.h | 4 
 1 file changed, 4 insertions(+)

diff --git a/arch/powerpc/include/asm/asm-compat.h 
b/arch/powerpc/include/asm/asm-compat.h
index 4b237aa..21164ff 100644
--- a/arch/powerpc/include/asm/asm-compat.h
+++ b/arch/powerpc/include/asm/asm-compat.h
@@ -34,10 +34,14 @@
 #define PPC_MIN_STKFRM 112
 
 #ifdef __BIG_ENDIAN__
+#define LWZX_BEstringify_in_c(lwzx)
 #define LDX_BE stringify_in_c(ldx)
+#define STDX_BEstringify_in_c(stwx)
 #define STDX_BEstringify_in_c(stdx)
 #else
+#define LWZX_BEstringify_in_c(lwbrx)
 #define LDX_BE stringify_in_c(ldbrx)
+#define STWX_BEstringify_in_c(stwbrx)
 #define STDX_BEstringify_in_c(stdbrx)
 #endif
 
-- 
1.8.1.4

--
To unsubscribe from this list: send the line unsubscribe kvm-ppc in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 5/6] KVM: PPC: Book3S HV: Access XICS in BE

2014-06-11 Thread Alexander Graf
On the exit path from the guest we check what type of interrupt we received
if we received one. This means we're doing hardware access to the XICS interrupt
controller.

However, when running on a little endian system, this access is byte reversed.

So let's make sure to swizzle the bytes back again and virtuall make XICS
accesses big endian.

Signed-off-by: Alexander Graf ag...@suse.de
---
 arch/powerpc/kvm/book3s_hv_rmhandlers.S | 17 +++--
 1 file changed, 15 insertions(+), 2 deletions(-)

diff --git a/arch/powerpc/kvm/book3s_hv_rmhandlers.S 
b/arch/powerpc/kvm/book3s_hv_rmhandlers.S
index 3530d06..40dec37 100644
--- a/arch/powerpc/kvm/book3s_hv_rmhandlers.S
+++ b/arch/powerpc/kvm/book3s_hv_rmhandlers.S
@@ -36,6 +36,13 @@
 #define NAPPING_CEDE   1
 #define NAPPING_NOVCPU 2
 
+.macro bswap32 regd, regs
+   srwi\regd,\regs,24
+   rlwimi  \regd,\regs,24,16,23
+   rlwimi  \regd,\regs,8,8,15
+   rlwimi  \regd,\regs,24,0,7
+.endm
+
 /*
  * Call kvmppc_hv_entry in real mode.
  * Must be called with interrupts hard-disabled.
@@ -2206,7 +2213,12 @@ kvmppc_read_intr:
cmpdi   r6, 0
beq-1f
lwzcix  r0, r6, r7
-   rlwinm. r3, r0, 0, 0xff
+#ifdef __LITTLE_ENDIAN__
+   bswap32 r3, r0
+#else
+   mr  r3, r0
+#endif
+   rlwinm. r3, r3, 0, 0xff
sync
beq 1f  /* if nothing pending in the ICP */
 
@@ -2241,7 +2253,8 @@ kvmppc_read_intr:
 42:/* It's not an IPI and it's for the host, stash it in the PACA
 * before exit, it will be picked up by the host ICP driver
 */
-   stw r0, HSTATE_SAVED_XIRR(r13)
+   li  r4, HSTATE_SAVED_XIRR
+   STWX_BE r0, r13, r4
li  r3, 1
b   1b
 
-- 
1.8.1.4

--
To unsubscribe from this list: send the line unsubscribe kvm-ppc in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 3/6] KVM: PPC: Book3S HV: Access guest VPA in BE

2014-06-11 Thread Alexander Graf
There are a few shared data structures between the host and the guest. Most
of them get registered through the VPA interface.

These data structures are defined to always be in big endian byte order, so
let's make sure we always access them in big endian.

Signed-off-by: Alexander Graf ag...@suse.de
---
 arch/powerpc/kvm/book3s_hv.c | 16 
 arch/powerpc/kvm/book3s_hv_ras.c |  6 +++---
 2 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/arch/powerpc/kvm/book3s_hv.c b/arch/powerpc/kvm/book3s_hv.c
index c38cf9f..f8640f4 100644
--- a/arch/powerpc/kvm/book3s_hv.c
+++ b/arch/powerpc/kvm/book3s_hv.c
@@ -270,7 +270,7 @@ struct kvm_vcpu *kvmppc_find_vcpu(struct kvm *kvm, int id)
 static void init_vpa(struct kvm_vcpu *vcpu, struct lppaca *vpa)
 {
vpa-__old_status |= LPPACA_OLD_SHARED_PROC;
-   vpa-yield_count = 1;
+   vpa-yield_count = cpu_to_be32(1);
 }
 
 static int set_vpa(struct kvm_vcpu *vcpu, struct kvmppc_vpa *v,
@@ -333,9 +333,9 @@ static unsigned long do_h_register_vpa(struct kvm_vcpu 
*vcpu,
if (va == NULL)
return H_PARAMETER;
if (subfunc == H_VPA_REG_VPA)
-   len = ((struct reg_vpa *)va)-length.hword;
+   len = be16_to_cpu(((struct reg_vpa *)va)-length.hword);
else
-   len = ((struct reg_vpa *)va)-length.word;
+   len = be32_to_cpu(((struct reg_vpa *)va)-length.word);
kvmppc_unpin_guest_page(kvm, va, vpa, false);
 
/* Check length */
@@ -540,11 +540,11 @@ static void kvmppc_create_dtl_entry(struct kvm_vcpu *vcpu,
return;
memset(dt, 0, sizeof(struct dtl_entry));
dt-dispatch_reason = 7;
-   dt-processor_id = vc-pcpu + vcpu-arch.ptid;
-   dt-timebase = now + vc-tb_offset;
-   dt-enqueue_to_dispatch_time = stolen;
-   dt-srr0 = kvmppc_get_pc(vcpu);
-   dt-srr1 = vcpu-arch.shregs.msr;
+   dt-processor_id = cpu_to_be16(vc-pcpu + vcpu-arch.ptid);
+   dt-timebase = cpu_to_be64(now + vc-tb_offset);
+   dt-enqueue_to_dispatch_time = cpu_to_be32(stolen);
+   dt-srr0 = cpu_to_be64(kvmppc_get_pc(vcpu));
+   dt-srr1 = cpu_to_be64(vcpu-arch.shregs.msr);
++dt;
if (dt == vcpu-arch.dtl.pinned_end)
dt = vcpu-arch.dtl.pinned_addr;
diff --git a/arch/powerpc/kvm/book3s_hv_ras.c b/arch/powerpc/kvm/book3s_hv_ras.c
index 768a9f9..6a3ba8a 100644
--- a/arch/powerpc/kvm/book3s_hv_ras.c
+++ b/arch/powerpc/kvm/book3s_hv_ras.c
@@ -45,14 +45,14 @@ static void reload_slb(struct kvm_vcpu *vcpu)
return;
 
/* Sanity check */
-   n = min_t(u32, slb-persistent, SLB_MIN_SIZE);
+   n = min_t(u32, be32_to_cpu(slb-persistent), SLB_MIN_SIZE);
if ((void *) slb-save_area[n]  vcpu-arch.slb_shadow.pinned_end)
return;
 
/* Load up the SLB from that */
for (i = 0; i  n; ++i) {
-   unsigned long rb = slb-save_area[i].esid;
-   unsigned long rs = slb-save_area[i].vsid;
+   unsigned long rb = be64_to_cpu(slb-save_area[i].esid);
+   unsigned long rs = be64_to_cpu(slb-save_area[i].vsid);
 
rb = (rb  ~0xFFFul) | i;   /* insert entry number */
asm volatile(slbmte %0,%1 : : r (rs), r (rb));
-- 
1.8.1.4

--
To unsubscribe from this list: send the line unsubscribe kvm-ppc in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 6/6] KVM: PPC: Book3S HV: Enable for little endian hosts

2014-06-11 Thread Alexander Graf
Now that we've fixed all the issues that HV KVM code had on little endian
hosts, we can enable it in the kernel configuration for users to play with.

Signed-off-by: Alexander Graf ag...@suse.de
---
 arch/powerpc/kvm/Kconfig | 1 -
 1 file changed, 1 deletion(-)

diff --git a/arch/powerpc/kvm/Kconfig b/arch/powerpc/kvm/Kconfig
index d6a53b9..8aeeda1 100644
--- a/arch/powerpc/kvm/Kconfig
+++ b/arch/powerpc/kvm/Kconfig
@@ -75,7 +75,6 @@ config KVM_BOOK3S_64
 config KVM_BOOK3S_64_HV
tristate KVM support for POWER7 and PPC970 using hypervisor mode in 
host
depends on KVM_BOOK3S_64
-   depends on !CPU_LITTLE_ENDIAN
select KVM_BOOK3S_HV_POSSIBLE
select MMU_NOTIFIER
select CMA
-- 
1.8.1.4

--
To unsubscribe from this list: send the line unsubscribe kvm-ppc in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 4/6] KVM: PPC: Book3S HV: Access host lppaca and shadow slb in BE

2014-06-11 Thread Alexander Graf
Some data structures are always stored in big endian. Among those are the LPPACA
fields as well as the shadow slb. These structures might be shared with a
hypervisor.

So whenever we access those fields, make sure we do so in big endian byte order.

Signed-off-by: Alexander Graf ag...@suse.de
---
 arch/powerpc/kvm/book3s_hv_rmhandlers.S | 20 ++--
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/arch/powerpc/kvm/book3s_hv_rmhandlers.S 
b/arch/powerpc/kvm/book3s_hv_rmhandlers.S
index 220aefb..3530d06 100644
--- a/arch/powerpc/kvm/book3s_hv_rmhandlers.S
+++ b/arch/powerpc/kvm/book3s_hv_rmhandlers.S
@@ -32,10 +32,6 @@
 
 #define VCPU_GPRS_TM(reg) (((reg) * ULONG_SIZE) + VCPU_GPR_TM)
 
-#ifdef __LITTLE_ENDIAN__
-#error Need to fix lppaca and SLB shadow accesses in little endian mode
-#endif
-
 /* Values in HSTATE_NAPPING(r13) */
 #define NAPPING_CEDE   1
 #define NAPPING_NOVCPU 2
@@ -585,9 +581,10 @@ kvmppc_got_guest:
ld  r3, VCPU_VPA(r4)
cmpdi   r3, 0
beq 25f
-   lwz r5, LPPACA_YIELDCOUNT(r3)
+   li  r6, LPPACA_YIELDCOUNT
+   LWZX_BE r5, r3, r6
addir5, r5, 1
-   stw r5, LPPACA_YIELDCOUNT(r3)
+   STWX_BE r5, r3, r6
li  r6, 1
stb r6, VCPU_VPA_DIRTY(r4)
 25:
@@ -1328,9 +1325,10 @@ END_FTR_SECTION_IFSET(CPU_FTR_ARCH_206)
ld  r8, VCPU_VPA(r9)/* do they have a VPA? */
cmpdi   r8, 0
beq 25f
-   lwz r3, LPPACA_YIELDCOUNT(r8)
+   li  r4, LPPACA_YIELDCOUNT
+   LWZX_BE r3, r8, r4
addir3, r3, 1
-   stw r3, LPPACA_YIELDCOUNT(r8)
+   STWX_BE r3, r8, r4
li  r3, 1
stb r3, VCPU_VPA_DIRTY(r9)
 25:
@@ -1643,8 +1641,10 @@ END_FTR_SECTION_IFSET(CPU_FTR_ARCH_207S)
 33:ld  r8,PACA_SLBSHADOWPTR(r13)
 
.rept   SLB_NUM_BOLTED
-   ld  r5,SLBSHADOW_SAVEAREA(r8)
-   ld  r6,SLBSHADOW_SAVEAREA+8(r8)
+   li  r3, SLBSHADOW_SAVEAREA
+   LDX_BE  r5, r8, r3
+   addir3, r3, 8
+   LDX_BE  r6, r8, r3
andis.  r7,r5,SLB_ESID_V@h
beq 1f
slbmte  r6,r5
-- 
1.8.1.4

--
To unsubscribe from this list: send the line unsubscribe kvm-ppc in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 2/6] KVM: PPC: Book3S HV: Make HTAB code LE host aware

2014-06-11 Thread Alexander Graf
When running on an LE host all data structures are kept in little endian
byte order. However, the HTAB still needs to be maintained in big endian.

So every time we access any HTAB we need to make sure we do so in the right
byte order. Fix up all accesses to manually byte swap.

Signed-off-by: Alexander Graf ag...@suse.de
---
 arch/powerpc/include/asm/kvm_book3s_64.h |  14 +++-
 arch/powerpc/kvm/book3s_64_mmu_hv.c  |  95 +-
 arch/powerpc/kvm/book3s_hv_rm_mmu.c  | 111 ++-
 3 files changed, 126 insertions(+), 94 deletions(-)

diff --git a/arch/powerpc/include/asm/kvm_book3s_64.h 
b/arch/powerpc/include/asm/kvm_book3s_64.h
index fddb72b..2e99a3e 100644
--- a/arch/powerpc/include/asm/kvm_book3s_64.h
+++ b/arch/powerpc/include/asm/kvm_book3s_64.h
@@ -61,18 +61,26 @@ extern unsigned long kvm_rma_pages;
 
 static inline long try_lock_hpte(unsigned long *hpte, unsigned long bits)
 {
-   unsigned long tmp, old;
+   unsigned long tmp, old, lockbit;
+
+   /*
+* We load/store in native endian, but the HTAB is in big endian. If
+* we byte swap all data we apply on the PTE we're implicitly correct
+* again.
+*/
+   lockbit = cpu_to_be64(HPTE_V_HVLOCK);
+   bits = cpu_to_be64(bits);
 
asm volatile(  ldarx   %0,0,%2\n
   and.%1,%0,%3\n
   bne 2f\n
-  ori %0,%0,%4\n
+  or  %0,%0,%4\n
   stdcx.  %0,0,%2\n
   beq+2f\n
   mr  %1,%3\n
 2:isync
 : =r (tmp), =r (old)
-: r (hpte), r (bits), i (HPTE_V_HVLOCK)
+: r (hpte), r (bits), r (lockbit)
 : cc, memory);
return old == 0;
 }
diff --git a/arch/powerpc/kvm/book3s_64_mmu_hv.c 
b/arch/powerpc/kvm/book3s_64_mmu_hv.c
index 8056107..f53cf2e 100644
--- a/arch/powerpc/kvm/book3s_64_mmu_hv.c
+++ b/arch/powerpc/kvm/book3s_64_mmu_hv.c
@@ -474,12 +474,12 @@ static int kvmppc_mmu_book3s_64_hv_xlate(struct kvm_vcpu 
*vcpu, gva_t eaddr,
return -ENOENT;
}
hptep = (unsigned long *)(kvm-arch.hpt_virt + (index  4));
-   v = hptep[0]  ~HPTE_V_HVLOCK;
+   v = be64_to_cpu(hptep[0])  ~HPTE_V_HVLOCK;
gr = kvm-arch.revmap[index].guest_rpte;
 
/* Unlock the HPTE */
asm volatile(lwsync : : : memory);
-   hptep[0] = v;
+   hptep[0] = cpu_to_be64(v);
preempt_enable();
 
gpte-eaddr = eaddr;
@@ -611,11 +611,11 @@ int kvmppc_book3s_hv_page_fault(struct kvm_run *run, 
struct kvm_vcpu *vcpu,
preempt_disable();
while (!try_lock_hpte(hptep, HPTE_V_HVLOCK))
cpu_relax();
-   hpte[0] = hptep[0]  ~HPTE_V_HVLOCK;
-   hpte[1] = hptep[1];
+   hpte[0] = be64_to_cpu(hptep[0])  ~HPTE_V_HVLOCK;
+   hpte[1] = be64_to_cpu(hptep[1]);
hpte[2] = r = rev-guest_rpte;
asm volatile(lwsync : : : memory);
-   hptep[0] = hpte[0];
+   hptep[0] = cpu_to_be64(hpte[0]);
preempt_enable();
 
if (hpte[0] != vcpu-arch.pgfault_hpte[0] ||
@@ -731,8 +731,9 @@ int kvmppc_book3s_hv_page_fault(struct kvm_run *run, struct 
kvm_vcpu *vcpu,
preempt_disable();
while (!try_lock_hpte(hptep, HPTE_V_HVLOCK))
cpu_relax();
-   if ((hptep[0]  ~HPTE_V_HVLOCK) != hpte[0] || hptep[1] != hpte[1] ||
-   rev-guest_rpte != hpte[2])
+   if ((be64_to_cpu(hptep[0])  ~HPTE_V_HVLOCK) != hpte[0] ||
+   be64_to_cpu(hptep[1]) != hpte[1] ||
+   rev-guest_rpte != hpte[2])
/* HPTE has been changed under us; let the guest retry */
goto out_unlock;
hpte[0] = (hpte[0]  ~HPTE_V_ABSENT) | HPTE_V_VALID;
@@ -752,20 +753,20 @@ int kvmppc_book3s_hv_page_fault(struct kvm_run *run, 
struct kvm_vcpu *vcpu,
rcbits = *rmap  KVMPPC_RMAP_RC_SHIFT;
r = rcbits | ~(HPTE_R_R | HPTE_R_C);
 
-   if (hptep[0]  HPTE_V_VALID) {
+   if (be64_to_cpu(hptep[0])  HPTE_V_VALID) {
/* HPTE was previously valid, so we need to invalidate it */
unlock_rmap(rmap);
-   hptep[0] |= HPTE_V_ABSENT;
+   hptep[0] |= cpu_to_be64(HPTE_V_ABSENT);
kvmppc_invalidate_hpte(kvm, hptep, index);
/* don't lose previous R and C bits */
-   r |= hptep[1]  (HPTE_R_R | HPTE_R_C);
+   r |= be64_to_cpu(hptep[1])  (HPTE_R_R | HPTE_R_C);
} else {
kvmppc_add_revmap_chain(kvm, rev, rmap, index, 0);
}
 
-   hptep[1] = r;
+   hptep[1] = cpu_to_be64(r);
eieio();
-   hptep[0] = hpte[0];
+   hptep[0] = cpu_to_be64(hpte[0]);
asm volatile(ptesync : : : memory);
preempt_enable();
if (page  hpte_is_writable(r))
@@ -784,7 +785,7 @@ int 

[PATCH] KVM: PPC: Book3s HV: Fix tlbie compile error

2014-06-11 Thread Alexander Graf
Some compilers complain about uninitialized variables in the compute_tlbie_rb
function. When you follow the code path you'll realize that we'll never get
to that point, but the compiler isn't all that smart.

So just default to 4k page sizes for everything, making the compiler happy
and the code slightly easier to read.

Signed-off-by: Alexander Graf ag...@suse.de
---
 arch/powerpc/include/asm/kvm_book3s_64.h | 8 ++--
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/arch/powerpc/include/asm/kvm_book3s_64.h 
b/arch/powerpc/include/asm/kvm_book3s_64.h
index fddb72b..c7871f3 100644
--- a/arch/powerpc/include/asm/kvm_book3s_64.h
+++ b/arch/powerpc/include/asm/kvm_book3s_64.h
@@ -110,16 +110,12 @@ static inline int __hpte_actual_psize(unsigned int lp, 
int psize)
 static inline unsigned long compute_tlbie_rb(unsigned long v, unsigned long r,
 unsigned long pte_index)
 {
-   int b_psize, a_psize;
+   int b_psize = MMU_PAGE_4K, a_psize = MMU_PAGE_4K;
unsigned int penc;
unsigned long rb = 0, va_low, sllp;
unsigned int lp = (r  LP_SHIFT)  ((1  LP_BITS) - 1);
 
-   if (!(v  HPTE_V_LARGE)) {
-   /* both base and actual psize is 4k */
-   b_psize = MMU_PAGE_4K;
-   a_psize = MMU_PAGE_4K;
-   } else {
+   if (v  HPTE_V_LARGE) {
for (b_psize = 0; b_psize  MMU_PAGE_COUNT; b_psize++) {
 
/* valid entries have a shift value */
-- 
1.8.1.4

--
To unsubscribe from this list: send the line unsubscribe kvm-ppc in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v10 3/3] drivers/vfio: EEH support for VFIO PCI device

2014-06-11 Thread Alex Williamson
On Tue, 2014-06-10 at 11:41 +1000, Gavin Shan wrote:
 The patch adds new IOCTL commands for sPAPR VFIO container device
 to support EEH functionality for PCI devices, which have been passed
 through from host to somebody else via VFIO.
 
 Signed-off-by: Gavin Shan gws...@linux.vnet.ibm.com
 Acked-by: Alexander Graf ag...@suse.de

Acked-by: Alex Williamson alex.william...@redhat.com

 ---
  Documentation/vfio.txt  | 87 
 +++--
  drivers/vfio/Makefile   |  1 +
  drivers/vfio/pci/vfio_pci.c | 18 ++--
  drivers/vfio/vfio_iommu_spapr_tce.c | 17 +++-
  drivers/vfio/vfio_spapr_eeh.c   | 87 
 +
  include/linux/vfio.h| 23 ++
  include/uapi/linux/vfio.h   | 34 +++
  7 files changed, 259 insertions(+), 8 deletions(-)
  create mode 100644 drivers/vfio/vfio_spapr_eeh.c
 
 diff --git a/Documentation/vfio.txt b/Documentation/vfio.txt
 index b9ca023..96978ec 100644
 --- a/Documentation/vfio.txt
 +++ b/Documentation/vfio.txt
 @@ -305,7 +305,15 @@ faster, the map/unmap handling has been implemented in 
 real mode which provides
  an excellent performance which has limitations such as inability to do
  locked pages accounting in real time.
  
 -So 3 additional ioctls have been added:
 +4) According to sPAPR specification, A Partitionable Endpoint (PE) is an I/O
 +subtree that can be treated as a unit for the purposes of partitioning and
 +error recovery. A PE may be a single or multi-function IOA (IO Adapter), a
 +function of a multi-function IOA, or multiple IOAs (possibly including switch
 +and bridge structures above the multiple IOAs). PPC64 guests detect PCI 
 errors
 +and recover from them via EEH RTAS services, which works on the basis of
 +additional ioctl commands.
 +
 +So 4 additional ioctls have been added:
  
   VFIO_IOMMU_SPAPR_TCE_GET_INFO - returns the size and the start
   of the DMA window on the PCI bus.
 @@ -316,9 +324,12 @@ So 3 additional ioctls have been added:
  
   VFIO_IOMMU_DISABLE - disables the container.
  
 + VFIO_EEH_PE_OP - provides an API for EEH setup, error detection and 
 recovery.
  
  The code flow from the example above should be slightly changed:
  
 + struct vfio_eeh_pe_op pe_op = { .argsz = sizeof(pe_op), .flags = 0 };
 +
   .
   /* Add the group to the container */
   ioctl(group, VFIO_GROUP_SET_CONTAINER, container);
 @@ -342,9 +353,79 @@ The code flow from the example above should be slightly 
 changed:
   dma_map.flags = VFIO_DMA_MAP_FLAG_READ | VFIO_DMA_MAP_FLAG_WRITE;
  
   /* Check here is .iova/.size are within DMA window from 
 spapr_iommu_info */
 -
   ioctl(container, VFIO_IOMMU_MAP_DMA, dma_map);
 - .
 +
 + /* Get a file descriptor for the device */
 + device = ioctl(group, VFIO_GROUP_GET_DEVICE_FD, :06:0d.0);
 +
 + 
 +
 + /* Gratuitous device reset and go... */
 + ioctl(device, VFIO_DEVICE_RESET);
 +
 + /* Make sure EEH is supported */
 + ioctl(container, VFIO_CHECK_EXTENSION, VFIO_EEH);
 +
 + /* Enable the EEH functionality on the device */
 + pe_op.op = VFIO_EEH_PE_ENABLE;
 + ioctl(container, VFIO_EEH_PE_OP, pe_op);
 +
 + /* You're suggested to create additional data struct to represent
 +  * PE, and put child devices belonging to same IOMMU group to the
 +  * PE instance for later reference.
 +  */
 +
 + /* Check the PE's state and make sure it's in functional state */
 + pe_op.op = VFIO_EEH_PE_GET_STATE;
 + ioctl(container, VFIO_EEH_PE_OP, pe_op);
 +
 + /* Save device state using pci_save_state().
 +  * EEH should be enabled on the specified device.
 +  */
 +
 + 
 +
 + /* When 0xFF's returned from reading PCI config space or IO BARs
 +  * of the PCI device. Check the PE's state to see if that has been
 +  * frozen.
 +  */
 + ioctl(container, VFIO_EEH_PE_OP, pe_op);
 +
 + /* Waiting for pending PCI transactions to be completed and don't
 +  * produce any more PCI traffic from/to the affected PE until
 +  * recovery is finished.
 +  */
 +
 + /* Enable IO for the affected PE and collect logs. Usually, the
 +  * standard part of PCI config space, AER registers are dumped
 +  * as logs for further analysis.
 +  */
 + pe_op.op = VFIO_EEH_PE_UNFREEZE_IO;
 + ioctl(container, VFIO_EEH_PE_OP, pe_op);
 +
 + /*
 +  * Issue PE reset: hot or fundamental reset. Usually, hot reset
 +  * is enough. However, the firmware of some PCI adapters would
 +  * require fundamental reset.
 +  */
 + pe_op.op = VFIO_EEH_PE_RESET_HOT;
 + ioctl(container, VFIO_EEH_PE_OP, pe_op);
 + pe_op.op = VFIO_EEH_PE_RESET_DEACTIVATE;
 + ioctl(container, VFIO_EEH_PE_OP, pe_op);
 +
 + /* Configure the PCI bridges for the affected PE */
 + pe_op.op = VFIO_EEH_PE_CONFIGURE;
 + ioctl(container, 

[PATCH v2 02/10] DMA, CMA: fix possible memory leak

2014-06-11 Thread Joonsoo Kim
We should free memory for bitmap when we find zone mis-match,
otherwise this memory will leak.

Additionally, I copy code comment from ppc kvm's cma code to notify
why we need to check zone mis-match.

Signed-off-by: Joonsoo Kim iamjoonsoo@lge.com

diff --git a/drivers/base/dma-contiguous.c b/drivers/base/dma-contiguous.c
index bd0bb81..fb0cdce 100644
--- a/drivers/base/dma-contiguous.c
+++ b/drivers/base/dma-contiguous.c
@@ -177,14 +177,24 @@ static int __init cma_activate_area(struct cma *cma)
base_pfn = pfn;
for (j = pageblock_nr_pages; j; --j, pfn++) {
WARN_ON_ONCE(!pfn_valid(pfn));
+   /*
+* alloc_contig_range requires the pfn range
+* specified to be in the same zone. Make this
+* simple by forcing the entire CMA resv range
+* to be in the same zone.
+*/
if (page_zone(pfn_to_page(pfn)) != zone)
-   return -EINVAL;
+   goto err;
}
init_cma_reserved_pageblock(pfn_to_page(base_pfn));
} while (--i);
 
mutex_init(cma-lock);
return 0;
+
+err:
+   kfree(cma-bitmap);
+   return -EINVAL;
 }
 
 static struct cma cma_areas[MAX_CMA_AREAS];
-- 
1.7.9.5

--
To unsubscribe from this list: send the line unsubscribe kvm-ppc in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v2 06/10] CMA: generalize CMA reserved area management functionality

2014-06-11 Thread Joonsoo Kim
Currently, there are two users on CMA functionality, one is the DMA
subsystem and the other is the kvm on powerpc. They have their own code
to manage CMA reserved area even if they looks really similar.
From my guess, it is caused by some needs on bitmap management. Kvm side
wants to maintain bitmap not for 1 page, but for more size. Eventually it
use bitmap where one bit represents 64 pages.

When I implement CMA related patches, I should change those two places
to apply my change and it seem to be painful to me. I want to change
this situation and reduce future code management overhead through
this patch.

This change could also help developer who want to use CMA in their
new feature development, since they can use CMA easily without
copying  pasting this reserved area management code.

In previous patches, we have prepared some features to generalize
CMA reserved area management and now it's time to do it. This patch
moves core functions to mm/cma.c and change DMA APIs to use
these functions.

There is no functional change in DMA APIs.

v2: There is no big change from v1 in mm/cma.c. Mostly renaming.

Acked-by: Michal Nazarewicz min...@mina86.com
Signed-off-by: Joonsoo Kim iamjoonsoo@lge.com

diff --git a/drivers/base/Kconfig b/drivers/base/Kconfig
index 00e13ce..4eac559 100644
--- a/drivers/base/Kconfig
+++ b/drivers/base/Kconfig
@@ -283,16 +283,6 @@ config CMA_ALIGNMENT
 
  If unsure, leave the default value 8.
 
-config CMA_AREAS
-   int Maximum count of the CMA device-private areas
-   default 7
-   help
- CMA allows to create CMA areas for particular devices. This parameter
- sets the maximum number of such device private CMA areas in the
- system.
-
- If unsure, leave the default value 7.
-
 endif
 
 endmenu
diff --git a/drivers/base/dma-contiguous.c b/drivers/base/dma-contiguous.c
index 9bc9340..f177f73 100644
--- a/drivers/base/dma-contiguous.c
+++ b/drivers/base/dma-contiguous.c
@@ -24,25 +24,10 @@
 
 #include linux/memblock.h
 #include linux/err.h
-#include linux/mm.h
-#include linux/mutex.h
-#include linux/page-isolation.h
 #include linux/sizes.h
-#include linux/slab.h
-#include linux/swap.h
-#include linux/mm_types.h
 #include linux/dma-contiguous.h
 #include linux/log2.h
-
-struct cma {
-   unsigned long   base_pfn;
-   unsigned long   count;
-   unsigned long   *bitmap;
-   int order_per_bit; /* Order of pages represented by one bit */
-   struct mutexlock;
-};
-
-struct cma *dma_contiguous_default_area;
+#include linux/cma.h
 
 #ifdef CONFIG_CMA_SIZE_MBYTES
 #define CMA_SIZE_MBYTES CONFIG_CMA_SIZE_MBYTES
@@ -50,6 +35,8 @@ struct cma *dma_contiguous_default_area;
 #define CMA_SIZE_MBYTES 0
 #endif
 
+struct cma *dma_contiguous_default_area;
+
 /*
  * Default global CMA area size can be defined in kernel's .config.
  * This is useful mainly for distro maintainers to create a kernel
@@ -156,199 +143,13 @@ void __init dma_contiguous_reserve(phys_addr_t limit)
}
 }
 
-static DEFINE_MUTEX(cma_mutex);
-
-static unsigned long cma_bitmap_aligned_mask(struct cma *cma, int align_order)
-{
-   return (1  (align_order  cma-order_per_bit)) - 1;
-}
-
-static unsigned long cma_bitmap_maxno(struct cma *cma)
-{
-   return cma-count  cma-order_per_bit;
-}
-
-static unsigned long cma_bitmap_pages_to_bits(struct cma *cma,
-   unsigned long pages)
-{
-   return ALIGN(pages, 1  cma-order_per_bit)  cma-order_per_bit;
-}
-
-static void clear_cma_bitmap(struct cma *cma, unsigned long pfn, int count)
-{
-   unsigned long bitmapno, nr_bits;
-
-   bitmapno = (pfn - cma-base_pfn)  cma-order_per_bit;
-   nr_bits = cma_bitmap_pages_to_bits(cma, count);
-
-   mutex_lock(cma-lock);
-   bitmap_clear(cma-bitmap, bitmapno, nr_bits);
-   mutex_unlock(cma-lock);
-}
-
-static int __init cma_activate_area(struct cma *cma)
-{
-   int bitmap_maxno = cma_bitmap_maxno(cma);
-   int bitmap_size = BITS_TO_LONGS(bitmap_maxno) * sizeof(long);
-   unsigned long base_pfn = cma-base_pfn, pfn = base_pfn;
-   unsigned i = cma-count  pageblock_order;
-   struct zone *zone;
-
-   pr_debug(%s()\n, __func__);
-
-   cma-bitmap = kzalloc(bitmap_size, GFP_KERNEL);
-   if (!cma-bitmap)
-   return -ENOMEM;
-
-   WARN_ON_ONCE(!pfn_valid(pfn));
-   zone = page_zone(pfn_to_page(pfn));
-
-   do {
-   unsigned j;
-   base_pfn = pfn;
-   for (j = pageblock_nr_pages; j; --j, pfn++) {
-   WARN_ON_ONCE(!pfn_valid(pfn));
-   /*
-* alloc_contig_range requires the pfn range
-* specified to be in the same zone. Make this
-* simple by forcing the entire CMA resv range
-* to be in the same zone.
-*/
-   if 

[PATCH v2 05/10] DMA, CMA: support arbitrary bitmap granularity

2014-06-11 Thread Joonsoo Kim
ppc kvm's cma region management requires arbitrary bitmap granularity,
since they want to reserve very large memory and manage this region
with bitmap that one bit for several pages to reduce management overheads.
So support arbitrary bitmap granularity for following generalization.

Signed-off-by: Joonsoo Kim iamjoonsoo@lge.com

diff --git a/drivers/base/dma-contiguous.c b/drivers/base/dma-contiguous.c
index bc4c171..9bc9340 100644
--- a/drivers/base/dma-contiguous.c
+++ b/drivers/base/dma-contiguous.c
@@ -38,6 +38,7 @@ struct cma {
unsigned long   base_pfn;
unsigned long   count;
unsigned long   *bitmap;
+   int order_per_bit; /* Order of pages represented by one bit */
struct mutexlock;
 };
 
@@ -157,9 +158,38 @@ void __init dma_contiguous_reserve(phys_addr_t limit)
 
 static DEFINE_MUTEX(cma_mutex);
 
+static unsigned long cma_bitmap_aligned_mask(struct cma *cma, int align_order)
+{
+   return (1  (align_order  cma-order_per_bit)) - 1;
+}
+
+static unsigned long cma_bitmap_maxno(struct cma *cma)
+{
+   return cma-count  cma-order_per_bit;
+}
+
+static unsigned long cma_bitmap_pages_to_bits(struct cma *cma,
+   unsigned long pages)
+{
+   return ALIGN(pages, 1  cma-order_per_bit)  cma-order_per_bit;
+}
+
+static void clear_cma_bitmap(struct cma *cma, unsigned long pfn, int count)
+{
+   unsigned long bitmapno, nr_bits;
+
+   bitmapno = (pfn - cma-base_pfn)  cma-order_per_bit;
+   nr_bits = cma_bitmap_pages_to_bits(cma, count);
+
+   mutex_lock(cma-lock);
+   bitmap_clear(cma-bitmap, bitmapno, nr_bits);
+   mutex_unlock(cma-lock);
+}
+
 static int __init cma_activate_area(struct cma *cma)
 {
-   int bitmap_size = BITS_TO_LONGS(cma-count) * sizeof(long);
+   int bitmap_maxno = cma_bitmap_maxno(cma);
+   int bitmap_size = BITS_TO_LONGS(bitmap_maxno) * sizeof(long);
unsigned long base_pfn = cma-base_pfn, pfn = base_pfn;
unsigned i = cma-count  pageblock_order;
struct zone *zone;
@@ -221,6 +251,7 @@ core_initcall(cma_init_reserved_areas);
  * @base: Base address of the reserved area optional, use 0 for any
  * @limit: End address of the reserved memory (optional, 0 for any).
  * @alignment: Alignment for the contiguous memory area, should be power of 2
+ * @order_per_bit: Order of pages represented by one bit on bitmap.
  * @res_cma: Pointer to store the created cma region.
  * @fixed: hint about where to place the reserved area
  *
@@ -235,7 +266,7 @@ core_initcall(cma_init_reserved_areas);
  */
 static int __init __dma_contiguous_reserve_area(phys_addr_t size,
phys_addr_t base, phys_addr_t limit,
-   phys_addr_t alignment,
+   phys_addr_t alignment, int order_per_bit,
struct cma **res_cma, bool fixed)
 {
struct cma *cma = cma_areas[cma_area_count];
@@ -269,6 +300,8 @@ static int __init __dma_contiguous_reserve_area(phys_addr_t 
size,
base = ALIGN(base, alignment);
size = ALIGN(size, alignment);
limit = ~(alignment - 1);
+   /* size should be aligned with order_per_bit */
+   BUG_ON(!IS_ALIGNED(size  PAGE_SHIFT, 1  order_per_bit));
 
/* Reserve memory */
if (base  fixed) {
@@ -294,6 +327,7 @@ static int __init __dma_contiguous_reserve_area(phys_addr_t 
size,
 */
cma-base_pfn = PFN_DOWN(base);
cma-count = size  PAGE_SHIFT;
+   cma-order_per_bit = order_per_bit;
*res_cma = cma;
cma_area_count++;
 
@@ -313,7 +347,7 @@ int __init dma_contiguous_reserve_area(phys_addr_t size, 
phys_addr_t base,
 {
int ret;
 
-   ret = __dma_contiguous_reserve_area(size, base, limit, 0,
+   ret = __dma_contiguous_reserve_area(size, base, limit, 0, 0,
res_cma, fixed);
if (ret)
return ret;
@@ -324,13 +358,6 @@ int __init dma_contiguous_reserve_area(phys_addr_t size, 
phys_addr_t base,
return 0;
 }
 
-static void clear_cma_bitmap(struct cma *cma, unsigned long pfn, int count)
-{
-   mutex_lock(cma-lock);
-   bitmap_clear(cma-bitmap, pfn - cma-base_pfn, count);
-   mutex_unlock(cma-lock);
-}
-
 /**
  * dma_alloc_from_contiguous() - allocate pages from contiguous area
  * @dev:   Pointer to device for which the allocation is performed.
@@ -345,7 +372,8 @@ static void clear_cma_bitmap(struct cma *cma, unsigned long 
pfn, int count)
 static struct page *__dma_alloc_from_contiguous(struct cma *cma, int count,
   unsigned int align)
 {
-   unsigned long mask, pfn, pageno, start = 0;
+   unsigned long mask, pfn, start = 0;
+   unsigned long bitmap_maxno, bitmapno, nr_bits;
struct page *page = NULL;
int ret;
 
@@ -358,18 +386,19 @@ static struct page *__dma_alloc_from_contiguous(struct 
cma *cma, 

[PATCH v2 10/10] mm, cma: use spinlock instead of mutex

2014-06-11 Thread Joonsoo Kim
Currently, we should take the mutex for manipulating bitmap.
This job may be really simple and short so we don't need to sleep
if contended. So I change it to spinlock.

Signed-off-by: Joonsoo Kim iamjoonsoo@lge.com

diff --git a/mm/cma.c b/mm/cma.c
index 22a5b23..3085e8c 100644
--- a/mm/cma.c
+++ b/mm/cma.c
@@ -27,6 +27,7 @@
 #include linux/memblock.h
 #include linux/err.h
 #include linux/mm.h
+#include linux/spinlock.h
 #include linux/mutex.h
 #include linux/sizes.h
 #include linux/slab.h
@@ -36,7 +37,7 @@ struct cma {
unsigned long   count;
unsigned long   *bitmap;
int order_per_bit; /* Order of pages represented by one bit */
-   struct mutexlock;
+   spinlock_t  lock;
 };
 
 /*
@@ -72,9 +73,9 @@ static void clear_cma_bitmap(struct cma *cma, unsigned long 
pfn, int count)
bitmapno = (pfn - cma-base_pfn)  cma-order_per_bit;
nr_bits = cma_bitmap_pages_to_bits(cma, count);
 
-   mutex_lock(cma-lock);
+   spin_lock(cma-lock);
bitmap_clear(cma-bitmap, bitmapno, nr_bits);
-   mutex_unlock(cma-lock);
+   spin_unlock(cma-lock);
 }
 
 static int __init cma_activate_area(struct cma *cma)
@@ -112,7 +113,7 @@ static int __init cma_activate_area(struct cma *cma)
init_cma_reserved_pageblock(pfn_to_page(base_pfn));
} while (--i);
 
-   mutex_init(cma-lock);
+   spin_lock_init(cma-lock);
return 0;
 
 err:
@@ -261,11 +262,11 @@ struct page *cma_alloc(struct cma *cma, int count, 
unsigned int align)
nr_bits = cma_bitmap_pages_to_bits(cma, count);
 
for (;;) {
-   mutex_lock(cma-lock);
+   spin_lock(cma-lock);
bitmapno = bitmap_find_next_zero_area(cma-bitmap,
bitmap_maxno, start, nr_bits, mask);
if (bitmapno = bitmap_maxno) {
-   mutex_unlock(cma-lock);
+   spin_unlock(cma-lock);
break;
}
bitmap_set(cma-bitmap, bitmapno, nr_bits);
@@ -274,7 +275,7 @@ struct page *cma_alloc(struct cma *cma, int count, unsigned 
int align)
 * our exclusive use. If the migration fails we will take the
 * lock again and unmark it.
 */
-   mutex_unlock(cma-lock);
+   spin_unlock(cma-lock);
 
pfn = cma-base_pfn + (bitmapno  cma-order_per_bit);
mutex_lock(cma_mutex);
-- 
1.7.9.5

--
To unsubscribe from this list: send the line unsubscribe kvm-ppc in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v2 04/10] DMA, CMA: support alignment constraint on cma region

2014-06-11 Thread Joonsoo Kim
ppc kvm's cma area management needs alignment constraint on
cma region. So support it to prepare generalization of cma area
management functionality.

Additionally, add some comments which tell us why alignment
constraint is needed on cma region.

Signed-off-by: Joonsoo Kim iamjoonsoo@lge.com

diff --git a/drivers/base/dma-contiguous.c b/drivers/base/dma-contiguous.c
index 8a44c82..bc4c171 100644
--- a/drivers/base/dma-contiguous.c
+++ b/drivers/base/dma-contiguous.c
@@ -32,6 +32,7 @@
 #include linux/swap.h
 #include linux/mm_types.h
 #include linux/dma-contiguous.h
+#include linux/log2.h
 
 struct cma {
unsigned long   base_pfn;
@@ -219,6 +220,7 @@ core_initcall(cma_init_reserved_areas);
  * @size: Size of the reserved area (in bytes),
  * @base: Base address of the reserved area optional, use 0 for any
  * @limit: End address of the reserved memory (optional, 0 for any).
+ * @alignment: Alignment for the contiguous memory area, should be power of 2
  * @res_cma: Pointer to store the created cma region.
  * @fixed: hint about where to place the reserved area
  *
@@ -233,15 +235,15 @@ core_initcall(cma_init_reserved_areas);
  */
 static int __init __dma_contiguous_reserve_area(phys_addr_t size,
phys_addr_t base, phys_addr_t limit,
+   phys_addr_t alignment,
struct cma **res_cma, bool fixed)
 {
struct cma *cma = cma_areas[cma_area_count];
-   phys_addr_t alignment;
int ret = 0;
 
-   pr_debug(%s(size %lx, base %08lx, limit %08lx)\n, __func__,
-(unsigned long)size, (unsigned long)base,
-(unsigned long)limit);
+   pr_debug(%s(size %lx, base %08lx, limit %08lx align_order %08lx)\n,
+   __func__, (unsigned long)size, (unsigned long)base,
+   (unsigned long)limit, (unsigned long)alignment);
 
/* Sanity checks */
if (cma_area_count == ARRAY_SIZE(cma_areas)) {
@@ -253,8 +255,17 @@ static int __init 
__dma_contiguous_reserve_area(phys_addr_t size,
if (!size)
return -EINVAL;
 
-   /* Sanitise input arguments */
-   alignment = PAGE_SIZE  max(MAX_ORDER - 1, pageblock_order);
+   if (alignment  !is_power_of_2(alignment))
+   return -EINVAL;
+
+   /*
+* Sanitise input arguments.
+* CMA area should be at least MAX_ORDER - 1 aligned. Otherwise,
+* CMA area could be merged into other MIGRATE_TYPE by buddy mechanism
+* and CMA property will be broken.
+*/
+   alignment = max(alignment,
+   (phys_addr_t)PAGE_SIZE  max(MAX_ORDER - 1, pageblock_order));
base = ALIGN(base, alignment);
size = ALIGN(size, alignment);
limit = ~(alignment - 1);
@@ -302,7 +313,8 @@ int __init dma_contiguous_reserve_area(phys_addr_t size, 
phys_addr_t base,
 {
int ret;
 
-   ret = __dma_contiguous_reserve_area(size, base, limit, res_cma, fixed);
+   ret = __dma_contiguous_reserve_area(size, base, limit, 0,
+   res_cma, fixed);
if (ret)
return ret;
 
-- 
1.7.9.5

--
To unsubscribe from this list: send the line unsubscribe kvm-ppc in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v2 08/10] mm, cma: clean-up cma allocation error path

2014-06-11 Thread Joonsoo Kim
We can remove one call sites for clear_cma_bitmap() if we first
call it before checking error number.

Signed-off-by: Joonsoo Kim iamjoonsoo@lge.com

diff --git a/mm/cma.c b/mm/cma.c
index 1e1b017..01a0713 100644
--- a/mm/cma.c
+++ b/mm/cma.c
@@ -282,11 +282,12 @@ struct page *cma_alloc(struct cma *cma, int count, 
unsigned int align)
if (ret == 0) {
page = pfn_to_page(pfn);
break;
-   } else if (ret != -EBUSY) {
-   clear_cma_bitmap(cma, pfn, count);
-   break;
}
+
clear_cma_bitmap(cma, pfn, count);
+   if (ret != -EBUSY)
+   break;
+
pr_debug(%s(): memory range at %p is busy, retrying\n,
 __func__, pfn_to_page(pfn));
/* try again with a bit different memory target */
-- 
1.7.9.5

--
To unsubscribe from this list: send the line unsubscribe kvm-ppc in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v2 07/10] PPC, KVM, CMA: use general CMA reserved area management framework

2014-06-11 Thread Joonsoo Kim
Now, we have general CMA reserved area management framework,
so use it for future maintainabilty. There is no functional change.

Acked-by: Michal Nazarewicz min...@mina86.com
Acked-by: Paolo Bonzini pbonz...@redhat.com
Signed-off-by: Joonsoo Kim iamjoonsoo@lge.com

diff --git a/arch/powerpc/kvm/book3s_hv_builtin.c 
b/arch/powerpc/kvm/book3s_hv_builtin.c
index 7cde8a6..28ec226 100644
--- a/arch/powerpc/kvm/book3s_hv_builtin.c
+++ b/arch/powerpc/kvm/book3s_hv_builtin.c
@@ -16,12 +16,14 @@
 #include linux/init.h
 #include linux/memblock.h
 #include linux/sizes.h
+#include linux/cma.h
 
 #include asm/cputable.h
 #include asm/kvm_ppc.h
 #include asm/kvm_book3s.h
 
-#include book3s_hv_cma.h
+#define KVM_CMA_CHUNK_ORDER18
+
 /*
  * Hash page table alignment on newer cpus(CPU_FTR_ARCH_206)
  * should be power of 2.
@@ -43,6 +45,8 @@ static unsigned long kvm_cma_resv_ratio = 5;
 unsigned long kvm_rma_pages = (1  27)  PAGE_SHIFT; /* 128MB */
 EXPORT_SYMBOL_GPL(kvm_rma_pages);
 
+static struct cma *kvm_cma;
+
 /* Work out RMLS (real mode limit selector) field value for a given RMA size.
Assumes POWER7 or PPC970. */
 static inline int lpcr_rmls(unsigned long rma_size)
@@ -97,7 +101,7 @@ struct kvm_rma_info *kvm_alloc_rma()
ri = kmalloc(sizeof(struct kvm_rma_info), GFP_KERNEL);
if (!ri)
return NULL;
-   page = kvm_alloc_cma(kvm_rma_pages, kvm_rma_pages);
+   page = cma_alloc(kvm_cma, kvm_rma_pages, get_order(kvm_rma_pages));
if (!page)
goto err_out;
atomic_set(ri-use_count, 1);
@@ -112,7 +116,7 @@ EXPORT_SYMBOL_GPL(kvm_alloc_rma);
 void kvm_release_rma(struct kvm_rma_info *ri)
 {
if (atomic_dec_and_test(ri-use_count)) {
-   kvm_release_cma(pfn_to_page(ri-base_pfn), kvm_rma_pages);
+   cma_release(kvm_cma, pfn_to_page(ri-base_pfn), kvm_rma_pages);
kfree(ri);
}
 }
@@ -134,13 +138,13 @@ struct page *kvm_alloc_hpt(unsigned long nr_pages)
/* Old CPUs require HPT aligned on a multiple of its size */
if (!cpu_has_feature(CPU_FTR_ARCH_206))
align_pages = nr_pages;
-   return kvm_alloc_cma(nr_pages, align_pages);
+   return cma_alloc(kvm_cma, nr_pages, get_order(align_pages));
 }
 EXPORT_SYMBOL_GPL(kvm_alloc_hpt);
 
 void kvm_release_hpt(struct page *page, unsigned long nr_pages)
 {
-   kvm_release_cma(page, nr_pages);
+   cma_release(kvm_cma, page, nr_pages);
 }
 EXPORT_SYMBOL_GPL(kvm_release_hpt);
 
@@ -179,7 +183,8 @@ void __init kvm_cma_reserve(void)
align_size = HPT_ALIGN_PAGES  PAGE_SHIFT;
 
align_size = max(kvm_rma_pages  PAGE_SHIFT, align_size);
-   kvm_cma_declare_contiguous(selected_size, align_size);
+   cma_declare_contiguous(selected_size, 0, 0, align_size,
+   KVM_CMA_CHUNK_ORDER - PAGE_SHIFT, kvm_cma, false);
}
 }
 
diff --git a/arch/powerpc/kvm/book3s_hv_cma.c b/arch/powerpc/kvm/book3s_hv_cma.c
deleted file mode 100644
index d9d3d85..000
--- a/arch/powerpc/kvm/book3s_hv_cma.c
+++ /dev/null
@@ -1,240 +0,0 @@
-/*
- * Contiguous Memory Allocator for ppc KVM hash pagetable  based on CMA
- * for DMA mapping framework
- *
- * Copyright IBM Corporation, 2013
- * Author Aneesh Kumar K.V aneesh.ku...@linux.vnet.ibm.com
- *
- * 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 optional) any later version of the license.
- *
- */
-#define pr_fmt(fmt) kvm_cma:  fmt
-
-#ifdef CONFIG_CMA_DEBUG
-#ifndef DEBUG
-#  define DEBUG
-#endif
-#endif
-
-#include linux/memblock.h
-#include linux/mutex.h
-#include linux/sizes.h
-#include linux/slab.h
-
-#include book3s_hv_cma.h
-
-struct kvm_cma {
-   unsigned long   base_pfn;
-   unsigned long   count;
-   unsigned long   *bitmap;
-};
-
-static DEFINE_MUTEX(kvm_cma_mutex);
-static struct kvm_cma kvm_cma_area;
-
-/**
- * kvm_cma_declare_contiguous() - reserve area for contiguous memory handling
- *   for kvm hash pagetable
- * @size:  Size of the reserved memory.
- * @alignment:  Alignment for the contiguous memory area
- *
- * This function reserves memory for kvm cma area. It should be
- * called by arch code when early allocator (memblock or bootmem)
- * is still activate.
- */
-long __init kvm_cma_declare_contiguous(phys_addr_t size, phys_addr_t alignment)
-{
-   long base_pfn;
-   phys_addr_t addr;
-   struct kvm_cma *cma = kvm_cma_area;
-
-   pr_debug(%s(size %lx)\n, __func__, (unsigned long)size);
-
-   if (!size)
-   return -EINVAL;
-   /*
-* Sanitise input arguments.
-* We should be pageblock aligned for CMA.
-*/
-   alignment = max(alignment, (phys_addr_t)(PAGE_SIZE  pageblock_order));
-   size = ALIGN(size, alignment);

[PATCH v2 01/10] DMA, CMA: clean-up log message

2014-06-11 Thread Joonsoo Kim
We don't need explicit 'CMA:' prefix, since we already define prefix
'cma:' in pr_fmt. So remove it.

And, some logs print function name and others doesn't. This looks
bad to me, so I unify log format to print function name consistently.

Lastly, I add one more debug log on cma_activate_area().

Signed-off-by: Joonsoo Kim iamjoonsoo@lge.com

diff --git a/drivers/base/dma-contiguous.c b/drivers/base/dma-contiguous.c
index 83969f8..bd0bb81 100644
--- a/drivers/base/dma-contiguous.c
+++ b/drivers/base/dma-contiguous.c
@@ -144,7 +144,7 @@ void __init dma_contiguous_reserve(phys_addr_t limit)
}
 
if (selected_size  !dma_contiguous_default_area) {
-   pr_debug(%s: reserving %ld MiB for global area\n, __func__,
+   pr_debug(%s(): reserving %ld MiB for global area\n, __func__,
 (unsigned long)selected_size / SZ_1M);
 
dma_contiguous_reserve_area(selected_size, selected_base,
@@ -163,8 +163,9 @@ static int __init cma_activate_area(struct cma *cma)
unsigned i = cma-count  pageblock_order;
struct zone *zone;
 
-   cma-bitmap = kzalloc(bitmap_size, GFP_KERNEL);
+   pr_debug(%s()\n, __func__);
 
+   cma-bitmap = kzalloc(bitmap_size, GFP_KERNEL);
if (!cma-bitmap)
return -ENOMEM;
 
@@ -234,7 +235,8 @@ int __init dma_contiguous_reserve_area(phys_addr_t size, 
phys_addr_t base,
 
/* Sanity checks */
if (cma_area_count == ARRAY_SIZE(cma_areas)) {
-   pr_err(Not enough slots for CMA reserved regions!\n);
+   pr_err(%s(): Not enough slots for CMA reserved regions!\n,
+   __func__);
return -ENOSPC;
}
 
@@ -274,14 +276,15 @@ int __init dma_contiguous_reserve_area(phys_addr_t size, 
phys_addr_t base,
*res_cma = cma;
cma_area_count++;
 
-   pr_info(CMA: reserved %ld MiB at %08lx\n, (unsigned long)size / SZ_1M,
-   (unsigned long)base);
+   pr_info(%s(): reserved %ld MiB at %08lx\n,
+   __func__, (unsigned long)size / SZ_1M, (unsigned long)base);
 
/* Architecture specific contiguous memory fixup. */
dma_contiguous_early_fixup(base, size);
return 0;
 err:
-   pr_err(CMA: failed to reserve %ld MiB\n, (unsigned long)size / SZ_1M);
+   pr_err(%s(): failed to reserve %ld MiB\n,
+   __func__, (unsigned long)size / SZ_1M);
return ret;
 }
 
-- 
1.7.9.5

--
To unsubscribe from this list: send the line unsubscribe kvm-ppc in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v2 09/10] mm, cma: move output param to the end of param list

2014-06-11 Thread Joonsoo Kim
Conventionally, we put output param to the end of param list.
cma_declare_contiguous() doesn't look like that, so change it.

Additionally, move down cma_areas reference code to the position
where it is really needed.

Signed-off-by: Joonsoo Kim iamjoonsoo@lge.com

diff --git a/arch/powerpc/kvm/book3s_hv_builtin.c 
b/arch/powerpc/kvm/book3s_hv_builtin.c
index 28ec226..97613ea 100644
--- a/arch/powerpc/kvm/book3s_hv_builtin.c
+++ b/arch/powerpc/kvm/book3s_hv_builtin.c
@@ -184,7 +184,7 @@ void __init kvm_cma_reserve(void)
 
align_size = max(kvm_rma_pages  PAGE_SHIFT, align_size);
cma_declare_contiguous(selected_size, 0, 0, align_size,
-   KVM_CMA_CHUNK_ORDER - PAGE_SHIFT, kvm_cma, false);
+   KVM_CMA_CHUNK_ORDER - PAGE_SHIFT, false, kvm_cma);
}
 }
 
diff --git a/drivers/base/dma-contiguous.c b/drivers/base/dma-contiguous.c
index f177f73..bfd4553 100644
--- a/drivers/base/dma-contiguous.c
+++ b/drivers/base/dma-contiguous.c
@@ -149,7 +149,7 @@ int __init dma_contiguous_reserve_area(phys_addr_t size, 
phys_addr_t base,
 {
int ret;
 
-   ret = cma_declare_contiguous(size, base, limit, 0, 0, res_cma, fixed);
+   ret = cma_declare_contiguous(size, base, limit, 0, 0, fixed, res_cma);
if (ret)
return ret;
 
diff --git a/include/linux/cma.h b/include/linux/cma.h
index e38efe9..e53eead 100644
--- a/include/linux/cma.h
+++ b/include/linux/cma.h
@@ -6,7 +6,7 @@ struct cma;
 extern int __init cma_declare_contiguous(phys_addr_t size,
phys_addr_t base, phys_addr_t limit,
phys_addr_t alignment, int order_per_bit,
-   struct cma **res_cma, bool fixed);
+   bool fixed, struct cma **res_cma);
 extern struct page *cma_alloc(struct cma *cma, int count, unsigned int align);
 extern bool cma_release(struct cma *cma, struct page *pages, int count);
 #endif
diff --git a/mm/cma.c b/mm/cma.c
index 01a0713..22a5b23 100644
--- a/mm/cma.c
+++ b/mm/cma.c
@@ -142,8 +142,8 @@ core_initcall(cma_init_reserved_areas);
  * @limit: End address of the reserved memory (optional, 0 for any).
  * @alignment: Alignment for the contiguous memory area, should be power of 2
  * @order_per_bit: Order of pages represented by one bit on bitmap.
- * @res_cma: Pointer to store the created cma region.
  * @fixed: hint about where to place the reserved area
+ * @res_cma: Pointer to store the created cma region.
  *
  * This function reserves memory from early allocator. It should be
  * called by arch specific code once the early allocator (memblock or bootmem)
@@ -156,9 +156,9 @@ core_initcall(cma_init_reserved_areas);
 int __init cma_declare_contiguous(phys_addr_t size,
phys_addr_t base, phys_addr_t limit,
phys_addr_t alignment, int order_per_bit,
-   struct cma **res_cma, bool fixed)
+   bool fixed, struct cma **res_cma)
 {
-   struct cma *cma = cma_areas[cma_area_count];
+   struct cma *cma;
int ret = 0;
 
pr_debug(%s(size %lx, base %08lx, limit %08lx alignment %08lx)\n,
@@ -214,6 +214,7 @@ int __init cma_declare_contiguous(phys_addr_t size,
 * Each reserved area must be initialised later, when more kernel
 * subsystems (like slab allocator) are available.
 */
+   cma = cma_areas[cma_area_count];
cma-base_pfn = PFN_DOWN(base);
cma-count = size  PAGE_SHIFT;
cma-order_per_bit = order_per_bit;
-- 
1.7.9.5

--
To unsubscribe from this list: send the line unsubscribe kvm-ppc in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v2 03/10] DMA, CMA: separate core cma management codes from DMA APIs

2014-06-11 Thread Joonsoo Kim
To prepare future generalization work on cma area management code,
we need to separate core cma management codes from DMA APIs.
We will extend these core functions to cover requirements of
ppc kvm's cma area management functionality in following patches.
This separation helps us not to touch DMA APIs while extending
core functions.

Signed-off-by: Joonsoo Kim iamjoonsoo@lge.com

diff --git a/drivers/base/dma-contiguous.c b/drivers/base/dma-contiguous.c
index fb0cdce..8a44c82 100644
--- a/drivers/base/dma-contiguous.c
+++ b/drivers/base/dma-contiguous.c
@@ -231,9 +231,9 @@ core_initcall(cma_init_reserved_areas);
  * If @fixed is true, reserve contiguous area at exactly @base.  If false,
  * reserve in range from @base to @limit.
  */
-int __init dma_contiguous_reserve_area(phys_addr_t size, phys_addr_t base,
-  phys_addr_t limit, struct cma **res_cma,
-  bool fixed)
+static int __init __dma_contiguous_reserve_area(phys_addr_t size,
+   phys_addr_t base, phys_addr_t limit,
+   struct cma **res_cma, bool fixed)
 {
struct cma *cma = cma_areas[cma_area_count];
phys_addr_t alignment;
@@ -288,16 +288,30 @@ int __init dma_contiguous_reserve_area(phys_addr_t size, 
phys_addr_t base,
 
pr_info(%s(): reserved %ld MiB at %08lx\n,
__func__, (unsigned long)size / SZ_1M, (unsigned long)base);
-
-   /* Architecture specific contiguous memory fixup. */
-   dma_contiguous_early_fixup(base, size);
return 0;
+
 err:
pr_err(%s(): failed to reserve %ld MiB\n,
__func__, (unsigned long)size / SZ_1M);
return ret;
 }
 
+int __init dma_contiguous_reserve_area(phys_addr_t size, phys_addr_t base,
+  phys_addr_t limit, struct cma **res_cma,
+  bool fixed)
+{
+   int ret;
+
+   ret = __dma_contiguous_reserve_area(size, base, limit, res_cma, fixed);
+   if (ret)
+   return ret;
+
+   /* Architecture specific contiguous memory fixup. */
+   dma_contiguous_early_fixup(base, size);
+
+   return 0;
+}
+
 static void clear_cma_bitmap(struct cma *cma, unsigned long pfn, int count)
 {
mutex_lock(cma-lock);
@@ -316,20 +330,16 @@ static void clear_cma_bitmap(struct cma *cma, unsigned 
long pfn, int count)
  * global one. Requires architecture specific dev_get_cma_area() helper
  * function.
  */
-struct page *dma_alloc_from_contiguous(struct device *dev, int count,
+static struct page *__dma_alloc_from_contiguous(struct cma *cma, int count,
   unsigned int align)
 {
unsigned long mask, pfn, pageno, start = 0;
-   struct cma *cma = dev_get_cma_area(dev);
struct page *page = NULL;
int ret;
 
if (!cma || !cma-count)
return NULL;
 
-   if (align  CONFIG_CMA_ALIGNMENT)
-   align = CONFIG_CMA_ALIGNMENT;
-
pr_debug(%s(cma %p, count %d, align %d)\n, __func__, (void *)cma,
 count, align);
 
@@ -377,6 +387,17 @@ struct page *dma_alloc_from_contiguous(struct device *dev, 
int count,
return page;
 }
 
+struct page *dma_alloc_from_contiguous(struct device *dev, int count,
+  unsigned int align)
+{
+   struct cma *cma = dev_get_cma_area(dev);
+
+   if (align  CONFIG_CMA_ALIGNMENT)
+   align = CONFIG_CMA_ALIGNMENT;
+
+   return __dma_alloc_from_contiguous(cma, count, align);
+}
+
 /**
  * dma_release_from_contiguous() - release allocated pages
  * @dev:   Pointer to device for which the pages were allocated.
@@ -387,10 +408,9 @@ struct page *dma_alloc_from_contiguous(struct device *dev, 
int count,
  * It returns false when provided pages do not belong to contiguous area and
  * true otherwise.
  */
-bool dma_release_from_contiguous(struct device *dev, struct page *pages,
+static bool __dma_release_from_contiguous(struct cma *cma, struct page *pages,
 int count)
 {
-   struct cma *cma = dev_get_cma_area(dev);
unsigned long pfn;
 
if (!cma || !pages)
@@ -410,3 +430,11 @@ bool dma_release_from_contiguous(struct device *dev, 
struct page *pages,
 
return true;
 }
+
+bool dma_release_from_contiguous(struct device *dev, struct page *pages,
+int count)
+{
+   struct cma *cma = dev_get_cma_area(dev);
+
+   return __dma_release_from_contiguous(cma, pages, count);
+}
-- 
1.7.9.5

--
To unsubscribe from this list: send the line unsubscribe kvm-ppc in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v2 00/10] CMA: generalize CMA reserved area management code

2014-06-11 Thread Joonsoo Kim
Currently, there are two users on CMA functionality, one is the DMA
subsystem and the other is the kvm on powerpc. They have their own code
to manage CMA reserved area even if they looks really similar.
From my guess, it is caused by some needs on bitmap management. Kvm side
wants to maintain bitmap not for 1 page, but for more size. Eventually it
use bitmap where one bit represents 64 pages.

When I implement CMA related patches, I should change those two places
to apply my change and it seem to be painful to me. I want to change
this situation and reduce future code management overhead through
this patch.

This change could also help developer who want to use CMA in their
new feature development, since they can use CMA easily without
copying  pasting this reserved area management code.

v2:
  Although this patchset looks very different with v1, the end result,
  that is, mm/cma.c is same with v1's one. So I carry Ack to patch 6-7.

Patch 1-5 prepare some features to cover ppc kvm's requirements.
Patch 6-7 generalize CMA reserved area management code and change users
to use it.
Patch 8-10 clean-up minor things.

Joonsoo Kim (10):
  DMA, CMA: clean-up log message
  DMA, CMA: fix possible memory leak
  DMA, CMA: separate core cma management codes from DMA APIs
  DMA, CMA: support alignment constraint on cma region
  DMA, CMA: support arbitrary bitmap granularity
  CMA: generalize CMA reserved area management functionality
  PPC, KVM, CMA: use general CMA reserved area management framework
  mm, cma: clean-up cma allocation error path
  mm, cma: move output param to the end of param list
  mm, cma: use spinlock instead of mutex

 arch/powerpc/kvm/book3s_hv_builtin.c |   17 +-
 arch/powerpc/kvm/book3s_hv_cma.c |  240 
 arch/powerpc/kvm/book3s_hv_cma.h |   27 ---
 drivers/base/Kconfig |   10 -
 drivers/base/dma-contiguous.c|  248 ++---
 include/linux/cma.h  |   12 ++
 include/linux/dma-contiguous.h   |3 +-
 mm/Kconfig   |   11 ++
 mm/Makefile  |1 +
 mm/cma.c |  333 ++
 10 files changed, 382 insertions(+), 520 deletions(-)
 delete mode 100644 arch/powerpc/kvm/book3s_hv_cma.c
 delete mode 100644 arch/powerpc/kvm/book3s_hv_cma.h
 create mode 100644 include/linux/cma.h
 create mode 100644 mm/cma.c

-- 
1.7.9.5

--
To unsubscribe from this list: send the line unsubscribe kvm-ppc in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] KVM: PPC: Book3s PR: Disable AIL mode with OPAL

2014-06-11 Thread Paul Mackerras
On Tue, Jun 10, 2014 at 07:23:00PM +0200, Alexander Graf wrote:
 When we're using PR KVM we must not allow the CPU to take interrupts
 in virtual mode, as the SLB does not contain host kernel mappings
 when running inside the guest context.
 
 To make sure we get good performance for non-KVM tasks but still
 properly functioning PR KVM, let's just disable AIL whenever a vcpu
 is scheduled in.
 
 This patch fixes running PR KVM on POWER8 bare metal for me.

We already handle this for the situation where we're running under a
hypervisor with the calls to pSeries_disable_reloc_on_exc() and
pSeries_enable_reloc_on_exc() in kvmppc_core_init_vm_pr() and
kvmppc_core_destroy_vm_pr() respectively.

The obvious approach to fixing this problem would be to generalize
those calls, perhaps via a ppc_md callback, to work on the powernv
platform too.  If you don't want to do that, for instance because
those calls are defined to operate across the whole machine rather
than a single CPU thread, and you prefer to affect just the one thread
we're running on, then I think you need to explain that in the commit
message.

Regards,
Paul.
--
To unsubscribe from this list: send the line unsubscribe kvm-ppc in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] KVM: PPC: Book3s HV: Fix tlbie compile error

2014-06-11 Thread Paul Mackerras
On Wed, Jun 11, 2014 at 05:16:02PM +0200, Alexander Graf wrote:
 Some compilers complain about uninitialized variables in the compute_tlbie_rb
 function. When you follow the code path you'll realize that we'll never get
 to that point, but the compiler isn't all that smart.
 
 So just default to 4k page sizes for everything, making the compiler happy
 and the code slightly easier to read.
 
 Signed-off-by: Alexander Graf ag...@suse.de

Acked-by: Paul Mackerras pau...@samba.org
--
To unsubscribe from this list: send the line unsubscribe kvm-ppc in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v2 01/10] DMA, CMA: clean-up log message

2014-06-11 Thread Aneesh Kumar K.V
Joonsoo Kim iamjoonsoo@lge.com writes:

 We don't need explicit 'CMA:' prefix, since we already define prefix
 'cma:' in pr_fmt. So remove it.

 And, some logs print function name and others doesn't. This looks
 bad to me, so I unify log format to print function name consistently.

 Lastly, I add one more debug log on cma_activate_area().

 Signed-off-by: Joonsoo Kim iamjoonsoo@lge.com

 diff --git a/drivers/base/dma-contiguous.c b/drivers/base/dma-contiguous.c
 index 83969f8..bd0bb81 100644
 --- a/drivers/base/dma-contiguous.c
 +++ b/drivers/base/dma-contiguous.c
 @@ -144,7 +144,7 @@ void __init dma_contiguous_reserve(phys_addr_t limit)
   }

   if (selected_size  !dma_contiguous_default_area) {
 - pr_debug(%s: reserving %ld MiB for global area\n, __func__,
 + pr_debug(%s(): reserving %ld MiB for global area\n, __func__,
(unsigned long)selected_size / SZ_1M);

Do we need to do function(), or just function:. I have seen the later
usage in other parts of the kernel.


   dma_contiguous_reserve_area(selected_size, selected_base,
 @@ -163,8 +163,9 @@ static int __init cma_activate_area(struct cma *cma)
   unsigned i = cma-count  pageblock_order;
   struct zone *zone;

 - cma-bitmap = kzalloc(bitmap_size, GFP_KERNEL);
 + pr_debug(%s()\n, __func__);

why ?


 + cma-bitmap = kzalloc(bitmap_size, GFP_KERNEL);
   if (!cma-bitmap)
   return -ENOMEM;

 @@ -234,7 +235,8 @@ int __init dma_contiguous_reserve_area(phys_addr_t size, 
 phys_addr_t base,

   /* Sanity checks */
   if (cma_area_count == ARRAY_SIZE(cma_areas)) {
 - pr_err(Not enough slots for CMA reserved regions!\n);
 + pr_err(%s(): Not enough slots for CMA reserved regions!\n,
 + __func__);
   return -ENOSPC;
   }

 @@ -274,14 +276,15 @@ int __init dma_contiguous_reserve_area(phys_addr_t 
 size, phys_addr_t base,
   *res_cma = cma;
   cma_area_count++;

 - pr_info(CMA: reserved %ld MiB at %08lx\n, (unsigned long)size / SZ_1M,
 - (unsigned long)base);
 + pr_info(%s(): reserved %ld MiB at %08lx\n,
 + __func__, (unsigned long)size / SZ_1M, (unsigned long)base);

   /* Architecture specific contiguous memory fixup. */
   dma_contiguous_early_fixup(base, size);
   return 0;
  err:
 - pr_err(CMA: failed to reserve %ld MiB\n, (unsigned long)size / SZ_1M);
 + pr_err(%s(): failed to reserve %ld MiB\n,
 + __func__, (unsigned long)size / SZ_1M);
   return ret;
  }

 -- 
 1.7.9.5

--
To unsubscribe from this list: send the line unsubscribe kvm-ppc in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v2 02/10] DMA, CMA: fix possible memory leak

2014-06-11 Thread Aneesh Kumar K.V
Joonsoo Kim iamjoonsoo@lge.com writes:

 We should free memory for bitmap when we find zone mis-match,
 otherwise this memory will leak.

 Additionally, I copy code comment from ppc kvm's cma code to notify
 why we need to check zone mis-match.

 Signed-off-by: Joonsoo Kim iamjoonsoo@lge.com

Reviewed-by: Aneesh Kumar K.V aneesh.ku...@linux.vnet.ibm.com


 diff --git a/drivers/base/dma-contiguous.c b/drivers/base/dma-contiguous.c
 index bd0bb81..fb0cdce 100644
 --- a/drivers/base/dma-contiguous.c
 +++ b/drivers/base/dma-contiguous.c
 @@ -177,14 +177,24 @@ static int __init cma_activate_area(struct cma *cma)
   base_pfn = pfn;
   for (j = pageblock_nr_pages; j; --j, pfn++) {
   WARN_ON_ONCE(!pfn_valid(pfn));
 + /*
 +  * alloc_contig_range requires the pfn range
 +  * specified to be in the same zone. Make this
 +  * simple by forcing the entire CMA resv range
 +  * to be in the same zone.
 +  */
   if (page_zone(pfn_to_page(pfn)) != zone)
 - return -EINVAL;
 + goto err;
   }
   init_cma_reserved_pageblock(pfn_to_page(base_pfn));
   } while (--i);

   mutex_init(cma-lock);
   return 0;
 +
 +err:
 + kfree(cma-bitmap);
 + return -EINVAL;
  }

  static struct cma cma_areas[MAX_CMA_AREAS];
 -- 
 1.7.9.5

--
To unsubscribe from this list: send the line unsubscribe kvm-ppc in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v2 03/10] DMA, CMA: separate core cma management codes from DMA APIs

2014-06-11 Thread Aneesh Kumar K.V
Joonsoo Kim iamjoonsoo@lge.com writes:

 To prepare future generalization work on cma area management code,
 we need to separate core cma management codes from DMA APIs.
 We will extend these core functions to cover requirements of
 ppc kvm's cma area management functionality in following patches.
 This separation helps us not to touch DMA APIs while extending
 core functions.

 Signed-off-by: Joonsoo Kim iamjoonsoo@lge.com

Reviewed-by: Aneesh Kumar K.V aneesh.ku...@linux.vnet.ibm.com


 diff --git a/drivers/base/dma-contiguous.c b/drivers/base/dma-contiguous.c
 index fb0cdce..8a44c82 100644
 --- a/drivers/base/dma-contiguous.c
 +++ b/drivers/base/dma-contiguous.c
 @@ -231,9 +231,9 @@ core_initcall(cma_init_reserved_areas);
   * If @fixed is true, reserve contiguous area at exactly @base.  If false,
   * reserve in range from @base to @limit.
   */
 -int __init dma_contiguous_reserve_area(phys_addr_t size, phys_addr_t base,
 -phys_addr_t limit, struct cma **res_cma,
 -bool fixed)
 +static int __init __dma_contiguous_reserve_area(phys_addr_t size,
 + phys_addr_t base, phys_addr_t limit,
 + struct cma **res_cma, bool fixed)
  {
   struct cma *cma = cma_areas[cma_area_count];
   phys_addr_t alignment;
 @@ -288,16 +288,30 @@ int __init dma_contiguous_reserve_area(phys_addr_t 
 size, phys_addr_t base,

   pr_info(%s(): reserved %ld MiB at %08lx\n,
   __func__, (unsigned long)size / SZ_1M, (unsigned long)base);
 -
 - /* Architecture specific contiguous memory fixup. */
 - dma_contiguous_early_fixup(base, size);
   return 0;
 +
  err:
   pr_err(%s(): failed to reserve %ld MiB\n,
   __func__, (unsigned long)size / SZ_1M);
   return ret;
  }

 +int __init dma_contiguous_reserve_area(phys_addr_t size, phys_addr_t base,
 +phys_addr_t limit, struct cma **res_cma,
 +bool fixed)
 +{
 + int ret;
 +
 + ret = __dma_contiguous_reserve_area(size, base, limit, res_cma, fixed);
 + if (ret)
 + return ret;
 +
 + /* Architecture specific contiguous memory fixup. */
 + dma_contiguous_early_fixup(base, size);
 +
 + return 0;
 +}
 +
  static void clear_cma_bitmap(struct cma *cma, unsigned long pfn, int count)
  {
   mutex_lock(cma-lock);
 @@ -316,20 +330,16 @@ static void clear_cma_bitmap(struct cma *cma, unsigned 
 long pfn, int count)
   * global one. Requires architecture specific dev_get_cma_area() helper
   * function.
   */
 -struct page *dma_alloc_from_contiguous(struct device *dev, int count,
 +static struct page *__dma_alloc_from_contiguous(struct cma *cma, int count,
  unsigned int align)
  {
   unsigned long mask, pfn, pageno, start = 0;
 - struct cma *cma = dev_get_cma_area(dev);
   struct page *page = NULL;
   int ret;

   if (!cma || !cma-count)
   return NULL;

 - if (align  CONFIG_CMA_ALIGNMENT)
 - align = CONFIG_CMA_ALIGNMENT;
 -
   pr_debug(%s(cma %p, count %d, align %d)\n, __func__, (void *)cma,
count, align);

 @@ -377,6 +387,17 @@ struct page *dma_alloc_from_contiguous(struct device 
 *dev, int count,
   return page;
  }

 +struct page *dma_alloc_from_contiguous(struct device *dev, int count,
 +unsigned int align)
 +{
 + struct cma *cma = dev_get_cma_area(dev);
 +
 + if (align  CONFIG_CMA_ALIGNMENT)
 + align = CONFIG_CMA_ALIGNMENT;
 +
 + return __dma_alloc_from_contiguous(cma, count, align);
 +}
 +
  /**
   * dma_release_from_contiguous() - release allocated pages
   * @dev:   Pointer to device for which the pages were allocated.
 @@ -387,10 +408,9 @@ struct page *dma_alloc_from_contiguous(struct device 
 *dev, int count,
   * It returns false when provided pages do not belong to contiguous area and
   * true otherwise.
   */
 -bool dma_release_from_contiguous(struct device *dev, struct page *pages,
 +static bool __dma_release_from_contiguous(struct cma *cma, struct page 
 *pages,
int count)
  {
 - struct cma *cma = dev_get_cma_area(dev);
   unsigned long pfn;

   if (!cma || !pages)
 @@ -410,3 +430,11 @@ bool dma_release_from_contiguous(struct device *dev, 
 struct page *pages,

   return true;
  }
 +
 +bool dma_release_from_contiguous(struct device *dev, struct page *pages,
 +  int count)
 +{
 + struct cma *cma = dev_get_cma_area(dev);
 +
 + return __dma_release_from_contiguous(cma, pages, count);
 +}
 -- 
 1.7.9.5

--
To unsubscribe from this list: send the line unsubscribe kvm-ppc in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v2 04/10] DMA, CMA: support alignment constraint on cma region

2014-06-11 Thread Aneesh Kumar K.V
Joonsoo Kim iamjoonsoo@lge.com writes:

 ppc kvm's cma area management needs alignment constraint on
 cma region. So support it to prepare generalization of cma area
 management functionality.

 Additionally, add some comments which tell us why alignment
 constraint is needed on cma region.

 Signed-off-by: Joonsoo Kim iamjoonsoo@lge.com

Reviewed-by: Aneesh Kumar K.V aneesh.ku...@linux.vnet.ibm.com


 diff --git a/drivers/base/dma-contiguous.c b/drivers/base/dma-contiguous.c
 index 8a44c82..bc4c171 100644
 --- a/drivers/base/dma-contiguous.c
 +++ b/drivers/base/dma-contiguous.c
 @@ -32,6 +32,7 @@
  #include linux/swap.h
  #include linux/mm_types.h
  #include linux/dma-contiguous.h
 +#include linux/log2.h

  struct cma {
   unsigned long   base_pfn;
 @@ -219,6 +220,7 @@ core_initcall(cma_init_reserved_areas);
   * @size: Size of the reserved area (in bytes),
   * @base: Base address of the reserved area optional, use 0 for any
   * @limit: End address of the reserved memory (optional, 0 for any).
 + * @alignment: Alignment for the contiguous memory area, should be power of 2
   * @res_cma: Pointer to store the created cma region.
   * @fixed: hint about where to place the reserved area
   *
 @@ -233,15 +235,15 @@ core_initcall(cma_init_reserved_areas);
   */
  static int __init __dma_contiguous_reserve_area(phys_addr_t size,
   phys_addr_t base, phys_addr_t limit,
 + phys_addr_t alignment,
   struct cma **res_cma, bool fixed)
  {
   struct cma *cma = cma_areas[cma_area_count];
 - phys_addr_t alignment;
   int ret = 0;

 - pr_debug(%s(size %lx, base %08lx, limit %08lx)\n, __func__,
 -  (unsigned long)size, (unsigned long)base,
 -  (unsigned long)limit);
 + pr_debug(%s(size %lx, base %08lx, limit %08lx align_order %08lx)\n,
 + __func__, (unsigned long)size, (unsigned long)base,
 + (unsigned long)limit, (unsigned long)alignment);

   /* Sanity checks */
   if (cma_area_count == ARRAY_SIZE(cma_areas)) {
 @@ -253,8 +255,17 @@ static int __init 
 __dma_contiguous_reserve_area(phys_addr_t size,
   if (!size)
   return -EINVAL;

 - /* Sanitise input arguments */
 - alignment = PAGE_SIZE  max(MAX_ORDER - 1, pageblock_order);
 + if (alignment  !is_power_of_2(alignment))
 + return -EINVAL;
 +
 + /*
 +  * Sanitise input arguments.
 +  * CMA area should be at least MAX_ORDER - 1 aligned. Otherwise,
 +  * CMA area could be merged into other MIGRATE_TYPE by buddy mechanism
 +  * and CMA property will be broken.
 +  */
 + alignment = max(alignment,
 + (phys_addr_t)PAGE_SIZE  max(MAX_ORDER - 1, pageblock_order));
   base = ALIGN(base, alignment);
   size = ALIGN(size, alignment);
   limit = ~(alignment - 1);
 @@ -302,7 +313,8 @@ int __init dma_contiguous_reserve_area(phys_addr_t size, 
 phys_addr_t base,
  {
   int ret;

 - ret = __dma_contiguous_reserve_area(size, base, limit, res_cma, fixed);
 + ret = __dma_contiguous_reserve_area(size, base, limit, 0,
 + res_cma, fixed);
   if (ret)
   return ret;

 -- 
 1.7.9.5

--
To unsubscribe from this list: send the line unsubscribe kvm-ppc in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v2 01/10] DMA, CMA: clean-up log message

2014-06-11 Thread Minchan Kim
Hi Joonsoo,

On Thu, Jun 12, 2014 at 12:21:38PM +0900, Joonsoo Kim wrote:
 We don't need explicit 'CMA:' prefix, since we already define prefix
 'cma:' in pr_fmt. So remove it.
 
 And, some logs print function name and others doesn't. This looks
 bad to me, so I unify log format to print function name consistently.
 
 Lastly, I add one more debug log on cma_activate_area().

When I take a look, it just indicates cma_activate_area was called or not,
without what range for the area was reserved successfully so I couldn't see
the intention for new message. Description should explain it so that everybody
can agree on your claim.

 
 Signed-off-by: Joonsoo Kim iamjoonsoo@lge.com
 
 diff --git a/drivers/base/dma-contiguous.c b/drivers/base/dma-contiguous.c
 index 83969f8..bd0bb81 100644
 --- a/drivers/base/dma-contiguous.c
 +++ b/drivers/base/dma-contiguous.c
 @@ -144,7 +144,7 @@ void __init dma_contiguous_reserve(phys_addr_t limit)
   }
  
   if (selected_size  !dma_contiguous_default_area) {
 - pr_debug(%s: reserving %ld MiB for global area\n, __func__,
 + pr_debug(%s(): reserving %ld MiB for global area\n, __func__,
(unsigned long)selected_size / SZ_1M);
  
   dma_contiguous_reserve_area(selected_size, selected_base,
 @@ -163,8 +163,9 @@ static int __init cma_activate_area(struct cma *cma)
   unsigned i = cma-count  pageblock_order;
   struct zone *zone;
  
 - cma-bitmap = kzalloc(bitmap_size, GFP_KERNEL);
 + pr_debug(%s()\n, __func__);
  
 + cma-bitmap = kzalloc(bitmap_size, GFP_KERNEL);
   if (!cma-bitmap)
   return -ENOMEM;
  
 @@ -234,7 +235,8 @@ int __init dma_contiguous_reserve_area(phys_addr_t size, 
 phys_addr_t base,
  
   /* Sanity checks */
   if (cma_area_count == ARRAY_SIZE(cma_areas)) {
 - pr_err(Not enough slots for CMA reserved regions!\n);
 + pr_err(%s(): Not enough slots for CMA reserved regions!\n,
 + __func__);
   return -ENOSPC;
   }
  
 @@ -274,14 +276,15 @@ int __init dma_contiguous_reserve_area(phys_addr_t 
 size, phys_addr_t base,
   *res_cma = cma;
   cma_area_count++;
  
 - pr_info(CMA: reserved %ld MiB at %08lx\n, (unsigned long)size / SZ_1M,
 - (unsigned long)base);
 + pr_info(%s(): reserved %ld MiB at %08lx\n,
 + __func__, (unsigned long)size / SZ_1M, (unsigned long)base);
  
   /* Architecture specific contiguous memory fixup. */
   dma_contiguous_early_fixup(base, size);
   return 0;
  err:
 - pr_err(CMA: failed to reserve %ld MiB\n, (unsigned long)size / SZ_1M);
 + pr_err(%s(): failed to reserve %ld MiB\n,
 + __func__, (unsigned long)size / SZ_1M);
   return ret;
  }
  
 -- 
 1.7.9.5

-- 
Kind regards,
Minchan Kim
--
To unsubscribe from this list: send the line unsubscribe kvm-ppc in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v2 02/10] DMA, CMA: fix possible memory leak

2014-06-11 Thread Minchan Kim
On Thu, Jun 12, 2014 at 12:21:39PM +0900, Joonsoo Kim wrote:
 We should free memory for bitmap when we find zone mis-match,
 otherwise this memory will leak.

Then, -stable stuff?

 
 Additionally, I copy code comment from ppc kvm's cma code to notify
 why we need to check zone mis-match.
 
 Signed-off-by: Joonsoo Kim iamjoonsoo@lge.com
 
 diff --git a/drivers/base/dma-contiguous.c b/drivers/base/dma-contiguous.c
 index bd0bb81..fb0cdce 100644
 --- a/drivers/base/dma-contiguous.c
 +++ b/drivers/base/dma-contiguous.c
 @@ -177,14 +177,24 @@ static int __init cma_activate_area(struct cma *cma)
   base_pfn = pfn;
   for (j = pageblock_nr_pages; j; --j, pfn++) {
   WARN_ON_ONCE(!pfn_valid(pfn));
 + /*
 +  * alloc_contig_range requires the pfn range
 +  * specified to be in the same zone. Make this
 +  * simple by forcing the entire CMA resv range
 +  * to be in the same zone.
 +  */
   if (page_zone(pfn_to_page(pfn)) != zone)
 - return -EINVAL;
 + goto err;

At a first glance, I thought it would be better to handle such error
before activating.
So when I see the registration code(ie, dma_contiguous_revere_area),
I realized it is impossible because we didn't set up zone yet. :(

If so, when we detect to fail here, it would be better to report more
meaningful error message like what was successful zone and what is
new zone and failed pfn number?

   }
   init_cma_reserved_pageblock(pfn_to_page(base_pfn));
   } while (--i);
  
   mutex_init(cma-lock);
   return 0;
 +
 +err:
 + kfree(cma-bitmap);
 + return -EINVAL;
  }
  
  static struct cma cma_areas[MAX_CMA_AREAS];
 -- 
 1.7.9.5

-- 
Kind regards,
Minchan Kim
--
To unsubscribe from this list: send the line unsubscribe kvm-ppc in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v2 03/10] DMA, CMA: separate core cma management codes from DMA APIs

2014-06-11 Thread Minchan Kim
On Thu, Jun 12, 2014 at 12:21:40PM +0900, Joonsoo Kim wrote:
 To prepare future generalization work on cma area management code,
 we need to separate core cma management codes from DMA APIs.
 We will extend these core functions to cover requirements of
 ppc kvm's cma area management functionality in following patches.
 This separation helps us not to touch DMA APIs while extending
 core functions.
 
 Signed-off-by: Joonsoo Kim iamjoonsoo@lge.com
 
 diff --git a/drivers/base/dma-contiguous.c b/drivers/base/dma-contiguous.c
 index fb0cdce..8a44c82 100644
 --- a/drivers/base/dma-contiguous.c
 +++ b/drivers/base/dma-contiguous.c
 @@ -231,9 +231,9 @@ core_initcall(cma_init_reserved_areas);
   * If @fixed is true, reserve contiguous area at exactly @base.  If false,
   * reserve in range from @base to @limit.
   */
 -int __init dma_contiguous_reserve_area(phys_addr_t size, phys_addr_t base,
 -phys_addr_t limit, struct cma **res_cma,
 -bool fixed)
 +static int __init __dma_contiguous_reserve_area(phys_addr_t size,
 + phys_addr_t base, phys_addr_t limit,
 + struct cma **res_cma, bool fixed)
  {
   struct cma *cma = cma_areas[cma_area_count];
   phys_addr_t alignment;
 @@ -288,16 +288,30 @@ int __init dma_contiguous_reserve_area(phys_addr_t 
 size, phys_addr_t base,
  
   pr_info(%s(): reserved %ld MiB at %08lx\n,
   __func__, (unsigned long)size / SZ_1M, (unsigned long)base);
 -
 - /* Architecture specific contiguous memory fixup. */
 - dma_contiguous_early_fixup(base, size);
   return 0;
 +
  err:
   pr_err(%s(): failed to reserve %ld MiB\n,
   __func__, (unsigned long)size / SZ_1M);
   return ret;
  }
  
 +int __init dma_contiguous_reserve_area(phys_addr_t size, phys_addr_t base,
 +phys_addr_t limit, struct cma **res_cma,
 +bool fixed)
 +{
 + int ret;
 +
 + ret = __dma_contiguous_reserve_area(size, base, limit, res_cma, fixed);
 + if (ret)
 + return ret;
 +
 + /* Architecture specific contiguous memory fixup. */
 + dma_contiguous_early_fixup(base, size);

In old, base and size are aligned with alignment and passed into arch fixup
but your patch is changing it.
I didn't look at what kinds of side effect it makes but just want to confirm.

 +
 + return 0;
 +}
 +
  static void clear_cma_bitmap(struct cma *cma, unsigned long pfn, int count)
  {
   mutex_lock(cma-lock);
 @@ -316,20 +330,16 @@ static void clear_cma_bitmap(struct cma *cma, unsigned 
 long pfn, int count)
   * global one. Requires architecture specific dev_get_cma_area() helper
   * function.
   */
 -struct page *dma_alloc_from_contiguous(struct device *dev, int count,
 +static struct page *__dma_alloc_from_contiguous(struct cma *cma, int count,
  unsigned int align)
  {
   unsigned long mask, pfn, pageno, start = 0;
 - struct cma *cma = dev_get_cma_area(dev);
   struct page *page = NULL;
   int ret;
  
   if (!cma || !cma-count)
   return NULL;
  
 - if (align  CONFIG_CMA_ALIGNMENT)
 - align = CONFIG_CMA_ALIGNMENT;
 -
   pr_debug(%s(cma %p, count %d, align %d)\n, __func__, (void *)cma,
count, align);
  
 @@ -377,6 +387,17 @@ struct page *dma_alloc_from_contiguous(struct device 
 *dev, int count,
   return page;
  }
  

Please move the description in __dma_alloc_from_contiguous to here exported API.

 +struct page *dma_alloc_from_contiguous(struct device *dev, int count,
 +unsigned int align)
 +{
 + struct cma *cma = dev_get_cma_area(dev);
 +
 + if (align  CONFIG_CMA_ALIGNMENT)
 + align = CONFIG_CMA_ALIGNMENT;
 +
 + return __dma_alloc_from_contiguous(cma, count, align);
 +}
 +
  /**
   * dma_release_from_contiguous() - release allocated pages
   * @dev:   Pointer to device for which the pages were allocated.
 @@ -387,10 +408,9 @@ struct page *dma_alloc_from_contiguous(struct device 
 *dev, int count,
   * It returns false when provided pages do not belong to contiguous area and
   * true otherwise.
   */
 -bool dma_release_from_contiguous(struct device *dev, struct page *pages,
 +static bool __dma_release_from_contiguous(struct cma *cma, struct page 
 *pages,
int count)
  {
 - struct cma *cma = dev_get_cma_area(dev);
   unsigned long pfn;
  
   if (!cma || !pages)
 @@ -410,3 +430,11 @@ bool dma_release_from_contiguous(struct device *dev, 
 struct page *pages,
  
   return true;
  }
 +

Ditto.

 +bool dma_release_from_contiguous(struct device *dev, struct page *pages,
 +  int count)
 +{
 + struct cma *cma = dev_get_cma_area(dev);
 +
 + return __dma_release_from_contiguous(cma, pages, count);
 +}
 -- 
 1.7.9.5


Re: [PATCH v2 01/10] DMA, CMA: clean-up log message

2014-06-11 Thread Joonsoo Kim
On Thu, Jun 12, 2014 at 10:11:19AM +0530, Aneesh Kumar K.V wrote:
 Joonsoo Kim iamjoonsoo@lge.com writes:
 
  We don't need explicit 'CMA:' prefix, since we already define prefix
  'cma:' in pr_fmt. So remove it.
 
  And, some logs print function name and others doesn't. This looks
  bad to me, so I unify log format to print function name consistently.
 
  Lastly, I add one more debug log on cma_activate_area().
 
  Signed-off-by: Joonsoo Kim iamjoonsoo@lge.com
 
  diff --git a/drivers/base/dma-contiguous.c b/drivers/base/dma-contiguous.c
  index 83969f8..bd0bb81 100644
  --- a/drivers/base/dma-contiguous.c
  +++ b/drivers/base/dma-contiguous.c
  @@ -144,7 +144,7 @@ void __init dma_contiguous_reserve(phys_addr_t limit)
  }
 
  if (selected_size  !dma_contiguous_default_area) {
  -   pr_debug(%s: reserving %ld MiB for global area\n, __func__,
  +   pr_debug(%s(): reserving %ld MiB for global area\n, __func__,
   (unsigned long)selected_size / SZ_1M);
 
 Do we need to do function(), or just function:. I have seen the later
 usage in other parts of the kernel.

Hello,

I also haven't seen this format in other kernel code, but, in cma, they use
this format as following.

function(arg1, arg2, ...): some message

If we all dislike this format, we can change it after merging this
patchset. Until then, it seems better to me to leave it as is.

 
 
  dma_contiguous_reserve_area(selected_size, selected_base,
  @@ -163,8 +163,9 @@ static int __init cma_activate_area(struct cma *cma)
  unsigned i = cma-count  pageblock_order;
  struct zone *zone;
 
  -   cma-bitmap = kzalloc(bitmap_size, GFP_KERNEL);
  +   pr_debug(%s()\n, __func__);
 
 why ?
 

This pr_debug() comes from ppc kvm's kvm_cma_init_reserved_areas().
I want to maintain all log messages as much as possible to reduce confusion
with this generalization.

Thanks.
--
To unsubscribe from this list: send the line unsubscribe kvm-ppc in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v2 01/10] DMA, CMA: clean-up log message

2014-06-11 Thread Joonsoo Kim
On Thu, Jun 12, 2014 at 02:18:53PM +0900, Minchan Kim wrote:
 Hi Joonsoo,
 
 On Thu, Jun 12, 2014 at 12:21:38PM +0900, Joonsoo Kim wrote:
  We don't need explicit 'CMA:' prefix, since we already define prefix
  'cma:' in pr_fmt. So remove it.
  
  And, some logs print function name and others doesn't. This looks
  bad to me, so I unify log format to print function name consistently.
  
  Lastly, I add one more debug log on cma_activate_area().
 
 When I take a look, it just indicates cma_activate_area was called or not,
 without what range for the area was reserved successfully so I couldn't see
 the intention for new message. Description should explain it so that everybody
 can agree on your claim.
 

Hello,

I paste the answer in other thread.

This pr_debug() comes from ppc kvm's kvm_cma_init_reserved_areas().
I want to maintain all log messages as much as possible to reduce
confusion with this generalization.

If I need to respin this patchset, I will explain more about it.

Thanks.
--
To unsubscribe from this list: send the line unsubscribe kvm-ppc in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v2 04/10] DMA, CMA: support alignment constraint on cma region

2014-06-11 Thread Minchan Kim
On Thu, Jun 12, 2014 at 12:21:41PM +0900, Joonsoo Kim wrote:
 ppc kvm's cma area management needs alignment constraint on
 cma region. So support it to prepare generalization of cma area
 management functionality.
 
 Additionally, add some comments which tell us why alignment
 constraint is needed on cma region.
 
 Signed-off-by: Joonsoo Kim iamjoonsoo@lge.com
 
 diff --git a/drivers/base/dma-contiguous.c b/drivers/base/dma-contiguous.c
 index 8a44c82..bc4c171 100644
 --- a/drivers/base/dma-contiguous.c
 +++ b/drivers/base/dma-contiguous.c
 @@ -32,6 +32,7 @@
  #include linux/swap.h
  #include linux/mm_types.h
  #include linux/dma-contiguous.h
 +#include linux/log2.h
  
  struct cma {
   unsigned long   base_pfn;
 @@ -219,6 +220,7 @@ core_initcall(cma_init_reserved_areas);
   * @size: Size of the reserved area (in bytes),
   * @base: Base address of the reserved area optional, use 0 for any
   * @limit: End address of the reserved memory (optional, 0 for any).
 + * @alignment: Alignment for the contiguous memory area, should be power of 2
   * @res_cma: Pointer to store the created cma region.
   * @fixed: hint about where to place the reserved area
   *

Pz, move the all description to new API function rather than internal one.

 @@ -233,15 +235,15 @@ core_initcall(cma_init_reserved_areas);
   */
  static int __init __dma_contiguous_reserve_area(phys_addr_t size,
   phys_addr_t base, phys_addr_t limit,
 + phys_addr_t alignment,
   struct cma **res_cma, bool fixed)
  {
   struct cma *cma = cma_areas[cma_area_count];
 - phys_addr_t alignment;
   int ret = 0;
  
 - pr_debug(%s(size %lx, base %08lx, limit %08lx)\n, __func__,
 -  (unsigned long)size, (unsigned long)base,
 -  (unsigned long)limit);
 + pr_debug(%s(size %lx, base %08lx, limit %08lx align_order %08lx)\n,

Why is it called by align_order?

 + __func__, (unsigned long)size, (unsigned long)base,
 + (unsigned long)limit, (unsigned long)alignment);
  
   /* Sanity checks */
   if (cma_area_count == ARRAY_SIZE(cma_areas)) {
 @@ -253,8 +255,17 @@ static int __init 
 __dma_contiguous_reserve_area(phys_addr_t size,
   if (!size)
   return -EINVAL;
  
 - /* Sanitise input arguments */
 - alignment = PAGE_SIZE  max(MAX_ORDER - 1, pageblock_order);
 + if (alignment  !is_power_of_2(alignment))
 + return -EINVAL;
 +
 + /*
 +  * Sanitise input arguments.
 +  * CMA area should be at least MAX_ORDER - 1 aligned. Otherwise,
 +  * CMA area could be merged into other MIGRATE_TYPE by buddy mechanism

I'm not a native but try for clear documenation.

 Pages both ends in CMA area could be merged into adjacent unmovable
 migratetype page by page allocator's buddy algorithm. In the case,
 you couldn't get a contiguous memory, which is not what we want.

 +  * and CMA property will be broken.
 +  */
 + alignment = max(alignment,
 + (phys_addr_t)PAGE_SIZE  max(MAX_ORDER - 1, pageblock_order));
   base = ALIGN(base, alignment);
   size = ALIGN(size, alignment);
   limit = ~(alignment - 1);
 @@ -302,7 +313,8 @@ int __init dma_contiguous_reserve_area(phys_addr_t size, 
 phys_addr_t base,
  {
   int ret;
  
 - ret = __dma_contiguous_reserve_area(size, base, limit, res_cma, fixed);
 + ret = __dma_contiguous_reserve_area(size, base, limit, 0,
 + res_cma, fixed);
   if (ret)
   return ret;
  
 -- 
 1.7.9.5

-- 
Kind regards,
Minchan Kim
--
To unsubscribe from this list: send the line unsubscribe kvm-ppc in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v2 02/10] DMA, CMA: fix possible memory leak

2014-06-11 Thread Joonsoo Kim
On Thu, Jun 12, 2014 at 02:25:43PM +0900, Minchan Kim wrote:
 On Thu, Jun 12, 2014 at 12:21:39PM +0900, Joonsoo Kim wrote:
  We should free memory for bitmap when we find zone mis-match,
  otherwise this memory will leak.
 
 Then, -stable stuff?

I don't think so. This is just possible leak candidate, so we don't
need to push this to stable tree.

 
  
  Additionally, I copy code comment from ppc kvm's cma code to notify
  why we need to check zone mis-match.
  
  Signed-off-by: Joonsoo Kim iamjoonsoo@lge.com
  
  diff --git a/drivers/base/dma-contiguous.c b/drivers/base/dma-contiguous.c
  index bd0bb81..fb0cdce 100644
  --- a/drivers/base/dma-contiguous.c
  +++ b/drivers/base/dma-contiguous.c
  @@ -177,14 +177,24 @@ static int __init cma_activate_area(struct cma *cma)
  base_pfn = pfn;
  for (j = pageblock_nr_pages; j; --j, pfn++) {
  WARN_ON_ONCE(!pfn_valid(pfn));
  +   /*
  +* alloc_contig_range requires the pfn range
  +* specified to be in the same zone. Make this
  +* simple by forcing the entire CMA resv range
  +* to be in the same zone.
  +*/
  if (page_zone(pfn_to_page(pfn)) != zone)
  -   return -EINVAL;
  +   goto err;
 
 At a first glance, I thought it would be better to handle such error
 before activating.
 So when I see the registration code(ie, dma_contiguous_revere_area),
 I realized it is impossible because we didn't set up zone yet. :(
 
 If so, when we detect to fail here, it would be better to report more
 meaningful error message like what was successful zone and what is
 new zone and failed pfn number?

What I want to do in early phase of this patchset is to make cma code
on DMA APIs similar to ppc kvm's cma code. ppc kvm's cma code already
has this error handling logic, so I make this patch.

If we think that we need more things, we can do that on general cma code
after merging this patchset.

Thanks.

--
To unsubscribe from this list: send the line unsubscribe kvm-ppc in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html