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 1vBpIw-005ebc-1U for pgsql-hackers@arkaria.postgresql.org; Thu, 23 Oct 2025 07:00:09 +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 1vBpIt-0065v1-Qv for pgsql-hackers@arkaria.postgresql.org; Thu, 23 Oct 2025 07:00:06 +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 1vBpIt-0065ut-FO for pgsql-hackers@lists.postgresql.org; Thu, 23 Oct 2025 07:00:06 +0000 Received: from mail-lf1-x12a.google.com ([2a00:1450:4864:20::12a]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1vBpIq-003knf-0T for pgsql-hackers@postgresql.org; Thu, 23 Oct 2025 07:00:06 +0000 Received: by mail-lf1-x12a.google.com with SMTP id 2adb3069b0e04-57a960fe78fso664501e87.2 for ; Thu, 23 Oct 2025 00:00:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1761202802; x=1761807602; darn=postgresql.org; h=in-reply-to:from:content-language:references:cc:to:subject :user-agent:mime-version:date:message-id:from:to:cc:subject:date :message-id:reply-to; bh=PJZoBu3Qz4ctJgBPAN+5vtNqEH4+8Ci1VeWtMHL+JmA=; b=jFawaftPBS0Yd6ExEBuaP3j0uIGrk18F8xh9LozTYNbcctnOvIbX0EZ1CrwXkn2taZ gqrydBJvHFXrDMIseYZLcxp5VPMWNPGqX96vhLo5fJU6fm0aNIQEaCPdamyeDhDtLXQr THCcc0VB1tH31+YfROED/eWON5Ez9sa909wiE6UUI0w6CxV6GQPQOD/LMoSyeZu15F1p YTCspeLylgUeB2Cn+BhgMsgMYdDlceRf0l0oWGQm2rlHTpwps6vGcrX28TDelXZJ90v/ V4PehmrX3/gzWWmz3avWuBP1QiGt73hVId7nThTqUbO582sZDbPZPJjrlDaDrZiAWSyr 27nA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1761202802; x=1761807602; h=in-reply-to:from:content-language:references:cc:to:subject :user-agent:mime-version:date:message-id:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=PJZoBu3Qz4ctJgBPAN+5vtNqEH4+8Ci1VeWtMHL+JmA=; b=keiSjnLE1CgsyOOUPTUB5JxaRdQW0rHFcfrLdZzBWGYpCc1EV2c06a+O/gC4/noqOu xcVWGuKXbQlAjrNCzG1FHz0i1kv0WoEWOqnHxikmoAklmy8swhKjfkefrfjHoMGtLlJl 7eqAjf4eME6LOq16oR7VdoEWbyERJcyVX+XlsXssZx7+AE2XTgbjr41i4N+aU/jlRO/I YiwPAdzoTwjvQgYTCyL+iYVvCLr/S6hyeLAD/aJA6RZkSDG62ddHBujBOuQ4vdfYP8Lq gQa2yP+PBwNLac8JqRzra5R4IGJlbjCOptEglYbeX8Mz2ZqmTdYXJeXPZrA/L7Vr87Iu MWbw== X-Gm-Message-State: AOJu0Yy5/xL+/bAxL+yomCRIXCOc7QweJnr9q+vDGpJ+or8a3hGbKMvz IAgOn8M+jghfkTNZAFrO0/NjRnXQ9wRE8rrEgqC7zoufdoWxLR7VuALQ X-Gm-Gg: ASbGncvKL9RCEKS5ax0uAtwRYGrqAOWgh7GE1+HtZDD3rT8NHXmsRCVo9uKLl7m5Wzy SuUxIP0KRu18ATDLFrdDKmk+MknzTM1iQV2qY1vezDWy1x7yYGa3DqTK5Gzlt9WN+2CkYXvwpfr YUJWfhLt1XAodHR0jPB7VRD2ugK+Fkjj9YbYJhXJEu2eyJ/W90xSFUyI/X7R0XfV52V94fRR7SL iEqfCEB/OtBoBSyYht39hodLIneZK34h4Iq+X9coRpE7eKIPBsNaMTeP+ozevn/ignELG4W29a2 mjaeiKVfF/7nPhQL9UoMEHYxxX6GPoOjfezfkef6wETGpWbY1SzuDt5Lg7yRbCsg1PUXtrKdNRU rn5EkAFxpIOIE6a5ceh5UENP6rhuTy2HDx7ArG4i3SDBuynpimsH8HH4d4WqDMRuT3Trjh9iFL2 DsiUw= X-Google-Smtp-Source: AGHT+IEXQHJ2iuWzbanMbzBKIkkScZjb4AQMH0rIFjIwH2Jy8Pls41UCGk5CiFwcm0mZJWEF90VR/g== X-Received: by 2002:a05:6512:158e:b0:592:f490:5bcc with SMTP id 2adb3069b0e04-592f4905dccmr488350e87.6.1761202801697; Thu, 23 Oct 2025 00:00:01 -0700 (PDT) Received: from [192.168.0.50] ([89.149.120.198]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-592f4d168bcsm491742e87.68.2025.10.23.00.00.00 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 23 Oct 2025 00:00:01 -0700 (PDT) Content-Type: multipart/alternative; boundary="------------vySgsWq5u6ExQwFnCymloIGZ" Message-ID: <927941c8-e5a1-4787-bbd9-88f0d92b55d0@gmail.com> Date: Thu, 23 Oct 2025 10:00:00 +0300 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: IO in wrong state on riscv64 To: Thomas Munro , Andres Freund Cc: pgsql-hackers , greg@burd.me References: <60bbebf4-0a80-4e5f-83c0-311c85f6bd5c@gmail.com> Content-Language: en-US From: Alexander Lakhin In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk This is a multi-part message in MIME format. --------------vySgsWq5u6ExQwFnCymloIGZ Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Hello Thomas, 23.10.2025 00:51, Thomas Munro wrote: > On a more practical note, Alexander, does this work? > > #if !defined(pg_read_barrier_impl) && defined(HAVE_GCC__ATOMIC_INT32_CAS) > /* acquire semantics include read barrier semantics */ > -# define pg_read_barrier_impl() > __atomic_thread_fence(__ATOMIC_ACQUIRE) > +# define pg_read_barrier_impl() do { > __atomic_signal_fence(__ATOMIC_ACQUIRE); > __atomic_thread_fence(__ATOMIC_ACQUIRE); } while (0) > #endif > > Someone might want to write an arch-riscv.h that spits out the asm > instead (should be just FENCE R, R and FENCE W, W as far as I can see, > which might be slightly better than what acquire/release generate, on > paper at least), but apparently this problem is wider than RISCV so we > need a general solution anyway. Thank you for working on this! Unfortunately, this change doesn't lead to change in disassembly of pgaio_io_wait(), produced with clang-19 -O1. That is, I'm getting the same disassembly as the one I sent you before (error/pgaio_io_wait.asm). I tried:  #if !defined(pg_read_barrier_impl) && defined(HAVE_GCC__ATOMIC_INT32_CAS)  /* acquire semantics include read barrier semantics */ -#              define pg_read_barrier_impl() __atomic_thread_fence(__ATOMIC_ACQUIRE) +#              define pg_read_barrier_impl()           do { } while (0)  #endif to make sure that the change of pg_read_barrier_impl() affects pgaio_io_wait() and really saw a difference in the disassembly. I haven't run tests with the modified version yet, going to test later just to be sure, but I suppose we want to see the binary code changed. Best regards, Alexander --------------vySgsWq5u6ExQwFnCymloIGZ Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 8bit
Hello Thomas,

23.10.2025 00:51, Thomas Munro wrote:
On a more practical note, Alexander, does this work?

 #if !defined(pg_read_barrier_impl) && defined(HAVE_GCC__ATOMIC_INT32_CAS)
 /* acquire semantics include read barrier semantics */
-#              define pg_read_barrier_impl()
__atomic_thread_fence(__ATOMIC_ACQUIRE)
+#              define pg_read_barrier_impl()           do {
__atomic_signal_fence(__ATOMIC_ACQUIRE);
__atomic_thread_fence(__ATOMIC_ACQUIRE); } while (0)
 #endif

Someone might want to write an arch-riscv.h that spits out the asm
instead (should be just FENCE R, R and FENCE W, W as far as I can see,
which might be slightly better than what acquire/release generate, on
paper at least), but apparently this problem is wider than RISCV so we
need a general solution anyway.

Thank you for working on this!

Unfortunately, this change doesn't lead to change in disassembly of
pgaio_io_wait(), produced with clang-19 -O1. That is, I'm getting the same
disassembly as the one I sent you before (error/pgaio_io_wait.asm).
I tried:
 #if !defined(pg_read_barrier_impl) && defined(HAVE_GCC__ATOMIC_INT32_CAS)
 /* acquire semantics include read barrier semantics */
-#              define pg_read_barrier_impl()           __atomic_thread_fence(__ATOMIC_ACQUIRE)
+#              define pg_read_barrier_impl()           do { } while (0)
 #endif
to make sure that the change of pg_read_barrier_impl() affects
pgaio_io_wait() and really saw a difference in the disassembly.

I haven't run tests with the modified version yet, going to test later
just to be sure, but I suppose we want to see the binary code changed.

Best regards,
Alexander
--------------vySgsWq5u6ExQwFnCymloIGZ--