From patchwork Tue Nov 20 14:09:52 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robin Murphy X-Patchwork-Id: 10690737 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7BAB515A7 for ; Tue, 20 Nov 2018 16:25:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6A3792A9A2 for ; Tue, 20 Nov 2018 16:25:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5E8B62A9DE; Tue, 20 Nov 2018 16:25:40 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.6 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id EE6E72A9A2 for ; Tue, 20 Nov 2018 16:25:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=vvrxACiTvJpDMzZCJof0jEdsfY8VqmJcS/ci+cJqWL0=; b=j+dN3vjfdidAdk y38baHEBlUfFCxHkcw73u3qYJqGj7uk2WyeHx3lPdhLdxCARXTVpbQg/wvILoe2WM55uh/2hPZdWh nuYpNnNwLcP+wrsPr1tDfGczGfD53UVnjAfHjzvWV9mIi4od1KOkTez/5mtcBctGis8yySh78yOmn ajmmWNJvncLQFzImpBFAjGPu2KxaXBqQLdbHXWOJlZWe6bu96mhtn4jboRzUlnXXI6Ar0uTJaWIj8 x/9SYAzEcI0nF5JzM49tw0wFb+jW3agiF93MEwSzP2jkkkvrEYtI5yefyBRT/iwDDGvd+IGj2twsj t1G8JasaZJ8376Y0uT/g==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1gP8q5-0005rD-HV; Tue, 20 Nov 2018 16:25:25 +0000 Received: from casper.infradead.org ([85.118.1.10]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gP8kv-0001i9-VM for linux-arm-kernel@bombadil.infradead.org; Tue, 20 Nov 2018 16:20:06 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=Yc+AFKZZS9ZF6dxGvUOAIgUzg0qEUVPxkMiwxTPjuyQ=; b=n5Vu/aOKiR7Q0oNUXL9AEYGLOu BLRXG8JDCqEWP4C1QkcPvM3RuN18QtCzrTqEGOvFjSOLjjwgNQEHhNe+tcomcJrNaumPv0sj5FRFb FdNk88edyT4cGB8gCGqFNboH0KAA1O3fZm74yGGn6veB1eGaFnb0GqqB1ji+FQQ2U18smNFWBvyZr 1xPw/8gHEFmxigoGGDYmKyDMuP3gu5thqOAcoRysQmofOwx15FuxwHdfbAIwgAA25OfbLb1nQVeqy 3RBM/FVNyTPdhrfgKtujEWQoz4Aow2MJYVmeun9hj3/o77j03UP7n+wNr1AHWv4Ivfj+W8XGNUXeY e4WppWTw==; Received: from foss.arm.com ([217.140.101.70]) by casper.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1gP6jP-0007wn-Vu for linux-arm-kernel@lists.infradead.org; Tue, 20 Nov 2018 14:10:25 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id DE81C15AB; Tue, 20 Nov 2018 06:10:10 -0800 (PST) Received: from e110467-lin.cambridge.arm.com (e110467-lin.cambridge.arm.com [10.1.196.75]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 7E4FF3F5A0; Tue, 20 Nov 2018 06:10:09 -0800 (PST) From: Robin Murphy To: hch@lst.de, konrad.wilk@oracle.com Subject: [PATCH 1/2] swiotlb: Make DIRECT_MAPPING_ERROR viable Date: Tue, 20 Nov 2018 14:09:52 +0000 Message-Id: X-Mailer: git-send-email 2.19.1.dirty In-Reply-To: References: MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20181120_141024_160602_B705D1D9 X-CRM114-Status: GOOD ( 12.82 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: iommu@lists.linux-foundation.org, john.stultz@linaro.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, m.szyprowski@samsung.com Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP With the overflow buffer removed, we no longer have a unique address which is guaranteed not to be a valid DMA target to use as an error token. The DIRECT_MAPPING_ERROR value of 0 tries to at least represent an unlikely DMA target, but unfortunately there are already SWIOTLB users with DMA-able memory at physical address 0 which now gets falsely treated as a mapping failure and leads to all manner of misbehaviour. The best we can do to mitigate that is flip DIRECT_MAPPING_ERROR to the commonly-used all-bits-set value, since the last single byte of memory is by far the least-likely-valid DMA target. Fixes: dff8d6c1ed58 ("swiotlb: remove the overflow buffer")] Reported-by: John Stultz Signed-off-by: Robin Murphy --- include/linux/dma-direct.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/linux/dma-direct.h b/include/linux/dma-direct.h index bd73e7a91410..9de9c7ab39d6 100644 --- a/include/linux/dma-direct.h +++ b/include/linux/dma-direct.h @@ -5,7 +5,7 @@ #include #include -#define DIRECT_MAPPING_ERROR 0 +#define DIRECT_MAPPING_ERROR ~(dma_addr_t)0 #ifdef CONFIG_ARCH_HAS_PHYS_TO_DMA #include From patchwork Tue Nov 20 14:09:53 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robin Murphy X-Patchwork-Id: 10690807 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7F75815A7 for ; Tue, 20 Nov 2018 16:46:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6D66F2A323 for ; Tue, 20 Nov 2018 16:46:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5F1EE2A8DE; Tue, 20 Nov 2018 16:46:00 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.6 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id E851F2A323 for ; Tue, 20 Nov 2018 16:45:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=j6u1lEB1Pi3A2hpD1/snuZSh4V9pnz+VLCT2sfPfs/Y=; b=g73SBxV2DXqrBl emXDWtNeAZn3zRzN/qVcqNz+j6b2BqpPEGv0SJFoC0JxKtu/hVJ2w/U1jkYAlNGTsV9oaRU+ILcgt 66dkozf2U+iMPSG/y++FM6Pi1biWVitZI0MLxrhWXddsPQxeLA8lmliGuMJDbG/U6iaZKel4cAFtv MmXFSIhzxnqtCEnZw229/38qVdKWIKPh/Y4Y0y2xHSWXIDeV7+/wOHGAElNcCqGXeAYbvZfgQJi4+ 6vcD9wJJVuese+0Aq4dXJZNiaS8x6WAc1uVXwXAiuJJEII5nFDqGb2Xj+7Loh9ntsgFBuByRrzxab xZc4/sf5Oq0nBixHDlNQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1gP99y-0004wG-Be; Tue, 20 Nov 2018 16:45:58 +0000 Received: from casper.infradead.org ([85.118.1.10]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gP8ku-0000yR-L3 for linux-arm-kernel@bombadil.infradead.org; Tue, 20 Nov 2018 16:20:05 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=xARdDvKXKf2h2wqBYnjBquOUrLDwtc4DCZuwqi66wXI=; b=a5dK/dugRjskfYU1iyfY1JD/nW KJBUIEReEChI1kcvOs4Oc97zspp4jwWFUqc0yip19+g3u5to7I24cMb2HYA0hfca4SUjeCGRkfJmE vWNcJLZhWbyPlUZXj+hnIrOCqkyg8rmFn5RV8kYfrisWn5p1NVcGHf0sKPKcZkpjjcZQ55g3hEO5m H4sqUmH6PeQom7yz9Cyhvg7pYMzncolpc+MsaOrFLMBpgMffRaRQX6mmmRU40kxkZAlTqb+PLgpCx zAyMTwHHq938a75m5JSfRLyy79Y2NEmKBGcphjLG/2dQQt5Q6u0xdMHZduKLCaiOs04dCdidMl+Pf asrErVkg==; Received: from foss.arm.com ([217.140.101.70]) by casper.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1gP6jP-0007wp-Vs for linux-arm-kernel@lists.infradead.org; Tue, 20 Nov 2018 14:10:26 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 84E9115BE; Tue, 20 Nov 2018 06:10:12 -0800 (PST) Received: from e110467-lin.cambridge.arm.com (e110467-lin.cambridge.arm.com [10.1.196.75]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 261053F5A0; Tue, 20 Nov 2018 06:10:11 -0800 (PST) From: Robin Murphy To: hch@lst.de, konrad.wilk@oracle.com Subject: [PATCH 2/2] swiotlb: Skip cache maintenance on map error Date: Tue, 20 Nov 2018 14:09:53 +0000 Message-Id: X-Mailer: git-send-email 2.19.1.dirty In-Reply-To: References: MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20181120_141024_168414_3CE2768A X-CRM114-Status: UNSURE ( 9.88 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: iommu@lists.linux-foundation.org, john.stultz@linaro.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, m.szyprowski@samsung.com Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP If swiotlb_bounce_page() failed, calling arch_sync_dma_for_device() may lead to such delights as performing cache maintenance on whatever address phys_to_virt(SWIOTLB_MAP_ERROR) looks like, which is typically outside the kernel memory map and goes about as well as expected. Don't do that. Fixes: a4a4330db46a ("swiotlb: add support for non-coherent DMA") Signed-off-by: Robin Murphy --- kernel/dma/swiotlb.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c index 5731daa09a32..045930e32c0e 100644 --- a/kernel/dma/swiotlb.c +++ b/kernel/dma/swiotlb.c @@ -679,7 +679,8 @@ dma_addr_t swiotlb_map_page(struct device *dev, struct page *page, } if (!dev_is_dma_coherent(dev) && - (attrs & DMA_ATTR_SKIP_CPU_SYNC) == 0) + (attrs & DMA_ATTR_SKIP_CPU_SYNC) == 0 && + dev_addr != DIRECT_MAPPING_ERROR) arch_sync_dma_for_device(dev, phys, size, dir); return dev_addr;