Skip to content

Conversation

@EricccTaiwan
Copy link
Contributor

@EricccTaiwan EricccTaiwan commented Mar 29, 2025

Newer kernel versions (>= 5.4) require explicitly including <linux/vmalloc.h> to use vmalloc() and vfree(). Older kernels might have included this implicitly through other headers, but this is no longer the case.

Without this include, builds will fail with implicit function declaration errors on recent kernels such as 6.11.

@jserv
Copy link
Contributor

jserv commented Mar 29, 2025

I would like to ask @rota1001 to review and check the connection with sysprog21/kxo#1

@EricccTaiwan
Copy link
Contributor Author

I am using 6.11.0-21-generic,

$ uname -r
6.11.0-21-generic

Attempting to build without including <linux/vmalloc.h> results in the following errors:

/home/eric/linux2025/simrupt/simrupt.c: In function ‘simrupt_init’:
/home/eric/linux2025/simrupt/simrupt.c:359:20: error: implicit declaration of function ‘vmalloc’; did you mean ‘kmalloc’? [-Werror=implicit-function-declaration]
  359 |     fast_buf.buf = vmalloc(PAGE_SIZE);
      |                    ^~~~~~~
      |                    kmalloc
/home/eric/linux2025/simrupt/simrupt.c:359:18: warning: assignment to ‘char *’ from ‘int’ makes pointer from integer without a cast [-Wint-conversion]
  359 |     fast_buf.buf = vmalloc(PAGE_SIZE);
      |                  ^
/home/eric/linux2025/simrupt/simrupt.c:370:9: error: implicit declaration of function ‘vfree’; did you mean ‘kvfree’? [-Werror=implicit-function-declaration]
  370 |         vfree(fast_buf.buf);
      |         ^~~~~
      |         kvfree
cc1: some warnings being treated as errors
make[3]: *** [scripts/Makefile.build:244: /home/eric/linux2025/simrupt/simrupt.o] Error 1
make[2]: *** [/usr/src/linux-headers-6.11.0-21-generic/Makefile:1932: /home/eric/linux2025/simrupt] Error 2
make[1]: *** [Makefile:224: __sub-make] Error 2
make[1]: Leaving directory '/usr/src/linux-headers-6.11.0-21-generic'
make: *** [Makefile:9: all] Error 2

@EricccTaiwan
Copy link
Contributor Author

EricccTaiwan commented Mar 29, 2025

The vmalloc() and vfree() functions are implemented in mm/vmalloc.c, while their interfaces are declared in include/linux/vmalloc.h.

The same issue regarding implicit declaration of vmalloc() can also be seen in this Stack Overflow discussion.

Therefore, I believe both simrupt and kxo should explicitly include <linux/vmalloc.h> to properly access these interfaces. Failing to include it will cause implicit declaration errors on newer kernels, such as 6.11.

@rota1001
Copy link
Contributor

@jserv I've reviewed this change, and it looks like the same problem as what has been memtioned in sysprog21/kxo#1. Moreover, this change works for my environment (6.11.0-19-generic).

Copy link
Contributor

@jserv jserv left a comment

Choose a reason for hiding this comment

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

Append Tested-by: Chisheng Chen <johnny1001s000602@gmail.com> to acknowledge the review from @rota1001

See https://git-scm.com/docs/SubmittingPatches

@EricccTaiwan EricccTaiwan changed the title Add missing include for recent kernels Explicitly include linux/vmalloc.h on x86 Mar 29, 2025
@EricccTaiwan EricccTaiwan changed the title Explicitly include linux/vmalloc.h on x86 Include <linux/vmalloc.h> explicitly on x86 Mar 29, 2025
@EricccTaiwan
Copy link
Contributor Author

EricccTaiwan commented Mar 29, 2025

This patch also fixes sysprog21/kxo#1, which I have tested on my x86_64 system running kernel 6.11.0-21-generic.

Due to git commit message guidelines (72-character line limit), I've included the relevant kernel commit links here separately for reference:

@jserv
Copy link
Contributor

jserv commented Mar 29, 2025

See if the following statements were correct:

Commit 1f059dfdf5d1 ("mm/vmalloc: Add empty <asm/vmalloc.h> headers and use them from <linux/vmalloc.h>") restructured kernel header dependencies since kernel v6.14, necessitating explicit inclusion
of <linux/vmalloc.h> on x86 architectures.

This ensures compatibility across kernel versions and prevents build errors due to implicit declarations on recent kernels (>= 6.14).

Per @rota1001 reported, the affected kernel version is at least v6.11, and the above seems to be confusing. Clarify it.

@EricccTaiwan
Copy link
Contributor Author

EricccTaiwan commented Mar 29, 2025

After re-checking, commit 1f059dfdf5d1 ("mm/vmalloc: Add empty <asm/vmalloc.h> headers and use them from <linux/vmalloc.h>") was first merged into kernel version v5.6-rc1. The original mention of >= 6.14 was incorrect and misleading. I've updated the commit message accordingly to clarify this.

box

@EricccTaiwan EricccTaiwan changed the title Include <linux/vmalloc.h> explicitly on x86 Include <linux/vmalloc.h> explicitly on x86 Mar 29, 2025
@jserv
Copy link
Contributor

jserv commented Mar 29, 2025

The original mention of >= 6.14 was incorrect and misleading. I've updated the commit message accordingly to clarify this.

Clarify the following message:

Commit 1f059dfdf5d1 ("mm/vmalloc: Add empty <asm/vmalloc.h> headers
and use them from <linux/vmalloc.h>") restructured kernel header
dependencies since kernel v6.14, necessitating explicit inclusion
of <linux/vmalloc.h> on x86 architectures.

Commit 1f059dfdf5d1 ("mm/vmalloc: Add empty <asm/vmalloc.h> headers
and use them from <linux/vmalloc.h>") restructured kernel header
dependencies since kernel v5.6-rc1, necessitating explicit inclusion
of <linux/vmalloc.h> on x86 architectures.

This ensures compatibility across kernel versions and prevents build
errors due to implicit declarations on kernels since v5.6-rc1.

Tested-by: Chisheng Chen <johnny1001s000602@gmail.com>
Co-authored-by: Po-Ying Chiu <charlie910417@gmail.com>
@jserv jserv merged commit 69efd79 into sysprog21:main Mar 29, 2025
@jserv
Copy link
Contributor

jserv commented Mar 29, 2025

Thank @EricccTaiwan for contributing!

JeffBla added a commit to JeffBla/kxo that referenced this pull request Mar 31, 2025
Newer kernel versions (>= 5.4) require explicitly including
<linux/vmalloc.h> to use vmalloc() and vfree(). Older kernels might
have included it implicitly through other headers, but this is no
longer the case. Without this include, builds fail with implicit
function declaration errors on recent kernels such as 6.11.

Ref: sysprog21/simrupt#6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants