2021-05-13 19:41:42

by J. R. Okajima

[permalink] [raw]
Subject: LOCKDEP customizable numbers upper limit

Hello,

According to the commit in v5.13-rc1,
5dc33592e9553 2021-04-05 lockdep: Allow tuning tracing capacity constants.
several lockdep numbers have their own range as 10--30.
But if we set all 30s, we got a compilation error.

kernel/locking/lockdep.c:3536:2: note: in expansion of macro 'BUILD_BUG_ON'
BUILD_BUG_ON((1UL << 24) <= ARRAY_SIZE(chain_hlocks));

kernel/locking/lockdep.c
----------------------------------------
static u16 chain_hlocks[MAX_LOCKDEP_CHAIN_HLOCKS];
:::
BUILD_BUG_ON((1UL << 24) <= ARRAY_SIZE(chain_hlocks));
:::
----------------------------------------

MAX_LOCKDEP_CHAIN_HLOCKS is defined in kernel/locking/lockdep_internal.h
as this.

#define MAX_LOCKDEP_CHAINS_BITS CONFIG_LOCKDEP_CHAINS_BITS
#define MAX_LOCKDEP_CHAINS (1UL << MAX_LOCKDEP_CHAINS_BITS)
#define MAX_LOCKDEP_CHAIN_HLOCKS (MAX_LOCKDEP_CHAINS*5)

I don't know what this 'multiply by 5' means and why
ARRAY_SIZE(chain_hlocks) is limited to (1UL << 24), but setting 30 to
CONFIG_LOCKDEP_CHAINS_BITS obviously causes BUILD_BUG.
'*5' is more than 2 bits shift, so CONFIG_LOCKDEP_CHAINS_BITS has to be
less than (24-2), limited to the range 10--21.

Hmm, I tried.

CONFIG_LOCKDEP_BITS=30
CONFIG_LOCKDEP_CHAINS_BITS=21
CONFIG_LOCKDEP_STACK_TRACE_BITS=30
CONFIG_LOCKDEP_STACK_TRACE_HASH_BITS=30
CONFIG_LOCKDEP_CIRCULAR_QUEUE_BITS=30

Arg, LD failed.
ld: kernel/locking/lockdep.o: in function `lockdep_hlock_class':
lockdep.c:(.text+0x84f): relocation truncated to fit: R_X86_64_PC32 against `.bss'

I am afraid these LOCKDEP configurations need some sort of balancing.


J. R. Okajima


2021-05-13 21:47:00

by Tetsuo Handa

[permalink] [raw]
Subject: Re: LOCKDEP customizable numbers upper limit

On 2021/05/13 22:39, J. R. Okajima wrote:
> Hello,
>
> According to the commit in v5.13-rc1,
> 5dc33592e9553 2021-04-05 lockdep: Allow tuning tracing capacity constants.
> several lockdep numbers have their own range as 10--30.
> But if we set all 30s, we got a compilation error.

Thanks for your report.

Initial proposal at
https://lore.kernel.org/lkml/1595640639-9310-1-git-send-email-penguin-kernel@I-love.SAKURA.ne.jp/
allowed only "double the upper limits", and subsequent proposals allowed arbitrary sizes in
response to https://lore.kernel.org/lkml/CACT4Y+YXT9iLij-AbrUwj=yPq-YNFw=Au9g0LQJCKwYonaHCDQ@mail.gmail.com/ ,
but practically increasing by a few bits should be sufficient.

I'm never expecting to use 30. I'm sure that setting 30s will become a too
much memory consumer that will prevent the kernel from booting correctly.
Thus, I don't think we need to care about randconfig kernels.

Please submit a patch that avoids only BUILD_BUG_ON().

Regards.


2021-05-15 06:44:57

by J. R. Okajima

[permalink] [raw]
Subject: PATCH: Re: LOCKDEP customizable numbers upper limit

Tetsuo Handa:
> Please submit a patch that avoids only BUILD_BUG_ON().

Here it is.

J. R. Okajima

----------------------------------------
commit 43e103e1a5975c61334811d16e207e6d0ac57b77
Author: J. R. Okajima <[email protected]>
Date: Sat May 15 03:17:10 2021 +0900

LOCKDEP: upper limit LOCKDEP_CHAINS_BITS

CONFIG_LOCKDEP_CHAINS_BITS value decides the size of chain_hlocks[] in
kernel/locking/lockdep.c, and it is checked by add_chain_cache() with
BUILD_BUG_ON((1UL << 24) <= ARRAY_SIZE(chain_hlocks));
This patch is just to silence BUILD_BUG_ON().

See-also: https://marc.info/?l=linux-kernel&m=162091320503900&w=2
Cc: Tetsuo Handa <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Signed-off-by: J. R. Okajima <[email protected]>

diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
index 678c13967580e..999ed5aa6bcee 100644
--- a/lib/Kconfig.debug
+++ b/lib/Kconfig.debug
@@ -1390,7 +1390,7 @@ config LOCKDEP_BITS
config LOCKDEP_CHAINS_BITS
int "Bitsize for MAX_LOCKDEP_CHAINS"
depends on LOCKDEP && !LOCKDEP_SMALL
- range 10 30
+ range 10 21
default 16
help
Try increasing this value if you hit "BUG: MAX_LOCKDEP_CHAINS too low!" message.