Received: by 2002:a05:7412:e794:b0:fa:551:50a7 with SMTP id o20csp898673rdd; Wed, 10 Jan 2024 03:01:03 -0800 (PST) X-Google-Smtp-Source: AGHT+IFGuTpWu3tDGvctsoiLau4yruteBWbw4PEvmgpBobd/onJxYWDeJ1itISb/Vr/LsE6AxzFF X-Received: by 2002:a05:6870:63a5:b0:205:fa87:35f6 with SMTP id t37-20020a05687063a500b00205fa8735f6mr502553oap.102.1704884463155; Wed, 10 Jan 2024 03:01:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704884463; cv=none; d=google.com; s=arc-20160816; b=COgwvfx/8aKWPy/8550f9/TWKVf2fzsIX+jy+8uiFyeBBjVxhDCTq2icMHiPRr/Hl2 /VfzpFvaIet0eXfZ65ry9hPkMp37n1EgM7q02ELBUY0sxUdGHoIMy5hdcXHR+v0CGY7x FxRGtmDBrUMRs4P2uhmvrt1BtcvzhHDNLb4FxW8MYPMYXNNbMDubjxu7J0E8zf7ZH/GZ pmsaNX9Sriw10sxKw9n81cL9ybBz8+Mji3biaLSwV2kEC2ykm6WpbRTqSubDM68/OaaJ bv1Ski0u3bgDZxfEhknrkzprCUGmdFhItDT7Az2nWENyXN8QBp13V8AEzezwlfM6MHZ7 6bQw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-transfer-encoding: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=NTmWilJtg5P8EAdgbWScW8Z1MmDyPZBrslnYAxCQJ+k=; fh=OBAJwzz7Q+dDFA9CjUb1DU31mX480vSl/LRWePkUshI=; b=VElQZEToH82bMx74dAgsvVtscp79zHWMcrOgcgBRkC6AjhUlL4nkDmTm2IuBkb5/ZJ 5HveTNl/Ep+9P7KqbNMneDXw7Vumt/dqYuHqQssvO0LnsDlArdGLNY9+srDZlfbB/pqG X2FE9uMhRo79j5lY+y56L04eKqqRL8l1kfmpmMeCej19s9xd/+dASrpj6vwagUetQf47 ruD53zvE7KlcYeHkd0hY8l/fmhAKnKb7RpOqmV3dxzZJVl+DhI7GaZKvjVNUnYUHqIRC lgXRshhPpRr7r+rguBbC+vC7MCzLyGzaUACWAuCUu5F9nAqVKPreOAQUAQp0/0D9N4O3 ultw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ffwll.ch header.s=google header.b=UHQ12vmo; spf=pass (google.com: domain of linux-kernel+bounces-22024-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-22024-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id j191-20020a6380c8000000b0059b64b153f6si3265929pgd.845.2024.01.10.03.01.02 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Jan 2024 03:01:03 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-22024-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@ffwll.ch header.s=google header.b=UHQ12vmo; spf=pass (google.com: domain of linux-kernel+bounces-22024-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-22024-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 242D128F3CD for ; Wed, 10 Jan 2024 10:54:53 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5016D41236; Wed, 10 Jan 2024 10:54:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ffwll.ch header.i=@ffwll.ch header.b="UHQ12vmo" Received: from mail-ed1-f47.google.com (mail-ed1-f47.google.com [209.85.208.47]) (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 E18F740C12 for ; Wed, 10 Jan 2024 10:54:42 +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-ed1-f47.google.com with SMTP id 4fb4d7f45d1cf-55369c59708so714157a12.1 for ; Wed, 10 Jan 2024 02:54:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ffwll.ch; s=google; t=1704884081; x=1705488881; darn=vger.kernel.org; h=in-reply-to:content-transfer-encoding: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=NTmWilJtg5P8EAdgbWScW8Z1MmDyPZBrslnYAxCQJ+k=; b=UHQ12vmo4zPd7E0cXzdWnUGKaLtUnbfCvL4kUOYsfkhV0NJ9i/q1bTYJf5CEuOqWPd FZrRe6rYgIQSAbV+2dLoLd0QpOu9hoqT1yNzgaA10eEQJgJ+noiK0dRj/O1EMg3wNxuf en49MwUzKKg6DBMytv27NT/+D/UOD8ATPtVOc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704884081; x=1705488881; h=in-reply-to:content-transfer-encoding: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=NTmWilJtg5P8EAdgbWScW8Z1MmDyPZBrslnYAxCQJ+k=; b=EqPv9HJUPRqnRskAmUG8vraI3mTcUp4wrQDOT0SPq4pqwD/9J8Cdvp3uTHpEC4KOO8 V5NLwhCNfhF418FfSumKdQP1CQqqfO9K8MKpjPqIqCbAFqEtv7Hn5P9MkeB/+HiS7ggm ivcGlpsR0l+KpTdqgAA5r5ivL5v2WjodhSclMUtm/bUyy2jdUrdPnBFbcBkr21LSCvEu oAeanyWHjW6jj3H7Qk7yTzCp5CLqqtLNW/6hZXByGofuLHFNjoA5z25bZMNdrh5TFVMb acsbxu2MtUdCzOe9bFTAWaKIQfl6PFcV/2d9QQ7RF1sIMAMc4q5XjHfAuGTvSGkedZHP MWiQ== X-Gm-Message-State: AOJu0Yz7UGOc/AJqcokpq5ZCgLrLFfl8eXww36juP6dvAE1PxQxHIUZi 5T6Lg4GmtoKIQHjF9wQ4tt/cftT1M/JDKQ== X-Received: by 2002:a17:906:7d8:b0:a28:ab63:db33 with SMTP id m24-20020a17090607d800b00a28ab63db33mr979438ejc.7.1704884081031; Wed, 10 Jan 2024 02:54:41 -0800 (PST) Received: from phenom.ffwll.local ([2a02:168:57f4:0:efd0:b9e5:5ae6:c2fa]) by smtp.gmail.com with ESMTPSA id k2-20020a170906680200b00a28f51adc39sm1967689ejr.61.2024.01.10.02.54.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Jan 2024 02:54:40 -0800 (PST) Date: Wed, 10 Jan 2024 11:54:38 +0100 From: Daniel Vetter To: Christian =?iso-8859-1?Q?K=F6nig?= Cc: 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 , 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: Christian =?iso-8859-1?Q?K=F6nig?= , 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 , 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> <8ce0d90d-c751-4250-8656-fcab27aec6c2@amd.com> <12505066-eb42-4ddf-9c6d-29eca6eefdbc@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=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <12505066-eb42-4ddf-9c6d-29eca6eefdbc@amd.com> X-Operating-System: Linux phenom 6.5.0-4-amd64 On Wed, Jan 10, 2024 at 11:46:35AM +0100, Christian K?nig wrote: > Am 10.01.24 um 11:22 schrieb Daniel Vetter: > > On Wed, Jan 10, 2024 at 11:19:37AM +0100, Christian K?nig wrote: > > > Am 10.01.24 um 10:56 schrieb Julia Zhang: > > > > 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. > > > Well as far as I can see this is nonsense from the DMA-buf side of things. > > > > > > SG tables are always needed as long as you don't re-import the same object > > > into your driver and then you shouldn't end up in this function in the first > > > place. > > > > > > So that drm_gem_map_attach() requires get_sg_table to be implemented is > > > intentional and should never be overridden like this. > > See my reply, tldr; you're allowed to reject ->attach with -EBUSY to > > handle exactly this case of non-shareable buffer types. But definitely > > don't silently fail, that's a "we'll oops on map_attachment" kind of bug > > :-) > > Ah, yes that makes much more sense! > > So basically just the "return 0;" needs to be "return -EBUSY;". Well plus 2nd patch to polish the virtio_dma_buf docs a bit, that would be nice :-D -Sima > > Regards, > Christian. > > > -Sima > > > > > Regards, > > > Christian. > > > > > > > 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; > > > > + > > > > + 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, > > > > }; > -- Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch