Received: by 10.213.65.68 with SMTP id h4csp1788822imn; Thu, 5 Apr 2018 03:58:05 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/QCQEpogMpwQ6pW/BI7Qo1uHK5XMaDTS02FIoopVOi0wMvl/5Q2BxAft1u4sZfKvd9gXEz X-Received: by 2002:a17:902:3341:: with SMTP id a59-v6mr22395052plc.68.1522925885660; Thu, 05 Apr 2018 03:58:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522925885; cv=none; d=google.com; s=arc-20160816; b=LP3lYmvZiv/ohfNNk/n9yxhky3GmIdrPePtpGTyPQbXpAjF+lZ6XrTDBNFCudkCLaF lSjtN8ygIvcG9TYMaD4UXm03Ifj8F3sJhfOZzifdQFXq7sW0Tvu18b/82CUaWdod3NZ8 lW1Meqt/fVr6BtFM8Xyh5PO0qR0gT4XM1e81VqWZUjsI2KQxJKa9ZCrVLtcFeobhBwPt uvdiCigKQ1ruJGLaQM5C2u/9tWTORdX6/L2FBK4EHW9FnXI6fCM1JHnjuiT3XaBCBfDP xynBooH7nGHTIUu8x82uz/omY2b6MqvqliplheoEQE6RgVGZIMAVkRtrL00JaVnpPQlD 3FCw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :arc-authentication-results; bh=jVDzeaGJGpwW485jCp/F/hPf+LwsCJ08MuNoBlA3AjA=; b=WazOaHIhqbBUWDJot+nWCeAZc6rNvDtUBE+71w1ZPuO0zrFzW4Iwvbf7DIqZZZuWCX ls6YojWZgEc80T3u/KB7PSRNGB0pKgeTJShdgrfiaKjfUZ2XgGuN+ZcU+QzzunzFlTy+ 7qHrqgeQ88aLDJBXIRO735ErKj+c0yGVXDUmkD44h2eJkXpoUfIhRZPK+F8L8aemJ/xc mR4l1gJdflu1o560NYJvGuLvsT+pjp5OtNUY9ZkEqWouJIxNm4Yf5SoMC0yEYcKBbCEK BR7E2AM3jYuXRWa/UlYkGkpCq0eJB1v1LdpamYr5X+FA+E8ls32jR2ckPEZdWqn81Kak tTEg== 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 102-v6si5373824pla.230.2018.04.05.03.57.50; Thu, 05 Apr 2018 03:58:05 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751278AbeDEK4n (ORCPT + 99 others); Thu, 5 Apr 2018 06:56:43 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:40892 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1750835AbeDEK4l (ORCPT ); Thu, 5 Apr 2018 06:56:41 -0400 Received: from pps.filterd (m0098414.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w35AsvQq129026 for ; Thu, 5 Apr 2018 06:56:41 -0400 Received: from e06smtp15.uk.ibm.com (e06smtp15.uk.ibm.com [195.75.94.111]) by mx0b-001b2d01.pphosted.com with ESMTP id 2h5fxt6xu7-1 (version=TLSv1.2 cipher=AES256-SHA256 bits=256 verify=NOT) for ; Thu, 05 Apr 2018 06:56:40 -0400 Received: from localhost by e06smtp15.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 5 Apr 2018 11:56:39 +0100 Received: from b06cxnps3074.portsmouth.uk.ibm.com (9.149.109.194) by e06smtp15.uk.ibm.com (192.168.101.145) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Thu, 5 Apr 2018 11:56:34 +0100 Received: from d06av23.portsmouth.uk.ibm.com (d06av23.portsmouth.uk.ibm.com [9.149.105.59]) by b06cxnps3074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id w35AuYbW10551720; Thu, 5 Apr 2018 10:56:34 GMT Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id A69C5A4051; Thu, 5 Apr 2018 11:48:59 +0100 (BST) Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id C765FA404D; Thu, 5 Apr 2018 11:48:57 +0100 (BST) Received: from localhost.in.ibm.com (unknown [9.122.211.94]) by d06av23.portsmouth.uk.ibm.com (Postfix) with ESMTP; Thu, 5 Apr 2018 11:48:57 +0100 (BST) From: Anshuman Khandual To: virtualization@lists.linux-foundation.org, linux-kernel@vger.kernel.org Cc: linuxppc-dev@lists.ozlabs.org, aik@ozlabs.ru, robh@kernel.org, joe@perches.com, elfring@users.sourceforge.net, david@gibson.dropbear.id.au, jasowang@redhat.com, benh@kernel.crashing.org, mpe@ellerman.id.au Subject: [RFC] virtio: Use DMA MAP API for devices without an IOMMU Date: Thu, 5 Apr 2018 16:26:31 +0530 X-Mailer: git-send-email 2.9.3 X-TM-AS-GCONF: 00 x-cbid: 18040510-0020-0000-0000-0000040E5E93 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18040510-0021-0000-0000-000042A271CB Message-Id: <20180405105631.9514-1-khandual@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2018-04-05_05:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1011 lowpriorityscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1709140000 definitions=main-1804050117 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org There are certian platforms which would like to use SWIOTLB based DMA API for bouncing purpose without actually requiring an IOMMU back end. But the virtio core does not allow such mechanism. Right now DMA MAP API is only selected for devices which have an IOMMU and then the QEMU/host back end will process all incoming SG buffer addresses as IOVA instead of simple GPA which is the case for simple bounce buffers after being processed with SWIOTLB API. To enable this usage, it introduces an architecture specific function which will just make virtio core front end select DMA operations structure. Signed-off-by: Anshuman Khandual --- This RFC is just to get some feedback. Please ignore the function call back into the architecture. It can be worked out properly later on. But the question is can we have virtio devices in the guest which would like to use SWIOTLB based (or any custom DMA API based) bounce buffering with out actually being an IOMMU devices emulated by QEMU/host as been with the current VIRTIO_F_IOMMU_PLATFORM virtio flag ? arch/powerpc/platforms/pseries/iommu.c | 6 ++++++ drivers/virtio/virtio_ring.c | 4 ++++ include/linux/virtio.h | 2 ++ 3 files changed, 12 insertions(+) diff --git a/arch/powerpc/platforms/pseries/iommu.c b/arch/powerpc/platforms/pseries/iommu.c index 06f02960b439..dd15fbddbe89 100644 --- a/arch/powerpc/platforms/pseries/iommu.c +++ b/arch/powerpc/platforms/pseries/iommu.c @@ -1396,3 +1396,9 @@ static int __init disable_multitce(char *str) __setup("multitce=", disable_multitce); machine_subsys_initcall_sync(pseries, tce_iommu_bus_notifier_init); + +bool is_virtio_dma_platform(void) +{ + return true; +} +EXPORT_SYMBOL(is_virtio_dma_platform); diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c index 71458f493cf8..9f205a79d378 100644 --- a/drivers/virtio/virtio_ring.c +++ b/drivers/virtio/virtio_ring.c @@ -144,6 +144,10 @@ struct vring_virtqueue { static bool vring_use_dma_api(struct virtio_device *vdev) { + /* Use DMA API even for virtio devices without an IOMMU */ + if (is_virtio_dma_platform()) + return true; + if (!virtio_has_iommu_quirk(vdev)) return true; diff --git a/include/linux/virtio.h b/include/linux/virtio.h index 988c7355bc22..d8bb83d753ea 100644 --- a/include/linux/virtio.h +++ b/include/linux/virtio.h @@ -200,6 +200,8 @@ static inline struct virtio_driver *drv_to_virtio(struct device_driver *drv) int register_virtio_driver(struct virtio_driver *drv); void unregister_virtio_driver(struct virtio_driver *drv); +extern bool is_virtio_dma_platform(void); + /* module_virtio_driver() - Helper macro for drivers that don't do * anything special in module init/exit. This eliminates a lot of * boilerplate. Each module may only use this macro once, and -- 2.14.1