Received: by 2002:a05:6358:a55:b0:ec:fcf4:3ecf with SMTP id 21csp3138324rwb; Fri, 20 Jan 2023 11:44:12 -0800 (PST) X-Google-Smtp-Source: AMrXdXtkoC9Z/3kNoVJDuLdtNrp0AvZWfSxVyzWcBRkpiTGpI9ixJ3zP/Hm02bYsJ5C569M0BHAO X-Received: by 2002:a17:907:8a1d:b0:84d:3822:2fc7 with SMTP id sc29-20020a1709078a1d00b0084d38222fc7mr21517689ejc.77.1674243852354; Fri, 20 Jan 2023 11:44:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674243852; cv=none; d=google.com; s=arc-20160816; b=BuWjcO8OMnFGpE2ECXBgqLUJjFM5Fhi5rkZkOiB3bMohYj0j7AWxWCuYl/tJSGAuyn dL9j9UCRTsQy5mTdNQJ/+AGq2WgGw3Kn/mTD/+rbXRr30f5HxxwlNkAe533UDk7Q8bN8 fR/Mp7buFNgbfUKS8qc5MfUny3kdyTiWCqWrf1PBkfbiFHFBTmH8ImtQCYGPH9VEaM/k 3A3MeqbY/L38tUONFDdOY8zU2PtJCJOLfOTNuj9WXH3khruqWwXe6IiN3kch8Qqka8/r uS+Ci+vsvvBRGA1SLidlkDqdUxRPcMN9nhlyqwEaE5kHbRmFkAbcAYT7zUm0+SWvaM9n bw8g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id; bh=iWxVjflqb25sWfI75qdLuTTRiTrEQAHL2kKbmB5jVKY=; b=h6V/YpDJEt4OQgTmRQ3ywWXOD+Sa6+VmvlfScxtcCbb8GFhxqIEP2t0oRpICIm52xL n4YRe35CPJTT5Oz16obL/s5vTk+/sYiBmZEXdG635zsND4yhniqVqbvM/KDb92+CCqxQ glvSqHF+jw97HuIV7LHSyfuXCXyUBMUx+36DFxqTlVDBTL+cEYtbLpPkLR+JtwV6Pqdt WcmPkPe+VcyWPplm4aERLTZ1KslBgJdPppDysv2o5G19ylW98dUn9KKRsHSI7Fsde+dH 5aScYPg0QxoGMyAJey8go7pElqaoJyxhXtVAo67xNE7hSsFYD+Ry8TX2bx7s8wwW4qev xNow== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v7-20020a509547000000b0049e7d30f950si4801694eda.539.2023.01.20.11.43.55; Fri, 20 Jan 2023 11:44:12 -0800 (PST) Received-SPF: pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229910AbjATT3O (ORCPT + 63 others); Fri, 20 Jan 2023 14:29:14 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34420 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229877AbjATT3M (ORCPT ); Fri, 20 Jan 2023 14:29:12 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id C3AE0D0DA2; Fri, 20 Jan 2023 11:28:48 -0800 (PST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id CB11511FB; Fri, 20 Jan 2023 11:29:08 -0800 (PST) Received: from [10.57.89.132] (unknown [10.57.89.132]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id A6FF03F445; Fri, 20 Jan 2023 11:28:23 -0800 (PST) Message-ID: Date: Fri, 20 Jan 2023 19:28:19 +0000 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; rv:102.0) Gecko/20100101 Thunderbird/102.6.1 Subject: Re: [PATCH v2 04/10] iommu/dma: Use the gfp parameter in __iommu_dma_alloc_noncontiguous() Content-Language: en-GB To: Jason Gunthorpe , Lu Baolu , Joerg Roedel , Kevin Tian , Matthew Rosato Cc: Alex Williamson , ath10k@lists.infradead.org, ath11k@lists.infradead.org, Christian Borntraeger , dri-devel@lists.freedesktop.org, iommu@lists.linux.dev, kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-arm-msm@vger.kernel.org, linux-media@vger.kernel.org, linux-rdma@vger.kernel.org, linux-remoteproc@vger.kernel.org, linux-s390@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com, linux-tegra@vger.kernel.org, linux-wireless@vger.kernel.org, netdev@vger.kernel.org, nouveau@lists.freedesktop.org, Niklas Schnelle , virtualization@lists.linux-foundation.org References: <4-v2-ce66f632bd0d+484-iommu_map_gfp_jgg@nvidia.com> From: Robin Murphy In-Reply-To: <4-v2-ce66f632bd0d+484-iommu_map_gfp_jgg@nvidia.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00,NICE_REPLY_A, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org On 2023-01-18 18:00, Jason Gunthorpe wrote: > Change the sg_alloc_table_from_pages() allocation that was hardwired to > GFP_KERNEL to use the gfp parameter like the other allocations in this > function. > > Auditing says this is never called from an atomic context, so it is safe > as is, but reads wrong. I think the point may have been that the sgtable metadata is a logically-distinct allocation from the buffer pages themselves. Much like the allocation of the pages array itself further down in __iommu_dma_alloc_pages(). I see these days it wouldn't be catastrophic to pass GFP_HIGHMEM into __get_free_page() via sg_kmalloc(), but still, allocating implementation-internal metadata with all the same constraints as a DMA buffer has just as much smell of wrong about it IMO. I'd say the more confusing thing about this particular context is why we're using iommu_map_sg_atomic() further down - that seems to have been an oversight in 781ca2de89ba, since this particular path has never supported being called in atomic context. Overall I'm starting to wonder if it might not be better to stick a "use GFP_KERNEL_ACCOUNT if you allocate" flag in the domain for any level of the API internals to pick up as appropriate, rather than propagate per-call gfp flags everywhere. As it stands we're still missing potential pagetable and other domain-related allocations by drivers in .attach_dev and even (in probably-shouldn't-really-happen cases) .unmap_pages... Thanks, Robin. > Signed-off-by: Jason Gunthorpe > --- > drivers/iommu/dma-iommu.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/drivers/iommu/dma-iommu.c b/drivers/iommu/dma-iommu.c > index 8c2788633c1766..e4bf1bb159f7c7 100644 > --- a/drivers/iommu/dma-iommu.c > +++ b/drivers/iommu/dma-iommu.c > @@ -822,7 +822,7 @@ static struct page **__iommu_dma_alloc_noncontiguous(struct device *dev, > if (!iova) > goto out_free_pages; > > - if (sg_alloc_table_from_pages(sgt, pages, count, 0, size, GFP_KERNEL)) > + if (sg_alloc_table_from_pages(sgt, pages, count, 0, size, gfp)) > goto out_free_iova; > > if (!(ioprot & IOMMU_CACHE)) {