Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp1748556imm; Sat, 28 Jul 2018 01:57:40 -0700 (PDT) X-Google-Smtp-Source: AAOMgpeT34yCyfXTV+2nifBhu/ptrtdgMcHLEW0bcHtfuY6fssPmbAwKeXwbwAL1P/T6flE6vOji X-Received: by 2002:a17:902:1ab:: with SMTP id b40-v6mr8836969plb.55.1532768259988; Sat, 28 Jul 2018 01:57:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532768259; cv=none; d=google.com; s=arc-20160816; b=rrrgx/ZvNRWz0mntCLPkF6TxHDJft6J84FKv/BrNyfCJ1CzHcDBy+X9VIsfAA26khc 0ImY4H7bJFFXpqB3W+bn2s7QWwvrqdwPYm+Oo4D7NdydkIqaEv0SKxY3WYigk9Kf8LM+ puymBwc6AxlNGGhVgM9masF8LzJrlpZO1eF0OYcRrftmXBLFKQjQtYwmcI1WZ5YG0y3p MA1wyw2PuHDLg3cX8FwSca29GZ7JE/AgP+c+jkZzV52GjYtPGQX8s8KJ5CyBm0lFItAi elJdODngkuh2VpMnc38rA9Occ/VpDH2L3d32PeIOjuz0BRWtW15lWePYmtP4rPSt2piV lv5g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:content-transfer-encoding :in-reply-to:mime-version:user-agent:date:from:cc:references:to :subject:arc-authentication-results; bh=OGNchPVeGqoR87I0PSFRVrl9DRzNG+RLKAMxMozvIus=; b=j51ookblijMlwpSVxmcOyX6IXNCt1jPs8/M1XdyNlodvhwBzCkC/JQbv7J24h7yUGT LAYuzuNiapMbtThZz1ErtZeW5SD/TDkAkgEonU6oVN2qHvZG/sdsSFj7UiqndRuC/aEU EvaZrAGCXrVBgAK4lPU4AlSxpteX7iQqDSYqu9uG3TIv3IkNu9pVH9K7rjEnViY+H5OD j868/61G+dFhtQ4HapepKYd2P5uDkdDSbUti4k3bcLphuupztir7rLlYFkAwE9jG/6ee IvTm6ZuXcGuwQJCUe87fUTpLWySPYz4nWHA0niyQtY/xnoWhGT16drMqZ90dcqBrdlkc 1yXg== 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 g12-v6si5701887pfh.346.2018.07.28.01.57.24; Sat, 28 Jul 2018 01:57:39 -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 S1727777AbeG1KWV (ORCPT + 99 others); Sat, 28 Jul 2018 06:22:21 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:51022 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726350AbeG1KWU (ORCPT ); Sat, 28 Jul 2018 06:22:20 -0400 Received: from pps.filterd (m0098420.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w6S8rsMq026311 for ; Sat, 28 Jul 2018 04:56:35 -0400 Received: from e06smtp05.uk.ibm.com (e06smtp05.uk.ibm.com [195.75.94.101]) by mx0b-001b2d01.pphosted.com with ESMTP id 2kgmp5s1ts-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Sat, 28 Jul 2018 04:56:34 -0400 Received: from localhost by e06smtp05.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Sat, 28 Jul 2018 09:56:33 +0100 Received: from b06cxnps3074.portsmouth.uk.ibm.com (9.149.109.194) by e06smtp05.uk.ibm.com (192.168.101.135) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Sat, 28 Jul 2018 09:56:29 +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 w6S8uSsL42074162 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Sat, 28 Jul 2018 08:56:28 GMT Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 001E8A4055; Sat, 28 Jul 2018 11:56:40 +0100 (BST) Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 6700EA4040; Sat, 28 Jul 2018 11:56:38 +0100 (BST) Received: from localhost.localdomain (unknown [9.122.224.197]) by d06av23.portsmouth.uk.ibm.com (Postfix) with ESMTP; Sat, 28 Jul 2018 11:56:38 +0100 (BST) Subject: Re: [RFC 2/4] virtio: Override device's DMA OPS with virtio_direct_dma_ops selectively To: virtualization@lists.linux-foundation.org, linux-kernel@vger.kernel.org References: <20180720035941.6844-1-khandual@linux.vnet.ibm.com> <20180720035941.6844-3-khandual@linux.vnet.ibm.com> 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, mst@redhat.com, hch@infradead.org, linuxram@us.ibm.com, haren@linux.vnet.ibm.com, paulus@samba.org, srikar@linux.vnet.ibm.com From: Anshuman Khandual Date: Sat, 28 Jul 2018 14:26:24 +0530 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.5.1 MIME-Version: 1.0 In-Reply-To: <20180720035941.6844-3-khandual@linux.vnet.ibm.com> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit X-TM-AS-GCONF: 00 x-cbid: 18072808-0020-0000-0000-000002AD3B6C X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18072808-0021-0000-0000-000020F94B4E Message-Id: X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2018-07-28_04:,, 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-1806210000 definitions=main-1807280095 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 07/20/2018 09:29 AM, Anshuman Khandual wrote: > Now that virtio core always needs all virtio devices to have DMA OPS, we > need to make sure that the structure it points is the right one. In the > absence of VIRTIO_F_IOMMU_PLATFORM flag QEMU expects GPA from guest kernel. > In such case, virtio device must use default virtio_direct_dma_ops DMA OPS > structure which transforms scatter gather buffer addresses as GPA. This > DMA OPS override must happen as early as possible during virtio device > initializatin sequence before virtio core starts using given device's DMA > OPS callbacks for I/O transactions. This change detects device's IOMMU flag > and does the override in case the flag is cleared. > > Signed-off-by: Anshuman Khandual > --- > drivers/virtio/virtio.c | 5 +++++ > 1 file changed, 5 insertions(+) > > diff --git a/drivers/virtio/virtio.c b/drivers/virtio/virtio.c > index 7907ad3..6b13987 100644 > --- a/drivers/virtio/virtio.c > +++ b/drivers/virtio/virtio.c > @@ -166,6 +166,8 @@ void virtio_add_status(struct virtio_device *dev, unsigned int status) > } > EXPORT_SYMBOL_GPL(virtio_add_status); > > +const struct dma_map_ops virtio_direct_dma_ops; > + > int virtio_finalize_features(struct virtio_device *dev) > { > int ret = dev->config->finalize_features(dev); > @@ -174,6 +176,9 @@ int virtio_finalize_features(struct virtio_device *dev) > if (ret) > return ret; The previous patch removed the code block for XEN guests which forced the use of DMA API all the time irrespective of VIRTIO_F_IOMMU_PLATFORM flag on the device. Here is what I have removed with patch 2/4 which breaks the existing semantics on XEN guests. -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; - - return false; -} XEN guests would not like override with virtio_direct_dma_ops in any case irrespective of the flag VIRTIO_F_IOMMU_PLATFORM. So the existing semantics can be preserved with something like this. It just assumes that dev->dma_ops is non-NULL and a valid one set by the architecture. If required we can add those tests here before skipping the override. diff --git a/drivers/virtio/virtio.c b/drivers/virtio/virtio.c index 7907ad3..6b13987 100644 --- a/drivers/virtio/virtio.c +++ b/drivers/virtio/virtio.c @@ -166,6 +166,8 @@ void virtio_add_status(struct virtio_device *dev, unsigned int status) } EXPORT_SYMBOL_GPL(virtio_add_status); +const struct dma_map_ops virtio_direct_dma_ops; + int virtio_finalize_features(struct virtio_device *dev) { int ret = dev->config->finalize_features(dev); @@ -174,6 +176,9 @@ int virtio_finalize_features(struct virtio_device *dev) if (ret) return ret; + + if (xen_domain()) + goto skip_override; + + if (virtio_has_iommu_quirk(dev)) + set_dma_ops(dev->dev.parent, &virtio_direct_dma_ops); + + skip_override: + if (!virtio_has_feature(dev, VIRTIO_F_VERSION_1)) return 0 Will incorporate these changes in the next version.