From nobody Tue Feb 10 02:27:34 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1683623215; cv=none; d=zohomail.com; s=zohoarc; b=jQAmo576S9e07/e1dVjZZxRnKnbVbn8E3mm4FjQx3YoqAl5OKhXKh30TnIMt9lJ2HkJ3at3DgtNm5wyUoD8X4XGEPrjTFAMPAwjJstSTIrsLjxW3klMp+ezXbg4RynkbM1Ai4mb0nmEZs5dcBLME0GqmvuGJ3h5gNahd9uSkYSo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1683623215; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=7G0JGRJuNzOy08wxI94uhJe0IVFxaXWeMU7b25jAV+E=; b=P+JCL7mcK7PHc8YCvaZ4ko2n+B988AD79roTMAXusKTwVtEAgD2NIcvGs4qwSKNHZQ6+Y8RNbWVl7c9moCIrvB48gPr2HjQ8uySlvE3QAZf3Y1nmmO/m1AclZpfs+7W9wlrp/lkkP/IzCXpENdyr8uGLA6PlrMvUo+7zsUllhLY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 168362321507947.444366190560345; Tue, 9 May 2023 02:06:55 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pwJHY-0005Fh-Ml; Tue, 09 May 2023 05:05:16 -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 1pwJHW-0005Er-TA for qemu-devel@nongnu.org; Tue, 09 May 2023 05:05:14 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pwJHR-0004uO-5b for qemu-devel@nongnu.org; Tue, 09 May 2023 05:05:12 -0400 Received: from mail-ej1-f70.google.com (mail-ej1-f70.google.com [209.85.218.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-381-0KkK-_LAMIevSfmMp0YZhA-1; Tue, 09 May 2023 05:05:07 -0400 Received: by mail-ej1-f70.google.com with SMTP id a640c23a62f3a-94a355cf318so646341566b.2 for ; Tue, 09 May 2023 02:05:07 -0700 (PDT) Received: from [192.168.10.118] ([2001:b07:6468:f312:9af8:e5f5:7516:fa89]) by smtp.gmail.com with ESMTPSA id e19-20020a056402089300b0050bd9d3ddf3sm515052edy.42.2023.05.09.02.05.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 May 2023 02:05:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1683623108; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=7G0JGRJuNzOy08wxI94uhJe0IVFxaXWeMU7b25jAV+E=; b=WPsYeXPAOfC4VpF16RGMRY3wXOrYX88bqLAI6qP3KkV8C/pje3CrUc9gqFxGekp5dFavT8 LYzk9Pxr0axi6nQ9Hd0VOHgo5EWVXUlEGrMk3C3nzGatwzaogUmps7n8dm/dfcrzmQQt60 YaDXaAPwgPSzbdGGgvct0WT5fULsUrY= X-MC-Unique: 0KkK-_LAMIevSfmMp0YZhA-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683623105; x=1686215105; 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=7G0JGRJuNzOy08wxI94uhJe0IVFxaXWeMU7b25jAV+E=; b=PJU0mUvLo4Us+is/YQARfgPjeAHKTZb7YT4rwvxTPyjBc7c4S/7HQarrIT0YoWBLHG UmW8jAFsSMsCcFAhfrMlJSxfX0X4b5wmp/3hLC7fJKjKS3+hvWHuQOb1rHpZUO5lfm2y LSSH6ALlPIzP0hNsBSVQmz5FSgf1u3KjSVKfc9r5QgE1dJE/tjXvuyY6fdTaDS8PCnQ+ mAL7f12HbVJiAvaIQMk7ntniJajI3gLCcbWtP21cfne7cMARRMykHfGNhmDPm8yRm/JU 6jPd2Q6bzs9M5eDju44Eim1BsOvKM6Yy8LrkRFjVJAA2bbjTVXJ+leF3gmiPr5z1GbQS FaKQ== X-Gm-Message-State: AC+VfDygQd/pWT17r6smfY4U3rD4xZXvrGtVDw6V/Da5CAlv3rfqKpRc ZzgLXyo/Z/F72w3TV0rD1ziujOsLHwlxG3wknuy5WvflP0jUd4EpFHhE+Z2nIw3a97B3I0znPv/ k+IFiBtq6Fo3Qomq/v0fuCiXMWQXjLmAILzgBrLNBy1lEvbsDXT/XFwAHlgs457qH5SARSqh76s I= X-Received: by 2002:a17:907:9718:b0:966:c09:1c57 with SMTP id jg24-20020a170907971800b009660c091c57mr10250180ejc.65.1683623105598; Tue, 09 May 2023 02:05:05 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5bMef7WgTQWa7iaG3to+nl5dibZJ8I3YSiY55JUrhGJovmTRs03E0ddAVAvSH4gXeA6NcldQ== X-Received: by 2002:a17:907:9718:b0:966:c09:1c57 with SMTP id jg24-20020a170907971800b009660c091c57mr10250146ejc.65.1683623105216; Tue, 09 May 2023 02:05:05 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Richard Henderson Subject: [PULL 04/16] call_rcu: stop using mb_set/mb_read Date: Tue, 9 May 2023 11:04:41 +0200 Message-Id: <20230509090453.37884-5-pbonzini@redhat.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230509090453.37884-1-pbonzini@redhat.com> References: <20230509090453.37884-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.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, DKIMWL_WL_HIGH=-0.001, 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1683623215705100001 Content-Type: text/plain; charset="utf-8" Use a store-release when enqueuing a new call_rcu, and a load-acquire when dequeuing; and read the tail after checking that node->next is consistent, which is the standard message passing pattern and it is clearer than mb_read/mb_set. Reviewed-by: Richard Henderson Signed-off-by: Paolo Bonzini --- util/rcu.c | 45 ++++++++++++++++++++++++++++++++------------- 1 file changed, 32 insertions(+), 13 deletions(-) diff --git a/util/rcu.c b/util/rcu.c index e5b6e52be6f8..30a7e220264a 100644 --- a/util/rcu.c +++ b/util/rcu.c @@ -189,8 +189,22 @@ static void enqueue(struct rcu_head *node) struct rcu_head **old_tail; =20 node->next =3D NULL; + + /* + * Make this node the tail of the list. The node will be + * used by further enqueue operations, but it will not + * be dequeued yet... + */ old_tail =3D qatomic_xchg(&tail, &node->next); - qatomic_mb_set(old_tail, node); + + /* + * ... until it is pointed to from another item in the list. + * In the meantime, try_dequeue() will find a NULL next pointer + * and loop. + * + * Synchronizes with qatomic_load_acquire() in try_dequeue(). + */ + qatomic_store_release(old_tail, node); } =20 static struct rcu_head *try_dequeue(void) @@ -198,26 +212,31 @@ static struct rcu_head *try_dequeue(void) struct rcu_head *node, *next; =20 retry: - /* Test for an empty list, which we do not expect. Note that for + /* Head is only written by this thread, so no need for barriers. */ + node =3D head; + + /* + * If the head node has NULL in its next pointer, the value is + * wrong and we need to wait until its enqueuer finishes the update. + */ + next =3D qatomic_load_acquire(&node->next); + if (!next) { + return NULL; + } + + /* + * Test for an empty list, which we do not expect. Note that for * the consumer head and tail are always consistent. The head * is consistent because only the consumer reads/writes it. * The tail, because it is the first step in the enqueuing. * It is only the next pointers that might be inconsistent. */ - if (head =3D=3D &dummy && qatomic_mb_read(&tail) =3D=3D &dummy.next) { + if (head =3D=3D &dummy && qatomic_read(&tail) =3D=3D &dummy.next) { abort(); } =20 - /* If the head node has NULL in its next pointer, the value is - * wrong and we need to wait until its enqueuer finishes the update. - */ - node =3D head; - next =3D qatomic_mb_read(&head->next); - if (!next) { - return NULL; - } - - /* Since we are the sole consumer, and we excluded the empty case + /* + * Since we are the sole consumer, and we excluded the empty case * above, the queue will always have at least two nodes: the * dummy node, and the one being removed. So we do not need to update * the tail pointer. --=20 2.40.1