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 Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1A428E732E7 for ; Thu, 28 Sep 2023 16:21:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231171AbjI1QV2 (ORCPT ); Thu, 28 Sep 2023 12:21:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45608 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231301AbjI1QVZ (ORCPT ); Thu, 28 Sep 2023 12:21:25 -0400 Received: from out3-smtp.messagingengine.com (out3-smtp.messagingengine.com [66.111.4.27]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 639CE136 for ; Thu, 28 Sep 2023 09:21:22 -0700 (PDT) Received: from compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailout.nyi.internal (Postfix) with ESMTP id 297385C0326; Thu, 28 Sep 2023 12:21:19 -0400 (EDT) Received: from imap51 ([10.202.2.101]) by compute6.internal (MEProxy); Thu, 28 Sep 2023 12:21:19 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=arndb.de; h=cc :cc:content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:sender :subject:subject:to:to; s=fm1; t=1695918079; x=1696004479; bh=p4 69W9XInE59/vnc2w8MJndcGm8KAMBXNFVAn/JwZEc=; b=Z1Kq296job7vIE/mHu VbYAvcBzkKkYvSUTPLWGS9loNusIlqPcMhqfwYzenbo798nIvGXv5wuF2KgxJqPH ZaZXEaYppw1FXDHgmY+DrHYXD9IfywbETYIHhmB/qPcfAum6z9xlwfvcWnZoW2sQ VUuPjWuglLUqof6omzQUt7UyRjK4esti+K/gM1FourvAcCwvS4Efa89U0gr1+72e IsT33D1cBpvIygNIf+G8wIX6NIN6ujO28aTfuPsWmHklIWyE/iENqWyfYVJKMWRb XbcJ8IEqBNO7tO9gXrnaHnwUqOn6chylfEZrgkMPvEnHn3TgNRu4NoAwtXo6WvKR pOFQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:sender:subject :subject:to:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm2; t=1695918079; x=1696004479; bh=p469W9XInE59/ vnc2w8MJndcGm8KAMBXNFVAn/JwZEc=; b=JD7SZWCc1+erEigqzF1UR86Q4nect JM6ZE+yzZCwc3yzImH8KKsd4HEZkv4XhXnacHvPrQsO7lVWMwz4sgLwpGNP0dxav +rrzXE709wxj6CLygtVwG9azQI6yba22R/ifCP/41p+L3VaDjTOiMCW5DDlyzIk3 NYXVqZQ8CQ3fxpy0uyUU/TCJMwaAJw5pQfMgds7iTKzwMJqsbwaxSL6ltntAJhqI oZw2tKxfvf9g4Rr1tWgr/ivdDokveDrFIlOrDqaUOcpBHqHNvxkTKOAb65QMRc9I w/HNplw9LVYkjN+h1K/rUgziIuV3sz2WkqxZS5mZmL7rIteixAPwyjD3g== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvkedrtddtgdeilecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpefofgggkfgjfhffhffvvefutgesthdtredtreertdenucfhrhhomhepfdetrhhn ugcuuegvrhhgmhgrnhhnfdcuoegrrhhnugesrghrnhgusgdruggvqeenucggtffrrghtth gvrhhnpeffheeugeetiefhgeethfejgfdtuefggeejleehjeeutefhfeeggefhkedtkeet ffenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpegrrh hnugesrghrnhgusgdruggv X-ME-Proxy: Feedback-ID: i56a14606:Fastmail Received: by mailuser.nyi.internal (Postfix, from userid 501) id A70AAB6008F; Thu, 28 Sep 2023 12:21:17 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.9.0-alpha0-958-g1b1b911df8-fm-20230927.002-g1b1b911d MIME-Version: 1.0 Message-Id: In-Reply-To: References: <20230926175208.9298-1-james.quinlan@broadcom.com> <20230926175208.9298-2-james.quinlan@broadcom.com> <1f08bd12-0ac4-43ea-b058-7836521eec12@app.fastmail.com> Date: Thu, 28 Sep 2023 12:20:56 -0400 From: "Arnd Bergmann" To: "Robin Murphy" , "Jim Quinlan" Cc: "Linus Walleij" , "Christoph Hellwig" , bcm-kernel-feedback-list@broadcom.com, jim2101024@gmail.com, "Russell King" , "Geert Uytterhoeven" , "Russell King" , "Andrew Morton" , "Jonathan Corbet" , "Thomas Gleixner" , "Sebastian Reichel" , "Mike Rapoport" , "Eric DeVolder" , "Nathan Chancellor" , "Kirill A. Shutemov" , "Christophe Leroy" , "moderated list:ARM PORT" , "open list" , "Claire Chang" Subject: Re: [PATCH v1 1/1] ARM: Select DMA_DIRECT_REMAP to fix restricted DMA Content-Type: text/plain Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Sep 28, 2023, at 11:33, Robin Murphy wrote: > On 28/09/2023 4:16 pm, Arnd Bergmann wrote: > >> It's unlikely but not impossible, as the driver has some >> unusual constructs, using a lot of coherent mappings that >> might otherwise be streaming mappings, and relying on >> dma_sync_single_for_device(..., DMA_BIDIRECTIONAL) for other >> data, but without the corresponding dma_sync_single_for_cpu(). >> If all the testing happens on x86, this might easily lead >> to a bug that only shows up on non-coherent systems but >> is never seen during testing. > > Probably the significant thing about restricted DMA is that it forces > all streaming DMA to be bounce-buffered. That should expose busted > synchronisation even more decisively than a lack of coherency. If > there's no IOMMU, then testing the driver in the absence of restricted > DMA but with "swiotlb=force" should confirm or disprove that. I see this sequence in the iwlwifi driver, in the iwl_save_fw_paging() function: block = alloc_pages(GFP_KERNEL, order); phys = dma_map_page(dev, block, 0, PAGE_SIZE << order, DMA_BIDIRECTIONAL); memcpy(page_address(block), ...); dma_sync_single_for_device(dev, phys, size, DMA_BIDIRECTIONAL); Which clearly violates the interface by writing into a page that is already owned by the device, without giving it back to the cpu first. Not sure if or how this would explain actual data corruption on armv7, since we write back the buffers in both the map and sync operations and never invalidate the cache, but the driver also doesn't ever read from the buffer (despite it being bidirectional). If it's not this problem, there is a good chance of others. Arnd