From patchwork Wed Oct 23 15:26:19 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 11207139 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1552713B1 for ; Wed, 23 Oct 2019 15:54:23 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id DF3FE2086D for ; Wed, 23 Oct 2019 15:54:22 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="erUmzOWt" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org DF3FE2086D Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:40170 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNIxq-0003tY-2q for patchwork-qemu-devel@patchwork.kernel.org; Wed, 23 Oct 2019 11:54:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39844) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNIXN-0005ND-BD for qemu-devel@nongnu.org; Wed, 23 Oct 2019 11:27:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iNIXM-0002lX-9J for qemu-devel@nongnu.org; Wed, 23 Oct 2019 11:27:01 -0400 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:32646 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iNIXM-0002l9-5t for qemu-devel@nongnu.org; Wed, 23 Oct 2019 11:27:00 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1571844419; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Qo4k4Dw+pnxV7TbicL18z1fOMWIRfsoSaltyjb9eTJE=; b=erUmzOWtDr4Fj6M+m4nm0vJePxVB8PVg4mJ/hfjS74TOt1uhV9EErxtf9KJMRWxOgA0XGr jpWQIIySxJvjvwnf8Hz7jD7mwtzv8g8liXOsndiwUCnUuzBxBD6tZv8hABdY2bjhr85exD DQD89WSxQHACIPabDddy2pOzvICQmfk= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-235-ySeDEXHHOMO2UOw_IhgC1w-1; Wed, 23 Oct 2019 11:26:56 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 4F4F31005500; Wed, 23 Oct 2019 15:26:53 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-117-192.ams2.redhat.com [10.36.117.192]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0B7B4608C1; Wed, 23 Oct 2019 15:26:46 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Subject: [PATCH 2/3] qcow2: Assert that qcow2_cache_get() callers hold s->lock Date: Wed, 23 Oct 2019 17:26:19 +0200 Message-Id: <20191023152620.13166-3-kwolf@redhat.com> In-Reply-To: <20191023152620.13166-1-kwolf@redhat.com> References: <20191023152620.13166-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-MC-Unique: ySeDEXHHOMO2UOw_IhgC1w-1 X-Mimecast-Spam-Score: 0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 207.211.31.120 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, psyhomb@gmail.com, michael@weiser.dinsnail.net, vsementsov@virtuozzo.com, den@virtuozzo.com, qemu-devel@nongnu.org, qemu-stable@nongnu.org, dgilbert@redhat.com, mreitz@redhat.com, lersek@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" qcow2_cache_do_get() requires that s->lock is locked because it can yield between picking a cache entry and actually taking ownership of it by setting offset and increasing the reference count. Add an assertion to make sure the caller really holds the lock. The function can be called outside of coroutine context, where bdrv_pread and flushes become synchronous operations. The lock cannot and need not be taken in this case. Signed-off-by: Kevin Wolf Reviewed-by: Denis V. Lunev Tested-by: Michael Weiser --- block/qcow2-cache.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/block/qcow2-cache.c b/block/qcow2-cache.c index d29b038a67..75b13dad99 100644 --- a/block/qcow2-cache.c +++ b/block/qcow2-cache.c @@ -327,6 +327,9 @@ static int qcow2_cache_do_get(BlockDriverState *bs, Qcow2Cache *c, int min_lru_index = -1; assert(offset != 0); + if (qemu_in_coroutine()) { + qemu_co_mutex_assert_locked(&s->lock); + } trace_qcow2_cache_get(qemu_coroutine_self(), c == s->l2_table_cache, offset, read_from_disk); @@ -386,6 +389,8 @@ static int qcow2_cache_do_get(BlockDriverState *bs, Qcow2Cache *c, } } + assert(c->entries[i].ref == 0); + assert(c->entries[i].offset == 0); c->entries[i].offset = offset; /* And return the right table */