* Re: [PATCH v2 06/10] CMA: generalize CMA reserved area management functionality
From: Aneesh Kumar K.V @ 2014-06-14 10:16 UTC (permalink / raw)
To: Joonsoo Kim, Andrew Morton, Marek Szyprowski, Michal Nazarewicz
Cc: Russell King - ARM Linux, kvm, linux-mm, Gleb Natapov,
Greg Kroah-Hartman, Alexander Graf, kvm-ppc, linux-kernel,
Minchan Kim, Paul Mackerras, Paolo Bonzini, Joonsoo Kim,
linuxppc-dev, linux-arm-kernel
In-Reply-To: <1402543307-29800-7-git-send-email-iamjoonsoo.kim@lge.com>
Joonsoo Kim <iamjoonsoo.kim@lge.com> writes:
> 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 <mina86@mina86.com>
> Signed-off-by: Joonsoo Kim <iamjoonsoo.kim@lge.com>
>
.....
> +
> + mask = cma_bitmap_aligned_mask(cma, align);
> + bitmap_maxno = cma_bitmap_maxno(cma);
> + nr_bits = cma_bitmap_pages_to_bits(cma, count);
> +
> + for (;;) {
> + mutex_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);
> + break;
> + }
> + bitmap_set(cma->bitmap, bitmapno, nr_bits);
> + /*
> + * It's safe to drop the lock here. We've marked this region for
> + * our exclusive use. If the migration fails we will take the
> + * lock again and unmark it.
> + */
> + mutex_unlock(&cma->lock);
> +
> + pfn = cma->base_pfn + (bitmapno << cma->order_per_bit);
> + mutex_lock(&cma_mutex);
> + ret = alloc_contig_range(pfn, pfn + count, MIGRATE_CMA);
> + mutex_unlock(&cma_mutex);
> + if (ret == 0) {
> + page = pfn_to_page(pfn);
> + break;
> + } else if (ret != -EBUSY) {
> + clear_cma_bitmap(cma, pfn, count);
> + break;
> + }
> +
For setting bit map we do
bitmap_set(cma->bitmap, bitmapno, nr_bits);
alloc_contig()..
if (error)
clear_cma_bitmap(cma, pfn, count);
Why ?
why not bitmap_clear() ?
-aneesh
^ permalink raw reply
* Re: kmemleak: Unable to handle kernel paging request
From: Catalin Marinas @ 2014-06-14 12:05 UTC (permalink / raw)
To: Benjamin Herrenschmidt
Cc: Denis Kirjanov, linux-kernel@vger.kernel.org, linux-mm@kvack.org,
Paul Mackerras, Naoya Horiguchi, linuxppc-dev@lists.ozlabs.org
In-Reply-To: <1402695853.20360.17.camel@pasglop>
On 13 Jun 2014, at 22:44, Benjamin Herrenschmidt =
<benh@kernel.crashing.org> wrote:
> On Fri, 2014-06-13 at 09:56 +0100, Catalin Marinas wrote:
>=20
>> OK, so that's the DART table allocated via alloc_dart_table(). Is
>> dart_tablebase removed from the kernel linear mapping after =
allocation?
>=20
> Yes.
>=20
>> If that's the case, we need to tell kmemleak to ignore this block =
(see
>> patch below, untested). But I still can't explain how commit
>> d4c54919ed863020 causes this issue.
>>=20
>> (also cc'ing the powerpc list and maintainers)
>=20
> We remove the DART from the linear mapping because it has to be mapped
> non-cachable and having it in the linear mapping would cause cache
> paradoxes. We also can't just change the caching attributes in the
> linear mapping because we use 16M pages for it and 970 CPUs don't
> support cache-inhibited 16M pages :-( And due to the MMU segmentation
> model, we also can't mix & match page sizes in that area.
>=20
> So we just unmap it, and ioremap it elsewhere.
OK, thanks for the explanation. So the kmemleak annotation makes sense.
Would you please take the I patch earlier (I guess with Denis=92 tested-
by). I can send it separately if more convenient.
Thanks,
Catalin=
^ permalink raw reply
* [PATCH] usb: gadget: fsl_qe_udc: Introduce use of managed version of kzalloc
From: Himangi Saraogi @ 2014-06-14 15:18 UTC (permalink / raw)
To: Li Yang, Felipe Balbi, GregKroah-Hartman, gregkh, linux-usb,
linuxppc-dev, linux-kernel
Cc: julia.lawall
This patch moves data allocated using kzalloc to managed data allocated
using devm_kzalloc and cleans now unnecessary kfrees in probe and remove
functions. Also, the unnecesary labels are removed and some labels are
renamed to preserve ordering.
The following Coccinelle semantic patch was used for making the change:
@platform@
identifier p, probefn, removefn;
@@
struct platform_driver p = {
.probe = probefn,
.remove = removefn,
};
@prb@
identifier platform.probefn, pdev;
expression e, e1, e2;
@@
probefn(struct platform_device *pdev, ...) {
<+...
- e = kzalloc(e1, e2)
+ e = devm_kzalloc(&pdev->dev, e1, e2)
...
?-kfree(e);
...+>
}
@rem depends on prb@
identifier platform.removefn;
expression e;
@@
removefn(...) {
<...
- kfree(e);
...>
}
Signed-off-by: Himangi Saraogi <himangi774@gmail.com>
---
Not compile tested due to incompatible architecture.
drivers/usb/gadget/fsl_qe_udc.c | 19 +++++++------------
1 file changed, 7 insertions(+), 12 deletions(-)
diff --git a/drivers/usb/gadget/fsl_qe_udc.c b/drivers/usb/gadget/fsl_qe_udc.c
index ad54833..7324308 100644
--- a/drivers/usb/gadget/fsl_qe_udc.c
+++ b/drivers/usb/gadget/fsl_qe_udc.c
@@ -2539,7 +2539,7 @@ static int qe_udc_probe(struct platform_device *ofdev)
goto err2;
/* create a buf for ZLP send, need to remain zeroed */
- udc->nullbuf = kzalloc(256, GFP_KERNEL);
+ udc->nullbuf = devm_kzalloc(&ofdev->dev, 256, GFP_KERNEL);
if (udc->nullbuf == NULL) {
dev_err(udc->dev, "cannot alloc nullbuf\n");
ret = -ENOMEM;
@@ -2547,10 +2547,10 @@ static int qe_udc_probe(struct platform_device *ofdev)
}
/* buffer for data of get_status request */
- udc->statusbuf = kzalloc(2, GFP_KERNEL);
+ udc->statusbuf = devm_kzalloc(&ofdev->dev, 2, GFP_KERNEL);
if (udc->statusbuf == NULL) {
ret = -ENOMEM;
- goto err4;
+ goto err3;
}
udc->nullp = virt_to_phys((void *)udc->nullbuf);
@@ -2581,13 +2581,13 @@ static int qe_udc_probe(struct platform_device *ofdev)
if (ret) {
dev_err(udc->dev, "cannot request irq %d err %d\n",
udc->usb_irq, ret);
- goto err5;
+ goto err4;
}
ret = usb_add_gadget_udc_release(&ofdev->dev, &udc->gadget,
qe_udc_release);
if (ret)
- goto err6;
+ goto err5;
platform_set_drvdata(ofdev, udc);
dev_info(udc->dev,
@@ -2595,9 +2595,9 @@ static int qe_udc_probe(struct platform_device *ofdev)
(udc->soc_type == PORT_QE) ? "QE" : "CPM");
return 0;
-err6:
- free_irq(udc->usb_irq, udc);
err5:
+ free_irq(udc->usb_irq, udc);
+err4:
irq_dispose_mapping(udc->usb_irq);
err_noirq:
if (udc->nullmap) {
@@ -2610,9 +2610,6 @@ err_noirq:
udc->nullp, 256,
DMA_TO_DEVICE);
}
- kfree(udc->statusbuf);
-err4:
- kfree(udc->nullbuf);
err3:
ep = &udc->eps[0];
cpm_muram_free(cpm_muram_offset(ep->rxbase));
@@ -2660,8 +2657,6 @@ static int qe_udc_remove(struct platform_device *ofdev)
udc->nullp, 256,
DMA_TO_DEVICE);
}
- kfree(udc->statusbuf);
- kfree(udc->nullbuf);
ep = &udc->eps[0];
cpm_muram_free(cpm_muram_offset(ep->rxbase));
--
1.9.1
^ permalink raw reply related
* [PATCH] arch: powerpc: platforms: cell: cbe_thermal.c: Cleaning up a variable is of the wrong type
From: Rickard Strandqvist @ 2014-06-14 16:25 UTC (permalink / raw)
To: Arnd Bergmann, Benjamin Herrenschmidt
Cc: cbe-oss-dev, linuxppc-dev, Paul Mackerras, linux-kernel,
Rickard Strandqvist
In-Reply-To: <1402763111-23458-1-git-send-email-rickard_strandqvist@spectrumdigital.se>
This variable is of the wrong type, everywhere it is used it
should be an unsigned int rather than a int.
Signed-off-by: Rickard Strandqvist <rickard_strandqvist@spectrumdigital.se>
---
arch/powerpc/platforms/cell/cbe_thermal.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/arch/powerpc/platforms/cell/cbe_thermal.c b/arch/powerpc/platforms/cell/cbe_thermal.c
index 94560db..2c15ff0 100644
--- a/arch/powerpc/platforms/cell/cbe_thermal.c
+++ b/arch/powerpc/platforms/cell/cbe_thermal.c
@@ -125,7 +125,7 @@ static ssize_t show_throttle(struct cbe_pmd_regs __iomem *pmd_regs, char *buf, i
static ssize_t store_throttle(struct cbe_pmd_regs __iomem *pmd_regs, const char *buf, size_t size, int pos)
{
u64 reg_value;
- int temp;
+ unsigned int temp;
u64 new_value;
int ret;
--
1.7.10.4
^ permalink raw reply related
* [PATCH] arch: powerpc: platforms: cell: cbe_thermal.c: Cleaning up a variable is of the wrong type
From: Rickard Strandqvist @ 2014-06-14 16:25 UTC (permalink / raw)
To: Arnd Bergmann, Benjamin Herrenschmidt
Cc: cbe-oss-dev, linuxppc-dev, Paul Mackerras, linux-kernel,
Rickard Strandqvist
This variable is of the wrong type, everywhere it is used it
should be an unsigned int rather than a int.
This was partly found using a static code analysis program called cppcheck.
Rickard Strandqvist (1):
arch: powerpc: platforms: cell: cbe_thermal.c: Cleaning up a variable is of the wrong type
arch/powerpc/platforms/cell/cbe_thermal.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
--
1.7.10.4
^ permalink raw reply
* [PATCH] powerpc/kvm: support to handle sw breakpoint
From: Madhavan Srinivasan @ 2014-06-14 21:08 UTC (permalink / raw)
To: agraf, benh, paulus; +Cc: Madhavan Srinivasan, linuxppc-dev, kvm-ppc, kvm
This patch adds kernel side support for software breakpoint.
Design is that, by using an illegal instruction, we trap to hypervisor
via Emulation Assistance interrupt, where we check for the illegal instruction
and accordingly we return to Host or Guest. Patch mandates use of "abs" instruction
(primary opcode 31 and extended opcode 360) as sw breakpoint instruction.
Based on PowerISA v2.01, ABS instruction has been dropped from the architecture
and treated an illegal instruction.
Signed-off-by: Madhavan Srinivasan <maddy@linux.vnet.ibm.com>
---
arch/powerpc/kvm/book3s.c | 3 ++-
arch/powerpc/kvm/book3s_hv.c | 23 +++++++++++++++++++----
2 files changed, 21 insertions(+), 5 deletions(-)
diff --git a/arch/powerpc/kvm/book3s.c b/arch/powerpc/kvm/book3s.c
index c254c27..b40fe5d 100644
--- a/arch/powerpc/kvm/book3s.c
+++ b/arch/powerpc/kvm/book3s.c
@@ -789,7 +789,8 @@ int kvm_arch_vcpu_ioctl_translate(struct kvm_vcpu *vcpu,
int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
struct kvm_guest_debug *dbg)
{
- return -EINVAL;
+ vcpu->guest_debug = dbg->control;
+ return 0;
}
void kvmppc_decrementer_func(unsigned long data)
diff --git a/arch/powerpc/kvm/book3s_hv.c b/arch/powerpc/kvm/book3s_hv.c
index 7a12edb..688421d 100644
--- a/arch/powerpc/kvm/book3s_hv.c
+++ b/arch/powerpc/kvm/book3s_hv.c
@@ -67,6 +67,14 @@
/* Used as a "null" value for timebase values */
#define TB_NIL (~(u64)0)
+/*
+ * SW_BRK_DBG_INT is debug Instruction for supporting Software Breakpoint.
+ * Instruction mnemonic is ABS, primary opcode is 31 and extended opcode is 360.
+ * Based on PowerISA v2.01, ABS instruction has been dropped from the architecture
+ * and treated an illegal instruction.
+ */
+#define SW_BRK_DBG_INT 0x7c0002d0
+
static void kvmppc_end_cede(struct kvm_vcpu *vcpu);
static int kvmppc_hv_setup_htab_rma(struct kvm_vcpu *vcpu);
@@ -721,12 +729,19 @@ static int kvmppc_handle_exit_hv(struct kvm_run *run, struct kvm_vcpu *vcpu,
break;
/*
* This occurs if the guest executes an illegal instruction.
- * We just generate a program interrupt to the guest, since
- * we don't emulate any guest instructions at this stage.
+ * To support software breakpoint, we check for the sw breakpoint
+ * instruction to return back to host, if not we just generate a
+ * program interrupt to the guest.
*/
case BOOK3S_INTERRUPT_H_EMUL_ASSIST:
- kvmppc_core_queue_program(vcpu, SRR1_PROGILL);
- r = RESUME_GUEST;
+ if (vcpu->arch.last_inst == SW_BRK_DBG_INT) {
+ run->exit_reason = KVM_EXIT_DEBUG;
+ run->debug.arch.address = vcpu->arch.pc;
+ r = RESUME_HOST;
+ } else {
+ kvmppc_core_queue_program(vcpu, 0x80000);
+ r = RESUME_GUEST;
+ }
break;
/*
* This occurs if the guest (kernel or userspace), does something that
--
1.8.3.1
^ permalink raw reply related
* [PATCH V2] KVM: PPC: BOOK3S: HV: Use base page size when comparing against slb value
From: Aneesh Kumar K.V @ 2014-06-15 18:47 UTC (permalink / raw)
To: agraf, benh, paulus; +Cc: linuxppc-dev, kvm, kvm-ppc, Aneesh Kumar K.V
With guests supporting Multiple page size per segment (MPSS),
hpte_page_size returns the actual page size used. Add a new function to
return base page size and use that to compare against the the page size
calculated from SLB. Without this patch a hpte lookup can fail since
we are comparing wrong page size in kvmppc_hv_find_lock_hpte.
Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
---
Changes from V1:
* Remove obsolete comment from the code
* Update commit message
arch/powerpc/include/asm/kvm_book3s_64.h | 19 +++++++++++++++++--
arch/powerpc/kvm/book3s_64_mmu_hv.c | 2 +-
arch/powerpc/kvm/book3s_hv_rm_mmu.c | 7 ++-----
3 files changed, 20 insertions(+), 8 deletions(-)
diff --git a/arch/powerpc/include/asm/kvm_book3s_64.h b/arch/powerpc/include/asm/kvm_book3s_64.h
index 34422be566ce..3d0f3fb9c6b6 100644
--- a/arch/powerpc/include/asm/kvm_book3s_64.h
+++ b/arch/powerpc/include/asm/kvm_book3s_64.h
@@ -202,8 +202,10 @@ static inline unsigned long compute_tlbie_rb(unsigned long v, unsigned long r,
return rb;
}
-static inline unsigned long hpte_page_size(unsigned long h, unsigned long l)
+static inline unsigned long __hpte_page_size(unsigned long h, unsigned long l,
+ bool is_base_size)
{
+
int size, a_psize;
/* Look at the 8 bit LP value */
unsigned int lp = (l >> LP_SHIFT) & ((1 << LP_BITS) - 1);
@@ -218,14 +220,27 @@ static inline unsigned long hpte_page_size(unsigned long h, unsigned long l)
continue;
a_psize = __hpte_actual_psize(lp, size);
- if (a_psize != -1)
+ if (a_psize != -1) {
+ if (is_base_size)
+ return 1ul << mmu_psize_defs[size].shift;
return 1ul << mmu_psize_defs[a_psize].shift;
+ }
}
}
return 0;
}
+static inline unsigned long hpte_page_size(unsigned long h, unsigned long l)
+{
+ return __hpte_page_size(h, l, 0);
+}
+
+static inline unsigned long hpte_base_page_size(unsigned long h, unsigned long l)
+{
+ return __hpte_page_size(h, l, 1);
+}
+
static inline unsigned long hpte_rpn(unsigned long ptel, unsigned long psize)
{
return ((ptel & HPTE_R_RPN) & ~(psize - 1)) >> PAGE_SHIFT;
diff --git a/arch/powerpc/kvm/book3s_64_mmu_hv.c b/arch/powerpc/kvm/book3s_64_mmu_hv.c
index f53cf2eae36a..7ff45ed27c65 100644
--- a/arch/powerpc/kvm/book3s_64_mmu_hv.c
+++ b/arch/powerpc/kvm/book3s_64_mmu_hv.c
@@ -1567,7 +1567,7 @@ static ssize_t kvm_htab_write(struct file *file, const char __user *buf,
goto out;
}
if (!rma_setup && is_vrma_hpte(v)) {
- unsigned long psize = hpte_page_size(v, r);
+ unsigned long psize = hpte_base_page_size(v, r);
unsigned long senc = slb_pgsize_encoding(psize);
unsigned long lpcr;
diff --git a/arch/powerpc/kvm/book3s_hv_rm_mmu.c b/arch/powerpc/kvm/book3s_hv_rm_mmu.c
index 87624ab5ba82..d86356bfc970 100644
--- a/arch/powerpc/kvm/book3s_hv_rm_mmu.c
+++ b/arch/powerpc/kvm/book3s_hv_rm_mmu.c
@@ -833,13 +833,10 @@ long kvmppc_hv_find_lock_hpte(struct kvm *kvm, gva_t eaddr, unsigned long slb_v,
r = be64_to_cpu(hpte[i+1]);
/*
- * Check the HPTE again, including large page size
- * Since we don't currently allow any MPSS (mixed
- * page-size segment) page sizes, it is sufficient
- * to check against the actual page size.
+ * Check the HPTE again, including base page size
*/
if ((v & valid) && (v & mask) == val &&
- hpte_page_size(v, r) == (1ul << pshift))
+ hpte_base_page_size(v, r) == (1ul << pshift))
/* Return with the HPTE still locked */
return (hash << 3) + (i >> 1);
--
1.9.1
^ permalink raw reply related
* [PATCH -next 01/26] powerpc: Use dma_zalloc_coherent
From: Joe Perches @ 2014-06-15 20:37 UTC (permalink / raw)
To: linux-kernel; +Cc: Olof Johansson, Paul Mackerras, linuxppc-dev
In-Reply-To: <cover.1402863904.git.joe@perches.com>
Use the zeroing function instead of dma_alloc_coherent & memset(,0,)
Signed-off-by: Joe Perches <joe@perches.com>
---
arch/powerpc/platforms/pasemi/dma_lib.c | 8 +++-----
arch/powerpc/sysdev/fsl_rmu.c | 9 ++++-----
2 files changed, 7 insertions(+), 10 deletions(-)
diff --git a/arch/powerpc/platforms/pasemi/dma_lib.c b/arch/powerpc/platforms/pasemi/dma_lib.c
index aafa01ba..52b391f 100644
--- a/arch/powerpc/platforms/pasemi/dma_lib.c
+++ b/arch/powerpc/platforms/pasemi/dma_lib.c
@@ -255,15 +255,13 @@ int pasemi_dma_alloc_ring(struct pasemi_dmachan *chan, int ring_size)
chan->ring_size = ring_size;
- chan->ring_virt = dma_alloc_coherent(&dma_pdev->dev,
- ring_size * sizeof(u64),
- &chan->ring_dma, GFP_KERNEL);
+ chan->ring_virt = dma_zalloc_coherent(&dma_pdev->dev,
+ ring_size * sizeof(u64),
+ &chan->ring_dma, GFP_KERNEL);
if (!chan->ring_virt)
return -ENOMEM;
- memset(chan->ring_virt, 0, ring_size * sizeof(u64));
-
return 0;
}
EXPORT_SYMBOL(pasemi_dma_alloc_ring);
diff --git a/arch/powerpc/sysdev/fsl_rmu.c b/arch/powerpc/sysdev/fsl_rmu.c
index b48197a..34b49fc 100644
--- a/arch/powerpc/sysdev/fsl_rmu.c
+++ b/arch/powerpc/sysdev/fsl_rmu.c
@@ -744,15 +744,14 @@ fsl_open_outb_mbox(struct rio_mport *mport, void *dev_id, int mbox, int entries)
}
/* Initialize outbound message descriptor ring */
- rmu->msg_tx_ring.virt = dma_alloc_coherent(priv->dev,
- rmu->msg_tx_ring.size * RIO_MSG_DESC_SIZE,
- &rmu->msg_tx_ring.phys, GFP_KERNEL);
+ rmu->msg_tx_ring.virt = dma_zalloc_coherent(priv->dev,
+ rmu->msg_tx_ring.size * RIO_MSG_DESC_SIZE,
+ &rmu->msg_tx_ring.phys,
+ GFP_KERNEL);
if (!rmu->msg_tx_ring.virt) {
rc = -ENOMEM;
goto out_dma;
}
- memset(rmu->msg_tx_ring.virt, 0,
- rmu->msg_tx_ring.size * RIO_MSG_DESC_SIZE);
rmu->msg_tx_ring.tx_slot = 0;
/* Point dequeue/enqueue pointers at first entry in ring */
--
1.8.1.2.459.gbcd45b4.dirty
^ permalink raw reply related
* [PATCH -next 00/26] treewide: Use dma_zalloc_coherent
From: Joe Perches @ 2014-06-15 20:37 UTC (permalink / raw)
To: linux-kernel
Cc: linux-wireless, linux-fbdev, linux-scsi, linux-sh, linux-rdma,
linux-arm-msm, dri-devel, linux-usb, linux-mmc, users, linux-nvme,
linux-ide, ath10k, linux-crypto, netdev, dmaengine, wcn36xx,
alsa-devel, linuxppc-dev, e1000-devel
Use the zeroing function instead of dma_alloc_coherent & memset(,0,)
Joe Perches (26):
powerpc: Use dma_zalloc_coherent
sh: Use dma_zalloc_coherent
ata: Use dma_zalloc_coherent
block: Use dma_zalloc_coherent
crypto: Use dma_zalloc_coherent
dma: Use dma_zalloc_coherent
gpu: Use dma_zalloc_coherent
infiniband: Use dma_zalloc_coherent
mmc: Use dma_zalloc_coherent
broadcom: Use dma_zalloc_coherent
hisilicon: Use dma_zalloc_coherent
intel: Use dma_zalloc_coherent
ath: Use dma_zalloc_coherent
rt2x00: Use dma_zalloc_coherent
bfa: Use dma_zalloc_coherent
bnx2fc: Use dma_zalloc_coherent
bnx2i: Use dma_zalloc_coherent
dpt_i2o: Use dma_zalloc_coherent
lpfc: Use dma_zalloc_coherent
megaraid: Use dma_zalloc_coherent
mvsas: Use dma_zalloc_coherent
qla2xxx: Use dma_zalloc_coherent
qla4xxx: Use dma_zalloc_coherent
usb: Use dma_zalloc_coherent
fbdev: Use dma_zalloc_coherent
sound: Use dma_zalloc_coherent
arch/powerpc/platforms/pasemi/dma_lib.c | 8 ++--
arch/powerpc/sysdev/fsl_rmu.c | 9 ++--
arch/sh/mm/consistent.c | 4 +-
drivers/ata/sata_fsl.c | 5 +--
drivers/block/nvme-core.c | 5 +--
drivers/crypto/amcc/crypto4xx_core.c | 8 ++--
drivers/crypto/ixp4xx_crypto.c | 8 ++--
drivers/dma/imx-sdma.c | 5 +--
drivers/dma/mxs-dma.c | 8 ++--
drivers/gpu/drm/drm_pci.c | 6 +--
drivers/infiniband/hw/cxgb3/cxio_hal.c | 7 ++--
drivers/infiniband/hw/mthca/mthca_memfree.c | 5 +--
drivers/infiniband/hw/ocrdma/ocrdma_hw.c | 20 ++++-----
drivers/infiniband/hw/ocrdma/ocrdma_stats.c | 6 +--
drivers/infiniband/hw/ocrdma/ocrdma_verbs.c | 8 ++--
drivers/mmc/host/msm_sdcc.c | 8 ++--
drivers/net/ethernet/broadcom/bcm63xx_enet.c | 6 +--
drivers/net/ethernet/hisilicon/hix5hd2_gmac.c | 5 +--
drivers/net/ethernet/intel/ixgb/ixgb_main.c | 6 +--
drivers/net/wireless/ath/ath10k/pci.c | 8 +---
drivers/net/wireless/ath/ath10k/wmi.c | 8 +---
drivers/net/wireless/ath/wcn36xx/dxe.c | 6 +--
drivers/net/wireless/rt2x00/rt2x00mmio.c | 8 ++--
drivers/scsi/bfa/bfad_bsg.c | 6 +--
drivers/scsi/bnx2fc/bnx2fc_hwi.c | 59 ++++++++++++---------------
drivers/scsi/bnx2fc/bnx2fc_tgt.c | 51 ++++++++++-------------
drivers/scsi/bnx2i/bnx2i_hwi.c | 14 +++----
drivers/scsi/dpt_i2o.c | 19 ++++-----
drivers/scsi/lpfc/lpfc_bsg.c | 5 +--
drivers/scsi/lpfc/lpfc_init.c | 22 ++++------
drivers/scsi/lpfc/lpfc_mbox.c | 6 +--
drivers/scsi/lpfc/lpfc_sli.c | 14 +++----
drivers/scsi/megaraid/megaraid_sas_fusion.c | 9 ++--
drivers/scsi/mvsas/mv_init.c | 26 +++++-------
drivers/scsi/qla2xxx/qla_init.c | 10 ++---
drivers/scsi/qla4xxx/ql4_init.c | 5 +--
drivers/scsi/qla4xxx/ql4_mbx.c | 21 ++++------
drivers/scsi/qla4xxx/ql4_nx.c | 5 +--
drivers/scsi/qla4xxx/ql4_os.c | 12 +++---
drivers/usb/dwc2/hcd_ddma.c | 20 ++++-----
drivers/usb/host/uhci-hcd.c | 7 ++--
drivers/video/fbdev/da8xx-fb.c | 9 ++--
sound/aoa/soundbus/i2sbus/core.c | 12 ++----
sound/sparc/dbri.c | 6 +--
44 files changed, 197 insertions(+), 308 deletions(-)
--
1.8.1.2.459.gbcd45b4.dirty
^ permalink raw reply
* [PATCH -next 26/26] sound: Use dma_zalloc_coherent
From: Joe Perches @ 2014-06-15 20:37 UTC (permalink / raw)
To: linux-kernel
Cc: Takashi Iwai, Johannes Berg, linuxppc-dev, alsa-devel,
Jaroslav Kysela
In-Reply-To: <cover.1402863904.git.joe@perches.com>
Use the zeroing function instead of dma_alloc_coherent & memset(,0,)
Signed-off-by: Joe Perches <joe@perches.com>
---
sound/aoa/soundbus/i2sbus/core.c | 12 ++++--------
sound/sparc/dbri.c | 6 ++----
2 files changed, 6 insertions(+), 12 deletions(-)
diff --git a/sound/aoa/soundbus/i2sbus/core.c b/sound/aoa/soundbus/i2sbus/core.c
index 4678360..a80d5ea 100644
--- a/sound/aoa/soundbus/i2sbus/core.c
+++ b/sound/aoa/soundbus/i2sbus/core.c
@@ -47,15 +47,11 @@ static int alloc_dbdma_descriptor_ring(struct i2sbus_dev *i2sdev,
/* We use the PCI APIs for now until the generic one gets fixed
* enough or until we get some macio-specific versions
*/
- r->space = dma_alloc_coherent(
- &macio_get_pci_dev(i2sdev->macio)->dev,
- r->size,
- &r->bus_addr,
- GFP_KERNEL);
+ r->space = dma_zalloc_coherent(&macio_get_pci_dev(i2sdev->macio)->dev,
+ r->size, &r->bus_addr, GFP_KERNEL);
+ if (!r->space)
+ return -ENOMEM;
- if (!r->space) return -ENOMEM;
-
- memset(r->space, 0, r->size);
r->cmds = (void*)DBDMA_ALIGN(r->space);
r->bus_cmd_start = r->bus_addr +
(dma_addr_t)((char*)r->cmds - (char*)r->space);
diff --git a/sound/sparc/dbri.c b/sound/sparc/dbri.c
index be1b1aa..b2c3d0d 100644
--- a/sound/sparc/dbri.c
+++ b/sound/sparc/dbri.c
@@ -2534,12 +2534,10 @@ static int snd_dbri_create(struct snd_card *card,
dbri->op = op;
dbri->irq = irq;
- dbri->dma = dma_alloc_coherent(&op->dev,
- sizeof(struct dbri_dma),
- &dbri->dma_dvma, GFP_ATOMIC);
+ dbri->dma = dma_zalloc_coherent(&op->dev, sizeof(struct dbri_dma),
+ &dbri->dma_dvma, GFP_ATOMIC);
if (!dbri->dma)
return -ENOMEM;
- memset((void *)dbri->dma, 0, sizeof(struct dbri_dma));
dprintk(D_GEN, "DMA Cmd Block 0x%p (0x%08x)\n",
dbri->dma, dbri->dma_dvma);
--
1.8.1.2.459.gbcd45b4.dirty
^ permalink raw reply related
* Re: kmemleak: Unable to handle kernel paging request
From: Michael Ellerman @ 2014-06-16 2:40 UTC (permalink / raw)
To: Denis Kirjanov
Cc: Catalin Marinas, linux-kernel@vger.kernel.org, linux-mm@kvack.org,
Paul Mackerras, Naoya Horiguchi, linuxppc-dev
In-Reply-To: <CAOJe8K1VJ5RFWSB9i4PMdYq5X2vEgv0opGwU39ZRhYdfwj-kPw@mail.gmail.com>
On Fri, 2014-06-13 at 14:26 +0400, Denis Kirjanov wrote:
> On 6/13/14, Catalin Marinas <catalin.marinas@arm.com> wrote:
> > On Fri, Jun 13, 2014 at 08:12:08AM +0100, Denis Kirjanov wrote:
> >> On 6/12/14, Catalin Marinas <catalin.marinas@arm.com> wrote:
> >> > On Thu, Jun 12, 2014 at 01:00:57PM +0100, Denis Kirjanov wrote:
> >> >> On 6/12/14, Denis Kirjanov <kda@linux-powerpc.org> wrote:
> >> >> > On 6/12/14, Catalin Marinas <catalin.marinas@arm.com> wrote:
> >> >> >> On 11 Jun 2014, at 21:04, Denis Kirjanov <kda@linux-powerpc.org>
> >> >> >> wrote:
> >> >> >>> On 6/11/14, Catalin Marinas <catalin.marinas@arm.com> wrote:
> >> >> >>>> On Wed, Jun 11, 2014 at 04:13:07PM +0400, Denis Kirjanov wrote:
> >> >> >>>>> I got a trace while running 3.15.0-08556-gdfb9454:
> >> >> >>>>>
> >> >> >>>>> [ 104.534026] Unable to handle kernel paging request for data
> >> >> >>>>> at
> >> >> >>>>> address 0xc00000007f000000
> >> >> >>>>
> >> >> >>>> Were there any kmemleak messages prior to this, like "kmemleak
> >> >> >>>> disabled"? There could be a race when kmemleak is disabled
> >> >> >>>> because
> >> >> >>>> of
> >> >> >>>> some fatal (for kmemleak) error while the scanning is taking
> >> >> >>>> place
> >> >> >>>> (which needs some more thinking to fix properly).
> >> >> >>>
> >> >> >>> No. I checked for the similar problem and didn't find anything
> >> >> >>> relevant.
> >> >> >>> I'll try to bisect it.
> >> >> >>
> >> >> >> Does this happen soon after boot? I guess it’s the first scan
> >> >> >> (scheduled at around 1min after boot). Something seems to be
> >> >> >> telling
> >> >> >> kmemleak that there is a valid memory block at 0xc00000007f000000.
> >> >> >
> >> >> > Yeah, it happens after a while with a booted system so that's the
> >> >> > first kmemleak scan.
> >> >>
> >> >> I've bisected to this commit: d4c54919ed86302094c0ca7d48a8cbd4ee753e92
> >> >> "mm: add !pte_present() check on existing hugetlb_entry callbacks".
> >> >> Reverting the commit fixes the issue
> >> >
> >> > I can't figure how this causes the problem but I have more questions.
> >> > Is
> >> > 0xc00000007f000000 address always the same in all crashes? If yes, you
> >> > could comment out start_scan_thread() in kmemleak_late_init() to avoid
> >> > the scanning thread starting. Once booted, you can run:
> >> >
> >> > echo dump=0xc00000007f000000 > /sys/kernel/debug/kmemleak
> >> >
> >> > and check the dmesg for what kmemleak knows about that address, when it
> >> > was allocated and whether it should be mapped or not.
> >>
> >> The address is always the same.
> >>
> >> [ 179.466239] kmemleak: Object 0xc00000007f000000 (size 16777216):
> >> [ 179.466503] kmemleak: comm "swapper/0", pid 0, jiffies 4294892300
> >> [ 179.466508] kmemleak: min_count = 0
> >> [ 179.466512] kmemleak: count = 0
> >> [ 179.466517] kmemleak: flags = 0x1
> >> [ 179.466522] kmemleak: checksum = 0
> >> [ 179.466526] kmemleak: backtrace:
> >> [ 179.466531] [<c000000000afc3dc>]
> >> .memblock_alloc_range_nid+0x68/0x88
> >> [ 179.466544] [<c000000000afc444>] .memblock_alloc_base+0x20/0x58
> >> [ 179.466553] [<c000000000ae96cc>] .alloc_dart_table+0x5c/0xb0
> >> [ 179.466561] [<c000000000aea300>] .pmac_probe+0x38/0xa0
> >> [ 179.466569] [<000000000002166c>] 0x2166c
> >> [ 179.466579] [<0000000000ae0e68>] 0xae0e68
> >> [ 179.466587] [<0000000000009bc4>] 0x9bc4
> >
> > OK, so that's the DART table allocated via alloc_dart_table(). Is
> > dart_tablebase removed from the kernel linear mapping after allocation?
> > If that's the case, we need to tell kmemleak to ignore this block (see
> > patch below, untested). But I still can't explain how commit
> > d4c54919ed863020 causes this issue.
> >
> > (also cc'ing the powerpc list and maintainers)
>
> Ok, your path fixes the oops.
>
> Ben, can you shed some light on this issue?
(I'm not Ben)
Yes, the memory for dart_tablebase is removed from the linear mapping. In fact
it's never mapped, see htab_initialize().
I don't easily see how commit d4c54919ed8, could have exposed this, but I don't
know enough of the kmemleak internals to say for sure.
cheers
^ permalink raw reply
* Re: [PATCH v2 01/10] DMA, CMA: clean-up log message
From: Joonsoo Kim @ 2014-06-16 5:18 UTC (permalink / raw)
To: Michal Nazarewicz
Cc: Russell King - ARM Linux, kvm, linux-mm, Gleb Natapov,
Greg Kroah-Hartman, Alexander Graf, kvm-ppc, linux-kernel,
Minchan Kim, Paul Mackerras, Aneesh Kumar K.V, Paolo Bonzini,
Andrew Morton, linuxppc-dev, linux-arm-kernel, Marek Szyprowski
In-Reply-To: <xa1tegyujvxv.fsf@mina86.com>
On Thu, Jun 12, 2014 at 11:53:16AM +0200, Michal Nazarewicz wrote:
> On Thu, Jun 12 2014, Michal Nazarewicz <mina86@mina86.com> wrote:
> > I used “function(arg1, arg2, …)” at the *beginning* of functions when
> > the arguments passed to the function were included in the message. In
> > all other cases I left it at just “function:” (or just no additional
> > prefix). IMO that's a reasonable strategy.
>
> At closer inspection, I realised drivers/base/dma-contiguous.c is
> Marek's code, but the above I think is still reasonable thing to do, so
> I'd rather standardise on having “function(…)” only at the beginning of
> a function. Just my 0.02 CHF.
Hello,
Now, I realize that these changes aren't needed in this patchset, so I
simplify this patch just to remove redundant 'CMA' prefix. Other things
can be done after merging if we need.
Thanks.
^ permalink raw reply
* Re: [PATCH v2 04/10] DMA, CMA: support alignment constraint on cma region
From: Joonsoo Kim @ 2014-06-16 5:19 UTC (permalink / raw)
To: Michal Nazarewicz
Cc: Russell King - ARM Linux, kvm, linux-mm, Gleb Natapov,
Greg Kroah-Hartman, Alexander Graf, kvm-ppc, linux-kernel,
Minchan Kim, Paul Mackerras, Aneesh Kumar K.V, Paolo Bonzini,
Andrew Morton, linuxppc-dev, linux-arm-kernel, Marek Szyprowski
In-Reply-To: <xa1t8up2jvi9.fsf@mina86.com>
On Thu, Jun 12, 2014 at 12:02:38PM +0200, Michal Nazarewicz wrote:
> On Thu, Jun 12 2014, Joonsoo Kim <iamjoonsoo.kim@lge.com> wrote:
> > ppc kvm's cma area management needs alignment constraint on
>
> I've noticed it earlier and cannot seem to get to terms with this. It
> should IMO be PPC, KVM and CMA since those are acronyms. But if you
> have strong feelings, it's not a big issue.
Yes, I will fix it.
>
> > 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.kim@lge.com>
>
> Acked-by: Michal Nazarewicz <mina86@mina86.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
> > @@ -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
>
> “must be power of 2 or zero”.
Okay.
> > * @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);
>
> Nit: Align with the rest of the arguments, i.e.:
>
> + 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);
What's the difference between mine and yours?
Thanks.
^ permalink raw reply
* Re: [PATCH v2 05/10] DMA, CMA: support arbitrary bitmap granularity
From: Joonsoo Kim @ 2014-06-16 5:23 UTC (permalink / raw)
To: Michal Nazarewicz
Cc: Russell King - ARM Linux, kvm, linux-mm, Gleb Natapov,
Greg Kroah-Hartman, Alexander Graf, kvm-ppc, linux-kernel,
Minchan Kim, Paul Mackerras, Aneesh Kumar K.V, Paolo Bonzini,
Andrew Morton, linuxppc-dev, linux-arm-kernel, Marek Szyprowski
In-Reply-To: <xa1t61k6juph.fsf@mina86.com>
On Thu, Jun 12, 2014 at 12:19:54PM +0200, Michal Nazarewicz wrote:
> On Thu, Jun 12 2014, Joonsoo Kim <iamjoonsoo.kim@lge.com> wrote:
> > 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.kim@lge.com>
>
> Acked-by: Michal Nazarewicz <mina86@mina86.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;
>
> Have you considered replacing count with maxno?
No, I haven't.
I think that count is better than maxno, since it represent number of
pages in this region.
>
> > unsigned long *bitmap;
> > + int order_per_bit; /* Order of pages represented by one bit */
>
> I'd make it unsigned.
Will fix it.
> > struct mutex lock;
> > };
> >
> > +static void clear_cma_bitmap(struct cma *cma, unsigned long pfn, int
> > count)
>
> For consistency cma_clear_bitmap would make more sense I think. On the
> other hand, you're just moving stuff around so perhaps renaming the
> function at this point is not worth it any more.
Will fix it.
> > +{
> > + 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;
>
> bitmap_maxno is never used again, perhaps:
>
> + int bitmap_size = BITS_TO_LONGS(cma_bitmap_maxno(cma)) * sizeof(long);
>
> instead? Up to you.
Okay!!
Thanks.
^ permalink raw reply
* Re: [PATCH v2 03/10] DMA, CMA: separate core cma management codes from DMA APIs
From: Joonsoo Kim @ 2014-06-16 5:24 UTC (permalink / raw)
To: Minchan Kim
Cc: kvm-ppc, Russell King - ARM Linux, kvm, Gleb Natapov,
Greg Kroah-Hartman, Alexander Graf, Michal Nazarewicz,
linux-kernel, linux-mm, Paul Mackerras, Aneesh Kumar K.V,
Paolo Bonzini, Andrew Morton, linuxppc-dev, linux-arm-kernel,
Marek Szyprowski
In-Reply-To: <20140612053743.GF12415@bbox>
On Thu, Jun 12, 2014 at 02:37:43PM +0900, Minchan Kim wrote:
> 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.kim@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.
Good catch!!!
I will fix it.
> > +
> > + 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.
>
Okay.
> > +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.
>
Okay.
Thanks.
^ permalink raw reply
* Re: [PATCH v2 06/10] CMA: generalize CMA reserved area management functionality
From: Joonsoo Kim @ 2014-06-16 5:27 UTC (permalink / raw)
To: Aneesh Kumar K.V
Cc: Russell King - ARM Linux, kvm, linux-mm, Gleb Natapov,
Greg Kroah-Hartman, Alexander Graf, Michal Nazarewicz,
linux-kernel, Minchan Kim, Paul Mackerras, kvm-ppc, Paolo Bonzini,
Andrew Morton, linuxppc-dev, linux-arm-kernel, Marek Szyprowski
In-Reply-To: <87a99fg5ir.fsf@linux.vnet.ibm.com>
On Sat, Jun 14, 2014 at 03:46:44PM +0530, Aneesh Kumar K.V wrote:
> Joonsoo Kim <iamjoonsoo.kim@lge.com> writes:
>
> > 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 <mina86@mina86.com>
> > Signed-off-by: Joonsoo Kim <iamjoonsoo.kim@lge.com>
> >
>
> .....
>
> > +
> > + mask = cma_bitmap_aligned_mask(cma, align);
> > + bitmap_maxno = cma_bitmap_maxno(cma);
> > + nr_bits = cma_bitmap_pages_to_bits(cma, count);
> > +
> > + for (;;) {
> > + mutex_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);
> > + break;
> > + }
> > + bitmap_set(cma->bitmap, bitmapno, nr_bits);
> > + /*
> > + * It's safe to drop the lock here. We've marked this region for
> > + * our exclusive use. If the migration fails we will take the
> > + * lock again and unmark it.
> > + */
> > + mutex_unlock(&cma->lock);
> > +
> > + pfn = cma->base_pfn + (bitmapno << cma->order_per_bit);
> > + mutex_lock(&cma_mutex);
> > + ret = alloc_contig_range(pfn, pfn + count, MIGRATE_CMA);
> > + mutex_unlock(&cma_mutex);
> > + if (ret == 0) {
> > + page = pfn_to_page(pfn);
> > + break;
> > + } else if (ret != -EBUSY) {
> > + clear_cma_bitmap(cma, pfn, count);
> > + break;
> > + }
> > +
>
>
> For setting bit map we do
> bitmap_set(cma->bitmap, bitmapno, nr_bits);
> alloc_contig()..
> if (error)
> clear_cma_bitmap(cma, pfn, count);
>
> Why ?
>
> why not bitmap_clear() ?
>
Unlike your psuedo code, for setting bitmap, we do
- grab the mutex
- bitmap_set
- release the mutex
clear_cma_bitmap() handles these things.
Thanks.
^ permalink raw reply
* Re: [PATCH v2 07/10] PPC, KVM, CMA: use general CMA reserved area management framework
From: Joonsoo Kim @ 2014-06-16 5:29 UTC (permalink / raw)
To: Aneesh Kumar K.V
Cc: Russell King - ARM Linux, kvm, linux-mm, Gleb Natapov,
Greg Kroah-Hartman, Alexander Graf, Michal Nazarewicz,
linux-kernel, Minchan Kim, Paul Mackerras, kvm-ppc, Paolo Bonzini,
Andrew Morton, linuxppc-dev, linux-arm-kernel, Marek Szyprowski
In-Reply-To: <87k38jg61e.fsf@linux.vnet.ibm.com>
On Sat, Jun 14, 2014 at 03:35:33PM +0530, Aneesh Kumar K.V wrote:
> Joonsoo Kim <iamjoonsoo.kim@lge.com> writes:
>
> > Now, we have general CMA reserved area management framework,
> > so use it for future maintainabilty. There is no functional change.
> >
> > Acked-by: Michal Nazarewicz <mina86@mina86.com>
> > Acked-by: Paolo Bonzini <pbonzini@redhat.com>
> > Signed-off-by: Joonsoo Kim <iamjoonsoo.kim@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_ORDER 18
> > +
> > /*
> > * 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..0000000
> > --- 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.kumar@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);
> > - /*
> > - * Reserve memory
> > - * Use __memblock_alloc_base() since
> > - * memblock_alloc_base() panic()s.
> > - */
> > - addr = __memblock_alloc_base(size, alignment, 0);
> > - if (!addr) {
> > - base_pfn = -ENOMEM;
> > - goto err;
> > - } else
> > - base_pfn = PFN_DOWN(addr);
> > -
> > - /*
> > - * Each reserved area must be initialised later, when more kernel
> > - * subsystems (like slab allocator) are available.
> > - */
> > - cma->base_pfn = base_pfn;
> > - cma->count = size >> PAGE_SHIFT;
> > - pr_info("CMA: reserved %ld MiB\n", (unsigned long)size / SZ_1M);
> > - return 0;
> > -err:
> > - pr_err("CMA: failed to reserve %ld MiB\n", (unsigned long)size / SZ_1M);
> > - return base_pfn;
> > -}
> > -
> > -/**
> > - * kvm_alloc_cma() - allocate pages from contiguous area
> > - * @nr_pages: Requested number of pages.
> > - * @align_pages: Requested alignment in number of pages
> > - *
> > - * This function allocates memory buffer for hash pagetable.
> > - */
> > -struct page *kvm_alloc_cma(unsigned long nr_pages, unsigned long align_pages)
> > -{
> > - int ret;
> > - struct page *page = NULL;
> > - struct kvm_cma *cma = &kvm_cma_area;
> > - unsigned long chunk_count, nr_chunk;
> > - unsigned long mask, pfn, pageno, start = 0;
> > -
> > -
> > - if (!cma || !cma->count)
> > - return NULL;
> > -
> > - pr_debug("%s(cma %p, count %lu, align pages %lu)\n", __func__,
> > - (void *)cma, nr_pages, align_pages);
> > -
> > - if (!nr_pages)
> > - return NULL;
> > - /*
> > - * align mask with chunk size. The bit tracks pages in chunk size
> > - */
> > - VM_BUG_ON(!is_power_of_2(align_pages));
> > - mask = (align_pages >> (KVM_CMA_CHUNK_ORDER - PAGE_SHIFT)) - 1;
> > - BUILD_BUG_ON(PAGE_SHIFT > KVM_CMA_CHUNK_ORDER);
> > -
> > - chunk_count = cma->count >> (KVM_CMA_CHUNK_ORDER - PAGE_SHIFT);
> > - nr_chunk = nr_pages >> (KVM_CMA_CHUNK_ORDER - PAGE_SHIFT);
> > -
> > - mutex_lock(&kvm_cma_mutex);
> > - for (;;) {
> > - pageno = bitmap_find_next_zero_area(cma->bitmap, chunk_count,
> > - start, nr_chunk, mask);
> > - if (pageno >= chunk_count)
> > - break;
> > -
> > - pfn = cma->base_pfn + (pageno << (KVM_CMA_CHUNK_ORDER - PAGE_SHIFT));
> > - ret = alloc_contig_range(pfn, pfn + nr_pages, MIGRATE_CMA);
> > - if (ret == 0) {
> > - bitmap_set(cma->bitmap, pageno, nr_chunk);
> > - page = pfn_to_page(pfn);
> > - memset(pfn_to_kaddr(pfn), 0, nr_pages <<
> > PAGE_SHIFT);
>
>
> The above memset is missing in the generic code. May be
>
> diff --git a/arch/powerpc/kvm/book3s_64_mmu_hv.c b/arch/powerpc/kvm/book3s_64_mmu_hv.c
> index 6f13ee6..8740b4c 100644
> --- a/arch/powerpc/kvm/book3s_64_mmu_hv.c
> +++ b/arch/powerpc/kvm/book3s_64_mmu_hv.c
> @@ -75,6 +75,7 @@ long kvmppc_alloc_hpt(struct kvm *kvm, u32 *htab_orderp)
> page = kvm_alloc_hpt(1 << (order - PAGE_SHIFT));
> if (page) {
> hpt = (unsigned long)pfn_to_kaddr(page_to_pfn(page));
> + memset((void *)hpt, 0, (1 << order));
> kvm->arch.hpt_cma_alloc = 1;
> } else
> --order;
>
>
>
> With that
>
> Tested-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Okay. Will do.
Really thanks for testing!!
Thanks.
^ permalink raw reply
* Re: [PATCH v2 00/10] CMA: generalize CMA reserved area management code
From: Joonsoo Kim @ 2014-06-16 5:32 UTC (permalink / raw)
To: Aneesh Kumar K.V
Cc: Russell King - ARM Linux, kvm, linux-mm, Gleb Natapov,
Greg Kroah-Hartman, Alexander Graf, Michal Nazarewicz,
linux-kernel, Minchan Kim, Paul Mackerras, kvm-ppc, Paolo Bonzini,
Andrew Morton, linuxppc-dev, linux-arm-kernel, Marek Szyprowski
In-Reply-To: <87r42seyvg.fsf@linux.vnet.ibm.com>
On Sat, Jun 14, 2014 at 12:55:39PM +0530, Aneesh Kumar K.V wrote:
> Joonsoo Kim <iamjoonsoo.kim@lge.com> writes:
>
> > 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.
>
>
> I wanted to test the ppc changes and found that the patch series doesn't apply
> against v3.15 . Do you have a kernel tree which I can clone to test this
> series ?
This is based on linux-next -next-20140610.
And my tree is on following link.
https://github.com/JoonsooKim/linux/tree/cma-general-v2.0-next-20140610
But, I think I'm late, because you have already added a Tested-by tag.
Thanks.
^ permalink raw reply
* Re: [PATCH v2 07/10] PPC, KVM, CMA: use general CMA reserved area management framework
From: Joonsoo Kim @ 2014-06-16 5:34 UTC (permalink / raw)
To: Aneesh Kumar K.V
Cc: Russell King - ARM Linux, kvm, linux-mm, Gleb Natapov,
Greg Kroah-Hartman, Alexander Graf, Michal Nazarewicz,
linux-kernel, Minchan Kim, Paul Mackerras, kvm-ppc, Paolo Bonzini,
Andrew Morton, linuxppc-dev, linux-arm-kernel, Marek Szyprowski
In-Reply-To: <87mwdfg9co.fsf@linux.vnet.ibm.com>
On Sat, Jun 14, 2014 at 02:23:59PM +0530, Aneesh Kumar K.V wrote:
> Joonsoo Kim <iamjoonsoo.kim@lge.com> writes:
>
> > Now, we have general CMA reserved area management framework,
> > so use it for future maintainabilty. There is no functional change.
> >
> > Acked-by: Michal Nazarewicz <mina86@mina86.com>
> > Acked-by: Paolo Bonzini <pbonzini@redhat.com>
> > Signed-off-by: Joonsoo Kim <iamjoonsoo.kim@lge.com>
>
> Need this. We may want to keep the VM_BUG_ON by moving
> KVM_CMA_CHUNK_ORDER around.
>
> diff --git a/arch/powerpc/kvm/book3s_64_mmu_hv.c b/arch/powerpc/kvm/book3s_64_mmu_hv.c
> index 8056107..1932e0e 100644
> --- a/arch/powerpc/kvm/book3s_64_mmu_hv.c
> +++ b/arch/powerpc/kvm/book3s_64_mmu_hv.c
> @@ -37,8 +37,6 @@
> #include <asm/ppc-opcode.h>
> #include <asm/cputable.h>
>
> -#include "book3s_hv_cma.h"
> -
> /* POWER7 has 10-bit LPIDs, PPC970 has 6-bit LPIDs */
> #define MAX_LPID_970 63
>
> @@ -64,7 +62,6 @@ long kvmppc_alloc_hpt(struct kvm *kvm, u32 *htab_orderp)
> }
>
> kvm->arch.hpt_cma_alloc = 0;
> - VM_BUG_ON(order < KVM_CMA_CHUNK_ORDER);
> page = kvm_alloc_hpt(1 << (order - PAGE_SHIFT));
> if (page) {
> hpt = (unsigned long)pfn_to_kaddr(page_to_pfn(page));
>
>
>
> -aneesh
Okay.
So do you also want this?
@@ -131,16 +135,18 @@ struct page *kvm_alloc_hpt(unsigned long nr_pages)
{
unsigned long align_pages = HPT_ALIGN_PAGES;
+ VM_BUG_ON(get_order(nr_pages) < KVM_CMA_CHUNK_ORDER - PAGE_SHIFT);
+
/* 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));
}
Thanks.
^ permalink raw reply
* [PATCH v3 -next 2/9] DMA, CMA: separate core CMA management codes from DMA APIs
From: Joonsoo Kim @ 2014-06-16 5:40 UTC (permalink / raw)
To: Andrew Morton, Aneesh Kumar K.V, Marek Szyprowski,
Michal Nazarewicz
Cc: Russell King - ARM Linux, kvm, linux-mm, Gleb Natapov,
Greg Kroah-Hartman, Alexander Graf, kvm-ppc, linux-kernel,
Minchan Kim, Paul Mackerras, Paolo Bonzini, Joonsoo Kim,
Zhang Yanfei, linuxppc-dev, linux-arm-kernel
In-Reply-To: <1402897251-23639-1-git-send-email-iamjoonsoo.kim@lge.com>
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.
v3: move decriptions to exporeted APIs (Minchan)
pass aligned base and size to dma_contiguous_early_fixup() (Minchan)
Acked-by: Michal Nazarewicz <mina86@mina86.com>
Reviewed-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Signed-off-by: Joonsoo Kim <iamjoonsoo.kim@lge.com>
diff --git a/drivers/base/dma-contiguous.c b/drivers/base/dma-contiguous.c
index 6467c91..9021762 100644
--- a/drivers/base/dma-contiguous.c
+++ b/drivers/base/dma-contiguous.c
@@ -213,26 +213,9 @@ static int __init cma_init_reserved_areas(void)
}
core_initcall(cma_init_reserved_areas);
-/**
- * dma_contiguous_reserve_area() - reserve custom contiguous area
- * @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).
- * @res_cma: Pointer to store the created cma region.
- * @fixed: hint about where to place the reserved area
- *
- * This function reserves memory from early allocator. It should be
- * called by arch specific code once the early allocator (memblock or bootmem)
- * has been activated and all other subsystems have already allocated/reserved
- * memory. This function allows to create custom reserved areas for specific
- * devices.
- *
- * 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;
@@ -286,15 +269,47 @@ int __init dma_contiguous_reserve_area(phys_addr_t size, phys_addr_t base,
pr_info("CMA: reserved %ld MiB at %08lx\n", (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);
return ret;
}
+/**
+ * dma_contiguous_reserve_area() - reserve custom contiguous area
+ * @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).
+ * @res_cma: Pointer to store the created cma region.
+ * @fixed: hint about where to place the reserved area
+ *
+ * This function reserves memory from early allocator. It should be
+ * called by arch specific code once the early allocator (memblock or bootmem)
+ * has been activated and all other subsystems have already allocated/reserved
+ * memory. This function allows to create custom reserved areas for specific
+ * devices.
+ *
+ * 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)
+{
+ 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(PFN_PHYS((*res_cma)->base_pfn),
+ (*res_cma)->count << PAGE_SHIFT);
+
+ return 0;
+}
+
static void clear_cma_bitmap(struct cma *cma, unsigned long pfn, int count)
{
mutex_lock(&cma->lock);
@@ -302,31 +317,16 @@ static void clear_cma_bitmap(struct cma *cma, unsigned long pfn, int count)
mutex_unlock(&cma->lock);
}
-/**
- * dma_alloc_from_contiguous() - allocate pages from contiguous area
- * @dev: Pointer to device for which the allocation is performed.
- * @count: Requested number of pages.
- * @align: Requested alignment of pages (in PAGE_SIZE order).
- *
- * This function allocates memory buffer for specified device. It uses
- * device specific contiguous memory area if available or the default
- * 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);
@@ -375,19 +375,30 @@ struct page *dma_alloc_from_contiguous(struct device *dev, int count,
}
/**
- * dma_release_from_contiguous() - release allocated pages
- * @dev: Pointer to device for which the pages were allocated.
- * @pages: Allocated pages.
- * @count: Number of allocated pages.
+ * dma_alloc_from_contiguous() - allocate pages from contiguous area
+ * @dev: Pointer to device for which the allocation is performed.
+ * @count: Requested number of pages.
+ * @align: Requested alignment of pages (in PAGE_SIZE order).
*
- * This function releases memory allocated by dma_alloc_from_contiguous().
- * It returns false when provided pages do not belong to contiguous area and
- * true otherwise.
+ * This function allocates memory buffer for specified device. It uses
+ * device specific contiguous memory area if available or the default
+ * global one. Requires architecture specific dev_get_cma_area() helper
+ * function.
*/
-bool dma_release_from_contiguous(struct device *dev, struct page *pages,
- int count)
+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);
+}
+
+static bool __dma_release_from_contiguous(struct cma *cma, struct page *pages,
+ int count)
+{
unsigned long pfn;
if (!cma || !pages)
@@ -407,3 +418,21 @@ bool dma_release_from_contiguous(struct device *dev, struct page *pages,
return true;
}
+
+/**
+ * dma_release_from_contiguous() - release allocated pages
+ * @dev: Pointer to device for which the pages were allocated.
+ * @pages: Allocated pages.
+ * @count: Number of allocated pages.
+ *
+ * This function releases memory allocated by dma_alloc_from_contiguous().
+ * 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,
+ int count)
+{
+ struct cma *cma = dev_get_cma_area(dev);
+
+ return __dma_release_from_contiguous(cma, pages, count);
+}
--
1.7.9.5
^ permalink raw reply related
* [PATCH v3 -next 3/9] DMA, CMA: support alignment constraint on CMA region
From: Joonsoo Kim @ 2014-06-16 5:40 UTC (permalink / raw)
To: Andrew Morton, Aneesh Kumar K.V, Marek Szyprowski,
Michal Nazarewicz
Cc: Russell King - ARM Linux, kvm, linux-mm, Gleb Natapov,
Greg Kroah-Hartman, Alexander Graf, kvm-ppc, linux-kernel,
Minchan Kim, Paul Mackerras, Paolo Bonzini, Joonsoo Kim,
Zhang Yanfei, linuxppc-dev, linux-arm-kernel
In-Reply-To: <1402897251-23639-1-git-send-email-iamjoonsoo.kim@lge.com>
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.
v3: fix wrongly spelled word, align_order->alignment (Minchan)
clear code documentation by Minchan's comment (Minchan)
Acked-by: Michal Nazarewicz <mina86@mina86.com>
Reviewed-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Signed-off-by: Joonsoo Kim <iamjoonsoo.kim@lge.com>
diff --git a/drivers/base/dma-contiguous.c b/drivers/base/dma-contiguous.c
index 9021762..5f62c28 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;
@@ -215,17 +216,16 @@ 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 alignment %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)) {
pr_err("Not enough slots for CMA reserved regions!\n");
return -ENOSPC;
@@ -234,8 +234,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.
+ * 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.
+ */
+ 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);
@@ -299,7 +308,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
^ permalink raw reply related
* [PATCH v3 -next 0/9] CMA: generalize CMA reserved area management code
From: Joonsoo Kim @ 2014-06-16 5:40 UTC (permalink / raw)
To: Andrew Morton, Aneesh Kumar K.V, Marek Szyprowski,
Michal Nazarewicz
Cc: Russell King - ARM Linux, kvm, linux-mm, Gleb Natapov,
Greg Kroah-Hartman, Alexander Graf, kvm-ppc, linux-kernel,
Minchan Kim, Paul Mackerras, Paolo Bonzini, Joonsoo Kim,
Zhang Yanfei, linuxppc-dev, linux-arm-kernel
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.
v3:
- Simplify old patch 1(log format fix) and move it to the end of patchset.
- Patch 2: Pass aligned base and size to dma_contiguous_early_fixup()
- Patch 5: Add some accessor functions to pass aligned base and size to
dma_contiguous_early_fixup() function
- Patch 5: Move MAX_CMA_AREAS definition to cma.h
- Patch 6: Add CMA region zeroing to PPC KVM's CMA alloc function
- Patch 8: put 'base' ahead of 'size' in cma_declare_contiguous()
- Remaining minor fixes are noted in commit description of each one
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.
This patchset is based on linux-next 20140610.
Patch 1-4 prepare some features to cover PPC KVM's requirements.
Patch 5-6 generalize CMA reserved area management code and change users
to use it.
Patch 7-9 clean-up minor things.
Joonsoo Kim (9):
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: change cma_declare_contiguous() to obey coding convention
mm, CMA: clean-up log message
arch/arm/mm/dma-mapping.c | 1 +
arch/powerpc/kvm/book3s_64_mmu_hv.c | 4 +-
arch/powerpc/kvm/book3s_hv_builtin.c | 19 +-
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 | 210 ++-------------------
include/linux/cma.h | 21 +++
include/linux/dma-contiguous.h | 11 +-
mm/Kconfig | 11 ++
mm/Makefile | 1 +
mm/cma.c | 335 ++++++++++++++++++++++++++++++++++
12 files changed, 397 insertions(+), 493 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
^ permalink raw reply
* [PATCH v3 -next 6/9] PPC, KVM, CMA: use general CMA reserved area management framework
From: Joonsoo Kim @ 2014-06-16 5:40 UTC (permalink / raw)
To: Andrew Morton, Aneesh Kumar K.V, Marek Szyprowski,
Michal Nazarewicz
Cc: Russell King - ARM Linux, kvm, linux-mm, Gleb Natapov,
Greg Kroah-Hartman, Alexander Graf, kvm-ppc, linux-kernel,
Minchan Kim, Paul Mackerras, Paolo Bonzini, Joonsoo Kim,
Zhang Yanfei, linuxppc-dev, linux-arm-kernel
In-Reply-To: <1402897251-23639-1-git-send-email-iamjoonsoo.kim@lge.com>
Now, we have general CMA reserved area management framework,
so use it for future maintainabilty. There is no functional change.
v3: add zeroing to CMA region (Aneesh)
fix compile error (Aneesh)
move VM_BUG_ON() to kvm_alloc_hpt() in book3s_hv_builtin.c (Aneesh)
Acked-by: Michal Nazarewicz <mina86@mina86.com>
Acked-by: Paolo Bonzini <pbonzini@redhat.com>
Tested-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Signed-off-by: Joonsoo Kim <iamjoonsoo.kim@lge.com>
diff --git a/arch/powerpc/kvm/book3s_64_mmu_hv.c b/arch/powerpc/kvm/book3s_64_mmu_hv.c
index 8056107..a41e625 100644
--- a/arch/powerpc/kvm/book3s_64_mmu_hv.c
+++ b/arch/powerpc/kvm/book3s_64_mmu_hv.c
@@ -37,8 +37,6 @@
#include <asm/ppc-opcode.h>
#include <asm/cputable.h>
-#include "book3s_hv_cma.h"
-
/* POWER7 has 10-bit LPIDs, PPC970 has 6-bit LPIDs */
#define MAX_LPID_970 63
@@ -64,10 +62,10 @@ long kvmppc_alloc_hpt(struct kvm *kvm, u32 *htab_orderp)
}
kvm->arch.hpt_cma_alloc = 0;
- VM_BUG_ON(order < KVM_CMA_CHUNK_ORDER);
page = kvm_alloc_hpt(1 << (order - PAGE_SHIFT));
if (page) {
hpt = (unsigned long)pfn_to_kaddr(page_to_pfn(page));
+ memset((void *)hpt, 0, (1 << order));
kvm->arch.hpt_cma_alloc = 1;
}
diff --git a/arch/powerpc/kvm/book3s_hv_builtin.c b/arch/powerpc/kvm/book3s_hv_builtin.c
index 7cde8a6..3960e0b 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_ORDER 18
+
/*
* 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);
}
}
@@ -131,16 +135,18 @@ struct page *kvm_alloc_hpt(unsigned long nr_pages)
{
unsigned long align_pages = HPT_ALIGN_PAGES;
+ VM_BUG_ON(get_order(nr_pages) < KVM_CMA_CHUNK_ORDER - PAGE_SHIFT);
+
/* 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 +185,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..0000000
--- 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.kumar@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);
- /*
- * Reserve memory
- * Use __memblock_alloc_base() since
- * memblock_alloc_base() panic()s.
- */
- addr = __memblock_alloc_base(size, alignment, 0);
- if (!addr) {
- base_pfn = -ENOMEM;
- goto err;
- } else
- base_pfn = PFN_DOWN(addr);
-
- /*
- * Each reserved area must be initialised later, when more kernel
- * subsystems (like slab allocator) are available.
- */
- cma->base_pfn = base_pfn;
- cma->count = size >> PAGE_SHIFT;
- pr_info("CMA: reserved %ld MiB\n", (unsigned long)size / SZ_1M);
- return 0;
-err:
- pr_err("CMA: failed to reserve %ld MiB\n", (unsigned long)size / SZ_1M);
- return base_pfn;
-}
-
-/**
- * kvm_alloc_cma() - allocate pages from contiguous area
- * @nr_pages: Requested number of pages.
- * @align_pages: Requested alignment in number of pages
- *
- * This function allocates memory buffer for hash pagetable.
- */
-struct page *kvm_alloc_cma(unsigned long nr_pages, unsigned long align_pages)
-{
- int ret;
- struct page *page = NULL;
- struct kvm_cma *cma = &kvm_cma_area;
- unsigned long chunk_count, nr_chunk;
- unsigned long mask, pfn, pageno, start = 0;
-
-
- if (!cma || !cma->count)
- return NULL;
-
- pr_debug("%s(cma %p, count %lu, align pages %lu)\n", __func__,
- (void *)cma, nr_pages, align_pages);
-
- if (!nr_pages)
- return NULL;
- /*
- * align mask with chunk size. The bit tracks pages in chunk size
- */
- VM_BUG_ON(!is_power_of_2(align_pages));
- mask = (align_pages >> (KVM_CMA_CHUNK_ORDER - PAGE_SHIFT)) - 1;
- BUILD_BUG_ON(PAGE_SHIFT > KVM_CMA_CHUNK_ORDER);
-
- chunk_count = cma->count >> (KVM_CMA_CHUNK_ORDER - PAGE_SHIFT);
- nr_chunk = nr_pages >> (KVM_CMA_CHUNK_ORDER - PAGE_SHIFT);
-
- mutex_lock(&kvm_cma_mutex);
- for (;;) {
- pageno = bitmap_find_next_zero_area(cma->bitmap, chunk_count,
- start, nr_chunk, mask);
- if (pageno >= chunk_count)
- break;
-
- pfn = cma->base_pfn + (pageno << (KVM_CMA_CHUNK_ORDER - PAGE_SHIFT));
- ret = alloc_contig_range(pfn, pfn + nr_pages, MIGRATE_CMA);
- if (ret == 0) {
- bitmap_set(cma->bitmap, pageno, nr_chunk);
- page = pfn_to_page(pfn);
- memset(pfn_to_kaddr(pfn), 0, nr_pages << PAGE_SHIFT);
- break;
- } else 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 */
- start = pageno + mask + 1;
- }
- mutex_unlock(&kvm_cma_mutex);
- pr_debug("%s(): returned %p\n", __func__, page);
- return page;
-}
-
-/**
- * kvm_release_cma() - release allocated pages for hash pagetable
- * @pages: Allocated pages.
- * @nr_pages: Number of allocated pages.
- *
- * This function releases memory allocated by kvm_alloc_cma().
- * It returns false when provided pages do not belong to contiguous area and
- * true otherwise.
- */
-bool kvm_release_cma(struct page *pages, unsigned long nr_pages)
-{
- unsigned long pfn;
- unsigned long nr_chunk;
- struct kvm_cma *cma = &kvm_cma_area;
-
- if (!cma || !pages)
- return false;
-
- pr_debug("%s(page %p count %lu)\n", __func__, (void *)pages, nr_pages);
-
- pfn = page_to_pfn(pages);
-
- if (pfn < cma->base_pfn || pfn >= cma->base_pfn + cma->count)
- return false;
-
- VM_BUG_ON(pfn + nr_pages > cma->base_pfn + cma->count);
- nr_chunk = nr_pages >> (KVM_CMA_CHUNK_ORDER - PAGE_SHIFT);
-
- mutex_lock(&kvm_cma_mutex);
- bitmap_clear(cma->bitmap,
- (pfn - cma->base_pfn) >> (KVM_CMA_CHUNK_ORDER - PAGE_SHIFT),
- nr_chunk);
- free_contig_range(pfn, nr_pages);
- mutex_unlock(&kvm_cma_mutex);
-
- return true;
-}
-
-static int __init kvm_cma_activate_area(unsigned long base_pfn,
- unsigned long count)
-{
- unsigned long pfn = base_pfn;
- unsigned i = count >> pageblock_order;
- struct zone *zone;
-
- 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 (page_zone(pfn_to_page(pfn)) != zone)
- return -EINVAL;
- }
- init_cma_reserved_pageblock(pfn_to_page(base_pfn));
- } while (--i);
- return 0;
-}
-
-static int __init kvm_cma_init_reserved_areas(void)
-{
- int bitmap_size, ret;
- unsigned long chunk_count;
- struct kvm_cma *cma = &kvm_cma_area;
-
- pr_debug("%s()\n", __func__);
- if (!cma->count)
- return 0;
- chunk_count = cma->count >> (KVM_CMA_CHUNK_ORDER - PAGE_SHIFT);
- bitmap_size = BITS_TO_LONGS(chunk_count) * sizeof(long);
- cma->bitmap = kzalloc(bitmap_size, GFP_KERNEL);
- if (!cma->bitmap)
- return -ENOMEM;
-
- ret = kvm_cma_activate_area(cma->base_pfn, cma->count);
- if (ret)
- goto error;
- return 0;
-
-error:
- kfree(cma->bitmap);
- return ret;
-}
-core_initcall(kvm_cma_init_reserved_areas);
diff --git a/arch/powerpc/kvm/book3s_hv_cma.h b/arch/powerpc/kvm/book3s_hv_cma.h
deleted file mode 100644
index 655144f..0000000
--- a/arch/powerpc/kvm/book3s_hv_cma.h
+++ /dev/null
@@ -1,27 +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.kumar@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.
- *
- */
-
-#ifndef __POWERPC_KVM_CMA_ALLOC_H__
-#define __POWERPC_KVM_CMA_ALLOC_H__
-/*
- * Both RMA and Hash page allocation will be multiple of 256K.
- */
-#define KVM_CMA_CHUNK_ORDER 18
-
-extern struct page *kvm_alloc_cma(unsigned long nr_pages,
- unsigned long align_pages);
-extern bool kvm_release_cma(struct page *pages, unsigned long nr_pages);
-extern long kvm_cma_declare_contiguous(phys_addr_t size,
- phys_addr_t alignment) __init;
-#endif
--
1.7.9.5
^ permalink raw reply related
* [PATCH v3 -next 4/9] DMA, CMA: support arbitrary bitmap granularity
From: Joonsoo Kim @ 2014-06-16 5:40 UTC (permalink / raw)
To: Andrew Morton, Aneesh Kumar K.V, Marek Szyprowski,
Michal Nazarewicz
Cc: Russell King - ARM Linux, kvm, linux-mm, Gleb Natapov,
Greg Kroah-Hartman, Alexander Graf, kvm-ppc, linux-kernel,
Minchan Kim, Paul Mackerras, Paolo Bonzini, Joonsoo Kim,
Zhang Yanfei, linuxppc-dev, linux-arm-kernel
In-Reply-To: <1402897251-23639-1-git-send-email-iamjoonsoo.kim@lge.com>
PPC KVM's CMA area 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.
v3: use consistent local variable name (Minchan)
use unsigned int for order_per_bit (Michal)
change clear_cma_bitmap to cma_clear_bitmap for consistency (Michal)
remove un-needed local variable, bitmap_maxno (Michal)
Acked-by: Michal Nazarewicz <mina86@mina86.com>
Acked-by: Zhang Yanfei <zhangyanfei@cn.fujitsu.com>
Acked-by: Minchan Kim <minchan@kernel.org>
Reviewed-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Signed-off-by: Joonsoo Kim <iamjoonsoo.kim@lge.com>
diff --git a/drivers/base/dma-contiguous.c b/drivers/base/dma-contiguous.c
index 5f62c28..c6eeb2c 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;
+ unsigned int order_per_bit; /* Order of pages represented by one bit */
struct mutex lock;
};
@@ -157,9 +158,37 @@ 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 cma_clear_bitmap(struct cma *cma, unsigned long pfn, int count)
+{
+ unsigned long bitmap_no, bitmap_count;
+
+ bitmap_no = (pfn - cma->base_pfn) >> cma->order_per_bit;
+ bitmap_count = cma_bitmap_pages_to_bits(cma, count);
+
+ mutex_lock(&cma->lock);
+ bitmap_clear(cma->bitmap, bitmap_no, bitmap_count);
+ 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_size = BITS_TO_LONGS(cma_bitmap_maxno(cma)) * sizeof(long);
unsigned long base_pfn = cma->base_pfn, pfn = base_pfn;
unsigned i = cma->count >> pageblock_order;
struct zone *zone;
@@ -215,9 +244,9 @@ static int __init cma_init_reserved_areas(void)
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)
+ phys_addr_t base, phys_addr_t limit,
+ phys_addr_t alignment, unsigned int order_per_bit,
+ struct cma **res_cma, bool fixed)
{
struct cma *cma = &cma_areas[cma_area_count];
int ret = 0;
@@ -249,6 +278,10 @@ static int __init __dma_contiguous_reserve_area(phys_addr_t size,
size = ALIGN(size, alignment);
limit &= ~(alignment - 1);
+ /* size should be aligned with order_per_bit */
+ if (!IS_ALIGNED(size >> PAGE_SHIFT, 1 << order_per_bit))
+ return -EINVAL;
+
/* Reserve memory */
if (base && fixed) {
if (memblock_is_region_reserved(base, size) ||
@@ -273,6 +306,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++;
@@ -308,7 +342,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;
@@ -320,17 +354,11 @@ 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);
-}
-
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, bitmap_no, bitmap_count;
struct page *page = NULL;
int ret;
@@ -343,18 +371,19 @@ static struct page *__dma_alloc_from_contiguous(struct cma *cma, int count,
if (!count)
return NULL;
- mask = (1 << align) - 1;
-
+ mask = cma_bitmap_aligned_mask(cma, align);
+ bitmap_maxno = cma_bitmap_maxno(cma);
+ bitmap_count = cma_bitmap_pages_to_bits(cma, count);
for (;;) {
mutex_lock(&cma->lock);
- pageno = bitmap_find_next_zero_area(cma->bitmap, cma->count,
- start, count, mask);
- if (pageno >= cma->count) {
+ bitmap_no = bitmap_find_next_zero_area(cma->bitmap,
+ bitmap_maxno, start, bitmap_count, mask);
+ if (bitmap_no >= bitmap_maxno) {
mutex_unlock(&cma->lock);
break;
}
- bitmap_set(cma->bitmap, pageno, count);
+ bitmap_set(cma->bitmap, bitmap_no, bitmap_count);
/*
* It's safe to drop the lock here. We've marked this region for
* our exclusive use. If the migration fails we will take the
@@ -362,7 +391,7 @@ static struct page *__dma_alloc_from_contiguous(struct cma *cma, int count,
*/
mutex_unlock(&cma->lock);
- pfn = cma->base_pfn + pageno;
+ pfn = cma->base_pfn + (bitmap_no << cma->order_per_bit);
mutex_lock(&cma_mutex);
ret = alloc_contig_range(pfn, pfn + count, MIGRATE_CMA);
mutex_unlock(&cma_mutex);
@@ -370,14 +399,14 @@ static struct page *__dma_alloc_from_contiguous(struct cma *cma, int count,
page = pfn_to_page(pfn);
break;
} else if (ret != -EBUSY) {
- clear_cma_bitmap(cma, pfn, count);
+ cma_clear_bitmap(cma, pfn, count);
break;
}
- clear_cma_bitmap(cma, pfn, count);
+ cma_clear_bitmap(cma, pfn, count);
pr_debug("%s(): memory range at %p is busy, retrying\n",
__func__, pfn_to_page(pfn));
/* try again with a bit different memory target */
- start = pageno + mask + 1;
+ start = bitmap_no + mask + 1;
}
pr_debug("%s(): returned %p\n", __func__, page);
@@ -424,7 +453,7 @@ static bool __dma_release_from_contiguous(struct cma *cma, struct page *pages,
VM_BUG_ON(pfn + count > cma->base_pfn + cma->count);
free_contig_range(pfn, count);
- clear_cma_bitmap(cma, pfn, count);
+ cma_clear_bitmap(cma, pfn, count);
return true;
}
--
1.7.9.5
^ permalink raw reply related
* [PATCH v3 -next 8/9] mm, CMA: change cma_declare_contiguous() to obey coding convention
From: Joonsoo Kim @ 2014-06-16 5:40 UTC (permalink / raw)
To: Andrew Morton, Aneesh Kumar K.V, Marek Szyprowski,
Michal Nazarewicz
Cc: Russell King - ARM Linux, kvm, linux-mm, Gleb Natapov,
Greg Kroah-Hartman, Alexander Graf, kvm-ppc, linux-kernel,
Minchan Kim, Paul Mackerras, Paolo Bonzini, Joonsoo Kim,
Zhang Yanfei, linuxppc-dev, linux-arm-kernel
In-Reply-To: <1402897251-23639-1-git-send-email-iamjoonsoo.kim@lge.com>
Conventionally, we put output param to the end of param list
and put the 'base' ahead of 'size', but 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.
v3: put 'base' ahead of 'size' (Minchan)
Acked-by: Michal Nazarewicz <mina86@mina86.com>
Reviewed-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Signed-off-by: Joonsoo Kim <iamjoonsoo.kim@lge.com>
diff --git a/arch/powerpc/kvm/book3s_hv_builtin.c b/arch/powerpc/kvm/book3s_hv_builtin.c
index 3960e0b..6cf498a 100644
--- a/arch/powerpc/kvm/book3s_hv_builtin.c
+++ b/arch/powerpc/kvm/book3s_hv_builtin.c
@@ -185,8 +185,8 @@ void __init kvm_cma_reserve(void)
align_size = HPT_ALIGN_PAGES << PAGE_SHIFT;
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);
+ cma_declare_contiguous(0, selected_size, 0, align_size,
+ KVM_CMA_CHUNK_ORDER - PAGE_SHIFT, false, &kvm_cma);
}
}
diff --git a/drivers/base/dma-contiguous.c b/drivers/base/dma-contiguous.c
index 0411c1c..6606abd 100644
--- a/drivers/base/dma-contiguous.c
+++ b/drivers/base/dma-contiguous.c
@@ -165,7 +165,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(base, size, limit, 0, 0, fixed, res_cma);
if (ret)
return ret;
diff --git a/include/linux/cma.h b/include/linux/cma.h
index 69d3726..32cab7a 100644
--- a/include/linux/cma.h
+++ b/include/linux/cma.h
@@ -15,7 +15,7 @@ extern unsigned long cma_get_size(struct cma *cma);
extern int __init cma_declare_contiguous(phys_addr_t size,
phys_addr_t base, phys_addr_t limit,
phys_addr_t alignment, unsigned 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 b442a13..9961120 100644
--- a/mm/cma.c
+++ b/mm/cma.c
@@ -141,13 +141,13 @@ core_initcall(cma_init_reserved_areas);
/**
* cma_declare_contiguous() - reserve custom contiguous area
- * @size: Size of the reserved area (in bytes),
* @base: Base address of the reserved area optional, use 0 for any
+ * @size: Size of the reserved area (in bytes),
* @limit: End address of the reserved memory (optional, 0 for any).
* @alignment: Alignment for the CMA area, should be power of 2 or zero
* @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)
@@ -157,12 +157,12 @@ 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 cma_declare_contiguous(phys_addr_t size,
- phys_addr_t base, phys_addr_t limit,
+int __init cma_declare_contiguous(phys_addr_t base,
+ phys_addr_t size, phys_addr_t limit,
phys_addr_t alignment, unsigned 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",
@@ -218,6 +218,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
^ permalink raw reply related
page: next (older) | prev (newer) | latest
- recent:[subjects (threaded)|topics (new)|topics (active)]
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox