Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751863AbdL2SDw (ORCPT ); Fri, 29 Dec 2017 13:03:52 -0500 Received: from mail-co1nam03on0139.outbound.protection.outlook.com ([104.47.40.139]:58052 "EHLO NAM03-CO1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751200AbdL2SDt (ORCPT ); Fri, 29 Dec 2017 13:03:49 -0500 From: Trent Piepho To: "linux-mtd@lists.infradead.org" , "linux@armlinux.org.uk" , "broonie@kernel.org" , "cyrille.pitchen@wedev4u.fr" , "dwmw2@infradead.org" , "computersforpeace@gmail.com" , "vigneshr@ti.com" , "boris.brezillon@free-electrons.com" , "richard@nod.at" , "marek.vasut@gmail.com" CC: "linux-spi@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "nicolas.ferre@microchip.com" , "radu.pirea@microchip.com" , "robh@kernel.org" , "devicetree@vger.kernel.org" Subject: Re: [PATCH 1/3] mtd: spi-nor: add optional DMA-safe bounce buffer for data transfer Thread-Topic: [PATCH 1/3] mtd: spi-nor: add optional DMA-safe bounce buffer for data transfer Thread-Index: AQHTfHXE8/fvhJVkOkO7c5x52lKY/6NWCpOAgAKMrwCAAIpvAIABAZKAgACCkIA= Date: Fri, 29 Dec 2017 18:03:47 +0000 Message-ID: <1514570627.26695.114.camel@impinj.com> References: <1514317385.26695.39.camel@impinj.com> <1a7dc424-1ce0-6c64-fc52-bb88ec7db8fa@wedev4u.fr> <1514487276.26695.94.camel@impinj.com> <08be8b42-732a-bf28-40c4-f46bf9d71c80@ti.com> In-Reply-To: <08be8b42-732a-bf28-40c4-f46bf9d71c80@ti.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: spf=none (sender IP is ) smtp.mailfrom=tpiepho@impinj.com; x-originating-ip: [216.243.31.162] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1;MWHPR0601MB3756;7:N8PZPOdisxl5kTu7Vohr2Iq2O8ZlLuvb5GThG0mnYS0WRE/oVzoJ7w++hAlHU2S6YkxbT1m39kmDkOni14MrUXS6ox65RR7VX0KbnaTmf0c+2CWgWNEFIy9sA9HZJneAqVdy3ZDWsimbT9cUWlJm5q/TlKzwWZhuNfRq5g/BZMNxJwFjkWDM1ob/FBOQ/FWTia0W1sqGRg/V+LFCSEKSyCgiayPUUuwiMzmHC8/xXkiwR1H/VfAb2wY5qLsrN7t6 x-ms-exchange-antispam-srfa-diagnostics: SSOS; x-ms-office365-filtering-correlation-id: 5b4ffe58-559a-433b-a110-08d54ee68265 x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(4534020)(4602075)(4627115)(201703031133081)(201702281549075)(5600026)(4604075)(3008032)(2017052603307)(7153060);SRVR:MWHPR0601MB3756; x-ms-traffictypediagnostic: MWHPR0601MB3756: x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:; x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(6040470)(2401047)(8121501046)(5005006)(3002001)(10201501046)(93006095)(93001095)(3231023)(944501075)(6041268)(20161123564045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123558120)(20161123562045)(20161123560045)(6072148)(201708071742011);SRVR:MWHPR0601MB3756;BCL:0;PCL:0;RULEID:(100000803101)(100110400095);SRVR:MWHPR0601MB3756; x-forefront-prvs: 0536638EAC x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(396003)(346002)(39840400004)(366004)(376002)(39380400002)(377424004)(24454002)(189003)(78114003)(199004)(76104003)(59450400001)(229853002)(76176011)(478600001)(53936002)(6436002)(103116003)(6512007)(93886005)(4326008)(316002)(68736007)(2906002)(8676002)(561944003)(6116002)(6506007)(3280700002)(81166006)(110136005)(3846002)(8936002)(6246003)(3660700001)(25786009)(99286004)(54906003)(39060400002)(81156014)(66066001)(6486002)(97736004)(2900100001)(4001150100001)(5250100002)(36756003)(106356001)(2201001)(14454004)(105586002)(217423001)(7416002)(305945005)(86362001)(2950100002)(2501003)(102836004)(7736002)(5660300001)(921003)(1121003);DIR:OUT;SFP:1102;SCL:1;SRVR:MWHPR0601MB3756;H:MWHPR0601MB3753.namprd06.prod.outlook.com;FPR:;SPF:None;PTR:InfoNoRecords;MX:1;A:1;LANG:en; x-microsoft-antispam-message-info: SRU5XsRY0JWHn8lS9jrc1WqBseRI6RtullpqwGfA5VLVqG9kp2W+USvzmLDjhaqWeVlIAjs5bX8Bn4gSSupgQA== spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="utf-8" Content-ID: <51651E7A11DB4D408180A3F356864551@namprd06.prod.outlook.com> MIME-Version: 1.0 X-OriginatorOrg: impinj.com X-MS-Exchange-CrossTenant-Network-Message-Id: 5b4ffe58-559a-433b-a110-08d54ee68265 X-MS-Exchange-CrossTenant-originalarrivaltime: 29 Dec 2017 18:03:47.9467 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 6de70f0f-7357-4529-a415-d8cbb7e93e5e X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR0601MB3756 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from base64 to 8bit by mail.home.local id vBTI3vM6001239 Content-Length: 2144 Lines: 54 On Fri, 2017-12-29 at 15:46 +0530, Vignesh R wrote: > On Friday 29 December 2017 12:24 AM, Trent Piepho wrote: > > > > > Vignesh has suggested to call virt_addr_valid() instead. > > > I think Boris has also told me about this function. > > > So it might be the right solution. What do you think about their proposal? > > > > Not sure what exactly the differences are between these methods. The > > fact that each of the many existing DMA fixes uses slightly different > > code to detect what is unsafe speaks to the difficulty of this problem! > > My understanding based on Documentation/DMA-API-HOWTO.txt and > Documentation/arm/memory.txt is that > virt_addr_valid() will guarantee that address is in range of > PAGE_OFFSET to high_memory-1 (Kernel direct-mapped RAM region) which is > address range of buffers that are DMA'able. There's code in gpmi-nand.c that does: /* first try to map the upper buffer directly */ if (virt_addr_valid(this->upper_buf) && !object_is_on_stack(this->upper_buf)) { sg_init_one(sgl, this->upper_buf, this->upper_len); So whoever wrote that thought that stack objects needed an additional test beyond virt_addr_valid. But it does appear to be far more common to depend on just virt_addr_valid, so perhaps the code in gpmi-nand is in error. > > virt_addr_valid() is already used by spi-ti-qspi. spi core uses for > > the buffer map helper, but that code path is for buffers which are NOT > > vmalloc or highmem, but are still not virt_addr_valid() for some other > > reason. > > > > if (vmalloced_buf || kmap_buf) { > /* Handle vmalloc'd or kmap'd buffers */ > ... This stuff does get DMAed. So I have to wonder, if spi.c thinks it can use DMA with vmalloc or highmem, couldn't spi-not do the same instead of the bounce buffer? > } else if (virt_addr_valid(buf)) { > /* Handle kmalloc'd and such buffers */ > ... > } else { > /* Error if none of the above */ So what is this case here for? It's some class that does not have a valid virtual address and yet is not vmalloc or highmem. > return -EINVAL; > } >