Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp1539983ybt; Thu, 9 Jul 2020 09:21:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxI6+TC6UdWHx41DR2xldeAyQTq/VY0BK0y5vqr/pbhtas/7C5oqDRe6YKmpRHFON6qhvZd X-Received: by 2002:a05:6402:b4b:: with SMTP id bx11mr71311126edb.286.1594311668339; Thu, 09 Jul 2020 09:21:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594311668; cv=none; d=google.com; s=arc-20160816; b=dYZ6j4prFz5EDc8eCILP/WxB+PfmDYipH+srUfBejL9hp6EJMNhCbbMqch5bcosjSp DigM+lGg6DkYWHla/Y2h8rKciUFf6iQ8oAe/LEvp3vw29p9NcmqP3luJtJ+uCVEnUmc/ VBFiHokSmo68pK2WfRF1Bj9EdsP3FfOL3GTu7h7t3+TcqnfoSx8h5t4X6J7BAL1JfQK4 SjUib9ZO15ayPsrC7UBQQf5CoZUqxU6mTo8I2cqilTPvIqhbkkw8T60XXCr21kqJzV/W gbWc32Hx2r/R6BNTAfsrqLR9C/3BzkUq0NqzoDyoVuvVlI0ASUmvLwDXY5kxPo0kEh+S 8UCQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=I3Ub/E8Jtcrejd4V3jGdDXcR9qZ7MniBq0swpMfuv08=; b=vFnftgFP+sqYACAYgr8M5XiJElD4adkmb7cBEfDhikPK6YscPUUshFMbfujOOENGRA a3tQFpRTyofGxYnE7ute9aQ1Zy+6Izi3JFW32E0zl6qriiLcEyx0/zsBHy+UoxAGuD4s Yiqd5LJ5cD3D3xsjsvGvm5BvKOLqOB5RGVzndAGKohnZjNurBRWuihsjxioEitCpIE7e JcWgzEVra6chhVlQyEcYZbZdcLndfTc8hbv82Lw5h1L99yY3ve/+Z+6kKs35NDx3l7Gl CpoRNNFwbrVA9hjOgGcqgSrN4Pd6bFSGf51eLRsxfcVwUtZ3M4GWcB6GTE2jwfvMDQmT WYnA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id p5si2298654edt.466.2020.07.09.09.20.44; Thu, 09 Jul 2020 09:21:08 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728276AbgGIQTm (ORCPT + 99 others); Thu, 9 Jul 2020 12:19:42 -0400 Received: from mx2.suse.de ([195.135.220.15]:39146 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728132AbgGIQTg (ORCPT ); Thu, 9 Jul 2020 12:19:36 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id EA3F0AEC8; Thu, 9 Jul 2020 16:19:33 +0000 (UTC) From: Nicolas Saenz Julienne To: hch@lst.de, Robin Murphy , David Rientjes , iommu@lists.linux-foundation.org, Marek Szyprowski Cc: linux-rpi-kernel@lists.infradead.org, jeremy.linton@arm.com, Nicolas Saenz Julienne , linux-kernel@vger.kernel.org Subject: [PATCH 3/4] dma-pool: Introduce dma_guess_pool() Date: Thu, 9 Jul 2020 18:19:03 +0200 Message-Id: <20200709161903.26229-4-nsaenzjulienne@suse.de> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200709161903.26229-1-nsaenzjulienne@suse.de> References: <20200709161903.26229-1-nsaenzjulienne@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org dma-pool's dev_to_pool() creates the false impression that there is a way to grantee a mapping between a device's DMA constraints and an atomic pool. It tuns out it's just a guess, and the device might need to use an atomic pool containing memory from a 'safer' (or lower) memory zone. To help mitigate this, introduce dma_guess_pool() which can be fed a device's DMA constraints or an atomic pool already known to be faulty in order for it to provide a better guess at which pool to use. Signed-off-by: Nicolas Saenz Julienne --- kernel/dma/pool.c | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/kernel/dma/pool.c b/kernel/dma/pool.c index 7363640fc91c..3d518de07617 100644 --- a/kernel/dma/pool.c +++ b/kernel/dma/pool.c @@ -203,7 +203,7 @@ static int __init dma_atomic_pool_init(void) } postcore_initcall(dma_atomic_pool_init); -static inline struct gen_pool *dev_to_pool(struct device *dev) +static inline struct gen_pool *dma_guess_pool_from_device(struct device *dev) { u64 phys_mask; gfp_t gfp; @@ -217,10 +217,30 @@ static inline struct gen_pool *dev_to_pool(struct device *dev) return atomic_pool_kernel; } +static inline struct gen_pool *dma_get_safer_pool(struct gen_pool *bad_pool) +{ + if (bad_pool == atomic_pool_kernel) + return atomic_pool_dma32 ? : atomic_pool_dma; + + if (bad_pool == atomic_pool_dma32) + return atomic_pool_dma; + + return NULL; +} + +static inline struct gen_pool *dma_guess_pool(struct device *dev, + struct gen_pool *bad_pool) +{ + if (bad_pool) + return dma_get_safer_pool(bad_pool); + + return dma_guess_pool_from_device(dev); +} + void *dma_alloc_from_pool(struct device *dev, size_t size, struct page **ret_page, gfp_t flags) { - struct gen_pool *pool = dev_to_pool(dev); + struct gen_pool *pool = dma_guess_pool(dev, NULL); unsigned long val; void *ptr = NULL; @@ -245,7 +265,7 @@ void *dma_alloc_from_pool(struct device *dev, size_t size, bool dma_free_from_pool(struct device *dev, void *start, size_t size) { - struct gen_pool *pool = dev_to_pool(dev); + struct gen_pool *pool = dma_guess_pool(dev, NULL); if (!pool || !gen_pool_has_addr(pool, (unsigned long)start, size)) return false; -- 2.27.0