Message ID | 1538295197-23704-13-git-send-email-pbonzini@redhat.com |
---|---|
State | New |
Headers | show
Return-Path: <qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org> X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=<UNKNOWN>) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="YXKbjheQ"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42NJN93BQbz9s7T for <incoming@patchwork.ozlabs.org>; Sun, 30 Sep 2018 18:23:53 +1000 (AEST) Received: from localhost ([::1]:54258 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from <qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>) id 1g6X14-0002oT-SH for incoming@patchwork.ozlabs.org; Sun, 30 Sep 2018 04:23:50 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41227) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from <paolo.bonzini@gmail.com>) id 1g6WrA-000280-Bh for qemu-devel@nongnu.org; Sun, 30 Sep 2018 04:13:37 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from <paolo.bonzini@gmail.com>) id 1g6Wr7-00004r-Bn for qemu-devel@nongnu.org; Sun, 30 Sep 2018 04:13:36 -0400 Received: from mail-wm1-x32d.google.com ([2a00:1450:4864:20::32d]:38296) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from <paolo.bonzini@gmail.com>) id 1g6Wr7-0008Sg-3E for qemu-devel@nongnu.org; Sun, 30 Sep 2018 04:13:33 -0400 Received: by mail-wm1-x32d.google.com with SMTP id 193-v6so4331919wme.3 for <qemu-devel@nongnu.org>; Sun, 30 Sep 2018 01:13:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:subject:date:message-id:in-reply-to:references; bh=Saaj0uOtVxSmGYAK3+Wp2ZSZkE/z9nB7pHaQINox8vw=; b=YXKbjheQX79Gna1nRVNPZUOseMcgLh+Msygzi1u79ka35mFUrYFkn6PhN8hY9v25my akiZvw6jOsDzTRwDKq/jTEz5eJy5A/rcEKAnMLxviGGOL7g8L/rof9m08CEJ+Dw7OhqF PD8qQmtd/khtFASOTu99gU/czqqN1qI/N6TwWNg4fzxneKBihwCSffeid6lHWzm/Jpew UJnkR9LGfsSUsD0T8wMqpLeqs1P8UP01vF7kzkMXchAnKa9HeMuwEx7Qz2dWKwvWZm4s KTNRtigP/rAGc8B+i+rYS8vBpT8KKEdK5OXoNnzox1DVWSxJxH8MvQooJ5rNL/txS64g gVHg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:subject:date:message-id :in-reply-to:references; bh=Saaj0uOtVxSmGYAK3+Wp2ZSZkE/z9nB7pHaQINox8vw=; b=LamfiCaX8ceTJRu6I8hrEIoclMpeVFMBwIg2ewCMpUG95gURBy42hXN6rPC2UL06fq yo1siSapwmbtaaPhEZQcrXIut2sKEaR0GYkDncO8OfUa+aCG+aRJ4AK4mSbSbps3pG/0 T0P0oT+wOeCwlA2bnIKfyrPdQGjR0QjRVRkfyZz/evO6cfPDi/ryZcuL7UHl17LGzfBO 6FAtsNr+awPL7HSsJCLYwXKexaccF4Qvkk3w3W9cfgLJ0eG7kI5iC2XeYk1Hy4qm1cq5 bZj2K5GK6l6Lr8pNTdaBk0apAI7vJ9RZmfGwuviWe+2C9Ks39b7KBaX5OtrZl5II4+aa YYiw== X-Gm-Message-State: ABuFfoiU27EWpc0Yf6v2v+vICgiXSOmS5ncOfGJvQ79PosWfLmvJFbN7 rYQWSHTuyBUoGMfHGNdxLMMlvx+5 X-Google-Smtp-Source: ACcGV61p+osGkDdM/T9ch6QOC5Ir+MifJEUcbvqN1sOszWPCXhqQOyrI43RZaGFfyvAZffRwUYM2cg== X-Received: by 2002:a1c:8587:: with SMTP id h129-v6mr6412368wmd.105.1538295210644; Sun, 30 Sep 2018 01:13:30 -0700 (PDT) Received: from 640k.lan (94-36-187-248.adsl-ull.clienti.tiscali.it. [94.36.187.248]) by smtp.gmail.com with ESMTPSA id u76-v6sm11369194wmd.10.2018.09.30.01.13.29 for <qemu-devel@nongnu.org> (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 30 Sep 2018 01:13:30 -0700 (PDT) From: Paolo Bonzini <pbonzini@redhat.com> To: qemu-devel@nongnu.org Date: Sun, 30 Sep 2018 10:12:10 +0200 Message-Id: <1538295197-23704-13-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1538295197-23704-1-git-send-email-pbonzini@redhat.com> References: <1538295197-23704-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::32d Subject: [Qemu-devel] [PULL 12/79] cpus: take seqlock across qemu_icount updates X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: <qemu-devel.nongnu.org> List-Unsubscribe: <https://lists.nongnu.org/mailman/options/qemu-devel>, <mailto:qemu-devel-request@nongnu.org?subject=unsubscribe> List-Archive: <http://lists.nongnu.org/archive/html/qemu-devel/> List-Post: <mailto:qemu-devel@nongnu.org> List-Help: <mailto:qemu-devel-request@nongnu.org?subject=help> List-Subscribe: <https://lists.nongnu.org/mailman/listinfo/qemu-devel>, <mailto:qemu-devel-request@nongnu.org?subject=subscribe> Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" <qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org> |
Series |
[PULL,01/79] virtio: Return true from virtio_queue_empty if broken
|
expand
|
diff --git a/cpus.c b/cpus.c index 4abc3b3..6e1a892 100644 --- a/cpus.c +++ b/cpus.c @@ -245,21 +245,27 @@ static int64_t cpu_get_icount_executed(CPUState *cpu) * account executed instructions. This is done by the TCG vCPU * thread so the main-loop can see time has moved forward. */ -void cpu_update_icount(CPUState *cpu) +static void cpu_update_icount_locked(CPUState *cpu) { int64_t executed = cpu_get_icount_executed(cpu); cpu->icount_budget -= executed; -#ifndef CONFIG_ATOMIC64 - seqlock_write_lock(&timers_state.vm_clock_seqlock, - &timers_state.vm_clock_lock); -#endif atomic_set__nocheck(&timers_state.qemu_icount, timers_state.qemu_icount + executed); -#ifndef CONFIG_ATOMIC64 +} + +/* + * Update the global shared timer_state.qemu_icount to take into + * account executed instructions. This is done by the TCG vCPU + * thread so the main-loop can see time has moved forward. + */ +void cpu_update_icount(CPUState *cpu) +{ + seqlock_write_lock(&timers_state.vm_clock_seqlock, + &timers_state.vm_clock_lock); + cpu_update_icount_locked(cpu); seqlock_write_unlock(&timers_state.vm_clock_seqlock, &timers_state.vm_clock_lock); -#endif } static int64_t cpu_get_icount_raw_locked(void) @@ -272,7 +278,7 @@ static int64_t cpu_get_icount_raw_locked(void) exit(1); } /* Take into account what has run */ - cpu_update_icount(cpu); + cpu_update_icount_locked(cpu); } /* The read is protected by the seqlock, so __nocheck is okay. */ return atomic_read__nocheck(&timers_state.qemu_icount);
Even though writes of qemu_icount can safely race with reads in qemu_icount_raw, qemu_icount is also read by icount_adjust, which runs in the I/O thread. Therefore, writes do needs protection of the vm_clock_lock; for simplicity the patch protects it with both seqlock+spinlock, which we already do for hosts that lack 64-bit atomics. The bug actually predated the introduction of vm_clock_lock; cpu_update_icount would have needed the BQL before the spinlock was introduced. Reported-by: Emilio G. Cota <cota@braap.org> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> --- cpus.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-)