Go to file
Colin Ian King 0be645792c x86/lib: Fix overflow when counting digits
[ Upstream commit a24d61c609813963aacc9f6ec8343f4fcaac7243 ]

tl;dr: The num_digits() function has a theoretical overflow issue.
But it doesn't affect any actual in-tree users.  Fix it by using
a larger type for one of the local variables.

Long version:

There is an overflow in variable m in function num_digits when val
is >= 1410065408 which leads to the digit calculation loop to
iterate more times than required. This results in either more
digits being counted or in some cases (for example where val is
1932683193) the value of m eventually overflows to zero and the
while loop spins forever).

Currently the function num_digits is currently only being used for
small values of val in the SMP boot stage for digit counting on the
number of cpus and NUMA nodes, so the overflow is never encountered.
However it is useful to fix the overflow issue in case the function
is used for other purposes in the future. (The issue was discovered
while investigating the digit counting performance in various
kernel helper functions rather than any real-world use-case).

The simplest fix is to make m a long long, the overhead in
multiplication speed for a long long is very minor for small values
of val less than 10000 on modern processors. The alternative
fix is to replace the multiplication with a constant division
by 10 loop (this compiles down to an multiplication and shift)
without needing to make m a long long, but this is slightly slower
than the fix in this commit when measured on a range of x86
processors).

[ dhansen: subject and changelog tweaks ]

Fixes: 646e29a178 ("x86: Improve the printout of the SMP bootup CPU table")
Signed-off-by: Colin Ian King <colin.i.king@gmail.com>
Signed-off-by: Dave Hansen <dave.hansen@linux.intel.com>
Link: https://lore.kernel.org/all/20231102174901.2590325-1-colin.i.king%40gmail.com
Signed-off-by: Sasha Levin <sashal@kernel.org>
2024-01-25 15:27:18 -08:00
Documentation dt-bindings: nvmem: mxs-ocotp: Document fsl,ocotp 2024-01-01 12:39:04 +00:00
LICENSES
arch x86/lib: Fix overflow when counting digits 2024-01-25 15:27:18 -08:00
block blk-mq: don't count completed flush data request as inflight in case of quiesce 2024-01-20 11:50:04 +01:00
certs certs: Fix build error when PKCS#11 URI contains semicolon 2023-02-09 11:28:11 +01:00
crypto crypto: pcrypt - Fix hungtask for PADATA_RESET 2023-11-28 17:06:58 +00:00
drivers coresight: etm4x: Fix width of CCITMIN field 2024-01-20 11:50:11 +01:00
fs ksmbd: free ppace array on error in parse_dacl 2024-01-20 11:50:10 +01:00
include jbd2: increase the journal IO's priority 2024-01-20 11:50:06 +01:00
init btf, scripts: Exclude Rust CUs with pahole 2024-01-20 11:50:10 +01:00
io_uring net: Declare MSG_SPLICE_PAGES internal sendmsg() flag 2024-01-10 17:10:27 +01:00
ipc
kernel ring-buffer: Do not record in NMI if the arch does not support cmpxchg in NMI 2024-01-20 11:50:07 +01:00
lib btf, scripts: Exclude Rust CUs with pahole 2024-01-20 11:50:10 +01:00
mm mm: fix unmap_mapping_range high bits shift bug 2024-01-10 17:10:35 +01:00
net net: qrtr: ns: Return 0 if server port is not present 2024-01-20 11:50:09 +01:00
rust rust: allocator: Prevent mis-aligned allocation 2023-08-11 12:08:18 +02:00
samples fprobe: Pass entry_data to handlers 2023-10-25 12:03:12 +02:00
scripts scripts/decode_stacktrace.sh: optionally use LLVM utilities 2024-01-20 11:50:11 +01:00
security keys, dns: Allow key types (eg. DNS) to be reclaimed immediately on expiry 2024-01-01 12:38:58 +00:00
sound ASoC: SOF: Intel: hda-codec: Delay the codec device registration 2024-01-20 11:50:10 +01:00
tools kselftest: alsa: fixed a print formatting warning 2024-01-20 11:50:08 +01:00
usr
virt kvm/vfio: ensure kvg instance stays around in kvm_vfio_group_add() 2023-09-13 09:42:46 +02:00
.clang-format
.cocciconfig
.get_maintainer.ignore
.gitattributes
.gitignore
.mailmap
.rustfmt.toml
COPYING
CREDITS
Kbuild
Kconfig
MAINTAINERS genirq/affinity: Move group_cpus_evenly() into lib/ 2024-01-10 17:10:33 +01:00
Makefile Linux 6.1.74 2024-01-20 11:50:11 +01:00
README

README

Linux kernel
============

There are several guides for kernel developers and users. These guides can
be rendered in a number of formats, like HTML and PDF. Please read
Documentation/admin-guide/README.rst first.

In order to build the documentation, use ``make htmldocs`` or
``make pdfdocs``.  The formatted documentation can also be read online at:

    https://www.kernel.org/doc/html/latest/

There are various text files in the Documentation/ subdirectory,
several of them using the Restructured Text markup notation.

Please read the Documentation/process/changes.rst file, as it contains the
requirements for building and running the kernel, and information about
the problems which may result by upgrading your kernel.