Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp399626imm; Fri, 31 Aug 2018 03:35:41 -0700 (PDT) X-Google-Smtp-Source: ANB0VdZvmaNyIrY91J80neKTul+zSvXC1vi7JBjdkJ5fwxqIU6X13C4ef6TB9gzLJ/B6TRBRsODv X-Received: by 2002:a63:e0e:: with SMTP id d14-v6mr8170248pgl.38.1535711741392; Fri, 31 Aug 2018 03:35:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535711741; cv=none; d=google.com; s=arc-20160816; b=WuXHGc3fd4bKPXEFRzegEtPIygAnI0AVKZkWlujW7fU5wWYnqtO2faPiP+7DqyQITC JaeaawphMya2IGk2PryelTBbY9I6zQwnvR5rXzGfwWfgAjXohHOYpIzBFLNrIWUdaLCi 2SegCKDx1LVcJ1mp7Z7Pym4V3YkyrTipiNH0+5H7dJLFPLx2Ph3iMV2Joi4d02iw4b83 G7AX+b2r48/mEdQudDQrUCgFPNaBueMXvAIoueGkY8HdcjrmLKewaetrONo+kPa2mSng QzBeRNvl60rPMVbA9pYhjUtlFfvQOuufzK0PkRKmwMaqcxmE8+uI1poHaOBkcc4lUnwb HI4A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:arc-authentication-results; bh=D8eflnERVVnmyV4uIliMAqFR2z4AI9GlXrW8KWwX/mY=; b=hIflQOdkCGDmhxcZ3hvTtevVo+beXjmZgqyUj5jP1mEFzq4QqNQ9JTxjtlx6u/XHkU AvS8rwmRreHxzMRjFzhAQENlbbXUO3ocdB3kebESFE60sOl4xEUJFGjDsr77dF6QJ9EA EychzBfp8eAZFyspqpZa0W8gAtHlm9+AAy0ZVkoiDuUt1Fj/BI7H8jawxEHiKPeE6V2/ BYzYbmYUZok5hMFoTFOIGhZWLW0IyQZA081h2actyds1zPzU5fevrQycSROuUwSGc6BO ljmLoPiYeBmQWqVKTDgT2Z+BBeFjMrMdC/0PyTzKP74n09PIg14NTu0Yr99CY4nQT+86 BSqA== 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 r7-v6si8659781ple.309.2018.08.31.03.35.26; Fri, 31 Aug 2018 03:35:41 -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 S1727975AbeHaOic (ORCPT + 99 others); Fri, 31 Aug 2018 10:38:32 -0400 Received: from mail-qt0-f194.google.com ([209.85.216.194]:37746 "EHLO mail-qt0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726493AbeHaOib (ORCPT ); Fri, 31 Aug 2018 10:38:31 -0400 Received: by mail-qt0-f194.google.com with SMTP id n6-v6so13938544qtl.4; Fri, 31 Aug 2018 03:31:40 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=D8eflnERVVnmyV4uIliMAqFR2z4AI9GlXrW8KWwX/mY=; b=m1g1UyaqhLb/11tzBdBw11XZPW2I5RcKYYVTduF1mb3emFWk6Vbm8/AW07kjLtNI9f 7VX8dbO1ubTsRbWeR4sQs1EPylO2Wh55aa80zo2mJJmh7BrDk2m30fMXScPinm8lQckp cbWaBx8ogI0ZoPRyj+Z0I5nHo/edIsehx0KfA5s+wIhca/QMzbvDnPCZU6eMxuDl1cM5 29x2txhu4dwsSR8WNc7jz+cXcq3L2F3bjzVDhqVshdHq+ELwZ51OjBdtKcWijg2HKraK b7jw5qPpl9QFiS88OgbOx8r6V4hwyQlBkMDAnC5xpqs3Hjg89Dz5Cs77WX5a1z/5S2rv oq2w== X-Gm-Message-State: APzg51BLY+bgCdJpohiPmCyzMe3wVIZLye8HQysbso5LdGh2dV2VZhye NVy3WdQzsTV8J9R5l1yxcsK2cmbWzIK9W29edn8i/Fhs X-Received: by 2002:aed:3f22:: with SMTP id p31-v6mr15106815qtf.185.1535711500103; Fri, 31 Aug 2018 03:31:40 -0700 (PDT) MIME-Version: 1.0 References: <20180829130308.3504560-1-arnd@arndb.de> In-Reply-To: From: Arnd Bergmann Date: Fri, 31 Aug 2018 12:31:23 +0200 Message-ID: Subject: Re: [PATCH net-next 1/3] net: rework SIOCGSTAMP ioctl handling To: Willem de Bruijn Cc: Networking , David Miller , linux-arch , y2038 Mailman List , Eric Dumazet , Willem de Bruijn , Linux Kernel Mailing List , linux-hams@vger.kernel.org, Bluez mailing list , linux-can@vger.kernel.org, dccp@vger.kernel.org, linux-wpan@vger.kernel.org, linux-sctp@vger.kernel.org, linux-x25@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Aug 30, 2018 at 10:10 PM Willem de Bruijn wrote: > > On Wed, Aug 29, 2018 at 9:05 AM Arnd Bergmann wrote: > > > > The SIOCGSTAMP/SIOCGSTAMPNS ioctl commands are implemented by many > > socket protocol handlers, and all of those end up calling the same > > sock_get_timestamp()/sock_get_timestampns() helper functions, which > > results in a lot of duplicate code. > > > > With the introduction of 64-bit time_t on 32-bit architectures, this > > gets worse, as we then need four different ioctl commands in each > > socket protocol implementation. > > > > To simplify that, let's add a new .gettstamp() operation in > > struct proto_ops, and move ioctl implementation into the common > > sock_ioctl()/compat_sock_ioctl_trans() functions that these all go > > through. > > > > We can reuse the sock_get_timestamp() implementation, but generalize > > it so it can deal with both native and compat mode, as well as > > timeval and timespec structures. > > > > Signed-off-by: Arnd Bergmann > > This also will simplify fixing a recently reported race condition with > sock_get_timestamp [1]. That calls sock_enable_timestamp, which > modifies sk->sk_flags, without taking the socket lock. Currently some > callers of sock_get_timestamp hold the lock (ax25, netrom, qrtr), many > don't. See also how this patch removes the lock_sock in the netrom > case. Moving the call to sock_gettstamp outside the protocol handlers > will allow taking the lock inside the function. I suppose it would be best to always take that lock then, rather than removing the lock as my patch does at the moment. > If this is the only valid implementation of .gettstamp, the indirect > call could be avoided in favor of a simple branch. I thought about that as well, but I could not come up with a good way to encode the difference between socket protocols that allow timestamping and those that don't. I think ideally we would just call sock_gettstamp() unconditonally on every socket, and have that function decide whether timestamps make sense or not. The part I did not understand is which ones actually want the timestamps or not. Most protocols that implement the ioctls also assign skb->tstamp, but there are some protocols in which I could not see skb->tstamp ever being set, and some that set it but don't seem to have the ioctls. Looking at it again, it seems that sock_gettstamp() should actually deal with this gracefully: it will return a -EINVAL error condition if the timestamp remains at the SK_DEFAULT_STAMP initial value, which is probably just as appropriate (or better) as the current -ENOTTY default, and if we are actually recording timestamps, we might just as well report them. > Acked-by: Willem de Bruijn Thanks, Arnd