From patchwork Mon Jul 12 23:12:34 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jason Ekstrand X-Patchwork-Id: 12372553 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2B8D7C07E99 for ; Mon, 12 Jul 2021 23:12:52 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id EAB8260FE3 for ; Mon, 12 Jul 2021 23:12:51 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org EAB8260FE3 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=jlekstrand.net Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=intel-gfx-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 3735A89F3C; Mon, 12 Jul 2021 23:12:49 +0000 (UTC) Received: from mail-pg1-x52c.google.com (mail-pg1-x52c.google.com [IPv6:2607:f8b0:4864:20::52c]) by gabe.freedesktop.org (Postfix) with ESMTPS id 77FDF89F3C for ; Mon, 12 Jul 2021 23:12:47 +0000 (UTC) Received: by mail-pg1-x52c.google.com with SMTP id s18so4597520pgq.3 for ; Mon, 12 Jul 2021 16:12:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=jlekstrand-net.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=nkzbM4toqBuy9BjR9h4atQc2L52M+eVAdOZMZpVFBDk=; b=tDRnyXqhVIUwlfOaVTpOEAikRPvjAXq64gKcuT8ZY0gnwmCnHTdn9eclV0/AwSxgl4 rEWwXECbLSxknCRHvbCQxngpNDoXMZ2rpIehg7k7PLptDs9K5QtvH054+Fur/z2+U1BV eYZXPDSxccHY4s3d9OJyYC5UxW4Tx24yZ1eBwAxrkh6lHBmzM+2RaqQd/rkPe2HBinSb d9XJXQvhwHq7MmrLgm0NWstJexh9IUQb2VD6qCEpi5jwvQjPzZMUgPzdYRbx8qbmpdHC R958NToW8v8qP7OzR2+tAdiRirBRNd7nK1lMzAeugLHgKocbbdh/tUlxAJatoOQBV8K3 7IqA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=nkzbM4toqBuy9BjR9h4atQc2L52M+eVAdOZMZpVFBDk=; b=ZWYNDgYCvy2EQkUjQR3E1EplVlFL5rQQ3Wy9+LmGDPCns+dt9b7KV5zKiJ+waRQacy NIyUICC1fRB4C6/KPpfI/zG8nxzjx/Zmx9tKc8+ymPZTsbuvapuUgvW1j6hoiBKexgQl 4GNXADLm5ndXmKog+asqzvZ//ppsHbcMrsc+Mq3icWQeck+HRF5rs1vEtNtzGdZJTV8a 5b8M5Y0YsLTmB0qX2a+JOcRP812yjalMy3JUvH2nids5KmXpPUTOevNSrIF87cUJJlXq pAhrWRSFJNNxcxzuseGRu4qdG5HhJQbe/Iat8SsUHzwFvJ1j8zswf0f8Cf3dTokBATfg Sn6g== X-Gm-Message-State: AOAM532tIVvnmcMgu/gP7kW34JcC5AL/9OwV9xGPRPm3L8ggPFRbnYjH GTvmpLsbFTJ/azyTZvlWRURYeg== X-Google-Smtp-Source: ABdhPJyeMihlcnw5PjXFBnmOw3yjdc+aPvC5oVOJOvwZz3vXp7ZqDWXukz+PUNiKFM2IRwU8psxDjg== X-Received: by 2002:a63:1263:: with SMTP id 35mr1367308pgs.221.1626131567000; Mon, 12 Jul 2021 16:12:47 -0700 (PDT) Received: from omlet.com ([134.134.139.80]) by smtp.gmail.com with ESMTPSA id g123sm16980940pfb.187.2021.07.12.16.12.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Jul 2021 16:12:46 -0700 (PDT) From: Jason Ekstrand To: dri-devel@lists.freedesktop.org, intel-gfx@lists.freedesktop.org, daniel@ffwll.ch, christian.koenig@amd.com, thomas.hellstrom@linux.intel.com, matthew.auld@intel.com, maarten.lankhorst@linux.intel.com Date: Mon, 12 Jul 2021 18:12:34 -0500 Message-Id: <20210712231234.1031975-2-jason@jlekstrand.net> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210712231234.1031975-1-jason@jlekstrand.net> References: <20210712231234.1031975-1-jason@jlekstrand.net> MIME-Version: 1.0 Subject: [Intel-gfx] [PATCH 2/2] drm/i915/gem: Migrate to system at dma-buf attach time (v5) X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" From: Thomas Hellström Until we support p2p dma or as a complement to that, migrate data to system memory at dma-buf attach time if possible. v2: - Rebase on dynamic exporter. Update the igt_dmabuf_import_same_driver selftest to migrate if we are LMEM capable. v3: - Migrate also in the pin() callback. v4: - Migrate in attach v5: (jason) - Lock around the migration Signed-off-by: Thomas Hellström Signed-off-by: Michael J. Ruhl Reported-by: kernel test robot Signed-off-by: Jason Ekstrand Reviewed-by: Jason Ekstrand --- drivers/gpu/drm/i915/gem/i915_gem_dmabuf.c | 25 ++++++++++++++++++- .../drm/i915/gem/selftests/i915_gem_dmabuf.c | 4 ++- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/i915/gem/i915_gem_dmabuf.c b/drivers/gpu/drm/i915/gem/i915_gem_dmabuf.c index 9a655f69a0671..3163f00554476 100644 --- a/drivers/gpu/drm/i915/gem/i915_gem_dmabuf.c +++ b/drivers/gpu/drm/i915/gem/i915_gem_dmabuf.c @@ -170,8 +170,31 @@ static int i915_gem_dmabuf_attach(struct dma_buf *dmabuf, struct dma_buf_attachment *attach) { struct drm_i915_gem_object *obj = dma_buf_to_obj(dmabuf); + struct i915_gem_ww_ctx ww; + int err; + + for_i915_gem_ww(&ww, err, true) { + err = i915_gem_object_lock(obj, &ww); + if (err) + continue; + + if (!i915_gem_object_can_migrate(obj, INTEL_REGION_SMEM)) { + err = -EOPNOTSUPP; + continue; + } + + err = i915_gem_object_migrate(obj, &ww, INTEL_REGION_SMEM); + if (err) + continue; - return i915_gem_object_pin_pages_unlocked(obj); + err = i915_gem_object_wait_migration(obj, 0); + if (err) + continue; + + err = i915_gem_object_pin_pages(obj); + } + + return err; } static void i915_gem_dmabuf_detach(struct dma_buf *dmabuf, diff --git a/drivers/gpu/drm/i915/gem/selftests/i915_gem_dmabuf.c b/drivers/gpu/drm/i915/gem/selftests/i915_gem_dmabuf.c index 3dc0f8b3cdab0..4f7e77b1c0152 100644 --- a/drivers/gpu/drm/i915/gem/selftests/i915_gem_dmabuf.c +++ b/drivers/gpu/drm/i915/gem/selftests/i915_gem_dmabuf.c @@ -106,7 +106,9 @@ static int igt_dmabuf_import_same_driver(void *arg) int err; force_different_devices = true; - obj = i915_gem_object_create_shmem(i915, PAGE_SIZE); + obj = i915_gem_object_create_lmem(i915, PAGE_SIZE, 0); + if (IS_ERR(obj)) + obj = i915_gem_object_create_shmem(i915, PAGE_SIZE); if (IS_ERR(obj)) goto out_ret;