Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 87EAEC433FE for ; Thu, 6 Oct 2022 04:13:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229853AbiJFENu (ORCPT ); Thu, 6 Oct 2022 00:13:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59554 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229812AbiJFENt (ORCPT ); Thu, 6 Oct 2022 00:13:49 -0400 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 2684A5D0C8; Wed, 5 Oct 2022 21:13:36 -0700 (PDT) Received: from [192.168.1.9] (unknown [110.225.191.76]) by linux.microsoft.com (Postfix) with ESMTPSA id 6AF3320D5F2F; Wed, 5 Oct 2022 21:13:33 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 6AF3320D5F2F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1665029615; bh=Jk9C07usSWl1hRm56nMlcSu3Q9WBPTYD2ai756CsSxw=; h=Subject:To:Cc:References:From:Date:In-Reply-To:From; b=UHRrY9K1uylzO8Fi7JWePKUrHSL1dRD7anzMPMXIeXHom/622CxHh+M5cUbWN8jIt 4oAfg7Jb/1ipcbQAdWSaug0lo3fvKTS5lfqRzFJJN2M6Sf0+kitfW4xKboQTJrwtFD qiGkHqDA7hf7LwoDmAoPwto5fIwPL1uo52nu44+c= Subject: Re: [PATCH net] hv_netvsc: Fix race between VF offering and VF association message from host To: Haiyang Zhang , Jakub Kicinski Cc: KY Srinivasan , Stephen Hemminger , "wei.liu@kernel.org" , Dexuan Cui , "linux-hyperv@vger.kernel.org" , "netdev@vger.kernel.org" References: <1664372913-26140-1-git-send-email-gauravkohli@linux.microsoft.com> <20220929192620.2fa1542f@kernel.org> From: Gaurav Kohli Message-ID: Date: Thu, 6 Oct 2022 09:43:30 +0530 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:68.0) Gecko/20100101 Thunderbird/68.12.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-US Precedence: bulk List-ID: X-Mailing-List: linux-hyperv@vger.kernel.org On 9/30/2022 6:33 PM, Haiyang Zhang wrote: > >> -----Original Message----- >> From: Jakub Kicinski >> Sent: Thursday, September 29, 2022 10:26 PM >> To: Gaurav Kohli >> Cc: KY Srinivasan ; Haiyang Zhang >> ; Stephen Hemminger >> ; wei.liu@kernel.org; Dexuan Cui >> ; linux-hyperv@vger.kernel.org; >> netdev@vger.kernel.org >> Subject: Re: [PATCH net] hv_netvsc: Fix race between VF offering and VF >> association message from host >> >> On Wed, 28 Sep 2022 06:48:33 -0700 Gaurav Kohli wrote: >>> During vm boot, there might be possibility that vf registration >>> call comes before the vf association from host to vm. >>> >>> And this might break netvsc vf path, To prevent the same block >>> vf registration until vf bind message comes from host. >>> >>> Cc: stable@vger.kernel.org >>> Fixes: 00d7ddba11436 ("hv_netvsc: pair VF based on serial number") >>> Signed-off-by: Gaurav Kohli >> Is it possible to add a timeout or such? Waiting for an external >> event while holding rtnl lock seems a little scary. > We used to have time-out in many places of this driver. But there is > no protocol guarantees of the host response time, so the time out value > cannot be set. These time-outs were removed several years ago. > > >> The other question is - what protects the completion and ->vf_alloc >> from races? Is there some locking? ->vf_alloc only goes from 0 to 1 >> and never back? Thanks for the comment, i understand your concern for vf_alloc and reinit completion part, I think we can move reinit completion to unregistration part of vf code. Let me send v2 patch. > When Vf is removed, the vf_assoc msg will set it to 0 here: > net_device_ctx->vf_alloc = nvmsg->msg.v4_msg.vf_assoc.allocated; > net_device_ctx->vf_serial = nvmsg->msg.v4_msg.vf_assoc.serial; > > Also, I think this condition can be changed from: > + if (vf_is_up && !net_device_ctx->vf_alloc) { Thanks for the comment. This is needed to maintain state machine, as netvsc change event can comes multiple time. That's why i have put extra check to avoid any deadlock. > to: > + if (vf_is_up) { > So when VF comes up, it always wait for the completion without depending > on the vf_alloc. > > Thanks, > - Haiyang