From owner-freebsd-current@FreeBSD.ORG Tue Jun 3 10:20:29 2003 Return-Path: Delivered-To: freebsd-current@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 0617A37B401; Tue, 3 Jun 2003 10:20:29 -0700 (PDT) Received: from harmony.village.org (rover.bsdimp.com [204.144.255.66]) by mx1.FreeBSD.org (Postfix) with ESMTP id 0B62243F3F; Tue, 3 Jun 2003 10:20:28 -0700 (PDT) (envelope-from imp@bsdimp.com) Received: from localhost (warner@rover2.village.org [10.0.0.1]) by harmony.village.org (8.12.8/8.12.3) with ESMTP id h53HKMkA014884; Tue, 3 Jun 2003 11:20:23 -0600 (MDT) (envelope-from imp@bsdimp.com) Date: Tue, 03 Jun 2003 11:19:56 -0600 (MDT) Message-Id: <20030603.111956.46316212.imp@bsdimp.com> To: paul@freebsd-services.com From: "M. Warner Losh" In-Reply-To: <20030603155157.GH35187@survey.codeburst.net> References: <20030603134717.GD35187@survey.codeburst.net> <20030603.085659.13314075.imp@bsdimp.com> <20030603155157.GH35187@survey.codeburst.net> X-Mailer: Mew version 2.1 on Emacs 21.3 / Mule 5.0 (SAKAKI) Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit cc: hmp@freebsd.org cc: current@freebsd.org cc: des@freebsd.org Subject: Re: VFS: C99 sparse format for struct vfsops X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 03 Jun 2003 17:20:29 -0000 In message: <20030603155157.GH35187@survey.codeburst.net> Paul Richards writes: : I'm not sure that kobj actually needs to be MP safe if the kobj : struct is always embedded in a structure at a higher level i.e. : a use of kobj in say the device driver code will not interact with : it's use by say the linker code so the locking can be done on device : driver or linker level structs. Lock lock data, not code. The kobj dispatch tables are shared between all instances of the object. So if you have two instances of the driver, the driver locks protect softc for that driver. However, both softc's reference the kobj structures, directly or indirectly, that are not MP safe. If instance 1 takes out a lock, that doesn't prevent instance 2 from getting screwed by the following code: #define KOBJOPLOOKUP(OPS,OP) do { \ kobjop_desc_t _desc = &OP##_##desc; \ kobj_method_t *_ce = \ &OPS->cache[_desc->id & (KOBJ_CACHE_SIZE-1)]; \ if (_ce->desc != _desc) { \ KOBJOPMISS; \ [1] kobj_lookup_method(OPS->cls->methods, _ce, _desc); \ } else { \ KOBJOPHIT; \ } \ [2] _m = _ce->func; \ } while(0) Notice how OPS has a cache array. If instance 1 is calling the same ID as instance 2, modulo KOBJ_CACHE_SIZE, then a collision occurs and a race happens betwen [1] and [2]: thread 1 thread 2 _ce = ... _ce = ... HIT MISS set's *_ce via kobj_lookup_method _m gets set _m called _m set _m called Notice how thread 1's _m gets set based on the results of the kobj lookup, and we have a race, even if thread1 and thread2 took out their driver instance locks. Warner