From patchwork Wed Mar 24 21:24:11 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcelo Tosatti X-Patchwork-Id: 88069 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter.kernel.org (8.14.3/8.14.3) with ESMTP id o2OLUIwt014470 for ; Wed, 24 Mar 2010 21:30:19 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753524Ab0CXV3m (ORCPT ); Wed, 24 Mar 2010 17:29:42 -0400 Received: from mx1.redhat.com ([209.132.183.28]:39904 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753185Ab0CXV3V (ORCPT ); Wed, 24 Mar 2010 17:29:21 -0400 Received: from int-mx05.intmail.prod.int.phx2.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.18]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o2OLTLvD019042 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Wed, 24 Mar 2010 17:29:21 -0400 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx05.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o2OLTKDG029298; Wed, 24 Mar 2010 17:29:21 -0400 Received: from amt.cnet (vpn-10-46.rdu.redhat.com [10.11.10.46]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id o2OLTJV7008892; Wed, 24 Mar 2010 17:29:20 -0400 Received: from amt.cnet (amt.cnet [127.0.0.1]) by amt.cnet (Postfix) with ESMTP id C8EF368AC67; Wed, 24 Mar 2010 18:28:12 -0300 (BRT) Received: (from marcelo@localhost) by amt.cnet (8.14.3/8.14.3/Submit) id o2OLSBCw022413; Wed, 24 Mar 2010 18:28:11 -0300 Message-Id: <20100324212725.912860027@amt.cnet> User-Agent: quilt/0.47-1 Date: Wed, 24 Mar 2010 18:24:11 -0300 From: Marcelo Tosatti To: kvm@vger.kernel.org Cc: Marcelo Tosatti Subject: [patch 3/8] test: protect fwcfg accesses with lock References: <20100324212408.790319364@amt.cnet> Content-Disposition: inline; filename=fwcfg-lock X-Scanned-By: MIMEDefang 2.67 on 10.5.11.18 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.3 (demeter.kernel.org [140.211.167.41]); Wed, 24 Mar 2010 21:30:19 +0000 (UTC) Index: qemu-kvm/kvm/user/test/lib/x86/fwcfg.c =================================================================== --- qemu-kvm.orig/kvm/user/test/lib/x86/fwcfg.c +++ qemu-kvm/kvm/user/test/lib/x86/fwcfg.c @@ -1,4 +1,7 @@ #include "fwcfg.h" +#include "smp.h" + +static struct spinlock lock; uint64_t fwcfg_get_u(uint16_t index, int bytes) { @@ -6,11 +9,13 @@ uint64_t fwcfg_get_u(uint16_t index, int uint8_t b; int i; + spin_lock(&lock); asm volatile ("out %0, %1" : : "a"(index), "d"((uint16_t)BIOS_CFG_IOPORT)); for (i = 0; i < bytes; ++i) { asm volatile ("in %1, %0" : "=a"(b) : "d"((uint16_t)(BIOS_CFG_IOPORT + 1))); r |= (uint64_t)b << (i * 8); } + spin_unlock(&lock); return r; }