Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp2224227yba; Mon, 22 Apr 2019 02:49:43 -0700 (PDT) X-Google-Smtp-Source: APXvYqx+7QKDQRWMJco3H5TZe1wxltc6TQttL3sotaoaNOpdmdniXWtJoQMLtN7LI7FeZlMKXtxL X-Received: by 2002:a63:4644:: with SMTP id v4mr18216283pgk.422.1555926583144; Mon, 22 Apr 2019 02:49:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555926583; cv=none; d=google.com; s=arc-20160816; b=z3p0ugFtTZygVnK5XMOoUomMs2N2BKhL1sBoXSiYfmv6zrSU3yQBqwrO8AwSecj/zs i6ndBE4YNXmonJ68QXWHT4ou6rTIKAtIhtpENYSm67JY0md/pFwaWmlVZfP4X3/eLHqo XGFT0cwytic+T9shdv2uiOvfO2KFHjZLkIEYzP+TegODU4ndXxMrKBDj0JSkXIGaunM7 Ko6CErjFTuavh/KKSz+diZyNi95gr0KqXJ158pPPKtnYt5dnM12/phLVgHQh3k43UMVV 7uBd3x0vuvq1UL9VoxvCGenIXdWG0rmHCavK6fNL1/tV1DIeno8w6eC+Fo4ZNR5bXbIE 6Ibw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-transfer-encoding:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=TXXfU0bJmrKo+5D7gsP1QnnnoNDj7sTQVSu8bYCVM6E=; b=eW7Npu7XBf5ZgPsehPdjBIEcU4eLAo9utZtCbWZt0CV4/2Lg/tlprVsjQ3i6L1i2jr wDcvm4c/YPYlA3Gdm9zQzyPqJ8W4GPcbki3cIHipRJqAd2rYMHM1Qj1qiiJR31weyo1g KwaIIVZeHx20wmdKBrcYOKChsZyU+AHJynL8oZvi/4k5fP9NihhHrxu60pFousj7ChyD ZFV7ehK0GpUHhWr9K89zyIh80KYjY2Xre36iUN8jYrxDFJniB722J5dd2ASrimCkMfPb tacBUCeMOb0Ga9LuF3V68WEUeElfK5DQAxR28w/ekk5+GjQZu0zEQUewitlPogqjQKq4 iVag== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m15si12192197pgj.126.2019.04.22.02.49.27; Mon, 22 Apr 2019 02:49:43 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726502AbfDVJWO (ORCPT + 99 others); Mon, 22 Apr 2019 05:22:14 -0400 Received: from relay03.nicmail.ru ([195.208.3.4]:61090 "EHLO relay03.nicmail.ru" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726164AbfDVJWO (ORCPT ); Mon, 22 Apr 2019 05:22:14 -0400 X-Greylist: delayed 895 seconds by postgrey-1.27 at vger.kernel.org; Mon, 22 Apr 2019 05:22:13 EDT Received: from [109.70.25.186] (port=54594 helo=sghpc.hn.golosunov.pp.ru) by f19.mail.nic.ru with esmtp (Exim 5.55) (envelope-from ) id 1hIUux-000NPk-Ck; Mon, 22 Apr 2019 12:07:16 +0300 Received: from [46.0.38.82] (account sghpc@golosunov.pp.ru HELO sghpc.hn.golosunov.pp.ru) by proxy07.mail.nic.ru (Exim 5.55) with id 1hIUux-0000tC-Rl; Mon, 22 Apr 2019 12:07:15 +0300 Received: from stepan by sghpc.hn.golosunov.pp.ru with local (Exim 4.89) (envelope-from ) id 1hIUut-0002Yb-0e; Mon, 22 Apr 2019 13:07:11 +0400 Date: Mon, 22 Apr 2019 13:07:10 +0400 From: Stepan Golosunov To: Lukasz Majewski , Arnd Bergmann Cc: Deepa Dinamani , libc-alpha@sourceware.org, Paul Eggert , Joseph Myers , John Stultz , Thomas Gleixner , linux-kernel@vger.kernel.org Subject: Re: [PATCH 3/6] y2038: linux: Provide __clock_settime64 implementation Message-ID: <20190422090710.bmxdhhankurhafxq@sghpc.golosunov.pp.ru> References: <20190414220841.20243-1-lukma@denx.de> <20190414220841.20243-4-lukma@denx.de> <20190420002009.l65upn2t3qqoj5uy@sghpc.golosunov.pp.ru> <20190420132112.131f449b@jawa> MIME-Version: 1.0 Content-Type: text/plain; charset=koi8-r Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20190420132112.131f449b@jawa> User-Agent: NeoMutt/20170113 (1.7.2) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 20.04.2019 ? 13:21:12 +0200 Lukasz Majewski ???????: > Hi Stepan, > > > 15.04.2019 ? 00:08:38 +0200 Lukasz Majewski ???????: > > > +# if defined __NR_clock_settime64 > > > + /* Make sure that passed __timespec64 struct pad is 0. */ > > > + struct __timespec64 ts = *tp; > > > + ts.tv_pad = 0; > > > + return INLINE_SYSCALL_CALL (clock_settime64, clock_id, &ts); > > > > Isn't kernel supposed to zero out padding on its own? > > At least comment in kernel's get_timespec64 says so: > > > > /* Zero out the padding for 32 bit systems or in compat mode > > */ if (IS_ENABLED(CONFIG_64BIT_TIME) && in_compat_syscall()) > > kts.tv_nsec &= 0xFFFFFFFFUL; > > > > For ARM (and x86) 32 bit machines I do use following syscalls (like > clock_settime64): > https://elixir.bootlin.com/linux/v5.1-rc4/source/arch/arm/tools/syscall.tbl#L420 > > which are providing 64 bit time support on 32 bit systems. > > Yes. In those systems the upper part (32 bits) of tv_nsec is cleared up > with mask in the kernel. Is it? The kernel (5.1-rc6) code looks to me like /* Zero out the padding for 32 bit systems or in compat mode */ if (false && false) kts.tv_nsec &= 0xFFFFFFFFUL; in 32-bit kernels. And like if (false && true) kts.tv_nsec &= 0xFFFFFFFFUL; for COMPAT syscalls in 64-bit kernels. It should probably be changed into if (!IS_ENABLED(CONFIG_64BIT) || in_compat_syscall()) kts.tv_nsec &= 0xFFFFFFFFUL; (Or into something like if (!IS_ENABLED(CONFIG_64BIT) || in_compat_syscall() && !COMPAT_USE_64BIT_TIME) kts.tv_nsec &= 0xFFFFFFFFUL; if x32 should retain 64-bit tv_nsec.) > However, I would prefer not to pass random data > to the kernel, and hence I do clear it up explicitly in glibc. If the kernel does not ignore padding on its own, then zeroing it out is required everywhere timespec is passed to kernel, including via code not known to glibc. (Does anyone promise that there won't be any ioctls that accept timespec, for example?) That seems to be error-prone (and might requre copying larger structes). On the other hand, if kernel 5.1+ ignores padding as intended there is no need to create additional copy of structs in glibc code that calls into clock_settime64 (or into timer_settime64 that accepts larger struct, for example). > > The code looks buggy though. It fails to zero out the padding in > > 32-bit kernels. > > For the 32 bit systems without Y2038 support enabled in glibc - the > clock_settime would be used, which corresponds to sys_clock_settime32() > in the kernel. I am talking about kernels with Y2038 support. > > That part is probably broken since > > 98f76206b3350 ("compat: Cleanup in_compat_syscall() callers"). > > > > And, hmm, is CONFIG_64BIT_TIME enabled anywhere? I guess that the remaining CONFIG_64BIT_TIME in kernel should be replaced with CONFIG_COMPAT_32BIT_TIME or removed.