From nobody Sat Jul 12 14:48:38 2025 Delivered-To: importer2@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+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1678142065; cv=none; d=zohomail.com; s=zohoarc; b=UkY3DVTFimtp5fwTDPuLg9utTTaZuZLhSRD1mo0nR8EtkPVQmM6MNwC1tVE8ihEUAsQG0x5xgAM4NItw4quEjdKqc2rR1tq4Jy0Vc/FO/mOmnI1aPycfCzYlx6ixr+mm9sDgZPIihE8X7KOYFh60z4ibH+H6a2uegQP3Z/66hQo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1678142065; 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=mOHH4yPNJZf+Sa0450BcZZrU7cumuCnXGhvsXLoiMX8=; b=Y13x7QMNuSret8SMWV+Jm9oS0rCYoeES5kHHTY2F4qjUuxAT87B1ZaEtvJrV90rMFA6xQ7mTqsTWD3k3bST4iD9TPyOE/26lMPOeiHOCJOML6yV/O0Pf7gaKlCuJEnaUTttJvGEtf1nikVVBpJ4Wrqepa2Ji40ms4amWDCkGYvE= 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+importer2=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 167814206567510.938760048567815; Mon, 6 Mar 2023 14:34:25 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pZJOh-0004PA-1M; Mon, 06 Mar 2023 17:33:35 -0500 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 1pZJOf-0004O5-Gp for qemu-devel@nongnu.org; Mon, 06 Mar 2023 17:33:33 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pZJOe-0003YT-8G for qemu-devel@nongnu.org; Mon, 06 Mar 2023 17:33:33 -0500 Received: from mail-ed1-f71.google.com (mail-ed1-f71.google.com [209.85.208.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-646-YGC-_Pk_Nl6Ad4MBdmmSRg-1; Mon, 06 Mar 2023 17:33:30 -0500 Received: by mail-ed1-f71.google.com with SMTP id y1-20020a056402358100b004ea439d57b7so3694951edc.12 for ; Mon, 06 Mar 2023 14:33:30 -0800 (PST) Received: from avogadro.local ([2001:b07:6468:f312:9af8:e5f5:7516:fa89]) by smtp.gmail.com with ESMTPSA id dx11-20020a170906a84b00b008e493b7bb61sm5089287ejb.153.2023.03.06.14.33.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Mar 2023 14:33:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1678142011; 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=mOHH4yPNJZf+Sa0450BcZZrU7cumuCnXGhvsXLoiMX8=; b=X+2k4iU2GYI8SPXoA6l218yLSa1YOx8xOPLM3sX3rPbytGFn/rSpTvKbVQ8I48UeX5bM6V Gz4+1scSjDAR/j0qiDBCBR2exJj+UWCoHocMgnId0/yirDQtVpSLhxLK0k/CiqAf38ria2 JQxY1A85wW5yi0bImsdz/k042TPHLxs= X-MC-Unique: YGC-_Pk_Nl6Ad4MBdmmSRg-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678142009; 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=mOHH4yPNJZf+Sa0450BcZZrU7cumuCnXGhvsXLoiMX8=; b=TiLkg7DPpwpeKGpxedF9cPedoIa+pk7Lz7j5pxp0OLAX2xcM3oplJghOexAnAzde9l lMuzIg/qsT1lr1vlk8Tvd3851SC2vZlBudUvF06I/dqtH8fRnOTCZ2rdxDMTsL+2FPfF 0rqR/2woZ2xAaWjD8s3iQuH8BRNW0lBHNDXsABHYA5eQXjrX8giSbi2DBsMhqBZ2UkGs /Qkb78jIsrRH4/XnSQB/FEgDETngXPy6abQtNx5B6zuvG6kcdWXlzHcComeCUo9C3/3D eCXAciXsj7X3poDIrW0CYhTrfR6ZYPlDSpqKtNQYlZJPUwS8q9jJnNtDuaXPtU/Xi3hL H8zg== X-Gm-Message-State: AO0yUKWZxyNCzH+HnXACtU7V2YNmDHZt0pFkff48hsN5ZE/0HUtkUPG4 WkKN/0xliwcuekfGyOnjv9Tar2OYwQE0gIOQ4ppa8wiIW2borogvCFqBe10iQyiJN8jUPWTLRJR G5YQs2QDlM/fYj9J+NWd/4gAG56kPdOVavtegzea0gj5HkYl1cOCA4cgoxqAqCbPWaISMRVKhF2 8= X-Received: by 2002:aa7:c1d6:0:b0:4c1:88e:6ac9 with SMTP id d22-20020aa7c1d6000000b004c1088e6ac9mr11309673edp.10.1678142008895; Mon, 06 Mar 2023 14:33:28 -0800 (PST) X-Google-Smtp-Source: AK7set9ZOQDrKBDC+rHid1ppyEqqqrU4e3oCRRUFTha6BjHi1Z5w/FeAF6EqHD+wBDNGu2WOsfoyEg== X-Received: by 2002:aa7:c1d6:0:b0:4c1:88e:6ac9 with SMTP id d22-20020aa7c1d6000000b004c1088e6ac9mr11309658edp.10.1678142008624; Mon, 06 Mar 2023 14:33:28 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: gshan@redhat.com, eesposit@redhat.com, david@redhat.com, stefanha@redhat.com, cohuck@redhat.com, eauger@redhat.com, richard.henderson@linaro.org Subject: [PATCH v2 6/9] qemu-coroutine-lock: add smp_mb__after_rmw() Date: Mon, 6 Mar 2023 23:33:03 +0100 Message-Id: <20230306223306.84383-7-pbonzini@redhat.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230306223306.84383-1-pbonzini@redhat.com> References: <20230306223306.84383-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+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.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, RCVD_IN_MSPIKE_H2=-0.001, 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+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1678142067243100007 Content-Type: text/plain; charset="utf-8" mutex->from_push and mutex->handoff in qemu-coroutine-lock implement the familiar pattern: write a write b smp_mb() smp_mb() read b read a The memory barrier is required by the C memory model even after a SEQ_CST read-modify-write operation such as QSLIST_INSERT_HEAD_ATOMIC. Add it and avoid the unclear qatomic_mb_read() operation. Reviewed-by: Richard Henderson Reviewed-by: David Hildenbrand Signed-off-by: Paolo Bonzini --- util/qemu-coroutine-lock.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/util/qemu-coroutine-lock.c b/util/qemu-coroutine-lock.c index 58f3f771817b..84a50a9e9117 100644 --- a/util/qemu-coroutine-lock.c +++ b/util/qemu-coroutine-lock.c @@ -201,10 +201,16 @@ static void coroutine_fn qemu_co_mutex_lock_slowpath(= AioContext *ctx, trace_qemu_co_mutex_lock_entry(mutex, self); push_waiter(mutex, &w); =20 + /* + * Add waiter before reading mutex->handoff. Pairs with qatomic_mb_set + * in qemu_co_mutex_unlock. + */ + smp_mb__after_rmw(); + /* This is the "Responsibility Hand-Off" protocol; a lock() picks from * a concurrent unlock() the responsibility of waking somebody up. */ - old_handoff =3D qatomic_mb_read(&mutex->handoff); + old_handoff =3D qatomic_read(&mutex->handoff); if (old_handoff && has_waiters(mutex) && qatomic_cmpxchg(&mutex->handoff, old_handoff, 0) =3D=3D old_handof= f) { @@ -303,6 +309,7 @@ void coroutine_fn qemu_co_mutex_unlock(CoMutex *mutex) } =20 our_handoff =3D mutex->sequence; + /* Set handoff before checking for waiters. */ qatomic_mb_set(&mutex->handoff, our_handoff); if (!has_waiters(mutex)) { /* The concurrent lock has not added itself yet, so it --=20 2.39.1