Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S262937AbTH1Buo (ORCPT ); Wed, 27 Aug 2003 21:50:44 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S263415AbTH1Buo (ORCPT ); Wed, 27 Aug 2003 21:50:44 -0400 Received: from mail.jlokier.co.uk ([81.29.64.88]:25222 "EHLO mail.jlokier.co.uk") by vger.kernel.org with ESMTP id S262937AbTH1Bun (ORCPT ); Wed, 27 Aug 2003 21:50:43 -0400 Date: Thu, 28 Aug 2003 02:50:27 +0100 From: Jamie Lokier To: Timo Sirainen Cc: root@chaos.analogic.com, Martin Konold , linux-kernel@vger.kernel.org Subject: Re: Lockless file reading Message-ID: <20030828015027.GA4715@mail.jlokier.co.uk> References: <20030827233903.GB3759@mail.jlokier.co.uk> <1062031942.1454.147.camel@hurina> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1062031942.1454.147.camel@hurina> User-Agent: Mutt/1.4.1i Sender: linux-kernel-owner@vger.kernel.org X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1115 Lines: 29 Timo Sirainen wrote: > checksum[0]++; > xor = buf[0] ^ checksum[0]; Your algorithm isn't going to work if the new value of xor is the same as the old value of xor. > do { > memcpy(copy, buf, size*2); > } while (!verify(copy, size)); > memcpy(data, copy, size); It isn't safe because the memcpy() can read writes done on another processor out of order, and xor does not always change. You can read some of the newly written bytes in both the buf[] and checksum[] halves of the buffer, while reading some of the previous bytes in each half. If the set of new bytes in the first half matches the set in the second half well enough (i.e. the two sets match for bytes which aredifferent between the old and new data blocks), and the xor values are the same between the old and new data blocks, then your test will accept a mix of old and new data bytes. -- Jamie - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/