From mboxrd@z Thu Jan 1 00:00:00 1970 From: Sasha Levin Subject: Re: [PATCH v2 8/8] kvm tools: Use brlock in MMIO and IOPORT Date: Mon, 30 May 2011 11:56:56 +0300 Message-ID: <1306745816.14564.43.camel@lappy> References: <1306744247-26051-1-git-send-email-levinsasha928@gmail.com> <1306744247-26051-8-git-send-email-levinsasha928@gmail.com> <20110530084759.GI30513@elte.hu> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Cc: penberg@kernel.org, kvm@vger.kernel.org, asias.hejun@gmail.com, gorcunov@gmail.com, prasadjoshi124@gmail.com To: Ingo Molnar Return-path: Received: from mail-ww0-f44.google.com ([74.125.82.44]:47900 "EHLO mail-ww0-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753320Ab1E3I5Z (ORCPT ); Mon, 30 May 2011 04:57:25 -0400 Received: by wwa36 with SMTP id 36so3696292wwa.1 for ; Mon, 30 May 2011 01:57:24 -0700 (PDT) In-Reply-To: <20110530084759.GI30513@elte.hu> Sender: kvm-owner@vger.kernel.org List-ID: On Mon, 2011-05-30 at 10:47 +0200, Ingo Molnar wrote: > * Sasha Levin wrote: > > > @@ -55,41 +56,53 @@ static const char *to_direction(u8 is_write) > > bool kvm__register_mmio(u64 phys_addr, u64 phys_addr_len, void (*kvm_mmio_callback_fn)(u64 addr, u8 *data, u32 len, u8 is_write)) > > { > > struct mmio_mapping *mmio; > > + int ret; > > > > mmio = malloc(sizeof(*mmio)); > > if (mmio == NULL) > > return false; > > > > + br_write_lock(); > > *mmio = (struct mmio_mapping) { > > .node = RB_INT_INIT(phys_addr, phys_addr + phys_addr_len), > > .kvm_mmio_callback_fn = kvm_mmio_callback_fn, > > }; > > The initialization here does not use any global state AFAICS so it > does not need the write lock, right? > > > > > - return mmio_insert(&mmio_tree, mmio); > > + ret = mmio_insert(&mmio_tree, mmio); > > + br_write_unlock(); > > Shouldnt mmio_insert() thus have the write_lock()/unlock() sequence? Yes, the lock can be reduced to just the insert. > > bool kvm__deregister_mmio(u64 phys_addr) > > { > > struct mmio_mapping *mmio; > > > > + br_write_lock(); > > mmio = mmio_search_single(&mmio_tree, phys_addr); > > if (mmio == NULL) > > return false; > > Here we leak the write lock! > > > bool kvm__emulate_mmio(struct kvm *kvm, u64 phys_addr, u8 *data, u32 len, u8 is_write) > > { > > - struct mmio_mapping *mmio = mmio_search(&mmio_tree, phys_addr, len); > > + struct mmio_mapping *mmio; > > + > > + br_read_lock(); > > + mmio = mmio_search(&mmio_tree, phys_addr, len); > > > > if (mmio) > > mmio->kvm_mmio_callback_fn(phys_addr, data, len, is_write); > > else > > fprintf(stderr, "Warning: Ignoring MMIO %s at %016llx (length %u)\n", > > to_direction(is_write), phys_addr, len); > > + br_read_unlock(); > > > > return true; > > } > > Yummie, scalability here we come! :-) > > Thanks, > > Ingo -- Sasha.