From patchwork Mon Mar 4 18:17:00 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emilio Cota X-Patchwork-Id: 10838149 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id F14F317E9 for ; Mon, 4 Mar 2019 18:23:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DD4EA2AF36 for ; Mon, 4 Mar 2019 18:23:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D095A2AF7A; Mon, 4 Mar 2019 18:23:23 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 499332AF36 for ; Mon, 4 Mar 2019 18:23:23 +0000 (UTC) Received: from localhost ([127.0.0.1]:58646 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h0sFG-0004Lx-J5 for patchwork-qemu-devel@patchwork.kernel.org; Mon, 04 Mar 2019 13:23:22 -0500 Received: from eggs.gnu.org ([209.51.188.92]:44323) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h0sAR-0008CK-Ob for qemu-devel@nongnu.org; Mon, 04 Mar 2019 13:18:24 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h0sAQ-0000lS-LY for qemu-devel@nongnu.org; Mon, 04 Mar 2019 13:18:23 -0500 Received: from out2-smtp.messagingengine.com ([66.111.4.26]:59635) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1h0sAN-0000eD-RO; Mon, 04 Mar 2019 13:18:19 -0500 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 137442222B; Mon, 4 Mar 2019 13:18:19 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Mon, 04 Mar 2019 13:18:19 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=braap.org; h= from:to:cc:subject:date:message-id; s=mesmtp; bh=Z4KV7GaFmevlqDc X9Cv1lXDvSLs5qtJUKfpu42eXeyo=; b=NWa5noOUYPCQrLkC4p93DnKXZbiYnjH eXEgs8LbanXf1ZCiUQ7efce7HWvEhuoi8O5jY7l4QTGRQ/f7q02I+ON012IVqOF0 SFtkXrG7tfqCRYhXY5zgXHy3iuSwkbVCwdsyAGaX8pk+S3rcWLLGXi8HbqIXO+rS BgbSBFsaetpk= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:date:from:message-id:subject:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm2; bh=Z4KV7GaFmevlqDcX9Cv1lXDvSLs5qtJUKfpu42eXeyo=; b=cZyGL2RB rYw37Mhlr4+E5PS1MdFbdKgVcs3ahrtDFNfoaCE8ezvmQ32tT3lbs34O82QWddEK C5YP0ZMmEIq3zKVB9mJ2N5NxxPpnE5AHnk3PRGleiPR5rZtvrDmAjiWQ6BqqMZNd wNVmOLjhRv9wL9MO42cley6ery5NF+UwvA7zGnqMwcN5eqrQCFaOZPoF9NtTvt/4 QrpVL0A415MEhSYWQjHNet6w0SMdsPFJcr7UXUZDzuXpCVhafHqSpCw6SHfqmZtq Clnp4bg/3+zLGT6gpJ2MsPNNlnr8NlOR50tBcdF+SUsly04PL+16xRbndA+K2WTa ENizBM/8GOjBMg== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedutddrfedugdduuddtucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvufffkffosedttdertdertddtnecuhfhrohhmpedfgfhmihhlihhoucfi rdcuvehothgrfdcuoegtohhtrgessghrrggrphdrohhrgheqnecuffhomhgrihhnpehgih hthhhusgdrtghomhdpghhnuhdrohhrghenucfkphepuddvkedrheelrddvtddrvdduieen ucfrrghrrghmpehmrghilhhfrhhomheptghothgrsegsrhgrrghprdhorhhgnecuvehluh hsthgvrhfuihiivgeptd X-ME-Proxy: Received: from localhost (flamenco.cs.columbia.edu [128.59.20.216]) by mail.messagingengine.com (Postfix) with ESMTPA id 68CE7E44A5; Mon, 4 Mar 2019 13:18:14 -0500 (EST) From: "Emilio G. Cota" To: qemu-devel@nongnu.org Date: Mon, 4 Mar 2019 13:17:00 -0500 Message-Id: <20190304181813.8075-1-cota@braap.org> X-Mailer: git-send-email 2.17.1 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 66.111.4.26 Subject: [Qemu-devel] [PATCH v7 00/73] per-CPU locks X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Chris Wulff , Sagar Karandikar , David Hildenbrand , James Hogan , Anthony Green , Palmer Dabbelt , Mark Cave-Ayland , Max Filippov , "Edgar E. Iglesias" , Guan Xuetao , Marek Vasut , Christian Borntraeger , Artyom Tarasenko , Eduardo Habkost , Richard Henderson , Fabien Chouteau , qemu-s390x@nongnu.org, qemu-arm@nongnu.org, Alistair Francis , Stafford Horne , =?utf-8?q?Alex_Benn=C3=A9e?= , David Gibson , Bastian Koppelmann , Cornelia Huck , Laurent Vivier , Michael Walle , qemu-ppc@nongnu.org, Aleksandar Markovic , Paolo Bonzini , Aurelien Jarno Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP v6: https://lists.gnu.org/archive/html/qemu-devel/2019-01/msg07650.html All patches in the series have reviews now. Thanks everyone! I've tested all patches with `make check-qtest -j' for all targets. The series is checkpatch-clean (just some warnings about __COVERITY__). You can fetch the series from: https://github.com/cota/qemu/tree/cpu-lock-v7 --- v6->v7: - Rebase on master - Add a cpu_halted_set call to arm code that wasn't there in v6 - Add R-b's and Ack's. - Add comment to patch 3's log to explain why the bitmap is added there, even though it only gains a user at the end of the series. - Fix "prevent deadlock" comments before assertions; use "enforce locking order" instead, which is more accurate. - Add a few more comments, as suggested by Alex. v6->v7 diff (before rebase) below. Thanks, Emilio --- diff --git a/accel/tcg/cpu-exec.c b/accel/tcg/cpu-exec.c index e4ae04f72c..a513457520 100644 --- a/accel/tcg/cpu-exec.c +++ b/accel/tcg/cpu-exec.c @@ -435,7 +435,7 @@ static inline bool cpu_handle_halt_locked(CPUState *cpu) && replay_interrupt()) { X86CPU *x86_cpu = X86_CPU(cpu); - /* prevent deadlock; cpu_mutex must be acquired _after_ the BQL */ + /* locking order: cpu_mutex must be acquired _after_ the BQL */ cpu_mutex_unlock(cpu); qemu_mutex_lock_iothread(); cpu_mutex_lock(cpu); diff --git a/cpus.c b/cpus.c index 4f17fe25bf..82a93f2a5a 100644 --- a/cpus.c +++ b/cpus.c @@ -2062,7 +2062,7 @@ void qemu_mutex_lock_iothread_impl(const char *file, int line) { QemuMutexLockFunc bql_lock = atomic_read(&qemu_bql_mutex_lock_func); - /* prevent deadlock with CPU mutex */ + /* enforce locking order */ g_assert(no_cpu_mutex_locked()); g_assert(!qemu_mutex_iothread_locked()); diff --git a/include/qom/cpu.h b/include/qom/cpu.h index bb0729f969..726cb7b090 100644 --- a/include/qom/cpu.h +++ b/include/qom/cpu.h @@ -322,7 +322,8 @@ struct qemu_work_item; * @mem_io_pc: Host Program Counter at which the memory was accessed. * @mem_io_vaddr: Target virtual address at which the memory was accessed. * @kvm_fd: vCPU file descriptor for KVM. - * @lock: Lock to prevent multiple access to per-CPU fields. + * @lock: Lock to prevent multiple access to per-CPU fields. Must be acquired + * after the BQL. * @cond: Condition variable for per-CPU events. * @work_list: List of pending asynchronous work. * @halted: Nonzero if the CPU is in suspended state. @@ -804,6 +805,7 @@ static inline bool cpu_has_work(CPUState *cpu) bool (*func)(CPUState *cpu); bool ret; + /* some targets require us to hold the BQL when checking for work */ if (cc->has_work_with_iothread_lock) { if (qemu_mutex_iothread_locked()) { func = cc->has_work_with_iothread_lock; diff --git a/target/i386/kvm.c b/target/i386/kvm.c index 3f3c670897..65a14deb2f 100644 --- a/target/i386/kvm.c +++ b/target/i386/kvm.c @@ -3216,6 +3216,10 @@ void kvm_arch_pre_run(CPUState *cpu, struct kvm_run *run) qemu_mutex_lock_iothread(); } + /* + * We might have cleared some bits in cpu->interrupt_request since reading + * it; read it again. + */ interrupt_request = cpu_interrupt_request(cpu); /* Force the VCPU out of its inner loop to process any INIT requests