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 1sYTr0-00Bfbl-4q for pgsql-hackers@arkaria.postgresql.org; Mon, 29 Jul 2024 17:08:10 +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 1sYTqy-001FPx-02 for pgsql-hackers@arkaria.postgresql.org; Mon, 29 Jul 2024 17:08:08 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sYTqx-001FPo-Ib for pgsql-hackers@lists.postgresql.org; Mon, 29 Jul 2024 17:08:07 +0000 Received: from lahtoruutu.iki.fi ([2a0b:5c81:1c1::37]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sYTqu-0024E0-DU for pgsql-hackers@postgresql.org; Mon, 29 Jul 2024 17:08:06 +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 4WXlDG2LzKz49Pxq; Mon, 29 Jul 2024 20:07:57 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=lahtoruutu; t=1722272879; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=xVQM0IH9fFat/XHZ9mC6VERkXVgfnYcQHoyqf+94JwM=; b=HjILND+fjxY3kUjQDe0t2zSnsPQ3ylRuOSNWf9DyGcUGyDAlg1JdgNffoqZ2U9yYF2gAL/ +MYz3u1xgrFiqJ0LC+Z2Q+v7rvxC+jPhOfAy2LNfwuz3R/zUNd0RpDWxaFYLx16zrPeab6 6VNHXMbP6SVwno2f600XuZdRuZ+6CofW4+LrOyHSo5Y3b/qeE4UpDTgkqAfsbT8UsHM81F iu2sMGXaipcqRITdW9loOmqjHBvxfO8vA2LY7qQXSe3na6msp0YKVL8t91VufpU42lgKxx IVqt8RXYdXwJLmXPaRYis/4598weY2HK/DpWg07RHa5rt5PKT3WuETJPA4qFgQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=lahtoruutu; t=1722272879; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=xVQM0IH9fFat/XHZ9mC6VERkXVgfnYcQHoyqf+94JwM=; b=O2t+yzcpUSo6WP5FJtMtN5sVJ7fhD9WIruebULONe0xY1lhXnUa41N9BPgXIepQ8ghUIBA yj83DcELumGEADYPgUzIuyArWgU8CAEIm5ng9GrPTYlK/QEawCzsnIwsV31TDA9lksnoOQ muwN/JbIkkBkuolhRmHp4j/TseIk/NLtrvRzrHVsjWepnNenyenDMq8terHgNfu1RPm/cs JDQJZAQtJwmrUqwgOiIOh/PapKXoKhbW5OECXetmiaGPyzbScwrLqIfOaPymEqfoZSNtEH sgWEIiKwe62GJNCPKnu5cRzNuqepsscO9TlKRw5GNqC0tE/XRZ4exSNCWb+GDw== 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=1722272879; a=rsa-sha256; cv=none; b=hX1f8KtseEo0x8CNYXlcydhahPwKVZjE5KluTSelfYtENRyzdtSS6b5S4F3OCESFYOQwwK Ox3Xr0pMQjRH+wmR+8/AO1y8gwbz/X4Q7tBbpDqeHCq1w2Ujn2XVcP6aSfPQp6yEz8zfaX i9dq3blZHIZ0oEtplsnTpe4Bni6pCGrYm8aRUuN4uGQjy7yKPV3dcGRV5eGBExf2pGAtdC letc5BYxlwRdjq8Tj5dL7tGM5XUM8qf98iAd+zlYEN3mIj9tmCcCqQr2XJasS0Ae0VrGrZ mAxBSTwxA/XZetucxmsEmjwTY5QTtNJo4HtKLJtv3cc6Gz9NcaZY4k8m+8PLbw== Message-ID: Date: Mon, 29 Jul 2024 20:07:56 +0300 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Detect double-release of spinlock To: Andres Freund , Tom Lane , 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> Content-Language: en-US From: Heikki Linnakangas In-Reply-To: <20240729165154.56zqyg34x2ywkpsh@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 19:51, Andres Freund wrote: > On 2024-07-29 09:40:26 -0700, Andres Freund wrote: >> On 2024-07-29 12:33:13 -0400, Tom Lane wrote: >>> Andres Freund writes: >>>> On 2024-07-29 11:31:56 -0400, Tom Lane wrote: >>>>> There was some recent discussion about getting rid of >>>>> --disable-spinlocks on the grounds that nobody would use >>>>> hardware that lacked native spinlocks. But now I wonder >>>>> if there is a testing/debugging reason to keep it. >>> >>>> Seems it'd be a lot more straightforward to just add an assertion to the >>>> x86-64 spinlock implementation verifying that the spinlock isn't already free? >> >> FWIW, I quickly hacked that up, and it indeed quickly fails with 0393f542d72^ >> and passes with 0393f542d72. +1. Thanks! >>> Other context from this discussion: >>> I dunno, is that the only extra check that the --disable-spinlocks >>> implementation is providing? >> >> I think it also provides the (valuable!) check that spinlocks were actually >> initialized. But that again seems like something we'd be better off adding >> more general infrastructure for - nobody runs --disable-spinlocks locally, we >> shouldn't need to run this on the buildfarm to find problems like this. Note that the "check" for double-release with the fallback implementation wasn't an explicit check either. It just incremented the underlying semaphore, which caused very weird failures later in completely unrelated code. An explicit assert would be much nicer. +1 for removing --disable-spinlocks, but let's add this assertion first. >>> I'm kind of allergic to putting Asserts into spinlocked code segments, >>> mostly on the grounds that it violates the straight-line-code precept. >>> I suppose it's not really that bad for tests that you don't expect >>> to fail, but still ... >> >> I don't think the spinlock implementation itself is really affected by that >> rule - after all, the --disable-spinlocks implementation actually consists out >> of several layers of external function calls (including syscalls in some >> cases!). 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. -- Heikki Linnakangas Neon (https://neon.tech)