From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1759981AbYDKNzy (ORCPT ); Fri, 11 Apr 2008 09:55:54 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1758765AbYDKNzp (ORCPT ); Fri, 11 Apr 2008 09:55:45 -0400 Received: from caffeine.csclub.uwaterloo.ca ([129.97.134.17]:60667 "EHLO caffeine.csclub.uwaterloo.ca" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1758425AbYDKNzo (ORCPT ); Fri, 11 Apr 2008 09:55:44 -0400 Date: Fri, 11 Apr 2008 09:55:44 -0400 To: Bodo Eggert <7eggert@gmx.de> Cc: Diego Calleja , Jiri Kosina , Jan Kara , Michal Hocko , Meelis Roos , Linux Kernel list , linux-fsdevel@vger.kernel.org Subject: Re: file offset corruption on 32-bit machines? Message-ID: <20080411135544.GG2160@csclub.uwaterloo.ca> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.13 (2006-08-11) From: lsorense@csclub.uwaterloo.ca (Lennart Sorensen) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Apr 11, 2008 at 02:24:34PM +0200, Bodo Eggert wrote: > AS far as I understand, the race is e.g.: > > fpos := A:a, we want to make process/thread a read A:b or B:a without it > being a correct value in fpos. a!=b!=c, A!=B, A!=C. > > a: read fpos.high (A:?) > b: write fpos (B:b) > a: read fpos.low (A:b) > > > If you change this to > > a: read fpos.high > a: read fpos.low > a: read fpos.high > a: read fpos.low > > and compare the results, you need to > > a: read fpos.high (A:?) > b: write fpos (B:b) > a: read fpos.low (A:b) > b: write fpos (A:c) > a: read fpos.high (A:b),(A:?) > b: write fpos (C:b) > a: read fpos.low (A:b),(A:b) > > That would be winning three races in order to hit the bug. > > > OTOH, writers MUST NOT be interrupted, because: > > b: write fpos.high (B:a) > a: read fpos.high (B:?) > a: read fpos.low (B:a) > a: read fpos.high (B:a),(B:?) > a: read fpos.low (B:a),(B:a) > b: write fpos.low (B:b) So if you write multithreaded code and don't understand what locking around shared resources is for, then your application might break. Can you give an example where locking is being used correctly where this can possibly fail? The kernel can't prevent idiots from writing bad code that breaks. I just don't get this "problem". -- Len Sorensen