Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp1679445ybt; Thu, 25 Jun 2020 11:28:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJykWdVMg5pymlZ2tbf081lJP9bDCdauV411JfVC/8+cO0RyMgcdXy2n9gTpGNPUX3OYGhzq X-Received: by 2002:a17:907:426c:: with SMTP id nx20mr2018238ejb.548.1593109687531; Thu, 25 Jun 2020 11:28:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1593109687; cv=none; d=google.com; s=arc-20160816; b=0fuH213woy2xPH5NZiHt+sfZz+MaTn2Y9SHLb/QAbfYhtKv14P+UCkI1gs6UQo4TI+ dnJzipGzpXNNnoZpwKN093upAOE6G1uj4XsIFV/NWp1lCU8l04gbf+2sq3rDCXSgWLML SJfdAXNNGWauz9TD5G2bKZcoixSp2nEGcXFLcC1XG0ZjJTSWs3HwFtxFKZHe9DLk7xLv WDCdKVPcgYsE3C0MJyJEwLBwFNBK55qBMiMaqZJHPKXDiiuQp2M4rgI237YvnCCJP72U PcxzNHJeCflEko/FA/1jEK3jzMTJUJq2TuDMrooVkeo12bBnKJL/xOoPEr78ztm2yEFN 6yYg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :message-id:in-reply-to:subject:cc:to:from:date:dkim-signature; bh=Bf0behkZoRXVPsETq09gTC3lhf7TYZJX2j2/fwNtvaw=; b=NgJ7OfFfjOdxhvWSwWDIoMJIm5wcO2vCVHxM6TwjC90b6mQlrcyYjcsEwl5O4Ced0c QMVmT+TlvQi9A0tDUWBcExANBhNQvdLTazRjXUIUI4y3KARnRa/nFWYMMq5dkauL1U9v mKdao8Td/VjmXRDBSWk7qsP8UxwmTKnsbxxs9VHCMRIGfxNj8wgvEK2JEzHf5PW2ZBr5 8z+pO8oUgtHqDASHKO67FyAxYtlccOjXJlKxD5Nh0HxXVOtPt6NX6IbJwInjD6xAcbul K/jWnqCxfV21tiZ1ziaQs6BQnBMTh1mI+mXtHbHNbYxcy/NInoysE+m/NxR8o3tJenlp NaRA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="KNaQ/3jj"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d13si3247367edh.256.2020.06.25.11.27.44; Thu, 25 Jun 2020 11:28:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="KNaQ/3jj"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2406816AbgFYRba (ORCPT + 99 others); Thu, 25 Jun 2020 13:31:30 -0400 Received: from mail.kernel.org ([198.145.29.99]:51044 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2404698AbgFYRb3 (ORCPT ); Thu, 25 Jun 2020 13:31:29 -0400 Received: from localhost (c-67-164-102-47.hsd1.ca.comcast.net [67.164.102.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 0FEDB20789; Thu, 25 Jun 2020 17:31:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1593106288; bh=WhqBDPdOBNk4Nn0nlm/U/FBDprV3efhSWtdS+mTEZhI=; h=Date:From:To:cc:Subject:In-Reply-To:References:From; b=KNaQ/3jj9TpuSnPt+fOmTGLlW7zN97Hc5nMeEhGWFn3RY4Vu5yOi/rL1784qarDyK p9hWwTE8sLerEFX9rM+jYpsgztP56cS6phku8LqLBrkd8JcN8KNPpoVQD+Ru6HllCU KTeOrcYXJqrOnQ00srcPg/hv/0Q/e8ghv8knwqvk= Date: Thu, 25 Jun 2020 10:31:27 -0700 (PDT) From: Stefano Stabellini X-X-Sender: sstabellini@sstabellini-ThinkPad-T480s To: "Michael S. Tsirkin" cc: Stefano Stabellini , Peng Fan , boris.ostrovsky@oracle.com, jgross@suse.com, konrad.wilk@oracle.com, jasowang@redhat.com, x86@kernel.org, xen-devel@lists.xenproject.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, iommu@lists.linux-foundation.org, virtualization@lists.linux-foundation.org, linux-imx@nxp.com Subject: Re: [PATCH] xen: introduce xen_vring_use_dma In-Reply-To: <20200624181026-mutt-send-email-mst@kernel.org> Message-ID: References: <20200624091732.23944-1-peng.fan@nxp.com> <20200624050355-mutt-send-email-mst@kernel.org> <20200624163940-mutt-send-email-mst@kernel.org> <20200624181026-mutt-send-email-mst@kernel.org> User-Agent: Alpine 2.21 (DEB 202 2017-01-01) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 24 Jun 2020, Michael S. Tsirkin wrote: > On Wed, Jun 24, 2020 at 02:53:54PM -0700, Stefano Stabellini wrote: > > On Wed, 24 Jun 2020, Michael S. Tsirkin wrote: > > > On Wed, Jun 24, 2020 at 10:59:47AM -0700, Stefano Stabellini wrote: > > > > On Wed, 24 Jun 2020, Michael S. Tsirkin wrote: > > > > > On Wed, Jun 24, 2020 at 05:17:32PM +0800, Peng Fan wrote: > > > > > > Export xen_swiotlb for all platforms using xen swiotlb > > > > > > > > > > > > Use xen_swiotlb to determine when vring should use dma APIs to map the > > > > > > ring: when xen_swiotlb is enabled the dma API is required. When it is > > > > > > disabled, it is not required. > > > > > > > > > > > > Signed-off-by: Peng Fan > > > > > > > > > > Isn't there some way to use VIRTIO_F_IOMMU_PLATFORM for this? > > > > > Xen was there first, but everyone else is using that now. > > > > > > > > Unfortunately it is complicated and it is not related to > > > > VIRTIO_F_IOMMU_PLATFORM :-( > > > > > > > > > > > > The Xen subsystem in Linux uses dma_ops via swiotlb_xen to translate > > > > foreign mappings (memory coming from other VMs) to physical addresses. > > > > On x86, it also uses dma_ops to translate Linux's idea of a physical > > > > address into a real physical address (this is unneeded on ARM.) > > > > > > > > > > > > So regardless of VIRTIO_F_IOMMU_PLATFORM, dma_ops should be used on Xen/x86 > > > > always and on Xen/ARM if Linux is Dom0 (because it has foreign > > > > mappings.) That is why we have the if (xen_domain) return true; in > > > > vring_use_dma_api. > > > > > > VIRTIO_F_IOMMU_PLATFORM makes guest always use DMA ops. > > > > > > Xen hack predates VIRTIO_F_IOMMU_PLATFORM so it *also* > > > forces DMA ops even if VIRTIO_F_IOMMU_PLATFORM is clear. > > > > > > Unfortunately as a result Xen never got around to > > > properly setting VIRTIO_F_IOMMU_PLATFORM. > > > > I don't think VIRTIO_F_IOMMU_PLATFORM would be correct for this because > > the usage of swiotlb_xen is not a property of virtio, > > > Basically any device without VIRTIO_F_ACCESS_PLATFORM > (that is it's name in latest virtio spec, VIRTIO_F_IOMMU_PLATFORM is > what linux calls it) is declared as "special, don't follow normal rules > for access". > > So yes swiotlb_xen is not a property of virtio, but what *is* a property > of virtio is that it's not special, just a regular device from DMA POV. I am trying to understand what you meant but I think I am missing something. Are you saying that modern virtio should always have VIRTIO_F_ACCESS_PLATFORM, hence use normal dma_ops as any other devices? If that is the case, how is it possible that virtio breaks on ARM using the default dma_ops? The breakage is not Xen related (except that Xen turns dma_ops on). The original message from Peng was: vring_map_one_sg -> vring_use_dma_api -> dma_map_page -> __swiotlb_map_page ->swiotlb_map_page ->__dma_map_area(phys_to_virt(dma_to_phys(dev, dev_addr)), size, dir); However we are using per device dma area for rpmsg, phys_to_virt could not return a correct virtual address for virtual address in vmalloc area. Then kernel panic. I must be missing something. Maybe it is because it has to do with RPMesg? > > > > You might have noticed that I missed one possible case above: Xen/ARM > > > > DomU :-) > > > > > > > > Xen/ARM domUs don't need swiotlb_xen, it is not even initialized. So if > > > > (xen_domain) return true; would give the wrong answer in that case. > > > > Linux would end up calling the "normal" dma_ops, not swiotlb-xen, and > > > > the "normal" dma_ops fail. > > > > > > > > > > > > The solution I suggested was to make the check in vring_use_dma_api more > > > > flexible by returning true if the swiotlb_xen is supposed to be used, > > > > not in general for all Xen domains, because that is what the check was > > > > really meant to do. > > > > > > Why not fix DMA ops so they DTRT (nop) on Xen/ARM DomU? What is wrong with that? > > > > swiotlb-xen is not used on Xen/ARM DomU, the default dma_ops are the > > ones that are used. So you are saying, why don't we fix the default > > dma_ops to work with virtio? > > > > It is bad that the default dma_ops crash with virtio, so yes I think it > > would be good to fix that. However, even if we fixed that, the if > > (xen_domain()) check in vring_use_dma_api is still a problem. > > Why is it a problem? It just makes virtio use DMA API. > If that in turn works, problem solved. You are correct in the sense that it would work. However I do think it is wrong for vring_use_dma_api to enable dma_ops/swiotlb-xen for Xen/ARM DomUs that don't need it. There are many different types of Xen guests, Xen x86 is drastically different from Xen ARM, it seems wrong to treat them the same way. Anyway, re-reading the last messages of the original thread [1], it looks like Peng had a clear idea on how to fix the general issue. Peng, what happened with that? [1] https://lore.kernel.org/patchwork/patch/1033801/#1222404