From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754362AbbG3CoR (ORCPT ); Wed, 29 Jul 2015 22:44:17 -0400 Received: from mga09.intel.com ([134.134.136.24]:39408 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752856AbbG3CoQ (ORCPT ); Wed, 29 Jul 2015 22:44:16 -0400 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.15,574,1432623600"; d="scan'208";a="615679839" From: Feng Tang To: Andrew Morton , Michal Nazarewicz , Kyungmin Park , Marek Szyprowski , Joonsoo Kim , linux-kernel@vger.kernel.org Cc: Feng Tang Subject: [PATCH] CMA: Don't return a valid cma for non-cma dev Date: Thu, 30 Jul 2015 10:37:08 +0800 Message-Id: <1438223828-26140-1-git-send-email-feng.tang@intel.com> X-Mailer: git-send-email 1.7.9.5 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When system(one x86 soc) boot, we saw many normal dma allocation requests goes to cma area. The call chain is dma_generic_alloc_coherent dma_alloc_from_contiguous -- arch/x86/kernel/pci-dma.c cma_alloc(dev_get_cma_area(dev), count, align) Current dev_get_cma_area() will return a valid "cma" anyway. Then all these requests will be taken as valid cma request, and get pages from cma area, which has 2 problems: 1. make the cma area fragmented 2. confuse the cma reservation, usually cma memory size is set according to the expectation of system scenario, these unexpected requests will affect the designed cma usage. So this patch will enforce the judgement, and only return valid "cma" for real cma user, thus make normal user like IO device driver not abuse cma reserved region. Signed-off-by: Feng Tang --- include/linux/dma-contiguous.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/include/linux/dma-contiguous.h b/include/linux/dma-contiguous.h index 569bbd0..d6ccc19 100644 --- a/include/linux/dma-contiguous.h +++ b/include/linux/dma-contiguous.h @@ -66,7 +66,8 @@ static inline struct cma *dev_get_cma_area(struct device *dev) { if (dev && dev->cma_area) return dev->cma_area; - return dma_contiguous_default_area; + else + return NULL; } static inline void dev_set_cma_area(struct device *dev, struct cma *cma) -- 1.7.9.5