All of lore.kernel.org
 help / color / mirror / Atom feed
From: Nathan Chancellor <nathan@kernel.org>
To: Sami Tolvanen <samitolvanen@google.com>
Cc: Masahiro Yamada <masahiroy@kernel.org>,
	Kees Cook <keescook@chromium.org>,
	Catalin Marinas <catalin.marinas@arm.com>,
	Mark Rutland <mark.rutland@arm.com>,
	Nick Desaulniers <ndesaulniers@google.com>,
	Will Deacon <will@kernel.org>,
	linux-arm-kernel <linux-arm-kernel@lists.infradead.org>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	llvm@lists.linux.dev
Subject: Re: [PATCH 1/3] kbuild: Change CFI_CLANG to depend on __builtin_function_start
Date: Mon, 4 Apr 2022 15:52:11 -0700	[thread overview]
Message-ID: <Ykt2mz3gBTAyu9pL@dev-arch.thelio-3990X> (raw)
In-Reply-To: <CABCJKudaQJ0_e290gD+rG8SwEembd33ua1MG-w2OKRq3es8Kjw@mail.gmail.com>

On Mon, Apr 04, 2022 at 12:40:46PM -0700, Sami Tolvanen wrote:
> On Sat, Apr 2, 2022 at 6:32 AM Masahiro Yamada <masahiroy@kernel.org> wrote:
> >
> > On Sat, Apr 2, 2022 at 5:19 AM Sami Tolvanen <samitolvanen@google.com> wrote:
> > >
> > > Clang 14 added support for the __builtin_function_start()
> > > built-in function, which allows us to implement function_nocfi()
> > > without architecture-specific inline assembly. This patch changes
> > > CONFIG_CFI_CLANG to depend on the built-in and effectively upgrades
> > > the minimum supported compiler version for CFI to Clang 14.
> >
> > From this description, I think the straight-forward change would be:
> >
> >     depends on CLANG_VERSION >= 120000
> > -->
> >     depends on CLANG_VERSION >= 140000
> >
> > Any reason to avoid this?
> 
> I thought testing for the compiler feature was preferred, but I can
> certainly just increase the minimum version number here too.

I think we have been somewhat inconsistent with feature versus version
checking. It might be nice to hash out when a feature check should be
done instead of a version one.

Generally, I think we tend to prefer version checks, as they are
"cheaper" since we do not have to call the compiler again because we
already cached the version code. When adding version checks, our policy
has always been use the upstream version of LLVM that the feature in
question shipped in, even if it is a top of tree version, as people who
are using prereleased versions of LLVM should be frequently updating
them.

Unfortunately, that does not always match reality. For example,
Android's LLVM tracks the main branch but they are almost always behind
by a few months. For example, the latest release is 14.0.4, based on a
version of LLVM from January 28th:

https://android.googlesource.com/platform/prebuilts/clang/host/linux-x86/+/ab73cd180863dbd17fdb8f20e39b33ab38030cf9/clang-r450784b/clang_source_info.md
https://github.com/llvm/llvm-project/commits/282c83c32384cb2f37030c28650fef4150a8b67c

Normally, I would say "who cares?" but Android's LLVM is used by the
Android kernel team both downstream and upstream, so I would argue it is
important to take that into account when deciding to do a feature check
versus a version check. In other words, by moving to a version check,
will we knowingly break a version of clang that is relatively widely
used?

In this case, 14.0.4 has __builtin_function_start(), so I think it is
okay to use a version check instead of a feature one.

There are times where feature or problem checking is not always
possible:

https://lore.kernel.org/r/20220318230747.3900772-1-nathan@kernel.org/

In cases like these, we can work to upgrade the compiler before changing
the feature check ot a version one, which helps minimize the window for
breakage.

Another aspect of feature versus version checks is that it is easier to
clean up stale versions checks when we bump the minimum supported
version of the compiler (as we can just look for "CLANG_VERSION" across
the tree) compared to stale feature checks. We could fix this by adding
some sort of common keyword, like

Compiler check: <compiler> <comparison> <version>

like

Compiler check: clang <= 14.0.0

Cheers,
Nathan

WARNING: multiple messages have this Message-ID
From: Nathan Chancellor <nathan@kernel.org>
To: Sami Tolvanen <samitolvanen@google.com>
Cc: Masahiro Yamada <masahiroy@kernel.org>,
	Kees Cook <keescook@chromium.org>,
	Catalin Marinas <catalin.marinas@arm.com>,
	Mark Rutland <mark.rutland@arm.com>,
	Nick Desaulniers <ndesaulniers@google.com>,
	Will Deacon <will@kernel.org>,
	linux-arm-kernel <linux-arm-kernel@lists.infradead.org>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	llvm@lists.linux.dev
Subject: Re: [PATCH 1/3] kbuild: Change CFI_CLANG to depend on __builtin_function_start
Date: Mon, 4 Apr 2022 15:52:11 -0700	[thread overview]
Message-ID: <Ykt2mz3gBTAyu9pL@dev-arch.thelio-3990X> (raw)
In-Reply-To: <CABCJKudaQJ0_e290gD+rG8SwEembd33ua1MG-w2OKRq3es8Kjw@mail.gmail.com>

