From patchwork Fri Mar 14 16:50:23 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 3834061 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id DE134BF540 for ; Fri, 14 Mar 2014 16:56:56 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id ACBE52026D for ; Fri, 14 Mar 2014 16:56:55 +0000 (UTC) Received: from casper.infradead.org (casper.infradead.org [85.118.1.10]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 6785B2026C for ; Fri, 14 Mar 2014 16:56:54 +0000 (UTC) Received: from merlin.infradead.org ([2001:4978:20e::2]) by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1WOVPL-0002NI-9l; Fri, 14 Mar 2014 16:56:31 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1WOVPC-0001t5-5C; Fri, 14 Mar 2014 16:56:22 +0000 Received: from mail-wi0-f182.google.com ([209.85.212.182]) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1WOVP8-0001rh-IZ for linux-arm-kernel@lists.infradead.org; Fri, 14 Mar 2014 16:56:19 +0000 Received: by mail-wi0-f182.google.com with SMTP id d1so2878895wiv.9 for ; Fri, 14 Mar 2014 09:55:56 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:message-id:date:from:user-agent:mime-version:to :cc:subject:references:in-reply-to:content-type :content-transfer-encoding; bh=LSKD0CDwbmS91W3Z+NzL3cV0zRycfxBlB2xayZ+I3K4=; b=I1mp9nhwuEouUE0TSFmPqxRnrbOXLonuOnNq4ycqRQ4GdjMmPVZ693WMUE/C2OLJN/ wfh2y9w2sRUjq0J/gaAqsXPXiGe0JxMdMI/YT7oj1LLZDkz9fF/uFg4fnWwh4y91niBJ qix7JBt3u24qVsCzDAN0SV75xMm+bTl6uu3Oqc7HXwwr4gX5d4iR3AbFM/JR6pWQFJc1 T6hDCcHgr0JJe9eGawyBWb84iNMNRkLE98vTNtJwM+C7IrYoF6puH8dQIBjVrpr/nNZH 7GJ1hOMClWdc1VEUNktkfigk6rgeMtgY/qvGtHZFcI4gs5ZtudgBRDPKSQWQYmCi4g2P fP9A== X-Gm-Message-State: ALoCoQm9PqiBGeyINROJRrhuY04/61qOh9SRnpe/D9VYtzTvF9lIwHHtfR3cOELdK9l1xuotf8ys X-Received: by 10.194.157.41 with SMTP id wj9mr7589102wjb.34.1394815825626; Fri, 14 Mar 2014 09:50:25 -0700 (PDT) Received: from [10.80.2.139] ([185.25.64.249]) by mx.google.com with ESMTPSA id f1sm6609627wik.1.2014.03.14.09.50.24 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 14 Mar 2014 09:50:24 -0700 (PDT) Message-ID: <5323334F.90700@linaro.org> Date: Fri, 14 Mar 2014 16:50:23 +0000 From: Julien Grall User-Agent: Mozilla/5.0 (X11; Linux i686; rv:17.0) Gecko/20131104 Icedove/17.0.10 MIME-Version: 1.0 To: Stefano Stabellini , "gregkh@linuxfoundation.org" , Russell King Subject: Re: [PATCH 2/2] arm/xen: Don't use xen DMA ops when the device is protected by an IOMMU References: <1392913301-25524-1-git-send-email-julien.grall@linaro.org> <1392914159.32657.18.camel@kazak.uk.xensource.com> <20140224151636.GA13489@kroah.com> In-Reply-To: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140314_125618_707640_4810203C X-CRM114-Status: GOOD ( 20.25 ) X-Spam-Score: -2.6 (--) Cc: Mark Rutland , devicetree@vger.kernel.org, Ian Campbell , Pawel Moll , Ian Campbell , linux-kernel@vger.kernel.org, Rob Herring , Rob Landley , Kumar Gala , xen-devel@lists.xenproject.org, linux-arm-kernel@lists.infradead.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP On 02/24/2014 08:49 PM, Stefano Stabellini wrote: > On Mon, 24 Feb 2014, gregkh@linuxfoundation.org wrote: > Julien is proposing to store the list of "safe" devices on an hash table > in the Xen specific code (in arch/arm/xen/enlighten.c, see > http://marc.info/?l=linux-kernel&m=139291370526082&w=2). > Whenever Linux is about to do DMA, we would check in the hashtable to > figure out whether we need to go through the swiotlb or we can simply > use the native dma_ops. > > Ian and I were thinking that it would be much easier and faster to have > a "xen_safe_device" parameter in struct device and just check for that. > It doesn't actually need to be in struct device, it could simply be a > flag in struct device_dma_parameters as Ian was suggesting. > > Julien, could you please come up with a simple patch to demonstrate the > concept? Hello Stefano and Greg, Sorry for the late answer. I wrote a simple patch which depend on patch #1. Let me know if it's the right direction. Regards, commit ca55e82bc191678b284792d2f0d200fa1ce08e16 Author: Julien Grall Date: Fri Mar 14 16:27:01 2014 +0000 ARM: platform_device: dev_archdata: Add xen specific boolean Until now, every DMA-capable devices are using specific Xen DMA ops when Linux is running as DOM0. These DMA ops call swiotlb-xen to bounce buffer. With the support of IOMMU drivers in Xen, every device protected by IOMMU must not use swiotlb DMA ops. This patch introduces a boolean in dev_archdata to indicate if the device can safely use its own DMA ops or swiotlb ops. Signed-off-by: Julien Grall diff --git a/arch/arm/include/asm/device.h b/arch/arm/include/asm/device.h index dc662fc..345a96e 100644 --- a/arch/arm/include/asm/device.h +++ b/arch/arm/include/asm/device.h @@ -17,6 +17,9 @@ struct dev_archdata { #ifdef CONFIG_ARM_DMA_USE_IOMMU struct dma_iommu_mapping *mapping; #endif +#ifdef CONFIG_XEN + bool is_protected; +#endif }; struct omap_device; diff --git a/arch/arm/include/asm/xen/dma-mapping.h b/arch/arm/include/asm/xen/dma-mapping.h index 002fc57..d6cc012 100644 --- a/arch/arm/include/asm/xen/dma-mapping.h +++ b/arch/arm/include/asm/xen/dma-mapping.h @@ -5,9 +5,21 @@ extern struct dma_map_ops *xen_dma_ops; +#ifdef CONFIG_XEN +static inline bool xen_is_protected_device(const struct device *dev) +{ + return dev->archdata.is_protected; +} +#else +static inline bool xen_is_protected_device(const struct device *dev) +{ + return 0; +} +#endif + static inline bool need_xen_dma_ops(struct device *dev) { - return xen_initial_domain(); + return xen_initial_domain() && !xen_is_protected_device(dev); } #endif /* _ASM_ARM_XEN_DMA_MAPPING_H */