Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp958702pxp; Wed, 16 Mar 2022 22:39:27 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyjdIMY/doz2AlgGc9a3OZ/HG98nCXQvGl/+SYBElZMqfjFGs9tueFeRDkxwDLt+AEUhCh/ X-Received: by 2002:a63:6b83:0:b0:380:102:8779 with SMTP id g125-20020a636b83000000b0038001028779mr2470992pgc.42.1647495567608; Wed, 16 Mar 2022 22:39:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647495567; cv=none; d=google.com; s=arc-20160816; b=FO7w8zcy34kVsne8ItNP2ZzD6J33/BlfbcywkEa+vxRMJn6sekso87yEe3YTAkSGbM gi73Sc48kiinLW7xrib+9guGVfq3yzvTEKi8/SlyDkrk+1IfSTXhXZBGRwx0fcclpACt 9fgqKdMR4D7mzr7W2IFyeqMjqt+leL1Mhzxk6rJW7ZqRWJthIXSUcELNXZGb2qBxtH5A 2BETT2wmMobKTnAc+OXgmfs7o0xnmERs7P8+gtj6I42sWmCYKb8RAtkh9pAAc1sT2d+4 GRgJaf20lhrZzzUANOJG9gBdv9DcljF9Y74Y9NWwyeyL45o+ThvvEiTNXsEaYTSicpt/ 4BlA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=NeL+ZAdeZ8JoZGVA817K7yFz4gHXWOWH1FDiBb973ak=; b=HyKpM3KFdayDS7oj07/t+wn0415mEmdzyj8d1apTL9yM6yqDfjr2QMLzH28F+Wx84y iw4uh8Nm2isRxCq3f2KcYLCMHk7w28IrG3M123imiWIXt7UhXRJNypg09udZMdwhKB/I zEWwjqyh/LJctzlEHbLcAdZlzl2L3NLfsYMz4hKxuq0dhhAyOh8hIUJEX6hYUTB/RLkF c4GkpFQJuX6JU7ef5Bx+zAVOO9mAKER/yJzO94tsbBOvyM9aSmdwKvvOeTDEwncnpBKA SuY2g3XYKerBrdDBErIBb0NjehAFsMrpV1A/96o3esUdJaYSyYcqxNkuwzjEq2GTjqTa +pMA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=V+rSKskS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=collabora.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id l18-20020a17090a409200b001bf866c6bb9si6362227pjg.190.2022.03.16.22.39.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Mar 2022 22:39:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=V+rSKskS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=collabora.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id A8C8D139AEB; Wed, 16 Mar 2022 21:44:20 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350515AbiCPNxe (ORCPT + 99 others); Wed, 16 Mar 2022 09:53:34 -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 X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,NICE_REPLY_A,RDNS_NONE,SPF_HELO_NONE, T_SCC_BODY_TEXT_LINE,UNPARSEABLE_RELAY autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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.