From nobody Wed May 15 13:55:53 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1677252947; cv=none; d=zohomail.com; s=zohoarc; b=LkJZmHTC8hI+MduXKb48nVQh9RR3E19kmlYqf9noYBY9gS8Jjugpy6iCKzZR6JrWi78olOtr0tvnHS5iCS8VewnmwMjNiD/3OF6RtrJD76jVPOXFhVU0i9z2HYBewjDj3BziCgH52pmnDd7sTpjYA24svBijC9z5kEndvXf4sj4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1677252947; h=Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=VzbLUEUjtY0tsDWNS62Tcb+S81iHP1D44kGH0OHXbkA=; b=Sl7FtQMdvJB1C1ZSfXm6h0jfCAss87mx14eR91lFz1ai722s7XrilDXWLFIo0jzjG43NKSgF0R5demKXflgunuPuHXUaN0JJQa9at9fl4t1XIiT0KVQCc9vNXJes4H9u33GGoZzGpq/SE/acjsM3A63dO/SyhqNcVWPFRYaAKg8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1677252947867863.5965012145361; Fri, 24 Feb 2023 07:35:47 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.501210.772855 (Exim 4.92) (envelope-from ) id 1pVa6U-0008HX-GW; Fri, 24 Feb 2023 15:35:22 +0000 Received: by outflank-mailman (output) from mailman id 501210.772855; Fri, 24 Feb 2023 15:35:22 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pVa6U-0008HQ-Dv; Fri, 24 Feb 2023 15:35:22 +0000 Received: by outflank-mailman (input) for mailman id 501210; Fri, 24 Feb 2023 15:35:20 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pVa6S-0008HK-BT for xen-devel@lists.xenproject.org; Fri, 24 Feb 2023 15:35:20 +0000 Received: from mail-ed1-x535.google.com (mail-ed1-x535.google.com [2a00:1450:4864:20::535]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id d8031373-b458-11ed-88bb-e56d68cac8db; Fri, 24 Feb 2023 16:35:19 +0100 (CET) Received: by mail-ed1-x535.google.com with SMTP id ck15so57515502edb.0 for ; Fri, 24 Feb 2023 07:35:19 -0800 (PST) Received: from EPUAKYIW03DD.. ([91.123.150.38]) by smtp.gmail.com with ESMTPSA id kg19-20020a17090776f300b008be0b7242d5sm8441360ejc.90.2023.02.24.07.35.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Feb 2023 07:35:17 -0800 (PST) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: d8031373-b458-11ed-88bb-e56d68cac8db DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=VzbLUEUjtY0tsDWNS62Tcb+S81iHP1D44kGH0OHXbkA=; b=UUW2cNQxQ9wiI1y1uEIiov8/aAn6pQQMVXzfBkhJVbnD02igAWyzWePL5TL0KIpFXc f06QP9Z9KFOrAD5Ctv6w7WEt4EpGTRp7azcZPWKRgRcy7Rq6bww9dx6TUNU5NGO2rgjk yo4aNdOesMKZr3LRk9rjWzwFngPGaCK+rpUGcmZndXmJb/SCuTPWMP987JyoGPrq687s ZVdvsxSaXkI4Dq/rU97CmzGR6MHk9vwsst50gUNty8yu/Rf8o86l8jy2Z4iYWyKTLm2+ qmsbKn9RXvDBmUJKNNwq8NfnVSmnAykvHSw/wUNDR0l1tseozRwukyc+jIcN3OqCKJFh W4xw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=VzbLUEUjtY0tsDWNS62Tcb+S81iHP1D44kGH0OHXbkA=; b=gNwM13qojWkzyD+4jmmpniF3BH3CaKWpJHsmg8gPSZakKNUsSiyYSvelzipPBr3C98 Ha5JciJ8niw1r6hs/SFUEbJlswUBe7mI76IBWzqlY9PEP92xMyUilKyaNp1EOADuUQnK fTKAb+pQhzi5zWQqEpIlhPA7ettHO9RhvuJ3pQ9SrCoxxh/rDBAXkwD1OG1HnwfcIpVR uHxXcdqqO1gnBokT/NN0VumQKJNCWP0G7NcfcNIrMPIu89+49SuJJc0jTmmVfM7eXEjE 1W+OY97BgX5GzB8knPhWXqXLBkIId+3qhfJJFgbmIi0x8dj6dxry2/EhfEd6S1AW+ny4 f8HA== X-Gm-Message-State: AO0yUKWb6nwwiBKGC+S0CgBnyLb6Ua0RuDmBS+42GKfewmigC/pZEsxd Yro/JFfgmWTmA3jGFi6W6owmRfmb+3I= X-Google-Smtp-Source: AK7set9QwwaNgb3OunBObQ+DvB0YGMDXoLNPjUGf1qbnK8dvMDVSCNC8+t8Bu3sMBeMmTuUP+/sN9w== X-Received: by 2002:a17:907:1612:b0:8e4:86ed:7203 with SMTP id hb18-20020a170907161200b008e486ed7203mr144549ejc.11.1677252918233; Fri, 24 Feb 2023 07:35:18 -0800 (PST) From: Oleksandr Tyshchenko To: xen-devel@lists.xenproject.org, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, virtualization@lists.linux-foundation.org Cc: Oleksandr Tyshchenko , David Airlie , Gerd Hoffmann , Gurchetan Singh , Chia-I Wu , Daniel Vetter , Dmitry Osipenko , Juergen Gross , Stefano Stabellini Subject: [PATCH] drm/virtio: Pass correct device to dma_sync_sgtable_for_device() Date: Fri, 24 Feb 2023 17:34:50 +0200 Message-Id: <20230224153450.526222-1-olekstysh@gmail.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1677252948458100001 Content-Type: text/plain; charset="utf-8" From: Oleksandr Tyshchenko The "vdev->dev.parent" should be used instead of "vdev->dev" as a device for which to perform the DMA operation in both virtio_gpu_cmd_transfer_to_host_2d(3d). Because the virtio-gpu device "vdev->dev" doesn't really have DMA OPS assigned to it, but parent (virtio-pci or virtio-mmio) device "vdev->dev.parent" has. The more, the sgtable in question the code is trying to sync here was mapped for the parent device (by using its DMA OPS) previously at: virtio_gpu_object_shmem_init()->drm_gem_shmem_get_pages_sgt()-> dma_map_sgtable(), so should be synced here for the same parent device. Fixes: b5c9ed70d1a9 ("drm/virtio: Improve DMA API usage for shmem BOs") Signed-off-by: Oleksandr Tyshchenko Reviewed-by: Dmitry Osipenko --- This patch fixes the following issue when running on top of Xen with=20 CONFIG_XEN_VIRTIO=3Dy (patch was only tested in Xen environment (ARM64 gues= t) w/ and w/o using Xen grants for virtio): [ 0.830235] [drm] pci: virtio-gpu-pci detected at 0000:00:03.0 [ 0.832078] [drm] features: +virgl +edid -resource_blob -host_visible [ 0.832084] [drm] features: -context_init [ 0.837320] [drm] number of scanouts: 1 [ 0.837460] [drm] number of cap sets: 2 [ 0.904372] [drm] cap set 0: id 1, max-version 1, max-size 308 [ 0.905399] [drm] cap set 1: id 2, max-version 2, max-size 696 [ 0.907202] [drm] Initialized virtio_gpu 0.1.0 0 for 0000:00:03.0 on min= or 0 [ 0.927241] virtio-pci 0000:00:03.0: [drm] drm_plane_enable_fb_damage_cl= ips() not called [ 0.927279] Unable to handle kernel paging request at virtual address ff= ffffffc0053000 [ 0.927284] Mem abort info: [ 0.927286] ESR =3D 0x0000000096000144 [ 0.927289] EC =3D 0x25: DABT (current EL), IL =3D 32 bits [ 0.927293] SET =3D 0, FnV =3D 0 [ 0.927295] EA =3D 0, S1PTW =3D 0 [ 0.927298] FSC =3D 0x04: level 0 translation fault [ 0.927301] Data abort info: [ 0.927303] ISV =3D 0, ISS =3D 0x00000144 [ 0.927305] CM =3D 1, WnR =3D 1 [ 0.927308] swapper pgtable: 4k pages, 48-bit VAs, pgdp=3D000000004127f0= 00 [ 0.927312] [ffffffffc0053000] pgd=3D0000000000000000, p4d=3D00000000000= 00000 [ 0.927323] Internal error: Oops: 0000000096000144 [#1] PREEMPT SMP [ 0.927329] Modules linked in: [ 0.927336] CPU: 0 PID: 1 Comm: swapper/0 Tainted: G W 6= .2.0-rc4-yocto-standard #1 [ 0.927343] Hardware name: XENVM-4.18 (DT) [ 0.927346] pstate: 60000005 (nZCv daif -PAN -UAO -TCO -DIT -SSBS BTYPE= =3D--) [ 0.927352] pc : dcache_clean_poc+0x20/0x38 [ 0.927370] lr : arch_sync_dma_for_device+0x24/0x30 [ 0.927379] sp : ffff80000972b3e0 [ 0.927381] x29: ffff80000972b3e0 x28: ffff000001aa8a00 x27: 00000000000= 00000 [ 0.927389] x26: 0000000000000000 x25: ffff000002815010 x24: 00000000000= 00000 [ 0.927396] x23: ffff8000090f9078 x22: 0000000000000001 x21: 00000000000= 00002 [ 0.927403] x20: ffff000002b6b580 x19: 8000000000053000 x18: fffffffffff= fffff [ 0.927410] x17: 0000000000000000 x16: 0000000000000000 x15: ffff8000096= 3b94e [ 0.927416] x14: 0000000000000001 x13: ffff80000963b93b x12: 64615f616d6= 45f67 [ 0.927423] x11: ffff800009513110 x10: 000000000000000a x9 : ffff8000097= 2b360 [ 0.927430] x8 : ffff8000095130c8 x7 : ffff80000972b150 x6 : 00000000000= 0000c [ 0.927436] x5 : 0000000000000000 x4 : 0000000000000000 x3 : 00000000000= 0003f [ 0.927443] x2 : 0000000000000040 x1 : ffffffffc0067000 x0 : ffffffffc00= 53000 [ 0.927450] Call trace: [ 0.927452] dcache_clean_poc+0x20/0x38 [ 0.927459] dma_direct_sync_sg_for_device+0x124/0x130 [ 0.927466] dma_sync_sg_for_device+0x64/0xd0 [ 0.927475] virtio_gpu_cmd_transfer_to_host_2d+0x10c/0x110 [ 0.927483] virtio_gpu_primary_plane_update+0x340/0x3d0 [ 0.927490] drm_atomic_helper_commit_planes+0xe8/0x20c [ 0.927497] drm_atomic_helper_commit_tail+0x54/0xa0 [ 0.927503] commit_tail+0x160/0x190 [ 0.927507] drm_atomic_helper_commit+0x16c/0x180 [ 0.927513] drm_atomic_commit+0xa8/0xe0 [ 0.927521] drm_client_modeset_commit_atomic+0x200/0x260 [ 0.927529] drm_client_modeset_commit_locked+0x5c/0x1a0 [ 0.927536] drm_client_modeset_commit+0x30/0x60 [ 0.927540] drm_fb_helper_set_par+0xc8/0x120 [ 0.927548] fbcon_init+0x3b8/0x510 [ 0.927557] visual_init+0xb4/0x104 [ 0.927565] do_bind_con_driver.isra.0+0x1c4/0x394 [ 0.927572] do_take_over_console+0x144/0x1fc [ 0.927577] do_fbcon_takeover+0x6c/0xe4 [ 0.927583] fbcon_fb_registered+0x1e4/0x1f0 [ 0.927588] register_framebuffer+0x214/0x310 [ 0.927592] __drm_fb_helper_initial_config_and_unlock+0x33c/0x540 [ 0.927599] drm_fb_helper_initial_config+0x4c/0x60 [ 0.927604] drm_fbdev_client_hotplug+0xc4/0x150 [ 0.927609] drm_fbdev_generic_setup+0x90/0x154 [ 0.927614] virtio_gpu_probe+0xc8/0x16c [ 0.927621] virtio_dev_probe+0x19c/0x240 [ 0.927629] really_probe+0xbc/0x2dc [ 0.927637] __driver_probe_device+0x78/0xe0 [ 0.927641] driver_probe_device+0xd8/0x160 [ 0.927645] __driver_attach+0x94/0x19c [ 0.927649] bus_for_each_dev+0x70/0xd0 [ 0.927656] driver_attach+0x24/0x30 [ 0.927660] bus_add_driver+0x154/0x20c [ 0.927664] driver_register+0x78/0x130 [ 0.927670] register_virtio_driver+0x24/0x3c [ 0.927675] virtio_gpu_driver_init+0x18/0x24 [ 0.927684] do_one_initcall+0x50/0x1d0 [ 0.927691] kernel_init_freeable+0x210/0x27c [ 0.927699] kernel_init+0x24/0x12c [ 0.927707] ret_from_fork+0x10/0x20 [ 0.927716] Code: d2800082 9ac32042 d1000443 8a230000 (d50b7a20) [ 0.927721] ---[ end trace 0000000000000000 ]--- [ 0.927728] Kernel panic - not syncing: Attempted to kill init! exitcode= =3D0x0000000b [ 0.927732] SMP: stopping secondary CPUs [ 0.927791] Kernel Offset: disabled [ 0.927794] CPU features: 0x80000,41058100,0000421b [ 0.927799] Memory Limit: none [ 1.015063] ---[ end Kernel panic - not syncing: Attempted to kill init!= exitcode=3D0x0000000b ]--- --- --- drivers/gpu/drm/virtio/virtgpu_vq.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/virtio/virtgpu_vq.c b/drivers/gpu/drm/virtio/v= irtgpu_vq.c index a04a9b20896d..1778a2081fd6 100644 --- a/drivers/gpu/drm/virtio/virtgpu_vq.c +++ b/drivers/gpu/drm/virtio/virtgpu_vq.c @@ -604,7 +604,7 @@ void virtio_gpu_cmd_transfer_to_host_2d(struct virtio_g= pu_device *vgdev, bool use_dma_api =3D !virtio_has_dma_quirk(vgdev->vdev); =20 if (virtio_gpu_is_shmem(bo) && use_dma_api) - dma_sync_sgtable_for_device(&vgdev->vdev->dev, + dma_sync_sgtable_for_device(vgdev->vdev->dev.parent, bo->base.sgt, DMA_TO_DEVICE); =20 cmd_p =3D virtio_gpu_alloc_cmd(vgdev, &vbuf, sizeof(*cmd_p)); @@ -1026,7 +1026,7 @@ void virtio_gpu_cmd_transfer_to_host_3d(struct virtio= _gpu_device *vgdev, bool use_dma_api =3D !virtio_has_dma_quirk(vgdev->vdev); =20 if (virtio_gpu_is_shmem(bo) && use_dma_api) - dma_sync_sgtable_for_device(&vgdev->vdev->dev, + dma_sync_sgtable_for_device(vgdev->vdev->dev.parent, bo->base.sgt, DMA_TO_DEVICE); =20 cmd_p =3D virtio_gpu_alloc_cmd(vgdev, &vbuf, sizeof(*cmd_p)); --=20 2.34.1