From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on gnuweeb.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=ALL_TRUSTED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NO_DNS_FOR_FROM,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.6 Received: from localhost.localdomain (unknown [180.246.144.41]) by gnuweeb.org (Postfix) with ESMTPSA id B435A80962; Tue, 16 Aug 2022 16:53:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gnuweeb.org; s=default; t=1660668813; bh=XRrd1rJFXfvJqQ5timEc4qOSDOcgd2PG+1vdIo8m7mg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=h6uYE+pt0F/u4BFjLPRU0lifSyWqsHnKiRrTugCWEovJ72GuQFqSrOzvXmqBRjNsV e/6tyEy14ym8kTySSrKeeplyJaQj5mK41D3Pjl41dk0ZqWECnMM/tfxAPRcLnhgNNE Jtpa7sKic68DZ1EyjGmoHYBVMOBLIPSMmIOccsDzflulecn3Cn5VoV/CYP+lq7WV0r Eu6fFaaakRHa/1TeK4G6ksoyZ+XeIHExEKVkOzmRzeHijCBWUIQ/syKyeeWktRzRRv 8Vv/ITkFQC96kJiaV0TPBhj8UbqMQNZTIw+Isk6NwKwgesfH5K2V/h0I7FDotMCEZV cMLdUp0qnUGUQ== From: Ammar Faizi To: Alviro Iskandar Setiawan Cc: Ammar Faizi , GNU/Weeb Mailing List Subject: [PATCH ncns v1 3/4] chnet: ring: Make sure we are holding the lock when calling `cqe_size()` Date: Tue, 16 Aug 2022 23:53:13 +0700 Message-Id: <20220816165314.3875649-4-ammarfaizi2@gnuweeb.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220816165314.3875649-1-ammarfaizi2@gnuweeb.org> References: <20220816165314.3875649-1-ammarfaizi2@gnuweeb.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: In `CNRingCtx::WaitCQE`, the first call to `cqe_size()` is not protected by the cqe_lock. Protect it. Fixes: a04f582cdbdbcefa3c08ce123696d0fd08a20702 ("chnet: Full refactor CNRing and change the interface") Signed-off-by: Ammar Faizi --- chnet/chnet_ring.cc | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/chnet/chnet_ring.cc b/chnet/chnet_ring.cc index c9a3da5..e9d0d57 100644 --- a/chnet/chnet_ring.cc +++ b/chnet/chnet_ring.cc @@ -366,6 +366,7 @@ uint32_t CNRingCtx::SubmitSQE(uint32_t to_submit) void CNRingCtx::WaitCQE(uint32_t to_wait) { uint32_t max_to_wait; + uint32_t cq_size; if (unlikely(!to_wait)) return; @@ -375,10 +376,11 @@ void CNRingCtx::WaitCQE(uint32_t to_wait) to_wait = max_to_wait; NotifyWaitCQEFreeSlot(); - if (to_wait <= cqe_size()) - return; std::unique_lock cqe_lock(state_->cqe_lock_); + cq_size = cqe_size(); + if (to_wait <= cq_size) + return; state_->cqe_to_wait_.store(to_wait); state_->cqe_cond_.wait(cqe_lock, [this, to_wait]{ -- Ammar Faizi