Skip to content
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

Make ebpf_kernel.h released under GPL-2.0-only or Apache-2.0 licenses #5114

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 7 additions & 9 deletions backends/ebpf/runtime/ebpf_common.h
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
/*
Copyright 2018 VMware, Inc.
SPDX-License-Identifier: (GPL-2.0-only or Apache-2.0)

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
This file is dual-license, so that when it is included from a source
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What makes this file GPL? Because of Linux types.h include?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comments try to explain, but let me know if a different explanation in the file's comments would make it clearer.

This file is currently #include'd by the C programs output by the p4c-ebpf back end, which in turn after they are compiled are intended to be loaded into the kernel as EBPF binaries, and executed within the kernel.

The easiest way to be clean on licenses for code run within the kernel is to release its source as GPL v2. Anything else and you want to get lawyers involved, I think.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Based on this article: https://ebpf.io/blog/ebpf-licensing-guide/

The license can be non-GPL but you would need to set it. Afaik we set it to GPL so that comment applies:

cstring license = "GPL"_cs; /// TODO: this should be a compiler option probably

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that if you read that licensing guide, they advise that most EBPF programs running within the kernel must be GPL 2.0.

They also advise: it is common practice for the EBPF code loaded into the kernel to be released under GPL 2.0, but for user-space applications that are their control plane programs, e.g. that add/modify/delete table entries in the running EBPF program, they can be licensed with the same choices available that any user-space application running on Linux has, i.e. they can be proprietary, Apache 2.0, GPL v*, etc. as the application developer wishes, subject to following the license of any libraries you use or other source code you depend upon.

This is why I think it is a reasonable choice for p4c to find those handful of files that are loaded into the Linux kernel and license them as GPL-2.0-only, or dual-licensed as (GPL-2.0-only or Apache-2.0), because some of the header files are included both from in-kernel EBPF programs, and from user-space programs. Fortunately, this appears like it might be only 2 files in the entire repo. Most of the EBPF-related source files in the p4c repo are either part of the p4c-ebpf executable, or some test program that runs in user space only.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have added a link to this article, and a couple of paragraphs of text summarizing how it applies to p4c source code, in commit 6 of my other PR documenting a proposed plan for licensing files in the p4c repo: 906fcf1

file intended to be compiled and loaded into the Linux kernel, it can
be included from a file licensed under GPL-2.0-only.

http://www.apache.org/licenses/LICENSE-2.0
When it is included from a source file intended to be compiled and run
as a user space program, it can be included from a file licensed as
Apache-2.0.

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

/*
Expand Down
17 changes: 7 additions & 10 deletions backends/ebpf/runtime/ebpf_kernel.h
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
/*
Copyright 2018 VMware, Inc.
SPDX-License-Identifier: (GPL-2.0-only or Apache-2.0)
Copy link
Collaborator

@fruffy fruffy Jan 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically we use libbpf to build the binaries for the kernel, which also has a complicated but more permissive license:

https://github.com/libbpf/libbpf?tab=readme-ov-file#license

I do not know whether that has any implications, quite the headache.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The license there appears to be the user's choice of BSD-2-Clause or LGPL-2.1. That is compatible with using it from a GPL-2.0-only program, or from an Apache-2.0 program, which are all we ever care about (and rarely if ever the GPL-2.0-only choice, but nice to know it is covered.)

The good news for the headache is that we can document it once, and the set of files involved should change extremely rarely, so we can automate simple license checks that these files continue to have the licenses we think are safe and defensible, and then the headache is past :-)


Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
This file is dual-license, so that when it is included from a source
file intended to be compiled and loaded into the Linux kernel, it can
be included from a file licensed under GPL-2.0-only.

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
When it is included from a source file intended to be compiled and run
as a user space program, it can be included from a file licensed as
Apache-2.0.
*/


Expand Down
Loading