From patchwork Sat Jul 22 21:44:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 705251 Delivered-To: patch@linaro.org Received: by 2002:a5d:60ca:0:b0:317:2194:b2bc with SMTP id x10csp1088496wrt; Sat, 22 Jul 2023 14:46:03 -0700 (PDT) X-Google-Smtp-Source: APBJJlHdX7J8nGtd0SPCKCbR64aTlMqnUS8MIw8gkeaTlAhaoLk1OmwZWgAuM9JbOTBaA0Iw9u5i X-Received: by 2002:a05:620a:4514:b0:767:b4c0:45a1 with SMTP id t20-20020a05620a451400b00767b4c045a1mr3914231qkp.66.1690062363052; Sat, 22 Jul 2023 14:46:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690062363; cv=none; d=google.com; s=arc-20160816; b=Qlp0pq/tiLL2BYZ9RXR+acf3n8BbuFpIlNp42iKa18PyuK1b+2GlmOphojlEh0mkWA urEZ9YXVPDvqstvMs5byUXflmjUI3sViVrs4imj5aXFSuwMmNrm+YRGlt9DFPCuRCOog ljdstFM2a3Ro0lT9J0pJtgDJYBfidntKvdUBIx3eyY67IREfH+qNJEi2wR4Fr2zbinXr InWLvun0Ezxx11llq2ilgnKorDSB8wbloqis3mQNdfHuNgKw6GpQG7//hfY4/M2pvgGw E+DslCCcz8bjTKE/Ki9xHWLV/qp9EjpNvMQtWRDqArbqMhx1VmdhiiM7VoU7pRZX3TAe u+Mg== 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:dkim-signature; bh=RIXdZdL1FiTxhzgwxu6CqaY5btcznVXT/yw1VVMrSHI=; fh=TtCgZ66/N8gcYChv/7jL6y0H4ktf2t4TbkT/u8v9Cwc=; b=Wl52RbAopDZQtYcL6xAx4bhhnQLQ695i0DIMOO7Wp2ivyvabBhmCRU5/oLUZpeBrb0 vG2zAZ2dFI9wfKeBDlCxiiyeM2EpYGw2f7CNanCMggjwVP+fLFSMG65jqpbAWBKS7FNK lT/cdEQ+qrc2HscV8+vfEjHX01PFPCN/lM4uHs3YnchUKRaH23enH4xlzcpCKJgEKSsz Ko5UUHdTP/IfaZxS37tFO/N2DKkRwiqtObxU2wyxf7WXg3eLLza4mogcdUsAOK1YzGA8 aaiDT/fhf4virLWuJnI7DY5w7WZu9KeR6aTOIynRpJQmjS/KPL2KX/DsQq80QxaKqkMY gfBg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="M96gN/5D"; 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"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id bm24-20020a05620a199800b00767dd2b2020si3332653qkb.163.2023.07.22.14.46.02 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sat, 22 Jul 2023 14:46:03 -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; dkim=pass header.i=@linaro.org header.s=google header.b="M96gN/5D"; 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"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qNKOx-0000I7-Rd; Sat, 22 Jul 2023 17:44:35 -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 1qNKOw-0000HK-H1 for qemu-devel@nongnu.org; Sat, 22 Jul 2023 17:44:34 -0400 Received: from mail-wm1-x32a.google.com ([2a00:1450:4864:20::32a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qNKOo-00033F-Ob for qemu-devel@nongnu.org; Sat, 22 Jul 2023 17:44:34 -0400 Received: by mail-wm1-x32a.google.com with SMTP id 5b1f17b1804b1-3fbc244d384so25481715e9.0 for ; Sat, 22 Jul 2023 14:44:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1690062265; x=1690667065; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=RIXdZdL1FiTxhzgwxu6CqaY5btcznVXT/yw1VVMrSHI=; b=M96gN/5DHwpuCZVjhRfoYzlfy4pqbWMZ1ssy3loBVh9cXoaD+nyp8Bga6sH53i74CJ IgK7kC215BXga+AJ0psvTBZNPlWf+dnQadMVzv+CT6hrh9OKPfi1TgKj5X+VfjqNNuYf cK9lrsVFES8w0HYF32jp9c+Ssdes27tIyDBP4YZLlDQdYjQlO+KonH15fLaqrPRI/i5Q 2qJ03QL2vJdUphEs60Tb62aaqNG7+SM8uhGjwk4mktaK69buETpJkLTyw/BKtJKe2Daa uyUpTWSEpuBSo4niE6H3a8R1ZQKUPoGPFrJwq6QwYQt6ICPvTVsx5DpvlfgqkpULloUW BSWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690062265; x=1690667065; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=RIXdZdL1FiTxhzgwxu6CqaY5btcznVXT/yw1VVMrSHI=; b=g6ah6D0IAdzgVjOTLraX98p51sS642yfGTVRsGwKWrfJNlVfHdqCZtYvb2q8psa/7I 8bxu6yaa2PEHIpjvTh3fglYArBcFCSmlam6wA7Aok3+viQu6qoUMaNDUfJgWp+7SDGdr E9DGpo4wCf43FDg38FmLAEd71+9kcADlBXnavrmyHB2zWjLAP/UPGiN0BUtCo71Pymty WmNfPgSIHcAr6F8Lq5u7nFHhuBp8SNjD52AW5qx89oKBmPhZlOKSDEf3tiFwQ1V4Uv8t i4YQ0fLW5QfaRaz8V4UDt5jrrQsRs/MOtYClz40BldhTLpFqENm1vseM09bosm/uphvi 5BIQ== X-Gm-Message-State: ABy/qLYSJ3DHwKv+hWoa/lXCEY950r5M0QVVklM+a1pqY+/GMoomuNrD ix/7EW90BKu1HyR3TNnJcKZxxtwT9uaQKnskSNPxgQ== X-Received: by 2002:a7b:cd0c:0:b0:3fc:7d2:e0c0 with SMTP id f12-20020a7bcd0c000000b003fc07d2e0c0mr4916595wmj.27.1690062265096; Sat, 22 Jul 2023 14:44:25 -0700 (PDT) Received: from stoup.acentic.lan (179.181-106-213.static.virginmediabusiness.co.uk. [213.106.181.179]) by smtp.gmail.com with ESMTPSA id v22-20020a7bcb56000000b003fbb9339b29sm8846384wmj.42.2023.07.22.14.44.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 22 Jul 2023 14:44:24 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: peter.maydell@linaro.org, qemu-stable@nongnu.org Subject: [PATCH for-8.1 v2 2/4] util/interval-tree: Use qatomic_set_mb in rb_link_node Date: Sat, 22 Jul 2023 22:44:20 +0100 Message-Id: <20230722214422.118743-3-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230722214422.118743-1-richard.henderson@linaro.org> References: <20230722214422.118743-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::32a; envelope-from=richard.henderson@linaro.org; helo=mail-wm1-x32a.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable 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 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 Signed-off-by: Richard Henderson Reviewed-by: Peter Maydell --- util/interval-tree.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/util/interval-tree.c b/util/interval-tree.c index 5a0ad21b2d..759562db7d 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_set_mb(rb_link, node); } static RBNode *rb_next(RBNode *node)