From patchwork Fri Oct 27 19:45:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rob Clark X-Patchwork-Id: 159141 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:d641:0:b0:403:3b70:6f57 with SMTP id cy1csp845735vqb; Fri, 27 Oct 2023 12:47:34 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEN9mobXvCHehGVCU2MVdR/2LXT6QFtMlYdpnpOwrGvW1+2iAkfeNy2wbD+Tp5EVcn6zZok X-Received: by 2002:a81:7805:0:b0:5a7:b545:dcaa with SMTP id t5-20020a817805000000b005a7b545dcaamr6906711ywc.23.1698436054128; Fri, 27 Oct 2023 12:47:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698436054; cv=none; d=google.com; s=arc-20160816; b=KfK4wIdEJOxqFUq1q6v2mK0Qdq2CpQl3WdyU1YY5HXfEXyi5QOrHVvNd3piCjnQfDc Fg6J8ObKkpwvrn1AEuNb1rwueAi7IABuXOoPgVoZQ3y9eTrTl1Us+1FlLVW39vEGBLOf Fp/sJLKO13GlbDHiUFRBPHxrwtvi2PtOjtNviHI9726ZoULNGu867SrkBkgN7kmzujDw loMfB8Kv9R/rigBeYm8H6YD2lbAccY+ka2N/3KyQ8y9Boe9eKzqmqkYfKYqMqDXZBafL 9FuelNIJrCAiYgn2//QSCfmLMOfn3+Wo50O8RhT18vbdsesRFbWOyxMFnrpykcI7LYdh kllA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=Cy6IbgFuL135BKR91oRxByMVAKgGs/1dk+ALnWKFvUw=; fh=D+EPs4f1tbcirM+xOcOZ25ESgeHsz4zHs+gyKhf0s0I=; b=rKjAvukhlnKg2nAe6PeHwPWO2ohhy8z/FtFhBbgKoCM4yJaPskww3JrG+G2oGQrDoJ DHfJ9uAdpqSZmQ74LxAl1bslVxEZD1QgMqz7vUO9RS4Tdaz8ZkRw7P4ixDCOKPMEYY9X RT/P462sbEumF/bvT+vYN1soo+sHeSQYfYR0/zGglNxbCyf5nmGq6I2iNY7jAfEUbdxU O+SycSoyViiEAFHs03noKy9PzZ5T5tF+Z8L5I18BpP/a4XgTzZs6CeMBUqfvZ+vhBq5v pKMxg1oRIwuG4tNsaCAswlU12BNvsu5qM+D1IevIfNDpuWRYnvSs4Zwbg8+TpvnXGM/C Lm2w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=HGKTSDKa; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id n7-20020a819c47000000b005a7d03fbab5si3835276ywa.340.2023.10.27.12.47.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Oct 2023 12:47:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=HGKTSDKa; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id CB72980A990D; Fri, 27 Oct 2023 12:46:15 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232575AbjJ0TqD (ORCPT + 27 others); Fri, 27 Oct 2023 15:46:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56992 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231302AbjJ0TqC (ORCPT ); Fri, 27 Oct 2023 15:46:02 -0400 Received: from mail-pl1-x629.google.com (mail-pl1-x629.google.com [IPv6:2607:f8b0:4864:20::629]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6024F1B3; Fri, 27 Oct 2023 12:45:52 -0700 (PDT) Received: by mail-pl1-x629.google.com with SMTP id d9443c01a7336-1cc30bf9e22so791085ad.1; Fri, 27 Oct 2023 12:45:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1698435952; x=1699040752; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=Cy6IbgFuL135BKR91oRxByMVAKgGs/1dk+ALnWKFvUw=; b=HGKTSDKaWPM7mggPNjkCr7OQfEvrAzv5qv48/iZgooWEogyEdQpJ8SQJIrOzNSjT3I jjFCLmhm7DFn1n2LU0ZGMT5S+EMjC/VuNJgq4xVXDoakw8SJv8hp6PX5y3/axCvCqNFS Iav+LuAeieQnamuNdJ545/lr09GqZHmUe8vN8C6j8Ha0zb8UR6Wd0XfXa/uCDPOwaRgH U9S63RH3BC3i77cFFff37ZcdVeqhQuRY9U9nqGXeUBnmFcy5rjI1+htraGrNIp2fQ6Z+ ZzXaUwfIPzhvAFaWHLmjjVScEAeL/CRSQsftsyrVE0BWSjfISnM/NNIkvM0SYFnZeSNI 1Y2w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698435952; x=1699040752; 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=Cy6IbgFuL135BKR91oRxByMVAKgGs/1dk+ALnWKFvUw=; b=cHFJnUoQlB7qckgcIR2juc7qfZC1gXwG4E2IZh0bfOgYmKI12o87BwElA/Jo9h5JMg oIBn1HPO4TQWcbjZBOKcKQM45JfGhttp8PBDfhj9QLrr9doH/4mP7RV/hA4q4nZ7bLs8 NFTOrlnvcvTJPHxliPVaKf0Y31tjJH0Rg6KJ45KuFsCfEQRgMH4imW7zEQzagUp1O2bq B6w90SfGm93K2+TXLxSMSVAY5D+hlGo2I3/eDGzOERoPzCIocf2kZ9W5CrQzfWVg1K4S f4XYmLVQPcaf+AQlXVXjon/la8OlOqcq5zoPbVYr/5X6Ue0ni8QsX1ZRc1WtkUtgOYSN q99Q== X-Gm-Message-State: AOJu0YwEgmvwXLyj7/CMjPH0GvUMNp3V1oVvD3WL9tOnyBeWG4sODqik 8jlnFJOpQnmyfJuqVjS2pFA= X-Received: by 2002:a17:902:e74e:b0:1cb:fcfb:61af with SMTP id p14-20020a170902e74e00b001cbfcfb61afmr8280487plf.30.1698435951704; Fri, 27 Oct 2023 12:45:51 -0700 (PDT) Received: from localhost ([2a00:79e1:abd:4a00:6c80:7c10:75a0:44f4]) by smtp.gmail.com with ESMTPSA id ju19-20020a170903429300b001ae0152d280sm1944708plb.193.2023.10.27.12.45.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Oct 2023 12:45:50 -0700 (PDT) From: Rob Clark To: dri-devel@lists.freedesktop.org Cc: freedreno@lists.freedesktop.org, linux-arm-msm@vger.kernel.org, Rob Clark , Rob Clark , Abhinav Kumar , Dmitry Baryshkov , Sean Paul , Marijn Suijten , David Airlie , Daniel Vetter , linux-kernel@vger.kernel.org (open list) Subject: [PATCH] drm/msm/gem: Add metadata Date: Fri, 27 Oct 2023 12:45:37 -0700 Message-ID: <20231027194537.408922-1-robdclark@gmail.com> X-Mailer: git-send-email 2.41.0 MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham 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 X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Fri, 27 Oct 2023 12:46:15 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780939283927872862 X-GMAIL-MSGID: 1780939283927872862 From: Rob Clark The EXT_external_objects extension is a bit awkward as it doesn't pass explicit modifiers, leaving the importer to guess with incomplete information. In the case of vk (turnip) exporting and gl (freedreno) importing, the "OPTIMAL_TILING_EXT" layout depends on VkImageCreateInfo flags (among other things), which the importer does not know. Which unfortunately leaves us with the need for a metadata back-channel. The contents of the metadata are defined by userspace. The EXT_external_objects extension is only required to work between compatible versions of gl and vk drivers, as defined by device and driver UUIDs. Signed-off-by: Rob Clark --- drivers/gpu/drm/msm/msm_drv.c | 59 +++++++++++++++++++++++++++++++++-- drivers/gpu/drm/msm/msm_gem.h | 4 +++ include/uapi/drm/msm_drm.h | 2 ++ 3 files changed, 63 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/msm/msm_drv.c b/drivers/gpu/drm/msm/msm_drv.c index b61ccea05327..8fe2677ea37a 100644 --- a/drivers/gpu/drm/msm/msm_drv.c +++ b/drivers/gpu/drm/msm/msm_drv.c @@ -37,9 +37,10 @@ * - 1.9.0 - Add MSM_SUBMIT_FENCE_SN_IN * - 1.10.0 - Add MSM_SUBMIT_BO_NO_IMPLICIT * - 1.11.0 - Add wait boost (MSM_WAIT_FENCE_BOOST, MSM_PREP_BOOST) + * - 1.12.0 - Add MSM_INFO_SET_METADATA and MSM_INFO_GET_METADATA */ #define MSM_VERSION_MAJOR 1 -#define MSM_VERSION_MINOR 10 +#define MSM_VERSION_MINOR 12 #define MSM_VERSION_PATCHLEVEL 0 static void msm_deinit_vram(struct drm_device *ddev); @@ -566,6 +567,8 @@ static int msm_ioctl_gem_info(struct drm_device *dev, void *data, break; case MSM_INFO_SET_NAME: case MSM_INFO_GET_NAME: + case MSM_INFO_SET_METADATA: + case MSM_INFO_GET_METADATA: break; default: return -EINVAL; @@ -618,7 +621,7 @@ static int msm_ioctl_gem_info(struct drm_device *dev, void *data, break; case MSM_INFO_GET_NAME: if (args->value && (args->len < strlen(msm_obj->name))) { - ret = -EINVAL; + ret = -ETOOSMALL; break; } args->len = strlen(msm_obj->name); @@ -627,6 +630,58 @@ static int msm_ioctl_gem_info(struct drm_device *dev, void *data, msm_obj->name, args->len)) ret = -EFAULT; } + break; + case MSM_INFO_SET_METADATA: + /* Impose a moderate upper bound on metadata size: */ + if (args->len > 128) { + ret = -EOVERFLOW; + break; + } + + ret = msm_gem_lock_interruptible(obj); + if (ret) + break; + + msm_obj->metadata = + krealloc(msm_obj->metadata, args->len, GFP_KERNEL); + msm_obj->metadata_size = args->len; + + if (copy_from_user(msm_obj->metadata, u64_to_user_ptr(args->value), + args->len)) { + msm_obj->metadata_size = 0; + ret = -EFAULT; + } + + msm_gem_unlock(obj); + + break; + case MSM_INFO_GET_METADATA: + if (!args->value) { + /* + * Querying the size is inherently racey, but + * EXT_external_objects expects the app to confirm + * via device and driver UUIDs that the exporter and + * importer versions match. All we can do from the + * kernel side is check the length under obj lock + * when userspace tries to retrieve the metadata + */ + args->len = msm_obj->metadata_size; + break; + } + + ret = msm_gem_lock_interruptible(obj); + if (ret) + break; + + if (args->len < msm_obj->metadata_size) { + ret = -ETOOSMALL; + } else if (copy_to_user(u64_to_user_ptr(args->value), + msm_obj->metadata, args->len)) { + ret = -EFAULT; + } + + msm_gem_unlock(obj); + break; } diff --git a/drivers/gpu/drm/msm/msm_gem.h b/drivers/gpu/drm/msm/msm_gem.h index 7f34263048a3..8d414b072c29 100644 --- a/drivers/gpu/drm/msm/msm_gem.h +++ b/drivers/gpu/drm/msm/msm_gem.h @@ -109,6 +109,10 @@ struct msm_gem_object { char name[32]; /* Identifier to print for the debugfs files */ + /* userspace metadata backchannel */ + void *metadata; + u32 metadata_size; + /** * pin_count: Number of times the pages are pinned * diff --git a/include/uapi/drm/msm_drm.h b/include/uapi/drm/msm_drm.h index 6c34272a13fd..6f2a7ad04aa4 100644 --- a/include/uapi/drm/msm_drm.h +++ b/include/uapi/drm/msm_drm.h @@ -139,6 +139,8 @@ struct drm_msm_gem_new { #define MSM_INFO_GET_NAME 0x03 /* get debug name, returned by pointer */ #define MSM_INFO_SET_IOVA 0x04 /* set the iova, passed by value */ #define MSM_INFO_GET_FLAGS 0x05 /* get the MSM_BO_x flags */ +#define MSM_INFO_SET_METADATA 0x06 /* set userspace metadata */ +#define MSM_INFO_GET_METADATA 0x07 /* get userspace metadata */ struct drm_msm_gem_info { __u32 handle; /* in */ From patchwork Sun Oct 29 15:07:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rob Clark X-Patchwork-Id: 159374 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:d641:0:b0:403:3b70:6f57 with SMTP id cy1csp1731580vqb; Sun, 29 Oct 2023 08:08:11 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEmYzgD/EnCj7x//bHBRoQ5zcJOa/3FxLSg1FNJaj9euYMtTdpWljy4XConkJPKZ6nqjbgz X-Received: by 2002:a17:903:288b:b0:1c5:6157:f073 with SMTP id ku11-20020a170903288b00b001c56157f073mr7860829plb.11.1698592090976; Sun, 29 Oct 2023 08:08:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698592090; cv=none; d=google.com; s=arc-20160816; b=ZtNmaA5OsRIGKolUfO6XpUX/r9gePZnerxmZnOtnOftazCn7PKpOIt1ZuW7eIdZHEd m8Df1/V9+XMZ2PmBy4CCu+BDDvT7mC4UMk52GmHTjGp2iRzqu6VdylsQgAYpfwpAG547 78pAH7cpEVxI/xYVJlLCrH7SPV3J+uhJY2MKeNhspX5sjotS5nnXqaHwd2a6Z9k1VLvb zGHYuj68rkwz8l5QG7VyO+2ZT5L2mPY1sV1U3cai8ynkTbTfjethi0QJH+d0whG5+XAM FDznf+xG6dFU+cttS9r8ydnkXnn7pamnoMAhryQ5RkuextgJ37agChjvWIEl8hXu4y2L N/6w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=FSklqDw7AA6NpVC0KwUQy6XYNfBWwLFmbDUXgjz8m44=; fh=CRg1aQJ6KHalDA9LWU27exd+PhhH5P0NBpuQp0bfKMA=; b=1F3rxImO/LCUFSVAJB4T7ewRUpzYGEgusRfp5PiLbnYGTcfbp6frP0HhdKki7z0szm A7fNkVs6ngZaPDzpbJkIemCVa2Kfj9w0rekC6M1jZVo1HWiIL3/KsfOfOVDVDdqMMKEN 0jKzWhpipFEJSDNRPf9GcqzoJreWtMEnZ03ZRt2ff6TPh7VdrwSiybwt9hOJwnJaIlaz H/ZrcQrBFNo5lDwMZhormOvbPUnrrFguXWj3z/6MAAI2YfYpEAfbrXmerUBpS1G7HdBp khtLD2y3DMgcfY25w9WHM3GEtMB9tfivNOB6odB7V+stKuxlnNS/ld/VLFyus+HIbUx+ HbzQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=ckWpJysl; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id d11-20020a170902f14b00b001c7615a8e09si3750687plb.593.2023.10.29.08.08.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 29 Oct 2023 08:08:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=ckWpJysl; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id CC76F80699D5; Sun, 29 Oct 2023 08:08:07 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230193AbjJ2PIC (ORCPT + 30 others); Sun, 29 Oct 2023 11:08:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38830 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229778AbjJ2PH4 (ORCPT ); Sun, 29 Oct 2023 11:07:56 -0400 Received: from mail-pf1-x434.google.com (mail-pf1-x434.google.com [IPv6:2607:f8b0:4864:20::434]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 255FCBD; Sun, 29 Oct 2023 08:07:54 -0700 (PDT) Received: by mail-pf1-x434.google.com with SMTP id d2e1a72fcca58-6ba54c3ed97so3626248b3a.2; Sun, 29 Oct 2023 08:07:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1698592073; x=1699196873; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=FSklqDw7AA6NpVC0KwUQy6XYNfBWwLFmbDUXgjz8m44=; b=ckWpJyslffVBfe3U24jKIJ21nXZnXz2GWujUYw7co0OKbJb7BTu4Hzl5A2TE4sQzru jPvY3CGHv3SJGSxYTkx349yTAK8EJbYgkxJTJkTxBmg+HQV+ydhxG2gI3GwML5WVsn0q kResPplemU+khYemRexjMAT3ZWp7xuvQAINUSOtThEuR2oV6DUJ9WpsVDO8lhvpTWldM WtOc99MAPs0SFR0bBDb/6JZdZDQo2q8wu5UcgLCHU6fFe+5WA7k1yvp37RXxm0QOgSrj xpjXndftBrLb1zbQDQTkvI8Etto9hFLJb+IWkX/Bim14NkmQrdpG+chQ/OUVHTIGmUrs vOmw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698592073; x=1699196873; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=FSklqDw7AA6NpVC0KwUQy6XYNfBWwLFmbDUXgjz8m44=; b=F5Kf2y9LaQmYRhd7MbYEAWOd7CrHNXn8HK2FRIvgLt+eugIKcJ33JJydv4cRr+qrtj dTv2QzpgKgwbaMzsz2ASD2K9zjJPQ0LMi/5JuaqdD18lAx9It2ExLkFnDBzy4+MHDzYU ThClHV4+Ma/qM2Qb1/+fLa/IgJVaHs6Vc5F596/e2GueumiinCeTkVFQ9tdpj6B2jaUF g1Sx307SX/W2L4Mm1E+MxHangxRbzy8vVTWlPOjPusuUkphrTcT41rW22ftfBn9v0SGD 0LKfd4ktmjkX/26S+ibKioMaFB3hBwdImgItl5Rz8PjO7/DJ1pkfqXXlbkgFWTa3fu9T CxoA== X-Gm-Message-State: AOJu0YyaRNfy4+g5GlpeDrphcq/WGzmPTRO3wkloqzMf+bt9uBKpI/yK pLstRgToTMS7fapc3Y2a+2hrs5METV0= X-Received: by 2002:a05:6a00:22cb:b0:6b6:e147:717 with SMTP id f11-20020a056a0022cb00b006b6e1470717mr9971653pfj.23.1698592073428; Sun, 29 Oct 2023 08:07:53 -0700 (PDT) Received: from localhost (c-73-37-105-206.hsd1.or.comcast.net. [73.37.105.206]) by smtp.gmail.com with ESMTPSA id q20-20020a62ae14000000b006934a1c69f8sm4393588pff.24.2023.10.29.08.07.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 29 Oct 2023 08:07:52 -0700 (PDT) From: Rob Clark To: dri-devel@lists.freedesktop.org Cc: freedreno@lists.freedesktop.org, linux-arm-msm@vger.kernel.org, Dmitry Baryshkov , Daniel Vetter , Daniel Stone , Rob Clark , Rob Clark , Abhinav Kumar , Sean Paul , Marijn Suijten , David Airlie , linux-kernel@vger.kernel.org (open list) Subject: [PATCH v2 2/2] drm/msm/gem: Add metadata Date: Sun, 29 Oct 2023 08:07:38 -0700 Message-ID: <20231029150740.6434-3-robdclark@gmail.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231027194537.408922-1-robdclark@gmail.com> References: <20231027194537.408922-1-robdclark@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS autolearn=ham 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 X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Sun, 29 Oct 2023 08:08:07 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780939283927872862 X-GMAIL-MSGID: 1781102900035891370 From: Rob Clark The EXT_external_objects extension is a bit awkward as it doesn't pass explicit modifiers, leaving the importer to guess with incomplete information. In the case of vk (turnip) exporting and gl (freedreno) importing, the "OPTIMAL_TILING_EXT" layout depends on VkImageCreateInfo flags (among other things), which the importer does not know. Which unfortunately leaves us with the need for a metadata back-channel. The contents of the metadata are defined by userspace. The EXT_external_objects extension is only required to work between compatible versions of gl and vk drivers, as defined by device and driver UUIDs. v2: add missing metadata kfree Signed-off-by: Rob Clark Reviewed-by: Dmitry Baryshkov --- drivers/gpu/drm/msm/msm_drv.c | 57 ++++++++++++++++++++++++++++++++++- drivers/gpu/drm/msm/msm_gem.c | 1 + drivers/gpu/drm/msm/msm_gem.h | 4 +++ include/uapi/drm/msm_drm.h | 2 ++ 4 files changed, 63 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/msm/msm_drv.c b/drivers/gpu/drm/msm/msm_drv.c index 781db689fb16..9ec74ab4cfea 100644 --- a/drivers/gpu/drm/msm/msm_drv.c +++ b/drivers/gpu/drm/msm/msm_drv.c @@ -49,9 +49,10 @@ * - 1.9.0 - Add MSM_SUBMIT_FENCE_SN_IN * - 1.10.0 - Add MSM_SUBMIT_BO_NO_IMPLICIT * - 1.11.0 - Add wait boost (MSM_WAIT_FENCE_BOOST, MSM_PREP_BOOST) + * - 1.12.0 - Add MSM_INFO_SET_METADATA and MSM_INFO_GET_METADATA */ #define MSM_VERSION_MAJOR 1 -#define MSM_VERSION_MINOR 11 +#define MSM_VERSION_MINOR 12 #define MSM_VERSION_PATCHLEVEL 0 static void msm_deinit_vram(struct drm_device *ddev); @@ -844,6 +845,8 @@ static int msm_ioctl_gem_info(struct drm_device *dev, void *data, break; case MSM_INFO_SET_NAME: case MSM_INFO_GET_NAME: + case MSM_INFO_SET_METADATA: + case MSM_INFO_GET_METADATA: break; default: return -EINVAL; @@ -905,6 +908,58 @@ static int msm_ioctl_gem_info(struct drm_device *dev, void *data, msm_obj->name, args->len)) ret = -EFAULT; } + break; + case MSM_INFO_SET_METADATA: + /* Impose a moderate upper bound on metadata size: */ + if (args->len > 128) { + ret = -EOVERFLOW; + break; + } + + ret = msm_gem_lock_interruptible(obj); + if (ret) + break; + + msm_obj->metadata = + krealloc(msm_obj->metadata, args->len, GFP_KERNEL); + msm_obj->metadata_size = args->len; + + if (copy_from_user(msm_obj->metadata, u64_to_user_ptr(args->value), + args->len)) { + msm_obj->metadata_size = 0; + ret = -EFAULT; + } + + msm_gem_unlock(obj); + + break; + case MSM_INFO_GET_METADATA: + if (!args->value) { + /* + * Querying the size is inherently racey, but + * EXT_external_objects expects the app to confirm + * via device and driver UUIDs that the exporter and + * importer versions match. All we can do from the + * kernel side is check the length under obj lock + * when userspace tries to retrieve the metadata + */ + args->len = msm_obj->metadata_size; + break; + } + + ret = msm_gem_lock_interruptible(obj); + if (ret) + break; + + if (args->len < msm_obj->metadata_size) { + ret = -ETOOSMALL; + } else if (copy_to_user(u64_to_user_ptr(args->value), + msm_obj->metadata, args->len)) { + ret = -EFAULT; + } + + msm_gem_unlock(obj); + break; } diff --git a/drivers/gpu/drm/msm/msm_gem.c b/drivers/gpu/drm/msm/msm_gem.c index 1113e6b2ec8e..175ee4ab8a6f 100644 --- a/drivers/gpu/drm/msm/msm_gem.c +++ b/drivers/gpu/drm/msm/msm_gem.c @@ -1058,6 +1058,7 @@ static void msm_gem_free_object(struct drm_gem_object *obj) drm_gem_object_release(obj); + kfree(msm_obj->metadata); kfree(msm_obj); } diff --git a/drivers/gpu/drm/msm/msm_gem.h b/drivers/gpu/drm/msm/msm_gem.h index 7f34263048a3..8d414b072c29 100644 --- a/drivers/gpu/drm/msm/msm_gem.h +++ b/drivers/gpu/drm/msm/msm_gem.h @@ -109,6 +109,10 @@ struct msm_gem_object { char name[32]; /* Identifier to print for the debugfs files */ + /* userspace metadata backchannel */ + void *metadata; + u32 metadata_size; + /** * pin_count: Number of times the pages are pinned * diff --git a/include/uapi/drm/msm_drm.h b/include/uapi/drm/msm_drm.h index 6c34272a13fd..6f2a7ad04aa4 100644 --- a/include/uapi/drm/msm_drm.h +++ b/include/uapi/drm/msm_drm.h @@ -139,6 +139,8 @@ struct drm_msm_gem_new { #define MSM_INFO_GET_NAME 0x03 /* get debug name, returned by pointer */ #define MSM_INFO_SET_IOVA 0x04 /* set the iova, passed by value */ #define MSM_INFO_GET_FLAGS 0x05 /* get the MSM_BO_x flags */ +#define MSM_INFO_SET_METADATA 0x06 /* set userspace metadata */ +#define MSM_INFO_GET_METADATA 0x07 /* get userspace metadata */ struct drm_msm_gem_info { __u32 handle; /* in */