Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sYUfp-00Bl6T-41 for pgsql-hackers@arkaria.postgresql.org; Mon, 29 Jul 2024 18:00:40 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1sYUfn-001x2q-Jo for pgsql-hackers@arkaria.postgresql.org; Mon, 29 Jul 2024 18:00:39 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sYUfn-001x2i-8a for pgsql-hackers@lists.postgresql.org; Mon, 29 Jul 2024 18:00:39 +0000 Received: from lahtoruutu.iki.fi ([2a0b:5c81:1c1::37]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sYUfk-0026nj-Oy for pgsql-hackers@postgresql.org; Mon, 29 Jul 2024 18:00:38 +0000 Received: from [192.168.1.122] (dsl-hkibng22-54f8db-125.dhcp.inet.fi [84.248.219.125]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: hlinnaka) by lahtoruutu.iki.fi (Postfix) with ESMTPSA id 4WXmP00dRlz49Q0f; Mon, 29 Jul 2024 21:00:36 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=lahtoruutu; t=1722276036; 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=DVM1MGjBGlwpJrfl0DCAQ+GZFyVGK3mWP0lQN2GKhGs=; b=KD3bb5BlUSAijdoeNaXzsKHr/jgngYl9aAiBYKcLuLlICupnRyFCHgivx26TBysqOSXw50 tJ25QyVlOEY7blg5cZfAx3/y0rxe4jW/Ftr6QTrVh7CCrRlMsdxmMh1Uguwi3Za3xLLYgF zuyqvOl+jgO/Du4ooUn0IAF30fakgBxTZh3uoTNr/9ItBiyMmQ4avGeeROB5TsaoOp8TDh /Wdte0P0RBZRwKuziEjpmA7G8415XbqTTwZUMFvvLYmU8sGaRuvt7A06eSs339+ZQS7mMG T/eOhGQ5l0ubJS1SGDfvPI/ZXy2+UP2ZQDVhBKpRLhezUKVU5v2s59tQs1y+5A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=lahtoruutu; t=1722276036; 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=DVM1MGjBGlwpJrfl0DCAQ+GZFyVGK3mWP0lQN2GKhGs=; b=El/hRONnG0kWEtVhBOtFSaqC0T86RPBBnrxquQmulUspd7/v0J/OyJAgCKN8jyS9F1Puqo QIcq1dWtC/khTAu739xjQkugRbUxMCHkTxwllzfAkHIOjB3gaIiwdKfnnxhNDv+eem38Vx X3wraH/z5Uy+YdLePeR9/0lGGWbbXRZnHMANCUZlFE9rswm/NA/VTOJVOtKk3pR37kS3pW cgE/oJRrytEwcGZtUjEg4NlnR8mcc/3/9BbzEWbEH+Od3xm6C6S5WWX8LHpukDwvEr4H3+ SqrQXPddPvvKJ6G3lEZqxGX3cok1TIHqyFwVerL1++CLikfT2xlGQH32ZDLZgQ== ARC-Authentication-Results: i=1; ORIGINATING; auth=pass smtp.auth=hlinnaka smtp.mailfrom=hlinnaka@iki.fi ARC-Seal: i=1; s=lahtoruutu; d=iki.fi; t=1722276036; a=rsa-sha256; cv=none; b=h2FZld41AL61kLXTTWncpo8iJoHgRSvsTSfAKqhE4oOtoAQ0hTHasF2NrPeURqWOIVpuhy RuYYwT538T2HTBXVzNLucqRC0NV26uU0T51cph4CDJNB/Eou3gDvfdtO+s2xcFNWvg6qnb gCC8iVInmUcXujNkBawYvBDo5bJ28k7mMSorTY4BsIsQwrmKQqlCl8EepKyTULPFM7uB3j j1FJnFV9o1ft8DJV+m88LlGZRF61R6CSERXiNonXQIbFkuZuE8P5cr7MQDSiFr2TR2pmMg Yulto4RWfPqPy9Q9aEahtzJKeJRiF7/cF1/tww0fwyLwNGvgU1yS6DIFfHvUAQ== Message-ID: <790b901f-c0f6-4e97-b59a-97d8f921d57e@iki.fi> Date: Mon, 29 Jul 2024 21:00:35 +0300 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Detect double-release of spinlock To: Andres Freund , Tom Lane Cc: pgsql-hackers@postgresql.org References: <2600757.1722267116@sss.pgh.pa.us> <20240729161846.kgiafbe2dtgabxgb@awork3.anarazel.de> <2802449.1722270793@sss.pgh.pa.us> <20240729164026.yurg37tej34o76uk@awork3.anarazel.de> <20240729165154.56zqyg34x2ywkpsh@awork3.anarazel.de> <2809049.1722273922@sss.pgh.pa.us> <20240729174853.uo5qjqkxlacjg6vv@awork3.anarazel.de> Content-Language: en-US From: Heikki Linnakangas In-Reply-To: <20240729174853.uo5qjqkxlacjg6vv@awork3.anarazel.de> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 29/07/2024 20:48, Andres Freund wrote: > On 2024-07-29 13:25:22 -0400, Tom Lane wrote: >> Heikki Linnakangas writes: >>> Yeah I'm not worried about that at all. Also, the assert is made when >>> you have already released the spinlock; you are already out of the >>> critical section. >> >> Not in the patch Andres posted. > > Which seems fairly fundamental - once outside of the critical section, we > can't actually assert that the lock isn't acquired, somebody else *validly* > might have acquired it by then. You could do: bool was_free = S_LOCK_FREE(lock); S_UNLOCK(lock); Assert(!was_free); Depending on the underlying implementation, you could also use compare-and-exchange. That makes the assertion-enabled instructions a little different than without assertions though. > However, I still don't think it's a problem to assert that the lock is held in > in the unlock "routine". As mentioned before, the spinlock implementation > itself has never followed the "just straight line code" rule that users of > spinlocks are supposed to follow. Agreed. -- Heikki Linnakangas Neon (https://neon.tech)