From patchwork Mon Jul 31 21:02:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 708417 Delivered-To: patch@linaro.org Received: by 2002:a5d:6787:0:b0:317:2194:b2bc with SMTP id v7csp2522453wru; Mon, 31 Jul 2023 14:03:31 -0700 (PDT) X-Google-Smtp-Source: APBJJlEv6Y06m3aURvHPg895FT5L3fQT1bXQJ1f98k2etbxjtDDKlriP39/WAk3bywAlRNjOFIDn X-Received: by 2002:a05:620a:44d0:b0:76a:ece7:2071 with SMTP id y16-20020a05620a44d000b0076aece72071mr13695373qkp.41.1690837410844; Mon, 31 Jul 2023 14:03:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690837410; cv=none; d=google.com; s=arc-20160816; b=nidMx2MSdzi6TVppM6m+2rx942FxrKgg8NLjT3yQo9a53IhpSVevJRZlQxUllXECBk Ggj7Wg8jD4wsqU+fKmLQllNF6JZbY6Jy0KDpU6hhOOsmsNYQVFSBoszn7nHe7AdEmeZo 7b9PYDQTkKWdoyvPsLZhPNAkG8szmih2JHGRA+GopNtyDsA1WN/ZvQnLGbv86a2UNlts l1SbkvoE7m3a/oSHPBrfIBARTNkHj/vVAbp+GAvxdN6e/oF6ijk4Am/YqpxLiSAdZbth 51Z2pRd59dJJxMBNxXvcTtQG6csDWOIjzNsZuZfg6HWapmuyxNF1kHiZvlD5xI2ukH++ io4g== 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=MA43mJPR4S1w+5iUDGlCigiGv8RYffvPZ7jW3KkkkqY=; fh=20zcLA4cqjW/3I5wZ98zlxuHItai5Ka4phUhNNfJNfQ=; b=bLth90ue1fdRfnHHpSCZlP4dIT3Q6iFYKyBvr1Pw2h8naRlRYo7SquKUoeVXMZJvRX 0LjaWbQnFnmXFvjy+B9fRB68RJqOCyyEWhgv9exH2/FX/XeeHon1GPswpFFTuTO9JVOu ZruOXgavQkxFP+4Rk9S06G4AbWQ6oLh1GipJNSlxo/YObN8VPpXaSyKvqZr4AeCZNQGe kIkY7lLH2l7SG7GcutC/2m3yQO4j9a6AELo9ixfbuRLhkxKZXMkucddqcSGpLQzLeuJW +a28p7z+cSAsuXxaH57ajfq1FVvSHwbzmRl6SFEo2mFqm5YFkVoEppwHYhPj1I5cWrOf QXzQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=cnGCnJqq; 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 m17-20020a05620a291100b00767b7436df3si6547794qkp.319.2023.07.31.14.03.30 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 31 Jul 2023 14:03:30 -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=cnGCnJqq; 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 1qQa1z-0000p4-Nq; Mon, 31 Jul 2023 17:02:19 -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 1qQa1x-0000ns-ON for qemu-devel@nongnu.org; Mon, 31 Jul 2023 17:02:17 -0400 Received: from mail-pf1-x42b.google.com ([2607:f8b0:4864:20::42b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qQa1w-0006Me-2L for qemu-devel@nongnu.org; Mon, 31 Jul 2023 17:02:17 -0400 Received: by mail-pf1-x42b.google.com with SMTP id d2e1a72fcca58-686b91c2744so3549453b3a.0 for ; Mon, 31 Jul 2023 14:02:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1690837334; x=1691442134; 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=MA43mJPR4S1w+5iUDGlCigiGv8RYffvPZ7jW3KkkkqY=; b=cnGCnJqqN4OfwiB0PvTjzUO6GXxsNjPqBlL9J8Iy38HrST4Uxez8/EljBqcWQEqyTX x6Ci/EReAK8TdaZxilC77JTpudNJ2Qos13ZQkcUsMxDV+6bt6RDcp0tuHLclSXLTzKFG PUWed66a8f0pWHkGD3ja4z4Qwb9hKDUQOLJglU0EteoR9oHGowLw/vRiVvNoioTXHHWZ OxQ1Ul+GudS8fZta9Z8HrSqUWGy+f8GEMfiPGSBZ3GIV/16mrtAX+vRP9DSVvro0gBMi 7Ib8WHx1b+IAid8+mT6V11E6IzWKq/+Nm3Bu/VSwCMfIjbHvgA6yGx2K00qAK3HtzlDb OfUA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690837334; x=1691442134; 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=MA43mJPR4S1w+5iUDGlCigiGv8RYffvPZ7jW3KkkkqY=; b=hfJKVJvYdGAG0qUC9CMgAhbIC5UkJVTjFpRbUXFmFDX+GHt/qSDuHwnzT3ZiKoddTp 1U7k+ElGsY1HWwPZ6s02/Z0p/QLqASP8nbVP3Hby6akhk/Yz8lcirrqiELBf2L4q4Unv uPj45+WkztwjmXU8OAkp6MpNjlP1FGbRf/Uq5oBmHIr2K4/5tW6bSKfAeqkZJMy1uJOG fI4VnsiQZN1jFT//X0SRumbOELOhuPylHXhI1t020s0j2f8Wrvy10D/l71oNssOQF7jK da6MfKN4o/TB9eX3cHiCddwxAc/802LNb0kpfVyTdXErZalqurpWr+QKK7eHasa6YPeW gNSQ== X-Gm-Message-State: ABy/qLaC2Hqv0hMfrRDDVWBjFJnPc2Wwm22lHslgwW5CbX5pmwMs5pTJ FtI46rtaG1DNV59vj/mV0uLV7jnxzJtIWMrfw+4= X-Received: by 2002:a17:90a:de90:b0:267:f5d1:1dd3 with SMTP id n16-20020a17090ade9000b00267f5d11dd3mr9408459pjv.11.1690837334647; Mon, 31 Jul 2023 14:02:14 -0700 (PDT) Received: from stoup.. ([2602:47:d490:6901:4f6f:6b:2de4:e0cb]) by smtp.gmail.com with ESMTPSA id r11-20020a1709028bcb00b001bb8895848bsm8924230plo.71.2023.07.31.14.02.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 31 Jul 2023 14:02:14 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: qemu-stable@nongnu.org, Peter Maydell Subject: [PULL 02/10] util/interval-tree: Use qatomic_set_mb in rb_link_node Date: Mon, 31 Jul 2023 14:02:03 -0700 Message-Id: <20230731210211.137353-3-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230731210211.137353-1-richard.henderson@linaro.org> References: <20230731210211.137353-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::42b; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x42b.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=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 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 --- 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)