Bug 229209 - Linux kernel version number calculation inconsistent
Summary: Linux kernel version number calculation inconsistent
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: kern (show other bugs)
Version: CURRENT
Hardware: Any Any
: --- Affects Some People
Assignee: Chuck Tuffli
URL: https://reviews.freebsd.org/D15952
Keywords: patch
Depends on:
Blocks:
 
Reported: 2018-06-21 14:41 UTC by chuck
Modified: 2019-04-28 14:08 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description chuck 2018-06-21 14:41:36 UTC
The Linux compatibility code is converting the version number (e.g.
2.6.32) in two different ways and then comparing the results.

The linux_map_osrel() function converted MAJOR.MINOR.PATCH similar to
what FreeBSD does natively. I.e. where major=v0, minor=v1, and patch=v2
    v = v0 * 1000000 + v1 * 1000 + v2;

The LINUX_KERNVER() macro, on the other hand, converted the value with
bit shifts. I.e. where major=a, minor=b, and patch=c
    v = (((a) << 16) + ((b) << 8) + (c))
Comment 1 chuck 2018-06-21 14:50:42 UTC
Fix up for review https://reviews.freebsd.org/D15952
Comment 2 Conrad Meyer freebsd_committer freebsd_triage 2018-06-21 16:22:11 UTC
The latter is "correct" in that it will match the numeric versions Linux uses internally.
Comment 3 Ed Maste freebsd_committer freebsd_triage 2018-06-21 18:37:42 UTC
Aha, top-level Linux Makefile emits the KERNEL_VERSION macro into a header.
Comment 4 commit-hook freebsd_committer freebsd_triage 2018-06-22 00:02:23 UTC
A commit references this bug:

Author: chuck
Date: Fri Jun 22 00:02:04 UTC 2018
New revision: 335515
URL: https://svnweb.freebsd.org/changeset/base/335515

Log:
  Fix the Linux kernel version number calculation

  The Linux compatibility code was converting the version number (e.g.
  2.6.32) in two different ways and then comparing the results.

  The linux_map_osrel() function converted MAJOR.MINOR.PATCH similar to
  what FreeBSD does natively. I.e. where major=v0, minor=v1, and patch=v2
      v = v0 * 1000000 + v1 * 1000 + v2;

  The LINUX_KERNVER() macro, on the other hand, converted the value with
  bit shifts. I.e. where major=a, minor=b, and patch=c
      v = (((a) << 16) + ((b) << 8) + (c))

  The Linux kernel uses the later format via the KERNEL_VERSION() macro in
  include/generated/uapi/linux/version.h

  Fix is to use the LINUX_KERNVER() macro in linux_map_osrel() as well as
  in the .trans_osrel functions.

  PR: 229209
  Reviewed by: emaste, cem, imp (mentor)
  Approved by: imp (mentor)
  Differential Revision: https://reviews.freebsd.org/D15952

Changes:
  head/sys/amd64/linux/linux_sysvec.c
  head/sys/amd64/linux32/linux32_sysvec.c
  head/sys/compat/linux/linux_mib.c
  head/sys/i386/linux/linux_sysvec.c
Comment 5 Ed Maste freebsd_committer freebsd_triage 2018-10-04 01:14:21 UTC
Do we want to MFC this change?
Comment 6 Chuck Tuffli freebsd_committer freebsd_triage 2018-10-05 13:12:41 UTC
I'm fine with MFC'ing this as it can stand on its own. Bug it was mainly done to support a fix to the linprocfs stat (https://reviews.freebsd.org/D15858) entry.
Comment 7 Ed Maste freebsd_committer freebsd_triage 2018-10-05 13:18:47 UTC
OK - I'm largely indifferent to the MFC, just noticed that this PR wasn't closed after the commit.
Comment 8 Chuck Tuffli freebsd_committer freebsd_triage 2018-10-05 13:21:49 UTC
OK, that's my bad. Closing as this has been committed.
Comment 9 commit-hook freebsd_committer freebsd_triage 2019-04-28 14:08:17 UTC
A commit references this bug:

Author: dchagin
Date: Sun Apr 28 14:08:06 UTC 2019
New revision: 346835
URL: https://svnweb.freebsd.org/changeset/base/346835

Log:
  MFC r335515 (by chuck@):

  Fix the Linux kernel version number calculation

  The Linux compatibility code was converting the version number (e.g.
  2.6.32) in two different ways and then comparing the results.

  The linux_map_osrel() function converted MAJOR.MINOR.PATCH similar to
  what FreeBSD does natively. I.e. where major=v0, minor=v1, and patch=v2
      v = v0 * 1000000 + v1 * 1000 + v2;

  The LINUX_KERNVER() macro, on the other hand, converted the value with
  bit shifts. I.e. where major=a, minor=b, and patch=c
      v = (((a) << 16) + ((b) << 8) + (c))

  The Linux kernel uses the later format via the KERNEL_VERSION() macro in
  include/generated/uapi/linux/version.h

  Fix is to use the LINUX_KERNVER() macro in linux_map_osrel() as well as
  in the .trans_osrel functions.

  PR:		229209

Changes:
_U  stable/11/
  stable/11/sys/amd64/linux/linux_sysvec.c
  stable/11/sys/amd64/linux32/linux32_sysvec.c
  stable/11/sys/compat/linux/linux_mib.c
  stable/11/sys/i386/linux/linux_sysvec.c