From patchwork Mon Dec 18 02:02:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilya Maximets X-Patchwork-Id: 1877174 X-Patchwork-Delegate: i.maximets@samsung.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=2605:bc80:3010::138; helo=smtp1.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=patchwork.ozlabs.org) Received: from smtp1.osuosl.org (smtp1.osuosl.org [IPv6:2605:bc80:3010::138]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4StjlY3S8Mz23yc for ; Mon, 18 Dec 2023 13:03:05 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id 7614B81EC4; Mon, 18 Dec 2023 02:03:03 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp1.osuosl.org 7614B81EC4 X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp1.osuosl.org ([127.0.0.1]) by localhost (smtp1.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id vxwPiZxdJ-cq; Mon, 18 Dec 2023 02:03:02 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [IPv6:2605:bc80:3010:104::8cd3:938]) by smtp1.osuosl.org (Postfix) with ESMTPS id 9827181EB8; Mon, 18 Dec 2023 02:03:01 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp1.osuosl.org 9827181EB8 Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 632CAC0077; Mon, 18 Dec 2023 02:03:01 +0000 (UTC) X-Original-To: ovs-dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp1.osuosl.org (smtp1.osuosl.org [140.211.166.138]) by lists.linuxfoundation.org (Postfix) with ESMTP id 806CEC0077 for ; Mon, 18 Dec 2023 02:02:59 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id 4595381EAE for ; Mon, 18 Dec 2023 02:02:59 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp1.osuosl.org 4595381EAE X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp1.osuosl.org ([127.0.0.1]) by localhost (smtp1.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id xB8HSWATo8WC for ; Mon, 18 Dec 2023 02:02:58 +0000 (UTC) Received: from relay6-d.mail.gandi.net (relay6-d.mail.gandi.net [IPv6:2001:4b98:dc4:8::226]) by smtp1.osuosl.org (Postfix) with ESMTPS id 2C26181EAB for ; Mon, 18 Dec 2023 02:02:57 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp1.osuosl.org 2C26181EAB Received: by mail.gandi.net (Postfix) with ESMTPSA id 4F261C0002; Mon, 18 Dec 2023 02:02:55 +0000 (UTC) From: Ilya Maximets To: ovs-dev@openvswitch.org Date: Mon, 18 Dec 2023 03:02:40 +0100 Message-ID: <20231218020249.3447973-2-i.maximets@ovn.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231218020249.3447973-1-i.maximets@ovn.org> References: <20231218020249.3447973-1-i.maximets@ovn.org> MIME-Version: 1.0 X-GND-Sasl: i.maximets@ovn.org Cc: Ilya Maximets , Dumitru Ceara Subject: [ovs-dev] [PATCH 1/5] ovsdb: Fix incorrect sharing of UUID and _version columns. X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" Datum of UUID and _version columns is accessed directly via ovsdb_row_get_uuid_rw() and ovsdb_row_get_version_rw() functions instead of ovsdb_data_* functions. Meaning, the data will be directly modified even if it is shared between rows. Fix that by unsharing the data whenever RW pointer is taken. The issue was mostly hidden because weak reference assessment code always called ovsdb_datum_subtract() even if not needed. This way all the new transaction rows were always implicitly unshared. Also making ovsdb_datum_subtract() call conditional, so the issue can be hit by existing unit tests. Fixes: 485ac63d10f8 ("ovsdb: Add lazy-copy support for ovsdb_datum objects.") Signed-off-by: Ilya Maximets Acked-by: Mike Pattrick --- ovsdb/row.h | 2 ++ ovsdb/transaction.c | 6 ++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/ovsdb/row.h b/ovsdb/row.h index 59f498a20..6f5e58acb 100644 --- a/ovsdb/row.h +++ b/ovsdb/row.h @@ -130,6 +130,7 @@ ovsdb_row_get_uuid(const struct ovsdb_row *row) static inline struct uuid * ovsdb_row_get_uuid_rw(struct ovsdb_row *row) { + ovsdb_datum_unshare(&row->fields[OVSDB_COL_UUID], &ovsdb_type_uuid); return &row->fields[OVSDB_COL_UUID].keys[0].uuid; } @@ -142,6 +143,7 @@ ovsdb_row_get_version(const struct ovsdb_row *row) static inline struct uuid * ovsdb_row_get_version_rw(struct ovsdb_row *row) { + ovsdb_datum_unshare(&row->fields[OVSDB_COL_VERSION], &ovsdb_type_uuid); return &row->fields[OVSDB_COL_VERSION].keys[0].uuid; } diff --git a/ovsdb/transaction.c b/ovsdb/transaction.c index 4fdc5bcea..f43533a8c 100644 --- a/ovsdb/transaction.c +++ b/ovsdb/transaction.c @@ -733,8 +733,10 @@ assess_weak_refs(struct ovsdb_txn *txn, struct ovsdb_txn_row *txn_row) ovsdb_datum_sort_unique(&deleted_refs, &column->type); /* Removing elements that references deleted rows. */ - ovsdb_datum_subtract(datum, &column->type, - &deleted_refs, &column->type); + if (deleted_refs.n) { + ovsdb_datum_subtract(datum, &column->type, + &deleted_refs, &column->type); + } ovsdb_datum_destroy(&deleted_refs, &column->type); /* Generating the difference between old and new data. */