From patchwork Wed Mar 13 22:37:29 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Li,Rongqing via dev" X-Patchwork-Id: 1056284 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=openvswitch.org (client-ip=140.211.169.12; helo=mail.linuxfoundation.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=openvswitch.org Received: from mail.linuxfoundation.org (mail.linuxfoundation.org [140.211.169.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 44KRd157cZz9s5c for ; Thu, 14 Mar 2019 09:40:36 +1100 (AEDT) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id 23FC7C51; Wed, 13 Mar 2019 22:38:27 +0000 (UTC) X-Original-To: ovs-dev@openvswitch.org Delivered-To: ovs-dev@mail.linuxfoundation.org Received: from smtp1.linuxfoundation.org (smtp1.linux-foundation.org [172.17.192.35]) by mail.linuxfoundation.org (Postfix) with ESMTPS id 33404BA0 for ; Wed, 13 Mar 2019 22:38:26 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from EX13-EDG-OU-002.vmware.com (ex13-edg-ou-002.vmware.com [208.91.0.190]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id A003CD3 for ; Wed, 13 Mar 2019 22:38:25 +0000 (UTC) Received: from sc9-mailhost2.vmware.com (10.113.161.72) by EX13-EDG-OU-002.vmware.com (10.113.208.156) with Microsoft SMTP Server id 15.0.1156.6; Wed, 13 Mar 2019 15:38:21 -0700 Received: from vsairam-w01.vmware.com (vsairam-w01.prom.eng.vmware.com [10.33.78.42]) by sc9-mailhost2.vmware.com (Postfix) with ESMTP id 43E57B16A2; Wed, 13 Mar 2019 18:38:24 -0400 (EDT) To: Date: Wed, 13 Mar 2019 15:37:29 -0700 Message-ID: <20190313223729.83632-1-vsairam@vmware.com> X-Mailer: git-send-email 2.9.0.windows.1 MIME-Version: 1.0 Received-SPF: None (EX13-EDG-OU-002.vmware.com: vsairam@vmware.com does not designate permitted sender hosts) X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on smtp1.linux-foundation.org Subject: [ovs-dev] [PATCH] datapath-windows: Add guards around IpHelper adapter binding calls X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Sairam Venugopal via dev From: "Li,Rongqing via dev" Reply-To: Sairam Venugopal Sender: ovs-dev-bounces@openvswitch.org Errors-To: ovs-dev-bounces@openvswitch.org Protect internal adapter up/down calls with a dispatch lock. It was observed that the InternalAdapter bind calls could happen out of order thereby causing encap packets to not be sent properly. Add assert around the IpHelper bind calls to ensure Up/Down gets called only for the appropriate vports. Signed-off-by: Sairam Venugopal --- datapath-windows/ovsext/Switch.h | 2 ++ datapath-windows/ovsext/Vport.c | 34 +++++++++++++++++++++++++++++++--- 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/datapath-windows/ovsext/Switch.h b/datapath-windows/ovsext/Switch.h index 18a9ec6..806ee78 100644 --- a/datapath-windows/ovsext/Switch.h +++ b/datapath-windows/ovsext/Switch.h @@ -131,6 +131,8 @@ typedef struct _OVS_SWITCH_CONTEXT * vport */ INT32 countInternalVports; /* the number of internal * vports */ + UINT32 ipHelperBoundVportNo; /* vportNo bound to + * IpHelper */ /* * 'portIdHashArray' ONLY contains ports that exist on the Hyper-V switch, diff --git a/datapath-windows/ovsext/Vport.c b/datapath-windows/ovsext/Vport.c index e8c4d7f..57e7510 100644 --- a/datapath-windows/ovsext/Vport.c +++ b/datapath-windows/ovsext/Vport.c @@ -100,6 +100,12 @@ static NTSTATUS GetNICAlias(PNDIS_SWITCH_NIC_PARAMETERS nicParam, static NTSTATUS OvsConvertIfCountedStrToAnsiStr(PIF_COUNTED_STRING wStr, CHAR *str, UINT16 maxStrLen); +_Requires_lock_held_(switchContext->dispatchLock) +static VOID OvsBindVportWithIpHelper(POVS_VPORT_ENTRY vport, + POVS_SWITCH_CONTEXT switchContext); +_Requires_lock_held_(switchContext->dispatchLock) +static VOID OvsUnBindVportWithIpHelper(POVS_VPORT_ENTRY vport, + POVS_SWITCH_CONTEXT switchContext); /* * -------------------------------------------------------------------------- @@ -453,7 +459,7 @@ HvConnectNic(POVS_SWITCH_CONTEXT switchContext, vport->nicState = NdisSwitchNicStateConnected; if (nicParam->NicType == NdisSwitchNicTypeInternal) { - OvsInternalAdapterUp(vport->portNo, &vport->netCfgInstanceId); + OvsBindVportWithIpHelper(vport, switchContext); } NdisReleaseRWLock(switchContext->dispatchLock, &lockState); @@ -633,7 +639,7 @@ HvDisconnectNic(POVS_SWITCH_CONTEXT switchContext, } if (isInternalPort) { - OvsInternalAdapterDown(vport->portNo, vport->netCfgInstanceId); + OvsUnBindVportWithIpHelper(vport, switchContext); OvsRemoveAndDeleteVport(NULL, switchContext, vport, TRUE, TRUE); OvsPostVportEvent(&event); } @@ -1308,7 +1314,7 @@ OvsRemoveAndDeleteVport(PVOID usrParamsContext, if (hvDelete && vport->isAbsentOnHv == FALSE) { switchContext->countInternalVports--; ASSERT(switchContext->countInternalVports >= 0); - OvsInternalAdapterDown(vport->portNo, vport->netCfgInstanceId); + OvsUnBindVportWithIpHelper(vport, switchContext); } hvSwitchPort = TRUE; break; @@ -2814,3 +2820,25 @@ OvsTunnelVportPendingInit(PVOID context, ASSERT(*replyLen != 0); } } + +_Use_decl_annotations_ +static VOID +OvsBindVportWithIpHelper(POVS_VPORT_ENTRY vport, + POVS_SWITCH_CONTEXT switchContext) +{ + OVS_LOG_TRACE("OvsBindVportWithIpHelper: %d", vport->portNo); + ASSERT(switchContext->ipHelperBoundVportNo == 0); + switchContext->ipHelperBoundVportNo = vport->portNo; + OvsInternalAdapterUp(vport->portNo, &vport->netCfgInstanceId); +} + +_Use_decl_annotations_ +static VOID +OvsUnBindVportWithIpHelper(POVS_VPORT_ENTRY vport, + POVS_SWITCH_CONTEXT switchContext) +{ + OVS_LOG_TRACE("OvsUnBindVportWithIpHelper: %d", vport->portNo); + ASSERT(switchContext->ipHelperBoundVportNo == vport->portNo); + switchContext->ipHelperBoundVportNo = 0; + OvsInternalAdapterDown(vport->portNo, vport->netCfgInstanceId); +}