Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp826428imu; Tue, 20 Nov 2018 07:32:52 -0800 (PST) X-Google-Smtp-Source: AJdET5fAyDTArVN+ch4qo9FcpDttVT+AiDz52j9m4TVOu8HZZ+cE0iDMgEwGSIosL7/qvV/dS1HH X-Received: by 2002:a62:7dcb:: with SMTP id y194-v6mr2558851pfc.215.1542727972286; Tue, 20 Nov 2018 07:32:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542727972; cv=none; d=google.com; s=arc-20160816; b=gYoq44sxizSfXyRshOYRJ6ZTgfa3apd1AffuqhQmqWJLCvm0XyKKcRXMeWRu0DM8MX OcZOrqebVWhhxkqaSx3anbIFvEDDmloej4GRjRV4nHTQpCU5EMVuHuA6+IzOjsIn6jBs svHkEfCM60Orod0YtZFW/tz3kuf9BdnSWcDsk3cQpAOJvYvSTD81gSPOgAU6AY3MjLAF 1BuDogfX9qVGzFvj2OpeDrJY0KA9cZ77es0oDUl77JvHLBzmGaBMw0bVEDjBMUod1xxb J9xEj/Xo5aVg5McIHdhJXKcIxrXfmGsTOA0mrHK/7Adj9EwNAhUa0Z++0xwEdOuVuVm9 1crw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=qsGEBOOQmkz1/b0ARfpKgzDHPbwnm/6rqpo1QaEmANc=; b=gM09DebwCKt2oKk/PUTVnbr58WaDEE8yRZ9JG0+FcMvY4nZWNcjHA8B2+yBPH8mLD3 WOXMIeGGE/F14hfXTtXARMtyXwV0cNXMUtXAmQqq4N2l8TBwtUaE4fGKCJ83ohIRIddl AkzcEGKMbayp4Z9CcuCxjK4Zox69V9a8AibY37/WvHqdqYkMkhwcYg3yLnnz+xplRpr8 jgYajfmq/m3O0dR5kc3cFiWUEVeLB+BJaEzzzHPEgy8NwGIvHJr0I3Z/EI2S66QUZGc8 O4CKiJrOtM29x/QI7KqJZsWlG4KnoyVnopX7THHnwEOF15FdVNJNBb0/D/9rjYXB0+Jp 35mQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h3si27568680pll.116.2018.11.20.07.32.36; Tue, 20 Nov 2018 07:32:52 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727608AbeKUBbK (ORCPT + 99 others); Tue, 20 Nov 2018 20:31:10 -0500 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:50518 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725917AbeKUBbJ (ORCPT ); Tue, 20 Nov 2018 20:31:09 -0500 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 C7528EBD; Tue, 20 Nov 2018 07:01:35 -0800 (PST) Received: from [10.1.196.75] (e110467-lin.cambridge.arm.com [10.1.196.75]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 907753F5A0; Tue, 20 Nov 2018 07:01:34 -0800 (PST) Subject: Re: [PATCH 1/2] swiotlb: Make DIRECT_MAPPING_ERROR viable To: Konrad Rzeszutek Wilk Cc: hch@lst.de, m.szyprowski@samsung.com, john.stultz@linaro.org, iommu@lists.linux-foundation.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org References: <20181120144918.GH10917@char.us.oracle.com> From: Robin Murphy Message-ID: <7ea5809e-1e1d-6bac-b723-9f55fafeaaae@arm.com> Date: Tue, 20 Nov 2018 15:01:33 +0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.2.1 MIME-Version: 1.0 In-Reply-To: <20181120144918.GH10917@char.us.oracle.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-GB Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 20/11/2018 14:49, Konrad Rzeszutek Wilk wrote: > On Tue, Nov 20, 2018 at 02:09:52PM +0000, Robin Murphy wrote: >> 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. > > Are all the callers checking for DIRECT_MAPPING_ERROR or is it more of > a comparison (as in if (!ret)) ? dma_direct_map_page() and dma_direct_mapping_error() were already doing the right thing, and external callers must rely on the latter via dma_mapping_error() rather than trying to inspect the actual value themselves, since that varies between implementations anyway. AFAICS all the new return paths from swiotlb_map_page() are also robust in referencing the macro explicitly, so I think we're good. Thanks, Robin. >> 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 >> -- >> 2.19.1.dirty >>