Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1na9zy-00087B-AD for pgsql-hackers@arkaria.postgresql.org; Fri, 01 Apr 2022 05:39:02 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1na9zx-00026U-8a for pgsql-hackers@arkaria.postgresql.org; Fri, 01 Apr 2022 05:39:01 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1na9zw-00026K-Ca for pgsql-hackers@lists.postgresql.org; Fri, 01 Apr 2022 05:39:00 +0000 Received: from out1-smtp.messagingengine.com ([66.111.4.25]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1na9zt-0005Hi-Hr for pgsql-hackers@postgresql.org; Fri, 01 Apr 2022 05:39:00 +0000 Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.nyi.internal (Postfix) with ESMTP id 589295C0125; Fri, 1 Apr 2022 01:38:55 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute3.internal (MEProxy); Fri, 01 Apr 2022 01:38:55 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paquier.xyz; h= cc:cc:content-type:date:date:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:sender:subject :subject:to:to; s=fm1; bh=Vu0gZbYwEx8bNO59fhFuuqDHwtG15SguESmGZx f/nLg=; b=urqJWK5+qlpbhqveMsXFov1ElbTzHR8U6FRwDNBuGzWuEQBsWrzdmN JazPyCAzyyuf+ouDW9CghGfB+2xpVtfYI+g4+DfOBK9M7pCVoL6XletKNNEG12R/ WX8Bx25fAaHY8zyXK8iUiMVwlhwAowM+i2hS43IaE2NNVwjuUOAMzGAw8EGGq1RY ClzWAiN392e4O0wLqnBJjzzLDhdDaeq4CxZOiIVtL09IUmo/MLbGYuysqzAWdwHa 6NBVhHRqCfL3zr3vT3qpjfqJD3vLr7E6JTyw8hvNgkww+XxUC7+PDCH1lSluuMLZ zhqKQWINkCRMIqQtc6lw5h2kM+YXry7Q== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm3; bh=Vu0gZbYwEx8bNO59f hFuuqDHwtG15SguESmGZxf/nLg=; b=EC76W0B8yRJlXV3i/bLZy6JGeSF4cQFZN feWuXh9i1GQrvPNPjOvG4WN7OUeEgOA1QcmM7pUn/hazmjfVvVzlhZPmBmR/gjSo 0jDlcBaP7Qic2x9Bgm2YmsP1/XQwtAif0NTE1Qc1dlYYn1dQlyNHgNt5ek5x+Zao /ga0r6tsMtXv8Fhl0jeERHltgA7ekNRYdSVKpwmn1EQ6/RQhaGS249+Gn7sUypx7 Jc5nFhv+4QEeoMkBb3Yva7Jnv8Y4c3Fkyvc+HRN5VWgRcnyQObJghqvXaJam77MJ HL9Js7wcwdWgkIEPEUVSCZq9DC81h3vcq7mwEqAM+aWmds/OXFb+Q== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvvddrudeihedgleekucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne gfrhhlucfvnfffucdljedtmdenucfjughrpeffhffvuffkfhggtggujgesghdtreertddt vdenucfhrhhomhepofhitghhrggvlhcurfgrqhhuihgvrhcuoehmihgthhgrvghlsehprg hquhhivghrrdighiiiqeenucggtffrrghtthgvrhhnpedvgeduuefhtdeuleettdevjeeh heeiveeuieegleetgeeljeelieeuieehgeevhfenucevlhhushhtvghrufhiiigvpedtne curfgrrhgrmhepmhgrihhlfhhrohhmpehmihgthhgrvghlsehprghquhhivghrrdighiii X-ME-Proxy: Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 1 Apr 2022 01:38:54 -0400 (EDT) Date: Fri, 1 Apr 2022 14:38:51 +0900 From: Michael Paquier To: Matthias van de Meent Cc: PostgreSQL Hackers Subject: Re: Preventing indirection for IndexPageGetOpaque for known-size page special areas Message-ID: References: MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="G806gToVJUOclRG4" Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --G806gToVJUOclRG4 Content-Type: multipart/mixed; boundary="2tb1raO4Nn03KMxM" Content-Disposition: inline --2tb1raO4Nn03KMxM Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Thu, Mar 31, 2022 at 12:09:35PM +0200, Matthias van de Meent wrote: > PageInit MAXALIGNs the size of the special area that it receives as an > argument; so any changes to the page header that would misalign the > value would be AM-specific; in which case it is quite unlikely that > this is the right accessor for your page's special area. Right. I'd still be tempted to keep that per-AM rather than making the checks deeper with one extra macro layer in the page header or with a different macro that would depend on the opaque type, though. Like in the attached, for example. -- Michael --2tb1raO4Nn03KMxM Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="opaque-macros.patch" Content-Transfer-Encoding: quoted-printable diff --git a/src/include/access/ginblock.h b/src/include/access/ginblock.h index 9347f464f3..050fff80dc 100644 --- a/src/include/access/ginblock.h +++ b/src/include/access/ginblock.h @@ -108,7 +108,11 @@ typedef struct GinMetaPageData /* * Macros for accessing a GIN index page's opaque data */ -#define GinPageGetOpaque(page) ( (GinPageOpaque) PageGetSpecialPointer(pag= e) ) +#define GinPageGetOpaque(page) \ +( \ + AssertMacro(PageGetSpecialSize(page) =3D=3D MAXALIGN(sizeof(GinPageOpaque= Data))), \ + (GinPageOpaque) PageGetSpecialPointer(page) \ +) =20 #define GinPageIsLeaf(page) ( (GinPageGetOpaque(page)->flags & GIN_LEAF= ) !=3D 0 ) #define GinPageSetLeaf(page) ( GinPageGetOpaque(page)->flags |=3D GIN_LE= AF ) diff --git a/src/include/access/gist.h b/src/include/access/gist.h index a3337627b8..a10caf8ae9 100644 --- a/src/include/access/gist.h +++ b/src/include/access/gist.h @@ -164,7 +164,11 @@ typedef struct GISTENTRY bool leafkey; } GISTENTRY; =20 -#define GistPageGetOpaque(page) ( (GISTPageOpaque) PageGetSpecialPointer(p= age) ) +#define GistPageGetOpaque(page) \ +( \ + AssertMacro(PageGetSpecialSize(page) =3D=3D MAXALIGN(sizeof(GISTPageOpaqu= eData))), \ + (GISTPageOpaque) PageGetSpecialPointer(page) \ +) =20 #define GistPageIsLeaf(page) ( GistPageGetOpaque(page)->flags & F_LEAF) #define GIST_LEAF(entry) (GistPageIsLeaf((entry)->page)) diff --git a/src/include/access/hash.h b/src/include/access/hash.h index da372841c4..b442ddc4c8 100644 --- a/src/include/access/hash.h +++ b/src/include/access/hash.h @@ -85,7 +85,11 @@ typedef struct HashPageOpaqueData =20 typedef HashPageOpaqueData *HashPageOpaque; =20 -#define HashPageGetOpaque(page) ((HashPageOpaque) PageGetSpecialPointer(pa= ge)) +#define HashPageGetOpaque(page) \ +( \ + AssertMacro(PageGetSpecialSize(page) =3D=3D MAXALIGN(sizeof(HashPageOpaqu= eData))), \ + (HashPageOpaque) PageGetSpecialPointer(page) \ +) =20 #define H_NEEDS_SPLIT_CLEANUP(opaque) (((opaque)->hasho_flag & LH_BUCKET_N= EEDS_SPLIT_CLEANUP) !=3D 0) #define H_BUCKET_BEING_SPLIT(opaque) (((opaque)->hasho_flag & LH_BUCKET_BE= ING_SPLIT) !=3D 0) diff --git a/src/include/access/nbtree.h b/src/include/access/nbtree.h index 93f8267b48..e11839857d 100644 --- a/src/include/access/nbtree.h +++ b/src/include/access/nbtree.h @@ -70,7 +70,11 @@ typedef struct BTPageOpaqueData =20 typedef BTPageOpaqueData *BTPageOpaque; =20 -#define BTPageGetOpaque(page) ((BTPageOpaque) PageGetSpecialPointer(page)) +#define BTPageGetOpaque(page) \ +( \ + AssertMacro(PageGetSpecialSize(page) =3D=3D MAXALIGN(sizeof(BTPageOpaqueD= ata))), \ + (BTPageOpaque) PageGetSpecialPointer(page) \ +) =20 /* Bits defined in btpo_flags */ #define BTP_LEAF (1 << 0) /* leaf page, i.e. not internal page */ diff --git a/src/include/access/spgist_private.h b/src/include/access/spgis= t_private.h index eb56b1c6b8..d61433b5af 100644 --- a/src/include/access/spgist_private.h +++ b/src/include/access/spgist_private.h @@ -75,7 +75,12 @@ typedef SpGistPageOpaqueData *SpGistPageOpaque; #define SPGIST_LEAF (1<<2) #define SPGIST_NULLS (1<<3) =20 -#define SpGistPageGetOpaque(page) ((SpGistPageOpaque) PageGetSpecialPointe= r(page)) +#define SpGistPageGetOpaque(page) \ +( \ + AssertMacro(PageGetSpecialSize(page) =3D=3D MAXALIGN(sizeof(SpGistPageOpa= queData))), \ + (SpGistPageOpaque) PageGetSpecialPointer(page) \ +) + #define SpGistPageIsMeta(page) (SpGistPageGetOpaque(page)->flags & SPGIST_= META) #define SpGistPageIsDeleted(page) (SpGistPageGetOpaque(page)->flags & SPGI= ST_DELETED) #define SpGistPageIsLeaf(page) (SpGistPageGetOpaque(page)->flags & SPGIST_= LEAF) --2tb1raO4Nn03KMxM-- --G806gToVJUOclRG4 Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEG72nH6vTowiyblFKnvQgOdbyQH0FAmJGj+sACgkQnvQgOdby QH0GrA//Zy1eENBAOfzxmCFIosPHdN+fzoNcHODzcCdPG0z5YHc3L9toexe0Fvcl jqrKCBWQ/DlVhg3cRk6/WID6R52eW7VvkZSyrOJhmcCladxndWgr9aHOsU7Xlwqj Nvh0jK4jicTc7HhpYAQRpFkqt8H0wGPrwNRO+FahHDpxPDo2dHaLs/u0/bMQOHqd Hu9wKvY2lVo4rBDPxF3NtKbnV4a7hE04f9BsefLJ6CYrBPSIMdBfk/Sn/sG83Ocb PsO3lL7bJGFX6QEJHnNW6eNj2PKXa72VYQqdm9wYnUebu4FtJRrt33Nu3e9SEzwY opMP+TASrq7VOyP3N7bFpjEbgg1Q9JSqLxPp9Xjuxo6E0t/7zF/w/OqTbdXARCBh djK8uDnJwWsWM8+9yrFTy7MHzL/mcwQx5BNRtmsum/8iM+c6vpujDZEgFcrFC5IP SNXOihyzvHAyx7pk1y21Obp31oSivOatGTdFPEj8Ws4JOW0o789cBc8U85wJXYGE 6a3tmh0krnQU9cAD44Mx51gbbdDsAYfMcm41P8yxhEdFTH8o558Fv3EM4AdEj7i3 qoHxN/6YTdNrUR1DStT7uxer9NLvyvoCkmQ1Ju8qWJyeATyq23TDMaemUlQw1sDu 6JqMFWUqaOIjGYrbVMGT43oN1D491wKegmr+dB5tTK52X37RKYw= =cOwr -----END PGP SIGNATURE----- --G806gToVJUOclRG4--