On Mon, Apr 04, 2022 at 12:40:46PM -0700, Sami Tolvanen wrote:
> On Sat, Apr 2, 2022 at 6:32 AM Masahiro Yamada <masahiroy@kernel.org> wrote:
> >
> > On Sat, Apr 2, 2022 at 5:19 AM Sami Tolvanen <samitolvanen@google.com> wrote:
> > >
> > > Clang 14 added support for the __builtin_function_start()
> > > built-in function, which allows us to implement function_nocfi()
> > > without architecture-specific inline assembly. This patch changes
> > > CONFIG_CFI_CLANG to depend on the built-in and effectively upgrades
> > > the minimum supported compiler version for CFI to Clang 14.
> >
> > From this description, I think the straight-forward change would be:
> >
> >     depends on CLANG_VERSION >= 120000
> > -->
> >     depends on CLANG_VERSION >= 140000
> >
> > Any reason to avoid this?
> 
> I thought testing for the compiler feature was preferred, but I can
> certainly just increase the minimum version number here too.

I think we have been somewhat inconsistent with feature versus version
checking. It might be nice to hash out when a feature check should be
done instead of a version one.

Generally, I think we tend to prefer version checks, as they are
"cheaper" since we do not have to call the compiler again because we
already cached the version code. When adding version checks, our policy
has always been use the upstream version of LLVM that the feature in
question shipped in, even if it is a top of tree version, as people who
are using prereleased versions of LLVM should be frequently updating
them.

Unfortunately, that does not always match reality. For example,
Android's LLVM tracks the main branch but they are almost always behind
by a few months. For example, the latest release is 14.0.4, based on a
version of LLVM from January 28th:

https://android.googlesource.com/platform/prebuilts/clang/host/linux-x86/+/ab73cd180863dbd17fdb8f20e39b33ab38030cf9/clang-r450784b/clang_source_info.md
https://github.com/llvm/llvm-project/commits/282c83c32384cb2f37030c28650fef4150a8b67c

Normally, I would say "who cares?" but Android's LLVM is used by the
Android kernel team both downstream and upstream, so I would argue it is
important to take that into account when deciding to do a feature check
versus a version check. In other words, by moving to a version check,
will we knowingly break a version of clang that is relatively widely
used?

In this case, 14.0.4 has __builtin_function_start(), so I think it is
okay to use a version check instead of a feature one.

There are times where feature or problem checking is not always
possible:

https://lore.kernel.org/r/20220318230747.3900772-1-nathan@kernel.org/

In cases like these, we can work to upgrade the compiler before changing
the feature check ot a version one, which helps minimize the window for
breakage.

Another aspect of feature versus version checks is that it is easier to
clean up stale versions checks when we bump the minimum supported
version of the compiler (as we can just look for "CLANG_VERSION" across
the tree) compared to stale feature checks. We could fix this by adding
some sort of common keyword, like

Compiler check: <compiler> <comparison> <version>

like

Compiler check: clang <= 14.0.0

Cheers,
Nathan

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

  reply	other threads:[~2022-04-04 22:52 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-01 20:19 [PATCH 0/3] cfi: Use __builtin_function_start Sami Tolvanen
2022-04-01 20:19 ` Sami Tolvanen
2022-04-01 20:19 ` [PATCH 1/3] kbuild: Change CFI_CLANG to depend on __builtin_function_start Sami Tolvanen
2022-04-01 20:19   ` Sami Tolvanen
2022-04-02 13:31   ` Masahiro Yamada
2022-04-02 13:31     ` Masahiro Yamada
2022-04-04 19:40     ` Sami Tolvanen
2022-04-04 19:40       ` Sami Tolvanen
2022-04-04 22:52       ` Nathan Chancellor [this message]
2022-04-04 22:52         ` Nathan Chancellor
2022-04-05  2:53         ` Kees Cook
2022-04-05  2:53           ` Kees Cook
2022-04-01 20:19 ` [PATCH 2/3] linux/compiler-clang.h: define function_nocfi Sami Tolvanen
2022-04-01 20:19   ` Sami Tolvanen
2022-04-05 16:16   ` Mark Rutland
2022-04-05 16:16     ` Mark Rutland
2022-04-01 20:19 ` [PATCH 3/3] arm64: Drop the inline assembly implementation of function_nocfi Sami Tolvanen
2022-04-01 20:19   ` Sami Tolvanen
2022-04-04  9:03   ` Will Deacon
2022-04-04  9:03     ` Will Deacon
2022-04-05 16:23   ` Mark Rutland
2022-04-05 16:23     ` Mark Rutland
2022-04-01 20:49 ` [PATCH 0/3] cfi: Use __builtin_function_start Nick Desaulniers
2022-04-01 20:49   ` Nick Desaulniers

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Ykt2mz3gBTAyu9pL@dev-arch.thelio-3990X \
    --to=nathan@kernel.org \
    --cc=catalin.marinas@arm.com \
    --cc=keescook@chromium.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=llvm@lists.linux.dev \
    --cc=mark.rutland@arm.com \
    --cc=masahiroy@kernel.org \
    --cc=ndesaulniers@google.com \
    --cc=samitolvanen@google.com \
    --cc=will@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.