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 Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 77042C433F5 for ; Wed, 16 Mar 2022 13:52:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1353445AbiCPNxf (ORCPT ); Wed, 16 Mar 2022 09:53:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39950 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233718AbiCPNxc (ORCPT ); Wed, 16 Mar 2022 09:53:32 -0400 Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e3e3]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5FC6364BE1 for ; Wed, 16 Mar 2022 06:52:18 -0700 (PDT) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: dmitry.osipenko) with ESMTPSA id C1E881F44628 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1647438737; bh=FqvajMGnxRjtpeh5DO1PC1ggOMUMBHDf7570Spd3GV0=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=V+rSKskSoX2RTbQWfBTESQ8eTq8joYpfqPvvw3zETS2u/Mm6WrV6YTF6b1wer64p7 VY1qY7+ww2l6tgnJWoGPN9umMFhRMjfXvxPeXLcLXqfPiFWqWO+PU5oMSCsf6zyYeH pX/Ti8PiKa6pv5HD5iuvJ4HmxOIy05LikmRqJjtdwxxGJpOgPZ+57jxZhmB9jYBJ8I fHLRakOJkqWtFx/SAD59BDDhdVDR9ww3eGjByonf8eQjyOR36ti1Ijuj+QKAgef8JQ LU5ulPaoeapDLy/MTrJz+k2hny+szY/aw0VEYLjVdrqSUsbXrjL8FbQNfzn1EuWiBE h+Nhfsa6BP9Ug== Message-ID: <13f77cd8-ed57-3593-ab21-dafce91ee85e@collabora.com> Date: Wed, 16 Mar 2022 16:52:12 +0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.6.2 Subject: Re: [PATCH v2 4/8] drm/virtio: Improve DMA API usage for shmem BOs Content-Language: en-US To: Robin Murphy , David Airlie , Gerd Hoffmann , Gurchetan Singh , Chia-I Wu , Daniel Vetter , Daniel Almeida , Gert Wollny , Tomeu Vizoso , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , Rob Herring , Steven Price , Alyssa Rosenzweig Cc: linux-kernel@vger.kernel.org, virtualization@lists.linux-foundation.org, Gustavo Padovan , dri-devel@lists.freedesktop.org, Dmitry Osipenko References: <20220314224253.236359-1-dmitry.osipenko@collabora.com> <20220314224253.236359-5-dmitry.osipenko@collabora.com> From: Dmitry Osipenko In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 3/16/22 15:41, Robin Murphy wrote: > On 2022-03-14 22:42, Dmitry Osipenko wrote: >> DRM API requires the DRM's driver to be backed with the device that can >> be used for generic DMA operations. The VirtIO-GPU device can't perform >> DMA operations if it uses PCI transport because PCI device driver creates >> a virtual VirtIO-GPU device that isn't associated with the PCI. Use PCI's >> GPU device for the DRM's device instead of the VirtIO-GPU device and drop >> DMA-related hacks from the VirtIO-GPU driver. >> >> Signed-off-by: Dmitry Osipenko >> --- >>   drivers/gpu/drm/virtio/virtgpu_drv.c    | 22 +++++++--- >>   drivers/gpu/drm/virtio/virtgpu_drv.h    |  5 +-- >>   drivers/gpu/drm/virtio/virtgpu_kms.c    |  7 ++-- >>   drivers/gpu/drm/virtio/virtgpu_object.c | 56 +++++-------------------- >>   drivers/gpu/drm/virtio/virtgpu_vq.c     | 13 +++--- >>   5 files changed, 37 insertions(+), 66 deletions(-) >> >> diff --git a/drivers/gpu/drm/virtio/virtgpu_drv.c >> b/drivers/gpu/drm/virtio/virtgpu_drv.c >> index 5f25a8d15464..8449dad3e65c 100644 >> --- a/drivers/gpu/drm/virtio/virtgpu_drv.c >> +++ b/drivers/gpu/drm/virtio/virtgpu_drv.c >> @@ -46,9 +46,9 @@ static int virtio_gpu_modeset = -1; >>   MODULE_PARM_DESC(modeset, "Disable/Enable modesetting"); >>   module_param_named(modeset, virtio_gpu_modeset, int, 0400); >>   -static int virtio_gpu_pci_quirk(struct drm_device *dev, struct >> virtio_device *vdev) >> +static int virtio_gpu_pci_quirk(struct drm_device *dev) >>   { >> -    struct pci_dev *pdev = to_pci_dev(vdev->dev.parent); >> +    struct pci_dev *pdev = to_pci_dev(dev->dev); >>       const char *pname = dev_name(&pdev->dev); >>       bool vga = (pdev->class >> 8) == PCI_CLASS_DISPLAY_VGA; >>       char unique[20]; >> @@ -101,6 +101,7 @@ static int virtio_gpu_pci_quirk(struct drm_device >> *dev, struct virtio_device *vd >>   static int virtio_gpu_probe(struct virtio_device *vdev) >>   { >>       struct drm_device *dev; >> +    struct device *dma_dev; >>       int ret; >>         if (drm_firmware_drivers_only() && virtio_gpu_modeset == -1) >> @@ -109,18 +110,29 @@ static int virtio_gpu_probe(struct virtio_device >> *vdev) >>       if (virtio_gpu_modeset == 0) >>           return -EINVAL; >>   -    dev = drm_dev_alloc(&driver, &vdev->dev); >> +    /* >> +     * If GPU's parent is a PCI device, then we will use this PCI device >> +     * for the DRM's driver device because GPU won't have PCI's IOMMU >> DMA >> +     * ops in this case since GPU device is sitting on a separate >> (from PCI) >> +     * virtio-bus. >> +     */ >> +    if (!strcmp(vdev->dev.parent->bus->name, "pci")) > > Nit: dev_is_pci() ? Yes, thank you. > However, what about other VirtIO transports? Wouldn't virtio-mmio with > F_ACCESS_PLATFORM be in a similar situation? I couldn't find anyone using virtio-mmio for the GPU, both Qemu and crosvm support only PCI transport for GPU. But I'm now looking at virtio_mmio_probe() and see that virtio-mmio devices actually should be in the exactly same position as PCI devices. So you should be right and we need to use vdev->dev.parent for the DRM device universally. I'll improve it in the v3, thank you again.