X-Account-Key: account11
X-UIDL: GmailId16b2c9a50ea3b90f
X-Mozilla-Status: 0013
X-Mozilla-Status2: 00000000
X-Mozilla-Keys:                                                                                 
Delivered-To: larry.finger@gmail.com
Received: by 2002:a4a:b2cb:0:0:0:0:0 with SMTP id l11csp8290747ooo;
        Thu, 6 Jun 2019 04:43:59 -0700 (PDT)
X-Google-Smtp-Source: APXvYqwCuWkmxNEorwoFA8dV9n0gnv2GBWEgptpWhjUpg7zmkwpEpAZ0OoddjKTZH+rGzLk5PqDb
X-Received: by 2002:a0d:f7c1:: with SMTP id h184mr23332511ywf.461.1559821439502;
        Thu, 06 Jun 2019 04:43:59 -0700 (PDT)
ARC-Seal: i=1; a=rsa-sha256; t=1559821439; cv=none;
        d=google.com; s=arc-20160816;
        b=cwyAMW7kgYORTfk9s11BVuRyOK1aZ/y91JWwr6KOKPjipJrjl4Z4hU3kdcWdy4XKFx
         gYTTnCmpLQjMriyYBUCnK6H+TIupoTDV4xc2Zbd0o3MYzlJDnRLoxhQ0tGLa9faooOCk
         HVI7sohOmcS2usEzXxiIFXmHZeya5uHoc8dqbhVGERSvmUYr7eJay3A3XxiVCfsgUo2x
         Wdp3LeIQ8WTPcLfY7YXjggvhCrALhNjfjR+cuKRupwAc5ExKfZ6KTUikPOVqAZeDyEk6
         FsO52PBlpxzCc+eWSTyrnhUxm1yaluTml84QKHyu4mihylKmeQH4KtH+12GJ2+ZfhDHc
         Zyww==
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816;
        h=user-agent:in-reply-to:content-disposition:mime-version:references
         :message-id:subject:cc:to:from:date:delivered-to;
        bh=kt7o1+XVy+lXH5WOMXil8IA2OM6q4I/uYbcFkZqbRc8=;
        b=yphupkT6Zz+pYJvawZCl4bXGIugoNj5iCMqRlPqyqbEf4RN+3aY22jD5xpiDlw0jjS
         4h5S9kSgQJn14JjtpTfGee/fKwo5JiazPvYu68XodDh2maHWANND00ToKt9H10yeHUUm
         09L9jV51XLMRIGvJyTsw+qYDq52Rms2nuS93spZQ+gFrEmpaVPcnua1Mk7kgT+J5hgGa
         X5Ps+iqFFYXg7SeMwWvx0juniqkBIEUvbVyyb3SKd8FW24HyYx7b/q31/0euFLwj6W8A
         8UlSDrDJ4008OUhrjFeibePvH2exlHbj/RPDpDYY4XNIsqQmb+BZulXC09QlzV0aKdLC
         D/AQ==
ARC-Authentication-Results: i=1; mx.google.com;
       spf=neutral (google.com: 209.17.115.53 is neither permitted nor denied by best guess record for domain of hch@lst.de) smtp.mailfrom=hch@lst.de
Return-Path: <hch@lst.de>
Received: from atl4mhob15.registeredsite.com (atl4mhob15.registeredsite.com. [209.17.115.53])
        by mx.google.com with ESMTP id u187si831499ybb.479.2019.06.06.04.43.59
        for <larry.finger@gmail.com>;
        Thu, 06 Jun 2019 04:43:59 -0700 (PDT)
Received-SPF: neutral (google.com: 209.17.115.53 is neither permitted nor denied by best guess record for domain of hch@lst.de) client-ip=209.17.115.53;
Authentication-Results: mx.google.com;
       spf=neutral (google.com: 209.17.115.53 is neither permitted nor denied by best guess record for domain of hch@lst.de) smtp.mailfrom=hch@lst.de
Received: from mail.hostingplatform.com (atl4qibmail17pod0.registeredsite.com [10.30.71.59])
	by atl4mhob15.registeredsite.com (8.14.4/8.14.4) with ESMTP id x56Bhxx8019893
	(version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL)
	for <larry.finger@gmail.com>; Thu, 6 Jun 2019 07:43:59 -0400
