kernel: kthread_cpus argument parser overutilizes the stack

Bug #1957188 reported by M. Vefa Bicakci
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
StarlingX
Fix Released
Low
M. Vefa Bicakci

Bug Description

Brief Description
-----------------

Since commit https://review.opendev.org/plugins/gitiles/starlingx/kernel/+/7b55e47e1d9fe9524b6b6b56cb6cb6efa11938ec the kernel's kthread_cpus= argument parser utilizes a lot of stack space, which may or may not be harmful. This was discovered when building the kernel with the following options:

      CONFIG_MAXSMP=y
      CONFIG_NR_CPUS=8192
      CONFIG_CPUMASK_OFFSTACK=y
      CONFIG_FRAME_WARN=1024

which results in the following compilation-time warning:

        CC kernel/cpu.o
      kernel/cpu.c: In function 'kthread_setup':
      kernel/cpu.c:2475:1: warning: the frame size of 1032 bytes is larger than 1024 bytes [-Wframe-larger-than=]

Please note that the configuration quoted above is *not* used by StarlingX, so the bug being fixed (large stack allocation) will become applicable only if CONFIG_MAXSMP is set to 'y' in the future (or when a large CONFIG_NR_CPUS value is used with CONFIG_CPUMASK_OFFSTACK=y).

Severity
--------
Minor: Given that this issue does not affect StarlingX due to its current kernel configuration, this is a minor issue, but I would like to fix it regardless.

Steps to Reproduce
------------------
Please see above for the build configuration that reproduces the warning.

Expected Behavior
------------------
No kernel build warnings

Actual Behavior
----------------
Kernel build warning about kthread_setup function's frame size exceeding 1KiB.

Reproducibility
---------------
100%

System Configuration
--------------------
Not applicable.

Branch/Pull Time/Commit
-----------------------
The issue is reproduced since the merge of the commit at https://review.opendev.org/plugins/gitiles/starlingx/kernel/+/7b55e47e1d9fe9524b6b6b56cb6cb6efa11938ec

Last Pass
---------
Not applicable.

Timestamp/Logs
--------------
Please see the issue description.

Test Activity
-------------
Exploratory developer testing

Workaround
----------
None.

Changed in starlingx:
assignee: nobody → M. Vefa Bicakci (vbicakci)
status: New → Confirmed
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to kernel (master)

Fix proposed to branch: master
Review: https://review.opendev.org/c/starlingx/kernel/+/824460

Changed in starlingx:
status: Confirmed → In Progress
description: updated
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to kernel (master)

Reviewed: https://review.opendev.org/c/starlingx/kernel/+/824460
Committed: https://opendev.org/starlingx/kernel/commit/8fde1a80702c4fbfb3b4c9fd944a505578fa9ade
Submitter: "Zuul (22348)"
Branch: master

commit 8fde1a80702c4fbfb3b4c9fd944a505578fa9ade
Author: M. Vefa Bicakci <email address hidden>
Date: Tue Jan 11 17:00:27 2022 -0500

    kthread_cpus: Avoid large stack allocation

    Since commit 7b55e47e1d9f ("Restore CPU affinity patches'
    functionality"), the function kthread_setup() has allocated a cpumask
    structure on the stack, which uses 1024 bytes on the stack when
    CONFIG_MAXSMP is enabled. This was detected after setting
    CONFIG_FRAME_WARN to 1024 for testing purposes.

    To clarify, with the following configuration:

      $ grep -e MAXSMP= -e NR_CPUS= -e CPUMASK_OFFSTACK= \
        -e FRAME_WARN= .config
      CONFIG_MAXSMP=y
      CONFIG_NR_CPUS=8192
      CONFIG_CPUMASK_OFFSTACK=y
      CONFIG_FRAME_WARN=1024

    the following build warning is encountered:

        CC kernel/cpu.o
      kernel/cpu.c: In function 'kthread_setup':
      kernel/cpu.c:2475:1: warning: the frame size of 1032 bytes is \
          larger than 1024 bytes [-Wframe-larger-than=]

    This commit resolves this issue by allocating the cpumask structure
    using the boot memory allocator via alloc_bootmem_cpumask_var().
    A similar approach is taken for the housekeeping-related cpumask
    structures in kernel/sched/isolation.c.

    Please note that the issue fixed by this commit (large stack allocation)
    only exists when CONFIG_CPUMASK_OFFSTACK is enabled. StarlingX currently
    disables CONFIG_CPUMASK_OFFSTACK. Disabling CONFIG_CPUMASK_OFFSTACK sets
    CONFIG_NR_CPUS' maximum value to 512 CPUs, which in turn corresponds to
    64 bytes on the stack. In contrast, enabling CONFIG_CPUMASK_OFFSTACK
    (for example, by setting CONFIG_MAXSMP=y) raises the upper limit for
    CONFIG_NR_CPUS to 8192 CPUs, which translates to a 1024-byte bitmap.

    No change in behaviour is intended.

    While carrying out the code changes, space characters in the affected
    function were converted to tab characters as a minor clean-up.

    Testing:
    * Monolithic ISO image build was successful.
    * Installation and bootstrap of the built ISO was successful with a
      virtual machine in All-in-One simplex mode, using the low-latency
      profile.
    * kthread_cpus argument's behaviour was confirmed to not have been
      negatively affected by checking that the CPU affinity of kthreadd
      (i.e., pid 2) matches the kthread_cpus= argument's value.
    * kthread_cpus argument's error handling was confirmed to work as
      expected by booting up the installed system with an invalid argument
      ('kthread_cpus=abc'). In this scenario, the CPU affinity of kthreadd
      was observed to be correctly set to 0-7 (with an 8-CPU VM).

    Change-Id: I31d2175d6084142e63d4b38d7b0c5677046fce4f
    Closes-Bug: 1957188
    Fixes: 7b55e47e1d9f ("Restore CPU affinity patches' functionality")
    Signed-off-by: M. Vefa Bicakci <email address hidden>

Changed in starlingx:
status: In Progress → Fix Released
Ghada Khalil (gkhalil)
Changed in starlingx:
importance: Undecided → Low
tags: added: stx.7.0 stx.distro.other
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.