Received: by 10.223.164.221 with SMTP id h29csp165585wrb; Tue, 31 Oct 2017 11:48:47 -0700 (PDT) X-Google-Smtp-Source: ABhQp+RYd5GK5u5DDFlrZvtriQhwEM98PMPKrvTM1237pqLaJjJX5zGsyjlIZTX5Q8MLQuc8P5pj X-Received: by 10.101.65.75 with SMTP id x11mr2546307pgp.388.1509475727110; Tue, 31 Oct 2017 11:48:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1509475727; cv=none; d=google.com; s=arc-20160816; b=we4I1FlUCOmYurFHAVuF5DQjy0YmcyvNDQSfcntNff0/5uq/5p62rykPmI/U0MoY4q g3u0mNoyUkIXNtBEf/YIAYSHRl119eJ3puylwWOqlqBMFJuxdq3sK99eIcyKIjLFdjzP Mn1FUYyqnP3lXXepPTGNn2VBY93xHB7EG0cnZtqRtN8zJK/onZVWq0/5ZqMTFsZ8w9wf oyUc1l7MIRidDoWLEYMtxS5NhzaClscnh/+SPEeIlFdvg9yf30mmWyG3Zo+iF78VlY4O sgBXLO6oe5WPOS/vN4SuVJTPWNK1eKx/giGu4ovPj0EBmwtIKncIHEzOvHSAY+jCAAZx 5Uww== 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 :thread-index:mime-version:in-reply-to:references:from :dkim-signature:arc-authentication-results; bh=jOgc8DXV3VK/6UiArdDKZCqwrqAJMYdHg+tUzosmJnY=; b=tz1Z87NpKLOyMrC3KY+yeDLNRfWRiNZ5xl9SjpR8MYrT7+dLOwqHAvBgHiwbQPqipK OB8wXqCa8ZQ0yN5QsmEd9QaB9l7BQcnc5WiI+NqUOah8MTihHqrLAm4jxd0CF3/reU6c zRnrR/adVfNTyW26BH2HPC4mMYQ3mGce9w/Nb75AVRrU09EzMJnevAelO3+/5uDFVS8/ qhqPqRO/xgDurbVucblymVkkDT+7d54WhArCO1CW6PJz8ar/ShnqavcNupb0lRXvuDga 4xVctVkwfee/Dt5b7yd9h/Nfkwn/Dp+Xf96IjQT3ZDrG1sfmTo+AHwYozCcHqtOdi2ML nziA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@broadcom.com header.s=google header.b=Tjlxz04D; 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=QUARANTINE dis=NONE) header.from=broadcom.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v6si2278716pfa.316.2017.10.31.11.48.33; Tue, 31 Oct 2017 11:48:47 -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=@broadcom.com header.s=google header.b=Tjlxz04D; 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=QUARANTINE dis=NONE) header.from=broadcom.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753585AbdJaSsC (ORCPT + 99 others); Tue, 31 Oct 2017 14:48:02 -0400 Received: from mail-oi0-f67.google.com ([209.85.218.67]:51093 "EHLO mail-oi0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751796AbdJaSsA (ORCPT ); Tue, 31 Oct 2017 14:48:00 -0400 Received: by mail-oi0-f67.google.com with SMTP id q4so28256999oic.7 for ; Tue, 31 Oct 2017 11:47:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; h=from:references:in-reply-to:mime-version:thread-index:date :message-id:subject:to:cc; bh=jOgc8DXV3VK/6UiArdDKZCqwrqAJMYdHg+tUzosmJnY=; b=Tjlxz04DTxng66v1DWJZPzNIicw/szSeZjVkz22SMgKL0sddM7dAs8ryg01XAjSB/R WXlOUbFFY5IxCNl4KsliBNCBb/nM5HFmpDGcZv0fsqKWID/WWP6/JI0xlia7fNHtVBGf 68JOQNQ61aDvDr4gqoRV1NcVGuBjayZAY4fLw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:references:in-reply-to:mime-version :thread-index:date:message-id:subject:to:cc; bh=jOgc8DXV3VK/6UiArdDKZCqwrqAJMYdHg+tUzosmJnY=; b=C8AVauVr1Vo8/zMJQBrrB0N14zRPHUR1xeF6Qb13mG89GkqReQonpaHT6aFmDz9rzd x5nLwyrUYZBRkGQ/ndJ32K5EU2z6UA3AL3NJXiajfRzxsfjz9xaFowt4Z+QKyaO0VDHh aS2H/Y/cK6CKRblHxGJOtwfBE2uUxDAwus6WV51Xj1yrMJeF19h0U6VXI3FDaKs/zh65 TFnpICIA7JZGTM+35dlBe/L3PSp/MxVl/mmHH7WA4vf3bq0AHEqbI+wLumUCeI0+kphP O6UcywdjJParxoLQQldpjbrepCrhq0YWmjR0NeqzOC6BVRfF51Jcj20SFzrTyrne4btz z2YA== X-Gm-Message-State: AMCzsaUfpixXfbpnyEV/Mo7r50pwmC34nHW3yz5QNrjfhDo7rfp5liML xAzI2YyqjMhirTor352/SNSmymFCg2W/hEWkJrhvwQ== X-Received: by 10.202.199.196 with SMTP id x187mr1403076oif.22.1509475679300; Tue, 31 Oct 2017 11:47:59 -0700 (PDT) From: Sumit Saxena References: <20171025100720.GA145069@beast> In-Reply-To: <20171025100720.GA145069@beast> MIME-Version: 1.0 X-Mailer: Microsoft Outlook 14.0 Thread-Index: AQHcxFmqpfjAQ32GPGufbHT2Qq/rA6LrZuVA Date: Wed, 1 Nov 2017 00:17:56 +0530 Message-ID: <92b3d37d10162a899d5a829351fd1512@mail.gmail.com> Subject: RE: [PATCH] scsi: megaraid: Convert timers to use timer_setup() To: Kees Cook , "Martin K. Petersen" Cc: Kashyap Desai , Shivasharan Srikanteshwara , "James E.J. Bottomley" , "PDL,MEGARAIDLINUX" , linux-scsi@vger.kernel.org, linux-kernel@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 -----Original Message----- From: Kees Cook [mailto:keescook@chromium.org] Sent: Wednesday, October 25, 2017 3:37 PM To: Martin K. Petersen Cc: Kashyap Desai; Sumit Saxena; Shivasharan S; James E.J. Bottomley; megaraidlinux.pdl@broadcom.com; linux-scsi@vger.kernel.org; linux-kernel@vger.kernel.org Subject: [PATCH] scsi: megaraid: Convert timers to use timer_setup() In preparation for unconditionally passing the struct timer_list pointer to all timer callbacks, switch to using the new timer_setup() and from_timer() to pass the timer pointer explicitly. Also consolidates the timer setup functions arguments, which are all identical, and corrects on-stack timer usage. Cc: Kashyap Desai Cc: Sumit Saxena Cc: Shivasharan S Cc: "James E.J. Bottomley" Cc: "Martin K. Petersen" Cc: megaraidlinux.pdl@broadcom.com Cc: linux-scsi@vger.kernel.org Signed-off-by: Kees Cook --- drivers/scsi/megaraid/megaraid_ioctl.h | 6 +++++ drivers/scsi/megaraid/megaraid_mbox.c | 26 ++++++++++----------- drivers/scsi/megaraid/megaraid_mm.c | 27 +++++++++++----------- drivers/scsi/megaraid/megaraid_sas_base.c | 35 +++++++++++------------------ drivers/scsi/megaraid/megaraid_sas_fusion.c | 15 +++---------- 5 files changed, 47 insertions(+), 62 deletions(-) diff --git a/drivers/scsi/megaraid/megaraid_ioctl.h b/drivers/scsi/megaraid/megaraid_ioctl.h index 05f6e4ec3453..eedcbde46459 100644 --- a/drivers/scsi/megaraid/megaraid_ioctl.h +++ b/drivers/scsi/megaraid/megaraid_ioctl.h @@ -19,6 +19,7 @@ #include #include +#include #include "mbox_defs.h" @@ -153,6 +154,11 @@ typedef struct uioc { } __attribute__ ((aligned(1024),packed)) uioc_t; +/* For on-stack uioc timers. */ +struct uioc_timeout { + struct timer_list timer; + uioc_t *uioc; +}; /** * struct mraid_hba_info - information about the controller diff --git a/drivers/scsi/megaraid/megaraid_mbox.c b/drivers/scsi/megaraid/megaraid_mbox.c index ec3c43854978..530358cdcb39 100644 --- a/drivers/scsi/megaraid/megaraid_mbox.c +++ b/drivers/scsi/megaraid/megaraid_mbox.c @@ -3904,19 +3904,19 @@ megaraid_sysfs_get_ldmap_done(uioc_t *uioc) wake_up(&raid_dev->sysfs_wait_q); } - /** * megaraid_sysfs_get_ldmap_timeout - timeout handling for get ldmap - * @data : timed out packet + * @t : timed out timer * * Timeout routine to recover and return to application, in case the adapter * has stopped responding. A timeout of 60 seconds for this command seems like * a good value. */ static void -megaraid_sysfs_get_ldmap_timeout(unsigned long data) +megaraid_sysfs_get_ldmap_timeout(struct timer_list *t) { - uioc_t *uioc = (uioc_t *)data; + struct uioc_timeout *timeout = from_timer(timeout, t, timer); + uioc_t *uioc = timeout->uioc; adapter_t *adapter = (adapter_t *)uioc->buf_vaddr; mraid_device_t *raid_dev = ADAP2RAIDDEV(adapter); @@ -3951,8 +3951,7 @@ megaraid_sysfs_get_ldmap(adapter_t *adapter) mbox64_t *mbox64; mbox_t *mbox; char *raw_mbox; - struct timer_list sysfs_timer; - struct timer_list *timerp; + struct uioc_timeout timeout; caddr_t ldmap; int rval = 0; @@ -3988,14 +3987,12 @@ megaraid_sysfs_get_ldmap(adapter_t *adapter) /* * Setup a timer to recover from a non-responding controller */ - timerp = &sysfs_timer; - init_timer(timerp); - - timerp->function = megaraid_sysfs_get_ldmap_timeout; - timerp->data = (unsigned long)uioc; - timerp->expires = jiffies + 60 * HZ; + timeout.uioc = uioc; + timer_setup_on_stack(&timeout.timer, + megaraid_sysfs_get_ldmap_timeout, 0); Kees, Does calling "timer_setup_on_stack" instead of "timer_setup" intentional ? If yes, please help me understand the reason. Otherwise changes look good to me. - add_timer(timerp); + timeout.timer.expires = jiffies + 60 * HZ; + add_timer(&timeout.timer); /* * Send the command to the firmware @@ -4033,7 +4030,8 @@ megaraid_sysfs_get_ldmap(adapter_t *adapter) } - del_timer_sync(timerp); + del_timer_sync(&timeout.timer); + destroy_timer_on_stack(&timeout.timer); mutex_unlock(&raid_dev->sysfs_mtx); diff --git a/drivers/scsi/megaraid/megaraid_mm.c b/drivers/scsi/megaraid/megaraid_mm.c index 65b6f6ace3a5..bb802b0c12b8 100644 --- a/drivers/scsi/megaraid/megaraid_mm.c +++ b/drivers/scsi/megaraid/megaraid_mm.c @@ -35,7 +35,7 @@ static int kioc_to_mimd(uioc_t *, mimd_t __user *); static int handle_drvrcmd(void __user *, uint8_t, int *); static int lld_ioctl(mraid_mmadp_t *, uioc_t *); static void ioctl_done(uioc_t *); -static void lld_timedout(unsigned long); +static void lld_timedout(struct timer_list *); static void hinfo_to_cinfo(mraid_hba_info_t *, mcontroller_t *); static mraid_mmadp_t *mraid_mm_get_adapter(mimd_t __user *, int *); static uioc_t *mraid_mm_alloc_kioc(mraid_mmadp_t *); @@ -686,8 +686,7 @@ static int lld_ioctl(mraid_mmadp_t *adp, uioc_t *kioc) { int rval; - struct timer_list timer; - struct timer_list *tp = NULL; + struct uioc_timeout timeout = { }; kioc->status = -ENODATA; rval = adp->issue_uioc(adp->drvr_data, kioc, IOCTL_ISSUE); @@ -698,14 +697,12 @@ lld_ioctl(mraid_mmadp_t *adp, uioc_t *kioc) * Start the timer */ if (adp->timeout > 0) { - tp = &timer; - init_timer(tp); + timeout.uioc = kioc; + timer_setup_on_stack(&timeout.timer, lld_timedout, 0); Same question as above. - tp->function = lld_timedout; - tp->data = (unsigned long)kioc; - tp->expires = jiffies + adp->timeout * HZ; + timeout.timer.expires = jiffies + adp->timeout * HZ; - add_timer(tp); + add_timer(&timeout.timer); } /* @@ -713,8 +710,9 @@ lld_ioctl(mraid_mmadp_t *adp, uioc_t *kioc) * call, the ioctl either completed successfully or timedout. */ wait_event(wait_q, (kioc->status != -ENODATA)); - if (tp) { - del_timer_sync(tp); + if (timeout.timer.function) { + del_timer_sync(&timeout.timer); + destroy_timer_on_stack(&timeout.timer); } /* @@ -783,12 +781,13 @@ ioctl_done(uioc_t *kioc) /** * lld_timedout - callback from the expired timer - * @ptr : ioctl packet that timed out + * @t : timer that timed out */ static void -lld_timedout(unsigned long ptr) +lld_timedout(struct timer_list *t) { - uioc_t *kioc = (uioc_t *)ptr; + struct uioc_timeout *timeout = from_timer(timeout, t, timer); + uioc_t *kioc = timeout->uioc; kioc->status = -ETIME; kioc->timedout = 1; diff --git a/drivers/scsi/megaraid/megaraid_sas_base.c b/drivers/scsi/megaraid/megaraid_sas_base.c index e518dadc8161..a36e18156e49 100644 --- a/drivers/scsi/megaraid/megaraid_sas_base.c +++ b/drivers/scsi/megaraid/megaraid_sas_base.c @@ -2114,22 +2114,19 @@ static void megasas_complete_cmd_dpc(unsigned long instance_addr) megasas_check_and_restore_queue_depth(instance); } +static void megasas_sriov_heartbeat_handler(struct timer_list *t); + /** - * megasas_start_timer - Initializes a timer object + * megasas_start_timer - Initializes sriov heartbeat timer object * @instance: Adapter soft state - * @timer: timer object to be initialized - * @fn: timer function - * @interval: time interval between timer function call * */ -void megasas_start_timer(struct megasas_instance *instance, - struct timer_list *timer, - void *fn, unsigned long interval) -{ - init_timer(timer); - timer->expires = jiffies + interval; - timer->data = (unsigned long)instance; - timer->function = fn; +void megasas_start_timer(struct megasas_instance *instance) { + struct timer_list *timer = &instance->sriov_heartbeat_timer; + + timer_setup(timer, megasas_sriov_heartbeat_handler, 0); + timer->expires = jiffies + MEGASAS_SRIOV_HEARTBEAT_INTERVAL_VF; add_timer(timer); } @@ -2515,10 +2512,10 @@ int megasas_sriov_start_heartbeat(struct megasas_instance *instance, } /* Handler for SR-IOV heartbeat */ -void megasas_sriov_heartbeat_handler(unsigned long instance_addr) +static void megasas_sriov_heartbeat_handler(struct timer_list *t) { struct megasas_instance *instance = - (struct megasas_instance *)instance_addr; + from_timer(instance, t, sriov_heartbeat_timer); if (instance->hb_host_mem->HB.fwCounter != instance->hb_host_mem->HB.driverCounter) { @@ -5493,10 +5490,7 @@ static int megasas_init_fw(struct megasas_instance *instance) /* Launch SR-IOV heartbeat timer */ if (instance->requestorId) { if (!megasas_sriov_start_heartbeat(instance, 1)) - megasas_start_timer(instance, - &instance->sriov_heartbeat_timer, - megasas_sriov_heartbeat_handler, - MEGASAS_SRIOV_HEARTBEAT_INTERVAL_VF); + megasas_start_timer(instance); else instance->skip_heartbeat_timer_del = 1; } @@ -6507,10 +6501,7 @@ megasas_resume(struct pci_dev *pdev) /* Re-launch SR-IOV heartbeat timer */ if (instance->requestorId) { if (!megasas_sriov_start_heartbeat(instance, 0)) - megasas_start_timer(instance, - &instance->sriov_heartbeat_timer, - megasas_sriov_heartbeat_handler, - MEGASAS_SRIOV_HEARTBEAT_INTERVAL_VF); + megasas_start_timer(instance); else { instance->skip_heartbeat_timer_del = 1; goto fail_init_mfi; diff --git a/drivers/scsi/megaraid/megaraid_sas_fusion.c b/drivers/scsi/megaraid/megaraid_sas_fusion.c index 11bd2e698b84..3c399e7b3fe1 100644 --- a/drivers/scsi/megaraid/megaraid_sas_fusion.c +++ b/drivers/scsi/megaraid/megaraid_sas_fusion.c @@ -85,12 +85,9 @@ int megasas_transition_to_ready(struct megasas_instance *instance, int ocr); void megaraid_sas_kill_hba(struct megasas_instance *instance); extern u32 megasas_dbg_lvl; -void megasas_sriov_heartbeat_handler(unsigned long instance_addr); int megasas_sriov_start_heartbeat(struct megasas_instance *instance, int initial); -void megasas_start_timer(struct megasas_instance *instance, - struct timer_list *timer, - void *fn, unsigned long interval); +void megasas_start_timer(struct megasas_instance *instance); extern struct megasas_mgmt_info megasas_mgmt_info; extern unsigned int resetwaittime; extern unsigned int dual_qdepth_disable; @@ -4369,10 +4366,7 @@ int megasas_reset_fusion(struct Scsi_Host *shost, int reason) /* Restart SR-IOV heartbeat */ if (instance->requestorId) { if (!megasas_sriov_start_heartbeat(instance, 0)) - megasas_start_timer(instance, - &instance->sriov_heartbeat_timer, - megasas_sriov_heartbeat_handler, - MEGASAS_SRIOV_HEARTBEAT_INTERVAL_VF); + megasas_start_timer(instance); else instance->skip_heartbeat_timer_del = 1; } @@ -4404,10 +4398,7 @@ int megasas_reset_fusion(struct Scsi_Host *shost, int reason) } else { /* For VF: Restart HB timer if we didn't OCR */ if (instance->requestorId) { - megasas_start_timer(instance, - &instance->sriov_heartbeat_timer, - megasas_sriov_heartbeat_handler, - MEGASAS_SRIOV_HEARTBEAT_INTERVAL_VF); + megasas_start_timer(instance); } clear_bit(MEGASAS_FUSION_IN_RESET, &instance->reset_flags); instance->instancet->enable_intr(instance); -- 2.7.4 -- Kees Cook Pixel Security From 1582788565609659867@xxx Tue Oct 31 15:46:43 +0000 2017 X-GM-THRID: 1582223779778424148 X-Gmail-Labels: Inbox,Category Forums