Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp306305ybb; Wed, 15 Apr 2020 01:40:58 -0700 (PDT) X-Google-Smtp-Source: APiQypIoMNBLF8rCMWeHhZNIbVcuyvTKagAKetbBWsrciJb5Mip1hxL1b+vvZevN8gYrfchP5nrm X-Received: by 2002:a17:906:d9cf:: with SMTP id qk15mr4067899ejb.55.1586940058603; Wed, 15 Apr 2020 01:40:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1586940058; cv=none; d=google.com; s=arc-20160816; b=gdJUQ35BIp5gmLrQtCxv+LRxNkSajM4HNCk7DdI0BHogwnGcRb4D2T6dlWqzEIv1E4 JEVhF8r0j/L1J/brTxHJQMri1zE5A3dQ6HF+W9BQbMQvmDihCXD5c4dbSrPKIij4Uegz aozWz5M8oK8LO5StmxaG9Byi0RLxmBsMWtp3nDG4Kuv/LJQW5A2raM/BNl2AbR44SV3V ehQfVSPTYizo0JXs9a8B02Ny1JMXiiDvRzj2PNlVewgIgtfsviV2Ehj2Fp17+kF6VNkB 4rPPCQE00FuQXhaRXtJ27vw4qMFUus7bjoi/JEkGAyKCISWp3Quz1CpnY9g/uEUyqu9S 7arQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=A2RowUjCD/F36KDFuntQcHuGs8Lzj8pWrn7+X4mOzBA=; b=qR2Lhjh4rf7b4E+Npc3YI1PpBNyi4LDRgCYltbr8WpTEnl3WPCWGKi6D82kmhxZxHn Iu3yQL3aFq6VSeWyT8x4dDGYpY40SXeoioXX9P08A322Cuw4p9/KiYO4/5L0LtYrFwg6 mg/HTAn7YVkw8fv7NYFUWwqB2NPLKXbOQv5EncVjofPfDZnBpoQ1vgn9tkWLmJqjXZ3V XhoKQAF+VJX4Sjc/ONuTzoxjeXAdPdfLGFlV4VOUHDP3g3RWf1foj3DDb6+2SHg04MiE EEbsPg9f2CJvijkuk1/tIvKTUJx/x7KailyPi55riCI9yBerckMArBgR4cnwFnJIUB+P kiIw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for 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 d21si10929617ejk.498.2020.04.15.01.40.33; Wed, 15 Apr 2020 01:40:58 -0700 (PDT) Received-SPF: pass (google.com: best guess record for 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: best guess record for 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 S2406073AbgDNGng (ORCPT + 99 others); Tue, 14 Apr 2020 02:43:36 -0400 Received: from verein.lst.de ([213.95.11.211]:37684 "EHLO verein.lst.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728133AbgDNGnf (ORCPT ); Tue, 14 Apr 2020 02:43:35 -0400 Received: by verein.lst.de (Postfix, from userid 2407) id 1EBA468BEB; Tue, 14 Apr 2020 08:43:32 +0200 (CEST) Date: Tue, 14 Apr 2020 08:43:32 +0200 From: Christoph Hellwig To: David Rientjes Cc: Christoph Hellwig , Tom Lendacky , "Singh, Brijesh" , "Grimm, Jon" , Joerg Roedel , "linux-kernel@vger.kernel.org" , "iommu@lists.linux-foundation.org" Subject: Re: [rfc v2 4/6] dma-direct: atomic allocations must come from atomic coherent pools Message-ID: <20200414064332.GB23359@lst.de> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.17 (2007-11-01) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org > + /* > + * Unencrypted memory must come directly from DMA atomic pools if > + * blocking is not allowed. > + */ > + if (IS_ENABLED(CONFIG_DMA_COHERENT_POOL) && > + force_dma_unencrypted(dev) && !gfpflags_allow_blocking(gfp)) { > + ret = dma_alloc_from_pool(dev, PAGE_ALIGN(size), &page, gfp); > + if (!ret) > + return NULL; > + goto done; > + } > + > if (IS_ENABLED(CONFIG_DMA_DIRECT_REMAP) && > dma_alloc_need_uncached(dev, attrs) && > !gfpflags_allow_blocking(gfp)) { Can we keep a single conditional for the pool allocations? Maybe add a new dma_alloc_from_pool helper ala: static inline bool dma_alloc_from_pool(struct device *dev, gfp_t gfp) { if (!IS_ENABLED(CONFIG_DMA_COHERENT_POOL)) return false; if (gfpflags_allow_blocking(gfp)) return false; if (force_dma_unencrypted(dev)) return true; if (dma_alloc_need_uncached(dev)) return true; } } > @@ -203,6 +215,10 @@ void dma_direct_free_pages(struct device *dev, size_t size, void *cpu_addr, > { > unsigned int page_order = get_order(size); > > + if (IS_ENABLED(CONFIG_DMA_COHERENT_POOL) && > + dma_free_from_pool(dev, cpu_addr, PAGE_ALIGN(size))) > + return; > + Similarly I think we should have a single conditional to free from the pool instead.