From patchwork Tue Apr 23 11:04:25 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: fuzhantao X-Patchwork-Id: 1089322 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=huawei.com 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 44pLFP1hlpz9sNr for ; Tue, 23 Apr 2019 21:04:55 +1000 (AEST) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id 3F878F54; Tue, 23 Apr 2019 11:04:51 +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 844F9F4C for ; Tue, 23 Apr 2019 11:04:49 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from huawei.com (szxga06-in.huawei.com [45.249.212.32]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id 3E2A2F4 for ; Tue, 23 Apr 2019 11:04:47 +0000 (UTC) Received: from DGGEMS410-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 1D71B3A80ADDB7B04138; Tue, 23 Apr 2019 19:04:42 +0800 (CST) Received: from localhost (10.184.15.242) by DGGEMS410-HUB.china.huawei.com (10.3.19.210) with Microsoft SMTP Server id 14.3.439.0; Tue, 23 Apr 2019 19:04:32 +0800 From: fuzhantao To: , Date: Tue, 23 Apr 2019 19:04:25 +0800 Message-ID: <1556017465-18600-1-git-send-email-fuzhantao@huawei.com> X-Mailer: git-send-email 1.9.5.msysgit.1 MIME-Version: 1.0 X-Originating-IP: [10.184.15.242] X-CFilter-Loop: Reflected 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 Cc: i.maximets@samsung.com, fuzhantao@huawei.com Subject: [ovs-dev] [PATCH v3] Double postponing to free subtables. 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: , Sender: ovs-dev-bounces@openvswitch.org Errors-To: ovs-dev-bounces@openvswitch.org From: Zhantao Fu Subtable destruction should be double postponed because readers could still obtain old values while iterating over pvector implementation before its new version published. --- change since v2: - use git send-email to re-send patch change since v1: - delete the unused parameter in code, modify the subject and commit-message. Signed-off-by: Zhantao Fu --- lib/classifier.c | 31 +++++++++++++++++++------------ lib/dpif-netdev.c | 10 ++++++++-- 2 files changed, 27 insertions(+), 14 deletions(-) diff --git a/lib/classifier.c b/lib/classifier.c index edb40c8..0fad953 100644 --- a/lib/classifier.c +++ b/lib/classifier.c @@ -1468,6 +1468,24 @@ miniflow_get_map_in_range(const struct miniflow *miniflow, uint8_t start, return map; } +static void +subtable_destroy_cb(struct cls_subtable *subtable) +{ + int i; + + ovs_assert(ovsrcu_get_protected(struct trie_node *, &subtable->ports_trie) + == NULL); + ovs_assert(cmap_is_empty(&subtable->rules)); + ovs_assert(rculist_is_empty(&subtable->rules_list)); + + for (i = 0; i < subtable->n_indices; i++) { + ccmap_destroy(&subtable->indices[i]); + } + cmap_destroy(&subtable->rules); + + ovsrcu_postpone(free, subtable); +} + /* The new subtable will be visible to the readers only after this. */ static struct cls_subtable * insert_subtable(struct classifier *cls, const struct minimask *mask) @@ -1534,22 +1552,11 @@ insert_subtable(struct classifier *cls, const struct minimask *mask) static void destroy_subtable(struct classifier *cls, struct cls_subtable *subtable) { - int i; - pvector_remove(&cls->subtables, subtable); cmap_remove(&cls->subtables_map, &subtable->cmap_node, minimask_hash(&subtable->mask, 0)); - ovs_assert(ovsrcu_get_protected(struct trie_node *, &subtable->ports_trie) - == NULL); - ovs_assert(cmap_is_empty(&subtable->rules)); - ovs_assert(rculist_is_empty(&subtable->rules_list)); - - for (i = 0; i < subtable->n_indices; i++) { - ccmap_destroy(&subtable->indices[i]); - } - cmap_destroy(&subtable->rules); - ovsrcu_postpone(free, subtable); + ovsrcu_postpone(subtable_destroy_cb, subtable); } static unsigned int be_get_bit_at(const ovs_be32 value[], unsigned int ofs); diff --git a/lib/dpif-netdev.c b/lib/dpif-netdev.c index 4d6d0c3..8657a61 100644 --- a/lib/dpif-netdev.c +++ b/lib/dpif-netdev.c @@ -7592,6 +7592,13 @@ struct dpcls_subtable { /* 'mask' must be the last field, additional space is allocated here. */ }; +static void +dpcls_subtable_destroy_cb(struct dpcls_subtable *subtable) +{ + cmap_destroy(&subtable->rules); + ovsrcu_postpone(free, subtable); +} + /* Initializes 'cls' as a classifier that initially contains no classification * rules. */ static void @@ -7608,8 +7615,7 @@ dpcls_destroy_subtable(struct dpcls *cls, struct dpcls_subtable *subtable) pvector_remove(&cls->subtables, subtable); cmap_remove(&cls->subtables_map, &subtable->cmap_node, subtable->mask.hash); - cmap_destroy(&subtable->rules); - ovsrcu_postpone(free, subtable); + ovsrcu_postpone(dpcls_subtable_destroy_cb, subtable); } /* Destroys 'cls'. Rules within 'cls', if any, are not freed; this is the