Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit672f887

Browse files
committed
Merge tag 'timers-urgent-2020-10-25' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
Pull timer fixes from Thomas Gleixner: "A time namespace fix and a matching selftest. The futex absolute timeouts which are based on CLOCK_MONOTONIC require time namespace corrected. This was missed in the original time namesapce support"* tag 'timers-urgent-2020-10-25' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: selftests/timens: Add a test for futex() futex: Adjust absolute futex timeouts with per time namespace offset
2 parents87702a3 +a4fd841 commit672f887

File tree

3 files changed

+116
-1
lines changed

3 files changed

+116
-1
lines changed

‎kernel/futex.c‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
#include<linux/freezer.h>
4040
#include<linux/memblock.h>
4141
#include<linux/fault-inject.h>
42+
#include<linux/time_namespace.h>
4243

4344
#include<asm/futex.h>
4445

@@ -3797,6 +3798,8 @@ SYSCALL_DEFINE6(futex, u32 __user *, uaddr, int, op, u32, val,
37973798
t=timespec64_to_ktime(ts);
37983799
if (cmd==FUTEX_WAIT)
37993800
t=ktime_add_safe(ktime_get(),t);
3801+
elseif (!(op&FUTEX_CLOCK_REALTIME))
3802+
t=timens_ktime_to_host(CLOCK_MONOTONIC,t);
38003803
tp=&t;
38013804
}
38023805
/*
@@ -3989,6 +3992,8 @@ SYSCALL_DEFINE6(futex_time32, u32 __user *, uaddr, int, op, u32, val,
39893992
t=timespec64_to_ktime(ts);
39903993
if (cmd==FUTEX_WAIT)
39913994
t=ktime_add_safe(ktime_get(),t);
3995+
elseif (!(op&FUTEX_CLOCK_REALTIME))
3996+
t=timens_ktime_to_host(CLOCK_MONOTONIC,t);
39923997
tp=&t;
39933998
}
39943999
if (cmd==FUTEX_REQUEUE||cmd==FUTEX_CMP_REQUEUE||

‎tools/testing/selftests/timens/Makefile‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
TEST_GEN_PROGS := timens timerfd timer clock_nanosleep procfs exec
1+
TEST_GEN_PROGS := timens timerfd timer clock_nanosleep procfs exec futex
22
TEST_GEN_PROGS_EXTENDED := gettime_perf
33

44
CFLAGS := -Wall -Werror -pthread
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
#define_GNU_SOURCE
3+
#include<sched.h>
4+
5+
#include<linux/unistd.h>
6+
#include<linux/futex.h>
7+
#include<stdio.h>
8+
#include<string.h>
9+
#include<sys/syscall.h>
10+
#include<sys/types.h>
11+
#include<sys/wait.h>
12+
#include<time.h>
13+
#include<unistd.h>
14+
15+
#include"log.h"
16+
#include"timens.h"
17+
18+
#defineNSEC_PER_SEC 1000000000ULL
19+
20+
staticintrun_test(intclockid)
21+
{
22+
intfutex_op=FUTEX_WAIT_BITSET;
23+
structtimespectimeout,end;
24+
intval=0;
25+
26+
if (clockid==CLOCK_REALTIME)
27+
futex_op |=FUTEX_CLOCK_REALTIME;
28+
29+
clock_gettime(clockid,&timeout);
30+
timeout.tv_nsec+=NSEC_PER_SEC /10;// 100ms
31+
if (timeout.tv_nsec>NSEC_PER_SEC) {
32+
timeout.tv_sec++;
33+
timeout.tv_nsec-=NSEC_PER_SEC;
34+
}
35+
36+
if (syscall(__NR_futex,&val,futex_op,0,
37+
&timeout,0,FUTEX_BITSET_MATCH_ANY) >=0) {
38+
ksft_test_result_fail("futex didn't return ETIMEDOUT\n");
39+
return1;
40+
}
41+
42+
if (errno!=ETIMEDOUT) {
43+
ksft_test_result_fail("futex didn't return ETIMEDOUT: %s\n",
44+
strerror(errno));
45+
return1;
46+
}
47+
48+
clock_gettime(clockid,&end);
49+
50+
if (end.tv_sec<timeout.tv_sec||
51+
(end.tv_sec==timeout.tv_sec&&end.tv_nsec<timeout.tv_nsec)) {
52+
ksft_test_result_fail("futex slept less than 100ms\n");
53+
return1;
54+
}
55+
56+
57+
ksft_test_result_pass("futex with the %d clockid\n",clockid);
58+
59+
return0;
60+
}
61+
62+
intmain(intargc,char*argv[])
63+
{
64+
intstatus,len,fd;
65+
charbuf[4096];
66+
pid_tpid;
67+
structtimespecmtime_now;
68+
69+
nscheck();
70+
71+
ksft_set_plan(2);
72+
73+
clock_gettime(CLOCK_MONOTONIC,&mtime_now);
74+
75+
if (unshare_timens())
76+
return1;
77+
78+
len=snprintf(buf,sizeof(buf),"%d %d 0",
79+
CLOCK_MONOTONIC,70*24*3600);
80+
fd=open("/proc/self/timens_offsets",O_WRONLY);
81+
if (fd<0)
82+
returnpr_perror("/proc/self/timens_offsets");
83+
84+
if (write(fd,buf,len)!=len)
85+
returnpr_perror("/proc/self/timens_offsets");
86+
87+
close(fd);
88+
89+
pid=fork();
90+
if (pid<0)
91+
returnpr_perror("Unable to fork");
92+
if (pid==0) {
93+
intret=0;
94+
95+
ret |=run_test(CLOCK_REALTIME);
96+
ret |=run_test(CLOCK_MONOTONIC);
97+
if (ret)
98+
ksft_exit_fail();
99+
ksft_exit_pass();
100+
return0;
101+
}
102+
103+
if (waitpid(pid,&status,0)!=pid)
104+
returnpr_perror("Unable to wait the child process");
105+
106+
if (WIFEXITED(status))
107+
returnWEXITSTATUS(status);
108+
109+
return1;
110+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp