Skip to content

[BPF] make __BPF_FEATURE_MAY_GOTO available for cpuv1 #108071

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

eddyz87
Copy link
Contributor

@eddyz87 eddyz87 commented Sep 10, 2024

For some reason __BPF_FEATURE_MAY_GOTO is available for CPUs v{2,3,4} but is not available for CPU v1. This limitation is arbitrary:

  • the instruction is never produced by LLVM backend;
  • on Linux Kernel side this instruction is available in kernels that also support CPUv4.

Hence, it is more consistent to either always allow __BPF_FEATURE_MAY_GOTO or only allow it for CPUv4.

For some reason __BPF_FEATURE_MAY_GOTO is available for CPUs v{2,3,4}
but is not available for CPU v1. This limitation is arbitrary:
- the instruction is never produced by LLVM backend;
- on Linux Kernel side this instruction is available in kernels that
  also support CPUv4.

Hence, it is more consistent to either always allow
__BPF_FEATURE_MAY_GOTO or only allow it for CPUv4.
@eddyz87
Copy link
Contributor Author

eddyz87 commented Sep 10, 2024

@yonghong-song, @4ast,

As a cleanup, Yonghong suggested moving __BPF_FEATURE_MAY_GOTO macro so that it is available for CPUv1.
(Although, I think it's better to move both __BPF_FEATURE_MAY_GOTO and __BPF_FEATURE_ADDR_SPACE_CAST down to CPUv4, as this would be more consistent with kernel features support).

Wdyt?

@eddyz87 eddyz87 marked this pull request as ready for review September 10, 2024 18:49
@llvmbot llvmbot added clang Clang issues not falling into any other category clang:frontend Language frontend issues, e.g. anything involving "Sema" labels Sep 10, 2024
@llvmbot
Copy link
Member

llvmbot commented Sep 10, 2024

@llvm/pr-subscribers-clang

Author: None (eddyz87)

Changes

For some reason __BPF_FEATURE_MAY_GOTO is available for CPUs v{2,3,4} but is not available for CPU v1. This limitation is arbitrary:

  • the instruction is never produced by LLVM backend;
  • on Linux Kernel side this instruction is available in kernels that also support CPUv4.

Hence, it is more consistent to either always allow __BPF_FEATURE_MAY_GOTO or only allow it for CPUv4.


Full diff: https://github.com/llvm/llvm-project/pull/108071.diff

1 Files Affected:

  • (modified) clang/lib/Basic/Targets/BPF.cpp (+1-1)
diff --git a/clang/lib/Basic/Targets/BPF.cpp b/clang/lib/Basic/Targets/BPF.cpp
index a94ceee5a6a5e7..931f407ecb0d7e 100644
--- a/clang/lib/Basic/Targets/BPF.cpp
+++ b/clang/lib/Basic/Targets/BPF.cpp
@@ -37,6 +37,7 @@ void BPFTargetInfo::getTargetDefines(const LangOptions &Opts,
   }
 
   Builder.defineMacro("__BPF_FEATURE_ADDR_SPACE_CAST");
+  Builder.defineMacro("__BPF_FEATURE_MAY_GOTO");
 
   if (CPU.empty())
     CPU = "v3";
@@ -48,7 +49,6 @@ void BPFTargetInfo::getTargetDefines(const LangOptions &Opts,
 
   std::string CpuVerNumStr = CPU.substr(1);
   Builder.defineMacro("__BPF_CPU_VERSION__", CpuVerNumStr);
-  Builder.defineMacro("__BPF_FEATURE_MAY_GOTO");
 
   int CpuVerNum = std::stoi(CpuVerNumStr);
   if (CpuVerNum >= 2)

@4ast
Copy link
Member

4ast commented Sep 10, 2024

@yonghong-song, @4ast,

As a cleanup, Yonghong suggested moving __BPF_FEATURE_MAY_GOTO macro so that it is available for CPUv1. (Although, I think it's better to move both __BPF_FEATURE_MAY_GOTO and __BPF_FEATURE_ADDR_SPACE_CAST down to CPUv4, as this would be more consistent with kernel features support).

Wdyt?

why force users to specify -mcpu=v4 ?
may_goto and addr_cast are fine with v1.

<commit message would be squashed and is not relevant>
@eddyz87
Copy link
Contributor Author

eddyz87 commented Sep 10, 2024

@4ast,

why force users to specify -mcpu=v4 ? may_goto and addr_cast are fine with v1.

Ok, then this is exactly what this pull request does (allows may_goto for v1).

@eddyz87
Copy link
Contributor Author

eddyz87 commented Sep 24, 2024

@4ast, ping

@eddyz87 eddyz87 merged commit eabc885 into llvm:main Sep 24, 2024
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema" clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants