Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp4363561ybp; Mon, 14 Oct 2019 03:32:22 -0700 (PDT) X-Google-Smtp-Source: APXvYqyNU7PMDOZdWGq8v2CaXnuoVKaZH1B9FvhuC8QeVztSAS0Phie3R662jUqvBKBfYdlULMMu X-Received: by 2002:a05:6402:2c5:: with SMTP id b5mr27896914edx.45.1571049142000; Mon, 14 Oct 2019 03:32:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571049141; cv=none; d=google.com; s=arc-20160816; b=ceud6iLBHpkK0plazRTUYqBWarD/WdSLKof3UlJh+zRAkD98BP8OoePsk6TR4stlJX osTsIgpVhyHRRS/uNFz5/bk1O9og6x9OJeu0jnc0KOsteCcK9vj9FjwCuoMwZxcSQv+X 4cwWmU78YH/ppXzSHdhty8npBqy2VlG6Yl4ydJJOL0lCexLfFsQdzbcEi7YzbkQEXEFs +6uefy9jtcTBf3VVMSIDo0t7KIPeRa2FSzNvaaIOwP8m+MqHTnl2oN56gjDQ2FrBU58P vIidRgidPWxsw4gjsZ4PVq4V0aHl4lR/8nQLWR+4QuJa+33Gnx4pUWMBi2RP06m7bHCL 5XcQ== 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=D7Tay4h7qpXwC8h1z61VJpUJAMauudjhVuUK0Yt6xoE=; b=LvoB7ZtsVwkkUZcLGbr348l5BH2TRxMRnh5nCCwNcPGWhO2X4GC1Xbxbt2Nc0Nx+an 9v2g2qKCRJgmu1BtA47r8iV5ORLX0PmjZstU7DGuWyBG3Yt/eP3GQC377AfRw/9guOO9 eO6su01CU71ocXfpnaZ5kgyMkDsovXxw1BA0pACt3lc7ZqH/1R/vd8JuqpOYRU1hxv3Z mV9iLXEtr6ZbGg+Z+7Ll0DcLXnKrtayiocGgAZvPgjp+PkEYVYm6kAWrN6/lhjr+JIfj /S311L0PypHZlhsX5rSf1aphTNAXFIM7Wh3mhYhBIDVynMo/6PEyV7EHuWC3HtHTLT/p YEqw== 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 b15si11027442eda.152.2019.10.14.03.31.57; Mon, 14 Oct 2019 03:32:21 -0700 (PDT) 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 S1731347AbfJNK33 (ORCPT + 99 others); Mon, 14 Oct 2019 06:29:29 -0400 Received: from foss.arm.com ([217.140.110.172]:39912 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731119AbfJNK32 (ORCPT ); Mon, 14 Oct 2019 06:29:28 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id BDE68337; Mon, 14 Oct 2019 03:29:27 -0700 (PDT) Received: from [10.1.197.57] (e110467-lin.cambridge.arm.com [10.1.197.57]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 9C3363F718; Mon, 14 Oct 2019 03:29:25 -0700 (PDT) Subject: Re: [PATCH 1/2] dma-mapping: Add dma_addr_is_phys_addr() To: David Gibson , Ram Pai Cc: linux-kernel@vger.kernel.org, iommu@lists.linux-foundation.org, linuxppc-dev@lists.ozlabs.org, virtualization@lists.linux-foundation.org, benh@kernel.crashing.org, mpe@ellerman.id.au, paulus@ozlabs.org, mdroth@linux.vnet.ibm.com, aik@linux.ibm.com, paul.burton@mips.com, b.zolnierkie@samsung.com, m.szyprowski@samsung.com, hch@lst.de, jasowang@redhat.com, andmike@us.ibm.com, sukadev@linux.vnet.ibm.com References: <1570843519-8696-1-git-send-email-linuxram@us.ibm.com> <1570843519-8696-2-git-send-email-linuxram@us.ibm.com> <20191014045139.GN4080@umbus.fritz.box> From: Robin Murphy Message-ID: <37609731-5539-b906-aa94-2ef0242795ac@arm.com> Date: Mon, 14 Oct 2019 11:29:24 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1 MIME-Version: 1.0 In-Reply-To: <20191014045139.GN4080@umbus.fritz.box> Content-Type: text/plain; charset=windows-1252; 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 14/10/2019 05:51, David Gibson wrote: > On Fri, Oct 11, 2019 at 06:25:18PM -0700, Ram Pai wrote: >> From: Thiago Jung Bauermann >> >> In order to safely use the DMA API, virtio needs to know whether DMA >> addresses are in fact physical addresses and for that purpose, >> dma_addr_is_phys_addr() is introduced. >> >> cc: Benjamin Herrenschmidt >> cc: David Gibson >> cc: Michael Ellerman >> cc: Paul Mackerras >> cc: Michael Roth >> cc: Alexey Kardashevskiy >> cc: Paul Burton >> cc: Robin Murphy >> cc: Bartlomiej Zolnierkiewicz >> cc: Marek Szyprowski >> cc: Christoph Hellwig >> Suggested-by: Michael S. Tsirkin >> Signed-off-by: Ram Pai >> Signed-off-by: Thiago Jung Bauermann > > The change itself looks ok, so > > Reviewed-by: David Gibson > > However, I would like to see the commit message (and maybe the inline > comments) expanded a bit on what the distinction here is about. Some > of the text from the next patch would be suitable, about DMA addresses > usually being in a different address space but not in the case of > bounce buffering. Right, this needs a much tighter definition. "DMA address happens to be a valid physical address" is true of various IOMMU setups too, but I can't believe it's meaningful in such cases. If what you actually want is "DMA is direct or SWIOTLB" - i.e. "DMA address is physical address of DMA data (not necessarily the original buffer)" - wouldn't dma_is_direct() suffice? Robin. >> --- >> arch/powerpc/include/asm/dma-mapping.h | 21 +++++++++++++++++++++ >> arch/powerpc/platforms/pseries/Kconfig | 1 + >> include/linux/dma-mapping.h | 20 ++++++++++++++++++++ >> kernel/dma/Kconfig | 3 +++ >> 4 files changed, 45 insertions(+) >> >> diff --git a/arch/powerpc/include/asm/dma-mapping.h b/arch/powerpc/include/asm/dma-mapping.h >> index 565d6f7..f92c0a4b 100644 >> --- a/arch/powerpc/include/asm/dma-mapping.h >> +++ b/arch/powerpc/include/asm/dma-mapping.h >> @@ -5,6 +5,8 @@ >> #ifndef _ASM_DMA_MAPPING_H >> #define _ASM_DMA_MAPPING_H >> >> +#include >> + >> static inline const struct dma_map_ops *get_arch_dma_ops(struct bus_type *bus) >> { >> /* We don't handle the NULL dev case for ISA for now. We could >> @@ -15,4 +17,23 @@ static inline const struct dma_map_ops *get_arch_dma_ops(struct bus_type *bus) >> return NULL; >> } >> >> +#ifdef CONFIG_ARCH_HAS_DMA_ADDR_IS_PHYS_ADDR >> +/** >> + * dma_addr_is_phys_addr - check whether a device DMA address is a physical >> + * address >> + * @dev: device to check >> + * >> + * Returns %true if any DMA address for this device happens to also be a valid >> + * physical address (not necessarily of the same page). >> + */ >> +static inline bool dma_addr_is_phys_addr(struct device *dev) >> +{ >> + /* >> + * Secure guests always use the SWIOTLB, therefore DMA addresses are >> + * actually the physical address of the bounce buffer. >> + */ >> + return is_secure_guest(); >> +} >> +#endif >> + >> #endif /* _ASM_DMA_MAPPING_H */ >> diff --git a/arch/powerpc/platforms/pseries/Kconfig b/arch/powerpc/platforms/pseries/Kconfig >> index 9e35cdd..0108150 100644 >> --- a/arch/powerpc/platforms/pseries/Kconfig >> +++ b/arch/powerpc/platforms/pseries/Kconfig >> @@ -152,6 +152,7 @@ config PPC_SVM >> select SWIOTLB >> select ARCH_HAS_MEM_ENCRYPT >> select ARCH_HAS_FORCE_DMA_UNENCRYPTED >> + select ARCH_HAS_DMA_ADDR_IS_PHYS_ADDR >> help >> There are certain POWER platforms which support secure guests using >> the Protected Execution Facility, with the help of an Ultravisor >> diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h >> index f7d1eea..6df5664 100644 >> --- a/include/linux/dma-mapping.h >> +++ b/include/linux/dma-mapping.h >> @@ -693,6 +693,26 @@ static inline bool dma_addressing_limited(struct device *dev) >> dma_get_required_mask(dev); >> } >> >> +#ifndef CONFIG_ARCH_HAS_DMA_ADDR_IS_PHYS_ADDR >> +/** >> + * dma_addr_is_phys_addr - check whether a device DMA address is a physical >> + * address >> + * @dev: device to check >> + * >> + * Returns %true if any DMA address for this device happens to also be a valid >> + * physical address (not necessarily of the same page). >> + */ >> +static inline bool dma_addr_is_phys_addr(struct device *dev) >> +{ >> + /* >> + * Except in very specific setups, DMA addresses exist in a different >> + * address space from CPU physical addresses and cannot be directly used >> + * to reference system memory. >> + */ >> + return false; >> +} >> +#endif >> + >> #ifdef CONFIG_ARCH_HAS_SETUP_DMA_OPS >> void arch_setup_dma_ops(struct device *dev, u64 dma_base, u64 size, >> const struct iommu_ops *iommu, bool coherent); >> diff --git a/kernel/dma/Kconfig b/kernel/dma/Kconfig >> index 9decbba..6209b46 100644 >> --- a/kernel/dma/Kconfig >> +++ b/kernel/dma/Kconfig >> @@ -51,6 +51,9 @@ config ARCH_HAS_DMA_MMAP_PGPROT >> config ARCH_HAS_FORCE_DMA_UNENCRYPTED >> bool >> >> +config ARCH_HAS_DMA_ADDR_IS_PHYS_ADDR >> + bool >> + >> config DMA_NONCOHERENT_CACHE_SYNC >> bool >> >