From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7FBE1C433E0 for ; Fri, 26 Jun 2020 15:32:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4E3012080C for ; Fri, 26 Jun 2020 15:32:54 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="EhvtUapI" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726613AbgFZPcw (ORCPT ); Fri, 26 Jun 2020 11:32:52 -0400 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:23021 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725275AbgFZPcw (ORCPT ); Fri, 26 Jun 2020 11:32:52 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593185569; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=RTWe4soL1srkDL8PEEfq928W6GWa5t1pS8aCmfU8LHE=; b=EhvtUapIFt7i7WtEm4zKlZwJ66ueRYL1HMDLqFUD9sCUzdEz453LpX/JHmCvWlcOlbTJBb qL4QXTgytDesLZR0cZG0KW9uHvFJgN2VJXt+WVGn9+6naCBi7RqtzJPYIOsUSJwSDPcESW 35/6v9AYCcTuBtRVQ4RtJxVnLay6uv4= Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-349-B69HOd67M-m1Bed0EVRgww-1; Fri, 26 Jun 2020 11:32:47 -0400 X-MC-Unique: B69HOd67M-m1Bed0EVRgww-1 Received: by mail-wm1-f70.google.com with SMTP id t145so11758551wmt.2 for ; Fri, 26 Jun 2020 08:32:47 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=RTWe4soL1srkDL8PEEfq928W6GWa5t1pS8aCmfU8LHE=; b=oPaVJr/niCj62nfVoYYiwiQh6jDCgpAp80axaU2iSPuG9WltfqtyAtJ776umyTiWdh 4UYF4AUcyMuIj80EhGYiMVeUi1R3o0ZIwUvPOec6ZHDz6eQQ9TUi/8FOXn1pWa7yKDeu FagX+XtEStBZv1u5HibdZrKLiT6DzMgq8w7UBz5FwP5AMKpsYiXvZpJZosLsIkweSkMk WnfOnyPmRZClzSS6YzXuhFP1WE6i4WuDOnFkZd4xvsic4mFrrQy53dHObl594S284w2V b3gGa6T2LaFe4qTI5Z9e4qKhl+combZLh/FA2w/GhZ0E75hEenN5Qe/MCNqB38qxc5RB 8Qdg== X-Gm-Message-State: AOAM532seVEFeuerVJ+6TsR7qp3wANxdbGtJaMMJjbGNJ+1wSWL+dQ87 Z7+q/oRCL1nUJMyv+/TZ0uIGKlCXZfM0N9oJrWoiKSAXHEmp1X3XmOGR7MZtdfSa4DWTtK7NUdI CwCJ55WkuWjLL+O5hImJK9vz4 X-Received: by 2002:a5d:55cb:: with SMTP id i11mr4167961wrw.28.1593185566632; Fri, 26 Jun 2020 08:32:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzKcm6jtqvubhG72TQoDWqW1duiFh/JDhCCKL54qZ+AftyQ9QDCAEubqgx6Fkb+6w/6lcA4Aw== X-Received: by 2002:a5d:55cb:: with SMTP id i11mr4167932wrw.28.1593185566346; Fri, 26 Jun 2020 08:32:46 -0700 (PDT) Received: from redhat.com (bzq-79-182-31-92.red.bezeqint.net. [79.182.31.92]) by smtp.gmail.com with ESMTPSA id 65sm18427582wma.48.2020.06.26.08.32.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Jun 2020 08:32:45 -0700 (PDT) Date: Fri, 26 Jun 2020 11:32:41 -0400 From: "Michael S. Tsirkin" To: Stefano Stabellini Cc: 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 Message-ID: <20200626110629-mutt-send-email-mst@kernel.org> 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> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jun 25, 2020 at 10:31:27AM -0700, Stefano Stabellini wrote: > 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? I am saying it's a safe default. Clear VIRTIO_F_ACCESS_PLATFORM if you have some special needs e.g. you are very sure it's ok to bypass DMA ops, or you need to support a legacy guest (produced in the window between virtio 1 support in 2014 and support for VIRTIO_F_ACCESS_PLATFORM in 2016). > 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? I think it's an RPMesg bug, yes. > > > > > > 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. I could imagine some future Xen hosts setting a flag somewhere in the platform capability saying "no xen specific flag, rely on "VIRTIO_F_ACCESS_PLATFORM". Then you set that accordingly in QEMU. How about that? > > > 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 From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.8 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7A531C433E1 for ; Fri, 26 Jun 2020 15:32:55 +0000 (UTC) Received: from fraxinus.osuosl.org (smtp4.osuosl.org [140.211.166.137]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 3DD5A2080C for ; Fri, 26 Jun 2020 15:32:55 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="EhvtUapI" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3DD5A2080C Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=iommu-bounces@lists.linux-foundation.org Received: from localhost (localhost [127.0.0.1]) by fraxinus.osuosl.org (Postfix) with ESMTP id F1FC685B4D; Fri, 26 Jun 2020 15:32:54 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from fraxinus.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id dMQh9gLFBiNI; Fri, 26 Jun 2020 15:32:53 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by fraxinus.osuosl.org (Postfix) with ESMTP id E9E4385EC2; Fri, 26 Jun 2020 15:32:53 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id A3054C088C; Fri, 26 Jun 2020 15:32:53 +0000 (UTC) Received: from hemlock.osuosl.org (smtp2.osuosl.org [140.211.166.133]) by lists.linuxfoundation.org (Postfix) with ESMTP id 25056C016F for ; Fri, 26 Jun 2020 15:32:52 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by hemlock.osuosl.org (Postfix) with ESMTP id 1C4E988378 for ; Fri, 26 Jun 2020 15:32:52 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from hemlock.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id jZnJ6v-Q1k6r for ; Fri, 26 Jun 2020 15:32:51 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from us-smtp-delivery-1.mimecast.com (us-smtp-1.mimecast.com [205.139.110.61]) by hemlock.osuosl.org (Postfix) with ESMTPS id DD6BC882F6 for ; Fri, 26 Jun 2020 15:32:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593185569; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=RTWe4soL1srkDL8PEEfq928W6GWa5t1pS8aCmfU8LHE=; b=EhvtUapIFt7i7WtEm4zKlZwJ66ueRYL1HMDLqFUD9sCUzdEz453LpX/JHmCvWlcOlbTJBb qL4QXTgytDesLZR0cZG0KW9uHvFJgN2VJXt+WVGn9+6naCBi7RqtzJPYIOsUSJwSDPcESW 35/6v9AYCcTuBtRVQ4RtJxVnLay6uv4= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-240-6Oz2BfymOxucgN_ZIuBeAA-1; Fri, 26 Jun 2020 11:32:47 -0400 X-MC-Unique: 6Oz2BfymOxucgN_ZIuBeAA-1 Received: by mail-wm1-f69.google.com with SMTP id z11so11369895wmg.5 for ; Fri, 26 Jun 2020 08:32:47 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=RTWe4soL1srkDL8PEEfq928W6GWa5t1pS8aCmfU8LHE=; b=ZUbxmNuT2LkPjUiG36ylopLUw4Gsg6zw6Yjb1J85ZfJROG9FbQPE04kQEjTykOdcMC F252854YfNneCrAk4Et5v8gl9Q/xcPlEhGRTTJYiHQYVnBtMJ5F/0S9wYZKq4lsRTWqW eEWqco6E613zDecWK2DYP4i5NHr/ijYOb496dwPl67ATr6XUwZWpkG1PQui3w2gQBNNM z/EvmXVYTHqqv0DY1n0/8/zzMGvIEHn/4nDGwlN8FtB+OUMYGRr5TDKwYCPspVXtEWW5 fPN0UgwS89Bdy6UOitrNXFDScwe6y1R+FvFd27fpOScvhyc/RGTngTCEfZAWwnB7Redk slxg== X-Gm-Message-State: AOAM530XXkoed1GZI2pbRqDK4UeLBoNdYCDZ2OHOp2dVpE/yhBxVk42O mRpJ40xd7ofy8o17liPXN3e4LvNQxQubF+Oa7/wqg4OwFlbaRZjwhOEoOHlM+WUpLebrku0BWJ3 i7xnGSKtu5vpdPHA0gjeG6bASxX6WrA== X-Received: by 2002:a5d:55cb:: with SMTP id i11mr4167956wrw.28.1593185566631; Fri, 26 Jun 2020 08:32:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzKcm6jtqvubhG72TQoDWqW1duiFh/JDhCCKL54qZ+AftyQ9QDCAEubqgx6Fkb+6w/6lcA4Aw== X-Received: by 2002:a5d:55cb:: with SMTP id i11mr4167932wrw.28.1593185566346; Fri, 26 Jun 2020 08:32:46 -0700 (PDT) Received: from redhat.com (bzq-79-182-31-92.red.bezeqint.net. [79.182.31.92]) by smtp.gmail.com with ESMTPSA id 65sm18427582wma.48.2020.06.26.08.32.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Jun 2020 08:32:45 -0700 (PDT) Date: Fri, 26 Jun 2020 11:32:41 -0400 From: "Michael S. Tsirkin" To: Stefano Stabellini Subject: Re: [PATCH] xen: introduce xen_vring_use_dma Message-ID: <20200626110629-mutt-send-email-mst@kernel.org> 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> MIME-Version: 1.0 In-Reply-To: X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline Cc: jgross@suse.com, Peng Fan , konrad.wilk@oracle.com, jasowang@redhat.com, x86@kernel.org, linux-kernel@vger.kernel.org, virtualization@lists.linux-foundation.org, iommu@lists.linux-foundation.org, linux-imx@nxp.com, xen-devel@lists.xenproject.org, boris.ostrovsky@oracle.com, linux-arm-kernel@lists.infradead.org X-BeenThere: iommu@lists.linux-foundation.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: Development issues for Linux IOMMU support List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: iommu-bounces@lists.linux-foundation.org Sender: "iommu" On Thu, Jun 25, 2020 at 10:31:27AM -0700, Stefano Stabellini wrote: > 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? I am saying it's a safe default. Clear VIRTIO_F_ACCESS_PLATFORM if you have some special needs e.g. you are very sure it's ok to bypass DMA ops, or you need to support a legacy guest (produced in the window between virtio 1 support in 2014 and support for VIRTIO_F_ACCESS_PLATFORM in 2016). > 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? I think it's an RPMesg bug, yes. > > > > > > 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. I could imagine some future Xen hosts setting a flag somewhere in the platform capability saying "no xen specific flag, rely on "VIRTIO_F_ACCESS_PLATFORM". Then you set that accordingly in QEMU. How about that? > > > 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 _______________________________________________ iommu mailing list iommu@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/iommu From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Michael S. Tsirkin" Subject: Re: [PATCH] xen: introduce xen_vring_use_dma Date: Fri, 26 Jun 2020 11:32:41 -0400 Message-ID: <20200626110629-mutt-send-email-mst@kernel.org> 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> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: Content-Disposition: inline List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: iommu-bounces-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org Sender: "iommu" To: Stefano Stabellini Cc: jgross-IBi9RG/b67k@public.gmane.org, Peng Fan , konrad.wilk-QHcLZuEGTsvQT0dZR+AlfA@public.gmane.org, jasowang-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org, x86-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org, linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, virtualization-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org, iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org, linux-imx-3arQi8VN3Tc@public.gmane.org, xen-devel-GuqFBffKawtpuQazS67q72D2FQJk+8+b@public.gmane.org, boris.ostrovsky-QHcLZuEGTsvQT0dZR+AlfA@public.gmane.org, linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org List-Id: virtualization@lists.linuxfoundation.org On Thu, Jun 25, 2020 at 10:31:27AM -0700, Stefano Stabellini wrote: > 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? I am saying it's a safe default. Clear VIRTIO_F_ACCESS_PLATFORM if you have some special needs e.g. you are very sure it's ok to bypass DMA ops, or you need to support a legacy guest (produced in the window between virtio 1 support in 2014 and support for VIRTIO_F_ACCESS_PLATFORM in 2016). > 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? I think it's an RPMesg bug, yes. > > > > > > 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. I could imagine some future Xen hosts setting a flag somewhere in the platform capability saying "no xen specific flag, rely on "VIRTIO_F_ACCESS_PLATFORM". Then you set that accordingly in QEMU. How about that? > > > 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 From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.0 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4D362C433DF for ; Fri, 26 Jun 2020 15:35:17 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 18ECF20706 for ; Fri, 26 Jun 2020 15:35:17 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="qmKQEQZl"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="EhvtUapI" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 18ECF20706 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References:Message-ID: Subject:To:From:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=iyKDQ+Ms7JHue8MbyHrd6pMcZubc53pGBX/IgS86g60=; b=qmKQEQZlFlk9DPcxT2hwLQcNj jhGvlpJDpHL29j9I5f6QVc7SlQgxpMFt6IiZ+0gUq+6D7A/Yq/juKFwPdab3p9sHOxj7z0dmBa3ou d9EVCjHSrQLljAoIgOLXz3rOip321o5jM+U2vGdtra85WbvhQ7ctLCDr4xk6WKZjvXbAfgFoWsPCu xmhcOoWm7DZ3cQoeHI7J/IUHSNvJfP3C8dcvEHN8pRc+Xq0NCjJAkcSJ65WInNDb8jKrBamWThaip 1+CYv3ZtgEd+1d1m36nfG1OhrPdCuVwtjbv+lfVNdnLbezsiNAZEd1TN8bSkwYYN0BvB3Gv+tgJ2q dm5UyV0lQ==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1joqLc-0008Kp-8N; Fri, 26 Jun 2020 15:33:02 +0000 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120] helo=us-smtp-1.mimecast.com) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1joqLU-0008Jv-DX for linux-arm-kernel@lists.infradead.org; Fri, 26 Jun 2020 15:32:53 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593185569; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=RTWe4soL1srkDL8PEEfq928W6GWa5t1pS8aCmfU8LHE=; b=EhvtUapIFt7i7WtEm4zKlZwJ66ueRYL1HMDLqFUD9sCUzdEz453LpX/JHmCvWlcOlbTJBb qL4QXTgytDesLZR0cZG0KW9uHvFJgN2VJXt+WVGn9+6naCBi7RqtzJPYIOsUSJwSDPcESW 35/6v9AYCcTuBtRVQ4RtJxVnLay6uv4= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-144-9wF3Yju8PlOM1P1D0O8huw-1; Fri, 26 Jun 2020 11:32:48 -0400 X-MC-Unique: 9wF3Yju8PlOM1P1D0O8huw-1 Received: by mail-wm1-f71.google.com with SMTP id e15so11348529wme.8 for ; Fri, 26 Jun 2020 08:32:48 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=RTWe4soL1srkDL8PEEfq928W6GWa5t1pS8aCmfU8LHE=; b=i5kmlf0d3z8E/PiTpkEACHed5V0Clr5Fsv3+tXDQferKxWBdKMSSzbWQVSxy0YGejW mGOEfqwwyoDzx1r6/sT/1IpuY8udDbofNjjCNIH5uugnf0+pJ198lbAVm7ymVPMzjd22 Wu1lRDQPqjbA4U04CCF2oFTCPqee7cRNBfVqrgPChWVIqG1JuRl0mExN7mOdmS1+Ydu4 jyxw8PYFhdL8+hvR8IMdNzYQq3N3SmwCCq7Wp7oJYvnpwZLtx8c4dTkxz+059CWR6YAJ sIsAhPWLz2entcHMBFT8ImCl5Bap2eLmQUKYBt1To50LD1/EMHWW2RwU2YiSyMKrbxdV QvoQ== X-Gm-Message-State: AOAM532sKc4jsNUkfYkncQgaWjWg3szV3c2XPI4F2iiBruVa1iz00eFB 6CuojjcwnRQubMIpSK0reErBmjYFp1r59gtgwpxnpU7iL+reVKAmnrDlyPsSy0reCsSS5Fh3YFm OKJjJF/prhu3O87Wsz6jnBCGvOU5gRvsz92g= X-Received: by 2002:a5d:55cb:: with SMTP id i11mr4167949wrw.28.1593185566630; Fri, 26 Jun 2020 08:32:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzKcm6jtqvubhG72TQoDWqW1duiFh/JDhCCKL54qZ+AftyQ9QDCAEubqgx6Fkb+6w/6lcA4Aw== X-Received: by 2002:a5d:55cb:: with SMTP id i11mr4167932wrw.28.1593185566346; Fri, 26 Jun 2020 08:32:46 -0700 (PDT) Received: from redhat.com (bzq-79-182-31-92.red.bezeqint.net. [79.182.31.92]) by smtp.gmail.com with ESMTPSA id 65sm18427582wma.48.2020.06.26.08.32.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Jun 2020 08:32:45 -0700 (PDT) Date: Fri, 26 Jun 2020 11:32:41 -0400 From: "Michael S. Tsirkin" To: Stefano Stabellini Subject: Re: [PATCH] xen: introduce xen_vring_use_dma Message-ID: <20200626110629-mutt-send-email-mst@kernel.org> 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> MIME-Version: 1.0 In-Reply-To: X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: jgross@suse.com, Peng Fan , konrad.wilk@oracle.com, jasowang@redhat.com, x86@kernel.org, linux-kernel@vger.kernel.org, virtualization@lists.linux-foundation.org, iommu@lists.linux-foundation.org, linux-imx@nxp.com, xen-devel@lists.xenproject.org, boris.ostrovsky@oracle.com, linux-arm-kernel@lists.infradead.org Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Thu, Jun 25, 2020 at 10:31:27AM -0700, Stefano Stabellini wrote: > 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? I am saying it's a safe default. Clear VIRTIO_F_ACCESS_PLATFORM if you have some special needs e.g. you are very sure it's ok to bypass DMA ops, or you need to support a legacy guest (produced in the window between virtio 1 support in 2014 and support for VIRTIO_F_ACCESS_PLATFORM in 2016). > 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? I think it's an RPMesg bug, yes. > > > > > > 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. I could imagine some future Xen hosts setting a flag somewhere in the platform capability saying "no xen specific flag, rely on "VIRTIO_F_ACCESS_PLATFORM". Then you set that accordingly in QEMU. How about that? > > > 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 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.8 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5639FC433DF for ; Fri, 26 Jun 2020 15:33:17 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 2738A2080C for ; Fri, 26 Jun 2020 15:33:17 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="NWi7+Xgb" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2738A2080C Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1joqLW-0006V7-Ty; Fri, 26 Jun 2020 15:32:54 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1joqLV-0006V2-ET for xen-devel@lists.xenproject.org; Fri, 26 Jun 2020 15:32:53 +0000 X-Inumbo-ID: 4b95307e-b7c2-11ea-bb8b-bc764e2007e4 Received: from us-smtp-delivery-1.mimecast.com (unknown [207.211.31.81]) by us1-rack-iad1.inumbo.com (Halon) with ESMTP id 4b95307e-b7c2-11ea-bb8b-bc764e2007e4; Fri, 26 Jun 2020 15:32:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593185570; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=RTWe4soL1srkDL8PEEfq928W6GWa5t1pS8aCmfU8LHE=; b=NWi7+XgbhSCSK/wUfpqjFdV1YJFwxlJVxR/Myy/rufNo6jwZ5OZNxhsUv4yrvVQH8JtLx4 alR3Jm0vQgOXdc98glkWdTOP6Kt0ma7joFXjZQcoH8SizrS481WnGA6huSziR/aGfNIxkN Y/z8ohnJKJXXSXjvxTOggDRu+gid3ng= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-321-pC9Pyyy7MDugmDxvhj-VYw-1; Fri, 26 Jun 2020 11:32:48 -0400 X-MC-Unique: pC9Pyyy7MDugmDxvhj-VYw-1 Received: by mail-wm1-f71.google.com with SMTP id v24so11736402wmh.3 for ; Fri, 26 Jun 2020 08:32:48 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=RTWe4soL1srkDL8PEEfq928W6GWa5t1pS8aCmfU8LHE=; b=sp98Xf8wl89+oimxBAtLhZ/SASjSJZBg92IrtaiL74U+WqZ+3fZ4CzwZiCP8BTVvfm YEUsSKAMfXlyVDovOtKjitRQrfLNYnDCBjO2qSg3EKG+vKzzGH1YY5B3LHIuom7REC5+ draqtlNTmbDXv4W61qyZTUggM8oDDXTPtETDS4YqvBERAVH3UgvG2FXsnkLSAKfihNt8 PeCu+rLADJgDLDq9qhDcnBj5OElqesreElm98MbVSI0zlaDRzFY2OUOFKEA253lgCIvq Tc5+4ljSSV8RWpVAqZuqel2xzW9i6of3yN7+5hq+IL5pheuCYGnqtJEBHDt2ry2miNKw qXMQ== X-Gm-Message-State: AOAM533w5xF6hQTBeXZBhsLTDVsJ60eigPUGzkCqsbAyoZZudi1Vhqyi EkjwOsdY3+UlxJrsoAVhxgLuU/yQxG8rCdF9cOKTUArXDAVzELG1j3jiTXDXc6Sstpo4aoAaKtC N2UHv42aOv/l/oNTeuJZN1fHbV1o= X-Received: by 2002:a5d:55cb:: with SMTP id i11mr4167955wrw.28.1593185566631; Fri, 26 Jun 2020 08:32:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzKcm6jtqvubhG72TQoDWqW1duiFh/JDhCCKL54qZ+AftyQ9QDCAEubqgx6Fkb+6w/6lcA4Aw== X-Received: by 2002:a5d:55cb:: with SMTP id i11mr4167932wrw.28.1593185566346; Fri, 26 Jun 2020 08:32:46 -0700 (PDT) Received: from redhat.com (bzq-79-182-31-92.red.bezeqint.net. [79.182.31.92]) by smtp.gmail.com with ESMTPSA id 65sm18427582wma.48.2020.06.26.08.32.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Jun 2020 08:32:45 -0700 (PDT) Date: Fri, 26 Jun 2020 11:32:41 -0400 From: "Michael S. Tsirkin" To: Stefano Stabellini Subject: Re: [PATCH] xen: introduce xen_vring_use_dma Message-ID: <20200626110629-mutt-send-email-mst@kernel.org> 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> MIME-Version: 1.0 In-Reply-To: X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: jgross@suse.com, Peng Fan , konrad.wilk@oracle.com, jasowang@redhat.com, x86@kernel.org, linux-kernel@vger.kernel.org, virtualization@lists.linux-foundation.org, iommu@lists.linux-foundation.org, linux-imx@nxp.com, xen-devel@lists.xenproject.org, boris.ostrovsky@oracle.com, linux-arm-kernel@lists.infradead.org Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" On Thu, Jun 25, 2020 at 10:31:27AM -0700, Stefano Stabellini wrote: > 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? I am saying it's a safe default. Clear VIRTIO_F_ACCESS_PLATFORM if you have some special needs e.g. you are very sure it's ok to bypass DMA ops, or you need to support a legacy guest (produced in the window between virtio 1 support in 2014 and support for VIRTIO_F_ACCESS_PLATFORM in 2016). > 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? I think it's an RPMesg bug, yes. > > > > > > 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. I could imagine some future Xen hosts setting a flag somewhere in the platform capability saying "no xen specific flag, rely on "VIRTIO_F_ACCESS_PLATFORM". Then you set that accordingly in QEMU. How about that? > > > 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