Received: by 2002:a05:6358:c692:b0:131:369:b2a3 with SMTP id fe18csp507532rwb; Thu, 27 Jul 2023 16:52:12 -0700 (PDT) X-Google-Smtp-Source: APBJJlFDZSHwxmuvYg2zW8ylBU9rpjVtPoxAFp0xSli5nB3SlvTUib3yv7xIf4vL8dcduIIz1+7B X-Received: by 2002:a9d:4d83:0:b0:6b5:ee8f:73af with SMTP id u3-20020a9d4d83000000b006b5ee8f73afmr691309otk.5.1690501932535; Thu, 27 Jul 2023 16:52:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690501932; cv=none; d=google.com; s=arc-20160816; b=EKE+6mTvev+TZfBQCKbF5zDLS7xa/Ei+cc34l19bNOq06XZpFrMausRokAnZ1m7oJW TQWaRsgvKQuz5nco2zdcUdtYJNPdHzbyuKPZmbX9gKRVCYFA0/CJWNUelP0YrViAxQ+B AS0og+bnQUZxtOgdWH2Oq1h4KvyXzruVmPRxq8/Z0QqhlP5UyXg/+L1IrMYsGh22FSiy w9/SLdhSa+iVScbdjPEhZGMD+/K/yp5+CVUPQ7FRWvFVz0UL2rTy7NTJKpb7SJm4Mp6O nCacKzlXvE6THQqWoajRHtfykyyeKUOd4PONRfaF/K76qLAKqWH3BrJM9HBpQS4vcmX5 nBoA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=7NYvlsFz+3bTMfsTHbgY87g/2XWXC64dEH3md2UPJ6g=; fh=jwwqedQQfpx4/dzJey5//fD2XY5q3P6D5mporDYb9oQ=; b=P8iCKeiMw1J/V/bXcnm6dxk6dboe5eYLwDgBh0Utk3UGy94gJr3XZYXRLQi7y4fbTt pzFX71Io+zJpwgfnq1q1FX7HblnidGNcN5QmXcPywrBYloz6OyKnw+DEfeq8Ey7IkM8M 6eJU23tiTj65QwOsDLVGtFooGLp6JJ6bqectG8CU1WEat0429Uh7DigXCRXdepAF0vO5 05btB/SuV6b3hw45p83v5HV4E9RXkcxxbSMLhEx8N7RsZv4VC7YXbpKkvQtgk3S21j/3 Emv6JIIMGxK1xgLbo5tCkKoGQ4c6YxHCoA8fodfk6Ypyw20Jef8YV4pA9rT8PD4hZmMz c+fw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=bEhEEN4a; 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 x9-20020a634a09000000b00563d9de9a2csi1875432pga.572.2023.07.27.16.51.49; Thu, 27 Jul 2023 16:52:12 -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=bEhEEN4a; 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 S230440AbjG0WtW (ORCPT + 99 others); Thu, 27 Jul 2023 18:49:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56440 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229804AbjG0WtV (ORCPT ); Thu, 27 Jul 2023 18:49:21 -0400 Received: from mail-ua1-x92b.google.com (mail-ua1-x92b.google.com [IPv6:2607:f8b0:4864:20::92b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6D1151FC9 for ; Thu, 27 Jul 2023 15:49:20 -0700 (PDT) Received: by mail-ua1-x92b.google.com with SMTP id a1e0cc1a2514c-79a46f02d45so667572241.0 for ; Thu, 27 Jul 2023 15:49:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1690498159; x=1691102959; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=7NYvlsFz+3bTMfsTHbgY87g/2XWXC64dEH3md2UPJ6g=; b=bEhEEN4aoXgcgHk+7n4UIOPmdxMoQPFwdze+KHGhhUBZ5Ak4zM9xoDWKBQegUlH/o7 BStTXrDJWU2jomd5NOCIoRJGqSxTBQaJTtKUEW8eIg4sPZVH8sUwSxz51RS2evN/OEh9 zJwPquuESOUYwnk5GyJlbxbtXxtv3gVbrQCB8zee/hny6Oz8lg0yh/V4tjE4kjKTkwMX B9PClknNpeEICAlRKvJE+8th8h16OyO3xNr+1/gCRnbIVJYbEiy4yvZor+W8JIaMJZk8 m76qHkVn4y6ZWmBNkEVRZfKgOZ3T46OqYVOtF4eHpP6NBy7u2rlntuIEcQiVresy9Nl1 ieSg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690498159; x=1691102959; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=7NYvlsFz+3bTMfsTHbgY87g/2XWXC64dEH3md2UPJ6g=; b=EDmmsZFq2R0lhE/eL0f5QNMV/4apsQHV7p2EvYDY34rfQXHyp6bPgkEDVnblj047rf ID6K8QuOB15Od5XblsyGUgERMX1pmAgtGjbdM6mfa6i8ZbqkoFykdQYQGBD2tuF83Sbc bVa5hLNqYJ90QQhDqLUlx6qfsE6wZf4Jy92HZ0kRy3ay6XScoT/9qPsc09nJbSYsOseY pSs9JE8ylIgjHUwFS7EbBFroUAJbuFVOxNIrxty0ghGBNiHnTPrxJ1X4kFotJHxIjw1O zot6pIWs2iSB1bAUYKs2FniCpk7vgq1jFeQJmdtcZPG/O621O4RRG2miNGOmBEVeL3gZ GT1w== X-Gm-Message-State: ABy/qLYVI+TsZ2a+sM0ud8ymoLg/gwCmlqQAcLPpIGsbLXHRrreE4Ks5 96w4vgDPXYFcFMvH3os4vy4/+wDBBKbuFNi+qQFJmg== X-Received: by 2002:a67:fb46:0:b0:443:70ec:d28b with SMTP id e6-20020a67fb46000000b0044370ecd28bmr845103vsr.19.1690498159357; Thu, 27 Jul 2023 15:49:19 -0700 (PDT) MIME-Version: 1.0 References: <20230727-amdgpu-v1-1-a95690e75388@google.com> In-Reply-To: <20230727-amdgpu-v1-1-a95690e75388@google.com> From: Nick Desaulniers Date: Thu, 27 Jul 2023 15:49:07 -0700 Message-ID: Subject: Re: [PATCH] drm: fix indirect goto into statement expression UB 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 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_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 On Thu, Jul 27, 2023 at 3:47=E2=80=AFPM wrote: > > 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/20219106060208f0c2f5d09= 6eb3aed7b712f5067 > 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 object= s 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 p= ointer > - * 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 =3D &&__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; \ d'oh that's going to continue the do {} while(0) ... let me send a v2... > } while (0) > > /** > > --- > base-commit: 451cc82bd11eb6a374f4dbcfc1cf007eafea91ab > change-id: 20230727-amdgpu-93c0e5302951 > > Best regards, > -- > Nick Desaulniers > --=20 Thanks, ~Nick Desaulniers