Received: (qmail 10870 invoked by uid 78); 6 Jun 2019 11:43:58 -0000
Delivered-To: lwfinger.net-Larry.Finger@lwfinger.net
Received: (qmail 10858 invoked by uid 0); 6 Jun 2019 11:43:58 -0000
Received: from unknown (HELO atl4mhib12.myregisteredsite.com) (209.17.115.147)
  by 0 with ESMTPS (DHE-RSA-AES256-GCM-SHA384 encrypted); 6 Jun 2019 11:43:58 -0000
Received: from newverein.lst.de (verein.lst.de [213.95.11.211])
	by atl4mhib12.myregisteredsite.com (8.14.4/8.14.4) with ESMTP id x56BhuC5008752
	(version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO)
	for <Larry.Finger@lwfinger.net>; Thu, 6 Jun 2019 07:43:57 -0400
Received: by newverein.lst.de (Postfix, from userid 2407)
	id C2C8268B20; Thu,  6 Jun 2019 13:43:26 +0200 (CEST)
Date: Thu, 6 Jun 2019 13:43:25 +0200
From: Christoph Hellwig <hch@lst.de>
To: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Aaro Koskinen <aaro.koskinen@iki.fi>, Christoph Hellwig <hch@lst.de>,
        Christian Zigotzky <chzigotzky@xenosoft.de>,
        Michael Ellerman <mpe@ellerman.id.au>,
        Larry Finger <Larry.Finger@lwfinger.net>,
        linuxppc-dev@lists.ozlabs.org, linux-wireless@vger.kernel.org,
        linux-kernel@vger.kernel.org
Subject: Re: [BISECTED REGRESSION] b43legacy broken on G4 PowerBook
Message-ID: <20190606114325.GA7497@lst.de>
References: <20190605225059.GA9953@darkstar.musicnaut.iki.fi> <dfe6451c93574b61d4bdde4a05c5f8ccf86b31a0.camel@kernel.crashing.org> <20190606093149.GA11598@darkstar.musicnaut.iki.fi> <d87ac9a7faac0d5522cb496d74afc586410fed9c.camel@kernel.crashing.org> <f8df19ffe5b75537045119037459ae9ad4a1de39.camel@kernel.crashing.org>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
In-Reply-To: <f8df19ffe5b75537045119037459ae9ad4a1de39.camel@kernel.crashing.org>
User-Agent: Mutt/1.5.17 (2007-11-01)
X-SpamScore: 4
X-MailHub-Apparently-To: Larry.Finger@lwfinger.net
X-MailHub-Forwarded: Yes

On Thu, Jun 06, 2019 at 08:57:49PM +1000, Benjamin Herrenschmidt wrote:
> > Wow... that's an odd amount. One thing we could possibly do is add code
> > to limit the amount of RAM when we detect that device....
> 
> Sent too quickly... I mean that *or* force swiotlb at 30-bits on those systems based
> on detecting the presence of that device in the device-tree.

swiotlb doesn't really help you, as these days swiotlb on matters for
the dma_map* case.  What would help is a ZONE_DMA that covers these
devices.  No need to do the 24-bit x86 does, but 30-bit would do it.

WIP patch for testing below:

diff --git a/arch/powerpc/include/asm/page.h b/arch/powerpc/include/asm/page.h
index b8286a2013b4..7a367ce87c41 100644
--- a/arch/powerpc/include/asm/page.h
+++ b/arch/powerpc/include/asm/page.h
@@ -319,6 +319,10 @@ struct vm_area_struct;
 #endif /* __ASSEMBLY__ */
 #include <asm/slice.h>
 
+#if 1 /* XXX: pmac?  dynamic discovery? */
+#define ARCH_ZONE_DMA_BITS 30
+#else
 #define ARCH_ZONE_DMA_BITS 31
+#endif
 
 #endif /* _ASM_POWERPC_PAGE_H */
diff --git a/arch/powerpc/mm/mem.c b/arch/powerpc/mm/mem.c
index cba29131bccc..2540d3b2588c 100644
--- a/arch/powerpc/mm/mem.c
+++ b/arch/powerpc/mm/mem.c
@@ -248,7 +248,8 @@ void __init paging_init(void)
 	       (long int)((top_of_ram - total_ram) >> 20));
 
 #ifdef CONFIG_ZONE_DMA
-	max_zone_pfns[ZONE_DMA]	= min(max_low_pfn, 0x7fffffffUL >> PAGE_SHIFT);
+	max_zone_pfns[ZONE_DMA]	= min(max_low_pfn,
+			((1UL << ARCH_ZONE_DMA_BITS) - 1) >> PAGE_SHIFT);
 #endif
 	max_zone_pfns[ZONE_NORMAL] = max_low_pfn;
 #ifdef CONFIG_HIGHMEM


