Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp2317146imm; Sat, 28 Jul 2018 14:17:46 -0700 (PDT) X-Google-Smtp-Source: AAOMgpdBtDxMq2IX1+pFnIt5ZseM+EBwmgRfpokC+Qifu4JwwwJgS50CJb1eXs0Ec/TiEKXBr3Jw X-Received: by 2002:a17:902:a716:: with SMTP id w22-v6mr10827600plq.271.1532812666523; Sat, 28 Jul 2018 14:17:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532812666; cv=none; d=google.com; s=arc-20160816; b=a999Ar2/dn1Ao0ekXkxjoE7x4kAv7g3vGuPG9AZ8uvzTKl1bPiYRST2b/0HdHJqeHD Du/5l8QAn3UZCwtSaGNaq1MzTk+cOvRhkakYbi6IArJIMaaL5f+r9svHCXacggUT3Ma7 VFujR2uG4Rajf0e0BnueFkbW8v7LS3xmRM/2eoqGsxgZu9pvrS6PFbSSEhcFBQuQBHSf 0hjAi9zucwv0OhwIFHrLJO5wlzSmURJ3H1A4eWJpdFGNcFsaot65t/Qk622Lzmixd6Qe 7XQrJglemMMQk5d085+z3VQyCroCvrCKu2dH39wCWTfxV8GaSYysiTSIE9IvmG89rCl8 sFmw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :arc-authentication-results; bh=2UK19RNSyEb+wCUYuvDa6IUxlqIAan9G6e881ZOl/5Q=; b=ANG1XoIP52o6jC4MwSeEA9anXM3KfZh+ENvkZq4BqcnF751mw/D4o8w8a9q0/h1o4L WNe2iol0aJBGvrMotPn63rINn+GFxvr0Dv/w+YyWZLQn3TdzhcTTtjEnlOrfF7E+gD5o b3e+hVdXzxzejSFpRSL8BHUvM165ODJcUyUTbzaSvP6irVXL7gGEJxT9s2qmFYcNLaIk 7BIT1xRYolX94oeRlv3zVBc+1QURPh1UFsPgHTzqNB2VofNq/bPyi27aBNoV5TNllMJh iXmvdl+tHTL3aHtLgTYK0mNw8j1V80Ai7QV9jTtLWgmHZhS99L3VLCKOjfJilxVDm3hq PYDw== 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=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i4-v6si7083803pgd.657.2018.07.28.14.17.32; Sat, 28 Jul 2018 14:17:46 -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=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731059AbeG1WoQ (ORCPT + 99 others); Sat, 28 Jul 2018 18:44:16 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:53254 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1730551AbeG1WoQ (ORCPT ); Sat, 28 Jul 2018 18:44:16 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A196540216E4; Sat, 28 Jul 2018 21:16:25 +0000 (UTC) Received: from redhat.com (ovpn-116-41.ams2.redhat.com [10.36.116.41]) by smtp.corp.redhat.com (Postfix) with SMTP id 5066F111AF24; Sat, 28 Jul 2018 21:16:20 +0000 (UTC) Date: Sun, 29 Jul 2018 00:16:19 +0300 From: "Michael S. Tsirkin" To: Anshuman Khandual Cc: virtualization@lists.linux-foundation.org, linux-kernel@vger.kernel.org, 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, hch@infradead.org, linuxram@us.ibm.com, haren@linux.vnet.ibm.com, paulus@samba.org, srikar@linux.vnet.ibm.com Subject: Re: [RFC 2/4] virtio: Override device's DMA OPS with virtio_direct_dma_ops selectively Message-ID: <20180729001344-mutt-send-email-mst@kernel.org> References: <20180720035941.6844-1-khandual@linux.vnet.ibm.com> <20180720035941.6844-3-khandual@linux.vnet.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Sat, 28 Jul 2018 21:16:25 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Sat, 28 Jul 2018 21:16:25 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'mst@redhat.com' RCPT:'' Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, Jul 28, 2018 at 02:26:24PM +0530, Anshuman Khandual wrote: > 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: > + I prefer normal if scoping as opposed to goto spaghetti pls. Better yet move vring_use_dma_api here and use it. Less of a chance something will break. > if (!virtio_has_feature(dev, VIRTIO_F_VERSION_1)) > return 0 > > Will incorporate these changes in the next version.