Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp1551497imw; Tue, 5 Jul 2022 11:23:41 -0700 (PDT) X-Google-Smtp-Source: AGRyM1u7bqjxnDFnfEgqDRxuUTzQkBCBEc/nE72qcLmm98MWAstqqopZmffDQ9Zdj4KbjN3HZPPh X-Received: by 2002:a17:903:1208:b0:16b:81f6:e992 with SMTP id l8-20020a170903120800b0016b81f6e992mr43596742plh.55.1657045420864; Tue, 05 Jul 2022 11:23:40 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1657045420; cv=pass; d=google.com; s=arc-20160816; b=aRJbmt4Ho2TLeDc4B60hTTOwQLM90IlIpfUpZRc7S1qGgBvvl5NrcOBlhB0P9qJ5Ia 2JIboxsxd+JitsxJVgl3ELXQExFpCh0k/GotDA92YdlkoH0IoLY1YLPlSa4mH1+PRuat jr/k/okfeCUefUcLpwylDFMiNhr4UKLB0XDowDh7HOKqcqmUM/gGg08iG7GWPplH7nY8 B9JkdSWrTrhxo3AyyUtjE2ICBdo9dsvygKILIRkriWlXSwPVT46mro0p/KGnJgzm/V8/ YvtMvQuxfCorR2j7yTZZAc1/KTqrDulEvYxI+MgGkcMO4/Rmp2fS9MoRcAVVRhW6nPc3 B2bQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :msip_labels:content-language:accept-language:in-reply-to:references :message-id:date:thread-index:thread-topic:subject:to:from :dkim-signature; bh=WN5s6RYc7Ez/UXgk2feO2GEz8yfAlMNPepT/OZj//hU=; b=wEYbsz90pqFGyB58X/2sEZjPalqiz18QyGp83A5bAIswxBamjI5gGgxQqhYE6lQonM B/ZJgV6FlEwlbVufP+yM8v3y1eKAz3Svw1W/Mt/IgBk6PDYzh1iSaAkg9STD9i2fEssy Tt2ibEtZyx0eBsuFExVf2T8G8wc8EKi1QRQHF+X5biCz2BNtD/tCqcIpWJsFELAEFeZg AVI3nWcOrPab/kTeqwp/AdejvTcIIDxhgPp78Balg2bDEalbYIGH6twAHyLrGJUFcxU5 knwd+FHx2/MqOtDD4diKwxnWtz2JTVQOSk2dWmTsFZK56gF+wG3c1+RZqJnKmcfnsjVf kabg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector2 header.b=biG64LQ8; arc=pass (i=1 spf=pass spfdomain=microsoft.com dkim=pass dkdomain=microsoft.com dmarc=pass fromdomain=microsoft.com); 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=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n9-20020a170902e54900b0016bfe93ccb8si108043plf.222.2022.07.05.11.23.29; Tue, 05 Jul 2022 11:23:40 -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=@microsoft.com header.s=selector2 header.b=biG64LQ8; arc=pass (i=1 spf=pass spfdomain=microsoft.com dkim=pass dkdomain=microsoft.com dmarc=pass fromdomain=microsoft.com); 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=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232390AbiGERjS (ORCPT + 99 others); Tue, 5 Jul 2022 13:39:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60160 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229610AbiGERjR (ORCPT ); Tue, 5 Jul 2022 13:39:17 -0400 Received: from na01-obe.outbound.protection.outlook.com (mail-centralusazon11021017.outbound.protection.outlook.com [52.101.62.17]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 86E4017597; Tue, 5 Jul 2022 10:39:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=U1qgIikzvyYxyCBMty7jEKdK9TH1760FlPr5XigFuW+AO7qZY/1mzgIyZf3hC2Xh07TjpThhW2Wf6QxfwLfKyITO32O40SAnhgj6WMJM+ncWuCydd1R0YpqUpsL55RNeJ6qX8jMJCTW1yuGZWsq4o5aPo6EAMfHDWIQgptIYt6+5v3utR3mlotqsJGXx9iKez3ACwA4ZP1seahyssx/oXFiDvBX/1fDU/btlB9YfMSuvnJY5+a3fxA8Z4BMnBkGWujnKuCuFQevtLLY/0rVhxFk3YWWmcexB6U+LOviHq8WqA2lGVIdD5xoCv+B6K2ueaxJEY2+EVriVhNdxmT1u0g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=WN5s6RYc7Ez/UXgk2feO2GEz8yfAlMNPepT/OZj//hU=; b=jmSBxNBbt8ha0fLqJPR2br6mglOeoAIa/9fltHAsqhKfMe8l2CmYIdqPeGhaiTyicZDnsJoE8UI6dUB85LvuzC/vazZDX3wZ2rTdGscrYd657YvNsp7qz5VgtvWKLPY/9JpGaUXnzpXhX66USJf/csXEUpS+Npl3Y03k9fnoAkYw4/qQh/ZmUnRHiLYLePjIXGQ0OTigOOKEF8JjvnDe/PBQFd+HvZquIEDnpjve1bKlC8olvGSRBeWvE46WPBnX88vSGWCbnWgN9FBzxH/SO4uuZxxRQpo67SvkMOVLi9mYdmXAu3qh80Ssi50zQTQZ2+A9gygDUVpk9DayI7cniA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=microsoft.com; dmarc=pass action=none header.from=microsoft.com; dkim=pass header.d=microsoft.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=WN5s6RYc7Ez/UXgk2feO2GEz8yfAlMNPepT/OZj//hU=; b=biG64LQ8bTv/axB8kUbKG4vWFhGELEf542WAFKsNTvOPsZ0/eekaBLgR+BS40u1lFk7pXIUxjmr3+aT0Uby26ywmz53wnzqH4mgSxdrJ4eeIljox/MiSF/BzYQn8AE2Hjbmv2z0HzPtM+yFlmMBOOEdOWiLN6fq9XZHhvPhGDtc= Received: from PH0PR21MB3025.namprd21.prod.outlook.com (2603:10b6:510:d2::21) by PH0PR21MB2007.namprd21.prod.outlook.com (2603:10b6:510:48::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5438.3; Tue, 5 Jul 2022 17:39:13 +0000 Received: from PH0PR21MB3025.namprd21.prod.outlook.com ([fe80::7838:dcbf:513b:d992]) by PH0PR21MB3025.namprd21.prod.outlook.com ([fe80::7838:dcbf:513b:d992%5]) with mapi id 15.20.5438.000; Tue, 5 Jul 2022 17:39:12 +0000 From: "Michael Kelley (LINUX)" To: Saurabh Sengar , KY Srinivasan , Haiyang Zhang , Stephen Hemminger , "wei.liu@kernel.org" , Dexuan Cui , "jejb@linux.ibm.com" , "martin.petersen@oracle.com" , "linux-hyperv@vger.kernel.org" , "linux-scsi@vger.kernel.org" , "linux-kernel@vger.kernel.org" , Saurabh Singh Sengar Subject: RE: [PATCH] scsi: storvsc: Prevent running tasklet for long Thread-Topic: [PATCH] scsi: storvsc: Prevent running tasklet for long Thread-Index: AQHYkIRxnF98098OPUKVFTnw6GGSI61wBk5A Date: Tue, 5 Jul 2022 17:39:12 +0000 Message-ID: References: <1657035141-2132-1-git-send-email-ssengar@linux.microsoft.com> In-Reply-To: <1657035141-2132-1-git-send-email-ssengar@linux.microsoft.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: msip_labels: MSIP_Label_f42aa342-8706-4288-bd11-ebb85995028c_ActionId=0365133a-cc00-428a-a7b6-f435c1d844db;MSIP_Label_f42aa342-8706-4288-bd11-ebb85995028c_ContentBits=0;MSIP_Label_f42aa342-8706-4288-bd11-ebb85995028c_Enabled=true;MSIP_Label_f42aa342-8706-4288-bd11-ebb85995028c_Method=Standard;MSIP_Label_f42aa342-8706-4288-bd11-ebb85995028c_Name=Internal;MSIP_Label_f42aa342-8706-4288-bd11-ebb85995028c_SetDate=2022-07-05T17:21:32Z;MSIP_Label_f42aa342-8706-4288-bd11-ebb85995028c_SiteId=72f988bf-86f1-41af-91ab-2d7cd011db47; authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=microsoft.com; x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: bcb22dcd-8d38-4092-efba-08da5ead45f9 x-ms-traffictypediagnostic: PH0PR21MB2007:EE_ x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: d89VvyyMTHHMr8FJOQy4SPUhwXeoceHGxUovpqA43xvmgRxEXyqNGhtwdl7BDlQC+1+FCdRwngLpK1kPBYvwlcII3gUHPkL3fNxoRT89OBWk3C8sCZZsoFQZXEYxW+NhpHcfFZa+efrVrReStRCXh5yMXD1TwBBcE73zl1a8sL9k1F23qIbPX7kLM0MvJVq2+OfQuN2UGcBMG4ZurHGmifzpFhCc2DJ/8/QXWkxdHlN2pvOLnkdO3I5cPEzHce/AW/23XQzRqe5zik62dBtb7c/8IG2uYEnd/hsvJIoBNZMRKLnzmlRgOcoyMIa85w9C1KG2rbEuDC9NMAdemZfpTe96CLVhYrXb0GicXeLIk3CWkJS5Xur5nVuCDN7tcGk+xopUASah/maHTBotWvR4ccHDx0bY4+J1dGXltKgR0wmuWY+Qi8FTSm8P8M3sMjuM3hqDe5Ls1sc8mb6Lu3zEjXNlU68yuq8mbIPZ/85Z3g5Z1H6W1l+wcS5HaZPgZ0ulwIEoKcPRmTHOlplcOcWR7/ZcbO8bcpb2/qZ7f5ipTCCqIi4417vZKQxceXSPApSK/hx8hfn7DAcSbZet/Nfl7eMsVuOIqqPqe3Eb9EOwYheEmFSsG3+4/If4llNHmsa1HmB5UlVzuKr9oleOPwshe38O81T8G+Tw9rKNP3HkFRd64aMCE7DzWou7852EIzIjMPv7eIzDL3e5lspCtdQGgmL7OqTfLgEkqHUDj7YjrfLFKBhcWgv1ZpS5lHWQTzNYxpiVvi4kLbHeKbikRwY7hHgQkajcHfIyTfO8Ix4ZOsrug7tu7sHhumGQWTqt4V5/dvPVEVHUqqsTV/AXb5aRanflxCRDkZG7fACviL36JOK6VjUa5k4ETU2/HSLLaxB4 x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PH0PR21MB3025.namprd21.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230016)(4636009)(346002)(39860400002)(366004)(376002)(396003)(136003)(451199009)(33656002)(86362001)(2906002)(8936002)(122000001)(55016003)(5660300002)(9686003)(52536014)(8990500004)(26005)(38100700002)(66556008)(66476007)(66446008)(64756008)(8676002)(7696005)(76116006)(66946007)(38070700005)(186003)(110136005)(6636002)(316002)(10290500003)(921005)(6506007)(478600001)(71200400001)(83380400001)(82960400001)(41300700001)(82950400001);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?uV6nQpfsgyNMM/5VyZD3bXfVLQ8tV0dT1qj30Gk8/YZDFCSbMieYTQ0moJM8?= =?us-ascii?Q?JC4bbZD4kh6M843jNeFaoyzEgpqOqG2sAAGCS9HqKvY20PtMk4HEV8iJ5q9h?= =?us-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sI0H45ll8KL?= =?us-ascii?Q?cBFpCDYV2bt3mX6dtoYmjhSKxm8V2mBdJCkt0bdewt6Ramo6wYFHGzIja1A/?= =?us-ascii?Q?Dxpy9ZGiCnELaCu9tVzkLhAkngIJvCFBZjZEZUK8X8bl5bx6yTUCW5CgW4iV?= =?us-ascii?Q?B00lx9ic/2SKe19NBaSsze+Z24B1oEtDX8yzTPGSX8JV74r5+cZ9Ho/PMrV7?= =?us-ascii?Q?aGGTCRHUuRn5ngECt8Ujopib+y/QnPBFXvKKIn9gItoWiOhw23XgMYPg9vPm?= =?us-ascii?Q?uDRz+aX/W4mAbdOxU0kC6yYCLliPtl3rMj8/zZ+G2a8cEJe81vMxo+M+Av8Y?= =?us-ascii?Q?mNEgjWiPnbsMgQTwtEeHKgpNUs+0FPWbv4YEvcPZCZNnK3iE+FcY9949jds3?= =?us-ascii?Q?4NFyYVadcpXUsOfCFLhAmwij/RZRQMig8M/3WHev8LGtsQOMPfhLvZ8F5f8Y?= =?us-ascii?Q?wGqqKQri46UWZsC9k6rl+dVQYGa4whURjMVEkaAH30++qB0n0HQK1dYkw4Qa?= =?us-ascii?Q?rG+NmELy4TpaD4LHpmSgfAFYFBSt191oqCU9GTls57tY5n2w7h7ZPVdmxYRO?= =?us-ascii?Q?KDOQN0cRQ2bGqLrWFphZFkUmH64HydGljFaj8Y26Hg3RCaBVMDV9Jsrq1Xa0?= =?us-ascii?Q?fw=3D=3D?= Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: PH0PR21MB3025.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: bcb22dcd-8d38-4092-efba-08da5ead45f9 X-MS-Exchange-CrossTenant-originalarrivaltime: 05 Jul 2022 17:39:12.2082 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: L1cvqcl7IGl01Ta2gcO4kuw1kcCdNJGtr+SOHSt21Q7kW6XQkf+VUWZ0fOk+1iltolYLmYdWEf1AgxCl1+/VyxkMBJjBXHKdVfPdn9qgxPs= X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR21MB2007 X-Spam-Status: No, score=-1.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FORGED_SPF_HELO, RCVD_IN_DNSWL_NONE,SPF_HELO_PASS,SPF_NONE,T_SCC_BODY_TEXT_LINE 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 From: Saurabh Sengar Sent: Tuesday, July 5, 2= 022 8:32 AM >=20 > 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.=20 Actually, the "forever" part isn't possible. The way foreach_vmbus_pkt() works, it only runs until the ring buffer is empty, and it does not update the ring buffer read index until the empty condition is reached. So the Hyper-V host is prevented from continuously feeding new packets into the ring buffer while storvsc is reading them. But ring buffer is pretty big, = so storvsc could still end up processing a lot of completion packets and take an undesirable amount of time in the loop. Hence the scenario is valid. > Add a condition to limit execution of > this tasklet for finite amount of time to avoid such hazardous scenarios. >=20 > Signed-off-by: Saurabh Sengar > --- > drivers/scsi/storvsc_drv.c | 7 +++++++ > 1 file changed, 7 insertions(+) >=20 > 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) >=20 > +/* channel callback timeout in ms */ > +#define CALLBACK_TIMEOUT 5 > + > /* Packet structure describing virtual storage requests. */ > enum vstor_packet_operation { > VSTOR_OPERATION_COMPLETE_IO =3D 1, > @@ -1204,6 +1207,7 @@ static void storvsc_on_channel_callback(void *conte= xt) > struct hv_device *device; > struct storvsc_device *stor_device; > struct Scsi_Host *shost; > + unsigned long expire =3D jiffies + msecs_to_jiffies(CALLBACK_TIMEOUT); >=20 > if (channel->primary_channel !=3D NULL) > device =3D channel->primary_channel->device_obj; > @@ -1224,6 +1228,9 @@ static void storvsc_on_channel_callback(void *conte= xt) > u32 minlen =3D rqst_id ? sizeof(struct vstor_packet) : > sizeof(enum vstor_packet_operation); >=20 > + if (time_after(jiffies, expire)) > + break; > + Per my comment on the commit message, breaking out of the foreach_vmbus_pkt() loop leaves the ring indices unchanged. I *think* we want to close out the iteration via hv_pkt_iter_close() in the case where w= e exit the loop early, so that Hyper-V can re-use the ring buffer space from completions we've already processed. Also when we re-enter storvsc_on_channel_callback() and again do hv_pkt_iter_first(), that should be only after hv_pkt_iter_close() has been called; i.e., the hv_pkt_iter_* functions should be matched up correctly. The current implementation of these functions doesn't go awry if they aren't matched up correctly, but we should nonetheless do them correctly in case the implementation changes in the future. Similar code in netvsc_poll() has the same behavior of not closing out the hv_pkt_iter when the poll budget is exhausted, and we've had a recent internal discussion about changing that. Michael > if (pktlen < minlen) { > dev_err(&device->device, > "Invalid pkt: id=3D%llu, len=3D%u, minlen=3D%u\n", > -- > 1.8.3.1