* [PATCH 0/4] time namespace aware system boot time
@ 2020-10-07 20:00 Michael Weiß
2020-10-07 20:00 ` [PATCH 1/4] timens: additional helper function to add boottime in nsec Michael Weiß
` (3 more replies)
0 siblings, 4 replies; 7+ messages in thread
From: Michael Weiß @ 2020-10-07 20:00 UTC (permalink / raw)
To: Thomas Gleixner, Andrei Vagin, Dmitry Safonov, Christian Brauner
Cc: linux-kernel, Michael Weiß
Time namespaces make it possible to virtualize time inside of
containers, e.g., it is feasible to reset the uptime of a container
to zero by setting the time namespace offset for boottime to the
negated current value of the CLOCK_BOOTTIME.
However, the boot time stamp provided by getboottime64() does not
take care of time namespaces. The resulting boot time stamp 'btime'
provided by /proc/stat does not show a plausible time stamp inside
the time namespace of a container.
We address this by shifting the value returned by getboottime64()
by subtracting the boottime offset of the time namespace.
(A selftest to check the expected /proc/stat 'btime' inside the
namespace is provided.)
Further, to avoid to show processes as time travelers inside of the
time namespace the boottime offset then needs to be added to the
start_bootime provided by the task_struct.
Michael Weiß (4):
timens: additional helper function to add boottime in nsec
time: make getboottime64 aware of time namespace
fs/proc: apply timens offset for start_boottime of processes
selftests/timens: added selftest for /proc/stat btime
fs/proc/array.c | 6 ++-
include/linux/time_namespace.h | 7 +++
kernel/time/timekeeping.c | 3 ++
tools/testing/selftests/timens/procfs.c | 58 ++++++++++++++++++++++++-
4 files changed, 71 insertions(+), 3 deletions(-)
--
2.20.1
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 1/4] timens: additional helper function to add boottime in nsec
2020-10-07 20:00 [PATCH 0/4] time namespace aware system boot time Michael Weiß
@ 2020-10-07 20:00 ` Michael Weiß
2020-10-07 20:00 ` [PATCH 2/4] time: make getboottime64 aware of time namespace Michael Weiß
` (2 subsequent siblings)
3 siblings, 0 replies; 7+ messages in thread
From: Michael Weiß @ 2020-10-07 20:00 UTC (permalink / raw)
To: Thomas Gleixner, Andrei Vagin, Dmitry Safonov, Christian Brauner
Cc: linux-kernel, Michael Weiß
Provide a helper function to apply the boottime offset to u64 types
in nanoseconds.
Signed-off-by: Michael Weiß <michael.weiss@aisec.fraunhofer.de>
---
include/linux/time_namespace.h | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/include/linux/time_namespace.h b/include/linux/time_namespace.h
index 5b6031385db0..db02ec7dae8a 100644
--- a/include/linux/time_namespace.h
+++ b/include/linux/time_namespace.h
@@ -77,6 +77,13 @@ static inline void timens_add_boottime(struct timespec64 *ts)
*ts = timespec64_add(*ts, ns_offsets->boottime);
}
+static inline u64 timens_add_boottime_ns(u64 nsec)
+{
+ struct timens_offsets *ns_offsets = ¤t->nsproxy->time_ns->offsets;
+
+ return nsec + timespec64_to_ns(&ns_offsets->boottime);
+}
+
ktime_t do_timens_ktime_to_host(clockid_t clockid, ktime_t tim,
struct timens_offsets *offsets);
--
2.20.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 2/4] time: make getboottime64 aware of time namespace
2020-10-07 20:00 [PATCH 0/4] time namespace aware system boot time Michael Weiß
2020-10-07 20:00 ` [PATCH 1/4] timens: additional helper function to add boottime in nsec Michael Weiß
@ 2020-10-07 20:00 ` Michael Weiß
2020-10-07 20:00 ` [PATCH 3/4] fs/proc: apply timens offset for start_boottime of processes Michael Weiß
2020-10-07 20:00 ` [PATCH 4/4] selftests/timens: added selftest for /proc/stat btime Michael Weiß
3 siblings, 0 replies; 7+ messages in thread
From: Michael Weiß @ 2020-10-07 20:00 UTC (permalink / raw)
To: Thomas Gleixner, Andrei Vagin, Dmitry Safonov, Christian Brauner
Cc: linux-kernel, Michael Weiß
getboottime64() provides the time stamp of system boot. In case of
time namespaces, the offset to the boot time stamp was not applied
earlier. However, getboottime64 is used e.g., in /proc/stat to print
the system boot time to userspace. In container runtimes which utilize
time namespaces to virtualize boottime of a container, this leaks
information about the host system boot time.
Therefore, we make getboottime64() to respect the time namespace offset
for boottime by subtracting the boottime offset.
Signed-off-by: Michael Weiß <michael.weiss@aisec.fraunhofer.de>
---
kernel/time/timekeeping.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
index 4c47f388a83f..67530cdb389e 100644
--- a/kernel/time/timekeeping.c
+++ b/kernel/time/timekeeping.c
@@ -17,6 +17,7 @@
#include <linux/clocksource.h>
#include <linux/jiffies.h>
#include <linux/time.h>
+#include <linux/time_namespace.h>
#include <linux/tick.h>
#include <linux/stop_machine.h>
#include <linux/pvclock_gtod.h>
@@ -2154,6 +2155,8 @@ void getboottime64(struct timespec64 *ts)
{
struct timekeeper *tk = &tk_core.timekeeper;
ktime_t t = ktime_sub(tk->offs_real, tk->offs_boot);
+ /* shift boot time stamp according to the timens offset */
+ t = timens_ktime_to_host(CLOCK_BOOTTIME, t);
*ts = ktime_to_timespec64(t);
}
--
2.20.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 3/4] fs/proc: apply timens offset for start_boottime of processes
2020-10-07 20:00 [PATCH 0/4] time namespace aware system boot time Michael Weiß
2020-10-07 20:00 ` [PATCH 1/4] timens: additional helper function to add boottime in nsec Michael Weiß
2020-10-07 20:00 ` [PATCH 2/4] time: make getboottime64 aware of time namespace Michael Weiß
@ 2020-10-07 20:00 ` Michael Weiß
2020-10-07 22:38 ` kernel test robot
2020-10-07 20:00 ` [PATCH 4/4] selftests/timens: added selftest for /proc/stat btime Michael Weiß
3 siblings, 1 reply; 7+ messages in thread
From: Michael Weiß @ 2020-10-07 20:00 UTC (permalink / raw)
To: Thomas Gleixner, Andrei Vagin, Dmitry Safonov, Christian Brauner
Cc: linux-kernel, Michael Weiß
Since start_boottime of processes are seconds since boottime and the
boottime stamp is now shifted according to the timens offset, the
offset of the time namespace also needs to be applied before the
process stats are given to userspace.
This avoids that processes shown, e.g., by 'ps' appear as time
travelers in the corresponding time namespace.
Signed-off-by: Michael Weiß <michael.weiss@aisec.fraunhofer.de>
---
fs/proc/array.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/fs/proc/array.c b/fs/proc/array.c
index 65ec2029fa80..277f654f289e 100644
--- a/fs/proc/array.c
+++ b/fs/proc/array.c
@@ -56,6 +56,7 @@
#include <linux/types.h>
#include <linux/errno.h>
#include <linux/time.h>
+#include <linux/time_namespace.h>
#include <linux/kernel.h>
#include <linux/kernel_stat.h>
#include <linux/tty.h>
@@ -533,8 +534,9 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
priority = task_prio(task);
nice = task_nice(task);
- /* convert nsec -> ticks */
- start_time = nsec_to_clock_t(task->start_boottime);
+ /* apply timens offset for boottime and convert nsec -> ticks */
+ start_time =
+ nsec_to_clock_t(timens_add_boottime_ns(task->start_boottime));
seq_put_decimal_ull(m, "", pid_nr_ns(pid, ns));
seq_puts(m, " (");
--
2.20.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 4/4] selftests/timens: added selftest for /proc/stat btime
2020-10-07 20:00 [PATCH 0/4] time namespace aware system boot time Michael Weiß
` (2 preceding siblings ...)
2020-10-07 20:00 ` [PATCH 3/4] fs/proc: apply timens offset for start_boottime of processes Michael Weiß
@ 2020-10-07 20:00 ` Michael Weiß
3 siblings, 0 replies; 7+ messages in thread
From: Michael Weiß @ 2020-10-07 20:00 UTC (permalink / raw)
To: Thomas Gleixner, Andrei Vagin, Dmitry Safonov, Christian Brauner
Cc: linux-kernel, Michael Weiß
Test that btime value of /proc/stat is as expected in the time namespace
using a simple parser to get btime from /proc/stat.
Signed-off-by: Michael Weiß <michael.weiss@aisec.fraunhofer.de>
---
tools/testing/selftests/timens/procfs.c | 58 ++++++++++++++++++++++++-
1 file changed, 57 insertions(+), 1 deletion(-)
diff --git a/tools/testing/selftests/timens/procfs.c b/tools/testing/selftests/timens/procfs.c
index 7f14f0fdac84..f2519154208a 100644
--- a/tools/testing/selftests/timens/procfs.c
+++ b/tools/testing/selftests/timens/procfs.c
@@ -93,6 +93,33 @@ static int read_proc_uptime(struct timespec *uptime)
return 0;
}
+static int read_proc_stat_btime(unsigned long long *boottime_sec)
+{
+ FILE *proc;
+ char line_buf[2048];
+
+ proc = fopen("/proc/stat", "r");
+ if (proc == NULL) {
+ pr_perror("Unable to open /proc/stat");
+ return -1;
+ }
+
+ while (fgets(line_buf, 2048, proc)) {
+ if (sscanf(line_buf, "btime %llu", boottime_sec) != 1)
+ continue;
+ fclose(proc);
+ return 0;
+ }
+ if (errno) {
+ pr_perror("fscanf");
+ fclose(proc);
+ return -errno;
+ }
+ pr_err("failed to parse /proc/stat");
+ fclose(proc);
+ return -1;
+}
+
static int check_uptime(void)
{
struct timespec uptime_new, uptime_old;
@@ -123,18 +150,47 @@ static int check_uptime(void)
return 0;
}
+static int check_stat_btime(void)
+{
+ unsigned long long btime_new, btime_old;
+ unsigned long long btime_expected;
+
+ if (switch_ns(parent_ns))
+ return pr_err("switch_ns(%d)", parent_ns);
+
+ if (read_proc_stat_btime(&btime_old))
+ return 1;
+
+ if (switch_ns(child_ns))
+ return pr_err("switch_ns(%d)", child_ns);
+
+ if (read_proc_stat_btime(&btime_new))
+ return 1;
+
+ btime_expected = btime_old - TEN_DAYS_IN_SEC;
+ if (btime_new != btime_expected) {
+ pr_fail("btime in /proc/stat: old %llu, new %llu [%llu]",
+ btime_old, btime_new, btime_expected);
+ return 1;
+ }
+
+ ksft_test_result_pass("Passed for /proc/stat btime\n");
+ return 0;
+}
+
int main(int argc, char *argv[])
{
int ret = 0;
nscheck();
- ksft_set_plan(1);
+ ksft_set_plan(2);
if (init_namespaces())
return 1;
ret |= check_uptime();
+ ret |= check_stat_btime();
if (ret)
ksft_exit_fail();
--
2.20.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH 3/4] fs/proc: apply timens offset for start_boottime of processes
2020-10-07 20:00 ` [PATCH 3/4] fs/proc: apply timens offset for start_boottime of processes Michael Weiß
@ 2020-10-07 22:38 ` kernel test robot
0 siblings, 0 replies; 7+ messages in thread
From: kernel test robot @ 2020-10-07 22:38 UTC (permalink / raw)
To: Michael Weiß,
Thomas Gleixner, Andrei Vagin, Dmitry Safonov, Christian Brauner
Cc: kbuild-all, linux-kernel, Michael Weiß
[-- Attachment #1: Type: text/plain, Size: 9498 bytes --]
Hi "Michael,
Thank you for the patch! Yet something to improve:
[auto build test ERROR on tip/timers/core]
[also build test ERROR on kselftest/next linux/master linus/master v5.9-rc8 next-20201007]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/0day-ci/linux/commits/Michael-Wei/time-namespace-aware-system-boot-time/20201008-042240
base: https://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git 1b80043ed21894eca888157145b955df02887995
config: i386-randconfig-s031-20201008 (attached as .config)
compiler: gcc-9 (Debian 9.3.0-15) 9.3.0
reproduce:
# apt-get install sparse
# sparse version: v0.6.2-218-gc0e96d6d-dirty
# https://github.com/0day-ci/linux/commit/7896182eb6f184679138887429b286006d1c5172
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Michael-Wei/time-namespace-aware-system-boot-time/20201008-042240
git checkout 7896182eb6f184679138887429b286006d1c5172
# save the attached .config to linux build tree
make W=1 C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' ARCH=i386
If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>
All errors (new ones prefixed by >>):
fs/proc/array.c: In function 'do_task_stat':
>> fs/proc/array.c:539:19: error: implicit declaration of function 'timens_add_boottime_ns'; did you mean 'timens_add_boottime'? [-Werror=implicit-function-declaration]
539 | nsec_to_clock_t(timens_add_boottime_ns(task->start_boottime));
| ^~~~~~~~~~~~~~~~~~~~~~
| timens_add_boottime
cc1: some warnings being treated as errors
vim +539 fs/proc/array.c
431
432 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
433 struct pid *pid, struct task_struct *task, int whole)
434 {
435 unsigned long vsize, eip, esp, wchan = 0;
436 int priority, nice;
437 int tty_pgrp = -1, tty_nr = 0;
438 sigset_t sigign, sigcatch;
439 char state;
440 pid_t ppid = 0, pgid = -1, sid = -1;
441 int num_threads = 0;
442 int permitted;
443 struct mm_struct *mm;
444 unsigned long long start_time;
445 unsigned long cmin_flt = 0, cmaj_flt = 0;
446 unsigned long min_flt = 0, maj_flt = 0;
447 u64 cutime, cstime, utime, stime;
448 u64 cgtime, gtime;
449 unsigned long rsslim = 0;
450 unsigned long flags;
451
452 state = *get_task_state(task);
453 vsize = eip = esp = 0;
454 permitted = ptrace_may_access(task, PTRACE_MODE_READ_FSCREDS | PTRACE_MODE_NOAUDIT);
455 mm = get_task_mm(task);
456 if (mm) {
457 vsize = task_vsize(mm);
458 /*
459 * esp and eip are intentionally zeroed out. There is no
460 * non-racy way to read them without freezing the task.
461 * Programs that need reliable values can use ptrace(2).
462 *
463 * The only exception is if the task is core dumping because
464 * a program is not able to use ptrace(2) in that case. It is
465 * safe because the task has stopped executing permanently.
466 */
467 if (permitted && (task->flags & (PF_EXITING|PF_DUMPCORE))) {
468 if (try_get_task_stack(task)) {
469 eip = KSTK_EIP(task);
470 esp = KSTK_ESP(task);
471 put_task_stack(task);
472 }
473 }
474 }
475
476 sigemptyset(&sigign);
477 sigemptyset(&sigcatch);
478 cutime = cstime = utime = stime = 0;
479 cgtime = gtime = 0;
480
481 if (lock_task_sighand(task, &flags)) {
482 struct signal_struct *sig = task->signal;
483
484 if (sig->tty) {
485 struct pid *pgrp = tty_get_pgrp(sig->tty);
486 tty_pgrp = pid_nr_ns(pgrp, ns);
487 put_pid(pgrp);
488 tty_nr = new_encode_dev(tty_devnum(sig->tty));
489 }
490
491 num_threads = get_nr_threads(task);
492 collect_sigign_sigcatch(task, &sigign, &sigcatch);
493
494 cmin_flt = sig->cmin_flt;
495 cmaj_flt = sig->cmaj_flt;
496 cutime = sig->cutime;
497 cstime = sig->cstime;
498 cgtime = sig->cgtime;
499 rsslim = READ_ONCE(sig->rlim[RLIMIT_RSS].rlim_cur);
500
501 /* add up live thread stats at the group level */
502 if (whole) {
503 struct task_struct *t = task;
504 do {
505 min_flt += t->min_flt;
506 maj_flt += t->maj_flt;
507 gtime += task_gtime(t);
508 } while_each_thread(task, t);
509
510 min_flt += sig->min_flt;
511 maj_flt += sig->maj_flt;
512 thread_group_cputime_adjusted(task, &utime, &stime);
513 gtime += sig->gtime;
514 }
515
516 sid = task_session_nr_ns(task, ns);
517 ppid = task_tgid_nr_ns(task->real_parent, ns);
518 pgid = task_pgrp_nr_ns(task, ns);
519
520 unlock_task_sighand(task, &flags);
521 }
522
523 if (permitted && (!whole || num_threads < 2))
524 wchan = get_wchan(task);
525 if (!whole) {
526 min_flt = task->min_flt;
527 maj_flt = task->maj_flt;
528 task_cputime_adjusted(task, &utime, &stime);
529 gtime = task_gtime(task);
530 }
531
532 /* scale priority and nice values from timeslices to -20..20 */
533 /* to make it look like a "normal" Unix priority/nice value */
534 priority = task_prio(task);
535 nice = task_nice(task);
536
537 /* apply timens offset for boottime and convert nsec -> ticks */
538 start_time =
> 539 nsec_to_clock_t(timens_add_boottime_ns(task->start_boottime));
540
541 seq_put_decimal_ull(m, "", pid_nr_ns(pid, ns));
542 seq_puts(m, " (");
543 proc_task_name(m, task, false);
544 seq_puts(m, ") ");
545 seq_putc(m, state);
546 seq_put_decimal_ll(m, " ", ppid);
547 seq_put_decimal_ll(m, " ", pgid);
548 seq_put_decimal_ll(m, " ", sid);
549 seq_put_decimal_ll(m, " ", tty_nr);
550 seq_put_decimal_ll(m, " ", tty_pgrp);
551 seq_put_decimal_ull(m, " ", task->flags);
552 seq_put_decimal_ull(m, " ", min_flt);
553 seq_put_decimal_ull(m, " ", cmin_flt);
554 seq_put_decimal_ull(m, " ", maj_flt);
555 seq_put_decimal_ull(m, " ", cmaj_flt);
556 seq_put_decimal_ull(m, " ", nsec_to_clock_t(utime));
557 seq_put_decimal_ull(m, " ", nsec_to_clock_t(stime));
558 seq_put_decimal_ll(m, " ", nsec_to_clock_t(cutime));
559 seq_put_decimal_ll(m, " ", nsec_to_clock_t(cstime));
560 seq_put_decimal_ll(m, " ", priority);
561 seq_put_decimal_ll(m, " ", nice);
562 seq_put_decimal_ll(m, " ", num_threads);
563 seq_put_decimal_ull(m, " ", 0);
564 seq_put_decimal_ull(m, " ", start_time);
565 seq_put_decimal_ull(m, " ", vsize);
566 seq_put_decimal_ull(m, " ", mm ? get_mm_rss(mm) : 0);
567 seq_put_decimal_ull(m, " ", rsslim);
568 seq_put_decimal_ull(m, " ", mm ? (permitted ? mm->start_code : 1) : 0);
569 seq_put_decimal_ull(m, " ", mm ? (permitted ? mm->end_code : 1) : 0);
570 seq_put_decimal_ull(m, " ", (permitted && mm) ? mm->start_stack : 0);
571 seq_put_decimal_ull(m, " ", esp);
572 seq_put_decimal_ull(m, " ", eip);
573 /* The signal information here is obsolete.
574 * It must be decimal for Linux 2.0 compatibility.
575 * Use /proc/#/status for real-time signals.
576 */
577 seq_put_decimal_ull(m, " ", task->pending.signal.sig[0] & 0x7fffffffUL);
578 seq_put_decimal_ull(m, " ", task->blocked.sig[0] & 0x7fffffffUL);
579 seq_put_decimal_ull(m, " ", sigign.sig[0] & 0x7fffffffUL);
580 seq_put_decimal_ull(m, " ", sigcatch.sig[0] & 0x7fffffffUL);
581
582 /*
583 * We used to output the absolute kernel address, but that's an
584 * information leak - so instead we show a 0/1 flag here, to signal
585 * to user-space whether there's a wchan field in /proc/PID/wchan.
586 *
587 * This works with older implementations of procps as well.
588 */
589 if (wchan)
590 seq_puts(m, " 1");
591 else
592 seq_puts(m, " 0");
593
594 seq_put_decimal_ull(m, " ", 0);
595 seq_put_decimal_ull(m, " ", 0);
596 seq_put_decimal_ll(m, " ", task->exit_signal);
597 seq_put_decimal_ll(m, " ", task_cpu(task));
598 seq_put_decimal_ull(m, " ", task->rt_priority);
599 seq_put_decimal_ull(m, " ", task->policy);
600 seq_put_decimal_ull(m, " ", delayacct_blkio_ticks(task));
601 seq_put_decimal_ull(m, " ", nsec_to_clock_t(gtime));
602 seq_put_decimal_ll(m, " ", nsec_to_clock_t(cgtime));
603
604 if (mm && permitted) {
605 seq_put_decimal_ull(m, " ", mm->start_data);
606 seq_put_decimal_ull(m, " ", mm->end_data);
607 seq_put_decimal_ull(m, " ", mm->start_brk);
608 seq_put_decimal_ull(m, " ", mm->arg_start);
609 seq_put_decimal_ull(m, " ", mm->arg_end);
610 seq_put_decimal_ull(m, " ", mm->env_start);
611 seq_put_decimal_ull(m, " ", mm->env_end);
612 } else
613 seq_puts(m, " 0 0 0 0 0 0 0");
614
615 if (permitted)
616 seq_put_decimal_ll(m, " ", task->exit_code);
617 else
618 seq_puts(m, " 0");
619
620 seq_putc(m, '\n');
621 if (mm)
622 mmput(mm);
623 return 0;
624 }
625
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org
[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 28342 bytes --]
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 3/4] fs/proc: apply timens offset for start_boottime of processes
@ 2020-10-07 22:38 ` kernel test robot
0 siblings, 0 replies; 7+ messages in thread
From: kernel test robot @ 2020-10-07 22:38 UTC (permalink / raw)
To: kbuild-all
[-- Attachment #1: Type: text/plain, Size: 9737 bytes --]
Hi "Michael,
Thank you for the patch! Yet something to improve:
[auto build test ERROR on tip/timers/core]
[also build test ERROR on kselftest/next linux/master linus/master v5.9-rc8 next-20201007]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/0day-ci/linux/commits/Michael-Wei/time-namespace-aware-system-boot-time/20201008-042240
base: https://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git 1b80043ed21894eca888157145b955df02887995
config: i386-randconfig-s031-20201008 (attached as .config)
compiler: gcc-9 (Debian 9.3.0-15) 9.3.0
reproduce:
# apt-get install sparse
# sparse version: v0.6.2-218-gc0e96d6d-dirty
# https://github.com/0day-ci/linux/commit/7896182eb6f184679138887429b286006d1c5172
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Michael-Wei/time-namespace-aware-system-boot-time/20201008-042240
git checkout 7896182eb6f184679138887429b286006d1c5172
# save the attached .config to linux build tree
make W=1 C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' ARCH=i386
If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>
All errors (new ones prefixed by >>):
fs/proc/array.c: In function 'do_task_stat':
>> fs/proc/array.c:539:19: error: implicit declaration of function 'timens_add_boottime_ns'; did you mean 'timens_add_boottime'? [-Werror=implicit-function-declaration]
539 | nsec_to_clock_t(timens_add_boottime_ns(task->start_boottime));
| ^~~~~~~~~~~~~~~~~~~~~~
| timens_add_boottime
cc1: some warnings being treated as errors
vim +539 fs/proc/array.c
431
432 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
433 struct pid *pid, struct task_struct *task, int whole)
434 {
435 unsigned long vsize, eip, esp, wchan = 0;
436 int priority, nice;
437 int tty_pgrp = -1, tty_nr = 0;
438 sigset_t sigign, sigcatch;
439 char state;
440 pid_t ppid = 0, pgid = -1, sid = -1;
441 int num_threads = 0;
442 int permitted;
443 struct mm_struct *mm;
444 unsigned long long start_time;
445 unsigned long cmin_flt = 0, cmaj_flt = 0;
446 unsigned long min_flt = 0, maj_flt = 0;
447 u64 cutime, cstime, utime, stime;
448 u64 cgtime, gtime;
449 unsigned long rsslim = 0;
450 unsigned long flags;
451
452 state = *get_task_state(task);
453 vsize = eip = esp = 0;
454 permitted = ptrace_may_access(task, PTRACE_MODE_READ_FSCREDS | PTRACE_MODE_NOAUDIT);
455 mm = get_task_mm(task);
456 if (mm) {
457 vsize = task_vsize(mm);
458 /*
459 * esp and eip are intentionally zeroed out. There is no
460 * non-racy way to read them without freezing the task.
461 * Programs that need reliable values can use ptrace(2).
462 *
463 * The only exception is if the task is core dumping because
464 * a program is not able to use ptrace(2) in that case. It is
465 * safe because the task has stopped executing permanently.
466 */
467 if (permitted && (task->flags & (PF_EXITING|PF_DUMPCORE))) {
468 if (try_get_task_stack(task)) {
469 eip = KSTK_EIP(task);
470 esp = KSTK_ESP(task);
471 put_task_stack(task);
472 }
473 }
474 }
475
476 sigemptyset(&sigign);
477 sigemptyset(&sigcatch);
478 cutime = cstime = utime = stime = 0;
479 cgtime = gtime = 0;
480
481 if (lock_task_sighand(task, &flags)) {
482 struct signal_struct *sig = task->signal;
483
484 if (sig->tty) {
485 struct pid *pgrp = tty_get_pgrp(sig->tty);
486 tty_pgrp = pid_nr_ns(pgrp, ns);
487 put_pid(pgrp);
488 tty_nr = new_encode_dev(tty_devnum(sig->tty));
489 }
490
491 num_threads = get_nr_threads(task);
492 collect_sigign_sigcatch(task, &sigign, &sigcatch);
493
494 cmin_flt = sig->cmin_flt;
495 cmaj_flt = sig->cmaj_flt;
496 cutime = sig->cutime;
497 cstime = sig->cstime;
498 cgtime = sig->cgtime;
499 rsslim = READ_ONCE(sig->rlim[RLIMIT_RSS].rlim_cur);
500
501 /* add up live thread stats at the group level */
502 if (whole) {
503 struct task_struct *t = task;
504 do {
505 min_flt += t->min_flt;
506 maj_flt += t->maj_flt;
507 gtime += task_gtime(t);
508 } while_each_thread(task, t);
509
510 min_flt += sig->min_flt;
511 maj_flt += sig->maj_flt;
512 thread_group_cputime_adjusted(task, &utime, &stime);
513 gtime += sig->gtime;
514 }
515
516 sid = task_session_nr_ns(task, ns);
517 ppid = task_tgid_nr_ns(task->real_parent, ns);
518 pgid = task_pgrp_nr_ns(task, ns);
519
520 unlock_task_sighand(task, &flags);
521 }
522
523 if (permitted && (!whole || num_threads < 2))
524 wchan = get_wchan(task);
525 if (!whole) {
526 min_flt = task->min_flt;
527 maj_flt = task->maj_flt;
528 task_cputime_adjusted(task, &utime, &stime);
529 gtime = task_gtime(task);
530 }
531
532 /* scale priority and nice values from timeslices to -20..20 */
533 /* to make it look like a "normal" Unix priority/nice value */
534 priority = task_prio(task);
535 nice = task_nice(task);
536
537 /* apply timens offset for boottime and convert nsec -> ticks */
538 start_time =
> 539 nsec_to_clock_t(timens_add_boottime_ns(task->start_boottime));
540
541 seq_put_decimal_ull(m, "", pid_nr_ns(pid, ns));
542 seq_puts(m, " (");
543 proc_task_name(m, task, false);
544 seq_puts(m, ") ");
545 seq_putc(m, state);
546 seq_put_decimal_ll(m, " ", ppid);
547 seq_put_decimal_ll(m, " ", pgid);
548 seq_put_decimal_ll(m, " ", sid);
549 seq_put_decimal_ll(m, " ", tty_nr);
550 seq_put_decimal_ll(m, " ", tty_pgrp);
551 seq_put_decimal_ull(m, " ", task->flags);
552 seq_put_decimal_ull(m, " ", min_flt);
553 seq_put_decimal_ull(m, " ", cmin_flt);
554 seq_put_decimal_ull(m, " ", maj_flt);
555 seq_put_decimal_ull(m, " ", cmaj_flt);
556 seq_put_decimal_ull(m, " ", nsec_to_clock_t(utime));
557 seq_put_decimal_ull(m, " ", nsec_to_clock_t(stime));
558 seq_put_decimal_ll(m, " ", nsec_to_clock_t(cutime));
559 seq_put_decimal_ll(m, " ", nsec_to_clock_t(cstime));
560 seq_put_decimal_ll(m, " ", priority);
561 seq_put_decimal_ll(m, " ", nice);
562 seq_put_decimal_ll(m, " ", num_threads);
563 seq_put_decimal_ull(m, " ", 0);
564 seq_put_decimal_ull(m, " ", start_time);
565 seq_put_decimal_ull(m, " ", vsize);
566 seq_put_decimal_ull(m, " ", mm ? get_mm_rss(mm) : 0);
567 seq_put_decimal_ull(m, " ", rsslim);
568 seq_put_decimal_ull(m, " ", mm ? (permitted ? mm->start_code : 1) : 0);
569 seq_put_decimal_ull(m, " ", mm ? (permitted ? mm->end_code : 1) : 0);
570 seq_put_decimal_ull(m, " ", (permitted && mm) ? mm->start_stack : 0);
571 seq_put_decimal_ull(m, " ", esp);
572 seq_put_decimal_ull(m, " ", eip);
573 /* The signal information here is obsolete.
574 * It must be decimal for Linux 2.0 compatibility.
575 * Use /proc/#/status for real-time signals.
576 */
577 seq_put_decimal_ull(m, " ", task->pending.signal.sig[0] & 0x7fffffffUL);
578 seq_put_decimal_ull(m, " ", task->blocked.sig[0] & 0x7fffffffUL);
579 seq_put_decimal_ull(m, " ", sigign.sig[0] & 0x7fffffffUL);
580 seq_put_decimal_ull(m, " ", sigcatch.sig[0] & 0x7fffffffUL);
581
582 /*
583 * We used to output the absolute kernel address, but that's an
584 * information leak - so instead we show a 0/1 flag here, to signal
585 * to user-space whether there's a wchan field in /proc/PID/wchan.
586 *
587 * This works with older implementations of procps as well.
588 */
589 if (wchan)
590 seq_puts(m, " 1");
591 else
592 seq_puts(m, " 0");
593
594 seq_put_decimal_ull(m, " ", 0);
595 seq_put_decimal_ull(m, " ", 0);
596 seq_put_decimal_ll(m, " ", task->exit_signal);
597 seq_put_decimal_ll(m, " ", task_cpu(task));
598 seq_put_decimal_ull(m, " ", task->rt_priority);
599 seq_put_decimal_ull(m, " ", task->policy);
600 seq_put_decimal_ull(m, " ", delayacct_blkio_ticks(task));
601 seq_put_decimal_ull(m, " ", nsec_to_clock_t(gtime));
602 seq_put_decimal_ll(m, " ", nsec_to_clock_t(cgtime));
603
604 if (mm && permitted) {
605 seq_put_decimal_ull(m, " ", mm->start_data);
606 seq_put_decimal_ull(m, " ", mm->end_data);
607 seq_put_decimal_ull(m, " ", mm->start_brk);
608 seq_put_decimal_ull(m, " ", mm->arg_start);
609 seq_put_decimal_ull(m, " ", mm->arg_end);
610 seq_put_decimal_ull(m, " ", mm->env_start);
611 seq_put_decimal_ull(m, " ", mm->env_end);
612 } else
613 seq_puts(m, " 0 0 0 0 0 0 0");
614
615 if (permitted)
616 seq_put_decimal_ll(m, " ", task->exit_code);
617 else
618 seq_puts(m, " 0");
619
620 seq_putc(m, '\n');
621 if (mm)
622 mmput(mm);
623 return 0;
624 }
625
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
[-- Attachment #2: config.gz --]
[-- Type: application/gzip, Size: 28342 bytes --]
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2020-10-07 22:39 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-07 20:00 [PATCH 0/4] time namespace aware system boot time Michael Weiß
2020-10-07 20:00 ` [PATCH 1/4] timens: additional helper function to add boottime in nsec Michael Weiß
2020-10-07 20:00 ` [PATCH 2/4] time: make getboottime64 aware of time namespace Michael Weiß
2020-10-07 20:00 ` [PATCH 3/4] fs/proc: apply timens offset for start_boottime of processes Michael Weiß
2020-10-07 22:38 ` kernel test robot
2020-10-07 22:38 ` kernel test robot
2020-10-07 20:00 ` [PATCH 4/4] selftests/timens: added selftest for /proc/stat btime Michael Weiß
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.