Received: by 2002:a05:7412:e794:b0:fa:551:50a7 with SMTP id o20csp888033rdd; Wed, 10 Jan 2024 02:33:42 -0800 (PST) X-Google-Smtp-Source: AGHT+IG9AWI5GlpaE0LIsMOpowHJlMz5WZ8LLTa0g52xhWKvaW9o9n2e5bkskqsz+VPRFSpMJ7yh X-Received: by 2002:a17:902:7ec2:b0:1d4:669:3454 with SMTP id p2-20020a1709027ec200b001d406693454mr996040plb.69.1704882821991; Wed, 10 Jan 2024 02:33:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704882821; cv=none; d=google.com; s=arc-20160816; b=gUDTcEbdXItcIbegPrCxH7LjYAUxhtT3FVYzYDnlOaE1ce6QefWzn/SP90nUD+syib wmNYC7FbjdG9gZJqP5tKYNZ8Glw6UKP6gO+T347iWBr0TqQL6iYCX5NDqROxsQeLQ8y4 6ns4G4uXqvjHU1t5QHett38MnEEhaXi91fwrX6rN/U+q81XfWv+j+Znt7Ohya2rZ7YXh LKU2mcJcWktf7+NiZesVpSNlOMGaFguoMR3boRuyhfrVmSKSn/0nwr/eaKhYyDH0zGkX KAD2eukspgYiBeN+149OmPKEmPOJr9VRGEjy4uVl86vpYi/kPcGIqyUFQcfcxzSkvSpu jbEg== ARC-Message-Signature: i=1; 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=lJgNZQDQ+DIMBe4Tt1iYyaM+/r15yfvqro7593b4SXo=; fh=FgPqpU/8CWtFKPDDS97S5WMvP8/H5iwRPp/G+yYOqcI=; b=NCN98ckQyswM0zsr9D/+xCWngzNLnx4hUQNRqYnOiUYbuLMHhg3QzF7eMmkf7o5sFu +aNMg32cTvUrgACPjFxm8zeLgw+CahEuMwo/1ERLnX+2+4S2c1Z2Dkk8ZpHd4qeOMp9f 6+4DqlkxrxfYGQ+9u7eR7EJdbilhy9R59QYYQsgn3UN+Czg5CZk9vzpDX7bvqSBqV+oH z7X4fyiqxe1S+OjaWKA2T3cLrjw/4RdB0MbPLlJmWYIQLuCL6n8aXA6YrMcdvevK/qea Vxmuy/ZIpXmYl8rXTkHQMoIiEPs+/HX6x8azCVAjrj23hE6FLr77hx8qS6gyGFPeaa9e HHnQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ffwll.ch header.s=google header.b="TH5/C6o9"; spf=pass (google.com: domain of linux-kernel+bounces-21985-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-21985-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id j10-20020a170902da8a00b001d50870e26bsi3411660plx.437.2024.01.10.02.33.41 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Jan 2024 02:33:41 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-21985-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@ffwll.ch header.s=google header.b="TH5/C6o9"; spf=pass (google.com: domain of linux-kernel+bounces-21985-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-21985-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 2DBDFB275E5 for ; Wed, 10 Jan 2024 10:26:51 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 63CA3495DA; Wed, 10 Jan 2024 10:21:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ffwll.ch header.i=@ffwll.ch header.b="TH5/C6o9" Received: from mail-ej1-f53.google.com (mail-ej1-f53.google.com [209.85.218.53]) (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 8BC4B495D1 for ; Wed, 10 Jan 2024 10:21:30 +0000 (UTC) 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-ej1-f53.google.com with SMTP id a640c23a62f3a-a2b9e2c9858so22051466b.1 for ; Wed, 10 Jan 2024 02:21:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ffwll.ch; s=google; t=1704882088; x=1705486888; 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=lJgNZQDQ+DIMBe4Tt1iYyaM+/r15yfvqro7593b4SXo=; b=TH5/C6o9OXbpoXfn0ER9VeSL5UDL/0WA3TsCdAOLCZqEfQt2lggdq6sNx/QgDcCWos aYgQWNPA09Nh1v2fWNvfs864bKgNaUFkD6ShARCvo3RZXEDe5Nfjk0SYy+J8sG6NEnMa LeUaRdVB2iuZ1zneF5adIJ+4QY4Vs7f9CBCWw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704882088; x=1705486888; 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=lJgNZQDQ+DIMBe4Tt1iYyaM+/r15yfvqro7593b4SXo=; b=r0UgxZAOsQ5iopoDQJTa057GYEhUfNmKKwMCX2Jop6U3Z67pOd+f4O6jLBAyMqJxfl BlzEDXI/MBlHAl/sGvEDshqfClAuIx4SN0qoPMFYP2vvtvwFsPjytUwpoX6sBRN+ZH5C M5A6b4+mitWVWmfL0Zs90VQ/c2da1j3+ED7IgG41imqo2l46rVTSsYmETZELzr5H7pNo yMu0A3bLSPqgT0K6vVWsji/kepcqLgsMw4hJptohu+cVkELvyMs7hQ3ZK/ICxgZUfYiP FUjQTPPTsFHuZi2h0SMSU8dw7ovGqM5WfvaCCx+Bl7B9V6FmAlZTBnfOtnrwmQtU68Bx XvNg== X-Gm-Message-State: AOJu0YyhO9yIJrtOY5IvMxz/v8ZXCLG0ylnZ8QvHqpABCYmYMET7she/ PG9y2S+DQTstbO1bdID+0qnz6ePiNzizAQ== X-Received: by 2002:a17:906:5381:b0:a27:8258:8f6b with SMTP id g1-20020a170906538100b00a2782588f6bmr1051056ejo.5.1704882088567; Wed, 10 Jan 2024 02:21:28 -0800 (PST) Received: from phenom.ffwll.local ([2a02:168:57f4:0:efd0:b9e5:5ae6:c2fa]) by smtp.gmail.com with ESMTPSA id p17-20020a170906785100b00a2b09bfb648sm1948838ejm.5.2024.01.10.02.21.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Jan 2024 02:21:28 -0800 (PST) Date: Wed, 10 Jan 2024 11:21:26 +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 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: <20240110095627.227454-1-julia.zhang@amd.com> <20240110095627.227454-2-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: <20240110095627.227454-2-julia.zhang@amd.com> X-Operating-System: Linux phenom 6.5.0-4-amd64 On Wed, Jan 10, 2024 at 05:56:28PM +0800, Julia Zhang wrote: > drm_gem_map_attach() requires drm_gem_object_funcs.get_sg_table to be > implemented, or else return ENOSYS. Virtio has no get_sg_table > implemented for vram object. To fix this, add a new device_attach to > call drm_gem_map_attach() for shmem object and return 0 for vram object > instead of calling drm_gem_map_attach for both of these two kinds of > object. > > Signed-off-by: Julia Zhang > --- > drivers/gpu/drm/virtio/virtgpu_prime.c | 14 +++++++++++++- > 1 file changed, 13 insertions(+), 1 deletion(-) > > diff --git a/drivers/gpu/drm/virtio/virtgpu_prime.c b/drivers/gpu/drm/virtio/virtgpu_prime.c > index 44425f20d91a..f0b0ff6f3813 100644 > --- a/drivers/gpu/drm/virtio/virtgpu_prime.c > +++ b/drivers/gpu/drm/virtio/virtgpu_prime.c > @@ -71,6 +71,18 @@ static void virtgpu_gem_unmap_dma_buf(struct dma_buf_attachment *attach, > drm_gem_unmap_dma_buf(attach, sgt, dir); > } > > +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); > + > + if (virtio_gpu_is_vram(bo)) > + return 0; You need to reject attach here because these vram buffer objects cannot be used by any other driver. In that case dma_buf_attach _must_ fail, not silently succeed. Because if it silently succeeds then the subsequent dma_buf_map_attachment will blow up because you don't have the ->get_sg_table hook implemented. Per the documentation the error code for this case must be -EBUSY, see the section for the attach hook here: https://dri.freedesktop.org/docs/drm/driver-api/dma-buf.html#c.dma_buf_ops Since you're looking into this area, please make sure there's not other similar mistake in virtio code. Also can you please make a kerneldoc patch for struct virtio_dma_buf_ops to improve the documentation there? I think it would be good to move those to the inline style and then at least put a kernel-doc hyperlink to struct dma_buf_ops.attach and mention that attach must fail for non-shareable buffers. In general the virtio_dma_buf kerneldoc seems to be on the "too minimal, explains nothing" side of things :-/ Cheers, Sima > + > + return drm_gem_map_attach(dma_buf, attach); > +} > + > static const struct virtio_dma_buf_ops virtgpu_dmabuf_ops = { > .ops = { > .cache_sgt_mapping = true, > @@ -83,7 +95,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