From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.5 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 75B2BC433E1 for ; Mon, 22 Jun 2020 12:46:52 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 3FAFF20738 for ; Mon, 22 Jun 2020 12:46:52 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3FAFF20738 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=8bytes.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id BF0A46B0002; Mon, 22 Jun 2020 08:46:51 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id BA09F6B0003; Mon, 22 Jun 2020 08:46:51 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id ADFAB6B0005; Mon, 22 Jun 2020 08:46:51 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0185.hostedemail.com [216.40.44.185]) by kanga.kvack.org (Postfix) with ESMTP id 818A66B0002 for ; Mon, 22 Jun 2020 08:46:51 -0400 (EDT) Received: from smtpin10.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 2A52C2C88 for ; Mon, 22 Jun 2020 12:46:51 +0000 (UTC) X-FDA: 76956822222.10.fuel54_3f158da26e33 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin10.hostedemail.com (Postfix) with ESMTP id EFA6216A07F for ; Mon, 22 Jun 2020 12:46:50 +0000 (UTC) X-HE-Tag: fuel54_3f158da26e33 X-Filterd-Recvd-Size: 5345 Received: from theia.8bytes.org (8bytes.org [81.169.241.247]) by imf37.hostedemail.com (Postfix) with ESMTP for ; Mon, 22 Jun 2020 12:46:50 +0000 (UTC) Received: by theia.8bytes.org (Postfix, from userid 1000) id 907AA36B; Mon, 22 Jun 2020 14:46:48 +0200 (CEST) Date: Mon, 22 Jun 2020 14:46:47 +0200 From: Joerg Roedel To: Andrea Arcangeli Cc: Robin Murphy , Roman Gushchin , Yang Shi , iommu@lists.linux-foundation.org, Linux Kernel Mailing List , Linux MM , Michal Hocko , Johannes Weiner , "Kirill A. Shutemov" , Andrew Morton , Wei Yang Subject: Re: kernel BUG at mm/huge_memory.c:2613! Message-ID: <20200622124646.GI3701@8bytes.org> References: <20200619001938.GA135965@carbon.dhcp.thefacebook.com> <20200619011449.GC135965@carbon.dhcp.thefacebook.com> <20200619024026.GB21081@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200619024026.GB21081@redhat.com> User-Agent: Mutt/1.10.1 (2018-07-13) X-Rspamd-Queue-Id: EFA6216A07F X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam05 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: + Robin Robin, any idea on this? On Thu, Jun 18, 2020 at 10:40:26PM -0400, Andrea Arcangeli wrote: > Hello, > > On Thu, Jun 18, 2020 at 06:14:49PM -0700, Roman Gushchin wrote: > > I agree. The whole > > > > page = alloc_pages_node(nid, alloc_flags, order); > > if (!page) > > continue; > > if (!order) > > break; > > if (!PageCompound(page)) { > > split_page(page, order); > > break; > > } else if (!split_huge_page(page)) { > > break; > > } > > > > looks very suspicious to me. > > My wild guess is that gfp flags changed somewhere above, so we hit > > the branch which was never hit before. > > Right to be suspicious about the above: split_huge_page on a regular > page allocated by a driver was never meant to work. > > The PageLocked BUG_ON is just a symptom of a bigger issue, basically > split_huge_page it may survive, but it'll stay compound and in turn it > must be freed as compound. > > The respective free method doesn't even contemplate freeing compound > pages, the only way the free method can survive, is by removing > __GFP_COMP forcefully in the allocation that was perhaps set here > (there are that many __GFP_COMP in that directory): > > static void snd_malloc_dev_pages(struct snd_dma_buffer *dmab, size_t size) > { > gfp_t gfp_flags; > > gfp_flags = GFP_KERNEL > | __GFP_COMP /* compound page lets parts be mapped */ > > And I'm not sure what the comment means here, compound or non compound > doesn't make a difference when you map it, it's not a THP, the > mappings must be handled manually so nothing should check PG_compound > anyway in the mapping code. > > Something like this may improve things, it's an untested quick hack, > but this assumes it's always a bug to setup a compound page for these > DMA allocations and given the API it's probably a correct > assumption.. Compound is slower, unless you need it, you can avoid it > and then split_page will give contiguous memory page granular. Ideally > the code shouldn't call split_page at all and it should free it all at > once by keeping track of the order and by returning the order to the > caller, something the API can't do right now as it returns a plain > array that can only represent individual small pages. > > Once this is resolved, you may want to check your config, iommu passthrough > sounds more optimal for a soundcard. > > diff --git a/drivers/iommu/dma-iommu.c b/drivers/iommu/dma-iommu.c > index f68a62c3c32b..3dfbc010fa83 100644 > --- a/drivers/iommu/dma-iommu.c > +++ b/drivers/iommu/dma-iommu.c > @@ -499,6 +499,10 @@ static struct page **__iommu_dma_alloc_pages(struct device *dev, > > /* IOMMU can map any pages, so himem can also be used here */ > gfp |= __GFP_NOWARN | __GFP_HIGHMEM; > + if (unlikely(gfp & __GFP_COMP)) { > + WARN(); > + gfp &= ~__GFP_COMP; > + } > > while (count) { > struct page *page = NULL; > @@ -522,13 +526,8 @@ static struct page **__iommu_dma_alloc_pages(struct device *dev, > continue; > if (!order) > break; > - if (!PageCompound(page)) { > - split_page(page, order); > - break; > - } else if (!split_huge_page(page)) { > - break; > - } > - __free_pages(page, order); > + split_page(page, order); > + break; > } > if (!page) { > __iommu_dma_free_pages(pages, i); > diff --git a/sound/core/memalloc.c b/sound/core/memalloc.c > index 6850d13aa98c..378f5a36ec5f 100644 > --- a/sound/core/memalloc.c > +++ b/sound/core/memalloc.c > @@ -28,7 +28,6 @@ static void snd_malloc_dev_pages(struct snd_dma_buffer *dmab, size_t size) > gfp_t gfp_flags; > > gfp_flags = GFP_KERNEL > - | __GFP_COMP /* compound page lets parts be mapped */ > | __GFP_NORETRY /* don't trigger OOM-killer */ > | __GFP_NOWARN; /* no stack trace print - this call is non-critical */ > dmab->area = dma_alloc_coherent(dmab->dev.dev, size, &dmab->addr,