From patchwork Fri Apr 16 08:02:14 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gerd Hoffmann X-Patchwork-Id: 50327 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 79F51B7D61 for ; Fri, 16 Apr 2010 22:57:19 +1000 (EST) Received: from localhost ([127.0.0.1]:34985 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1O2l4X-0006KD-L2 for incoming@patchwork.ozlabs.org; Fri, 16 Apr 2010 08:55:01 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1O2l3G-0006Jv-RO for qemu-devel@nongnu.org; Fri, 16 Apr 2010 08:53:42 -0400 Received: from [140.186.70.92] (port=57449 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1O2l3D-0006JU-MT for qemu-devel@nongnu.org; Fri, 16 Apr 2010 08:53:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1O2gVV-0005ru-Og for qemu-devel@nongnu.org; Fri, 16 Apr 2010 04:06:11 -0400 Received: from mx1.redhat.com ([209.132.183.28]:55147) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1O2gVU-0005qd-9F for qemu-devel@nongnu.org; Fri, 16 Apr 2010 04:02:33 -0400 Received: from int-mx03.intmail.prod.int.phx2.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o3G82ONf006090 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 16 Apr 2010 04:02:25 -0400 Received: from zweiblum.home.kraxel.org (vpn2-8-252.ams2.redhat.com [10.36.8.252]) by int-mx03.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o3G82Fde024954 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Fri, 16 Apr 2010 04:02:18 -0400 Message-ID: <4BC81986.4060904@redhat.com> Date: Fri, 16 Apr 2010 10:02:14 +0200 From: Gerd Hoffmann User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.9) Gecko/20100330 Fedora/3.0.4-1.fc12 Thunderbird/3.0.4 MIME-Version: 1.0 To: Paolo Bonzini References: <1271238922-10008-1-git-send-email-kraxel@redhat.com> <1271238922-10008-9-git-send-email-kraxel@redhat.com> <4BC64AD6.6040209@redhat.com> In-Reply-To: <4BC64AD6.6040209@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.16 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. Cc: Blue Swirl , qemu-devel@nongnu.org Subject: [Qemu-devel] Re: [RfC PATCH 08/11] spice: add qxl device X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org On 04/15/10 01:08, Paolo Bonzini wrote: > On 04/14/2010 06:52 PM, Blue Swirl wrote: >> On 4/14/10, Gerd Hoffmann wrote: >>> +static inline void atomic_or(uint32_t *var, uint32_t add) >>> +{ >>> + __asm__ __volatile__ ("lock; orl %1, %0" : "+m" (*var) : "r" (add) >>> : "memory"); >>> +} >> >> This will break on non-x86 hosts. > > I'd just use __sync_fetch_and_or here. Good idea. I think we can zap the memory barrier and fix a small race while being at it, see the incremental fix below. cheers, Gerd diff --git a/hw/qxl.c b/hw/qxl.c index 7ac06f6..8cbd9a3 100644 --- a/hw/qxl.c +++ b/hw/qxl.c @@ -6,7 +6,6 @@ #include #include "qemu-common.h" -#include "qemu-barrier.h" #include "qemu-spice.h" #include "qemu-timer.h" #include "qemu-queue.h" @@ -176,11 +175,6 @@ static inline uint32_t msb_mask(uint32_t val) return mask; } -static inline void atomic_or(uint32_t *var, uint32_t add) -{ - __asm__ __volatile__ ("lock; orl %1, %0" : "+m" (*var) : "r" (add) : "memory"); -} - static ram_addr_t qxl_rom_size(void) { uint32_t rom_size = sizeof(QXLRom) + sizeof(QXLModes) + sizeof(qxl_modes); @@ -892,12 +886,13 @@ static void pipe_read(void *opaque) static void qxl_send_events(PCIQXLDevice *d, uint32_t events) { + uint32_t old_pending; + assert(d->ssd.running); - smp_wmb(); - if ((d->ram->int_pending & events) == events) { + old_pending = __sync_fetch_and_or(&d->ram->int_pending, events); + if ((old_pending & events) == events) { return; } - atomic_or(&d->ram->int_pending, events); if (pthread_self() == d->main) { qxl_set_irq(d); } else {