X-Received: by 2002:a05:6402:254d:b0:40b:74a9:e096 with SMTP id l13-20020a056402254d00b0040b74a9e096mr172839edb.129.1645633469608; Wed, 23 Feb 2022 08:24:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645633469; cv=none; d=google.com; s=arc-20160816; b=xLwyDO0qoWWEKma02oXSwzkETCc2s8tQ6MQG3sAFlTEstJBIzd3T6LkRotgJhFVQAx mlJKpoGx9EsaVrWAr3qMoUOhZDQrrEKtjoEfM9mN7QWAw4xr5yfCHBKrfrwdDATY9f8U t1MkCYLE3WaQFq85EmgyqvfIxfS4fjKBFksE8XGe3fGBUXaOFh8iklfuSIaAsuX6q6tS jYTmaVPgSxTHDDZp+Kp7tjW7HA2PyulVw0GTcN+ywwzp5E41Xl5IXtvRBG3KCslCyWb6 S3/N51xBdVoCrioxDSRHoFE1rAcPr3T9lA27v/aLBrmoWEjM+ZfSfUvezEEM5nv0X28A SfHQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :mime-version:accept-language:in-reply-to:references:message-id:date :thread-index:thread-topic:subject:cc:to:from; bh=FVHi4CcznDylQmp/PURNaZw7R5KbJgTsem8GiQEw2GY=; b=ksZEz5h03TI4SV4MirK4m9Afea+PFWhtOZRrs+jpzWcglc36YmR3TZ/7dxf4f/GSI6 BK4gHKqP8LMODXNT4KpqO+1WhZy1gPxZ5erMDoOsGs335ntITe5t+Jh/jYQBGK4mWRDe YSFsdeDPFKX8tQVzFjvuSxCoUttyvFf67LNKUK3lh+1ZvGcnIJD+CVe0BQshRqUxult8 S90f62aSFlpGzla7tcQ2d+weIA+mrXLhGM5HRYv9rGo/QXxiL2ed0KH/tDQa8GdimzgF 2e5qPbDnJMSUM9MIwIEK48vnmC/L6v5vSqBCAegABc3DAAuTbqmG3Ds53qpFM/x41Fac JYjw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=aculab.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v8si8582ejv.536.2022.02.23.08.23.56; Wed, 23 Feb 2022 08:24:29 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-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-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=aculab.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241849AbiBWO6F convert rfc822-to-8bit (ORCPT + 99 others); Wed, 23 Feb 2022 09:58:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52356 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241898AbiBWO6C (ORCPT ); Wed, 23 Feb 2022 09:58:02 -0500 Received: from eu-smtp-delivery-151.mimecast.com (eu-smtp-delivery-151.mimecast.com [185.58.86.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id C24EA5E140 for ; Wed, 23 Feb 2022 06:57:31 -0800 (PST) Received: from AcuMS.aculab.com (156.67.243.121 [156.67.243.121]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id uk-mta-93-G1szcwt_MjKPdsB-XVT1DQ-1; Wed, 23 Feb 2022 14:57:29 +0000 X-MC-Unique: G1szcwt_MjKPdsB-XVT1DQ-1 Received: from AcuMS.Aculab.com (fd9f:af1c:a25b:0:994c:f5c2:35d6:9b65) by AcuMS.aculab.com (fd9f:af1c:a25b:0:994c:f5c2:35d6:9b65) with Microsoft SMTP Server (TLS) id 15.0.1497.28; Wed, 23 Feb 2022 14:57:26 +0000 Received: from AcuMS.Aculab.com ([fe80::994c:f5c2:35d6:9b65]) by AcuMS.aculab.com ([fe80::994c:f5c2:35d6:9b65%12]) with mapi id 15.00.1497.028; Wed, 23 Feb 2022 14:57:26 +0000 From: David Laight To: 'Christoph Hellwig' , Baoquan He CC: "linux-kernel@vger.kernel.org" , "linux-mm@kvack.org" , "akpm@linux-foundation.org" , "cl@linux.com" , "42.hyeyoo@gmail.com" <42.hyeyoo@gmail.com>, "penberg@kernel.org" , "rientjes@google.com" , "iamjoonsoo.kim@lge.com" , "vbabka@suse.cz" , "david@redhat.com" , "herbert@gondor.apana.org.au" , "davem@davemloft.net" , "linux-crypto@vger.kernel.org" , "steffen.klassert@secunet.com" , "netdev@vger.kernel.org" , "hca@linux.ibm.com" , "gor@linux.ibm.com" , "agordeev@linux.ibm.com" , "borntraeger@linux.ibm.com" , "svens@linux.ibm.com" , "linux-s390@vger.kernel.org" , "michael@walle.cc" , "linux-i2c@vger.kernel.org" , "wsa@kernel.org" Subject: RE: [PATCH 1/2] dma-mapping: check dma_mask for streaming mapping allocs Thread-Topic: [PATCH 1/2] dma-mapping: check dma_mask for streaming mapping allocs Thread-Index: AQHYKMFGymqZSBR5G0e43mhWKNvBx6yhN5Ag Date: Wed, 23 Feb 2022 14:57:26 +0000 Message-ID: <4771de3911c24966b01fef9cf43f2d33@AcuMS.aculab.com> References: <20220219005221.634-1-bhe@redhat.com> <20220219005221.634-22-bhe@redhat.com> <20220219071730.GG26711@lst.de> <20220220084044.GC93179@MiWiFi-R3L-srv> <20220222084530.GA6210@lst.de> <20220222131120.GB10093@lst.de> <20220222155904.GA13323@lst.de> <20220223142555.GA5986@lst.de> In-Reply-To: <20220223142555.GA5986@lst.de> Accept-Language: en-GB, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-transport-fromentityheader: Hosted x-originating-ip: [10.202.205.107] MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=C51A453 smtp.mailfrom=david.laight@aculab.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: aculab.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8BIT X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=unavailable 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-kernel@vger.kernel.org From: Christoph Hellwig > Sent: 23 February 2022 14:26 > > On Wed, Feb 23, 2022 at 08:28:13AM +0800, Baoquan He wrote: > > Could you tell more why this is wrong? According to > > Documentation/core-api/dma-api.rst and DMA code, __dma_alloc_pages() is > > the core function of dma_alloc_pages()/dma_alloc_noncoherent() which are > > obviously streaming mapping, > > Why are they "obviously" streaming mappings? > > > why do we need to check > > dev->coherent_dma_mask here? Because dev->coherent_dma_mask is the subset > > of dev->dma_mask, it's safer to use dev->coherent_dma_mask in these > > places? This is confusing, I talked to Hyeonggon in private mail, he has > > the same feeling. > > Think of th coherent_dma_mask as dma_alloc_mask. It is the mask for the > DMA memory allocator. dma_mask is the mask for the dma_map_* routines. I suspect it is all to allow for things like: - A 64bit system with memory above 4G. - A device that can only generate 32bit addresses. - Some feature of the memory system (or bus bridges) that restricts cache snooping to the low 1G of address space. So dma_alloc_coherent() has to allocate memory below 1G. The dma_map functions have to use bounce-buffers for addresses above 4G. dma_alloc_noncoherent() can allocate anything below 4G and so avoid bounce buffers later on. David - Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)