From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wr1-f41.google.com (mail-wr1-f41.google.com [209.85.221.41]) (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 C673A39B952 for ; Sat, 4 Jul 2026 08:41:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.41 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783154498; cv=none; b=UsB6P6FcrerSt7oLsG2R/NZmBqD6OGFdUusGgaZ4yxnJMa/2f/amIvxREaA/VW2x0V9giVQtWSkShjlkw7H4ObC6wi8ehqOfYY4MEKuDnMsVVJyrlH4HQp0RVd2+FFHfBoFp3/uhxuHGV3las6fyik9Njt1TaQynGQcA5DfffCo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783154498; c=relaxed/simple; bh=Gy+dRhyxucoXfw7UnF8+YYDrnre5sYD78ZuVYjnQOn0=; h=From:To:Subject:Date:Message-ID:MIME-Version:Content-Type; b=PcTTmJO0xy4yrrZFO/EyngBPewpCaxaqnjbvv6X2gIu3xzOTuLEL8deUvdexFb5xLN8ZYvCZubr7HNuuT4B7lF5jDAzPnLPCJZsq+MZwxuNgpwgLP87sdC5flQ16S6xpnFUdFnTZ7v/m4HIOCfCXmXM0YJw6KcQZbxUmsvlQ4Mk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=qTvjqQmL; arc=none smtp.client-ip=209.85.221.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="qTvjqQmL" Received: by mail-wr1-f41.google.com with SMTP id ffacd0b85a97d-4728c12ba97so755004f8f.0 for ; Sat, 04 Jul 2026 01:41:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1783154495; x=1783759295; darn=vger.kernel.org; h=content-transfer-encoding:reply-to:mime-version:message-id:date :subject:to:from:from:to:cc:subject:date:message-id:reply-to; bh=2PKlx1RZlE0eFooFNfeW6nXm/sxrhaIM7NVbZ8hGbT4=; b=qTvjqQmLtb8OmMFnkxG8mk7dv+uArKXQ/G0LJqWTwpxea7o9rfv9cy18f4gTtvU0rp pZ/OBB/krKr82ajMlHxILO9cJv/L4GClq54axCSCA7Mwqao03dzAIWA27Zb5qoge6sgU clW/O2Fd1FS74XkpTJGOv9dvz+k1Pyny12LR0Lc3kTsgzIuGR41ldomJ3/nv1rEhyEDC mf7HdJaQbqTcvskmtd0ScHLbxgl0datVfHwASFnAQ2QX+kLEm+WEVeEghRSYx7q1gTbd QniTO0ZfvFFH8c2/OYpp/Ql0HGlVzngzE9UOw/5Ct5GNnpvVKMWmFtd4gkXYxD+lZKDQ +G6Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1783154495; x=1783759295; h=content-transfer-encoding:reply-to:mime-version:message-id:date :subject:to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=2PKlx1RZlE0eFooFNfeW6nXm/sxrhaIM7NVbZ8hGbT4=; b=SCpQZkEcKCGaGyXeVymybzpGt+oT3dnf7/Dvob9tR5pce6dVeYTWGpQgt0l/kIs7km z9BgIE4sEQGFriLtEbsmPp+0ENIlhgQxwCxrMmpbWfTkQ5hZOLQEA4jubOxpgP04Czgq SjXcP+yGpBxkahoabYMXWQORwjI2aKU68g/czCNYMt2+QdqjwZDcH+y2kzAIb0V/QeNs YGC+t+1JHTwMeX0ft9+7rBQbH4ENQbti3hFoJ9YE5o8tF8es7sqgcHSpBbezyZWo7EJb FOiOZ44pz9t2bhfQODQxcOTYaLFislnWIKJI7ZIyFFarbWPRPkXY7X/Zz1REl+reE7yt 1rzA== X-Forwarded-Encrypted: i=1; AHgh+Rps0x4hen5lxkuDmnsIr30/Gk/Y1nBuEqlTVvQdYrUhOOagO4DKy4XG0E8tuBWPizqiExJv1MRkKyQ7xVM=@vger.kernel.org X-Gm-Message-State: AOJu0Yw9jMTwbbbHjJ8XdWGLP4EF2fjaVyyDgKpJq92wvTJiTQywX6ia aQZDhBhOaqCu60VHWmPUaOPU/0z/b5vrnrVJtf4QWQQKOsDxH/FKdFsCLY0L2g== X-Gm-Gg: AfdE7cmhex1mdvhu2gGyFA6CnlHiJp+ja6DsRKVh9HCa7mxPmwDbKu0AxmuSBcWB958 eQytP2aIBPUtByOrdI+Uwx2On6eNnVeYZe80fwiL3KqQJ/uydD++GFTXioRd9mz1nafcBc6hbsf LN972MY8d7dgYFqZj5pNLF35gaGGYtV6ildUejqL2P36JbRMWJh0oJfwCqzrvd9y+FGYmU/POp1 XyyhNZ//ITXWIxqrtGIqR/ODt5IQL+jU3mfXoswfIBUBVGaCOKRkqzb3lxjwAXUi0A1BVKvfnRw /ALCCvTdgMUJDneJJtdzXFY6YQKjwUCZHTw0Lt7QhVXjX2+M5fq4qPH9f9T+R11jGowkE8JSbQA dzvYKAsP7Ch2G59Zp95n48RasXvflHnLtCzdKFv6LTD7Rc3n+wU6iPLsyDvwJPXPpWaaCsfFNCg 6hYDtdaMNMEgs8/MVXA9XFmQ0G2Q== X-Received: by 2002:a05:6000:469b:b0:46e:624e:3c2f with SMTP id ffacd0b85a97d-47aab77082bmr1649075f8f.47.1783154494914; Sat, 04 Jul 2026 01:41:34 -0700 (PDT) Received: from able.fritz.box ([2a00:e180:15be:2e00:3669:f2aa:a674:f340]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-47aa039bcdasm6519563f8f.21.2026.07.04.01.41.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 04 Jul 2026 01:41:34 -0700 (PDT) From: "=?UTF-8?q?Christian=20K=C3=B6nig?=" X-Google-Original-From: =?UTF-8?q?Christian=20K=C3=B6nig?= To: mikhail.v.gavrilov@gmail.com, dri-devel@lists.freedesktop.org, amd-gfx@lists.freedesktop.org, peterz@infradead.org, jpoimboe@kernel.org, llvm@lists.linux.dev, oe-kbuild-all@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH] drm/drm_exec: avoid indirect goto Date: Sat, 4 Jul 2026 10:41:33 +0200 Message-ID: <20260704084133.122053-1-christian.koenig@amd.com> X-Mailer: git-send-email 2.43.0 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=UTF-8 Reply-To: christian.koenig@amd.com Content-Transfer-Encoding: 8bit The drm_exec component uses a variable with scope limited to the for() and an indirect goto to allow instantiating multiple macros in the same function. This unfortunately doesn't work well with certain compilers when the indirect goto can't be lowered to a direct jump. Switch the indirect goto to a direct goto, the drawback is that we now can't use the dma_exec_until_all_locked() macro in the same function multiple times. The is currently only one user of this and only as a hacky workaround which is about to be removed. So document that the __label__ statement should be used when the macro is used multiple times and fix the tests and the only use case where that is necessary. Suggested-by: Peter Zijlstra Signed-off-by: Christian König --- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 2 ++ drivers/gpu/drm/tests/drm_exec_test.c | 24 ++++++++++++------ include/drm/drm_exec.h | 34 ++++++++++++++------------ 3 files changed, 36 insertions(+), 24 deletions(-) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c index fee4c94c2585..fc28d0fdad37 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c @@ -3011,6 +3011,8 @@ bool amdgpu_vm_handle_fault(struct amdgpu_device *adev, u32 pasid, is_compute_context = vm->is_compute_context; if (is_compute_context) { + __label__ drm_exec_retry; + /* Release the root PD lock since svm_range_restore_pages * might try to take it. * TODO: rework svm_range_restore_pages so that this isn't diff --git a/drivers/gpu/drm/tests/drm_exec_test.c b/drivers/gpu/drm/tests/drm_exec_test.c index 2fc47f3b463b..7a374e462348 100644 --- a/drivers/gpu/drm/tests/drm_exec_test.c +++ b/drivers/gpu/drm/tests/drm_exec_test.c @@ -180,19 +180,27 @@ static void test_multiple_loops(struct kunit *test) { struct drm_exec exec; - drm_exec_init(&exec, DRM_EXEC_INTERRUPTIBLE_WAIT, 0); - drm_exec_until_all_locked(&exec) { - break; + __label__ drm_exec_retry; + + drm_exec_init(&exec, DRM_EXEC_INTERRUPTIBLE_WAIT, 0); + drm_exec_until_all_locked(&exec) + { + break; + } + drm_exec_fini(&exec); } - drm_exec_fini(&exec); - drm_exec_init(&exec, DRM_EXEC_INTERRUPTIBLE_WAIT, 0); - drm_exec_until_all_locked(&exec) { - break; + __label__ drm_exec_retry; + + drm_exec_init(&exec, DRM_EXEC_INTERRUPTIBLE_WAIT, 0); + drm_exec_until_all_locked(&exec) + { + break; + } + drm_exec_fini(&exec); } - drm_exec_fini(&exec); KUNIT_SUCCEED(test); } diff --git a/include/drm/drm_exec.h b/include/drm/drm_exec.h index 8725ba92ff91..cc2937185a9f 100644 --- a/include/drm/drm_exec.h +++ b/include/drm/drm_exec.h @@ -101,17 +101,6 @@ drm_exec_obj(struct drm_exec *exec, unsigned long index) #define drm_exec_for_each_locked_object_reverse(exec, obj) \ __drm_exec_for_each_locked_object_reverse(exec, obj, __UNIQUE_ID(drm_exec)) -/* - * Helper to drm_exec_until_all_locked(). Don't use directly. - * - * Since labels can't be defined local to the loop's body we use a jump pointer - * to make sure that the retry is only used from within the loop's body. - */ -#define __drm_exec_until_all_locked(exec, _label) \ -_label: \ - for (void *const __maybe_unused __drm_exec_retry_ptr = &&_label; \ - drm_exec_cleanup(exec);) - /** * drm_exec_until_all_locked - loop until all GEM objects are locked * @exec: drm_exec object @@ -119,9 +108,18 @@ _label: \ * Core functionality of the drm_exec object. Loops until all GEM objects are * locked and no more contention exists. At the beginning of the loop it is * guaranteed that no GEM object is locked. + * + * A global label name drm_exec_retry is used, if you need to use more than one + * instance of this macro in the same function the label needs to be made local + * to the block with the __label__ keyword. */ #define drm_exec_until_all_locked(exec) \ - __drm_exec_until_all_locked(exec, __UNIQUE_ID(drm_exec)) + for (bool const __maybe_unused __drm_exec_loop = false; \ + drm_exec_cleanup(exec);) \ + if (false) { \ +drm_exec_retry: __maybe_unused; \ + continue; \ + } else /** * drm_exec_retry_on_contention - restart the loop to grap all locks @@ -129,12 +127,14 @@ _label: \ * * Control flow helper to continue when a contention was detected and we need to * clean up and re-start the loop to prepare all GEM objects. + * The __drm_exec_loop check exists to prevent usage outside of an + * drm_exec_until_all_locked() loop. */ #define drm_exec_retry_on_contention(exec) \ do { \ if (unlikely(drm_exec_is_contended(exec))) \ - goto *__drm_exec_retry_ptr; \ - } while (0) + goto drm_exec_retry; \ + } while (__drm_exec_loop) /** * drm_exec_is_contended - check for contention @@ -154,12 +154,14 @@ static inline bool drm_exec_is_contended(struct drm_exec *exec) * * Unconditionally retry the loop to lock all objects. For consistency, * the exec object needs to be newly initialized. + * The __drm_exec_loop check exists to prevent usage outside of an + * drm_exec_until_all_locked() loop. */ #define drm_exec_retry(_exec) \ do { \ WARN_ON((_exec)->contended != DRM_EXEC_DUMMY); \ - goto *__drm_exec_retry_ptr; \ - } while (0) + goto drm_exec_retry; \ + } while (__drm_exec_loop) /** * drm_exec_ticket - return the ww_acquire_ctx for this exec context -- 2.43.0