pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Christoph Berg <myon@debian.org>
Cc: Andres Freund <andres@anarazel.de>
Cc: PostgreSQL Bugs <pgsql-bugs@postgresql.org>
Subject: Re: Bus error in pg_logical_slot_get_changes (9.4.7, sparc)
Date: Thu, 14 Apr 2016 15:14:37 -0400
Message-ID: <15040.1460661277@sss.pgh.pa.us> (raw)
In-Reply-To: <20160414183602.GA22486@msg.df7cb.de>
References: <20160413211152.GA21711@msg.credativ.de>
	<20160413175827.dmlbtdf7c3mgmnex@alap3.anarazel.de>
	<20160414092919.GA11804@msg.df7cb.de>
	<20160414112518.GE11804@msg.df7cb.de>
	<423.1460653903@sss.pgh.pa.us>
	<20160414183602.GA22486@msg.df7cb.de>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>

Christoph Berg <myon@debian.org> writes:
> Re: Tom Lane 2016-04-14 <423.1460653903@sss.pgh.pa.us>
>> Proposed patch attached, but I'm still wondering why the alignment-picky
>> buildfarm members aren't all failing on this.  It seems to strongly
>> suggest that the regression tests' coverage is lacking here.

> This patch works both on sparc and amd64.  Thanks!
> (Tested on 9.4.7 only.)

I've been looking around and testing some more.  I noticed that the only
caller of ReorderBufferRestoreChange always passes a maxaligned buffer,
so most of the changes I suggested are unnecessary.  AFAICT, it's only
the second fetch of t_len that is at any risk.  Even there, at least in
HEAD, I cannot construct a test case in which the first tuple's t_len is
not a multiple of 4.  It's hard to tell what is causing that, because
surely heap_form_tuple guarantees no such thing.  I have a suspicion that
something in the impenetrable thicket that passes for prefix/suffix
optimization in log_heap_update is forcing the WAL-logged tuple length to
be rounded off to sizeof(int) (*not* MAXALIGN).

It might be that 9.4 acts differently here, but the lack of crashes in our
buildfarm suggests otherwise.  The best theory I can come up with is that
somehow, your Sparc compiler is deciding that "data" is 8-aligned at this
point and generating a code sequence that depends on that, even though
it's only being asked to fetch a uint32.  If the machine were a 64-bit
machine, the compiler could legitimately make such a deduction because of
the presence of a pointer field in HeapTupleData; but I dunno how it gets
to that conclusion if the architecture is 32-bit.  Anyway, there are few
enough architectures where it could make sense to use an 8-aligned
instruction to fetch a 4-byte value that it's not so surprising we've not
seen it crash elsewhere.

So I now think my previous patch is overkill, and we should instead use
something like the attached.

			regards, tom lane

-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs

Attachments:

alignment-fix-2.patch (text/x-diff, 1.9K) download diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 52c6986..4520708 100644 *** a/src/backend/replication/logical/reorderbuffer.c --- b/src/backend/replication/logical/reorderbuffer.c *************** ReorderBufferRestoreChanges(ReorderBuffe *** 2444,2449 **** --- 2444,2453 ---- /* * Convert change from its on-disk format to in-memory format and queue it onto * the TXN's ->changes list. + * + * Note: although "data" is declared char*, at entry it points to a + * maxalign'd buffer, making it safe in most of this function to assume + * that the pointed-to data is suitably aligned for direct access. */ static void ReorderBufferRestoreChange(ReorderBuffer *rb, ReorderBufferTXN *txn, *************** ReorderBufferRestoreChange(ReorderBuffer *** 2471,2477 **** case REORDER_BUFFER_CHANGE_INTERNAL_SPEC_INSERT: if (change->data.tp.oldtuple) { ! Size tuplelen = ((HeapTuple) data)->t_len; change->data.tp.oldtuple = ReorderBufferGetTupleBuf(rb, tuplelen - SizeofHeapTupleHeader); --- 2475,2481 ---- case REORDER_BUFFER_CHANGE_INTERNAL_SPEC_INSERT: if (change->data.tp.oldtuple) { ! uint32 tuplelen = ((HeapTuple) data)->t_len; change->data.tp.oldtuple = ReorderBufferGetTupleBuf(rb, tuplelen - SizeofHeapTupleHeader); *************** ReorderBufferRestoreChange(ReorderBuffer *** 2492,2498 **** if (change->data.tp.newtuple) { ! Size tuplelen = ((HeapTuple) data)->t_len; change->data.tp.newtuple = ReorderBufferGetTupleBuf(rb, tuplelen - SizeofHeapTupleHeader); --- 2496,2506 ---- if (change->data.tp.newtuple) { ! /* here, data might not be suitably aligned! */ ! uint32 tuplelen; ! ! memcpy(&tuplelen, data + offsetof(HeapTupleData, t_len), ! sizeof(uint32)); change->data.tp.newtuple = ReorderBufferGetTupleBuf(rb, tuplelen - SizeofHeapTupleHeader);

view thread (15+ messages)  latest in thread

Message-ID: <15040.1460661277@sss.pgh.pa.us>
Permalink:  ../15040.1460661277@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/15040.1460661277@sss.pgh.pa.us

 ·  · 

reply

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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: tgl@sss.pgh.pa.us, myon@debian.org, andres@anarazel.de
  Subject: Re: Bus error in pg_logical_slot_get_changes (9.4.7, sparc)
  In-Reply-To: <15040.1460661277@sss.pgh.pa.us>
  References: <20160413211152.GA21711@msg.credativ.de> <20160413175827.dmlbtdf7c3mgmnex@alap3.anarazel.de> <20160414092919.GA11804@msg.df7cb.de> <20160414112518.GE11804@msg.df7cb.de> <423.1460653903@sss.pgh.pa.us> <20160414183602.GA22486@msg.df7cb.de> <15040.1460661277@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