From patchwork Fri Oct 16 08:49:28 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 55086 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f200.google.com (mail-lb0-f200.google.com [209.85.217.200]) by patches.linaro.org (Postfix) with ESMTPS id 3412B22EAC for ; Fri, 16 Oct 2015 09:00:29 +0000 (UTC) Received: by lbbms9 with SMTP id ms9sf22161618lbb.3 for ; Fri, 16 Oct 2015 02:00:28 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:date :message-id:in-reply-to:references:cc:subject:precedence:list-id :list-unsubscribe:list-archive:list-post:list-help:list-subscribe :errors-to:sender:x-original-sender :x-original-authentication-results:mailing-list; bh=rtaFvRYAf0yDIJROjON0VS402Yq6BOQSnylhEJsvV8c=; b=mXv6gl9jVgtb6O64QKCuVGhB1P+e/UL/GyJhug7QTe0AGp9c2W7ERjK37dVCtdVGkZ ZJgTEd+51WRhpucr+cMijP+QrKSDoGHITNp3RrtIq+y4UewE+XvRIyXa41oyL0ACqfgd kXoP8vcqKq9WWLzYc1gNHAAIVgU0jkBEtTskeRRJMHwvddlT1QlPLU82cIzLSSphvfxF seb0mlsn8cFp645Akh9n2F4YBhAmlaqYm4RlKF+tRyVRQo5U3Xy+RjfcpDHqqVyClx4N enAhg8uxMbE090BiaYBadOwkERJDR4Kk/oQnn3S4lVF2DvtHFCy4JLKRhN/iLDfyTuYa coDw== X-Gm-Message-State: ALoCoQnQva+l7nOi5PAelMqTpJkcrGCK79pkMQWx1v5n8Dxw51+T109lUd9rCZODJiZO4m/zZJVL X-Received: by 10.194.156.193 with SMTP id wg1mr3267112wjb.3.1444986028157; Fri, 16 Oct 2015 02:00:28 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.25.32.207 with SMTP id g198ls265499lfg.18.gmail; Fri, 16 Oct 2015 02:00:27 -0700 (PDT) X-Received: by 10.112.151.106 with SMTP id up10mr7781192lbb.106.1444986027832; Fri, 16 Oct 2015 02:00:27 -0700 (PDT) Received: from mail-lb0-f179.google.com (mail-lb0-f179.google.com. [209.85.217.179]) by mx.google.com with ESMTPS id ab1si12203460lbc.108.2015.10.16.02.00.27 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 16 Oct 2015 02:00:27 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.179 as permitted sender) client-ip=209.85.217.179; Received: by lbbwb3 with SMTP id wb3so34324843lbb.1 for ; Fri, 16 Oct 2015 02:00:27 -0700 (PDT) X-Received: by 10.112.161.168 with SMTP id xt8mr6636004lbb.88.1444986027730; Fri, 16 Oct 2015 02:00:27 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.59.35 with SMTP id w3csp1127189lbq; Fri, 16 Oct 2015 02:00:24 -0700 (PDT) X-Received: by 10.140.18.240 with SMTP id 103mr17954362qgf.31.1444986024856; Fri, 16 Oct 2015 02:00:24 -0700 (PDT) Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id e77si17015939qka.101.2015.10.16.02.00.24 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Fri, 16 Oct 2015 02:00:24 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Received: from localhost ([::1]:51833 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zn0sC-0002VR-Dn for patch@linaro.org; Fri, 16 Oct 2015 05:00:24 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50023) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zn0iW-0003ZY-7t for qemu-devel@nongnu.org; Fri, 16 Oct 2015 04:50:25 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Zn0iV-0006ye-4p for qemu-devel@nongnu.org; Fri, 16 Oct 2015 04:50:24 -0400 Received: from mx1.redhat.com ([209.132.183.28]:49757) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zn0iU-0006yW-VG for qemu-devel@nongnu.org; Fri, 16 Oct 2015 04:50:23 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (Postfix) with ESMTPS id 94991461C3; Fri, 16 Oct 2015 08:50:22 +0000 (UTC) Received: from donizetti.redhat.com (ovpn-112-80.ams2.redhat.com [10.36.112.80]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t9G8oCaR010200; Fri, 16 Oct 2015 04:50:21 -0400 From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Fri, 16 Oct 2015 10:49:28 +0200 Message-Id: <1444985411-17803-7-git-send-email-pbonzini@redhat.com> In-Reply-To: <1444985411-17803-1-git-send-email-pbonzini@redhat.com> References: <1444985411-17803-1-git-send-email-pbonzini@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Peter Maydell Subject: [Qemu-devel] [PULL 06/49] cpu-exec-common.c: Clarify comment about cpu_reload_memory_map()'s RCU operations X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: , List-Help: , List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: pbonzini@redhat.com X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.179 as permitted sender) smtp.mailfrom=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 From: Peter Maydell The reason for cpu_reload_memory_map()'s RCU operations is not so much because the guest could make the critical section very long, but that it could have a critical section within which it made an arbitrary number of changes to the memory map and thus accumulate an unbounded amount of memory data structures awaiting reclamation. Clarify the comment to make this clearer. Signed-off-by: Peter Maydell Message-Id: <1443709790-25180-3-git-send-email-peter.maydell@linaro.org> Signed-off-by: Paolo Bonzini --- cpu-exec-common.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/cpu-exec-common.c b/cpu-exec-common.c index 16d305b..b95b09a 100644 --- a/cpu-exec-common.c +++ b/cpu-exec-common.c @@ -42,13 +42,21 @@ void cpu_reload_memory_map(CPUState *cpu) AddressSpaceDispatch *d; if (qemu_in_vcpu_thread()) { - /* Do not let the guest prolong the critical section as much as it - * as it desires. + /* The guest can in theory prolong the RCU critical section as long + * as it feels like. The major problem with this is that because it + * can do multiple reconfigurations of the memory map within the + * critical section, we could potentially accumulate an unbounded + * collection of memory data structures awaiting reclamation. * - * Currently, this is prevented by the I/O thread's periodinc kicking - * of the VCPU thread (iothread_requesting_mutex, qemu_cpu_kick_thread) - * but this will go away once TCG's execution moves out of the global - * mutex. + * Because the only thing we're currently protecting with RCU is the + * memory data structures, it's sufficient to break the critical section + * in this callback, which we know will get called every time the + * memory map is rearranged. + * + * (If we add anything else in the system that uses RCU to protect + * its data structures, we will need to implement some other mechanism + * to force TCG CPUs to exit the critical section, at which point this + * part of this callback might become unnecessary.) * * This pair matches cpu_exec's rcu_read_lock()/rcu_read_unlock(), which * only protects cpu->as->dispatch. Since we reload it below, we can