From patchwork Fri Aug 4 19:16:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Tokarev X-Patchwork-Id: 710232 Delivered-To: patch@linaro.org Received: by 2002:a05:6359:d30:b0:129:c516:61db with SMTP id gp48csp162294rwb; Fri, 4 Aug 2023 12:18:18 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH5KL30XZT+IFdCTHh4cCJ7swAX7fKxAG4w5AYxtlemV3HqGV62m5LkLUKrp8poZI1995Cp X-Received: by 2002:a1f:5c44:0:b0:487:19c7:4ed7 with SMTP id q65-20020a1f5c44000000b0048719c74ed7mr1968270vkb.16.1691176698436; Fri, 04 Aug 2023 12:18:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691176698; cv=none; d=google.com; s=arc-20160816; b=a7I7bMXRpJFq7CjOu/7Ngw7yEbSGZCbtbGZUd+Omwts88WTNY1IizWxaL9jO9vxTqF VWbjG56I17x5gQ+qyUTSq0qUanSqeVk4G0LWztEENlKHY4JbT7fQhMY94P55Q1bm/vYK eZ3otNLBMSrupBKr7Xu2Eei21qw11MEH6YjSTyGMr4yiXHks5lvUIbNzJLzOja36j8qF yNwrnGkS6yCuWU9mRLilMHlP+UU6hutnWRRtm7z87I2WM+cXmu62OSTGRcaoVvMtHuSu 0M/tPIJfbTOqR9G21ebijD05dOpRDCDEfBOyOOMgnUG6bDwa4xQVysPgMo0l3wnxFkxg BkwA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from; bh=wKVTryVzZe73FK1hD+juThMQnW4xn/TI2NSDr39LRvQ=; fh=Xkin6fdEYjnaOLU5AKa5pmdx6bOMlQ5vBl3viP607iU=; b=GE8t80dM1tVc+w9cExHQxODlDVZMXO8z1JdqJazT0nUdxfascf3+PaoUrYgfUQqIo4 ySs+kukDoQp0qhINa1fGDyeKWxwc07ujHt5w29uZCyCvynlQkf9cjsNluP9+mBkArOoe sOb74eSva9g8doK9QyshKQkDRKPc5ZUgq67E+u8zNJmkCy44FcakMR5HktZdENztXyJQ 51QzXXBtb3e7l3z96JYrwm9S0VY9TN4FNZ1/1LbJRzDBACh2ujeXOo+mLdRR/qb3Jvc0 O1IGTIPolNe7QEpttVvKlxkUu53EHaLQeoTSsy9uyFvrPF6Skdjay7TYWYgIhDKuOX04 EyaQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org" Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id 8-20020ac84e88000000b0040fefce0dbbsi1763009qtp.216.2023.08.04.12.18.18 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 04 Aug 2023 12:18:18 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org" Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qS0IT-0000Pu-MQ; Fri, 04 Aug 2023 15:17:13 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qS0IS-0000PH-EM; Fri, 04 Aug 2023 15:17:12 -0400 Received: from isrv.corpit.ru ([86.62.121.231]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qS0IR-0006xt-0H; Fri, 04 Aug 2023 15:17:12 -0400 Received: from tsrv.corpit.ru (tsrv.tls.msk.ru [192.168.177.2]) by isrv.corpit.ru (Postfix) with ESMTP id DBA821845C; Fri, 4 Aug 2023 22:17:11 +0300 (MSK) Received: from tls.msk.ru (mjt.wg.tls.msk.ru [192.168.177.130]) by tsrv.corpit.ru (Postfix) with SMTP id 709CC1B89F; Fri, 4 Aug 2023 22:16:51 +0300 (MSK) Received: (nullmailer pid 1875717 invoked by uid 1000); Fri, 04 Aug 2023 19:16:49 -0000 From: Michael Tokarev To: qemu-devel@nongnu.org Cc: qemu-stable@nongnu.org, Richard Henderson , Peter Maydell , Michael Tokarev Subject: [Stable-8.0.4 42/63] util/interval-tree: Use qatomic_set_mb in rb_link_node Date: Fri, 4 Aug 2023 22:16:25 +0300 Message-Id: <20230804191647.1875608-11-mjt@tls.msk.ru> X-Mailer: git-send-email 2.39.2 In-Reply-To: References: MIME-Version: 1.0 Received-SPF: pass client-ip=86.62.121.231; envelope-from=mjt@tls.msk.ru; helo=isrv.corpit.ru X-Spam_score_int: -68 X-Spam_score: -6.9 X-Spam_bar: ------ X-Spam_report: (-6.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_HI=-5, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org From: Richard Henderson Ensure that the stores to rb_left and rb_right are complete before inserting the new node into the tree. Otherwise a concurrent reader could see garbage in the new leaf. Cc: qemu-stable@nongnu.org Reviewed-by: Peter Maydell Signed-off-by: Richard Henderson (cherry picked from commit 4c8baa02d36379507afd17bdea87aabe0aa32ed3) Signed-off-by: Michael Tokarev (Mjt: s/qatomic_set_mb/qatomic_mb_set/ for 8.0 - it was renamed later) diff --git a/util/interval-tree.c b/util/interval-tree.c index 5a0ad21b2d..2000cd2935 100644 --- a/util/interval-tree.c +++ b/util/interval-tree.c @@ -128,7 +128,11 @@ static inline void rb_link_node(RBNode *node, RBNode *parent, RBNode **rb_link) node->rb_parent_color = (uintptr_t)parent; node->rb_left = node->rb_right = NULL; - qatomic_set(rb_link, node); + /* + * Ensure that node is initialized before insertion, + * as viewed by a concurrent search. + */ + qatomic_mb_set(rb_link, node); } static RBNode *rb_next(RBNode *node)