From patchwork Thu May 26 14:25:50 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sasha Levin X-Patchwork-Id: 821052 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter2.kernel.org (8.14.4/8.14.3) with ESMTP id p4QEQVum026399 for ; Thu, 26 May 2011 14:26:31 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932686Ab1EZO0U (ORCPT ); Thu, 26 May 2011 10:26:20 -0400 Received: from mail-ww0-f44.google.com ([74.125.82.44]:62634 "EHLO mail-ww0-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932563Ab1EZO0Q (ORCPT ); Thu, 26 May 2011 10:26:16 -0400 Received: by mail-ww0-f44.google.com with SMTP id 36so831594wwa.1 for ; Thu, 26 May 2011 07:26:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:from:to:cc:subject:date:message-id:x-mailer :in-reply-to:references; bh=EhBitv5vK6QRgXIhskEFsYdjIG0BBfy1chUcOyxLWW4=; b=i/s4Y+NdXDzZjtqWGaoDKCCCJFdKR9E2E0vtQQ5KHN5UNceyqHKKQ8IeumOq2uJSc4 InJo9TnfgvMQMugQWIiDemqhTuNsYtAorlryuRosAGwsT1CmA1UvXhp7GhKxSTYCgToc V09T8o0bGVBPULYbQ5PcJfBcxGOyzvIGorv4g= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; b=rvI20Peaje53pFWV128HlC4nS0OWM6rvljEwgw87bNZ1wNFSJFuugzN9Bk2FREqDV1 EHECZ5+wgSdLZvXxd3P9DruAZT5d4633ibue8CqkhbvBjQiD8YTUhyKXloD/aEJrYHuK Awci8Tsvt/qbhL4PM4dFW9Jp/lw2hNgIoSR6E= Received: by 10.227.60.78 with SMTP id o14mr947670wbh.12.1306419975943; Thu, 26 May 2011 07:26:15 -0700 (PDT) Received: from localhost.localdomain ([109.66.201.145]) by mx.google.com with ESMTPS id ej7sm506307wbb.19.2011.05.26.07.26.14 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 26 May 2011 07:26:15 -0700 (PDT) From: Sasha Levin To: penberg@kernel.org Cc: john@jfloren.net, kvm@vger.kernel.org, mingo@elte.hu, asias.hejun@gmail.com, gorcunov@gmail.com, prasadjoshi124@gmail.com, Sasha Levin Subject: [PATCH 6/6] kvm tools: Protect IOPORT tree by rwsem Date: Thu, 26 May 2011 17:25:50 +0300 Message-Id: <1306419950-19064-6-git-send-email-levinsasha928@gmail.com> X-Mailer: git-send-email 1.7.5.rc3 In-Reply-To: <1306419950-19064-1-git-send-email-levinsasha928@gmail.com> References: <1306419950-19064-1-git-send-email-levinsasha928@gmail.com> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter2.kernel.org [140.211.167.43]); Thu, 26 May 2011 14:26:31 +0000 (UTC) Makes ioport thread-safe. Signed-off-by: Sasha Levin --- tools/kvm/ioport.c | 7 +++++++ 1 files changed, 7 insertions(+), 0 deletions(-) diff --git a/tools/kvm/ioport.c b/tools/kvm/ioport.c index 1f13960..db9ff0f 100644 --- a/tools/kvm/ioport.c +++ b/tools/kvm/ioport.c @@ -3,6 +3,7 @@ #include "kvm/kvm.h" #include "kvm/util.h" #include "kvm/rbtree-interval.h" +#include "kvm/rwsem.h" #include /* for KVM_EXIT_* */ #include @@ -22,6 +23,7 @@ struct ioport_entry { static struct rb_root ioport_tree = RB_ROOT; bool ioport_debug; +static DECLARE_RWSEM(ioport_tree_sem); static struct ioport_entry *ioport_search(struct rb_root *root, u64 addr) { @@ -71,6 +73,7 @@ void ioport__register(u16 port, struct ioport_operations *ops, int count) { struct ioport_entry *entry; + down_write(&ioport_tree_sem); entry = ioport_search(&ioport_tree, port); if (entry) { pr_warning("ioport re-registered: %x", port); @@ -87,6 +90,8 @@ void ioport__register(u16 port, struct ioport_operations *ops, int count) }; ioport_insert(&ioport_tree, entry); + + up_write(&ioport_tree_sem); } static const char *to_direction(int direction) @@ -108,7 +113,9 @@ bool kvm__emulate_io(struct kvm *kvm, u16 port, void *data, int direction, int s bool ret; struct ioport_entry *entry; + down_read(&ioport_tree_sem); entry = ioport_search(&ioport_tree, port); + up_read(&ioport_tree_sem); if (!entry) goto error;