From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S967321AbdADTSH (ORCPT ); Wed, 4 Jan 2017 14:18:07 -0500 Received: from mail-pg0-f50.google.com ([74.125.83.50]:34965 "EHLO mail-pg0-f50.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S966511AbdADTR6 (ORCPT ); Wed, 4 Jan 2017 14:17:58 -0500 Date: Wed, 4 Jan 2017 11:17:49 -0800 From: Stephen Hemminger To: Vitaly Kuznetsov Cc: devel@linuxdriverproject.org, linux-kernel@vger.kernel.org, "K. Y. Srinivasan" , Haiyang Zhang , John Stultz , Thomas Gleixner , Alex Ng Subject: Re: [PATCH v2 4/4] hv_util: improve time adjustment accuracy by disabling interrupts Message-ID: <20170104111749.0e7d566e@xeon-e3> In-Reply-To: <20170104172439.19683-5-vkuznets@redhat.com> References: <20170104172439.19683-1-vkuznets@redhat.com> <20170104172439.19683-5-vkuznets@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 4 Jan 2017 18:24:39 +0100 Vitaly Kuznetsov wrote: > If we happen to receive interrupts during hv_set_host_time() execution > our adjustments may get inaccurate. Make the whole function atomic. > Unfortunately, we can's call do_settimeofday64() with interrupts > disabled as some cross-CPU work is being done but this call happens > very rarely. > > Signed-off-by: Vitaly Kuznetsov Ok, the race is between timer interrupts and calling do_adjtimex(). NTP has the same issue already. The getnstimeofday64() (or ktime_get) return an atomic value. If a clock tick interrupt happens during this code, then the value is still correct just old. If you want to avoid all races here, it looks like it would be better to get timekeeper_lock and call __do_adjtimex. The existing code in do_adjtimex() is expecting to be called from a system call and changing it's assumptions is probably not a good idea. Rather than calling system call from user space. Maybe better to provide real kernel API in time subsystem for this use case. What does KVM do?