Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp836253ybv; Thu, 20 Feb 2020 08:08:52 -0800 (PST) X-Google-Smtp-Source: APXvYqzCfKJMR0jqaZaEtS9QpHdrB0zQ5+fqeywwpAAQxpCm5plNy5mFTkagYCzHnWemuXnMF9zK X-Received: by 2002:a54:4006:: with SMTP id x6mr2602754oie.145.1582214932691; Thu, 20 Feb 2020 08:08:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582214932; cv=none; d=google.com; s=arc-20160816; b=ylRhjjrwOxLimh/WxtDjMFhL7ielPpDQTD99zz67H/HdLPAyftCQCxCIOViyQgfwUI 57wuundXTqw02dkZQHKJ50SihxFgwARM3YnUB5YHeC8E0hhSRb8qfqo1wXH0ldggh2eo 4c+5IugufCb1RYPVAimflI5Q8vK+WPa/uCtj49JfbkvPJJk5kiDpqaPpbps6kD8HVnlX /HsvtJo6fSHwp3oabNxEf/9KcTUCaEcV0LMH6YU4lWUSp5RJ4RYzxQzPEeZ1mTJ7ao5z rYpvDOK5UFUsHrNmnKOkegcqN6Lj1hjQAARgxcLA5jgV9C64yYAr7VFOehdPLf8fcuHO 29Ng== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:references:in-reply-to:date :subject:cc:to:from; bh=rgQo0yjSeXdPKud1Y0Eaj6see31bp2pNFa+KqfSLmFk=; b=Eyc3tLC2KcFcn86aigoGDCz/dGHT7Yg/9uv3j7kUKr57Ib1rsBBiKmo3Y2q9czdcnG vJWkJMzfQAFriCMQvVtLvYNl7KMMB5g0sCEwrmzUd+TkbkRE5MmyT4oeER4em52sMUY1 ikvK5MITV5KIOGyXjrfo8hUiZys9Rtv/4OJlqmk7LzTQ413I2EMAVy72vOINGDSauFS5 Xn9vbZ+iW3am+NHF0EtQ58QqNoVxESapkKz81QUDB4IhglEoTvNubivEYneTsmrlFDdS WSl35wa43Ze2ver2vW7ureMTHJUY+wUVnS18GMM13mZLdboUZJ1vT5sLpit8t6Ko5VbF xVWQ== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z129si2312979oia.17.2020.02.20.08.08.14; Thu, 20 Feb 2020 08:08:51 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728669AbgBTQID (ORCPT + 99 others); Thu, 20 Feb 2020 11:08:03 -0500 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:6676 "EHLO mx0b-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728567AbgBTQID (ORCPT ); Thu, 20 Feb 2020 11:08:03 -0500 Received: from pps.filterd (m0127361.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 01KG3x8Q027503 for ; Thu, 20 Feb 2020 11:08:01 -0500 Received: from e06smtp02.uk.ibm.com (e06smtp02.uk.ibm.com [195.75.94.98]) by mx0a-001b2d01.pphosted.com with ESMTP id 2y92xehp21-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 20 Feb 2020 11:08:01 -0500 Received: from localhost by e06smtp02.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 20 Feb 2020 16:07:59 -0000 Received: from b06cxnps4075.portsmouth.uk.ibm.com (9.149.109.197) by e06smtp02.uk.ibm.com (192.168.101.132) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Thu, 20 Feb 2020 16:07:53 -0000 Received: from d06av26.portsmouth.uk.ibm.com (d06av26.portsmouth.uk.ibm.com [9.149.105.62]) by b06cxnps4075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 01KG6btL22020162 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 20 Feb 2020 16:06:37 GMT Received: from d06av26.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id CE339AE058; Thu, 20 Feb 2020 16:06:37 +0000 (GMT) Received: from d06av26.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 4D54DAE057; Thu, 20 Feb 2020 16:06:37 +0000 (GMT) Received: from tuxmaker.boeblingen.de.ibm.com (unknown [9.152.85.9]) by d06av26.portsmouth.uk.ibm.com (Postfix) with ESMTP; Thu, 20 Feb 2020 16:06:37 +0000 (GMT) From: Halil Pasic To: "Michael S. Tsirkin" , Jason Wang , Marek Szyprowski , Robin Murphy , Christoph Hellwig Cc: Halil Pasic , linux-s390@vger.kernel.org, virtualization@lists.linux-foundation.org, linux-kernel@vger.kernel.org, iommu@lists.linux-foundation.org, Christian Borntraeger , Janosch Frank , Viktor Mihajlovski , Cornelia Huck , Ram Pai , Thiago Jung Bauermann , David Gibson , "Lendacky, Thomas" , Michael Mueller Subject: [PATCH 1/2] mm: move force_dma_unencrypted() to mem_encrypt.h Date: Thu, 20 Feb 2020 17:06:05 +0100 X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200220160606.53156-1-pasic@linux.ibm.com> References: <20200220160606.53156-1-pasic@linux.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 20022016-0008-0000-0000-00000354D0ED X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 20022016-0009-0000-0000-00004A75E16D Message-Id: <20200220160606.53156-2-pasic@linux.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.138,18.0.572 definitions=2020-02-20_04:2020-02-19,2020-02-20 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 adultscore=0 clxscore=1015 lowpriorityscore=0 phishscore=0 bulkscore=0 spamscore=0 suspectscore=0 malwarescore=0 priorityscore=1501 impostorscore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2001150001 definitions=main-2002200118 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Currently force_dma_unencrypted() is only used by the direct implementation of the DMA API, and thus resides in dma-direct.h. But there is nothing dma-direct specific about it: if one was -- for whatever reason -- to implement custom DMA ops that have to in the encrypted/protected scenarios dma-direct currently deals with, one would need exactly this kind of information. More importantly, virtio has to use DMA API (so that the memory encryption (x86) or protection (power, s390) is handled) under the very same circumstances force_dma_unencrypted() returns true. Furthermore, the in these cases the reason to go via the DMA API is distinct, compared to the reason indicated by VIRTIO_F_IOMMU_PLATFORM: we need to use DMA API independently of the device's properties with regards to access to memory. I.e. the addresses in the descriptors are still guest physical addresses, the device may still be implemented by a SMP CPU, and thus the device shall use those without any further translation. See [1]. Let's move force_dma_unencrypted() the so virtio, or other implementations of DMA ops can make the right decisions. [1] https://docs.oasis-open.org/virtio/virtio/v1.1/cs01/virtio-v1.1-cs01.html#x1-4100006 (In the spec VIRTIO_F_IOMMU_PLATFORM is called VIRTIO_F_ACCESS_PLATFORM). Signed-off-by: Halil Pasic Tested-by: Ram Pai Tested-by: Michael Mueller --- include/linux/dma-direct.h | 9 --------- include/linux/mem_encrypt.h | 10 ++++++++++ 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/include/linux/dma-direct.h b/include/linux/dma-direct.h index 24b8684aa21d..590b15d881b0 100644 --- a/include/linux/dma-direct.h +++ b/include/linux/dma-direct.h @@ -26,15 +26,6 @@ static inline phys_addr_t __dma_to_phys(struct device *dev, dma_addr_t dev_addr) } #endif /* !CONFIG_ARCH_HAS_PHYS_TO_DMA */ -#ifdef CONFIG_ARCH_HAS_FORCE_DMA_UNENCRYPTED -bool force_dma_unencrypted(struct device *dev); -#else -static inline bool force_dma_unencrypted(struct device *dev) -{ - return false; -} -#endif /* CONFIG_ARCH_HAS_FORCE_DMA_UNENCRYPTED */ - /* * If memory encryption is supported, phys_to_dma will set the memory encryption * bit in the DMA address, and dma_to_phys will clear it. The raw __phys_to_dma diff --git a/include/linux/mem_encrypt.h b/include/linux/mem_encrypt.h index 5c4a18a91f89..64a48c4b01a2 100644 --- a/include/linux/mem_encrypt.h +++ b/include/linux/mem_encrypt.h @@ -22,6 +22,16 @@ static inline bool mem_encrypt_active(void) { return false; } #endif /* CONFIG_ARCH_HAS_MEM_ENCRYPT */ +struct device; +#ifdef CONFIG_ARCH_HAS_FORCE_DMA_UNENCRYPTED +bool force_dma_unencrypted(struct device *dev); +#else +static inline bool force_dma_unencrypted(struct device *dev) +{ + return false; +} +#endif /* CONFIG_ARCH_HAS_FORCE_DMA_UNENCRYPTED */ + #ifdef CONFIG_AMD_MEM_ENCRYPT /* * The __sme_set() and __sme_clr() macros are useful for adding or removing -- 2.17.1