Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp298775ybp; Thu, 10 Oct 2019 18:26:45 -0700 (PDT) X-Google-Smtp-Source: APXvYqwzBW+Va5xZmODlV0JHCftyVaZX8KCac4ZUr5T4kdjvvVxh71G5BMCggHxThm4DTXgVO7QV X-Received: by 2002:a17:906:11d8:: with SMTP id o24mr11276091eja.224.1570757205747; Thu, 10 Oct 2019 18:26:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570757205; cv=none; d=google.com; s=arc-20160816; b=JpdyC1sLmQi6RNN9JrVWaojuW4R1HotJQ0dCYqgUjR3mh/KZUQzEQXZ18zphp+VnYF V+HJqnjaswt8YEgMgZkcU7b6JkNTysX5px4sTn7xZdoL+k41RA3cmkLLIDGnXsq/lkYe ryg1Fo0R5L7XP/QwYDbOjysAsqDH8WpH+WhoMeVk5e1TEK3gGUf2Le+dkIt5JqErwkFt IM5iYZnpkyNwG1QjQ2GJeo19KltFQqE9Q3HPio3fLp7jgqvN8gFXtqJW1TykfVXrAgQQ H3ByO04Si/Blv9gy1v/7SkKSVXodKGAnLaB9QcbhkcWmaPLhSgsWBNX+So+3tqTmEvSn 6nKA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=KKMvh3TVCiPMPLUBrZ3DHVUeq/BZpRss8YldgguRDNM=; b=AX51OnZ5TlNG2FyDyTjE1OWmZcIa/XKM6prUCU6jenq4HUXIY2uID01o6I9RW/1+yS dprl3lOT8iS+LlVKRB61CEGoZHvYZiuF4/avPY7rjBOp6pHVgv2trvz74i2z8fNqRKi/ D71wGqfJ8pImFeIMBxC06THI251sWvzW7saX8MhlabFetbOT+fgz4zgtL0l9oluO1RGV hUmqmSXCjv9Wo0omFXHwUbPH5leDqgzrcUw5wau/jixgkS1tVPkgT3yw7tG80xVDv+Pg N3vZKiJyZAwznoCb+Plur328H65eDVQXmRpt/cTD3u4zmQk+GiurzK5YOx7uFDDFcDU2 WwuQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@arista.com header.s=googlenew header.b=m7aym05t; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=REJECT dis=NONE) header.from=arista.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 20si4393837ejv.342.2019.10.10.18.26.21; Thu, 10 Oct 2019 18:26:45 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@arista.com header.s=googlenew header.b=m7aym05t; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=REJECT dis=NONE) header.from=arista.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728426AbfJKBZ2 (ORCPT + 99 others); Thu, 10 Oct 2019 21:25:28 -0400 Received: from mail-wr1-f68.google.com ([209.85.221.68]:36268 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728146AbfJKBYK (ORCPT ); Thu, 10 Oct 2019 21:24:10 -0400 Received: by mail-wr1-f68.google.com with SMTP id y19so9966020wrd.3 for ; Thu, 10 Oct 2019 18:24:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=arista.com; s=googlenew; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=KKMvh3TVCiPMPLUBrZ3DHVUeq/BZpRss8YldgguRDNM=; b=m7aym05tTiVEW8U1ykPTY+A/LOE4gvvek69lIq/4PpKGDPfT3+/Kt+ZpetJnkh1YGd 7XM3EdcLTNR+BmjKy8hQQLLADfjPPjJYtbMjWTSc60pPhhOygzO4lRJefAEufF8u2tj+ Zo4rvanU/aEaHbTL+jTfxuNz6I4QLLLpo/QREZYctp6NPL+z9j0rtsqfJRtbubHAk/B1 /U9IqwzC2QsLFdVf8NTGGTG9VqlZpXa3JGi4Kmuid763iykAUaCvhZQhUHaxU79PZxRe qlX0rHeHw44k4bqyvFX2+4o9OL5AUrVYT+CRgHM0iUyY7WvEQnoZuH6H4bsg2etUgNMA peFg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=KKMvh3TVCiPMPLUBrZ3DHVUeq/BZpRss8YldgguRDNM=; b=nuqjHCA69+8a6BnyrUtDAKmf+6a9pkCjnYvz5ySbJlkOsMuDNNnHZaIYkVPtIm4MlV ZBBvdVzmcx9CH34I07Tnj/6mZlo0arZe5vx4KHY0PuXHVCgj3SBIN6+R80zBy6gUaQ5m 8g1DTvUBUCoVOLyYv5zeUN5AS8rlLJIOo9nKsn+tARyX6Qt0sSoXTH07Yeg9Q1O9xMvR ve6YJUYZx7gek9vWCsgMMB87r8poLI6dAKhjCA0vUFDN8po/ahifvUIyp1QnHg7Z7O1c Xyq56pdRhHYZBbPX2glWlpph3e08MUq+QduJAt3CreNRpfMCKCfcumWyeqlPpyw/+UYY pchA== X-Gm-Message-State: APjAAAVJ9YzdhsSDgEQwNQFJLJ092B0Mx42ZvMefi2qWr6xv/G4uhAGa Qvtsn17ktI7TnpmvPCo3ycC8O4JswF4= X-Received: by 2002:a5d:6b0a:: with SMTP id v10mr10189124wrw.32.1570757047992; Thu, 10 Oct 2019 18:24:07 -0700 (PDT) Received: from localhost.localdomain ([2a02:8084:ea2:c100:228:f8ff:fe6f:83a8]) by smtp.gmail.com with ESMTPSA id l13sm7699795wmj.25.2019.10.10.18.24.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Oct 2019 18:24:07 -0700 (PDT) From: Dmitry Safonov To: linux-kernel@vger.kernel.org Cc: Dmitry Safonov <0x7f454c46@gmail.com>, Andrei Vagin , Dmitry Safonov , Adrian Reber , Andy Lutomirski , Arnd Bergmann , Christian Brauner , Cyrill Gorcunov , "Eric W. Biederman" , "H. Peter Anvin" , Ingo Molnar , Jann Horn , Jeff Dike , Oleg Nesterov , Pavel Emelyanov , Shuah Khan , Thomas Gleixner , Vincenzo Frascino , containers@lists.linux-foundation.org, criu@openvz.org, linux-api@vger.kernel.org, x86@kernel.org Subject: [PATCHv7 15/33] posix-timers: Make clock_nanosleep() time namespace aware Date: Fri, 11 Oct 2019 02:23:23 +0100 Message-Id: <20191011012341.846266-16-dima@arista.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191011012341.846266-1-dima@arista.com> References: <20191011012341.846266-1-dima@arista.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Andrei Vagin clock_nanosleep() accepts absolute values of expiration time, if the TIMER_ABSTIME flag is set. This value is in the task time namespace, which has to be converted to the host time namespace. Signed-off-by: Andrei Vagin Co-developed-by: Dmitry Safonov Signed-off-by: Dmitry Safonov --- kernel/time/posix-stubs.c | 12 ++++++++++-- kernel/time/posix-timers.c | 17 +++++++++++++++-- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/kernel/time/posix-stubs.c b/kernel/time/posix-stubs.c index 2ccefc9ce184..47ee2684d250 100644 --- a/kernel/time/posix-stubs.c +++ b/kernel/time/posix-stubs.c @@ -129,6 +129,7 @@ SYSCALL_DEFINE4(clock_nanosleep, const clockid_t, which_clock, int, flags, struct __kernel_timespec __user *, rmtp) { struct timespec64 t; + ktime_t texp; switch (which_clock) { case CLOCK_REALTIME: @@ -147,7 +148,10 @@ SYSCALL_DEFINE4(clock_nanosleep, const clockid_t, which_clock, int, flags, rmtp = NULL; current->restart_block.nanosleep.type = rmtp ? TT_NATIVE : TT_NONE; current->restart_block.nanosleep.rmtp = rmtp; - return hrtimer_nanosleep(timespec64_to_ktime(t), flags & TIMER_ABSTIME ? + texp = timespec64_to_ktime(t); + if (flags & TIMER_ABSTIME) + texp = timens_ktime_to_host(clockid, texp); + return hrtimer_nanosleep(texp, flags & TIMER_ABSTIME ? HRTIMER_MODE_ABS : HRTIMER_MODE_REL, which_clock); } @@ -215,6 +219,7 @@ SYSCALL_DEFINE4(clock_nanosleep_time32, clockid_t, which_clock, int, flags, struct old_timespec32 __user *, rmtp) { struct timespec64 t; + ktime texp; switch (which_clock) { case CLOCK_REALTIME: @@ -233,7 +238,10 @@ SYSCALL_DEFINE4(clock_nanosleep_time32, clockid_t, which_clock, int, flags, rmtp = NULL; current->restart_block.nanosleep.type = rmtp ? TT_COMPAT : TT_NONE; current->restart_block.nanosleep.compat_rmtp = rmtp; - return hrtimer_nanosleep(timespec64_to_ktime(t), flags & TIMER_ABSTIME ? + texp = timespec64_to_ktime(t); + if (flags & TIMER_ABSTIME) + texp = timens_ktime_to_host(clockid, texp); + return hrtimer_nanosleep(texp, flags & TIMER_ABSTIME ? HRTIMER_MODE_ABS : HRTIMER_MODE_REL, which_clock); } diff --git a/kernel/time/posix-timers.c b/kernel/time/posix-timers.c index c0ae1f6d2add..ccae99a645e1 100644 --- a/kernel/time/posix-timers.c +++ b/kernel/time/posix-timers.c @@ -1228,6 +1228,19 @@ static int common_nsleep(const clockid_t which_clock, int flags, which_clock); } +static int common_nsleep_timens(const clockid_t which_clock, int flags, + const struct timespec64 *rqtp) +{ + ktime_t texp = timespec64_to_ktime(*rqtp); + + if (flags & TIMER_ABSTIME) + texp = timens_ktime_to_host(which_clock, texp); + + return hrtimer_nanosleep(texp, flags & TIMER_ABSTIME ? + HRTIMER_MODE_ABS : HRTIMER_MODE_REL, + which_clock); +} + SYSCALL_DEFINE4(clock_nanosleep, const clockid_t, which_clock, int, flags, const struct __kernel_timespec __user *, rqtp, struct __kernel_timespec __user *, rmtp) @@ -1305,7 +1318,7 @@ static const struct k_clock clock_monotonic = { .clock_getres = posix_get_hrtimer_res, .clock_get_timespec = posix_get_monotonic_timespec, .clock_get_ktime = posix_get_monotonic_ktime, - .nsleep = common_nsleep, + .nsleep = common_nsleep_timens, .timer_create = common_timer_create, .timer_set = common_timer_set, .timer_get = common_timer_get, @@ -1354,7 +1367,7 @@ static const struct k_clock clock_boottime = { .clock_getres = posix_get_hrtimer_res, .clock_get_ktime = posix_get_boottime_ktime, .clock_get_timespec = posix_get_boottime_timespec, - .nsleep = common_nsleep, + .nsleep = common_nsleep_timens, .timer_create = common_timer_create, .timer_set = common_timer_set, .timer_get = common_timer_get, -- 2.23.0