Message ID | 20230731123625.3766-1-christian.koenig@amd.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:918b:0:b0:3e4:2afc:c1 with SMTP id s11csp2015554vqg; Mon, 31 Jul 2023 06:29:58 -0700 (PDT) X-Google-Smtp-Source: APBJJlHvlNEeIHuciCfHQdkgXVNr30LUiRmBtJwJ6gnCBBdVuESW5/3Y+1mQlp5nMxv3vI/qYXdj X-Received: by 2002:a05:6a00:2d94:b0:682:7d8a:f887 with SMTP id fb20-20020a056a002d9400b006827d8af887mr10714371pfb.30.1690810197901; Mon, 31 Jul 2023 06:29:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690810197; cv=none; d=google.com; s=arc-20160816; b=nJKFnkyDR7SzPiSKmNz7mKBe03qiPy0hzI5G+NShB+emGW6i5wGJ+PDDbT1TMtEYmg cVnu0hcRES2uYULauuavg6ha7NqP+pWP7pIKx8JVECQ90Fx0B7cJQJFecE3iGe1JXlDv Ajra7FmPl6AqJjn36kFkfgdVxM8sqDTv9jOzqiRMw5u/BlTgRu9TZ/K9lKve0rOEKH/I nUPPeAcGWS1hQ0xUtG7PZgEhHUkg7e+j56Mq5C8q2+1feglBqTvotNyauJAXcCgVKkGo 4MhzdLWNx3JSlBT4EQjO0QAJTsi+4fxWWuGP1VPmABepzJ1J2+stkpq7ENufodwLLvDe UTSA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:to:from:dkim-signature; bh=zf2opAJWpIyipvbGeaqpygqhHDn8/Va05DqGxlPq9ZA=; fh=iOzavT6TSyvpuKyMWthinQzWOTlCxpyYJVTD6/U4YNk=; b=NF1LWtgmH7uDqzbPqoAZRIu8yNudQBSz0ESWU9NTYTijZRvhSqY+iM7xOWOcPSbtUk gUXG9E5FlfU/J//gMkNwkflDjSB/Tu/8dEbXttNEKEkaMQ7AWVOuDsZ8kSr+CgtAIFpi 4RHt/B3Mu0/Ittu5I2Idc3g0k4EP1KxnWS/gTcgYBExycHK9+wfcPTl1ds7zvKCpWVBL +6l9M2iWOXYGMwUGIa0nxbKN+a7BDL3BquGLSQj/o3AyOjG8wDFRs4CTXmeqSnOVJY+2 42AAnKr8bmOOUVitlVUUvP/1dqrqZrYeyM8kxnQvGOPMxNZoMcsFOBUeFe7yTAA1h+Mz sTxQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=nGLy3tsl; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z25-20020a056a001d9900b006870cd8a877si5510883pfw.172.2023.07.31.06.29.45; Mon, 31 Jul 2023 06:29:57 -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=@gmail.com header.s=20221208 header.b=nGLy3tsl; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232748AbjGaMgc (ORCPT <rfc822;dengxinlin2429@gmail.com> + 99 others); Mon, 31 Jul 2023 08:36:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56932 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230226AbjGaMga (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Mon, 31 Jul 2023 08:36:30 -0400 Received: from mail-wr1-x435.google.com (mail-wr1-x435.google.com [IPv6:2a00:1450:4864:20::435]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 702E9133 for <linux-kernel@vger.kernel.org>; Mon, 31 Jul 2023 05:36:29 -0700 (PDT) Received: by mail-wr1-x435.google.com with SMTP id ffacd0b85a97d-313e742a787so3025078f8f.1 for <linux-kernel@vger.kernel.org>; Mon, 31 Jul 2023 05:36:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1690806988; x=1691411788; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:from:to:cc:subject:date:message-id:reply-to; bh=zf2opAJWpIyipvbGeaqpygqhHDn8/Va05DqGxlPq9ZA=; b=nGLy3tslf30CMuBGiZ5azZCYGUYkwNJncgji3o/tFpCs0J6224of147dgfuLSF8hfZ s0sra2xiU81n0Y/Dg+xkeGNm14dsEc2WNGZW1Sr6cqD2b7+j6sGO9A3eAhxq6gchENsx CzG3oMkOfFWE5FkttESQiNcQJ8DiWjy+07iT+0OH5+szSzEXPhDzY9poIBHCmprvsXKM eu3tyZoXW5C/a1SqK/mQlG+n8cOik2L9vgA2l5h+kzQ9G/wXO6MAupp9jN8nnfHSSGTb Qew89VNs8dD6l3I1+bLKRBuLm/+7hJostcnoqboC8KsSxP20bjvPRMYQCB5Jy5htO7il 9cKw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690806988; x=1691411788; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=zf2opAJWpIyipvbGeaqpygqhHDn8/Va05DqGxlPq9ZA=; b=HEWGHmrxGE/3nfzL8BUSxISy6PR8xfqt1jua8scZW+uw4LYvA3keWu7eaELGLvU1eJ JiA2XoSG+oQGJYxSqLXvoNzakIph45Y5b8t4kN4TzUKXnoo3L4pOa/DLVQ6yixW8op6w ZkW3dC0CjxxRCfr5FJl3lgzmYfmPXEJrdQUrOucQLwlvS4Ax3AP15QTuBfSc4eP10MMh gB2y6f0eUE4S4+T7v7pngubi4U1oZgaMBE5Ci2KUknYeeAmFkAUhT/nMA+WzCaX6SxPx RNj8ftgUgb+Q6z/YxpJMS5KLnH+ZSTooiwdkOzlO8YIaonXr4WLBlHDxOzHli2d8DNh4 mAgA== X-Gm-Message-State: ABy/qLbOsigLW8XEc+I4LpJGvjMzTZhYeVN4zqcKdAex4LS8isT+TQKx 5THiumhXmu+AuXW9Lm4ahmo= X-Received: by 2002:adf:fece:0:b0:313:df09:acfb with SMTP id q14-20020adffece000000b00313df09acfbmr8245282wrs.11.1690806987609; Mon, 31 Jul 2023 05:36:27 -0700 (PDT) Received: from able.fritz.box ([2a00:e180:14f0:a600:ce89:8608:2d6f:110d]) by smtp.gmail.com with ESMTPSA id e15-20020a5d4e8f000000b003143c532431sm12958292wru.27.2023.07.31.05.36.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 31 Jul 2023 05:36:27 -0700 (PDT) From: " =?utf-8?q?Christian_K=C3=B6nig?= " <ckoenig.leichtzumerken@gmail.com> X-Google-Original-From: =?utf-8?q?Christian_K=C3=B6nig?= <christian.koenig@amd.com> To: boris.brezillon@collabora.com, ndesaulniers@google.com, maarten.lankhorst@linux.intel.com, mripard@kernel.org, tzimmermann@suse.de, airlied@gmail.com, daniel@ffwll.ch, trix@redhat.com, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, llvm@lists.linux.dev, naresh.kamboju@linaro.org, dakr@redhat.com Subject: [PATCH 1/2] drm/exec: use unique instead of local label Date: Mon, 31 Jul 2023 14:36:24 +0200 Message-Id: <20230731123625.3766-1-christian.koenig@amd.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1772942994043948447 X-GMAIL-MSGID: 1772942994043948447 |
Series |
[1/2] drm/exec: use unique instead of local label
|
|
Commit Message
Christian König
July 31, 2023, 12:36 p.m. UTC
GCC forbids to jump to labels in loop conditions and a new clang
check stumbled over this.
So instead using a local label inside the loop condition use an
unique label outside of it.
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 <nathan@kernel.org>
Reported-by: Naresh Kamboju <naresh.kamboju@linaro.org>
CC: Boris Brezillon <boris.brezillon@collabora.com>
Signed-off-by: Christian König <christian.koenig@amd.com>
---
include/drm/drm_exec.h | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
Comments
On Mon, Jul 31, 2023 at 02:36:24PM +0200, Christian König wrote: > GCC forbids to jump to labels in loop conditions and a new clang > check stumbled over this. > > So instead using a local label inside the loop condition use an > unique label outside of it. > > 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 <nathan@kernel.org> > Reported-by: Naresh Kamboju <naresh.kamboju@linaro.org> > CC: Boris Brezillon <boris.brezillon@collabora.com> > Signed-off-by: Christian König <christian.koenig@amd.com> Passes my build tests and I inspected the preprocessed output to make sure it should work. I ran the KUnit tests, which all pass (although [1] is needed to fix a tangential issue): Tested-by: Nathan Chancellor <nathan@kernel.org> Thanks for fixing this! [1]: https://lore.kernel.org/20230728183400.306193-1-arthurgrillo@riseup.net/ > --- > include/drm/drm_exec.h | 14 +++++++------- > 1 file changed, 7 insertions(+), 7 deletions(-) > > diff --git a/include/drm/drm_exec.h b/include/drm/drm_exec.h > index 73205afec162..e0462361adf9 100644 > --- a/include/drm/drm_exec.h > +++ b/include/drm/drm_exec.h > @@ -3,6 +3,7 @@ > #ifndef __DRM_EXEC_H__ > #define __DRM_EXEC_H__ > > +#include <linux/compiler.h> > #include <linux/ww_mutex.h> > > #define DRM_EXEC_INTERRUPTIBLE_WAIT BIT(0) > @@ -74,13 +75,12 @@ struct drm_exec { > * 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); \ > +#define drm_exec_until_all_locked(exec) \ > +__PASTE(__drm_exec_, __LINE__): \ > + for (void *__drm_exec_retry_ptr; ({ \ > + __drm_exec_retry_ptr = &&__PASTE(__drm_exec_, __LINE__);\ > + (void)__drm_exec_retry_ptr; \ > + drm_exec_cleanup(exec); \ > });) > > /** > -- > 2.34.1 > >
On Mon, 31 Jul 2023 08:31:19 -0700 Nathan Chancellor <nathan@kernel.org> wrote: > On Mon, Jul 31, 2023 at 02:36:24PM +0200, Christian König wrote: > > GCC forbids to jump to labels in loop conditions and a new clang > > check stumbled over this. > > > > So instead using a local label inside the loop condition use an > > unique label outside of it. > > > > 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 <nathan@kernel.org> > > Reported-by: Naresh Kamboju <naresh.kamboju@linaro.org> > > CC: Boris Brezillon <boris.brezillon@collabora.com> Reviewed-by: Boris Brezillon <boris.brezillon@collabora.com> > > Signed-off-by: Christian König <christian.koenig@amd.com> > > Passes my build tests and I inspected the preprocessed output to make > sure it should work. I ran the KUnit tests, which all pass (although [1] > is needed to fix a tangential issue): > > Tested-by: Nathan Chancellor <nathan@kernel.org> > > Thanks for fixing this! > > [1]: https://lore.kernel.org/20230728183400.306193-1-arthurgrillo@riseup.net/ > > > --- > > include/drm/drm_exec.h | 14 +++++++------- > > 1 file changed, 7 insertions(+), 7 deletions(-) > > > > diff --git a/include/drm/drm_exec.h b/include/drm/drm_exec.h > > index 73205afec162..e0462361adf9 100644 > > --- a/include/drm/drm_exec.h > > +++ b/include/drm/drm_exec.h > > @@ -3,6 +3,7 @@ > > #ifndef __DRM_EXEC_H__ > > #define __DRM_EXEC_H__ > > > > +#include <linux/compiler.h> > > #include <linux/ww_mutex.h> > > > > #define DRM_EXEC_INTERRUPTIBLE_WAIT BIT(0) > > @@ -74,13 +75,12 @@ struct drm_exec { > > * 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); \ > > +#define drm_exec_until_all_locked(exec) \ > > +__PASTE(__drm_exec_, __LINE__): \ > > + for (void *__drm_exec_retry_ptr; ({ \ > > + __drm_exec_retry_ptr = &&__PASTE(__drm_exec_, __LINE__);\ > > + (void)__drm_exec_retry_ptr; \ > > + drm_exec_cleanup(exec); \ > > });) > > > > /** > > -- > > 2.34.1 > > > >
On Mon, Jul 31, 2023 at 5:36 AM Christian König <ckoenig.leichtzumerken@gmail.com> wrote: > > GCC forbids to jump to labels in loop conditions and a new clang > check stumbled over this. > > So instead using a local label inside the loop condition use an > unique label outside of it. > > 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 <nathan@kernel.org> > Reported-by: Naresh Kamboju <naresh.kamboju@linaro.org> > CC: Boris Brezillon <boris.brezillon@collabora.com> > Signed-off-by: Christian König <christian.koenig@amd.com> Works for me; thanks for the patch! Reviewed-by: Nick Desaulniers <ndesaulniers@google.com> I suspect it's possible to change the indirect goto into a direct goto with some further refactoring (macros can take block statements; if drm_exec_until_all_locked accepted a block statement arg then you could introduce a new scope, and a new local label to that scope, then just use direct goto), but this will probably apply cleaner. (oh, is 09593216bff1 only in next at the moment? The AuthorDate threw me.) There are some curious cases where __attribute__((cleanup())) doesn't mesh well with indirect gotos. https://gcc.gnu.org/bugzilla/show_bug.cgi?id=37722 May not ever be a problem here... > --- > include/drm/drm_exec.h | 14 +++++++------- > 1 file changed, 7 insertions(+), 7 deletions(-) > > diff --git a/include/drm/drm_exec.h b/include/drm/drm_exec.h > index 73205afec162..e0462361adf9 100644 > --- a/include/drm/drm_exec.h > +++ b/include/drm/drm_exec.h > @@ -3,6 +3,7 @@ > #ifndef __DRM_EXEC_H__ > #define __DRM_EXEC_H__ > > +#include <linux/compiler.h> If you wanted to be more specific (if this addition is due to __PASTE), then `compiler_types.h` is more precise. > #include <linux/ww_mutex.h> > > #define DRM_EXEC_INTERRUPTIBLE_WAIT BIT(0) > @@ -74,13 +75,12 @@ struct drm_exec { > * 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); \ > +#define drm_exec_until_all_locked(exec) \ > +__PASTE(__drm_exec_, __LINE__): \ > + for (void *__drm_exec_retry_ptr; ({ \ > + __drm_exec_retry_ptr = &&__PASTE(__drm_exec_, __LINE__);\ > + (void)__drm_exec_retry_ptr; \ > + drm_exec_cleanup(exec); \ > });) > > /** > -- > 2.34.1 >
On Tue, 1 Aug 2023 13:35:13 -0700 Nick Desaulniers <ndesaulniers@google.com> wrote: > On Mon, Jul 31, 2023 at 5:36 AM Christian König > <ckoenig.leichtzumerken@gmail.com> wrote: > > > > GCC forbids to jump to labels in loop conditions and a new clang > > check stumbled over this. > > > > So instead using a local label inside the loop condition use an > > unique label outside of it. > > > > 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 <nathan@kernel.org> > > Reported-by: Naresh Kamboju <naresh.kamboju@linaro.org> > > CC: Boris Brezillon <boris.brezillon@collabora.com> > > Signed-off-by: Christian König <christian.koenig@amd.com> > > Works for me; thanks for the patch! > Reviewed-by: Nick Desaulniers <ndesaulniers@google.com> > > I suspect it's possible to change the indirect goto into a direct goto > with some further refactoring (macros can take block statements; if > drm_exec_until_all_locked accepted a block statement arg then you > could introduce a new scope, and a new local label to that scope, then > just use direct goto), Maybe I'm wrong, but this sounds like the version I proposed here [1]. > but this will probably apply cleaner. (oh, is > 09593216bff1 only in next at the moment? The AuthorDate threw me.) > > There are some curious cases where __attribute__((cleanup())) doesn't > mesh well with indirect gotos. > https://gcc.gnu.org/bugzilla/show_bug.cgi?id=37722 > > May not ever be a problem here... [1]https://patchwork.freedesktop.org/patch/543077/
On Wed, Aug 2, 2023 at 1:44 AM Boris Brezillon <boris.brezillon@collabora.com> wrote: > > On Tue, 1 Aug 2023 13:35:13 -0700 > Nick Desaulniers <ndesaulniers@google.com> wrote: > > > On Mon, Jul 31, 2023 at 5:36 AM Christian König > > <ckoenig.leichtzumerken@gmail.com> wrote: > > > > > > GCC forbids to jump to labels in loop conditions and a new clang > > > check stumbled over this. > > > > > > So instead using a local label inside the loop condition use an > > > unique label outside of it. > > > > > > 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 <nathan@kernel.org> > > > Reported-by: Naresh Kamboju <naresh.kamboju@linaro.org> > > > CC: Boris Brezillon <boris.brezillon@collabora.com> > > > Signed-off-by: Christian König <christian.koenig@amd.com> > > > > Works for me; thanks for the patch! > > Reviewed-by: Nick Desaulniers <ndesaulniers@google.com> > > > > I suspect it's possible to change the indirect goto into a direct goto > > with some further refactoring (macros can take block statements; if > > drm_exec_until_all_locked accepted a block statement arg then you > > could introduce a new scope, and a new local label to that scope, then > > just use direct goto), > > Maybe I'm wrong, but this sounds like the version I proposed here [1]. Nearly; here's what I was imagining: ``` diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c index 977e1804718d..3ea8beb159f0 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c @@ -904,7 +904,7 @@ static int amdgpu_cs_parser_bos(struct amdgpu_cs_parser *p, e->user_invalidated = userpage_invalidated; } - drm_exec_until_all_locked(&p->exec) { + drm_exec_until_all_locked(&p->exec, { r = amdgpu_vm_lock_pd(&fpriv->vm, &p->exec, 1 + p->gang_size); drm_exec_retry_on_contention(&p->exec); if (unlikely(r)) @@ -928,7 +928,7 @@ static int amdgpu_cs_parser_bos(struct amdgpu_cs_parser *p, if (unlikely(r)) goto out_free_user_pages; } - } + }) amdgpu_bo_list_for_each_userptr_entry(e, p->bo_list) { struct mm_struct *usermm; diff --git a/include/drm/drm_exec.h b/include/drm/drm_exec.h index 73205afec162..8e32a9b704e7 100644 --- a/include/drm/drm_exec.h +++ b/include/drm/drm_exec.h @@ -74,14 +74,13 @@ struct drm_exec { * 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); \ - });) +#define drm_exec_until_all_locked(exec, block) \ + { \ + __label__ __drm_exec_retry; \ +__drm_exec_retry: \ + while (drm_exec_cleanup(exec)) \ + block \ +} /** * drm_exec_retry_on_contention - restart the loop to grap all locks @@ -93,7 +92,7 @@ __drm_exec_retry: \ #define drm_exec_retry_on_contention(exec) \ do { \ if (unlikely(drm_exec_is_contended(exec))) \ - goto *__drm_exec_retry_ptr; \ + goto __drm_exec_retry; \ } while (0) /** ``` (only updated one macro expansion site in drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c, didn't add proper trailing tabs to macro but you get the gist). But I think both compilers can optimize out the unnecessary indirection when it's obvious, so I don't think it matters much, other than the tastes of whoever has to maintain this. > > > but this will probably apply cleaner. (oh, is > > 09593216bff1 only in next at the moment? The AuthorDate threw me.) > > > > There are some curious cases where __attribute__((cleanup())) doesn't > > mesh well with indirect gotos. > > https://gcc.gnu.org/bugzilla/show_bug.cgi?id=37722 > > > > May not ever be a problem here... > > [1]https://patchwork.freedesktop.org/patch/543077/
Hi Christian, Can this be applied to drm-misc? Other drivers are starting to make use of this API and our builds with clang-17 and clang-18 have been broken for some time due to this. Cheers, Nathan On Mon, Jul 31, 2023 at 02:36:24PM +0200, Christian König wrote: > GCC forbids to jump to labels in loop conditions and a new clang > check stumbled over this. > > So instead using a local label inside the loop condition use an > unique label outside of it. > > 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 <nathan@kernel.org> > Reported-by: Naresh Kamboju <naresh.kamboju@linaro.org> > CC: Boris Brezillon <boris.brezillon@collabora.com> > Signed-off-by: Christian König <christian.koenig@amd.com> > --- > include/drm/drm_exec.h | 14 +++++++------- > 1 file changed, 7 insertions(+), 7 deletions(-) > > diff --git a/include/drm/drm_exec.h b/include/drm/drm_exec.h > index 73205afec162..e0462361adf9 100644 > --- a/include/drm/drm_exec.h > +++ b/include/drm/drm_exec.h > @@ -3,6 +3,7 @@ > #ifndef __DRM_EXEC_H__ > #define __DRM_EXEC_H__ > > +#include <linux/compiler.h> > #include <linux/ww_mutex.h> > > #define DRM_EXEC_INTERRUPTIBLE_WAIT BIT(0) > @@ -74,13 +75,12 @@ struct drm_exec { > * 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); \ > +#define drm_exec_until_all_locked(exec) \ > +__PASTE(__drm_exec_, __LINE__): \ > + for (void *__drm_exec_retry_ptr; ({ \ > + __drm_exec_retry_ptr = &&__PASTE(__drm_exec_, __LINE__);\ > + (void)__drm_exec_retry_ptr; \ > + drm_exec_cleanup(exec); \ > });) > > /** > -- > 2.34.1 >
On Wed, 9 Aug 2023 08:37:55 -0700 Nathan Chancellor <nathan@kernel.org> wrote: > Hi Christian, > > Can this be applied to drm-misc? Other drivers are starting to make use > of this API and our builds with clang-17 and clang-18 have been broken > for some time due to this. Queued to drm-misc-next.
Am 10.08.23 um 08:40 schrieb Boris Brezillon: > On Wed, 9 Aug 2023 08:37:55 -0700 > Nathan Chancellor <nathan@kernel.org> wrote: > >> Hi Christian, >> >> Can this be applied to drm-misc? Other drivers are starting to make use >> of this API and our builds with clang-17 and clang-18 have been broken >> for some time due to this. > Queued to drm-misc-next. Sorry for the delay I have been on vacation last week and haven't yet catched up to this point in my mails. Thanks for taking care of this, Christian.
On 01/08/2023 22.35, Nick Desaulniers wrote: > I suspect it's possible to change the indirect goto into a direct goto > with some further refactoring (macros can take block statements; Well, with some somewhat subtle restrictions. C99, 6.10.3.11. "The sequence of preprocessing tokens bounded by the outside-most matching parentheses forms the list of arguments for the function-like macro. The individual arguments within the list are separated by comma preprocessing tokens, but comma preprocessing tokens between matching inner parentheses do not separate arguments." cpp doesn't care about the {} tokens when trying to figure out what constitutes the "block" argument, so if that block contained any comma outside a () pair, cpp would barf something like error: macro "foo" passed 3 arguments, but takes just 2 So while the commas inside function calls (and other macro invocations) are fine, constructs like int x, y; or struct s s = {.a = 3, .b = 4} would be verboten inside that block. One way around that is to make block a variadic argument so it just gobbles up all preprocessor token. Or have the users pass a statement expression instead of a block. Rasmus
On Thu, Aug 10, 2023 at 08:48:05AM +0200, Christian König wrote: > Am 10.08.23 um 08:40 schrieb Boris Brezillon: > > On Wed, 9 Aug 2023 08:37:55 -0700 > > Nathan Chancellor <nathan@kernel.org> wrote: > > > > > Hi Christian, > > > > > > Can this be applied to drm-misc? Other drivers are starting to make use > > > of this API and our builds with clang-17 and clang-18 have been broken > > > for some time due to this. > > Queued to drm-misc-next. > > Sorry for the delay I have been on vacation last week and haven't yet > catched up to this point in my mails. No worries, 'tis the season :) hope it was a good time and thank you both for getting this fixed! Cheers, Nathan
diff --git a/include/drm/drm_exec.h b/include/drm/drm_exec.h index 73205afec162..e0462361adf9 100644 --- a/include/drm/drm_exec.h +++ b/include/drm/drm_exec.h @@ -3,6 +3,7 @@ #ifndef __DRM_EXEC_H__ #define __DRM_EXEC_H__ +#include <linux/compiler.h> #include <linux/ww_mutex.h> #define DRM_EXEC_INTERRUPTIBLE_WAIT BIT(0) @@ -74,13 +75,12 @@ struct drm_exec { * 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); \ +#define drm_exec_until_all_locked(exec) \ +__PASTE(__drm_exec_, __LINE__): \ + for (void *__drm_exec_retry_ptr; ({ \ + __drm_exec_retry_ptr = &&__PASTE(__drm_exec_, __LINE__);\ + (void)__drm_exec_retry_ptr; \ + drm_exec_cleanup(exec); \ });) /**