Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp2509951ybt; Fri, 3 Jul 2020 10:43:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzYgCso4YvwllH9CuUuHnLkVENqJPe2usE2Xf4Hb/wnJDNSOa5dqdrBWH+l7zLBrYPZkU8A X-Received: by 2002:a50:d78f:: with SMTP id w15mr43698530edi.245.1593798209343; Fri, 03 Jul 2020 10:43:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1593798209; cv=none; d=google.com; s=arc-20160816; b=iWWqeLhsFm2ViiZwhndLw0h2v1yb+TF0AAA2JhD+xwcfq/0EEU2AYVKkrWLPUn8nLD 7CT9aPfHwvndEFoOCWBi+zuHmB7Ys0HCvWmDXoSKxiOYoZh0mbKkqg5NzTrIFjWc7K3y ic7nvakRmDAfDk1zvFTEIt3zIEjfp7j9FjnWUrwVyq0TpPmKophhMfmYfGq2+VEQVs0d PJgcTtLoEDWbrcpzv7FdfUhyVpiSF3kIhpzd7BlONgJgXLUc39hVrQvzMltlh/laKn+7 /nAbzPhr/CYB747n4LVMfDIZtXnSjBrRuCnAHL3lGEpJ+RKmk6VmsBkXaM+lzHbHk6js ws9w== 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 :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=zCNxOnSWylenGbEjwlPhO9U5MEQjmA2eQmTgmGyKExA=; b=LhH50Oyo/mOwj5FQbUWs6dVXpjwr7hPd1Y3PE8/ufkXd9mUChCDKPDEeaG+VbURzCx TrNWC/1dnypTRZPwhpsxSkMxNpBBoJ52DztrfGTcxbgFHLPmFyoukIyeaSJ7ONmV+Lzl 3VFHRDDAmLME2nVrl2XsVC6b+jdO24M6bCMClH3MMvV1klPKHf7Cvk7kUGFCxdvnO/lr 2HCbxFvnqpmPKGJfu3XIm3+ruqS6Df2EMhC6kNPbUCJIftc9vWaIVqYb3gvkxbBpaWTg v/aHpeO3qPJAsbnd55yLgcRM+3l5enLDiGzOqtoGslyDX4gBCKmzKdond8evjf+LZgIO hWWg== 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 ce9si8920214edb.70.2020.07.03.10.43.06; Fri, 03 Jul 2020 10:43:29 -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 S1726830AbgGCRm3 (ORCPT + 99 others); Fri, 3 Jul 2020 13:42:29 -0400 Received: from foss.arm.com ([217.140.110.172]:56312 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726801AbgGCRm2 (ORCPT ); Fri, 3 Jul 2020 13:42:28 -0400 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 2175831B; Fri, 3 Jul 2020 10:42:27 -0700 (PDT) Received: from [10.57.21.32] (unknown [10.57.21.32]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id BFF653F73C; Fri, 3 Jul 2020 10:42:25 -0700 (PDT) Subject: Re: [BUG] XHCI getting ZONE_DMA32 memory > than its bus_dma_limit To: Nicolas Saenz Julienne , Jeremy Linton , "linux-arm-kernel@lists.infradead.org" , linux-mm@kvack.org, "linux-usb@vger.kernel.org" , rientjes@google.com, Christoph Hellwig , "linux-kernel@vger.kernel.org" Cc: linux-rpi-kernel References: <34619bdf-6527-ae82-7e4d-e2ea7c67ed56@arm.com> From: Robin Murphy Message-ID: Date: Fri, 3 Jul 2020 18:42:24 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-GB Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2020-07-03 15:53, Nicolas Saenz Julienne wrote: > Hi Jeremy, > thanks for the bug report. > > Just for the record the offending commit is: c84dc6e68a1d2 ("dma-pool: add > additional coherent pools to map to gfp mask"). > > On Thu, 2020-07-02 at 12:49 -0500, Jeremy Linton wrote: >> Hi, >> >> Using 5.8rc3: >> >> The rpi4 has a 3G dev->bus_dma_limit on its XHCI controller. With a usb3 >> hub, plus a few devices plugged in, randomly devices will fail >> operations. This appears to because xhci_alloc_container_ctx() is >> getting buffers > 3G via dma_pool_zalloc(). >> >> Tracking that down, it seems to be caused by dma_alloc_from_pool() using >> dev_to_pool()->dma_direct_optimal_gfp_mask() to "optimistically" select >> the atomic_pool_dma32 but then failing to verify that the allocations in >> the pool are less than the dev bus_dma_limit. > > I can reproduce this too. > > The way I see it, dev_to_pool() wants a strict dma_direct_optimal_gfp_mask() > that is never wrong, since it's going to stick to that pool for the device's > lifetime. I've been looking at how to implement it, and it's not so trivial as > I can't see a failproof way to make a distinction between who needs DMA32 and > who is OK with plain KERNEL memory. > > Otherwise, as Jeremy points out, the patch needs to implement allocations with > an algorithm similar to __dma_direct_alloc_pages()'s, which TBH I don't know if > it's a little overkill for the atomic context. > > Short of finding a fix in the coming rc's, I suggest we revert this. Or perhaps just get rid of atomic_pool_dma32 (and allocate atomic_pool_dma from ZONE_DMA32 if !ZONE_DMA). That should make it fall pretty much back in line while still preserving the potential benefit of the kernel pool for non-address-constrained devices. Robin.