Received: by 2002:a05:6358:c692:b0:131:369:b2a3 with SMTP id fe18csp472925rwb; Thu, 27 Jul 2023 16:11:32 -0700 (PDT) X-Google-Smtp-Source: APBJJlHqr92E/qMBzyMyTmaYePxJURwtNmt1xcwsxr/r+xvdoO9dXLU0Dqka1SFoZiuL6vciV7FS X-Received: by 2002:a05:6a00:150a:b0:66a:5d4a:e47d with SMTP id q10-20020a056a00150a00b0066a5d4ae47dmr109317pfu.8.1690499492118; Thu, 27 Jul 2023 16:11:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690499492; cv=none; d=google.com; s=arc-20160816; b=ZaMGB6zTIHJLvvKDUC6uEd7yyZYiMvV0fOcgNF4MPuyovdeWdUXBTnRUAe2Ro5MsHK LrZ8zY+H9lu4QzhbS8vFgG6IpkEgWuTjk21Rwx2t83fNAkycAnLfDozQ4ewZhuAsA+hA cBzuZTRTvACmS9hqyfGUm8000WF0rbvuNX1j20FHlru/8FBc1n2hcCLtKRzDq67Xgeli G15C9qi80yswEFtNbpYiQ16Icx2cVFvK/9WF9sT39HmqR77AmJSAtSbMQu4lBWxwfCUu UEpZPTomM92y8tuZioA97zufZral95txd5c4pvVJ7waV8xmChoGrL3UGt6BpRGQGvOc9 eGoA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:mime-version:date :dkim-signature; bh=h8M17W+SY6LNnIrBQCPmXoDqQ4N8XZNCU3T7YHTRw88=; fh=v/rtD6QXxVsGbeTOX1oLW82Q0OA1CKnQP0H0cIv7Qkk=; b=PMR55gTuEco0P+U6MI2do/P69nBkmNTqjKE+E9pzhvta/ZsZZt0RItpMKZ554n89KM k3FJXf6nchbfEWfI23jDgEY+oeHLNy2cGmuVoDFc3SzjzM9m5tWgYDZhzTySOYyVSLWu hozyuIB/SW+nc62eHnCb+1H5E03BiJdjQrlQNLr1fnwP3lnYo4kGJKjqFFMiSSkPyKoL dDLQ9iQDddk5+WJDUSIJx/w5CWZDFl/oi/1f/3C4fW+34sCfBisyzm88Dj04Wd5imOVg 0m9o+e489MVS7SH/QIzIx6RM0aowGrca4ok6Hdp/V8yVBwAklcxYqx1kjM4VUnUIYmsu TCyQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=qKt37uGq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id fc14-20020a056a002e0e00b0068208d19b15si2022143pfb.249.2023.07.27.16.11.19; Thu, 27 Jul 2023 16:11:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=qKt37uGq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231602AbjG0WrR (ORCPT + 99 others); Thu, 27 Jul 2023 18:47:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55890 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229804AbjG0WrP (ORCPT ); Thu, 27 Jul 2023 18:47:15 -0400 Received: from mail-yw1-x1149.google.com (mail-yw1-x1149.google.com [IPv6:2607:f8b0:4864:20::1149]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 911DF1BC1 for ; Thu, 27 Jul 2023 15:47:14 -0700 (PDT) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-583f048985bso15006157b3.2 for ; Thu, 27 Jul 2023 15:47:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1690498034; x=1691102834; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=h8M17W+SY6LNnIrBQCPmXoDqQ4N8XZNCU3T7YHTRw88=; b=qKt37uGq/wscmlYr8MsZg//pXb6RySyaO4y6NJeuPda08KKiBjtJBS67P14T6qV1M0 LL9mjLjQYaJiLnSUF4EWtgT2q06OnX5y+YpaxLHO6f+6a3EIbFNrTc+7RB4U+ZiuyvVa wVuGmAuWeRbHjs/5JgVP2QOlnsY5lyobE6B9bss/BiV7uNJCKRAb8KCsQodxtcNumAeV tfOwogzv3MOn84SrebCIma7DNohFZJb5l213YxgBfudwFCoGEAXHH/L6snpDUdyijney 6+Vc/w4tJvqI9+iRC6+Sw/3tZ8W5zMhUWDBE49fQTskT0ezoLHQgsg5p62+Ls2Lm9eBP fV9A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690498034; x=1691102834; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=h8M17W+SY6LNnIrBQCPmXoDqQ4N8XZNCU3T7YHTRw88=; b=XtlUZ5LdxHjItjGAiEt+7IWwcfhmMR4lYDo3cYPcSGJ+N3ZAQOHwK+9Lr7MyyBzaxf kf0U/z3TTtCeXOXg8JkImgmcFfD7BMfnkpPvvhrumaBw++rmlSaM5yWvFdW+birmhBqz gSr7yAjdpzcNR+UgYZ8EsYis6Akkn4a4t/OygbaZCTNSLBQyh7zm490sk3QgPpjWXXts HFT+FG7HJM5VLh3RUWcM8PwPuRP4W+rMRNK/vyPw7/1BxaAZSGdNi9OfNTrZwRqamtZm 1cOZ9HnIQDWS8sjpTqNN4XwXlhQLos5Fvlk7NJeIQp+Be6uopuDcVw9oZC6FyCw7AYwC kCGQ== X-Gm-Message-State: ABy/qLYzZ/BTXWmkHw6LO9/wjV7f4IrYzfMVXF9+mAoO3LIfIfKNwnOc MMuoZSEc3xF2CVLOv9FqAZUVHY/nDgoctJH2z64= X-Received: from ndesaulniers-desktop.svl.corp.google.com ([2620:15c:2d1:203:659f:4728:cfbb:8cc3]) (user=ndesaulniers job=sendgmr) by 2002:a05:690c:721:b0:573:8316:8d04 with SMTP id bt1-20020a05690c072100b0057383168d04mr212ywb.4.1690498033839; Thu, 27 Jul 2023 15:47:13 -0700 (PDT) Date: Thu, 27 Jul 2023 15:47:09 -0700 Mime-Version: 1.0 X-B4-Tracking: v=1; b=H4sIAOzzwmQC/x2MQQqAIBAAvxJ7TjAlwr4SHdS2XCgLpQjEv7d0n GGYAhkTYYaxKZDwoUxnZOjaBnywcUNBCzMoqbQc1CDssWzXLYz2Enstlek74NjZjMIlG33gPN7 7zvJKuNL736e51g9FP1hgbQAAAA== X-Developer-Key: i=ndesaulniers@google.com; a=ed25519; pk=UIrHvErwpgNbhCkRZAYSX0CFd/XFEwqX3D0xqtqjNug= X-Developer-Signature: v=1; a=ed25519-sha256; t=1690498032; l=3429; i=ndesaulniers@google.com; s=20220923; h=from:subject:message-id; bh=h5xjymXwHB0lf01RIpHtYLR4vTj4v+sUfx87gYKkB7Y=; b=N2uJPCF50jFFN4PLKe1RA7MLTy5RlIkmUWI7lMBscLyrcTCLI3tbqj7jsQDczYGb8rXqmc7m4 fVVfKltnA+lByM/BerwonDXLZydewq7ck6QpVuol9QtpGTy2Znh+q3q X-Mailer: b4 0.12.2 Message-ID: <20230727-amdgpu-v1-1-a95690e75388@google.com> Subject: [PATCH] drm: fix indirect goto into statement expression UB From: ndesaulniers@google.com To: Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Daniel Vetter , Nathan Chancellor , Tom Rix Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, llvm@lists.linux.dev, Naresh Kamboju , Nick Desaulniers Content-Type: text/plain; charset="utf-8" X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL 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 A new diagnostic in clang-17 now produces the following build error: drivers/gpu/drm/tests/drm_exec_test.c:41:3: error: cannot jump from this indirect goto statement to one of its possible targets 41 | drm_exec_retry_on_contention(&exec); | ^ include/drm/drm_exec.h:96:4: note: expanded from macro 'drm_exec_retry_on_contention' 96 | goto *__drm_exec_retry_ptr; | ^ drivers/gpu/drm/tests/drm_exec_test.c:39:2: note: possible target of indirect goto statement 39 | drm_exec_until_all_locked(&exec) { | ^ include/drm/drm_exec.h:79:33: note: expanded from macro 'drm_exec_until_all_locked' 79 | __label__ __drm_exec_retry; drivers/gpu/drm/tests/drm_exec_test.c:39:2: note: jump enters a statement expression The GCC manually currently states that: >> Jumping into a statement expression with a computed goto (see Labels >> as Values) has undefined behavior. So the diagnostic appears correct, even if codegen happened to produce working code. Looking closer at this code, while the original combination of statement expression, local label, and computed/indirect goto GNU C expressions were clever, a simple while loop and continue block might have sufficed. This approach might not work as expected if drm_exec_until_all_locked "loops" can be nested, but that doesn't appear to be an existing use case in the codebase. Fixes: commit 09593216bff1 ("drm: execution context for GEM buffers v7") Link: https://gcc.gnu.org/onlinedocs/gcc/Statement-Exprs.html Link: https://github.com/ClangBuiltLinux/linux/issues/1890 Link: https://github.com/llvm/llvm-project/commit/20219106060208f0c2f5d096eb3aed7b712f5067 Reported-by: Nathan Chancellor Reported-by: Naresh Kamboju Signed-off-by: Nick Desaulniers --- include/drm/drm_exec.h | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/include/drm/drm_exec.h b/include/drm/drm_exec.h index 73205afec162..393ac022ed3a 100644 --- a/include/drm/drm_exec.h +++ b/include/drm/drm_exec.h @@ -70,18 +70,9 @@ struct drm_exec { * 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. - * - * Since labels can't be defined local to the loops body we use a jump pointer - * to make sure that the retry is only used from within the loops body. */ #define drm_exec_until_all_locked(exec) \ - for (void *__drm_exec_retry_ptr; ({ \ - __label__ __drm_exec_retry; \ -__drm_exec_retry: \ - __drm_exec_retry_ptr = &&__drm_exec_retry; \ - (void)__drm_exec_retry_ptr; \ - drm_exec_cleanup(exec); \ - });) + while(drm_exec_cleanup(exec)) /** * drm_exec_retry_on_contention - restart the loop to grap all locks @@ -93,7 +84,7 @@ __drm_exec_retry: \ #define drm_exec_retry_on_contention(exec) \ do { \ if (unlikely(drm_exec_is_contended(exec))) \ - goto *__drm_exec_retry_ptr; \ + continue; \ } while (0) /** --- base-commit: 451cc82bd11eb6a374f4dbcfc1cf007eafea91ab change-id: 20230727-amdgpu-93c0e5302951 Best regards, -- Nick Desaulniers