From patchwork Fri Nov 10 15:58:27 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 118587 Delivered-To: patch@linaro.org Received: by 10.140.22.164 with SMTP id 33csp8099546qgn; Fri, 10 Nov 2017 07:59:19 -0800 (PST) X-Google-Smtp-Source: AGs4zMbIu77vzilKqZ0jiu3sCUE2K6BoeaSEMH3DHcNSk5DYp37Lzcg1wp3J/1toEeqZ0MDcOOYl X-Received: by 10.84.128.9 with SMTP id 9mr809612pla.332.1510329559712; Fri, 10 Nov 2017 07:59:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1510329559; cv=none; d=google.com; s=arc-20160816; b=oHLStVn7TbZiXuxK9OeYnUFC4TJjjNlPlitp7ydJF1pj3MmDx+zZouELVkGwwkxdzh HA9Am7oB6FO4SH83W5ZfvtIjNYa/2Db1bDeMLgiqbndOYsabq5Z+KFVVb2nxOPEZAhpS MBTMVjJOaW4CTeCwV80DHvGDsrlKqklP9YhbAdPQyJTcKg8skBSZJn7W4voi5/R8aI5E mKxr8epzmQzjFgJt36nmFuAERSJjKKactF2R5qqodx+bvJr81/3pTqy+32nFZ2oCmgB/ SdnpjB/AiPmR3X2p01QYIMMKhnivXyIFL3bUrGWXPuA8zwIRBv+jZez+6a1kYQkp6vCO mwLw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=Aw0uK2NOfqiyAUHs3/RZeuRsnGyBvvcDbVI8je7GpX8=; b=w4WIgeUq+1PJNPYLxanFEj5jcLLun4rzrC2JGaSoUiHOcaK/hKXyFrky5c/hznx3SR flZWHLcUQVO9eGUo11sTvow1dHvqlbEQ95zy4tZSgCBq/y062jE/PZ4nM0FNJa8Wlq1K l4ugtFc9oeGHi9aapJ03zhfRo4IIFzpE5FRUCPZrsGJ/ln0zTtLIU+TFMiPWI9aFjmY1 XUuL9Op9z/YG21Xv7wPLBxbfkT9WRjPN2IcKW94uTVL4YUYRsl7fqrJ9pKjpkVXvTC5F BR3K0vnOu/Pg7pFEEQ6tKpEshKpjQfLsmdbQnAn42ezDRRcMSp7VYFXpfDlf3zJHPU1J d5oQ== 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 h11si8769485pgp.611.2017.11.10.07.59.19; Fri, 10 Nov 2017 07:59:19 -0800 (PST) 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 S1753234AbdKJP7R (ORCPT + 24 others); Fri, 10 Nov 2017 10:59:17 -0500 Received: from mout.kundenserver.de ([217.72.192.74]:56813 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751191AbdKJP7P (ORCPT ); Fri, 10 Nov 2017 10:59:15 -0500 Received: from wuerfel.lan ([109.193.157.232]) by mrelayeu.kundenserver.de (mreue103 [212.227.15.145]) with ESMTPA (Nemesis) id 0Lo2Ke-1esr7S2DlI-00fyum; Fri, 10 Nov 2017 16:59:06 +0100 From: Arnd Bergmann To: Adam Radford , "James E.J. Bottomley" , "Martin K. Petersen" Cc: Arnd Bergmann , Sumit Saxena , linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 3/3] scsi: 3w-9xxx: rework lock timeouts Date: Fri, 10 Nov 2017 16:58:27 +0100 Message-Id: <20171110155840.1941250-3-arnd@arndb.de> X-Mailer: git-send-email 2.9.0 In-Reply-To: <20171110155840.1941250-1-arnd@arndb.de> References: <20171110155840.1941250-1-arnd@arndb.de> X-Provags-ID: V03:K0:6KCvk5auDwKDHtsDO5IWcEMfx+CBrbjts+B2Y8yA352GP5nQOrL VoO9Vupcynn8p+OKuDqxOD0GUeUe9KK8Tm/xIdlpPpgMjWcPgboHlw11Z+shRYlWL8GdlY1 3O/6NBR1dalK1pEjYex+X/1/6N+32W2T9Q8MZL9uPksjtpR19qSDsD9G9yqHqKPTvrO2Oln g/pmToQJpjJ3zdIwIGlJg== X-UI-Out-Filterresults: notjunk:1; V01:K0:Yfi0bK9b1iU=:eEf5vz0mAElNMceiK7Vs/y nEn3y23na4qfWilX1MCD6rKAy3nX1VgDMd0+B4XvWKiqlsAKYKElI5Hs55x+ATVBJ4AF1cGKI cidDLUaENvGRklciGX6UfUxh8a/ZTq76eu8DxXl4rRVvHPABgUx5gJ3NRFGcANsXsRdZaWlEi 2i3ycvOxz+9nv36VW8l9sf9bQvsId0O5pw0OBVHurXjOtphfyDysDeDYnAxXKp02B4f7FoW8n gY8+++8x+YIaiEk/Ze7i3Mf9ZGy6Rs45OdlD64M/OY3m/RGVOGZoWs3C1BONcTbMtOHq8O3vU iZLPJgq+acM3aHAj+swAWmuYafBzoSoH5zFaBMC3akqx9t+beHgqpiJfTx4p59yQ7mCen7vdM gGEO/T7pt0HcyCwVARitwpxeQngRoWmOGmO0fsKwdodrCvLs0OQL8/06xlSTDaxX6oixCwDdY +ya8CJ8/GyD584JgczMvFnMSKs5THqEAmtNl7QxlDPH0aFZW84KcEYW8htQYPw+8ad1TnWtUn Flw2aGse656YjCR3WUfmje76H9oOldiFRTPfA+eTG+E9XKc6Hx3AMCYDHuY/+HKbhqjrh0gfL 5wnA4S3EBnMzVrC1x8II1SUnYmfN4rQKL7n1fDtKa5hkb61AtZ0/YjoW+lnVu2AwjQAR6t1uP 8z7UD1gkf2/2rKPbeLJAVXAy+CFVaoxVRsJLwnZU6sT5NpGOWidjHCpz8pm5RWZsQa8zDntsG PVgV9ggh2PK9t9CfT3mS8NpUrECEcISht0IRqw== Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The TW_IOCTL_GET_LOCK ioctl uses do_gettimeofday() to check whether a lock has expired. This can misbehave due to a concurrent settimeofday() call, as it is based on 'real' time, and it will overflow in y2038 on 32-bit architectures, producing unexpected results when used across the overflow time. This changes it to using monotonic time, using ktime_get() to simplify the code. Signed-off-by: Arnd Bergmann --- drivers/scsi/3w-9xxx.c | 13 ++++++------- drivers/scsi/3w-9xxx.h | 2 +- 2 files changed, 7 insertions(+), 8 deletions(-) -- 2.9.0 Acked-by: Adam Radford diff --git a/drivers/scsi/3w-9xxx.c b/drivers/scsi/3w-9xxx.c index b1c9bd9c1bfd..b42c9c479d4b 100644 --- a/drivers/scsi/3w-9xxx.c +++ b/drivers/scsi/3w-9xxx.c @@ -645,8 +645,7 @@ static long twa_chrdev_ioctl(struct file *file, unsigned int cmd, unsigned long TW_Command_Full *full_command_packet; TW_Compatibility_Info *tw_compat_info; TW_Event *event; - struct timeval current_time; - u32 current_time_ms; + ktime_t current_time; TW_Device_Extension *tw_dev = twa_device_extension_list[iminor(inode)]; int retval = TW_IOCTL_ERROR_OS_EFAULT; void __user *argp = (void __user *)arg; @@ -837,17 +836,17 @@ static long twa_chrdev_ioctl(struct file *file, unsigned int cmd, unsigned long break; case TW_IOCTL_GET_LOCK: tw_lock = (TW_Lock *)tw_ioctl->data_buffer; - do_gettimeofday(¤t_time); - current_time_ms = (current_time.tv_sec * 1000) + (current_time.tv_usec / 1000); + current_time = ktime_get(); - if ((tw_lock->force_flag == 1) || (tw_dev->ioctl_sem_lock == 0) || (current_time_ms >= tw_dev->ioctl_msec)) { + if ((tw_lock->force_flag == 1) || (tw_dev->ioctl_sem_lock == 0) || + ktime_after(current_time, tw_dev->ioctl_time)) { tw_dev->ioctl_sem_lock = 1; - tw_dev->ioctl_msec = current_time_ms + tw_lock->timeout_msec; + tw_dev->ioctl_time = ktime_add_ms(current_time, tw_lock->timeout_msec); tw_ioctl->driver_command.status = 0; tw_lock->time_remaining_msec = tw_lock->timeout_msec; } else { tw_ioctl->driver_command.status = TW_IOCTL_ERROR_STATUS_LOCKED; - tw_lock->time_remaining_msec = tw_dev->ioctl_msec - current_time_ms; + tw_lock->time_remaining_msec = ktime_ms_delta(tw_dev->ioctl_time, current_time); } break; case TW_IOCTL_RELEASE_LOCK: diff --git a/drivers/scsi/3w-9xxx.h b/drivers/scsi/3w-9xxx.h index b6c208cc474f..d88cd3499bd5 100644 --- a/drivers/scsi/3w-9xxx.h +++ b/drivers/scsi/3w-9xxx.h @@ -666,7 +666,7 @@ typedef struct TAG_TW_Device_Extension { unsigned char event_queue_wrapped; unsigned int error_sequence_id; int ioctl_sem_lock; - u32 ioctl_msec; + ktime_t ioctl_time; int chrdev_request_id; wait_queue_head_t ioctl_wqueue; struct mutex ioctl_lock;