Received: by 2002:a05:7412:d1aa:b0:fc:a2b0:25d7 with SMTP id ba42csp973419rdb; Tue, 30 Jan 2024 04:31:15 -0800 (PST) X-Google-Smtp-Source: AGHT+IHWBcKXpRPl1ED4P09qoz7csya/uFoeHIG2Jhhu/wA4Bbljz3weClZvhbvgal/Gf4osJvO1 X-Received: by 2002:a17:907:10db:b0:a31:7dc1:c7c1 with SMTP id rv27-20020a17090710db00b00a317dc1c7c1mr6068095ejb.65.1706617875359; Tue, 30 Jan 2024 04:31:15 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706617875; cv=pass; d=google.com; s=arc-20160816; b=OkkVZtj+uToKnnOC0AlLH38H10naucxTUl2nUosbRNxXooMYYMf1RfDRqCVleNLLHv k3BHIt8kwB2oXvEIfE7oPhbHJSRieJlh8wYwgnp5naXHBYnlzIPYQFMYpHLs4KeOKApm p4GYcT/HOSmRHQY2k/s3GOrMYOh+V8nLobzsOZJp4rwdU61U0pWzZ5eyjKtFhXRZxwES F4bpidRn23pqbO846VK4h10idSSVFR5IvV8O0H1uJdWrSxBNEikK7z152/LZ/INkosuW +J8Fyy/i0c465cx60sHrgWU/KonjC0VqANHq47HH7ucFk1dPhWwq2BavrcK6VEAKjC50 VW3Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:mail-followup-to :message-id:subject:cc:to:from:date:dkim-signature; bh=+7bGttRPgttjMO74kPRnHYy9jYBfJV/qrJlhkxWu5S4=; fh=FgPqpU/8CWtFKPDDS97S5WMvP8/H5iwRPp/G+yYOqcI=; b=PAy78IPomrEqpAN1i9myoQYXnSJTedb+dvYc/O7DkRPvHbIe5kgwwk1GXeMQwmUeEg wRzFKOPqwojRPtWJ3TYt3Al9bK/IZjaaeMylybKy/jBx9SLo7gSmrZ1x5AjipU9YoOby K6S+sp30OVaRJfCVw7Em756D2lT9WY9Z1M2cNBEpEAT8kq+/YjkxJMV8vTMdIm8sKbib ZxuDTNAIVoSIzwocIM6Ll3VTN55JTyfgffSj0/TMpdVFJA/HHHX4pNyesj6igQsPEvYi PYAbj5wiO7SiRhShJnSsZmehBPQ1bLeKeF3jfQchIoa77v8Nh6t8+i/vrzNEw8lK5ItJ zHtA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@ffwll.ch header.s=google header.b=IxKtsgKN; arc=pass (i=1 dkim=pass dkdomain=ffwll.ch); spf=pass (google.com: domain of linux-kernel+bounces-44464-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-44464-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id o14-20020a17090637ce00b00a35a1ff1375si2154751ejc.790.2024.01.30.04.31.15 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 04:31:15 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-44464-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@ffwll.ch header.s=google header.b=IxKtsgKN; arc=pass (i=1 dkim=pass dkdomain=ffwll.ch); spf=pass (google.com: domain of linux-kernel+bounces-44464-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-44464-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id D4F1E1F25EFA for ; Tue, 30 Jan 2024 11:11:27 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5440967744; Tue, 30 Jan 2024 11:10:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ffwll.ch header.i=@ffwll.ch header.b="IxKtsgKN" Received: from mail-ed1-f42.google.com (mail-ed1-f42.google.com [209.85.208.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0B780664D9 for ; Tue, 30 Jan 2024 11:10:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.42 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706613038; cv=none; b=PqwsRwks23PucALWHTAxXixFe/b4oNRJASIXyA5AVFnOu4FPTfysVjcCHQWf2wifDoGPgFIAAJ34GtzAtftGHS/fL2eBjrF/oJniaCyRLkYlqsL3HLb4w5717DGQhYw3wy2tXB8U5xC+VqYepsqaRUDE50NHCSaf133MJMug0XM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706613038; c=relaxed/simple; bh=ScGBYNpHKYkEISElgUEgqulovKJQ0P6q1dAasqJZO4M=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=iNXamQiWIl4ZofS5HPIuYne89peX4wFiNQcYooMYe0PAmnRRw2k1morD+fdDG8FaL4H62VmOUjaYKVtYD2vZ5vxcGTIwSfHqZhspLhmZv5mq2tAKgtwl41m1bIgNdU4SffADK2tSl8m5Qy+nIfOcLckawY1yp17BfAlDPyBi7dA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ffwll.ch; spf=none smtp.mailfrom=ffwll.ch; dkim=pass (1024-bit key) header.d=ffwll.ch header.i=@ffwll.ch header.b=IxKtsgKN; arc=none smtp.client-ip=209.85.208.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ffwll.ch Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=ffwll.ch Received: by mail-ed1-f42.google.com with SMTP id 4fb4d7f45d1cf-55f4b824c92so90249a12.1 for ; Tue, 30 Jan 2024 03:10:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ffwll.ch; s=google; t=1706613034; x=1707217834; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references :mail-followup-to:message-id:subject:cc:to:from:date:from:to:cc :subject:date:message-id:reply-to; bh=+7bGttRPgttjMO74kPRnHYy9jYBfJV/qrJlhkxWu5S4=; b=IxKtsgKNunf9cuceUM3vk23/3sVOBkwyCvrM2xIS889TT3YeTn1R/O71KbVdAt+Kz9 KQPS3Z5U8qm9YdH6KleZzSkTWlyN91v1kzXUQ98yjD9Iy/vVkujqNbBkCGUjPmOsfnnX dfBQAi/8yoWY4vak1lLs8L+VszFJ9X7HLTHTg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706613034; x=1707217834; h=in-reply-to:content-disposition:mime-version:references :mail-followup-to:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=+7bGttRPgttjMO74kPRnHYy9jYBfJV/qrJlhkxWu5S4=; b=BisNJYHI8qEB3mSivSMTu+8YQ1Rvuja5+gPlLFxJUx8xECj8Wjy2mpQl3gUS4KfObf 7olgKIzPelqIpDzFWOsDMpyYXp8+14hPFJVFXH6gEmlwe9tLYfK0oUXUusZ6fwgSAcY2 ZPiwOPOdRljUTx5roZm4Dx7QN4bGXW9FfJge+VHAZErA8yeG1ee0h7dPjns1rJ6HkzdD noFt90vx82GTGJUS/GuEo5Wrdgl02FvJuDt7PdI4/NvZRzsjERb3D7LGgCmeBWGJA08P BdPTsqOS/nvcZwDd1Ibdi9NwzIXvdS47wg6eHBNT6VLudaFT+y+zYsCev2+UaNwAlEnH /GBQ== X-Gm-Message-State: AOJu0YzT9Xvt1zhwSPiMrh6emjfb7dgXOmgioxyO6qr2NS9RcOitNjsE dvV1Tll4VLHOsQ+z+yJf8nipJcvg09B16u1RalA3lFKUOkcWErCLbNqaze3vef4= X-Received: by 2002:a17:906:6d01:b0:a35:561d:cf5a with SMTP id m1-20020a1709066d0100b00a35561dcf5amr5957342ejr.6.1706613034072; Tue, 30 Jan 2024 03:10:34 -0800 (PST) Received: from phenom.ffwll.local ([2a02:168:57f4:0:efd0:b9e5:5ae6:c2fa]) by smtp.gmail.com with ESMTPSA id t13-20020a170906064d00b00a316d360ac3sm4977863ejb.8.2024.01.30.03.10.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 03:10:33 -0800 (PST) Date: Tue, 30 Jan 2024 12:10:31 +0100 From: Daniel Vetter To: Julia Zhang Cc: Gurchetan Singh , Chia-I Wu , David Airlie , Gerd Hoffmann , linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, amd-gfx@lists.freedesktop.org, virtualization@lists.linux-foundation.org, Alex Deucher , Christian =?iso-8859-1?Q?K=F6nig?= , Daniel Vetter , David Airlie , Erik Faye-Lund , Marek =?utf-8?B?T2zFocOhaw==?= , Pierre-Eric Pelloux-Prayer , Honglei Huang , Chen Jiqian , Huang Rui Subject: Re: [PATCH v2 1/1] drm/virtio: Implement device_attach Message-ID: Mail-Followup-To: Julia Zhang , Gurchetan Singh , Chia-I Wu , David Airlie , Gerd Hoffmann , linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, amd-gfx@lists.freedesktop.org, virtualization@lists.linux-foundation.org, Alex Deucher , Christian =?iso-8859-1?Q?K=F6nig?= , David Airlie , Erik Faye-Lund , Marek =?utf-8?B?T2zFocOhaw==?= , Pierre-Eric Pelloux-Prayer , Honglei Huang , Chen Jiqian , Huang Rui References: <20240129103118.3258781-1-julia.zhang@amd.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240129103118.3258781-1-julia.zhang@amd.com> X-Operating-System: Linux phenom 6.6.11-amd64 On Mon, Jan 29, 2024 at 06:31:19PM +0800, Julia Zhang wrote: > As vram objects don't have backing pages and thus can't implement > drm_gem_object_funcs.get_sg_table callback. This removes drm dma-buf > callbacks in virtgpu_gem_map_dma_buf()/virtgpu_gem_unmap_dma_buf() > and implement virtgpu specific map/unmap/attach callbacks to support > both of shmem objects and vram objects. > > Signed-off-by: Julia Zhang > --- > drivers/gpu/drm/virtio/virtgpu_prime.c | 40 +++++++++++++++++++++++--- > 1 file changed, 36 insertions(+), 4 deletions(-) > > diff --git a/drivers/gpu/drm/virtio/virtgpu_prime.c b/drivers/gpu/drm/virtio/virtgpu_prime.c > index 44425f20d91a..b490a5343b06 100644 > --- a/drivers/gpu/drm/virtio/virtgpu_prime.c > +++ b/drivers/gpu/drm/virtio/virtgpu_prime.c > @@ -49,11 +49,26 @@ virtgpu_gem_map_dma_buf(struct dma_buf_attachment *attach, > { > struct drm_gem_object *obj = attach->dmabuf->priv; > struct virtio_gpu_object *bo = gem_to_virtio_gpu_obj(obj); > + struct sg_table *sgt; > + int ret; > > if (virtio_gpu_is_vram(bo)) > return virtio_gpu_vram_map_dma_buf(bo, attach->dev, dir); > > - return drm_gem_map_dma_buf(attach, dir); > + sgt = drm_prime_pages_to_sg(obj->dev, > + to_drm_gem_shmem_obj(obj)->pages, > + obj->size >> PAGE_SHIFT); > + if (IS_ERR(sgt)) > + return sgt; > + > + ret = dma_map_sgtable(attach->dev, sgt, dir, DMA_ATTR_SKIP_CPU_SYNC); > + if (ret) { > + sg_free_table(sgt); > + kfree(sgt); > + return ERR_PTR(ret); > + } > + > + return sgt; > } > > static void virtgpu_gem_unmap_dma_buf(struct dma_buf_attachment *attach, > @@ -63,12 +78,29 @@ static void virtgpu_gem_unmap_dma_buf(struct dma_buf_attachment *attach, > struct drm_gem_object *obj = attach->dmabuf->priv; > struct virtio_gpu_object *bo = gem_to_virtio_gpu_obj(obj); > > + if (!sgt) > + return; > + > if (virtio_gpu_is_vram(bo)) { > virtio_gpu_vram_unmap_dma_buf(attach->dev, sgt, dir); > - return; > + } else { > + dma_unmap_sgtable(attach->dev, sgt, dir, DMA_ATTR_SKIP_CPU_SYNC); > + sg_free_table(sgt); > + kfree(sgt); > } > +} > + > +static int virtgpu_gem_device_attach(struct dma_buf *dma_buf, > + struct dma_buf_attachment *attach) > +{ > + struct drm_gem_object *obj = attach->dmabuf->priv; > + struct virtio_gpu_object *bo = gem_to_virtio_gpu_obj(obj); > + int ret = 0; > + > + if (!virtio_gpu_is_vram(bo) && obj->funcs->pin) > + ret = obj->funcs->pin(obj); > > - drm_gem_unmap_dma_buf(attach, sgt, dir); > + return ret; This doesn't look like what I've expected. There should be no need to change the map/unmap functions, especially not for the usual gem bo case. We should definitely keep using the exact same code for that. Instead all I expected is roughly virtgpu_gem_device_attach() { if (virtio_gpu_is_vram(bo)) { if (can_access_virtio_vram_directly(attach->dev) return 0; else return -EBUSY; } else { return drm_gem_map_attach(); } } Note that I think can_access_virtio_vram_directly() needs to be implemented first. I'm not even sure it's possible, might be that all the importers need to set the attachment->peer2peer flag. Which is why this thing exists really. But that's a pile more work to do. Frankly the more I look at the original patch that added vram export support the more this just looks like a "pls revert, this is just too broken". We should definitely not open-code any functions for the gem_bo export case, which your patch seems to do? Or maybe I'm just extremely confused. -Sima > > static const struct virtio_dma_buf_ops virtgpu_dmabuf_ops = { > @@ -83,7 +115,7 @@ static const struct virtio_dma_buf_ops virtgpu_dmabuf_ops = { > .vmap = drm_gem_dmabuf_vmap, > .vunmap = drm_gem_dmabuf_vunmap, > }, > - .device_attach = drm_gem_map_attach, > + .device_attach = virtgpu_gem_device_attach, > .get_uuid = virtgpu_virtio_get_uuid, > }; > > -- > 2.34.1 > -- Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch