Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp7224784ybp; Wed, 16 Oct 2019 05:46:04 -0700 (PDT) X-Google-Smtp-Source: APXvYqxWp8MH4BtOqFzZgkrqpsuDD759vAZV4y+MrpXn1F1QRjzthP7UNe2Lhah1IS6o4n1TtC3B X-Received: by 2002:a50:cd17:: with SMTP id z23mr39602783edi.250.1571229963921; Wed, 16 Oct 2019 05:46:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571229963; cv=none; d=google.com; s=arc-20160816; b=PXM/sIUjrufmzekRtMOB4JyEWF6Hpr9wYH0aKINu4UM6agqgKChd70vQwDzVAlSRQP UtJMQoXbr4Z4ZlXdnYgZ/tEJrwBfT+BhCPHs/2rUryZQ29g1p5XBoF5OPvE52WkuvNGh UcY6uFIoj2R1FuGf5UnWFMoUMdLwSyg6ylkRO8wXGbRwhusU5JsR5wMbdA2La8NWHeTe 4nQ/K3Qrmd1y0IDflBlrLJKmZjuZwbgkVOlx0tiFmS7zK5EAnaLGPomejdOs2i/hnjdd ZDlyKynh1AeJe249k1tTrTBT4JLsyoE9hy+W3guzSdbCzXdpKd1Mb4dEGc0n4/0vKW68 eqrg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:subject:message-id:user-agent:in-reply-to :content-disposition:mime-version:references:reply-to:cc:to:from :date; bh=5O9G8IEgPcVhVoGrbSo/qknStF+3qfS/5VjS98Jtz3U=; b=Sc2joqCg0eV7q8gcA2B1XvZxHit4zKAmTtQLEhE3/OFGtQDc4nl4qtio5jFkQm3Xcn 5AFIdw1RpJK/FMKOVZcB5+q+kE1/JSDCkAXHqH+rIopUmn1Htgp4snbOLERU+a7P4fyI wvKxALn252foRIXuL4M4nSDg2Mh2UP3p2KFSvotBky7eZ0IBhxQk/mAuLqraR1YrAiKD tZcKiy0YkRof6uNgC6XJ/9y4HgekBJ4tVb7a8RNaI2jhbOmI30THW9gpBpvAL3NjLg8S Nu0l9F1J1yDENt5koyRiwWkq5oXp4X5gtR/cOzsPxUqcE/dJHcUrTCwwNhfPWO9E/jhS dl4g== 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 n8si14972163ejz.22.2019.10.16.05.45.40; Wed, 16 Oct 2019 05:46:03 -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 S2390432AbfJPHzi (ORCPT + 99 others); Wed, 16 Oct 2019 03:55:38 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:41208 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726277AbfJPHzi (ORCPT ); Wed, 16 Oct 2019 03:55:38 -0400 Received: from pps.filterd (m0098399.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id x9G7gOhR018211 for ; Wed, 16 Oct 2019 03:55:37 -0400 Received: from e06smtp03.uk.ibm.com (e06smtp03.uk.ibm.com [195.75.94.99]) by mx0a-001b2d01.pphosted.com with ESMTP id 2vnugpf4me-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Wed, 16 Oct 2019 03:55:37 -0400 Received: from localhost by e06smtp03.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 16 Oct 2019 08:55:35 +0100 Received: from b06cxnps4076.portsmouth.uk.ibm.com (9.149.109.198) by e06smtp03.uk.ibm.com (192.168.101.133) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Wed, 16 Oct 2019 08:55:29 +0100 Received: from d06av26.portsmouth.uk.ibm.com (d06av26.portsmouth.uk.ibm.com [9.149.105.62]) by b06cxnps4076.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id x9G7tSFt45154546 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 16 Oct 2019 07:55:29 GMT Received: from d06av26.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id C1818AE063; Wed, 16 Oct 2019 07:55:28 +0000 (GMT) Received: from d06av26.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id C0871AE051; Wed, 16 Oct 2019 07:55:24 +0000 (GMT) Received: from oc0525413822.ibm.com (unknown [9.85.142.84]) by d06av26.portsmouth.uk.ibm.com (Postfix) with ESMTPS; Wed, 16 Oct 2019 07:55:24 +0000 (GMT) Date: Wed, 16 Oct 2019 00:55:21 -0700 From: Ram Pai To: Christoph Hellwig 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, david@gibson.dropbear.id.au, mpe@ellerman.id.au, paulus@ozlabs.org, mdroth@linux.vnet.ibm.com, aik@linux.ibm.com, paul.burton@mips.com, robin.murphy@arm.com, b.zolnierkie@samsung.com, m.szyprowski@samsung.com, jasowang@redhat.com, andmike@us.ibm.com, sukadev@linux.vnet.ibm.com Reply-To: Ram Pai References: <1570843519-8696-1-git-send-email-linuxram@us.ibm.com> <1570843519-8696-2-git-send-email-linuxram@us.ibm.com> <1570843519-8696-3-git-send-email-linuxram@us.ibm.com> <20191015073501.GA32345@lst.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20191015073501.GA32345@lst.de> User-Agent: Mutt/1.5.21 (2010-09-15) X-TM-AS-GCONF: 00 x-cbid: 19101607-0012-0000-0000-000003587DE7 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 19101607-0013-0000-0000-000021939633 Message-Id: <20191016075521.GA5201@oc0525413822.ibm.com> Subject: RE: [PATCH 2/2] virtio_ring: Use DMA API if memory is encrypted X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2019-10-16_03:,, 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=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1908290000 definitions=main-1910160072 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Oct 15, 2019 at 09:35:01AM +0200, Christoph Hellwig wrote: > On Fri, Oct 11, 2019 at 06:25:19PM -0700, Ram Pai wrote: > > From: Thiago Jung Bauermann > > > > Normally, virtio enables DMA API with VIRTIO_F_IOMMU_PLATFORM, which must > > be set by both device and guest driver. However, as a hack, when DMA API > > returns physical addresses, guest driver can use the DMA API; even though > > device does not set VIRTIO_F_IOMMU_PLATFORM and just uses physical > > addresses. > > Sorry, but this is a complete bullshit hack. Driver must always use > the DMA API if they do DMA, and if virtio devices use physical addresses > that needs to be returned through the platform firmware interfaces for > the dma setup. If you don't do that yet (which based on previous > informations you don't), you need to fix it, and we can then quirk > old implementations that already are out in the field. > > In other words: we finally need to fix that virtio mess and not pile > hacks on top of hacks. So force all virtio devices to use DMA API, except when VIRTIO_F_IOMMU_PLATFORM is not enabled? Any help detailing the idea, will enable us fix this issue once for all. Will something like below work? It removes the prior hacks, and always uses DMA API; except when VIRTIO_F_IOMMU_PLATFORM is not enabled. diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c index c8be1c4..b593d3d 100644 --- a/drivers/virtio/virtio_ring.c +++ b/drivers/virtio/virtio_ring.c @@ -240,22 +240,10 @@ static inline bool virtqueue_use_indirect(struct virtqueue *_vq, static bool vring_use_dma_api(struct virtio_device *vdev) { - if (!virtio_has_iommu_quirk(vdev)) - return true; - - /* Otherwise, we are left to guess. */ - /* - * In theory, it's possible to have a buggy QEMU-supposed - * emulated Q35 IOMMU and Xen enabled at the same time. On - * such a configuration, virtio has never worked and will - * not work without an even larger kludge. Instead, enable - * the DMA API if we're a Xen guest, which at least allows - * all of the sensible Xen configurations to work correctly. - */ - if (xen_domain()) - return true; + if (virtio_has_iommu_quirk(vdev)) + return false; - return false; + return true; } size_t virtio_max_dma_size(struct virtio_device *vdev) -- Ram Pai