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 1nYh4K-0006UV-Sp for pgsql-hackers@arkaria.postgresql.org; Mon, 28 Mar 2022 04:33:29 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1nYh4J-00045F-O3 for pgsql-hackers@arkaria.postgresql.org; Mon, 28 Mar 2022 04:33:27 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nYh4H-000456-Sw for pgsql-hackers@lists.postgresql.org; Mon, 28 Mar 2022 04:33:27 +0000 Received: from wout3-smtp.messagingengine.com ([64.147.123.19]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nYh4A-0005z8-4J for pgsql-hackers@postgresql.org; Mon, 28 Mar 2022 04:33:24 +0000 Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.west.internal (Postfix) with ESMTP id B8C0A3200D98; Mon, 28 Mar 2022 00:33:16 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute5.internal (MEProxy); Mon, 28 Mar 2022 00:33:16 -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=qEP+DYBLyKWLnR2xRytB5wASH/26L1PFlKakoW K/RhQ=; b=Q6hDmtEWarsDpnpRKYdh/nWKWT2iOhwugH664ctkmunWWGNHDtBSWw uOhTWLsBIOc0CDDKjy74WhwUchIYsKuATbxF4JF83oVoRvlpScJ3rcLbxpSEqO/+ z0gLNnd4zuQa0VHPbPhdakfKBohdZ0HrwP0/etG2Vvpfn9GZQ0ebkSZkIBxAfK79 punntxLUYMxFgITG8c7w9e45Wysz5lZvc4QlTELdQN/HSIZszRZ13tO64qcY+QtG 6KZAG8YGFophmi44IeqHIkGdnL9xHknwXVFyo36HlAWh18Sz6TB++t5D+7aLb/Lo FRrfqPc/LDqaObsi+l56tqoOoLebdJZw== 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=qEP+DYBLyKWLnR2xR ytB5wASH/26L1PFlKakoWK/RhQ=; b=Kpzcnk8ARJo3GDMCnyJ9BIRKDUVOIquEp D5kxO3WpYeDat7+lPGanoRqND9KyKtsba1vVikjjhGs2gjQV25a9SQOnfztU3rvu 6Ve5n1kwoD4YmIPY7jZ/CBAkq97O1Tm5bNapknm2er6IpKouW32vZHKggthj710L 7ea9G2dGkeBqcnChPkGpZybIJGziMuvIw/Kxa5X4U5l9cQZjuCbTPDwdvE4k/z/G XuHRU8hvzykh8E2PtiqCEbl3SDk5qL0MJmgJ6F/WA1vFDw0OQXw84IEE4+lW/1wT 8/6N0+y+TyAHawFNMtx66uyFL7Ty0dZRX7vuM/9R4oOk/2xj1tWZg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvvddrudehiedgkeehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne gfrhhlucfvnfffucdljedtmdenucfjughrpeffhffvuffkfhggtggujgesghdtreertddt vdenucfhrhhomhepofhitghhrggvlhcurfgrqhhuihgvrhcuoehmihgthhgrvghlsehprg hquhhivghrrdighiiiqeenucggtffrrghtthgvrhhnpedvgeduuefhtdeuleettdevjeeh heeiveeuieegleetgeeljeelieeuieehgeevhfenucevlhhushhtvghrufhiiigvpedtne curfgrrhgrmhepmhgrihhlfhhrohhmpehmihgthhgrvghlsehprghquhhivghrrdighiii X-ME-Proxy: Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 28 Mar 2022 00:31:39 -0400 (EDT) Date: Mon, 28 Mar 2022 13:31:16 +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="4HkTsHVIsffrlys8" Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --4HkTsHVIsffrlys8 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Wed, Feb 16, 2022 at 10:24:58PM +0100, Matthias van de Meent wrote: > A first good reason to do this is preventing further damage when a > page is corrupted: if I can somehow overwrite pd_special, > non-assert-enabled builds would start reading and writing at arbitrary > offsets from the page pointer, quite possibly in subsequent buffers > (or worse, on the stack, in case of stack-allocated blocks). Well, pageinspect has proved to be rather careless in this area for a couple of years, but this just came from the fact that we called PageGetSpecialPointer() before checking that PageGetSpecialSize() maps with the MAXALIGN'd size of the opaque area, if the related AM has one. I am not sure that we need to worry about corruptions, as data checksums would offer protection for most cases users usually need to worry about, at the exception of page corruptions because of memory for pages already read in the PG shared buffers from disk or even the OS cache. > A second reason would be less indirection to get to the opaque > pointer. This should improve performance a bit in those cases where we > (initially) only want to access the [Index]PageOpaque struct. We don't have many cases that do that, do we? > Lastly, 0002 and 0003 remove some repetitive tasks of dealing with the > [nbtree, hash] opaques by providing a typed accessor macro similar to > what is used in the GIN and (SP-)GIST index methods; improving the > legibility of the code and decreasing the churn. +#define PageGetSpecialOpaque(page, OpaqueDataTyp) \ +( \ + AssertMacro(PageGetPageSize(page) == BLCKSZ && \ + PageGetSpecialSize(page) == MAXALIGN(sizeof(OpaqueDataTyp))), \ + (OpaqueDataTyp *) ((char *) (page) + (BLCKSZ - MAXALIGN(sizeof(OpaqueDataTyp)))) \ +) Did you notice PageValidateSpecialPointer() that mentions MSVC? Could this stuff a problem if not an inline function. Perhaps you should do a s/OpaqueDataTyp/OpaqueDataType/. As a whole, this patch set looks like an improvement in terms of checks and consistency regarding the special area handling across the different AMs for the backend code, while reducing the MAXALIGN-ism on all those sizes, and this tends to be missed. Any other opinions? -- Michael --4HkTsHVIsffrlys8 Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEG72nH6vTowiyblFKnvQgOdbyQH0FAmJBOhQACgkQnvQgOdby QH2jIw/+OsnNiI78i9hJVdKxU2/Twu7gZf42kXjf8ACtVRTn3N7O0gVp5Gb4EJk5 0DRbp58gJtMP+yNOelAyS4e8US4p6ALVdLJVJ+6RR6i9Ql++LFZTu1dADAH5DfwU 5cFoYc/xd+fyijHgW5rvgO+4OK/fllm6pAodWtMC+R1xspPpaHezU3j/W8BpBohu pbsE6CUnIEwKswI9j8NFT48H/lrQCpl6z2a6SB6DkqWUfMPHmYWZGyk3ZqToJgNq ce9mYEsb+7tWz6vYQ5xs05RGWb1lrfSk2MOhTKeMRl06mYkJRSrEJFIuUtl73jW7 WVpxDHdcvUeri0E6mcmMaOlg9bK+auHGTYZFwaPOQLOZAjsyOZUZOUwZvscsc+Iy uYxyBZIm9yNTHExmAZrazwrkeBWMhvx+jEkoIurPBW8BHSL5COGAg5bi4xB3BK3t CzpRNekI0FaCZ2XrZMwyGvGd6+RxMZXeF4751VwVxahJ30VxwY2A0OwsVUvJxQgw dalPSLJ9UbP1VKU9OuVCHF6V0Z+9dVd4lG060G82G8H+6yFnkstOsuzDCeI1IrpO rLXP+MSYHSlxmLjlsMeCliUBJUruXd8e1ExGGOVXDLUTxJzcNlYPwI95ZCV8WcA6 nv9bMfIjty3+A33KT7Us7fiXDI98QVFhplpajXb6m98r/L1XUi4= =41lV -----END PGP SIGNATURE----- --4HkTsHVIsffrlys8--