Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp1398455imw; Tue, 5 Jul 2022 08:46:49 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vvmGnty/R6n/Euqw0xsAyrFHx1NLNdJLeQzXsz8Y5LVzKJC0Z3vAz+WwTzD5LlyDAQtjcf X-Received: by 2002:a17:906:1018:b0:718:dd3f:f28c with SMTP id 24-20020a170906101800b00718dd3ff28cmr35556584ejm.55.1657036009704; Tue, 05 Jul 2022 08:46:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657036009; cv=none; d=google.com; s=arc-20160816; b=0X12sXzn4ICcK8MrSd5Vt/W9BJIkeSgCMSiElXiuVF8t5Qc8lg7ds1P8vNG/Ai/ctm udvXOoT3uJCzjUEo6ljgvjnz0MsU1ejmo7SQFV7GaddEEmHwlVLX/laANspfAQAjZo3N vJ9DrYqwufRe78C6cgl/GZ0kC7IRD2Kz+5U4O/0pmD/gKve4W2PD5w3zcAmuKPn6yPaK 3tTtoJF+nH2gLYEZNWZlWB8cWvro5jyWYDJfYOiyG8m27jy1jBl6h1ocCjUgQZlJe1GX VzPdPNAPiqJuVLaW/XqwYpgvEN4I3bgVwTIkfNJTu8ucGYBmoLxN+c5a+M5hYdewLwX6 Yfiw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:subject:to:from:dkim-signature :dkim-filter; bh=kRnoCHsq+1Sa5DgsBfsbWeS+ACKGf2Fi6AFtFXIBaLs=; b=tXOhfSUgvRC7awQF6tx+RALQAQH/Fz81ZVoKxUN1ttgikSSJ1ZslskhXUroU5sG8bq 4Q61/MO93OADtd2sOvw03miYQLTyoNqqN0W8BuR4tIrPP4f6nxKhMABc6RPXJzzUu+Sc fw+jE408xStU4Ry6su00NkNew/W2ikorkfwrr+BAZDjEOlJ7R1Q1fqwCoDwjL8opMoW+ Yud4lszsvKpAZc2od45fhG3N+z+AqfdCYxN4xLBLkr1poto2TcXgyZ6nYtMqNm1tf2mn eSBPWO/wRog4Golr3E1vulxKX4vMbkT2kexiahNtnl4RQnS69tVPF32D+MutNHaDTLl+ YAaA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=pcGtDY6o; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.microsoft.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id nd17-20020a170907629100b0072a7935544dsi13938749ejc.325.2022.07.05.08.46.24; Tue, 05 Jul 2022 08:46:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=pcGtDY6o; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230100AbiGEPcc (ORCPT + 99 others); Tue, 5 Jul 2022 11:32:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58954 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231913AbiGEPc3 (ORCPT ); Tue, 5 Jul 2022 11:32:29 -0400 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id A9D471A395; Tue, 5 Jul 2022 08:32:28 -0700 (PDT) Received: from linuxonhyperv3.guj3yctzbm1etfxqx2vob5hsef.xx.internal.cloudapp.net (linux.microsoft.com [13.77.154.182]) by linux.microsoft.com (Postfix) with ESMTPSA id 5104920DDCA4; Tue, 5 Jul 2022 08:32:28 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 5104920DDCA4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1657035148; bh=kRnoCHsq+1Sa5DgsBfsbWeS+ACKGf2Fi6AFtFXIBaLs=; h=From:To:Subject:Date:From; b=pcGtDY6o/ZdZZ4/bmKzzdbHbBafbP4CgJR90LqZKqx4RuMS2A1BcxwKiK2nK41nO9 4IuBGt62IZmb8PpN6GSAdfdSmbRB5ABIqHX6mHjfMceWDJpPvEnlXpfIsMLXFxDuMZ 5kDXz9G1EsmuIVEeAzfhaLt4FV/Fe84GxJfxmp9I= From: Saurabh Sengar To: kys@microsoft.com, haiyangz@microsoft.com, sthemmin@microsoft.com, wei.liu@kernel.org, decui@microsoft.com, jejb@linux.ibm.com, martin.petersen@oracle.com, linux-hyperv@vger.kernel.org, linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org, ssengar@microsoft.com, mikelley@microsoft.com Subject: [PATCH] scsi: storvsc: Prevent running tasklet for long Date: Tue, 5 Jul 2022 08:32:21 -0700 Message-Id: <1657035141-2132-1-git-send-email-ssengar@linux.microsoft.com> X-Mailer: git-send-email 1.8.3.1 X-Spam-Status: No, score=-19.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_MED, SPF_HELO_PASS,SPF_PASS,T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL, USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org There can be scenarios where packets in ring buffer are continuously getting queued from upper layer and dequeued from storvsc interrupt handler, such scenarios can hold the foreach_vmbus_pkt loop (which is executing as a tasklet) for a long duration. Theoretically its possible that this loop executes forever. Add a condition to limit execution of this tasklet for finite amount of time to avoid such hazardous scenarios. Signed-off-by: Saurabh Sengar --- drivers/scsi/storvsc_drv.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/drivers/scsi/storvsc_drv.c b/drivers/scsi/storvsc_drv.c index fe000da..0c428cb 100644 --- a/drivers/scsi/storvsc_drv.c +++ b/drivers/scsi/storvsc_drv.c @@ -60,6 +60,9 @@ #define VMSTOR_PROTO_VERSION_WIN8_1 VMSTOR_PROTO_VERSION(6, 0) #define VMSTOR_PROTO_VERSION_WIN10 VMSTOR_PROTO_VERSION(6, 2) +/* channel callback timeout in ms */ +#define CALLBACK_TIMEOUT 5 + /* Packet structure describing virtual storage requests. */ enum vstor_packet_operation { VSTOR_OPERATION_COMPLETE_IO = 1, @@ -1204,6 +1207,7 @@ static void storvsc_on_channel_callback(void *context) struct hv_device *device; struct storvsc_device *stor_device; struct Scsi_Host *shost; + unsigned long expire = jiffies + msecs_to_jiffies(CALLBACK_TIMEOUT); if (channel->primary_channel != NULL) device = channel->primary_channel->device_obj; @@ -1224,6 +1228,9 @@ static void storvsc_on_channel_callback(void *context) u32 minlen = rqst_id ? sizeof(struct vstor_packet) : sizeof(enum vstor_packet_operation); + if (time_after(jiffies, expire)) + break; + if (pktlen < minlen) { dev_err(&device->device, "Invalid pkt: id=%llu, len=%u, minlen=%u\n", -- 1.8.3.1