From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 28045C43461 for ; Thu, 20 May 2021 12:33:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 10AEB60FDB for ; Thu, 20 May 2021 12:33:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235199AbhETMec (ORCPT ); Thu, 20 May 2021 08:34:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57134 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240796AbhETMeZ (ORCPT ); Thu, 20 May 2021 08:34:25 -0400 Received: from mail-yb1-xb2c.google.com (mail-yb1-xb2c.google.com [IPv6:2607:f8b0:4864:20::b2c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 52841C049EB0; Thu, 20 May 2021 04:40:35 -0700 (PDT) Received: by mail-yb1-xb2c.google.com with SMTP id y36so5764507ybi.11; Thu, 20 May 2021 04:40:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=vOKexcaIw4g2vbrwnKp/g+ph6O5XnE0uXT4mDO7PWv8=; b=GnJFb+uRtqee1qkdkQxzXg1Y+2KQ5NDp0kgEXxos+702pxqs64ye7RvB2WTT8j4Agk xvbcvm92rG/xl/JYAWmOda1E+BRfOtTRuWYIqObGt5jvH1I9mfhTAxkFC4Ywj2yry9p0 7pKidPRp4Du3ztmXXWqDBUghuF+36OciigUJvtX3ED1n5JNPRIdz21sUrDRbcBqcS434 X6Fqr2KsD8PRdmHZc6sJpc3ZXZm1fYLOMd4r0kl2wEvIkpLJyRXEXkCNK60Z6hbf9IKX hnWvBf//ruPYWW/GieQYuUuCKtHLs2i6T3Be9K3KslrrzOj72HtWPeARl+BJiwmzl+oJ G32g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=vOKexcaIw4g2vbrwnKp/g+ph6O5XnE0uXT4mDO7PWv8=; b=NPfHnhF/n5CZmkF/zdQg/SVBUjaLD11F4+uab5ltzwD82axb1hqqwA45VMu6UXMaV/ P7KOs2q8WVtuiB8pdCg1SAnOI/9vkMuISfscGEgABNozudnHDwUQmpiXCW29DNray6ds IS8um1h52IJO9WB83QCC5wYvonvErryQxlMW7jRlVnh6TUTmQB0KtDBWh4SLu6RdIccQ 8817aRkM0bSho8cpgBhfVn4Wta9Vzy+UIld1I/a0/WhoxVq8OSBTTtGvKTD5zuDb9E5m myM1IBJLzbOuQUWrBeRtbDY/cQpPsYMfVNyBM3oiufLTA4xxmoW78F4wS4WIsJ1Ss+6Q o/2Q== X-Gm-Message-State: AOAM533zvlxq7eSsyLOxvyAWa72+86dBopHn6r4I0yzcdaJa7hn1pvMw e3JrQ2rz2/Vi0G6/CbF/sCjamUocSXbZsHc3kmI= X-Google-Smtp-Source: ABdhPJxMCd99LMdMXUg+BnOiV3mkGMsYuFGUgUpYt2rcFslbZo0dMYlj9vDhbVi2LIGAwBtL/bcFZnxVi5ZPgJVOMV0= X-Received: by 2002:a25:6d89:: with SMTP id i131mr7000838ybc.148.1621510834531; Thu, 20 May 2021 04:40:34 -0700 (PDT) MIME-Version: 1.0 References: <20210520104343.317119-1-joerichey94@gmail.com> <20210520111119.GC17233@C02TD0UTHF1T.local> In-Reply-To: <20210520111119.GC17233@C02TD0UTHF1T.local> From: Joseph Richey Date: Thu, 20 May 2021 04:40:23 -0700 Message-ID: Subject: Re: [PATCH 0/6] Don't use BIT() macro in UAPI headers To: Mark Rutland Cc: trivial@kernel.org, Joe Richey , Thomas Gleixner , Ingo Molnar , Borislav Petkov , x86@kernel.org, "H. Peter Anvin" , Paolo Bonzini , Lorenzo Pieralisi , Mauro Carvalho Chehab , Zhangfei Gao , Zhou Wang , linux-kernel@vger.kernel.org, kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-media@vger.kernel.org, linux-accelerators@lists.ozlabs.org Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, May 20, 2021 at 4:11 AM Mark Rutland wrote: > > Hi, > > On Thu, May 20, 2021 at 03:43:37AM -0700, Joe Richey wrote: > > From: Joe Richey > > > > The BIT(n) macro is used in the kernel as an alias for (1 << n). > > However, it is not defined in the UAPI headers, which means that any > > UAPI header files must be careful not to use it, or else the user > > will get a linker error. > > Beware that the common definition of BIT() (in include/vdso/bits.h) is: > > | #define BIT(nr) (UL(1) << (nr)) > > That UL() can be important if `nr` is ever greater than bits per int. > > > For example, compiling the following program: > > > > #include > > #include > > > > // Detect if FSGSBASE instructions are enabled > > int main() { > > unsigned long val = getauxval(AT_HWCAP2); > > return !(val & HWCAP2_FSGSBASE); > > } > > > > Results in the following likner error: > > > > /usr/bin/ld: /tmp/cceFpAdR.o: in function `main': > > gs.c:(.text+0x21): undefined reference to `BIT' > > > > This patch series changes all UAPI uses of BIT() to just be open-coded. > > In include/uapi/linux/const.h we have an equivaleint _BITUL() macro, > which I think should be used in preference of open-coding this (and is > already used in a number of uapi headers). That's a good idea. I mostly just did the open-coding for consistency with the surrounding code, but aside from kvm.h there aren't really many usages to change, so I can do it. For kvm.h, I think it might be best to leave it open-coded and move the entire file to _BITUL() at once. > > > However, there really should be a check for this in checkpatch.pl > > Currently, the script actually _encourages_ users to use the BIT macro > > even if adding things to UAPI. > > I think having something that suggests s/BIT()/_BITUL()/ under uapi > would be good. I'll just change the script to recommend _BITUL() (instead of BIT()) if the code path contains "uapi". > > Thanks, > Mark. > > > > > Running `rg "BIT\(" **/uapi/**` shows no more usage of BIT() in any > > UAPI headers. Tested by building a basic kernel. Changes are trivial. > > > > Joe Richey (6): > > x86/elf: Don't use BIT() macro in UAPI headers > > KVM: X86: Don't use BIT() macro in UAPI headers > > drivers: firmware: psci: Don't use BIT() macro in UAPI headers > > uacce: Don't use BIT() macro in UAPI headers > > media: vicodec: Don't use BIT() macro in UAPI headers > > tools headers UAPI: Sync pkt_sched.h with the kernel sources > > > > arch/x86/include/uapi/asm/hwcap2.h | 2 +- > > include/uapi/linux/kvm.h | 4 +- > > include/uapi/linux/psci.h | 2 +- > > include/uapi/linux/v4l2-controls.h | 22 ++--- > > include/uapi/misc/uacce/uacce.h | 2 +- > > tools/include/uapi/linux/kvm.h | 4 +- > > tools/include/uapi/linux/pkt_sched.h | 122 ++++++++++++++++++++++++--- > > 7 files changed, 130 insertions(+), 28 deletions(-) > > > > -- > > 2.31.1 > > From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.7 required=3.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,DKIM_VALID,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C389FC433B4 for ; Thu, 20 May 2021 11:46:26 +0000 (UTC) Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 5707861057 for ; Thu, 20 May 2021 11:46:26 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5707861057 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=desiato.20200630; h=Sender:Content-Transfer-Encoding :Content-Type:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:Cc:To:Subject:Message-ID:Date:From:In-Reply-To: References:MIME-Version:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=PB5QKKPCyniuGJ0jaPwbBs2ZAJB5WPQdd+DzlD8Mrfk=; b=bHm8doX3gAiVCy+XZgx+QYVnnj WWkMPcdR/gZVAuP6c+5wzuhX1I2gipDsRrDOREdRE4lKrx5QC5hSztcsdOGKI5BfNqRNe/lfX6CVc 8YhZFDgWOcmctBkFymIlpUs7w+UZTOUFRYmHwEZ0gJYueHKBFnvKRVDkOXIZGYm21LZunhqWXFOil bQSxoZ0TtWBzx62CrOh9dTMfBAO03x0plukmm77FvmeK0GeCOiSk6VG2B5d7x8CG5eKJEa28s27+P zePxad9Eah0vFsEJxhFrnZaVB2fi31AKsQDJd9bVJ5wBKYjBxa3M+CaLY1DcsJbfLjpC21dGIRMQ/ cpXVSKww==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1ljh6B-000Zxi-Ej; Thu, 20 May 2021 11:44:20 +0000 Received: from bombadil.infradead.org ([2607:7c80:54:e::133]) by desiato.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1ljh2c-000XzI-JZ for linux-arm-kernel@desiato.infradead.org; Thu, 20 May 2021 11:40:39 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Type:Cc:To:Subject:Message-ID :Date:From:In-Reply-To:References:MIME-Version:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=vOKexcaIw4g2vbrwnKp/g+ph6O5XnE0uXT4mDO7PWv8=; b=jPMz1HyDWA3B5pQOVJd9JJAT5W TCVz/Qnnxcbo5S4VDziuXUff8CgYBPRnE7axkOHOFBHkbSdc6G63AYubLbZLsMptUESkvdfDGNaMc 3f4hreZ2NBR3wgyqOcSc7G32HsYhfpNbpkFmU20uRvepEp6C50byJwF5pnnXDI5Unfkp2+TsHr0AG my19uOXK179mDbCUmH9n1hrxQIIyJFPh5llkav7lK5Lpvl6ZhuBDphNLQaYuz/y+BI8r8oz3ephO9 P18Kwt4PneQ4R3vfX7YhoJgRhH1xQlXfI/4UYoLafHK4V6MkadtVSXxKsoVvOI07w8g7fos9Ca1A/ MMLxJLVQ==; Received: from mail-yb1-xb2e.google.com ([2607:f8b0:4864:20::b2e]) by bombadil.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1ljh2Z-00GGI3-M3 for linux-arm-kernel@lists.infradead.org; Thu, 20 May 2021 11:40:37 +0000 Received: by mail-yb1-xb2e.google.com with SMTP id g38so22316605ybi.12 for ; Thu, 20 May 2021 04:40:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=vOKexcaIw4g2vbrwnKp/g+ph6O5XnE0uXT4mDO7PWv8=; b=GnJFb+uRtqee1qkdkQxzXg1Y+2KQ5NDp0kgEXxos+702pxqs64ye7RvB2WTT8j4Agk xvbcvm92rG/xl/JYAWmOda1E+BRfOtTRuWYIqObGt5jvH1I9mfhTAxkFC4Ywj2yry9p0 7pKidPRp4Du3ztmXXWqDBUghuF+36OciigUJvtX3ED1n5JNPRIdz21sUrDRbcBqcS434 X6Fqr2KsD8PRdmHZc6sJpc3ZXZm1fYLOMd4r0kl2wEvIkpLJyRXEXkCNK60Z6hbf9IKX hnWvBf//ruPYWW/GieQYuUuCKtHLs2i6T3Be9K3KslrrzOj72HtWPeARl+BJiwmzl+oJ G32g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=vOKexcaIw4g2vbrwnKp/g+ph6O5XnE0uXT4mDO7PWv8=; b=a8xgFpiZdrHf35fRnkFywNXgMMJjFGTKMo1mEJli/iFt8xtpZLl0wemltocZLPx2il AdDLV/KU8TTQPv0K5m0KJXwPlwY5VNF53T6z6wkiPdb9Y4CUI6Jm1DFjBGNb9eaMggV9 41LNy5SLE2lFx7p23PJcgqXtKvDKirarVDGY7quehDbBObCR/dQvl971q6dT2YU7yqa1 tajbcd+U3cD4MnVAFJkJV9ZbLhR2+HgPg6dz6aQ4OplRfsZbl+cl3LgtS4fZJRXGrbtg TTDMmyk3ZDa/+CfIM0PzgfExecIEO4zdUN/7BDZf91rM4YKdb/Qfh+AQp9HIvonFqT9f kp+A== X-Gm-Message-State: AOAM532itM3PckcEB48WxkP9+Fc6v5NJEhbu7yn5SENI2GEY2gmcOaFT TCAaXX1kzE0f7Id+0wxvmi2o2V5j9+QovXHtROc= X-Google-Smtp-Source: ABdhPJxMCd99LMdMXUg+BnOiV3mkGMsYuFGUgUpYt2rcFslbZo0dMYlj9vDhbVi2LIGAwBtL/bcFZnxVi5ZPgJVOMV0= X-Received: by 2002:a25:6d89:: with SMTP id i131mr7000838ybc.148.1621510834531; Thu, 20 May 2021 04:40:34 -0700 (PDT) MIME-Version: 1.0 References: <20210520104343.317119-1-joerichey94@gmail.com> <20210520111119.GC17233@C02TD0UTHF1T.local> In-Reply-To: <20210520111119.GC17233@C02TD0UTHF1T.local> From: Joseph Richey Date: Thu, 20 May 2021 04:40:23 -0700 Message-ID: Subject: Re: [PATCH 0/6] Don't use BIT() macro in UAPI headers To: Mark Rutland Cc: trivial@kernel.org, Joe Richey , Thomas Gleixner , Ingo Molnar , Borislav Petkov , x86@kernel.org, "H. Peter Anvin" , Paolo Bonzini , Lorenzo Pieralisi , Mauro Carvalho Chehab , Zhangfei Gao , Zhou Wang , linux-kernel@vger.kernel.org, kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-media@vger.kernel.org, linux-accelerators@lists.ozlabs.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210520_044035_744049_68B98A17 X-CRM114-Status: GOOD ( 31.69 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Thu, May 20, 2021 at 4:11 AM Mark Rutland wrote: > > Hi, > > On Thu, May 20, 2021 at 03:43:37AM -0700, Joe Richey wrote: > > From: Joe Richey > > > > The BIT(n) macro is used in the kernel as an alias for (1 << n). > > However, it is not defined in the UAPI headers, which means that any > > UAPI header files must be careful not to use it, or else the user > > will get a linker error. > > Beware that the common definition of BIT() (in include/vdso/bits.h) is: > > | #define BIT(nr) (UL(1) << (nr)) > > That UL() can be important if `nr` is ever greater than bits per int. > > > For example, compiling the following program: > > > > #include > > #include > > > > // Detect if FSGSBASE instructions are enabled > > int main() { > > unsigned long val = getauxval(AT_HWCAP2); > > return !(val & HWCAP2_FSGSBASE); > > } > > > > Results in the following likner error: > > > > /usr/bin/ld: /tmp/cceFpAdR.o: in function `main': > > gs.c:(.text+0x21): undefined reference to `BIT' > > > > This patch series changes all UAPI uses of BIT() to just be open-coded. > > In include/uapi/linux/const.h we have an equivaleint _BITUL() macro, > which I think should be used in preference of open-coding this (and is > already used in a number of uapi headers). That's a good idea. I mostly just did the open-coding for consistency with the surrounding code, but aside from kvm.h there aren't really many usages to change, so I can do it. For kvm.h, I think it might be best to leave it open-coded and move the entire file to _BITUL() at once. > > > However, there really should be a check for this in checkpatch.pl > > Currently, the script actually _encourages_ users to use the BIT macro > > even if adding things to UAPI. > > I think having something that suggests s/BIT()/_BITUL()/ under uapi > would be good. I'll just change the script to recommend _BITUL() (instead of BIT()) if the code path contains "uapi". > > Thanks, > Mark. > > > > > Running `rg "BIT\(" **/uapi/**` shows no more usage of BIT() in any > > UAPI headers. Tested by building a basic kernel. Changes are trivial. > > > > Joe Richey (6): > > x86/elf: Don't use BIT() macro in UAPI headers > > KVM: X86: Don't use BIT() macro in UAPI headers > > drivers: firmware: psci: Don't use BIT() macro in UAPI headers > > uacce: Don't use BIT() macro in UAPI headers > > media: vicodec: Don't use BIT() macro in UAPI headers > > tools headers UAPI: Sync pkt_sched.h with the kernel sources > > > > arch/x86/include/uapi/asm/hwcap2.h | 2 +- > > include/uapi/linux/kvm.h | 4 +- > > include/uapi/linux/psci.h | 2 +- > > include/uapi/linux/v4l2-controls.h | 22 ++--- > > include/uapi/misc/uacce/uacce.h | 2 +- > > tools/include/uapi/linux/kvm.h | 4 +- > > tools/include/uapi/linux/pkt_sched.h | 122 ++++++++++++++++++++++++--- > > 7 files changed, 130 insertions(+), 28 deletions(-) > > > > -- > > 2.31.1 > > _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel