From mboxrd@z Thu Jan 1 00:00:00 1970 From: Ingo Molnar Subject: Re: [PATCH v2 8/8] kvm tools: Use brlock in MMIO and IOPORT Date: Mon, 30 May 2011 10:47:59 +0200 Message-ID: <20110530084759.GI30513@elte.hu> References: <1306744247-26051-1-git-send-email-levinsasha928@gmail.com> <1306744247-26051-8-git-send-email-levinsasha928@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Cc: penberg@kernel.org, kvm@vger.kernel.org, asias.hejun@gmail.com, gorcunov@gmail.com, prasadjoshi124@gmail.com To: Sasha Levin Return-path: Received: from mx3.mail.elte.hu ([157.181.1.138]:54865 "EHLO mx3.mail.elte.hu" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751961Ab1E3IsD (ORCPT ); Mon, 30 May 2011 04:48:03 -0400 Content-Disposition: inline In-Reply-To: <1306744247-26051-8-git-send-email-levinsasha928@gmail.com> Sender: kvm-owner@vger.kernel.org List-ID: * 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? > 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