rng-tools: disable the CPU affinity mask
PATCH 1/1 rng-tools: disable the CPU affinity mask
From: Mingli Yu <[email protected]>
For the jitter entropy source, each task thread will create an internal counter timer thread when the system clock resolution is under 5MHz.
But it will introduce high cpu usage for a long time and also make random data generate too slow if sets the CPU affinity mask of the internal counter timer thread.
There is no solution until now and the Upstream recommends to disable the internal timer and think Jitter RNG will not work due to the coarse timer. Check [1] and [2] for more details.
So disable the CPU affinity mask as a workaround to avoid lots of context switch and too high cpu load for a long time.
[1] https://github.com/smuellerDD/jitterentropy-library/issues/37
[2] https://github.com/nhorman/rng-tools/pull/123
--- ...tter.c-disable-the-CPU-affinity-mask.patch | 48 +++++++++++++++++++ .../rng-tools/rng-tools_6.11.bb | 1 + 2 files changed, 49 insertions(+) create mode 100644 meta/recipes-support/rng-tools/rng-tools/0001-rngd_jitter.c-disable-the-CPU-affinity-mask.patch
meta/recipes-support/rng-tools/rng-tools/0001-rngd_jitter.c-disable-the-CPU-affinity-mask.patch new file +48 -0
@@ -0,0 +1,48 @@ +From e44e35dd0b739da8718a5c78e0092bd2feabf5ce Mon Sep 17 00:00:00 2001 +From: Zhantao Tang <[email protected]> +Date: Sun, 25 Apr 2021 11:33:24 +0800 +Subject: [PATCH] rngd_jitter.c: disable the CPU affinity mask + +For the jitter entropy source, each task thread will create an internal +counter timer thread when the system clock resolution is under 5MHz. + +But it will introduce high cpu usage for a long time and also make random +data generate too slow if sets the CPU affinity mask of the internal counter +timer thread. + +So disable the CPU affinity mask to avoid lots of context switch and too +high cpu load for a long time. + +Upstream-Status: Denied[There is no solution until now and Upstream recommend + to disable the internal timer and think Jitter RNG will + not work due to the coarse timer. Check [1] and [2] for + more details] + +[1] https://github.com/smuellerDD/jitterentropy-library/issues/37 +[2] https://github.com/nhorman/rng-tools/pull/123 + +Signed-off-by: Zhantao Tang <[email protected]> +Signed-off-by: Mingli Yu <[email protected]> +--- + rngd_jitter.c | 5 ----- + 1 file changed, 5 deletions(-) + +diff --git a/rngd_jitter.c b/rngd_jitter.c +index c803f0d..ef03c6c 100644 +--- a/rngd_jitter.c ++++ b/rngd_jitter.c +@@ -252,11 +252,6 @@ static void *thread_entropy_task(void *data) + me->slptm.tv_nsec = 0; + } + +- /* fill initial entropy */ +- CPU_ZERO(&cpuset); +- CPU_SET(me->core_id, &cpuset); +- pthread_setaffinity_np(pthread_self(), CPU_ALLOC_SIZE(me->core_id+1), &cpuset); +- + tmpbuf = malloc(me->buf_sz); + if (!tmpbuf) { + message_entsrc(me->ent_src,LOG_DAEMON|LOG_DEBUG, "Unable to allocate temp buffer on cpu %d\n", me->core_id); +-- +2.17.1 +
meta/recipes-support/rng-tools/rng-tools_6.11.bb +1 -0
@@ -10,6 +10,7 @@ DEPENDS = "sysfsutils openssl" SRC_URI = "\ git://github.com/nhorman/rng-tools.git \ + file://0001-rngd_jitter.c-disable-the-CPU-affinity-mask.patch \ file://init \ file://default \ file://rngd.service \
Signature · 1 line
2.29.2
Quoted 19 lines · Mingli
From: Mingli Yu <[email protected]>
For the jitter entropy source, each task thread will create an internal counter timer thread when the system clock resolution is under 5MHz.
But it will introduce high cpu usage for a long time and also make random data generate too slow if sets the CPU affinity mask of the internal counter timer thread.
There is no solution until now and the Upstream recommends to disable the internal timer and think Jitter RNG will not work due to the coarse timer. Check [1] and [2] for more details.
So disable the CPU affinity mask as a workaround to avoid lots of context switch and too high cpu load for a long time.
[1] https://github.com/smuellerDD/jitterentropy-library/issues/37
[2] https://github.com/nhorman/rng-tools/pull/123
Quoted 6 lines
Signed-off-by Mingli Yu <[email protected]>---
...tter.c-disable-the-CPU-affinity-mask.patch | 48 +++++++++++++++++++
.../rng-tools/rng-tools_6.11.bb | 1 +2 files changed, 49 insertions(+)create mode 100644
meta/recipes-support/rng-tools/rng-tools/0001-rngd_jitter.c-disable-the-CPU-affinity-mask.patch
Thanks for investigating this upstream. From an OE-Core perspective, I've very reluctant to take what looks like a very board specific change which the upstream is advising against. The issue is that this will affect all hardware, not just the hardware which has the issue. I think we need to find a better solution.
Cheers,
Richard
Quoted 27 lines · Richard Purdie
Quoted 19 lines · Mingli
From: Mingli Yu <[email protected]>
For the jitter entropy source, each task thread will create an internal counter timer thread when the system clock resolution is under 5MHz.
But it will introduce high cpu usage for a long time and also make random data generate too slow if sets the CPU affinity mask of the internal counter timer thread.
There is no solution until now and the Upstream recommends to disable the internal timer and think Jitter RNG will not work due to the coarse timer. Check [1] and [2] for more details.
So disable the CPU affinity mask as a workaround to avoid lots of context switch and too high cpu load for a long time.
[1] https://github.com/smuellerDD/jitterentropy-library/issues/37
[2] https://github.com/nhorman/rng-tools/pull/123Quoted 6 lines
Signed-off-by Mingli Yu <[email protected]>---
...tter.c-disable-the-CPU-affinity-mask.patch | 48 +++++++++++++++++++
.../rng-tools/rng-tools_6.11.bb | 1 +2 files changed, 49 insertions(+)create mode 100644
meta/recipes-support/rng-tools/rng-tools/0001-rngd_jitter.c-disable-the-CPU-affinity-mask.patch
Quoted 9 lines
Thanks for investigating this upstream. From an OE-Core perspective, I've very reluctant to take what looks like a very board specific change which the upstream is advising against. The issue is that this will affect all hardware, not just the hardware which has the issue. I think we need to find a better solution.
Cheers,
Richard
FWIW I forcefully have to ensure nothing pulls in rng-tools in my builds which are for two different Rockchip chipsets (armv7 and armv8) as the rng-tools binary pegs the CPU at 100% for minutes after boot, every boot. It's particularly annoying as openssh brings it in by default which I've unsuccessfully argued is wrong before. I believe the problem is probably fairly widespread but just unnoticed.
Regards,
Signature · 2 lines
Jack Mitchell, Consultant https://www.tuxable.co.uk
Hi,
Quoted 38 lines · Jack Mitchell
Quoted 27 lines · Richard Purdie
Quoted 19 lines · Mingli
From: Mingli Yu <[email protected]>
For the jitter entropy source, each task thread will create an internal counter timer thread when the system clock resolution is under 5MHz.
But it will introduce high cpu usage for a long time and also make random data generate too slow if sets the CPU affinity mask of the internal counter timer thread.
There is no solution until now and the Upstream recommends to disable the internal timer and think Jitter RNG will not work due to the coarse timer. Check [1] and [2] for more details.
So disable the CPU affinity mask as a workaround to avoid lots of context switch and too high cpu load for a long time.
[1] https://github.com/smuellerDD/jitterentropy-library/issues/37
[2] https://github.com/nhorman/rng-tools/pull/123Quoted 6 lines
Signed-off-by Mingli Yu <[email protected]>---
...tter.c-disable-the-CPU-affinity-mask.patch | 48 +++++++++++++++++++
.../rng-tools/rng-tools_6.11.bb | 1 +2 files changed, 49 insertions(+)create mode 100644
meta/recipes-support/rng-tools/rng-tools/0001-rngd_jitter.c-disable-the-CPU-affinity-mask.patchQuoted 9 lines
Thanks for investigating this upstream. From an OE-Core perspective, I've very reluctant to take what looks like a very board specific change which the upstream is advising against. The issue is that this will affect all hardware, not just the hardware which has the issue. I think we need to find a better solution.
Cheers,
Richard
Quoted 6 lines
FWIW I forcefully have to ensure nothing pulls in rng-tools in my builds which are for two different Rockchip chipsets (armv7 and armv8) as the rng-tools binary pegs the CPU at 100% for minutes after boot, every boot. It's particularly annoying as openssh brings it in by default which I've unsuccessfully argued is wrong before. I believe the problem is probably fairly widespread but just unnoticed.
Unfortunately this is better than not having ssh, TLS etc encrypted access at all to/from the target HW since openssl and kernel refuse to proceed due to lack of entropy.
If your HW has random number generators and driver support is in place, then rng-tools isn't needed.
Cheers,
-Mikko
Quoted 39 lines · Jack Mitchell
Quoted 27 lines · Richard Purdie
Quoted 19 lines · Mingli
From: Mingli Yu <[email protected]>
For the jitter entropy source, each task thread will create an internal counter timer thread when the system clock resolution is under 5MHz.
But it will introduce high cpu usage for a long time and also make random data generate too slow if sets the CPU affinity mask of the internal counter timer thread.
There is no solution until now and the Upstream recommends to disable the internal timer and think Jitter RNG will not work due to the coarse timer. Check [1] and [2] for more details.
So disable the CPU affinity mask as a workaround to avoid lots of context switch and too high cpu load for a long time.
[1] https://github.com/smuellerDD/jitterentropy-library/issues/37
[2] https://github.com/nhorman/rng-tools/pull/123Quoted 6 lines
Signed-off-by Mingli Yu <[email protected]>--- ...tter.c-disable-the-CPU-affinity-mask.patch | 48 +++++++++++++++++++ .../rng-tools/rng-tools_6.11.bb | 1 + 2 files changed, 49 insertions(+) create mode 100644 meta/recipes-support/rng-tools/rng-tools/0001-rngd_jitter.c-disable-the-CPU-affinity-mask.patchQuoted 9 lines
Thanks for investigating this upstream. From an OE-Core perspective, I've very reluctant to take what looks like a very board specific change which the upstream is advising against. The issue is that this will affect all hardware, not just the hardware which has the issue. I think we need to find a better solution.
Cheers,
Richard
Quoted 6 lines
FWIW I forcefully have to ensure nothing pulls in rng-tools in my builds which are for two different Rockchip chipsets (armv7 and armv8) as the rng-tools binary pegs the CPU at 100% for minutes after boot, every boot. It's particularly annoying as openssh brings it in by default which I've unsuccessfully argued is wrong before. I believe the problem is probably fairly widespread but just unnoticed.
Is the reason for the CPU being pegged because of the jitter entropy source? If so, perhaps you can disable libjitterentropy in rng-tools packageconfig. We might also be able to make that packageconfig option more "automatic" by basing it on some high precision timer MACHINE_FEATURE instead of always being included.
Quoted 9 lines
Regards,
--
Jack Mitchell, Consultant
https://www.tuxable.co.uk