From patchwork Tue Nov 21 00:38:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rob Clark X-Patchwork-Id: 745793 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Rt4yfhbV" Received: from mail-oi1-x236.google.com (mail-oi1-x236.google.com [IPv6:2607:f8b0:4864:20::236]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A30E5D9; Mon, 20 Nov 2023 16:40:05 -0800 (PST) Received: by mail-oi1-x236.google.com with SMTP id 5614622812f47-3b2ec9a79bdso3601609b6e.3; Mon, 20 Nov 2023 16:40:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1700527205; x=1701132005; 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=7jJiNmIhW71Zn4Fc0nq68KcS1kEb54hrII7uSxSemAM=; b=Rt4yfhbVMN1O9U2g7OhGuyiqVI/VDTNM1Y9yqEltZ8mgdwXi4Oq7UVVGe7CL92ejI5 LYuHPs5kdVi2f5qPc+QHUwfEFH6jSezQNQxTM9tA4tugpzl8nvbepax3MxPwV+Kvb5/m 04d0T6J9R+rCvQO5h2d+6e/v+dBuhPJC+oOCAN6ITieYV+MKuAKk0VoELwAO9SUfk4Ji CNcWbhdDgmHmxtMciOlmhy9aVyapQgJi6EkBtcNtz5/wMKQLIWA/tUaXjNc3kCowjtaH nfQPa8LKgbLO+o4TYjLXuVNJYM7swVR95qguBP0rLt6Ar3D34SSDFbecrg3bXTemRS1p wlJA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700527205; x=1701132005; 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=7jJiNmIhW71Zn4Fc0nq68KcS1kEb54hrII7uSxSemAM=; b=Us0K8juDPZNbyZuOZ/pcockakvdsXaP7tHfKzdnql5of3uE1JhbbD+TuGya2bU3kDu LEtvgkTq4NvkxSCJvMzEy/+kDTTI8vLbG+xIVLyWsqrvgR9/P4RVOAfMKwzNgNL/NbPt Kaa0eTv41lj/nfXB6ozoC4uJ1DtviI7eaukK+yvERKB9KqpHu3wWLTlK5BSRt4t1beEb PVhYJhIN7G1zbvka6AmteC1v1khBtzA8ml5iINgKITXuLK7fV9NM60q/RjGI7lq5+7Ze 6JaoaswIqhd5yHfeINPtyNh2eXN9K0gfkLEqVeVFvwBoA9GyT715or73NQN9O8+ZkTzQ WzVA== X-Gm-Message-State: AOJu0YwA+tuJZ4E2UcwpGPYhsZa62mP+KM4kNFZqrrnQ6loZtQZgwUrd y1AhBa994iXORE0VrEmgDQg= X-Google-Smtp-Source: AGHT+IHcGK1NJmg8WEvF1E/QUfwop36BTwpUAa5h3H7ELtuDNLXxZzI9udncaGpBHWzB0HNrN1hbMg== X-Received: by 2002:a05:6808:114b:b0:3ae:170f:a39b with SMTP id u11-20020a056808114b00b003ae170fa39bmr12467395oiu.17.1700527204827; Mon, 20 Nov 2023 16:40:04 -0800 (PST) Received: from localhost ([47.215.232.245]) by smtp.gmail.com with ESMTPSA id r1-20020a6560c1000000b005ab281d0777sm5665374pgv.20.2023.11.20.16.40.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Nov 2023 16:40:04 -0800 (PST) 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 v2 1/7] drm/msm/gem: Remove "valid" tracking Date: Mon, 20 Nov 2023 16:38:45 -0800 Message-ID: <20231121003935.5868-2-robdclark@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231121003935.5868-1-robdclark@gmail.com> References: <20231121003935.5868-1-robdclark@gmail.com> Precedence: bulk X-Mailing-List: linux-arm-msm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Rob Clark This was a small optimization for pre-soft-pin userspace. But mesa switched to soft-pin nearly 5yrs ago. So lets drop the optimization and simplify the code. Signed-off-by: Rob Clark Reviewed-by: Dmitry Baryshkov --- drivers/gpu/drm/msm/msm_gem.h | 2 -- drivers/gpu/drm/msm/msm_gem_submit.c | 44 +++++----------------------- 2 files changed, 8 insertions(+), 38 deletions(-) diff --git a/drivers/gpu/drm/msm/msm_gem.h b/drivers/gpu/drm/msm/msm_gem.h index 8ddef5443140..c36c1c1fa222 100644 --- a/drivers/gpu/drm/msm/msm_gem.h +++ b/drivers/gpu/drm/msm/msm_gem.h @@ -271,7 +271,6 @@ struct msm_gem_submit { struct msm_gpu_submitqueue *queue; struct pid *pid; /* submitting process */ bool fault_dumped; /* Limit devcoredump dumping to one per submit */ - bool valid; /* true if no cmdstream patching needed */ bool in_rb; /* "sudo" mode, copy cmds into RB */ struct msm_ringbuffer *ring; unsigned int nr_cmds; @@ -288,7 +287,6 @@ struct msm_gem_submit { } *cmd; /* array of size nr_cmds */ struct { /* make sure these don't conflict w/ MSM_SUBMIT_BO_x */ -#define BO_VALID 0x8000 /* is current addr in cmdstream correct/valid? */ #define BO_LOCKED 0x4000 /* obj lock is held */ #define BO_PINNED 0x2000 /* obj (pages) is pinned and on active list */ uint32_t flags; diff --git a/drivers/gpu/drm/msm/msm_gem_submit.c b/drivers/gpu/drm/msm/msm_gem_submit.c index 6d8ec1337e8b..996274ef32a6 100644 --- a/drivers/gpu/drm/msm/msm_gem_submit.c +++ b/drivers/gpu/drm/msm/msm_gem_submit.c @@ -150,8 +150,6 @@ static int submit_lookup_objects(struct msm_gem_submit *submit, submit->bos[i].handle = submit_bo.handle; submit->bos[i].flags = submit_bo.flags; - /* in validate_objects() we figure out if this is true: */ - submit->bos[i].iova = submit_bo.presumed; } spin_lock(&file->table_lock); @@ -278,9 +276,6 @@ static void submit_unlock_unpin_bo(struct msm_gem_submit *submit, int i) { unsigned cleanup_flags = BO_PINNED | BO_LOCKED; submit_cleanup_bo(submit, i, cleanup_flags); - - if (!(submit->bos[i].flags & BO_VALID)) - submit->bos[i].iova = 0; } /* This is where we make sure all the bo's are reserved and pin'd: */ @@ -390,8 +385,6 @@ static int submit_pin_objects(struct msm_gem_submit *submit) struct msm_drm_private *priv = submit->dev->dev_private; int i, ret = 0; - submit->valid = true; - for (i = 0; i < submit->nr_bos; i++) { struct drm_gem_object *obj = submit->bos[i].obj; struct msm_gem_vma *vma; @@ -407,14 +400,7 @@ static int submit_pin_objects(struct msm_gem_submit *submit) if (ret) break; - if (vma->iova == submit->bos[i].iova) { - submit->bos[i].flags |= BO_VALID; - } else { - submit->bos[i].iova = vma->iova; - /* iova changed, so address in cmdstream is not valid: */ - submit->bos[i].flags &= ~BO_VALID; - submit->valid = false; - } + submit->bos[i].iova = vma->iova; } /* @@ -451,7 +437,7 @@ static void submit_attach_object_fences(struct msm_gem_submit *submit) } static int submit_bo(struct msm_gem_submit *submit, uint32_t idx, - struct drm_gem_object **obj, uint64_t *iova, bool *valid) + struct drm_gem_object **obj, uint64_t *iova) { if (idx >= submit->nr_bos) { SUBMIT_ERROR(submit, "invalid buffer index: %u (out of %u)\n", @@ -463,8 +449,6 @@ static int submit_bo(struct msm_gem_submit *submit, uint32_t idx, *obj = submit->bos[idx].obj; if (iova) *iova = submit->bos[idx].iova; - if (valid) - *valid = !!(submit->bos[idx].flags & BO_VALID); return 0; } @@ -477,9 +461,6 @@ static int submit_reloc(struct msm_gem_submit *submit, struct drm_gem_object *ob uint32_t *ptr; int ret = 0; - if (!nr_relocs) - return 0; - if (offset % 4) { SUBMIT_ERROR(submit, "non-aligned cmdstream buffer: %u\n", offset); return -EINVAL; @@ -500,7 +481,6 @@ static int submit_reloc(struct msm_gem_submit *submit, struct drm_gem_object *ob struct drm_msm_gem_submit_reloc submit_reloc = relocs[i]; uint32_t off; uint64_t iova; - bool valid; if (submit_reloc.submit_offset % 4) { SUBMIT_ERROR(submit, "non-aligned reloc offset: %u\n", @@ -519,13 +499,10 @@ static int submit_reloc(struct msm_gem_submit *submit, struct drm_gem_object *ob goto out; } - ret = submit_bo(submit, submit_reloc.reloc_idx, NULL, &iova, &valid); + ret = submit_bo(submit, submit_reloc.reloc_idx, NULL, &iova); if (ret) goto out; - if (valid) - continue; - iova += submit_reloc.reloc_offset; if (submit_reloc.shift < 0) @@ -879,8 +856,7 @@ int msm_ioctl_gem_submit(struct drm_device *dev, void *data, struct drm_gem_object *obj; uint64_t iova; - ret = submit_bo(submit, submit->cmd[i].idx, - &obj, &iova, NULL); + ret = submit_bo(submit, submit->cmd[i].idx, &obj, &iova); if (ret) goto out; @@ -894,17 +870,13 @@ int msm_ioctl_gem_submit(struct drm_device *dev, void *data, submit->cmd[i].iova = iova + (submit->cmd[i].offset * 4); - if (submit->valid) + if (likely(!submit->cmd[i].nr_relocs)) continue; if (!gpu->allow_relocs) { - if (submit->cmd[i].nr_relocs) { - SUBMIT_ERROR(submit, "relocs not allowed\n"); - ret = -EINVAL; - goto out; - } - - continue; + SUBMIT_ERROR(submit, "relocs not allowed\n"); + ret = -EINVAL; + goto out; } ret = submit_reloc(submit, obj, submit->cmd[i].offset * 4, From patchwork Tue Nov 21 00:38:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rob Clark X-Patchwork-Id: 745792 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Nv4V/xDT" Received: from mail-ot1-x335.google.com (mail-ot1-x335.google.com [IPv6:2607:f8b0:4864:20::335]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2DCA0CA; Mon, 20 Nov 2023 16:40:10 -0800 (PST) Received: by mail-ot1-x335.google.com with SMTP id 46e09a7af769-6ce2eaf7c2bso3138692a34.0; Mon, 20 Nov 2023 16:40:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1700527209; x=1701132009; 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=uYOj379SOV2UbK9laVZ0cIdfJ+7kdLAIQwa994Jd5yg=; b=Nv4V/xDTd7md1BA6Ni3F+r9zWISB33lJg+fWIP6bw4SH4c9xMsrYxixX6vkhW/t5G0 u2oXyVpns4NV2szh1fh5KV7/oEJcPCo5bOAG+rsxGpt1AxdbBp8tmb/tJhgu9Tdy6kcs DLOxyC5ccP4NIrG13QuhrYBq+vBAancpSuRRHfn1d2dRMxbQF+YcpiPCl//3O4ieFt3L 7UoETVodGiUuUq5eOyB7brvnVg2SuqpMyl8hNBV363RU3wsqPvlzsctJOS2bhfVdnOnx NnX600dPR0Nk8EFzFD2BGNpanc4GFQNPMSsZwzuQNYwJGh3Qn7lTFTnWb4sh06W0gT78 732A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700527209; x=1701132009; 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=uYOj379SOV2UbK9laVZ0cIdfJ+7kdLAIQwa994Jd5yg=; b=b8a7h8NnR1uhDq59hDKeIeLbCSmRtlN8petnNjumamggrDnZXNah6E7zDZ6vIqavwO SH9endLGnlWsMi7xVTZv155rjSLrd/lrXjWOswW8ilPYD1n+0sawNw1JEY07LhzFKozh fcIJPMjrwYUjq/rETSRbv6SIVH1ga6kEuzq8dreEkrBIqkfY4BqPWYocRzMd1JhO2gbP 5QKaYHh+M0Ix0mKqZ5R7gwCsMWSlqSYL7SOWyFs0rKdlqrlCVvkYeU/18jYFbjjXpPDW xxXpNdxwkf1BGoLmeiKEmoPdU4gV3E9w1YeaBbvMwBEJkg+D7tzHbxNeXeEr9BE1hclB skAg== X-Gm-Message-State: AOJu0YzdS//tiViR11wtFPbI9k/ETzKrCtW9W5LbUP5f0dZajIoNllb2 KuuNe+xVYHgqXujE6Bwgl0Q= X-Google-Smtp-Source: AGHT+IEvgLhoaeclWGQbluYzwOZp4JoyP7RhFpckX77W1BHHUivUh5KC3AVkJ82uQaL1insC8VVbPg== X-Received: by 2002:a05:6870:d3cc:b0:1f0:c29:d75c with SMTP id l12-20020a056870d3cc00b001f00c29d75cmr11052773oag.47.1700527209326; Mon, 20 Nov 2023 16:40:09 -0800 (PST) Received: from localhost ([47.215.232.245]) by smtp.gmail.com with ESMTPSA id it14-20020a056a00458e00b006c8721330fesm6666553pfb.74.2023.11.20.16.40.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Nov 2023 16:40:08 -0800 (PST) From: Rob Clark To: dri-devel@lists.freedesktop.org Cc: freedreno@lists.freedesktop.org, linux-arm-msm@vger.kernel.org, Rob Clark , Dmitry Baryshkov , Rob Clark , Abhinav Kumar , Sean Paul , Marijn Suijten , David Airlie , Daniel Vetter , linux-kernel@vger.kernel.org (open list) Subject: [PATCH v2 3/7] drm/msm/gem: Don't queue job to sched in error cases Date: Mon, 20 Nov 2023 16:38:47 -0800 Message-ID: <20231121003935.5868-4-robdclark@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231121003935.5868-1-robdclark@gmail.com> References: <20231121003935.5868-1-robdclark@gmail.com> Precedence: bulk X-Mailing-List: linux-arm-msm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Rob Clark We shouldn't be running the job in error cases. This also avoids having to think too hard about where the objs get unpinned (and if necessary, the resv takes over tracking that the obj is busy).. ie. error cases it always happens synchronously, and normal cases it happens from scheduler job_run() callback. Signed-off-by: Rob Clark Reviewed-by: Dmitry Baryshkov --- drivers/gpu/drm/msm/msm_gem_submit.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/gpu/drm/msm/msm_gem_submit.c b/drivers/gpu/drm/msm/msm_gem_submit.c index 2d5527dc3e1a..786b48a55309 100644 --- a/drivers/gpu/drm/msm/msm_gem_submit.c +++ b/drivers/gpu/drm/msm/msm_gem_submit.c @@ -946,6 +946,9 @@ int msm_ioctl_gem_submit(struct drm_device *dev, void *data, } } + if (ret) + goto out; + submit_attach_object_fences(submit); /* The scheduler owns a ref now: */ From patchwork Tue Nov 21 00:38:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rob Clark X-Patchwork-Id: 745791 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="XFl80V1O" Received: from mail-pl1-x62a.google.com (mail-pl1-x62a.google.com [IPv6:2607:f8b0:4864:20::62a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E1629114; Mon, 20 Nov 2023 16:40:13 -0800 (PST) Received: by mail-pl1-x62a.google.com with SMTP id d9443c01a7336-1cc0e78ec92so31414955ad.3; Mon, 20 Nov 2023 16:40:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1700527213; x=1701132013; 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=o0h8yAS+G8YHpuqagMyaQ9goLsE9tJyhmBTQ25AFj0s=; b=XFl80V1Og099vz55KWPDjiTyP9/em07jGeREaCjtjfkjMvA5QE6a/ZoNkWZcw9a0jb ngHgPouSgzkvgMdtHeIQD++1Ez72yp0PRUXivbOcebtdhSPLFf1O+mGu1ZOiMUrXLYga SHAvzkoSiYqZGoq/TaZCBITVE7lSyxRbL+UZsm+/r7dhiaJhfo0MbJHuNBcOOeCyZEWt L/4qLfP5wJHRRPzKKjxc1gWNMVC9N/KMJra2B3koQfS6AG701wx3Mm2noipzE/T2YjAU wkaho+5DyQtKcWN5KkknB3J567VJf+ScIx2REH2TXB8Qu+JzbpObvESlQz2rSs/Vpuay sDPA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700527213; x=1701132013; 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=o0h8yAS+G8YHpuqagMyaQ9goLsE9tJyhmBTQ25AFj0s=; b=dlYMHVhxFP2MWUoq0HniqdzXiAFLMldE6Bse7/Ww03wwMsJL5Lwd2NxG8/XXjhHcNJ UJ7AJvEvNRZbNg8A0Crw7XzzzHKAjl7hkE9IQGSmxUcvuHWY4/W6JySDyzc6MTWK8j3N QuxNKX4Z8zN+Ka5OXXRVYVEjK+QVVnPcPm0s1pKmzWAf4wzXUbwFlWP5tI62frE9pwS0 lvhTUiBX4JDXziI7TpPFD48dBTvhozU+2JkeddtKVL95DhsiWHwC7m94ZyvL22WmAPe4 vk382D0yg299uytaJSVjGYq2KDrmKz0Vj7hXyOgqB3PdobLctAupQ9fJszBTRQqUPScm wCuQ== X-Gm-Message-State: AOJu0YzAMn3udRDZJAl5XFKgmqs/5xSiw11ZwlLgQXea6qyho96QRMdo 4Rw23kqIQ/nzb2TqFH3VirI= X-Google-Smtp-Source: AGHT+IFRewbZRAvUU6gZKQNB4YVM/KU5JvPUE8Ku/K2+YHY6o9UQhoZvejH2rTSIxis/nDYoz8E2Qw== X-Received: by 2002:a17:902:eb8f:b0:1cc:237c:75d6 with SMTP id q15-20020a170902eb8f00b001cc237c75d6mr7706097plg.67.1700527213178; Mon, 20 Nov 2023 16:40:13 -0800 (PST) Received: from localhost ([47.215.232.245]) by smtp.gmail.com with ESMTPSA id u1-20020a170902b28100b001cf567252besm4035798plr.237.2023.11.20.16.40.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Nov 2023 16:40:12 -0800 (PST) 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 v2 5/7] drm/msm/gem: Cleanup submit_cleanup_bo() Date: Mon, 20 Nov 2023 16:38:49 -0800 Message-ID: <20231121003935.5868-6-robdclark@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231121003935.5868-1-robdclark@gmail.com> References: <20231121003935.5868-1-robdclark@gmail.com> Precedence: bulk X-Mailing-List: linux-arm-msm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Rob Clark Now that it only handles unlock duty, drop the superfluous arg and rename it. Signed-off-by: Rob Clark --- drivers/gpu/drm/msm/msm_gem_submit.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/drivers/gpu/drm/msm/msm_gem_submit.c b/drivers/gpu/drm/msm/msm_gem_submit.c index d001bf286606..603f04d851d9 100644 --- a/drivers/gpu/drm/msm/msm_gem_submit.c +++ b/drivers/gpu/drm/msm/msm_gem_submit.c @@ -248,14 +248,10 @@ static int submit_lookup_cmds(struct msm_gem_submit *submit, return ret; } -/* Unwind bo state, according to cleanup_flags. In the success case, only - * the lock is dropped at the end of the submit (and active/pin ref is dropped - * later when the submit is retired). - */ -static void submit_cleanup_bo(struct msm_gem_submit *submit, int i, - unsigned cleanup_flags) +static void submit_unlock_bo(struct msm_gem_submit *submit, int i) { struct drm_gem_object *obj = submit->bos[i].obj; + unsigned cleanup_flags = BO_LOCKED; unsigned flags = submit->bos[i].flags & cleanup_flags; /* @@ -304,10 +300,10 @@ static int submit_lock_objects(struct msm_gem_submit *submit) } for (; i >= 0; i--) - submit_cleanup_bo(submit, i, BO_LOCKED); + submit_unlock_bo(submit, i); if (slow_locked > 0) - submit_cleanup_bo(submit, slow_locked, BO_LOCKED); + submit_unlock_bo(submit, slow_locked); if (ret == -EDEADLK) { struct drm_gem_object *obj = submit->bos[contended].obj; @@ -533,7 +529,6 @@ static int submit_reloc(struct msm_gem_submit *submit, struct drm_gem_object *ob */ static void submit_cleanup(struct msm_gem_submit *submit, bool error) { - unsigned cleanup_flags = BO_LOCKED; unsigned i; if (error) @@ -541,7 +536,7 @@ static void submit_cleanup(struct msm_gem_submit *submit, bool error) for (i = 0; i < submit->nr_bos; i++) { struct drm_gem_object *obj = submit->bos[i].obj; - submit_cleanup_bo(submit, i, cleanup_flags); + submit_unlock_bo(submit, i); if (error) drm_gem_object_put(obj); } From patchwork Tue Nov 21 00:38:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rob Clark X-Patchwork-Id: 745790 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="fEln3ZDf" Received: from mail-oa1-x2c.google.com (mail-oa1-x2c.google.com [IPv6:2001:4860:4864:20::2c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C8710D49; Mon, 20 Nov 2023 16:40:32 -0800 (PST) Received: by mail-oa1-x2c.google.com with SMTP id 586e51a60fabf-1f066fc2a28so3108796fac.0; Mon, 20 Nov 2023 16:40:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1700527232; x=1701132032; 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=AxPjYZ32BBCzKXQ5KBeoAc5/CWYpCWybJmLe95iBq8c=; b=fEln3ZDfwiwCzzicDTpFbD2F/grxJZscS9b5PFUr9SVgv1yyGXoBKQuY9QZ1nBUHoA hXNdWY4Z1s4swxu9SWuCgVXd/+Tnn54zYdATIYRVfJz9q+RlKe1dHn2ByrOd4PrTOeQj h4f7TIebfZqqeUriXmZ6fjWVkSDMdg2Odn0z28lhZW2t3SculodHlLWRCcImM/ok90d9 JJ/gVWPdkApQu/+Xqn+YjwssjUXZqj4L00nvN3jwr2mh6ivKd0J0litRKOtCnKZIMKcA U/cbGdR4O7LEO1nhqmY5DnK1K9q7M2BIM3EIjNB3CQkfgOTSrgWDEv0Jqtpkf4gTVi56 yyJA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700527232; x=1701132032; 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=AxPjYZ32BBCzKXQ5KBeoAc5/CWYpCWybJmLe95iBq8c=; b=rdB2HyZa6HnewnPnIoySDX/OrWzv/ZUFz5bzU9VYIqmYzFpGbdEKj4TuaurvKzt44X YCSi8CYuTPcjS8t6L8mo8zuho2qostLkbI+e7z43+R+mvMW6bB+Onb5A4ohTZfK8aDxL vK1IIbHhNJ0DZV9a/v8HKd8ejvDzcfmyVuQA3P+uNebDcQ4778G1Kj7z7rQda64poyqX EfJ2OGzFVD1QCv4duNhNVo/WeRQMFK0g1QQONbzujd4kZfdo++j2F5Am5cEfxPp6MQfI v2UfHFFIuqpo2K9lWJWq/oxdapb17G5QRXiWgS3ffp0zXUG1q756VyYXUk6LT/xEgTkC YA0A== X-Gm-Message-State: AOJu0YyEQBCICPVNmr5GufaN+SjSB8gRIMqCDRLLL9RILr8Kr2cKYlkS 814gE+JareozzjCL1+NUGG8= X-Google-Smtp-Source: AGHT+IF2yrgKf/ZIhHKifS6sSdREvPsGKX1yzt0OjmXQKViCC55+Hz1UC/MRYTiAmp2IJVBFZ86a0Q== X-Received: by 2002:a05:6871:8184:b0:1f9:4aee:6ef6 with SMTP id so4-20020a056871818400b001f94aee6ef6mr4200177oab.53.1700527232001; Mon, 20 Nov 2023 16:40:32 -0800 (PST) Received: from localhost ([47.215.232.245]) by smtp.gmail.com with ESMTPSA id c10-20020a631c4a000000b005b82611378bsm6610476pgm.52.2023.11.20.16.40.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Nov 2023 16:40:31 -0800 (PST) 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 v2 7/7] drm/msm/gem: Convert to drm_exec Date: Mon, 20 Nov 2023 16:38:51 -0800 Message-ID: <20231121003935.5868-8-robdclark@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231121003935.5868-1-robdclark@gmail.com> References: <20231121003935.5868-1-robdclark@gmail.com> Precedence: bulk X-Mailing-List: linux-arm-msm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Rob Clark Replace the ww_mutex locking dance with the drm_exec helper. v2: Error path fixes, move drm_exec_fini so we only call it once (and only if we have drm_exec_init() Signed-off-by: Rob Clark --- drivers/gpu/drm/msm/Kconfig | 1 + drivers/gpu/drm/msm/msm_gem.h | 5 +- drivers/gpu/drm/msm/msm_gem_submit.c | 119 +++++---------------------- 3 files changed, 24 insertions(+), 101 deletions(-) diff --git a/drivers/gpu/drm/msm/Kconfig b/drivers/gpu/drm/msm/Kconfig index 6309a857ca31..f91d87afc0d3 100644 --- a/drivers/gpu/drm/msm/Kconfig +++ b/drivers/gpu/drm/msm/Kconfig @@ -16,6 +16,7 @@ config DRM_MSM select DRM_DP_AUX_BUS select DRM_DISPLAY_DP_HELPER select DRM_DISPLAY_HELPER + select DRM_EXEC select DRM_KMS_HELPER select DRM_PANEL select DRM_BRIDGE diff --git a/drivers/gpu/drm/msm/msm_gem.h b/drivers/gpu/drm/msm/msm_gem.h index af884ced7a0d..7f34263048a3 100644 --- a/drivers/gpu/drm/msm/msm_gem.h +++ b/drivers/gpu/drm/msm/msm_gem.h @@ -9,6 +9,7 @@ #include #include +#include "drm/drm_exec.h" #include "drm/gpu_scheduler.h" #include "msm_drv.h" @@ -254,7 +255,7 @@ struct msm_gem_submit { struct msm_gpu *gpu; struct msm_gem_address_space *aspace; struct list_head node; /* node in ring submit list */ - struct ww_acquire_ctx ticket; + struct drm_exec exec; uint32_t seqno; /* Sequence number of the submit on the ring */ /* Hw fence, which is created when the scheduler executes the job, and @@ -287,8 +288,6 @@ struct msm_gem_submit { struct drm_msm_gem_submit_reloc *relocs; } *cmd; /* array of size nr_cmds */ struct { -/* make sure these don't conflict w/ MSM_SUBMIT_BO_x */ -#define BO_LOCKED 0x4000 /* obj lock is held */ uint32_t flags; union { struct drm_gem_object *obj; diff --git a/drivers/gpu/drm/msm/msm_gem_submit.c b/drivers/gpu/drm/msm/msm_gem_submit.c index 603f04d851d9..40878c26a749 100644 --- a/drivers/gpu/drm/msm/msm_gem_submit.c +++ b/drivers/gpu/drm/msm/msm_gem_submit.c @@ -248,85 +248,30 @@ static int submit_lookup_cmds(struct msm_gem_submit *submit, return ret; } -static void submit_unlock_bo(struct msm_gem_submit *submit, int i) -{ - struct drm_gem_object *obj = submit->bos[i].obj; - unsigned cleanup_flags = BO_LOCKED; - unsigned flags = submit->bos[i].flags & cleanup_flags; - - /* - * Clear flags bit before dropping lock, so that the msm_job_run() - * path isn't racing with submit_cleanup() (ie. the read/modify/ - * write is protected by the obj lock in all paths) - */ - submit->bos[i].flags &= ~cleanup_flags; - - if (flags & BO_LOCKED) - dma_resv_unlock(obj->resv); -} - /* This is where we make sure all the bo's are reserved and pin'd: */ static int submit_lock_objects(struct msm_gem_submit *submit) { - int contended, slow_locked = -1, i, ret = 0; - -retry: - for (i = 0; i < submit->nr_bos; i++) { - struct drm_gem_object *obj = submit->bos[i].obj; - - if (slow_locked == i) - slow_locked = -1; + int ret; - contended = i; + drm_exec_init(&submit->exec, DRM_EXEC_INTERRUPTIBLE_WAIT, submit->nr_bos); - if (!(submit->bos[i].flags & BO_LOCKED)) { - ret = dma_resv_lock_interruptible(obj->resv, - &submit->ticket); + drm_exec_until_all_locked (&submit->exec) { + for (unsigned i = 0; i < submit->nr_bos; i++) { + struct drm_gem_object *obj = submit->bos[i].obj; + ret = drm_exec_prepare_obj(&submit->exec, obj, 1); + drm_exec_retry_on_contention(&submit->exec); if (ret) - goto fail; - submit->bos[i].flags |= BO_LOCKED; + goto error; } } - ww_acquire_done(&submit->ticket); - return 0; -fail: - if (ret == -EALREADY) { - SUBMIT_ERROR(submit, "handle %u at index %u already on submit list\n", - submit->bos[i].handle, i); - ret = -EINVAL; - } - - for (; i >= 0; i--) - submit_unlock_bo(submit, i); - - if (slow_locked > 0) - submit_unlock_bo(submit, slow_locked); - - if (ret == -EDEADLK) { - struct drm_gem_object *obj = submit->bos[contended].obj; - /* we lost out in a seqno race, lock and retry.. */ - ret = dma_resv_lock_slow_interruptible(obj->resv, - &submit->ticket); - if (!ret) { - submit->bos[contended].flags |= BO_LOCKED; - slow_locked = contended; - goto retry; - } - - /* Not expecting -EALREADY here, if the bo was already - * locked, we should have gotten -EALREADY already from - * the dma_resv_lock_interruptable() call. - */ - WARN_ON_ONCE(ret == -EALREADY); - } - +error: return ret; } -static int submit_fence_sync(struct msm_gem_submit *submit, bool no_implicit) +static int submit_fence_sync(struct msm_gem_submit *submit) { int i, ret = 0; @@ -334,22 +279,6 @@ static int submit_fence_sync(struct msm_gem_submit *submit, bool no_implicit) struct drm_gem_object *obj = submit->bos[i].obj; bool write = submit->bos[i].flags & MSM_SUBMIT_BO_WRITE; - /* NOTE: _reserve_shared() must happen before - * _add_shared_fence(), which makes this a slightly - * strange place to call it. OTOH this is a - * convenient can-fail point to hook it in. - */ - ret = dma_resv_reserve_fences(obj->resv, 1); - if (ret) - return ret; - - /* If userspace has determined that explicit fencing is - * used, it can disable implicit sync on the entire - * submit: - */ - if (no_implicit) - continue; - /* Otherwise userspace can ask for implicit sync to be * disabled on specific buffers. This is useful for internal * usermode driver managed buffers, suballocation, etc. @@ -529,17 +458,14 @@ static int submit_reloc(struct msm_gem_submit *submit, struct drm_gem_object *ob */ static void submit_cleanup(struct msm_gem_submit *submit, bool error) { - unsigned i; - - if (error) + if (error) { submit_unpin_objects(submit); - - for (i = 0; i < submit->nr_bos; i++) { - struct drm_gem_object *obj = submit->bos[i].obj; - submit_unlock_bo(submit, i); - if (error) - drm_gem_object_put(obj); + /* job wasn't enqueued to scheduler, so early retirement: */ + msm_submit_retire(submit); } + + if (submit->exec.objects) + drm_exec_fini(&submit->exec); } void msm_submit_retire(struct msm_gem_submit *submit) @@ -733,7 +659,6 @@ int msm_ioctl_gem_submit(struct drm_device *dev, void *data, struct msm_submit_post_dep *post_deps = NULL; struct drm_syncobj **syncobjs_to_reset = NULL; int out_fence_fd = -1; - bool has_ww_ticket = false; unsigned i; int ret; @@ -839,15 +764,15 @@ int msm_ioctl_gem_submit(struct drm_device *dev, void *data, goto out; /* copy_*_user while holding a ww ticket upsets lockdep */ - ww_acquire_init(&submit->ticket, &reservation_ww_class); - has_ww_ticket = true; ret = submit_lock_objects(submit); if (ret) goto out; - ret = submit_fence_sync(submit, !!(args->flags & MSM_SUBMIT_NO_IMPLICIT)); - if (ret) - goto out; + if (!(args->flags & MSM_SUBMIT_NO_IMPLICIT)) { + ret = submit_fence_sync(submit); + if (ret) + goto out; + } ret = submit_pin_objects(submit); if (ret) @@ -978,8 +903,6 @@ int msm_ioctl_gem_submit(struct drm_device *dev, void *data, out: submit_cleanup(submit, !!ret); - if (has_ww_ticket) - ww_acquire_fini(&submit->ticket); out_unlock: mutex_unlock(&queue->lock); out_post_unlock: