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: 26271 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-qa0-f71.google.com (mail-qa0-f71.google.com [209.85.216.71]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id BB16F20143 for ; Fri, 14 Mar 2014 16:50:30 +0000 (UTC) Received: by mail-qa0-f71.google.com with SMTP id j7sf5495734qaq.6 for ; Fri, 14 Mar 2014 09:50:30 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:message-id:date:from:user-agent :mime-version:to:cc:subject:references:in-reply-to:sender:precedence :list-id:x-original-sender:x-original-authentication-results :mailing-list:list-post:list-help:list-archive:list-unsubscribe :content-type:content-transfer-encoding; bh=RbUZ0C5jcE6jvBIwMAg6yEo/H/gepaTnBFirwB+2jHU=; b=U7QiJENrGaVCDJ1ZtsgN9VRp75NlbHS/B1D+kkSugS9CGBYlJJOLLC4CKHBddO1Cil EeIYhbaBhGpMQYM1vlAwImylxVoZEvfnhqdXyeHnoKAsJ0TZL5MW+nikrHl3QPAhsu1/ l9XlujpvU1+8xNqfKJdxa8EgV08/PSLJS6RzxYKlnb0T1wjH1a0BbL/+ICjjBUHLpMM8 s1IHla7D/BHuh0Liupof/isCM4Fc0XYEwICU+nRfe7Fx4dhHidN1wkJMF6ykTdVeDzXq lpY+5lOX+NNZ+jhS4P29GmsumFt4ibz6Qo2WuWZjztpies7u3Roo9UdHmlM02eOr7QnD GsPg== X-Gm-Message-State: ALoCoQnDFTVyGrBfQMbSapqoqrvA/076uEKITevQJwyEpp4ZWg7AfVxU1aAgaBxY1aVzcAoSvu09 X-Received: by 10.236.17.161 with SMTP id j21mr2910016yhj.55.1394815830528; Fri, 14 Mar 2014 09:50:30 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.105.100 with SMTP id b91ls844690qgf.26.gmail; Fri, 14 Mar 2014 09:50:30 -0700 (PDT) X-Received: by 10.58.96.36 with SMTP id dp4mr5382460veb.21.1394815830441; Fri, 14 Mar 2014 09:50:30 -0700 (PDT) Received: from mail-vc0-f174.google.com (mail-vc0-f174.google.com [209.85.220.174]) by mx.google.com with ESMTPS id tz5si2295509vdc.124.2014.03.14.09.50.30 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 14 Mar 2014 09:50:30 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.220.174 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.220.174; Received: by mail-vc0-f174.google.com with SMTP id ld13so3035121vcb.33 for ; Fri, 14 Mar 2014 09:50:30 -0700 (PDT) X-Received: by 10.52.30.230 with SMTP id v6mr5997267vdh.6.1394815830296; Fri, 14 Mar 2014 09:50:30 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.220.78.9 with SMTP id i9csp33675vck; Fri, 14 Mar 2014 09:50:29 -0700 (PDT) X-Received: by 10.66.146.199 with SMTP id te7mr10096330pab.106.1394815828882; Fri, 14 Mar 2014 09:50:28 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id wh4si6261608pbc.64.2014.03.14.09.50.28; Fri, 14 Mar 2014 09:50:28 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of devicetree-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755674AbaCNQu1 (ORCPT + 9 others); Fri, 14 Mar 2014 12:50:27 -0400 Received: from mail-we0-f181.google.com ([74.125.82.181]:57236 "EHLO mail-we0-f181.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755617AbaCNQu0 (ORCPT ); Fri, 14 Mar 2014 12:50:26 -0400 Received: by mail-we0-f181.google.com with SMTP id q58so2328597wes.40 for ; Fri, 14 Mar 2014 09:50:25 -0700 (PDT) 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 CC: Ian Campbell , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, xen-devel@lists.xenproject.org, Rob Herring , Pawel Moll , Mark Rutland , Ian Campbell , Kumar Gala , Rob Landley , devicetree@vger.kernel.org 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: Sender: devicetree-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: devicetree@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: julien.grall@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.220.174 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , 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 */