From patchwork Thu Feb 23 21:31:41 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Zhou X-Patchwork-Id: 731764 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.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 3vTnWC17vwz9s7r for ; Fri, 24 Feb 2017 08:32:07 +1100 (AEDT) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id 639CDC26; Thu, 23 Feb 2017 21:31:52 +0000 (UTC) X-Original-To: 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 EA55CC17 for ; Thu, 23 Feb 2017 21:31:50 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.7.6 Received: from mail-pg0-f67.google.com (mail-pg0-f67.google.com [74.125.83.67]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id 944AB168 for ; Thu, 23 Feb 2017 21:31:50 +0000 (UTC) Received: by mail-pg0-f67.google.com with SMTP id s67so393155pgb.1 for ; Thu, 23 Feb 2017 13:31:50 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:content-transfer-encoding; bh=+Ap9X1ND11cOrOywa88MoWYZr0ntzqaJhwPpQPzYZXE=; b=MuriMTFlDfExEXEpbaXtkdzGOQ0K7gyp96d+IJIhS46pjVt7KpHLG9e9mQaGGwtWVJ rpjz5xFtMx2YKUcvMdWA6zZcBR6L+n//K8p0/JgqZlaSAgv639XDgGVXH+Homui6vO9T 6l7RtDRWYDTeuvKli2AeW4Inn5jRCa2ZonQvZDriGO6DjElACgmAe903UU0pZN/PvRje rqRb4QagPdDNlODUL2+GgpdbEPVE83RhpnYQbDVjnInu6xoMfRpUwLOrGDvAPx80f+f6 VkHGhv6q4TsE77ZLBrfKXZdU7ycKAKgU5o790NnlaO50to1EKCp8OlRyo2d3P34WDFwf x6tw== X-Gm-Message-State: AMke39lSbUCAIclfIZyQuF8N5ugNF0UuSTs6yNO9odJREGcMvQP8Fs22UiPCmOMVZ697XQ== X-Received: by 10.84.197.3 with SMTP id m3mr57196542pld.89.1487885510201; Thu, 23 Feb 2017 13:31:50 -0800 (PST) Received: from ubuntu.localdomain ([208.91.1.34]) by smtp.gmail.com with ESMTPSA id l25sm11407706pfg.134.2017.02.23.13.31.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 23 Feb 2017 13:31:49 -0800 (PST) From: Andy Zhou To: dev@openvswitch.org Date: Thu, 23 Feb 2017 13:31:41 -0800 Message-Id: <1487885501-105263-2-git-send-email-azhou@ovn.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1487885501-105263-1-git-send-email-azhou@ovn.org> References: <1487885501-105263-1-git-send-email-azhou@ovn.org> X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on smtp1.linux-foundation.org Cc: Huanle Han Subject: [ovs-dev] [PATCH 2/2] ofproto/bond: Fix bond post recirc rule leak. 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: , MIME-Version: 1.0 Sender: ovs-dev-bounces@openvswitch.org Errors-To: ovs-dev-bounces@openvswitch.org When bond is removed or when its configuration changes, the post recirculation rules that are installed by current bond configuration, if any, should be also be removed. Reported-by: Huanle Han Reported-at: https://mail.openvswitch.org/pipermail/ovs-dev/2017-February/328969.html CC: Huanle Han Signed-off-by: Andy Zhou Acked-by: Jarno Rajahalme --- ofproto/bond.c | 36 ++++++++++++++++++++++++++---------- 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/ofproto/bond.c b/ofproto/bond.c index 6e10c5143c0e..5bb124bda5ad 100644 --- a/ofproto/bond.c +++ b/ofproto/bond.c @@ -190,6 +190,7 @@ static struct bond_slave *choose_output_slave(const struct bond *, struct flow_wildcards *, uint16_t vlan) OVS_REQ_RDLOCK(rwlock); +static void update_recirc_rules__(struct bond *bond); /* Attempts to parse 's' as the name of a bond balancing mode. If successful, * stores the mode in '*balance' and returns true. Otherwise returns false @@ -264,7 +265,6 @@ bond_ref(const struct bond *bond_) void bond_unref(struct bond *bond) { - struct bond_pr_rule_op *pr_op; struct bond_slave *slave; if (!bond || ovs_refcount_unref_relaxed(&bond->ref_cnt) != 1) { @@ -283,18 +283,18 @@ bond_unref(struct bond *bond) hmap_destroy(&bond->slaves); ovs_mutex_destroy(&bond->mutex); - free(bond->hash); - free(bond->name); - - HMAP_FOR_EACH_POP (pr_op, hmap_node, &bond->pr_rule_ops) { - free(pr_op); - } - hmap_destroy(&bond->pr_rule_ops); + /* Free bond resources. Remove existing post recirc rules. */ if (bond->recirc_id) { recirc_free_id(bond->recirc_id); + bond->recirc_id = 0; } + free(bond->hash); + bond->hash = NULL; + update_recirc_rules__(bond); + hmap_destroy(&bond->pr_rule_ops); + free(bond->name); free(bond); } @@ -322,9 +322,17 @@ add_pr_rule(struct bond *bond, const struct match *match, hmap_insert(&bond->pr_rule_ops, &pr_op->hmap_node, hash); } +/* This function should almost never be called directly. + * 'update_recirc_rules()' should be called instead. Since + * this function modifies 'bond->pr_rule_ops', it is only + * safe when 'rwlock' is held. + * + * However, when the 'bond' is the only reference in the system, + * calling this function avoid acquiring lock only to satisfy + * lock annotation. Currently, only 'bond_unref()' calls + * this function directly. */ static void -update_recirc_rules(struct bond *bond) - OVS_REQ_WRLOCK(rwlock) +update_recirc_rules__(struct bond *bond) { struct match match; struct bond_pr_rule_op *pr_op, *next_op; @@ -394,6 +402,12 @@ update_recirc_rules(struct bond *bond) ofpbuf_uninit(&ofpacts); } +static void +update_recirc_rules(struct bond *bond) + OVS_REQ_RDLOCK(rwlock) +{ + update_recirc_rules__(bond); +} /* Updates 'bond''s overall configuration to 's'. * @@ -1640,6 +1654,8 @@ bond_entry_reset(struct bond *bond) } else { free(bond->hash); bond->hash = NULL; + /* Remove existing post recirc rules. */ + update_recirc_rules(bond); } }