Message ID | 20230411092747.3759032-1-kevin.brodsky@arm.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp2448429vqo; Tue, 11 Apr 2023 02:50:22 -0700 (PDT) X-Google-Smtp-Source: AKy350avx3YuREliWuwMAYl5CHoptz5Yl0lSbe9GKZRrl9GNAZuoZDtxF3iO5hW0JB5t8khhXmrX X-Received: by 2002:a17:907:98fb:b0:92f:33ca:c9a3 with SMTP id ke27-20020a17090798fb00b0092f33cac9a3mr1944421ejc.71.1681206621832; Tue, 11 Apr 2023 02:50:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681206621; cv=none; d=google.com; s=arc-20160816; b=xLrkASsqyEp3CbXaaCr6YG7peeXE6V/wd2Qbn6ps4rADk1zxtbsY/NpfGsC/7uLo1n 1xcnMwwXy0QWBc8AuxWVoQoJ/SUS34ZIKvBzdP+2t7Ye4Djgyw7Fsm8xu6XTD8noJd9U MqP/cMJanj0yJvS9eNvOIV0CPNFsTyUaxCTZXxgSiYVHifTrt/voVsieeyx72eMPg7Fv ayxxBJgVpIJmjjS9zTX9DIi8aei0AmpKuLzzhQapVpEXdDVddMDHeMQgyloUH0SWQ+ZZ CEnsIY9eSACo3jmvnOM4ZwVyPwVQyjbfx9hk9f+9JD2/aIK2Jt/+ubQMH7pfoQmkrBtF hlPA== 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:cc:to:from; bh=FUgAXLr1iYAC7dgjc2/dCB4XWMuKY/pZEeWUFAG1yko=; b=gw/vhEb7Oh377frsMdqm1DwHMYh78sHjvS+2nJ1bnPmybM3SgzaCrlSyh48ba83Scz AdwpSw4o8L9EyO91MTsegrRWOJJlwnmp//bnBXdB1HXs1h91zNCPHsoQQAcCBang2grU FHphgRyYIcPyK2ILp+zIM3u5ICLsJeJKFgnLrB2AlNysEzCH3vi8La2nKqIBH4i1M+hR 8qxUWzmF12NjqExg4x2Wqhn9T//vnRLKAIyge5x2j6Sjx4+JOxHiLyDwGbDe+LKyNzua v8DL3EHg3WVt3/9YJUh7qyWmfz4PAEpnnmQEmif333KCT2KVa+BJsPr9wSj6KvQMzIaC YEuA== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ke22-20020a17090798f600b0094de067bcb6si109796ejc.725.2023.04.11.02.49.57; Tue, 11 Apr 2023 02:50:21 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229732AbjDKJ2R (ORCPT <rfc822;yuanzuo1009@gmail.com> + 99 others); Tue, 11 Apr 2023 05:28:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47298 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229482AbjDKJ2A (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Tue, 11 Apr 2023 05:28:00 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id A71C4C3; Tue, 11 Apr 2023 02:27:57 -0700 (PDT) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id D0E0BD75; Tue, 11 Apr 2023 02:28:41 -0700 (PDT) Received: from e123572-lin.arm.com (e123572-lin.cambridge.arm.com [10.1.194.65]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 578DC3F73F; Tue, 11 Apr 2023 02:27:56 -0700 (PDT) From: Kevin Brodsky <kevin.brodsky@arm.com> To: linux-kernel@vger.kernel.org Cc: linux-kbuild@vger.kernel.org, Masahiro Yamada <masahiroy@kernel.org>, Sam Ravnborg <sam@ravnborg.org>, Petr Vorel <petr.vorel@gmail.com>, Andrew Morton <akpm@linux-foundation.org>, Kevin Brodsky <kevin.brodsky@arm.com>, Ruben Ayrapetyan <ruben.ayrapetyan@arm.com> Subject: [PATCH RESEND] uapi/linux/const.h: Prefer ISO-friendly __typeof__ Date: Tue, 11 Apr 2023 10:27:47 +0100 Message-Id: <20230411092747.3759032-1-kevin.brodsky@arm.com> X-Mailer: git-send-email 2.38.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.3 required=5.0 tests=RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE autolearn=unavailable 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: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1762872915086522648?= X-GMAIL-MSGID: =?utf-8?q?1762872915086522648?= |
Series |
[RESEND] uapi/linux/const.h: Prefer ISO-friendly __typeof__
|
|
Commit Message
Kevin Brodsky
April 11, 2023, 9:27 a.m. UTC
typeof is (still) a GNU extension, which means that it cannot be used when building ISO C (e.g. -std=c99). It should therefore be avoided in uapi headers in favour of the ISO-friendly __typeof__. Unfortunately this issue could not be detected by CONFIG_UAPI_HEADER_TEST=y as the __ALIGN_KERNEL() macro is not expanded in any uapi header. Reported-by: Ruben Ayrapetyan <ruben.ayrapetyan@arm.com> Tested-by: Ruben Ayrapetyan <ruben.ayrapetyan@arm.com> Signed-off-by: Kevin Brodsky <kevin.brodsky@arm.com> --- include/uapi/linux/const.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Comments
Hi Kevin, > typeof is (still) a GNU extension, which means that it cannot be > used when building ISO C (e.g. -std=c99). It should therefore be > avoided in uapi headers in favour of the ISO-friendly __typeof__. IMHO UAPI are built with -std=c90 -Wall -Werror=implicit-function-declaration (see usr/include/Makefile). But one or the other, you're right both require __typeof__. "If you are writing a header file that must work when included in ISO C programs, write __typeof__ instead of typeof." https://gcc.gnu.org/onlinedocs/gcc-12.2.0/gcc/Typeof.html Reviewed-by: Petr Vorel <pvorel@suse.cz> Tested-by: Petr Vorel <pvorel@suse.cz> Kind regards, Petr > Unfortunately this issue could not be detected by > CONFIG_UAPI_HEADER_TEST=y as the __ALIGN_KERNEL() macro is not > expanded in any uapi header. > Reported-by: Ruben Ayrapetyan <ruben.ayrapetyan@arm.com> > Tested-by: Ruben Ayrapetyan <ruben.ayrapetyan@arm.com> > Signed-off-by: Kevin Brodsky <kevin.brodsky@arm.com> > --- > include/uapi/linux/const.h | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > diff --git a/include/uapi/linux/const.h b/include/uapi/linux/const.h > index af2a44c08683..a429381e7ca5 100644 > --- a/include/uapi/linux/const.h > +++ b/include/uapi/linux/const.h > @@ -28,7 +28,7 @@ > #define _BITUL(x) (_UL(1) << (x)) > #define _BITULL(x) (_ULL(1) << (x)) > -#define __ALIGN_KERNEL(x, a) __ALIGN_KERNEL_MASK(x, (typeof(x))(a) - 1) > +#define __ALIGN_KERNEL(x, a) __ALIGN_KERNEL_MASK(x, (__typeof__(x))(a) - 1) > #define __ALIGN_KERNEL_MASK(x, mask) (((x) + (mask)) & ~(mask)) > #define __KERNEL_DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d))
> Hi Kevin, > > typeof is (still) a GNU extension, which means that it cannot be > > used when building ISO C (e.g. -std=c99). It should therefore be > > avoided in uapi headers in favour of the ISO-friendly __typeof__. > IMHO UAPI are built with -std=c90 -Wall -Werror=implicit-function-declaration > (see usr/include/Makefile). > But one or the other, you're right both require __typeof__. > "If you are writing a header file that must work when included in ISO C > programs, write __typeof__ instead of typeof." > https://gcc.gnu.org/onlinedocs/gcc-12.2.0/gcc/Typeof.html > Reviewed-by: Petr Vorel <pvorel@suse.cz> > Tested-by: Petr Vorel <pvorel@suse.cz> IMHO problem was introduced when -std=c90 was added (back then the code was in include/uapi/linux/kernel.h). Fixes: d6fc9fcbaa65 ("kbuild: compile-test exported headers to ensure they are self-contained") Kind regards, Petr > Kind regards, > Petr > > Unfortunately this issue could not be detected by > > CONFIG_UAPI_HEADER_TEST=y as the __ALIGN_KERNEL() macro is not > > expanded in any uapi header. > > Reported-by: Ruben Ayrapetyan <ruben.ayrapetyan@arm.com> > > Tested-by: Ruben Ayrapetyan <ruben.ayrapetyan@arm.com> > > Signed-off-by: Kevin Brodsky <kevin.brodsky@arm.com> > > --- > > include/uapi/linux/const.h | 2 +- > > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/include/uapi/linux/const.h b/include/uapi/linux/const.h > > index af2a44c08683..a429381e7ca5 100644 > > --- a/include/uapi/linux/const.h > > +++ b/include/uapi/linux/const.h > > @@ -28,7 +28,7 @@ > > #define _BITUL(x) (_UL(1) << (x)) > > #define _BITULL(x) (_ULL(1) << (x)) > > -#define __ALIGN_KERNEL(x, a) __ALIGN_KERNEL_MASK(x, (typeof(x))(a) - 1) > > +#define __ALIGN_KERNEL(x, a) __ALIGN_KERNEL_MASK(x, (__typeof__(x))(a) - 1) > > #define __ALIGN_KERNEL_MASK(x, mask) (((x) + (mask)) & ~(mask)) > > #define __KERNEL_DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d))
On Tue, 11 Apr 2023 23:39:46 +0200 Petr Vorel <pvorel@suse.cz> wrote: > > Hi Kevin, > > > > typeof is (still) a GNU extension, which means that it cannot be > > > used when building ISO C (e.g. -std=c99). It should therefore be > > > avoided in uapi headers in favour of the ISO-friendly __typeof__. > > > IMHO UAPI are built with -std=c90 -Wall -Werror=implicit-function-declaration > > (see usr/include/Makefile). > > But one or the other, you're right both require __typeof__. > > > "If you are writing a header file that must work when included in ISO C > > programs, write __typeof__ instead of typeof." > > https://gcc.gnu.org/onlinedocs/gcc-12.2.0/gcc/Typeof.html > > > Reviewed-by: Petr Vorel <pvorel@suse.cz> > > Tested-by: Petr Vorel <pvorel@suse.cz> > > IMHO problem was introduced when -std=c90 was added (back then the code was in > include/uapi/linux/kernel.h). Well... what actually _is_ the problem? Presumably build issues under some circumstances. Could we please see an instance of those issues and a description of the circumstances under which they occur? > Fixes: d6fc9fcbaa65 ("kbuild: compile-test exported headers to ensure they are self-contained") Might need a cc:stable, depending on the answers to the above.
On 12/04/2023 02:24, Andrew Morton wrote: > On Tue, 11 Apr 2023 23:39:46 +0200 Petr Vorel <pvorel@suse.cz> wrote: > >>> Hi Kevin, >>>> typeof is (still) a GNU extension, which means that it cannot be >>>> used when building ISO C (e.g. -std=c99). It should therefore be >>>> avoided in uapi headers in favour of the ISO-friendly __typeof__. >>> IMHO UAPI are built with -std=c90 -Wall -Werror=implicit-function-declaration >>> (see usr/include/Makefile). >>> But one or the other, you're right both require __typeof__. >>> "If you are writing a header file that must work when included in ISO C >>> programs, write __typeof__ instead of typeof." >>> https://gcc.gnu.org/onlinedocs/gcc-12.2.0/gcc/Typeof.html >>> Reviewed-by: Petr Vorel <pvorel@suse.cz> >>> Tested-by: Petr Vorel <pvorel@suse.cz> >> IMHO problem was introduced when -std=c90 was added (back then the code was in >> include/uapi/linux/kernel.h). > Well... what actually _is_ the problem? Presumably build issues under > some circumstances. Could we please see an instance of those issues > and a description of the circumstances under which they occur? This matters from a userspace perspective, not a kernel one. uapi headers and their contents are expected to be usable in a variety of situations, and in particular when building ISO C applications (with -std=c99 or similar). This particular problem can be reproduced by trying to use the __ALIGN_KERNEL macro directly in application code, say: #include <linux/const.h> int align(int x, int a) { return __KERNEL_ALIGN(x, a); } and trying to build that with -std=c99. I do not believe this patch really fixes any other patch: __ALIGN_KERNEL() has always used typeof, so it has never been ISO-friendly. d6fc9fcbaa65 ("kbuild: compile-test exported headers to ensure they are self-contained") could not have spotted this issue, because the macro is never expanded when simply including uapi headers. One could consider that 607ca46e97a1 ("UAPI: (Scripted) Disintegrate include/linux") is the culprit because it moved the macro to include/uapi as-is, but that's arguable. > >> Fixes: d6fc9fcbaa65 ("kbuild: compile-test exported headers to ensure they are self-contained") > Might need a cc:stable, depending on the answers to the above. Considering this issue has always been present, I do not believe it is the case. Thanks, Kevin IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you.
diff --git a/include/uapi/linux/const.h b/include/uapi/linux/const.h index af2a44c08683..a429381e7ca5 100644 --- a/include/uapi/linux/const.h +++ b/include/uapi/linux/const.h @@ -28,7 +28,7 @@ #define _BITUL(x) (_UL(1) << (x)) #define _BITULL(x) (_ULL(1) << (x)) -#define __ALIGN_KERNEL(x, a) __ALIGN_KERNEL_MASK(x, (typeof(x))(a) - 1) +#define __ALIGN_KERNEL(x, a) __ALIGN_KERNEL_MASK(x, (__typeof__(x))(a) - 1) #define __ALIGN_KERNEL_MASK(x, mask) (((x) + (mask)) & ~(mask)) #define __KERNEL_DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d))