From: Tom Lane <tgl@sss.pgh.pa.us>
To: Dmitry Dolgov <9erthalion6@gmail.com>
Cc: Andres Freund <andres@anarazel.de>
Cc: Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
Cc: Michael Paquier <michael.paquier@gmail.com>
Cc: Vincent Lachenal <vincent.lachenal@gmail.com>
Cc: PostgreSQL mailing lists <pgsql-bugs@postgresql.org>
Subject: Re: [BUGS] BUG #14897: Segfault on statitics SQL request
Date: Mon, 13 Nov 2017 22:31:23 -0500
Message-ID: <17615.1510630283@sss.pgh.pa.us> (raw)
In-Reply-To: <10396.1510621709@sss.pgh.pa.us>
References: <20171110185747.31519.28038@wrigleys.postgresql.org>
<1415.1510340891@sss.pgh.pa.us>
<CAA2tJ7o-VK+ghsxifDAszFN5fikmG6U3sWHCEvc9nAVOypfjAw@mail.gmail.com>
<5652.1510344738@sss.pgh.pa.us>
<CAA2tJ7qsopt0hHbsm397H62LMsaE4hjRwaUu3FQdNgo5AYAGXA@mail.gmail.com>
<7710.1510346813@sss.pgh.pa.us>
<CAA2tJ7odG4KB=wvu_+5FfssxckbLTnEuR9C_TXRyeU_35z+CSA@mail.gmail.com>
<10197.1510349123@sss.pgh.pa.us>
<CAA2tJ7p72wbuHEzOA_g2V4YcmeDPHYKggenTR4dXG=kSpCiO8Q@mail.gmail.com>
<14075.1510352167@sss.pgh.pa.us>
<CA+q6zcXe9aV5NV88u9Y=vMp+=fP7QOXgTyFQhzuvmCvTBvb_kQ@mail.gmail.com>
<17617.1510355215@sss.pgh.pa.us>
<CAB7nPqR7mWvtnALZF93oez_v03NFCJ8dXP9CNicaUDv3KjDbYw@mail.gmail.com>
<3192.1510508352@sss.pgh.pa.us>
<CAB7nPqReMmn3Pg942we4aK73SFSVamdM0SAUO0BZHcvzA71h+A@mail.gmail.com>
<CA+q6zcWnWYX0ArC6QYC3YeRk3WnsyuexV1FzqBuBpGqODEK3fQ@mail.gmail.com>
<10396.1510621709@sss.pgh.pa.us>
I wrote:
> So what I am now thinking is that the only practical answer is to stop
> gcc from believing that it is safe to use 16-aligned instructions on
> int128's. (Some reading on the net suggests that the actual performance
> penalty for that is minimal anyway on modern Intel chips.)
Concretely, the attached patch fixes it for me. I've verified by
examining the assembly code that this stops gcc from using movdqa or
movaps in numeric.c, except for one place where it apparently can
prove that it's dealing with a sufficiently-aligned local variable.
As I said before, I don't like moving the int128 typedefs into a section
where they don't belong, but that's just cosmetic --- this is good enough
for testing.
BTW, for me, gcc only seems to want to generate 16-aligned instructions
in functions used for parallel aggregation. That may explain why we've
not seen a report before: the vulnerable code exists in 9.6, but it's not
used by default, since parallelization isn't on by default.
regards, tom lane
Attachments:
[text/x-diff] int128-hack.patch (1.3K, ../17615.1510630283@sss.pgh.pa.us/2-int128-hack.patch)
download | inline diff:diff --git a/src/include/c.h b/src/include/c.hindex 852551c121..19574a1a16 100644--- a/src/include/c.h+++ b/src/include/c.h@@ -301,17 +301,6 @@ typedef unsigned long long int uint64;
#define UINT64_FORMAT "%" INT64_MODIFIER "u"
/*
- * 128-bit signed and unsigned integers- * There currently is only a limited support for the type. E.g. 128bit- * literals and snprintf are not supported; but math is.- */-#if defined(PG_INT128_TYPE)-#define HAVE_INT128-typedef PG_INT128_TYPE int128;-typedef unsigned PG_INT128_TYPE uint128;-#endif--/*
* stdint.h limits aren't guaranteed to be present and aren't guaranteed to
* have compatible types with our fixed width types. So just define our own.
*/
@@ -642,6 +631,25 @@ typedef NameData *Name;
#define pg_attribute_noreturn()
#endif
+/*+ * 128-bit signed and unsigned integers+ * There currently is only a limited support for the type. E.g. 128bit+ * literals and snprintf are not supported; but math is.+ */+#if defined(PG_INT128_TYPE)+#define HAVE_INT128+typedef PG_INT128_TYPE int128+#if defined(pg_attribute_aligned)+pg_attribute_aligned(MAXIMUM_ALIGNOF)+#endif+;+typedef unsigned PG_INT128_TYPE uint128+#if defined(pg_attribute_aligned)+pg_attribute_aligned(MAXIMUM_ALIGNOF)+#endif+;+#endif+
/*
* Forcing a function not to be inlined can be useful if it's the slow path of
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-bugs@postgresql.org
Cc: tgl@sss.pgh.pa.us, 9erthalion6@gmail.com, andres@anarazel.de, peter.eisentraut@2ndquadrant.com, michael.paquier@gmail.com, vincent.lachenal@gmail.com
Subject: Re: [BUGS] BUG #14897: Segfault on statitics SQL request
In-Reply-To: <17615.1510630283@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox