From nobody Sun May 19 06:23:11 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1651674743; cv=none; d=zohomail.com; s=zohoarc; b=kIRYEjA4x/kMLjAe0lw/ZEGwibkWvontT5ebhC6TObn8nESJnIoS+0aiZbcMxKWB/KayJsfs9BMDRwtWCoMGPUaFZDxLQFwglmiL+s8Zxw0HLTISvRwxHjCivNy/ZwGNYN19YnL3VgSMXmqP0ClgiAj6S2f7Lb+4VGRjLgLnRUc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1651674743; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=JPenWIdohtSBCEhLlxaLO6pPH5tqekKoSOptC+3Z9cE=; b=fletX715x3sKmOzXRrJRgXuuAMJByL/cQROojW3er6ZlRqH3iaLoRmnhkaOC42mFiodiLUyIIDzONNMYR86hdhVd/mQzcGykcXQKx/c2qYI7Zl8M4TEDnIyT1lrMa7k6OBMr3qxr6oZjn/4Kl71IvUWVJomDVCi3hfGbnAvITTo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1651674743547605.8887017427359; Wed, 4 May 2022 07:32:23 -0700 (PDT) Received: from localhost ([::1]:37322 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nmG3C-0001F3-EL for importer@patchew.org; Wed, 04 May 2022 10:32:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43834) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nmFwd-0000mC-Vo for qemu-devel@nongnu.org; Wed, 04 May 2022 10:25:36 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:34315) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nmFwc-0007ED-Eo for qemu-devel@nongnu.org; Wed, 04 May 2022 10:25:35 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-538-uK-ZU5UsMkabA6Apitkwng-1; Wed, 04 May 2022 10:25:30 -0400 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 72DEB811E83; Wed, 4 May 2022 14:25:30 +0000 (UTC) Received: from merkur.str.redhat.com (dhcp-192-180.str.redhat.com [10.33.192.180]) by smtp.corp.redhat.com (Postfix) with ESMTP id E7493402189; Wed, 4 May 2022 14:25:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1651674333; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=JPenWIdohtSBCEhLlxaLO6pPH5tqekKoSOptC+3Z9cE=; b=RXNZPYsg/zaixZQxdacfP2Fc0FrzsLprwWoCgNj6zIASInZerkfPX2wcFYSoJjxTN5x+9P CvgWDFCekkDJ3fp3LPY6BYyTmcGe6BLNsGh4akCEoVIQ7DIH7Z3LE5zhQmdr8TfFOGzQNU M2ulzzTH20Aj3Pr32b58TJTTFmooVjA= X-MC-Unique: uK-ZU5UsMkabA6Apitkwng-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, qemu-devel@nongnu.org Subject: [PULL 01/13] qemu-img: properly list formats which have consistency check implemented Date: Wed, 4 May 2022 16:25:10 +0200 Message-Id: <20220504142522.167506-2-kwolf@redhat.com> In-Reply-To: <20220504142522.167506-1-kwolf@redhat.com> References: <20220504142522.167506-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.85 on 10.11.54.9 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1651674744435100001 Content-Type: text/plain; charset="utf-8" From: "Denis V. Lunev" Simple grep for the .bdrv_co_check callback presence gives the following list of block drivers * QED * VDI * VHDX * VMDK * Parallels which have this callback. The presense of the callback means that consistency check is supported. The patch updates documentation accordingly. Signed-off-by: Denis V. Lunev CC: Kevin Wolf CC: Hanna Reitz Message-Id: <20220407083932.531965-1-den@openvz.org> Reviewed-by: Eric Blake Signed-off-by: Kevin Wolf --- docs/tools/qemu-img.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/tools/qemu-img.rst b/docs/tools/qemu-img.rst index 8885ea11cf..85a6e05b35 100644 --- a/docs/tools/qemu-img.rst +++ b/docs/tools/qemu-img.rst @@ -332,8 +332,8 @@ Command description: ``-r all`` fixes all kinds of errors, with a higher risk of choosing the wrong fix or hiding corruption that has already occurred. =20 - Only the formats ``qcow2``, ``qed`` and ``vdi`` support - consistency checks. + Only the formats ``qcow2``, ``qed``, ``parallels``, ``vhdx``, ``vmdk`` a= nd + ``vdi`` support consistency checks. =20 In case the image does not have any inconsistencies, check exits with ``= 0``. Other exit codes indicate the kind of inconsistency found or if another = error --=20 2.35.1 From nobody Sun May 19 06:23:11 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1651674514; cv=none; d=zohomail.com; s=zohoarc; b=QnAjRV7vUqNhDF3nQpp0nYHkNoW83ysZQtlTWdm0hUObbloOpEX0U6zcXqgrKkvBeJdoteMRDI9vUVRN86feDP8N0du7e+t4ouhMdfRoA4pQznqGdFqTq+XyDukjI0MSNeA5Wzc9bAgWt/d+hkEnamqaNrFYCR9uH9fOSHFbDuE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1651674514; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=kDSw1aY237C3BIH44HkL6LE8R4LkCHonPUNscpmiisA=; b=iaVT553+9fsLwvLASbMkrQ5XRM1q/Xdz5isnUJLA2+DRpfJyODarmQKloOTCYzKWvdI32nLJ2SY60jXImocJsskcLYxE4X8c3//pmJmdG9Zt/t2fvzi6lrpjbn35auZcloZWO7CzJYLkGSZAMV511fdOnOJ5fvO1bA+CnIitlyM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1651674514934443.2501534222779; Wed, 4 May 2022 07:28:34 -0700 (PDT) Received: from localhost ([::1]:58088 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nmFzV-0004LC-TX for importer@patchew.org; Wed, 04 May 2022 10:28:33 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43902) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nmFwf-0000oU-EV for qemu-devel@nongnu.org; Wed, 04 May 2022 10:25:37 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:54844) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nmFwd-0007EX-8c for qemu-devel@nongnu.org; Wed, 04 May 2022 10:25:37 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-422-MVlDlN4uPt6FhLMpKbB5qg-1; Wed, 04 May 2022 10:25:31 -0400 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 2EC3B80A0AD; Wed, 4 May 2022 14:25:31 +0000 (UTC) Received: from merkur.str.redhat.com (dhcp-192-180.str.redhat.com [10.33.192.180]) by smtp.corp.redhat.com (Postfix) with ESMTP id A3148402189; Wed, 4 May 2022 14:25:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1651674334; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=kDSw1aY237C3BIH44HkL6LE8R4LkCHonPUNscpmiisA=; b=MnubhyMlIRFmmMb3i9G1IaB35LHLto87Ncin/ihwaqaHOnGWT+8Ko1M/IykFQ9o4vp4jaV 6PXxAv3t5ck+6bUdP+KKH9iFCJ0duuA/PIP2A29oMi6TmK9Izn3xWCi3oIDoKBnf7DpS8B kgGkZP595WQEjBVktaHa0AlO/vvdwj0= X-MC-Unique: MVlDlN4uPt6FhLMpKbB5qg-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, qemu-devel@nongnu.org Subject: [PULL 02/13] docs/vhost-user: Clarifications for VHOST_USER_ADD/REM_MEM_REG Date: Wed, 4 May 2022 16:25:11 +0200 Message-Id: <20220504142522.167506-3-kwolf@redhat.com> In-Reply-To: <20220504142522.167506-1-kwolf@redhat.com> References: <20220504142522.167506-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.85 on 10.11.54.9 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1651674515841100001 Content-Type: text/plain; charset="utf-8" The specification for VHOST_USER_ADD/REM_MEM_REG messages is unclear in several points, which has led to clients having incompatible implementations. This changes the specification to be more explicit about them: * VHOST_USER_ADD_MEM_REG is not specified as receiving a file descriptor, though it obviously does need to do so. All implementations agree on this one, fix the specification. * VHOST_USER_REM_MEM_REG is not specified as receiving a file descriptor either, and it also has no reason to do so. rust-vmm does not send file descriptors for removing a memory region (in agreement with the specification), libvhost-user and QEMU do (which is a bug), though libvhost-user doesn't actually make any use of it. Change the specification so that for compatibility QEMU's behaviour becomes legal, even if discouraged, but rust-vmm's behaviour becomes the explicitly recommended mode of operation. * VHOST_USER_ADD_MEM_REG doesn't have a documented return value, which is the desired behaviour in the non-postcopy case. It also implemented like this in QEMU and rust-vmm, though libvhost-user is buggy and sometimes sends an unexpected reply. This will be fixed in a separate patch. However, in postcopy mode it does reply like VHOST_USER_SET_MEM_TABLE. This behaviour is shared between libvhost-user and QEMU; rust-vmm doesn't implement postcopy mode yet. Mention it explicitly in the spec. * The specification doesn't mention how VHOST_USER_REM_MEM_REG identifies the memory region to be removed. Change it to describe the existing behaviour of libvhost-user (guest address, user address and size must match). Signed-off-by: Kevin Wolf Message-Id: <20220407133657.155281-2-kwolf@redhat.com> Reviewed-by: Raphael Norwitz Reviewed-by: Stefan Hajnoczi Signed-off-by: Kevin Wolf --- docs/interop/vhost-user.rst | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/docs/interop/vhost-user.rst b/docs/interop/vhost-user.rst index 4dbc84fd00..f9e721ba5f 100644 --- a/docs/interop/vhost-user.rst +++ b/docs/interop/vhost-user.rst @@ -308,6 +308,7 @@ replies. Here is a list of the ones that do: There are several messages that the master sends with file descriptors pas= sed in the ancillary data: =20 +* ``VHOST_USER_ADD_MEM_REG`` * ``VHOST_USER_SET_MEM_TABLE`` * ``VHOST_USER_SET_LOG_BASE`` (if ``VHOST_USER_PROTOCOL_F_LOG_SHMFD``) * ``VHOST_USER_SET_LOG_FD`` @@ -1334,6 +1335,14 @@ Master message types ``VHOST_USER_REM_MEM_REG`` message, this message is used to set and update the memory tables of the slave device. =20 + Exactly one file descriptor from which the memory is mapped is + passed in the ancillary data. + + In postcopy mode (see ``VHOST_USER_POSTCOPY_LISTEN``), the slave + replies with the bases of the memory mapped region to the master. + For further details on postcopy, see ``VHOST_USER_SET_MEM_TABLE``. + They apply to ``VHOST_USER_ADD_MEM_REG`` accordingly. + ``VHOST_USER_REM_MEM_REG`` :id: 38 :equivalent ioctl: N/A @@ -1349,6 +1358,14 @@ Master message types ``VHOST_USER_ADD_MEM_REG`` message, this message is used to set and update the memory tables of the slave device. =20 + The memory region to be removed is identified by its guest address, + user address and size. The mmap offset is ignored. + + No file descriptors SHOULD be passed in the ancillary data. For + compatibility with existing incorrect implementations, the slave MAY + accept messages with one file descriptor. If a file descriptor is + passed, the slave MUST close it without using it otherwise. + ``VHOST_USER_SET_STATUS`` :id: 39 :equivalent ioctl: VHOST_VDPA_SET_STATUS --=20 2.35.1 From nobody Sun May 19 06:23:11 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1651674774; cv=none; d=zohomail.com; s=zohoarc; b=J1oxJRuotEAoNW3v9pumx06hkENCuXgxRanaPOo7pFFCRLYwhlHpP7pEgALgVoDRZyV1h6I6U0T1vHbNnT/3N4klDhVk4IL3pjp+wGiVMXB6XwmRUVjfWqOab/LzEwpFRirTK0d8MW9PHAIKBUOa9XujOWa27QAGypRRLMPqDm4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1651674774; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=h+TE5ouz8KL2A8BCyvOWgUnAQIXdkz1rfzvortdhYEs=; b=Ov+QKoJ5hIiK6hJd7QF370Btc872fqLVNO5YkI5ixI22wF1GV456QkDMuM7bbpv9TnL72g5fORGYSZdo9+AUr9aPEDBruYefwezHDMlKg75mxu8dVgmSJ4idFQ5s5R99GuAk46FgYjggDtqZpuQNlYfr9MAZ5cQvzRpkWMX948g= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1651674774784736.8917425173174; Wed, 4 May 2022 07:32:54 -0700 (PDT) Received: from localhost ([::1]:39656 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nmG3h-0002pb-OL for importer@patchew.org; Wed, 04 May 2022 10:32:53 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43912) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nmFwf-0000os-J2 for qemu-devel@nongnu.org; Wed, 04 May 2022 10:25:37 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:57346) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nmFwe-0007Ei-1g for qemu-devel@nongnu.org; Wed, 04 May 2022 10:25:37 -0400 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-517-a4qbZ0RgP56mXEf7bli40A-1; Wed, 04 May 2022 10:25:32 -0400 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id DDDCF1C3E981; Wed, 4 May 2022 14:25:31 +0000 (UTC) Received: from merkur.str.redhat.com (dhcp-192-180.str.redhat.com [10.33.192.180]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5F4F54021A2; Wed, 4 May 2022 14:25:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1651674335; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=h+TE5ouz8KL2A8BCyvOWgUnAQIXdkz1rfzvortdhYEs=; b=aupcs/UPMNwqNnX35Einiu94/kVOdE+kN8ZNRaBn8zCPxulCGeG475N+r95sIba71tOSXN UhbGxg4W9253DeeIoB+Mg5vgCUV89OtN23JfFgqYGBzJZ0IWRNa0uvrVePCWXmNdU3X3x6 O+QyjZ8C034DoRRFgltpgL3ioaC3twc= X-MC-Unique: a4qbZ0RgP56mXEf7bli40A-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, qemu-devel@nongnu.org Subject: [PULL 03/13] libvhost-user: Fix extra vu_add/rem_mem_reg reply Date: Wed, 4 May 2022 16:25:12 +0200 Message-Id: <20220504142522.167506-4-kwolf@redhat.com> In-Reply-To: <20220504142522.167506-1-kwolf@redhat.com> References: <20220504142522.167506-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.85 on 10.11.54.9 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1651674776256100001 Content-Type: text/plain; charset="utf-8" Outside of postcopy mode, neither VHOST_USER_ADD_MEM_REG nor VHOST_USER_REM_MEM_REG are supposed to send a reply unless explicitly requested with the need_reply flag. Their current implementation always sends a reply, even if it isn't requested. This confuses the master because it will interpret the reply as a reply for the next message for which it actually expects a reply. need_reply is already handled correctly by vu_dispatch(), so just don't send a reply in the non-postcopy part of the message handler for these two commands. Signed-off-by: Kevin Wolf Message-Id: <20220407133657.155281-3-kwolf@redhat.com> Reviewed-by: Raphael Norwitz Reviewed-by: Stefan Hajnoczi Signed-off-by: Kevin Wolf --- subprojects/libvhost-user/libvhost-user.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/subprojects/libvhost-user/libvhost-user.c b/subprojects/libvho= st-user/libvhost-user.c index 47d2efc60f..eccaff5168 100644 --- a/subprojects/libvhost-user/libvhost-user.c +++ b/subprojects/libvhost-user/libvhost-user.c @@ -800,8 +800,7 @@ vu_add_mem_reg(VuDev *dev, VhostUserMsg *vmsg) { =20 DPRINT("Successfully added new region\n"); dev->nregions++; - vmsg_set_reply_u64(vmsg, 0); - return true; + return false; } } =20 @@ -874,15 +873,13 @@ vu_rem_mem_reg(VuDev *dev, VhostUserMsg *vmsg) { } } =20 - if (found) { - vmsg_set_reply_u64(vmsg, 0); - } else { + if (!found) { vu_panic(dev, "Specified region not found\n"); } =20 close(vmsg->fds[0]); =20 - return true; + return false; } =20 static bool --=20 2.35.1 From nobody Sun May 19 06:23:11 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1651674503; cv=none; d=zohomail.com; s=zohoarc; b=gTMmnRgCJ957+7SPzlG3UhjA7l9+2FrOGIJLr7FRIP9NxHHyom7xEC1rc1LTgS412nMbgFi/MDJf9CTTcYc3Q9GU+VARU3iCSmvw1k3y9lwY0T1WbzUUGUZaEKH7mE/p8g+/06TYgZB3ygq3fnq3SqMaG5dC/CJ4jGClSn6Ia1Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1651674503; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=jShNb8zjaz4KfKVWUZlXVwKcvpapd0KBg4kgStHe8Xk=; b=ameOlKS9uJZTZLQU42gCZL66MzJWILMDUKVtrXLXUkjv2QrAlnEzClrPxo9sbbAtlo0OFAk2yO2d+ZbdJsVl1HBMqxqP5agYX+W+0FLbKvhKE5nS5dqF4EdW9C5LIlYuDq10bwE00Pka6Zd+qBF3lizZOwv/+Qci6SheQnIfiXE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1651674503772577.1050808086775; Wed, 4 May 2022 07:28:23 -0700 (PDT) Received: from localhost ([::1]:57342 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nmFzI-0003ou-Ue for importer@patchew.org; Wed, 04 May 2022 10:28:20 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43894) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nmFwf-0000o3-7k for qemu-devel@nongnu.org; Wed, 04 May 2022 10:25:37 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:58752) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nmFwc-0007EI-P1 for qemu-devel@nongnu.org; Wed, 04 May 2022 10:25:36 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-470-uOWRhDOkOxWzBupqT7rXtQ-1; Wed, 04 May 2022 10:25:32 -0400 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 9B36F86B8AC; Wed, 4 May 2022 14:25:32 +0000 (UTC) Received: from merkur.str.redhat.com (dhcp-192-180.str.redhat.com [10.33.192.180]) by smtp.corp.redhat.com (Postfix) with ESMTP id 19E80402189; Wed, 4 May 2022 14:25:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1651674334; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=jShNb8zjaz4KfKVWUZlXVwKcvpapd0KBg4kgStHe8Xk=; b=C58UjT1hPfbjAJFuZkdAV91xSmHSotIBQAUxBjXtReBtqZi+i5qR6uUAh2m3W7TdSaLYdx /e9v+JwngPXjpUS8OQVUtxHlJnd6Y4O9UxQlcTDHnpaEeTmE3CTxKrGg+rWAM08rl6Hctt sDsF7WXSNA5zD7ttjBMOwG+2g7aMRt0= X-MC-Unique: uOWRhDOkOxWzBupqT7rXtQ-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, qemu-devel@nongnu.org Subject: [PULL 04/13] vhost-user: Don't pass file descriptor for VHOST_USER_REM_MEM_REG Date: Wed, 4 May 2022 16:25:13 +0200 Message-Id: <20220504142522.167506-5-kwolf@redhat.com> In-Reply-To: <20220504142522.167506-1-kwolf@redhat.com> References: <20220504142522.167506-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.85 on 10.11.54.9 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1651674506225100001 Content-Type: text/plain; charset="utf-8" The spec clarifies now that QEMU should not send a file descriptor in a request to remove a memory region. Change it accordingly. For libvhost-user, this is a bug fix that makes it compatible with rust-vmm's implementation that doesn't send a file descriptor. Keep accepting, but ignoring a file descriptor for compatibility with older QEMU versions. Signed-off-by: Kevin Wolf Message-Id: <20220407133657.155281-4-kwolf@redhat.com> Reviewed-by: Raphael Norwitz Reviewed-by: Stefan Hajnoczi Signed-off-by: Kevin Wolf --- hw/virtio/vhost-user.c | 2 +- subprojects/libvhost-user/libvhost-user.c | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c index a80315ecfc..2d434ff0bc 100644 --- a/hw/virtio/vhost-user.c +++ b/hw/virtio/vhost-user.c @@ -751,7 +751,7 @@ static int send_remove_regions(struct vhost_dev *dev, vhost_user_fill_msg_region(®ion_buffer, shadow_reg, 0); msg->payload.mem_reg.region =3D region_buffer; =20 - ret =3D vhost_user_write(dev, msg, &fd, 1); + ret =3D vhost_user_write(dev, msg, NULL, 0); if (ret < 0) { return ret; } diff --git a/subprojects/libvhost-user/libvhost-user.c b/subprojects/libvho= st-user/libvhost-user.c index eccaff5168..d0041c864b 100644 --- a/subprojects/libvhost-user/libvhost-user.c +++ b/subprojects/libvhost-user/libvhost-user.c @@ -822,15 +822,15 @@ vu_rem_mem_reg(VuDev *dev, VhostUserMsg *vmsg) { int i; bool found =3D false; =20 - if (vmsg->fd_num !=3D 1) { + if (vmsg->fd_num > 1) { vmsg_close_fds(vmsg); - vu_panic(dev, "VHOST_USER_REM_MEM_REG received %d fds - only 1 fd " + vu_panic(dev, "VHOST_USER_REM_MEM_REG received %d fds - at most 1 = fd " "should be sent for this message type", vmsg->fd_num= ); return false; } =20 if (vmsg->size < VHOST_USER_MEM_REG_SIZE) { - close(vmsg->fds[0]); + vmsg_close_fds(vmsg); vu_panic(dev, "VHOST_USER_REM_MEM_REG requires a message size of a= t " "least %d bytes and only %d bytes were received", VHOST_USER_MEM_REG_SIZE, vmsg->size); @@ -877,7 +877,7 @@ vu_rem_mem_reg(VuDev *dev, VhostUserMsg *vmsg) { vu_panic(dev, "Specified region not found\n"); } =20 - close(vmsg->fds[0]); + vmsg_close_fds(vmsg); =20 return false; } --=20 2.35.1 From nobody Sun May 19 06:23:11 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1651674770; cv=none; d=zohomail.com; s=zohoarc; b=OH6diiTELv1WikLgx9I/EQiBZMTxEg53v8qwnIOD6PcoFLSBy8QEYBX8Zt+ttjrrZjvzviz1P415qXLG0U/h3suAIUreMZWfCMbSqnT/6e5Ij23aay8+/6SxYUc0c1vwYkZeWxenurB8VEZciwNLftJMCo5Q7DVJGPza30WW6JI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1651674770; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=k3eLwBwv1jVmhyvYs1+wYGmfoQi/Isq1ZlKzAv9M9sw=; b=NQbjN3YzJ19/t59n4+9RoDdMGbRjSfDwpmULbb0PyM1Pr6qXohxyUvatVrKX4VTAShdLucwyl56ykt65XUWISwcGTBRV1knrXr3TegmKQMn+BeUZypjxViM2JHBQFksKQJiFOfNHLfiCvZgqdmOhZwgMBZHWLZI6HgHoWXwHfL8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1651674770739799.0148846394103; Wed, 4 May 2022 07:32:50 -0700 (PDT) Received: from localhost ([::1]:39304 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nmG3d-0002bz-KP for importer@patchew.org; Wed, 04 May 2022 10:32:49 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43946) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nmFwg-0000pU-Ee for qemu-devel@nongnu.org; Wed, 04 May 2022 10:25:39 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:49381) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nmFwe-0007F6-Eu for qemu-devel@nongnu.org; Wed, 04 May 2022 10:25:38 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-10-ZXqK_xdDM-GAqxBZ1riENQ-1; Wed, 04 May 2022 10:25:33 -0400 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 562EA1014A61; Wed, 4 May 2022 14:25:33 +0000 (UTC) Received: from merkur.str.redhat.com (dhcp-192-180.str.redhat.com [10.33.192.180]) by smtp.corp.redhat.com (Postfix) with ESMTP id CB4A0402189; Wed, 4 May 2022 14:25:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1651674335; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=k3eLwBwv1jVmhyvYs1+wYGmfoQi/Isq1ZlKzAv9M9sw=; b=BGvhDozemaFDBhZ3E0J1sMlitzwgkv8sU/SBoEwAaQMVrJy0Y5v5fZludV6RV3nVSVLCX7 nju/kxXQo4qxShMnXcBAGjVEhILqZ9g1ptZ91j0ms9lHoiaI0aId1BYejZxVxR2Hl9Tyge zkY3Iv91b+6tqALSNOAF/e9fHDwhN8o= X-MC-Unique: ZXqK_xdDM-GAqxBZ1riENQ-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, qemu-devel@nongnu.org Subject: [PULL 05/13] block: Classify bdrv_get_flags() as I/O function Date: Wed, 4 May 2022 16:25:14 +0200 Message-Id: <20220504142522.167506-6-kwolf@redhat.com> In-Reply-To: <20220504142522.167506-1-kwolf@redhat.com> References: <20220504142522.167506-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.85 on 10.11.54.9 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1651674772246100001 Content-Type: text/plain; charset="utf-8" From: Hanna Reitz This function is safe to call in an I/O context, and qcow2_do_open() does so (invoked in an I/O context by qcow2_co_invalidate_cache()). Signed-off-by: Hanna Reitz Message-Id: <20220427114057.36651-2-hreitz@redhat.com> Reviewed-by: Eric Blake Signed-off-by: Kevin Wolf --- include/block/block-global-state.h | 1 - include/block/block-io.h | 1 + block.c | 2 +- 3 files changed, 2 insertions(+), 2 deletions(-) diff --git a/include/block/block-global-state.h b/include/block/block-globa= l-state.h index 25bb69bbef..21265e3966 100644 --- a/include/block/block-global-state.h +++ b/include/block/block-global-state.h @@ -172,7 +172,6 @@ void bdrv_next_cleanup(BdrvNextIterator *it); BlockDriverState *bdrv_next_monitor_owned(BlockDriverState *bs); void bdrv_iterate_format(void (*it)(void *opaque, const char *name), void *opaque, bool read_only); -int bdrv_get_flags(BlockDriverState *bs); char *bdrv_get_full_backing_filename(BlockDriverState *bs, Error **errp); char *bdrv_dirname(BlockDriverState *bs, Error **errp); =20 diff --git a/include/block/block-io.h b/include/block/block-io.h index 5e3f346806..62c84f0519 100644 --- a/include/block/block-io.h +++ b/include/block/block-io.h @@ -103,6 +103,7 @@ int bdrv_apply_auto_read_only(BlockDriverState *bs, con= st char *errmsg, bool bdrv_is_read_only(BlockDriverState *bs); bool bdrv_is_writable(BlockDriverState *bs); bool bdrv_is_sg(BlockDriverState *bs); +int bdrv_get_flags(BlockDriverState *bs); bool bdrv_is_inserted(BlockDriverState *bs); void bdrv_lock_medium(BlockDriverState *bs, bool locked); void bdrv_eject(BlockDriverState *bs, bool eject_flag); diff --git a/block.c b/block.c index 8cd16e757e..2c00dddd80 100644 --- a/block.c +++ b/block.c @@ -6298,7 +6298,7 @@ const char *bdrv_get_device_or_node_name(const BlockD= riverState *bs) =20 int bdrv_get_flags(BlockDriverState *bs) { - GLOBAL_STATE_CODE(); + IO_CODE(); return bs->open_flags; } =20 --=20 2.35.1 From nobody Sun May 19 06:23:11 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1651674853; cv=none; d=zohomail.com; s=zohoarc; b=kalArf/CoHNXWHdhMnemKRS//qCmAag+BeyKWSXmml/Y4O3WtGjW5ByM55ksxq+QFk+dANZPFwy7WKj28qdIKN1eozz3kR+q5MvXPlgJPV0PohA0/eRF1ygpeNzTJorYofpsT7+E52cCUiL/FMpz5ieRJn7Y2GtozyNrsZZ5jGg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1651674853; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=CLXSn/nyPMG0gDDfnhgpYQX85htiZ5wnoZj7/jcHbL4=; b=J/skLKPzM/3ySEutAxu6ATqIZwvrv356sl9+45OnV5F1NCh0JtVhvA++ZsGWRhkHYj0EIqQ90OtEFenQugxfxQf+4whjEkqrsckro5WA9vH7BGZi/iLoqi+0UFQgKnL55K/e4H0KCQewpvGlDDwTBsFDwDFIfema0CGkRHl/QG8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1651674853819416.20124733026285; Wed, 4 May 2022 07:34:13 -0700 (PDT) Received: from localhost ([::1]:46418 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nmG4x-0007OZ-W4 for importer@patchew.org; Wed, 04 May 2022 10:34:12 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44092) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nmFwj-0000t8-Ga for qemu-devel@nongnu.org; Wed, 04 May 2022 10:25:42 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:20707) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nmFwg-0007GD-6g for qemu-devel@nongnu.org; Wed, 04 May 2022 10:25:41 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-613-QHsH3zQ5N5OG7uF10SA22g-1; Wed, 04 May 2022 10:25:34 -0400 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 11AC318E004B; Wed, 4 May 2022 14:25:34 +0000 (UTC) Received: from merkur.str.redhat.com (dhcp-192-180.str.redhat.com [10.33.192.180]) by smtp.corp.redhat.com (Postfix) with ESMTP id 863BC4021A2; Wed, 4 May 2022 14:25:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1651674337; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=CLXSn/nyPMG0gDDfnhgpYQX85htiZ5wnoZj7/jcHbL4=; b=eFX5A9Ur7S0I8UjwtOwAiYQ8+8RyJrWEqdyDRZkXyRpKtSykBB4KJPbIYAVDGTo7VUpWKq sJFL2y/kkxMic/ZfpltuosfyuWXt9NTM7e2p6JwUDvdgjk7asch97/eo4dZF5GuRHPIcdY BqRVoEpzV0GwZc5UnslzoGJUfHUcEc0= X-MC-Unique: QHsH3zQ5N5OG7uF10SA22g-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, qemu-devel@nongnu.org Subject: [PULL 06/13] qcow2: Do not reopen data_file in invalidate_cache Date: Wed, 4 May 2022 16:25:15 +0200 Message-Id: <20220504142522.167506-7-kwolf@redhat.com> In-Reply-To: <20220504142522.167506-1-kwolf@redhat.com> References: <20220504142522.167506-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.85 on 10.11.54.9 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1651674854884100001 Content-Type: text/plain; charset="utf-8" From: Hanna Reitz qcow2_co_invalidate_cache() closes and opens the qcow2 file, by calling qcow2_close() and qcow2_do_open(). These two functions must thus be usable from both a global-state and an I/O context. As they are, they are not safe to call in an I/O context, because they use bdrv_unref_child() and bdrv_open_child() to close/open the data_file child, respectively, both of which are global-state functions. When used from qcow2_co_invalidate_cache(), we do not need to close/open the data_file child, though (we do not do this for bs->file or bs->backing either), and so we should skip it in the qcow2_co_invalidate_cache() path. To do so, add a parameter to qcow2_do_open() and qcow2_close() to make them skip handling s->data_file, and have qcow2_co_invalidate_cache() exempt it from the memset() on the BDRVQcow2State. (Note that the QED driver similarly closes/opens the QED image by invoking bdrv_qed_close()+bdrv_qed_do_open(), but both functions seem safe to use in an I/O context.) Fixes: https://gitlab.com/qemu-project/qemu/-/issues/945 Signed-off-by: Hanna Reitz Message-Id: <20220427114057.36651-3-hreitz@redhat.com> Reviewed-by: Eric Blake Signed-off-by: Kevin Wolf --- block/qcow2.c | 104 ++++++++++++++++++++++++++++++-------------------- 1 file changed, 62 insertions(+), 42 deletions(-) diff --git a/block/qcow2.c b/block/qcow2.c index b5c47931ef..4f5e6440fb 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -1296,7 +1296,8 @@ static int validate_compression_type(BDRVQcow2State *= s, Error **errp) =20 /* Called with s->lock held. */ static int coroutine_fn qcow2_do_open(BlockDriverState *bs, QDict *options, - int flags, Error **errp) + int flags, bool open_data_file, + Error **errp) { ERRP_GUARD(); BDRVQcow2State *s =3D bs->opaque; @@ -1614,50 +1615,52 @@ static int coroutine_fn qcow2_do_open(BlockDriverSt= ate *bs, QDict *options, goto fail; } =20 - /* Open external data file */ - s->data_file =3D bdrv_open_child(NULL, options, "data-file", bs, - &child_of_bds, BDRV_CHILD_DATA, - true, errp); - if (*errp) { - ret =3D -EINVAL; - goto fail; - } + if (open_data_file) { + /* Open external data file */ + s->data_file =3D bdrv_open_child(NULL, options, "data-file", bs, + &child_of_bds, BDRV_CHILD_DATA, + true, errp); + if (*errp) { + ret =3D -EINVAL; + goto fail; + } =20 - if (s->incompatible_features & QCOW2_INCOMPAT_DATA_FILE) { - if (!s->data_file && s->image_data_file) { - s->data_file =3D bdrv_open_child(s->image_data_file, options, - "data-file", bs, &child_of_bds, - BDRV_CHILD_DATA, false, errp); + if (s->incompatible_features & QCOW2_INCOMPAT_DATA_FILE) { + if (!s->data_file && s->image_data_file) { + s->data_file =3D bdrv_open_child(s->image_data_file, optio= ns, + "data-file", bs, &child_of_= bds, + BDRV_CHILD_DATA, false, err= p); + if (!s->data_file) { + ret =3D -EINVAL; + goto fail; + } + } if (!s->data_file) { + error_setg(errp, "'data-file' is required for this image"); ret =3D -EINVAL; goto fail; } - } - if (!s->data_file) { - error_setg(errp, "'data-file' is required for this image"); - ret =3D -EINVAL; - goto fail; - } =20 - /* No data here */ - bs->file->role &=3D ~BDRV_CHILD_DATA; + /* No data here */ + bs->file->role &=3D ~BDRV_CHILD_DATA; =20 - /* Must succeed because we have given up permissions if anything */ - bdrv_child_refresh_perms(bs, bs->file, &error_abort); - } else { - if (s->data_file) { - error_setg(errp, "'data-file' can only be set for images with = an " - "external data file"); - ret =3D -EINVAL; - goto fail; - } + /* Must succeed because we have given up permissions if anythi= ng */ + bdrv_child_refresh_perms(bs, bs->file, &error_abort); + } else { + if (s->data_file) { + error_setg(errp, "'data-file' can only be set for images w= ith " + "an external data file"); + ret =3D -EINVAL; + goto fail; + } =20 - s->data_file =3D bs->file; + s->data_file =3D bs->file; =20 - if (data_file_is_raw(bs)) { - error_setg(errp, "data-file-raw requires a data file"); - ret =3D -EINVAL; - goto fail; + if (data_file_is_raw(bs)) { + error_setg(errp, "data-file-raw requires a data file"); + ret =3D -EINVAL; + goto fail; + } } } =20 @@ -1839,7 +1842,7 @@ static int coroutine_fn qcow2_do_open(BlockDriverStat= e *bs, QDict *options, =20 fail: g_free(s->image_data_file); - if (has_data_file(bs)) { + if (open_data_file && has_data_file(bs)) { bdrv_unref_child(bs, s->data_file); s->data_file =3D NULL; } @@ -1876,7 +1879,8 @@ static void coroutine_fn qcow2_open_entry(void *opaqu= e) BDRVQcow2State *s =3D qoc->bs->opaque; =20 qemu_co_mutex_lock(&s->lock); - qoc->ret =3D qcow2_do_open(qoc->bs, qoc->options, qoc->flags, qoc->err= p); + qoc->ret =3D qcow2_do_open(qoc->bs, qoc->options, qoc->flags, true, + qoc->errp); qemu_co_mutex_unlock(&s->lock); } =20 @@ -2714,7 +2718,7 @@ static int qcow2_inactivate(BlockDriverState *bs) return result; } =20 -static void qcow2_close(BlockDriverState *bs) +static void qcow2_do_close(BlockDriverState *bs, bool close_data_file) { BDRVQcow2State *s =3D bs->opaque; qemu_vfree(s->l1_table); @@ -2740,7 +2744,7 @@ static void qcow2_close(BlockDriverState *bs) g_free(s->image_backing_file); g_free(s->image_backing_format); =20 - if (has_data_file(bs)) { + if (close_data_file && has_data_file(bs)) { bdrv_unref_child(bs, s->data_file); s->data_file =3D NULL; } @@ -2749,11 +2753,17 @@ static void qcow2_close(BlockDriverState *bs) qcow2_free_snapshots(bs); } =20 +static void qcow2_close(BlockDriverState *bs) +{ + qcow2_do_close(bs, true); +} + static void coroutine_fn qcow2_co_invalidate_cache(BlockDriverState *bs, Error **errp) { ERRP_GUARD(); BDRVQcow2State *s =3D bs->opaque; + BdrvChild *data_file; int flags =3D s->flags; QCryptoBlock *crypto =3D NULL; QDict *options; @@ -2767,14 +2777,24 @@ static void coroutine_fn qcow2_co_invalidate_cache(= BlockDriverState *bs, crypto =3D s->crypto; s->crypto =3D NULL; =20 - qcow2_close(bs); + /* + * Do not reopen s->data_file (i.e., have qcow2_do_close() not close i= t, + * and then prevent qcow2_do_open() from opening it), because this fun= ction + * runs in the I/O path and as such we must not invoke global-state + * functions like bdrv_unref_child() and bdrv_open_child(). + */ =20 + qcow2_do_close(bs, false); + + data_file =3D s->data_file; memset(s, 0, sizeof(BDRVQcow2State)); + s->data_file =3D data_file; + options =3D qdict_clone_shallow(bs->options); =20 flags &=3D ~BDRV_O_INACTIVE; qemu_co_mutex_lock(&s->lock); - ret =3D qcow2_do_open(bs, options, flags, errp); + ret =3D qcow2_do_open(bs, options, flags, false, errp); qemu_co_mutex_unlock(&s->lock); qobject_unref(options); if (ret < 0) { --=20 2.35.1 From nobody Sun May 19 06:23:11 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1651675033; cv=none; d=zohomail.com; s=zohoarc; b=LEvKeVZUSNGIO/7vvnqGU2orMyVFU3WI5HS/JWuQiCSF17URwGymCulOYQIeENPGA/HuEnkPOFW06HGCwWQ4LfRgsBUa8RmLuspECcVkUf+/xIHUdch+bnZ476xyPYjgAOtf05gOgIjVVRr8Nq74Kcm/X8+BjbeAz+WR1D/MdN0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1651675033; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=bwrTv1nHgz7R8Rsr+X7iaBFxqQjwmzvWlujG/Ax9JIg=; b=RdbxhABlwFe2qK3/s29an0dXzVWF+4nW+DNpVFQvUzNz5FZZdPH2ornFiELdUAYx4PkKu1s2NL35jcJfZyTQ7B/E8tBRJF5Vr2OXuKhYTX7Vs/gg9I5O5Ypdfs7WVhn0SJe/WwyVyON+AxZSr8T1syDcIgYT3LD2rOQlIhBAy3k= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1651675033724432.62026777727124; Wed, 4 May 2022 07:37:13 -0700 (PDT) Received: from localhost ([::1]:54544 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nmG7s-0004dh-Mh for importer@patchew.org; Wed, 04 May 2022 10:37:12 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44166) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nmFwk-0000tp-UG for qemu-devel@nongnu.org; Wed, 04 May 2022 10:25:43 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:53155) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nmFwh-0007Gf-C1 for qemu-devel@nongnu.org; Wed, 04 May 2022 10:25:42 -0400 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-641-myJKUiyPPgOcuHMvQjGWhQ-1; Wed, 04 May 2022 10:25:35 -0400 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id C281F29ABA08; Wed, 4 May 2022 14:25:34 +0000 (UTC) Received: from merkur.str.redhat.com (dhcp-192-180.str.redhat.com [10.33.192.180]) by smtp.corp.redhat.com (Postfix) with ESMTP id 40C9C4021A3; Wed, 4 May 2022 14:25:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1651674338; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=bwrTv1nHgz7R8Rsr+X7iaBFxqQjwmzvWlujG/Ax9JIg=; b=Hs0LT9j7wMHIO60mvEKq9z5f0d09bAtBfW0sjmJP9jq8Xvq/ePJhV2jEjYOPxhX8uluLz+ xrkSN9HGOQoUbPYpIYK1ERQMC+QNxBIDlZpR2pdb76P/pvMOshlmUTdREaD3TPzZTzHIGY CMOZnm+Or/OH85lSrI4ZLUQn91TOhLo= X-MC-Unique: myJKUiyPPgOcuHMvQjGWhQ-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, qemu-devel@nongnu.org Subject: [PULL 07/13] Revert "main-loop: Disable GLOBAL_STATE_CODE() assertions" Date: Wed, 4 May 2022 16:25:16 +0200 Message-Id: <20220504142522.167506-8-kwolf@redhat.com> In-Reply-To: <20220504142522.167506-1-kwolf@redhat.com> References: <20220504142522.167506-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.85 on 10.11.54.9 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1651675035039100001 Content-Type: text/plain; charset="utf-8" From: Hanna Reitz This reverts commit b1c073490553f80594b903ceedfc7c1aef6b1b19. (We wanted to do so once the 7.1 tree opens, which has happened. The issue reported in https://gitlab.com/qemu-project/qemu/-/issues/945 should be fixed by the preceding patches.) Signed-off-by: Hanna Reitz Message-Id: <20220427114057.36651-4-hreitz@redhat.com> Reviewed-by: Eric Blake Signed-off-by: Kevin Wolf --- include/qemu/main-loop.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/include/qemu/main-loop.h b/include/qemu/main-loop.h index d3750c8e76..89bd9edefb 100644 --- a/include/qemu/main-loop.h +++ b/include/qemu/main-loop.h @@ -284,8 +284,7 @@ bool qemu_in_main_thread(void); #else #define GLOBAL_STATE_CODE() \ do { \ - /* FIXME: Re-enable after 7.0 release */ \ - /* assert(qemu_in_main_thread()); */ \ + assert(qemu_in_main_thread()); \ } while (0) #endif /* CONFIG_COCOA */ =20 --=20 2.35.1 From nobody Sun May 19 06:23:11 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1651674882; cv=none; d=zohomail.com; s=zohoarc; b=OhwtthIf2Z0NaqqZgq3tlv1C8nrM6hNQsnrBQMvAuPWfwiVIh2pzsNDX/zs4RmodgUdf06IbL1YIoKGTLUHyM2ta2rUI+5tNBYVDy3gKslZUHl+SBr2Y2R7k+qYnf+ZW+G3jZuMg1suzMO0Uklua+ZR39q4+sTpRA46Mgnh5mPw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1651674882; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=/8HRoTe5Si1EPm2zBxMmsdNODjn1RuROexxK2Q5XatA=; b=EkgbeITe/PZgr0Nq2PQmhPvNaepeYOZH+XBAUxdzNcBncGp0AyM8jufbgdf1vLubIVPUi80EQHD63m2xCVEcNpNAP2YrimHvvNQTp7vTzewHK8uH1b09hDfcDs0Wy+lQp/SaC6FiQ9FLoIV23+mhqzTJYN5w53e/VZFkeuAYVEI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1651674882935194.16002759249307; Wed, 4 May 2022 07:34:42 -0700 (PDT) Received: from localhost ([::1]:48974 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nmG5R-0000jr-ID for importer@patchew.org; Wed, 04 May 2022 10:34:41 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44182) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nmFwl-0000ty-Bt for qemu-devel@nongnu.org; Wed, 04 May 2022 10:25:44 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:48360) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nmFwh-0007Go-Le for qemu-devel@nongnu.org; Wed, 04 May 2022 10:25:42 -0400 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-278-yre8KemCOgKaVZ83S9wxhA-1; Wed, 04 May 2022 10:25:35 -0400 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 7F81B3C62B64; Wed, 4 May 2022 14:25:35 +0000 (UTC) Received: from merkur.str.redhat.com (dhcp-192-180.str.redhat.com [10.33.192.180]) by smtp.corp.redhat.com (Postfix) with ESMTP id F2607402189; Wed, 4 May 2022 14:25:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1651674339; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=/8HRoTe5Si1EPm2zBxMmsdNODjn1RuROexxK2Q5XatA=; b=W+1xpIq8CHayNnv6Vo3267dRJDFUj1u107+0ReaxZgkJBZhyLPg5hjzaSDhR2vpUq73pjF 6RzM8B8gckeDoLNhzIGtRH5IZEPas/hwlfChn08ZhGOYSQo/Wbjf+ITKUOMt951ncEhbav s7vG4cEdMlUCNng0lroW0hdW1HDQ/oY= X-MC-Unique: yre8KemCOgKaVZ83S9wxhA-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, qemu-devel@nongnu.org Subject: [PULL 08/13] iotests: Add regression test for issue 945 Date: Wed, 4 May 2022 16:25:17 +0200 Message-Id: <20220504142522.167506-9-kwolf@redhat.com> In-Reply-To: <20220504142522.167506-1-kwolf@redhat.com> References: <20220504142522.167506-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.85 on 10.11.54.9 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1651674884796100001 Content-Type: text/plain; charset="utf-8" From: Hanna Reitz Create a VM with a BDS in an iothread, add -incoming defer to the command line, and then export this BDS via NBD. Doing so should not fail an assertion. Signed-off-by: Hanna Reitz Message-Id: <20220427114057.36651-5-hreitz@redhat.com> Reviewed-by: Eric Blake Tested-by: Eric Blake Signed-off-by: Kevin Wolf --- .../tests/export-incoming-iothread | 81 +++++++++++++++++++ .../tests/export-incoming-iothread.out | 5 ++ 2 files changed, 86 insertions(+) create mode 100755 tests/qemu-iotests/tests/export-incoming-iothread create mode 100644 tests/qemu-iotests/tests/export-incoming-iothread.out diff --git a/tests/qemu-iotests/tests/export-incoming-iothread b/tests/qemu= -iotests/tests/export-incoming-iothread new file mode 100755 index 0000000000..7679e49103 --- /dev/null +++ b/tests/qemu-iotests/tests/export-incoming-iothread @@ -0,0 +1,81 @@ +#!/usr/bin/env python3 +# group: rw quick migration +# +# Regression test for issue 945: +# https://gitlab.com/qemu-project/qemu/-/issues/945 +# Test adding an export on top of an iothread-ed block device while in +# -incoming defer. +# +# Copyright (C) 2022 Red Hat, Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# + +import os +import iotests +from iotests import qemu_img_create + + +image_size =3D 1 * 1024 * 1024 +test_img =3D os.path.join(iotests.test_dir, 'test.img') +node_name =3D 'node0' +iothread_id =3D 'iothr0' + +nbd_sock =3D os.path.join(iotests.sock_dir, 'nbd.sock') + + +class TestExportIncomingIothread(iotests.QMPTestCase): + def setUp(self) -> None: + qemu_img_create('-f', iotests.imgfmt, test_img, str(image_size)) + + self.vm =3D iotests.VM() + self.vm.add_object(f'iothread,id=3D{iothread_id}') + self.vm.add_blockdev(( + f'driver=3D{iotests.imgfmt}', + f'node-name=3D{node_name}', + 'file.driver=3Dfile', + f'file.filename=3D{test_img}' + )) + self.vm.add_incoming('defer') + self.vm.launch() + + def tearDown(self): + self.vm.shutdown() + os.remove(test_img) + + def test_export_add(self): + result =3D self.vm.qmp('nbd-server-start', { + 'addr': { + 'type': 'unix', + 'data': { + 'path': nbd_sock + } + } + }) + self.assert_qmp(result, 'return', {}) + + # Regression test for issue 945: This should not fail an assertion + result =3D self.vm.qmp('block-export-add', { + 'type': 'nbd', + 'id': 'exp0', + 'node-name': node_name, + 'iothread': iothread_id + }) + self.assert_qmp(result, 'return', {}) + + +if __name__ =3D=3D '__main__': + iotests.main(supported_fmts=3D['generic'], + unsupported_fmts=3D['luks'], # Would need a secret + supported_protocols=3D['file']) diff --git a/tests/qemu-iotests/tests/export-incoming-iothread.out b/tests/= qemu-iotests/tests/export-incoming-iothread.out new file mode 100644 index 0000000000..ae1213e6f8 --- /dev/null +++ b/tests/qemu-iotests/tests/export-incoming-iothread.out @@ -0,0 +1,5 @@ +. +---------------------------------------------------------------------- +Ran 1 tests + +OK --=20 2.35.1 From nobody Sun May 19 06:23:11 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1651674765; cv=none; d=zohomail.com; s=zohoarc; b=Rps70pDVqCwCmmMTyIBMwuSMC55mSKtE5cvrqozlmecwvLcAV4bL2UZMZz+OpvNhhHdbCzrksnhnKve7m4M2peBEf4r7xNeI5PxbcvfYhD/IXwa8Go3jjIp7EC44luyBJ1NsUQj1T+vKgw148HU/cfNYsd1QCRD72s6GjyqqujU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1651674765; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=E7xwsxesBQ+3VuWv6RvchuwUM5KU8fumXkBFuXRjQwk=; b=ASsHhI+sSvUNpwtXocdj8VOK28o9ycyL7WJjmHz9Y79VvtNRK1W8Ta6RZw6bnSgJCykSg7yO+p0RkhJUZTQFzeyPh1VtWqazHr23ynGf/BIDysLnue5a6AOdCzKfFs097+0z791MjWpgQKx8EpzPn5S9UmIKQwXiQmA7/zKif8k= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1651674765669299.58742256256085; Wed, 4 May 2022 07:32:45 -0700 (PDT) Received: from localhost ([::1]:38918 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nmG3Y-0002Kt-4g for importer@patchew.org; Wed, 04 May 2022 10:32:44 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44170) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nmFwk-0000tq-Un for qemu-devel@nongnu.org; Wed, 04 May 2022 10:25:43 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:31909) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nmFwi-0007HA-9U for qemu-devel@nongnu.org; Wed, 04 May 2022 10:25:42 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-371-Zdq_0Z4nMwuYJryLv9mhmA-1; Wed, 04 May 2022 10:25:36 -0400 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 3A6C88039D7; Wed, 4 May 2022 14:25:36 +0000 (UTC) Received: from merkur.str.redhat.com (dhcp-192-180.str.redhat.com [10.33.192.180]) by smtp.corp.redhat.com (Postfix) with ESMTP id AF625402189; Wed, 4 May 2022 14:25:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1651674339; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=E7xwsxesBQ+3VuWv6RvchuwUM5KU8fumXkBFuXRjQwk=; b=L0QHtM7C8IG8C+TcTTVhJr9KilNS6wzCqSDgoe/VhTOvZFQOSB1Kf38TGOhvn0765rw78Q zr9Cyk+85c/NsKmgPFp55Jr4oNhqEubPF6n+ciXI/AWL6u4T4MVU0wVVgfUVBkhUSjFnL8 xWu8nUtlOGCKZFnzkConREl1ReOsh28= X-MC-Unique: Zdq_0Z4nMwuYJryLv9mhmA-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, qemu-devel@nongnu.org Subject: [PULL 09/13] block/vmdk: Fix reopening bs->file Date: Wed, 4 May 2022 16:25:18 +0200 Message-Id: <20220504142522.167506-10-kwolf@redhat.com> In-Reply-To: <20220504142522.167506-1-kwolf@redhat.com> References: <20220504142522.167506-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.85 on 10.11.54.9 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1651674766236100001 Content-Type: text/plain; charset="utf-8" From: Hanna Reitz VMDK disk data is stored in extents, which may or may not be separate from bs->file. VmdkExtent.file points to where they are stored. Each that is stored in bs->file will simply reuse the exact pointer value of bs->file. (That is why vmdk_free_extents() will unref VmdkExtent.file (e->file) only if e->file !=3D bs->file.) Reopen operations can change bs->file (they will replace the whole BdrvChild object, not just the BDS stored in that BdrvChild), and then we will need to change all .file pointers of all such VmdkExtents to point to the new BdrvChild. In vmdk_reopen_prepare(), we have to check which VmdkExtents are affected, and in vmdk_reopen_commit(), we can modify them. We have to split this because: - The new BdrvChild is created only after prepare, so we can change VmdkExtent.file only in commit - In commit, there no longer is any (valid) reference to the old BdrvChild object, so there would be nothing to compare VmdkExtent.file against to see whether it was equal to bs->file before reopening (There is BDRVReopenState.old_file_bs, but the old bs->file BdrvChild's .bs pointer will be NULL-ed when the new BdrvChild is created, and so we cannot compare VmdkExtent.file->bs against BDRVReopenState.old_file_bs) Signed-off-by: Hanna Reitz Message-Id: <20220314162719.65384-2-hreitz@redhat.com> Signed-off-by: Kevin Wolf --- block/vmdk.c | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 55 insertions(+), 1 deletion(-) diff --git a/block/vmdk.c b/block/vmdk.c index 37c0946066..38e5ab3806 100644 --- a/block/vmdk.c +++ b/block/vmdk.c @@ -178,6 +178,10 @@ typedef struct BDRVVmdkState { char *create_type; } BDRVVmdkState; =20 +typedef struct BDRVVmdkReopenState { + bool *extents_using_bs_file; +} BDRVVmdkReopenState; + typedef struct VmdkMetaData { unsigned int l1_index; unsigned int l2_index; @@ -400,15 +404,63 @@ static int vmdk_is_cid_valid(BlockDriverState *bs) return 1; } =20 -/* We have nothing to do for VMDK reopen, stubs just return success */ static int vmdk_reopen_prepare(BDRVReopenState *state, BlockReopenQueue *queue, Error **errp) { + BDRVVmdkState *s; + BDRVVmdkReopenState *rs; + int i; + assert(state !=3D NULL); assert(state->bs !=3D NULL); + assert(state->opaque =3D=3D NULL); + + s =3D state->bs->opaque; + + rs =3D g_new0(BDRVVmdkReopenState, 1); + state->opaque =3D rs; + + /* + * Check whether there are any extents stored in bs->file; if bs->file + * changes, we will need to update their .file pointers to follow suit + */ + rs->extents_using_bs_file =3D g_new(bool, s->num_extents); + for (i =3D 0; i < s->num_extents; i++) { + rs->extents_using_bs_file[i] =3D s->extents[i].file =3D=3D state->= bs->file; + } + return 0; } =20 +static void vmdk_reopen_clean(BDRVReopenState *state) +{ + BDRVVmdkReopenState *rs =3D state->opaque; + + g_free(rs->extents_using_bs_file); + g_free(rs); + state->opaque =3D NULL; +} + +static void vmdk_reopen_commit(BDRVReopenState *state) +{ + BDRVVmdkState *s =3D state->bs->opaque; + BDRVVmdkReopenState *rs =3D state->opaque; + int i; + + for (i =3D 0; i < s->num_extents; i++) { + if (rs->extents_using_bs_file[i]) { + s->extents[i].file =3D state->bs->file; + } + } + + vmdk_reopen_clean(state); +} + +static void vmdk_reopen_abort(BDRVReopenState *state) +{ + vmdk_reopen_clean(state); +} + static int vmdk_parent_open(BlockDriverState *bs) { char *p_name; @@ -3072,6 +3124,8 @@ static BlockDriver bdrv_vmdk =3D { .bdrv_open =3D vmdk_open, .bdrv_co_check =3D vmdk_co_check, .bdrv_reopen_prepare =3D vmdk_reopen_prepare, + .bdrv_reopen_commit =3D vmdk_reopen_commit, + .bdrv_reopen_abort =3D vmdk_reopen_abort, .bdrv_child_perm =3D bdrv_default_perms, .bdrv_co_preadv =3D vmdk_co_preadv, .bdrv_co_pwritev =3D vmdk_co_pwritev, --=20 2.35.1 From nobody Sun May 19 06:23:11 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1651674515; cv=none; d=zohomail.com; s=zohoarc; b=N/6hI8g+l/CEeuwccjyPzEpGS8/E2ygNTzbY3GpKOJ7MfoSD6I06BiUFqa8FSKNKDlTjgfilJwOW6pm21OQ0FkN8z0RxPHyllafNl4Fc3/R7O1taFNWsFxnPF/5PRGxwFRduijuwEoRco5YRyCdpUH474MCj68sqc5+mS5rriDU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1651674515; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=c7u9B8zZJ2FkOFZ8LOS4U5oMNmKJnFbcVYLWMhgki4U=; b=jv9jv7GTnz9hPZFUr36Y9ciLP9LXJWdBUmQr0AmeBlrYftW+RPPVTr3dC73KmxUQNAcIWqgt9/CDbjJZzWgDoeadExMFltw4ob/mI4XKJHAmQHKOIfMiYvrAcXt2K4w7hqMRFWlpSknZPf0OeB6cArtBq9trQ7pjEbS3qPaQc2o= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1651674515473194.09124389622093; Wed, 4 May 2022 07:28:35 -0700 (PDT) Received: from localhost ([::1]:58028 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nmFzW-0004J2-3T for importer@patchew.org; Wed, 04 May 2022 10:28:34 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44158) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nmFwk-0000tl-Sp for qemu-devel@nongnu.org; Wed, 04 May 2022 10:25:43 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:33425) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nmFwh-0007Ge-CA for qemu-devel@nongnu.org; Wed, 04 May 2022 10:25:41 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-258-lS3SMvjWPGOGP1gZZyraNg-1; Wed, 04 May 2022 10:25:37 -0400 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id EA799800186; Wed, 4 May 2022 14:25:36 +0000 (UTC) Received: from merkur.str.redhat.com (dhcp-192-180.str.redhat.com [10.33.192.180]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6AAA64021A2; Wed, 4 May 2022 14:25:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1651674338; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=c7u9B8zZJ2FkOFZ8LOS4U5oMNmKJnFbcVYLWMhgki4U=; b=RVflZWRVJgLdOSwpfm79wb6M5dmeOb+stsJzcWMhjc+/G4qV24VXSw/uaTWRres09RvmQi vQ4GHzXFM7BwGDzOI9611eMil9OsZ4WkGRqVI0RRshaQNks7bOaz+RFnu3opIPASRFJ9Oa GoswTCCG+gJs1MIyDoA9unSuvNGbZKg= X-MC-Unique: lS3SMvjWPGOGP1gZZyraNg-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, qemu-devel@nongnu.org Subject: [PULL 10/13] iotests/reopen-file: Test reopening file child Date: Wed, 4 May 2022 16:25:19 +0200 Message-Id: <20220504142522.167506-11-kwolf@redhat.com> In-Reply-To: <20220504142522.167506-1-kwolf@redhat.com> References: <20220504142522.167506-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.85 on 10.11.54.9 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1651674515868100002 Content-Type: text/plain; charset="utf-8" From: Hanna Reitz This should work for all format drivers that support reopening, so test it. (This serves as a regression test for HEAD^: This test used to fail for VMDK before HEAD^.) Signed-off-by: Hanna Reitz Message-Id: <20220314162719.65384-3-hreitz@redhat.com> Signed-off-by: Kevin Wolf --- tests/qemu-iotests/tests/reopen-file | 89 ++++++++++++++++++++++++ tests/qemu-iotests/tests/reopen-file.out | 5 ++ 2 files changed, 94 insertions(+) create mode 100755 tests/qemu-iotests/tests/reopen-file create mode 100644 tests/qemu-iotests/tests/reopen-file.out diff --git a/tests/qemu-iotests/tests/reopen-file b/tests/qemu-iotests/test= s/reopen-file new file mode 100755 index 0000000000..8590a94d53 --- /dev/null +++ b/tests/qemu-iotests/tests/reopen-file @@ -0,0 +1,89 @@ +#!/usr/bin/env python3 +# group: rw quick +# +# Test reopening a format driver's file child +# +# Copyright (C) 2022 Red Hat, Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# + +import os +import iotests +from iotests import imgfmt, qemu_img_create, QMPTestCase + + +image_size =3D 1 * 1024 * 1024 +test_img =3D os.path.join(iotests.test_dir, 'test.img') + + +class TestReopenFile(QMPTestCase): + def setUp(self) -> None: + res =3D qemu_img_create('-f', imgfmt, test_img, str(image_size)) + assert res.returncode =3D=3D 0 + + # Add format driver node ('format') on top of the file ('file'), t= hen + # add another raw node ('raw') on top of 'file' so for the reopen = we + # can just switch from 'file' to 'raw' + self.vm =3D iotests.VM() + self.vm.add_blockdev(self.vm.qmp_to_opts({ + 'driver': imgfmt, + 'node-name': 'format', + 'file': { + 'driver': 'file', + 'node-name': 'file', + 'filename': test_img + } + })) + self.vm.add_blockdev(self.vm.qmp_to_opts({ + 'driver': 'raw', + 'node-name': 'raw', + 'file': 'file' + })) + self.vm.launch() + + def tearDown(self) -> None: + self.vm.shutdown() + os.remove(test_img) + + # Check if there was any qemu-io run that failed + if 'Pattern verification failed' in self.vm.get_log(): + print('ERROR: Pattern verification failed:') + print(self.vm.get_log()) + self.fail('qemu-io pattern verification failed') + + def test_reopen_file(self) -> None: + result =3D self.vm.qmp('blockdev-reopen', options=3D[{ + 'driver': imgfmt, + 'node-name': 'format', + 'file': 'raw' + }]) + self.assert_qmp(result, 'return', {}) + + # Do some I/O to the image to see whether it still works + # (Pattern verification will be checked by tearDown()) + result =3D self.vm.qmp('human-monitor-command', + command_line=3D'qemu-io format "write -P 42 0= 64k"') + self.assert_qmp(result, 'return', '') + + result =3D self.vm.qmp('human-monitor-command', + command_line=3D'qemu-io format "read -P 42 0 = 64k"') + self.assert_qmp(result, 'return', '') + + +if __name__ =3D=3D '__main__': + # Must support creating images and reopen + iotests.main(supported_fmts=3D['qcow', 'qcow2', 'qed', 'raw', 'vdi', '= vhdx', + 'vmdk', 'vpc'], + supported_protocols=3D['file']) diff --git a/tests/qemu-iotests/tests/reopen-file.out b/tests/qemu-iotests/= tests/reopen-file.out new file mode 100644 index 0000000000..ae1213e6f8 --- /dev/null +++ b/tests/qemu-iotests/tests/reopen-file.out @@ -0,0 +1,5 @@ +. +---------------------------------------------------------------------- +Ran 1 tests + +OK --=20 2.35.1 From nobody Sun May 19 06:23:11 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1651674862; cv=none; d=zohomail.com; s=zohoarc; b=GZotm0+iCk9QYNmOa7rIPETsrRZ9w0Eyje33/7V0KRcFevz8o4P3ioiuruhSTzh7UZgM5O+abXCtVKgioLaLq/Y/CK3LQJGfxqK3sl3fvzxK6lSHKAeQ0pVn5JB2nzv3UN5strRYVoqWpOnxkSPssk5XcQFv00+i+KmmBageGHc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1651674862; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=PJdPU0b9Q2J3QqG8M5+vlXeikGiGvdzhsO1C5GkBCUo=; b=m1kZ9HLy2lX8kN0YZ34rhpbIFDBSmTll4IEl2VLeotxJEOyWuKm297mX0IoBGPEIwSL21XQQyqHAkXf22oJbdG0iCdxhNYZ2BYDr7uPqPSGiB2qIwt1lWIyogLo5DR9MsOYf+PEISCCj7LVLA/3ZWGBWrVUXXNtsMN+qDW0vOc8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1651674862979720.6669519779753; Wed, 4 May 2022 07:34:22 -0700 (PDT) Received: from localhost ([::1]:47282 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nmG57-00080c-Qo for importer@patchew.org; Wed, 04 May 2022 10:34:21 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44276) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nmFwn-0000wG-MY for qemu-devel@nongnu.org; Wed, 04 May 2022 10:25:46 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:46203) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nmFwk-0007IN-Jg for qemu-devel@nongnu.org; Wed, 04 May 2022 10:25:45 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-547-oLtpN51TPaSssLKr_dhrdA-1; Wed, 04 May 2022 10:25:38 -0400 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 39C96185A7A4; Wed, 4 May 2022 14:25:38 +0000 (UTC) Received: from merkur.str.redhat.com (dhcp-192-180.str.redhat.com [10.33.192.180]) by smtp.corp.redhat.com (Postfix) with ESMTP id 270D1402189; Wed, 4 May 2022 14:25:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1651674341; 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=PJdPU0b9Q2J3QqG8M5+vlXeikGiGvdzhsO1C5GkBCUo=; b=EXtbkxjbQrE8zaC15Othp/++bd0tA3W4BU9ASkaht3IsNjblZTC1R4fGe8teZQsJPdNzuZ b77lkE+VSj+I8OHvG0HQopqjqVsKrCIH14NGVnCJcbTSC+Y2EmJRqwj3AVmHq4Zl/hNv1c 6a1FUk/hiwLgbuD27wysNJwmf2Wxcjw= X-MC-Unique: oLtpN51TPaSssLKr_dhrdA-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, qemu-devel@nongnu.org Subject: [PULL 11/13] coroutine-ucontext: use QEMU_DEFINE_STATIC_CO_TLS() Date: Wed, 4 May 2022 16:25:20 +0200 Message-Id: <20220504142522.167506-12-kwolf@redhat.com> In-Reply-To: <20220504142522.167506-1-kwolf@redhat.com> References: <20220504142522.167506-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.85 on 10.11.54.9 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1651674864835100001 From: Stefan Hajnoczi Thread-Local Storage variables cannot be used directly from coroutine code because the compiler may optimize TLS variable accesses across qemu_coroutine_yield() calls. When the coroutine is re-entered from another thread the TLS variables from the old thread must no longer be used. Use QEMU_DEFINE_STATIC_CO_TLS() for the current and leader variables. Signed-off-by: Stefan Hajnoczi Message-Id: <20220307153853.602859-2-stefanha@redhat.com> Reviewed-by: Philippe Mathieu-Daud=C3=A9 Signed-off-by: Kevin Wolf --- util/coroutine-ucontext.c | 38 ++++++++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/util/coroutine-ucontext.c b/util/coroutine-ucontext.c index ed368e1a3e..ddc98fb4f8 100644 --- a/util/coroutine-ucontext.c +++ b/util/coroutine-ucontext.c @@ -25,6 +25,7 @@ #include "qemu/osdep.h" #include #include "qemu/coroutine_int.h" +#include "qemu/coroutine-tls.h" =20 #ifdef CONFIG_VALGRIND_H #include @@ -66,8 +67,8 @@ typedef struct { /** * Per-thread coroutine bookkeeping */ -static __thread CoroutineUContext leader; -static __thread Coroutine *current; +QEMU_DEFINE_STATIC_CO_TLS(Coroutine *, current); +QEMU_DEFINE_STATIC_CO_TLS(CoroutineUContext, leader); =20 /* * va_args to makecontext() must be type 'int', so passing @@ -97,14 +98,15 @@ static inline __attribute__((always_inline)) void finish_switch_fiber(void *fake_stack_save) { #ifdef CONFIG_ASAN + CoroutineUContext *leaderp =3D get_ptr_leader(); const void *bottom_old; size_t size_old; =20 __sanitizer_finish_switch_fiber(fake_stack_save, &bottom_old, &size_ol= d); =20 - if (!leader.stack) { - leader.stack =3D (void *)bottom_old; - leader.stack_size =3D size_old; + if (!leaderp->stack) { + leaderp->stack =3D (void *)bottom_old; + leaderp->stack_size =3D size_old; } #endif #ifdef CONFIG_TSAN @@ -161,8 +163,10 @@ static void coroutine_trampoline(int i0, int i1) =20 /* Initialize longjmp environment and switch back the caller */ if (!sigsetjmp(self->env, 0)) { - start_switch_fiber_asan(COROUTINE_YIELD, &fake_stack_save, leader.= stack, - leader.stack_size); + CoroutineUContext *leaderp =3D get_ptr_leader(); + + start_switch_fiber_asan(COROUTINE_YIELD, &fake_stack_save, + leaderp->stack, leaderp->stack_size); start_switch_fiber_tsan(&fake_stack_save, self, true); /* true=3Dc= aller */ siglongjmp(*(sigjmp_buf *)co->entry_arg, 1); } @@ -297,7 +301,7 @@ qemu_coroutine_switch(Coroutine *from_, Coroutine *to_, int ret; void *fake_stack_save =3D NULL; =20 - current =3D to_; + set_current(to_); =20 ret =3D sigsetjmp(from->env, 0); if (ret =3D=3D 0) { @@ -315,18 +319,24 @@ qemu_coroutine_switch(Coroutine *from_, Coroutine *to= _, =20 Coroutine *qemu_coroutine_self(void) { - if (!current) { - current =3D &leader.base; + Coroutine *self =3D get_current(); + CoroutineUContext *leaderp =3D get_ptr_leader(); + + if (!self) { + self =3D &leaderp->base; + set_current(self); } #ifdef CONFIG_TSAN - if (!leader.tsan_co_fiber) { - leader.tsan_co_fiber =3D __tsan_get_current_fiber(); + if (!leaderp->tsan_co_fiber) { + leaderp->tsan_co_fiber =3D __tsan_get_current_fiber(); } #endif - return current; + return self; } =20 bool qemu_in_coroutine(void) { - return current && current->caller; + Coroutine *self =3D get_current(); + + return self && self->caller; } --=20 2.35.1 From nobody Sun May 19 06:23:11 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1651675135; cv=none; d=zohomail.com; s=zohoarc; b=F/6H78c68/se9+aPv/hBRklguxbM9TrHrbqrJozx50JxOhcDeZ24wtyUPbc2N8EBWbrG27hjskC3VLM3fZ3066Nu8Qf9HPGmxqwjc9bfDplAmMFd8hS5WejIVOkJ3yZhDdd6r9BmcBApistlTYgoxrd5BLR2udg8qGVFcBcUv2Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1651675135; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=pgJsgpcMfue21DBQk6EWb/0FL3uN14JD9qhyUMZZ3Zs=; b=lF2LIDIHWW5/IxnUWJJAex61T0CUQnZZW5zJoULpFZibP8CUbCr68M468IEgEb7XXEde2M7NwkjTNm06AvzWBIneDztSyJ04fpPU4OzPIG1gc+MOBVCl0ti2/JWalJKjKUiSAqdOTzF81wVEbXRdytPTf19Jfm2PNVPuNIcm5Wk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1651675135299214.40572553706545; Wed, 4 May 2022 07:38:55 -0700 (PDT) Received: from localhost ([::1]:34460 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nmG9V-0001ec-Uo for importer@patchew.org; Wed, 04 May 2022 10:38:53 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44256) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nmFwn-0000v9-6L for qemu-devel@nongnu.org; Wed, 04 May 2022 10:25:45 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:46652) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nmFwj-0007Hh-7Q for qemu-devel@nongnu.org; Wed, 04 May 2022 10:25:44 -0400 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-321-t96ITecHMdK4Jx61H5qFIA-1; Wed, 04 May 2022 10:25:39 -0400 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E963F1C3E983; Wed, 4 May 2022 14:25:38 +0000 (UTC) Received: from merkur.str.redhat.com (dhcp-192-180.str.redhat.com [10.33.192.180]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6972A402189; Wed, 4 May 2022 14:25:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1651674340; 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=pgJsgpcMfue21DBQk6EWb/0FL3uN14JD9qhyUMZZ3Zs=; b=aaP9XhIL4Vrql6lWpXcKKqqurjB9bEwTgyayrrcHZRcu3C+5bS5q8g7JBjHvjlmQDg6FY2 v47gOpJvX7ycBcDAECkSYTd1CtlrHD+Zk9rrOfYTwy83IdwTPXK3RNFzHUiEoK1uWyNoGo Cy+5dEufW5rH6m8iZB2AqyM8muJ17tw= X-MC-Unique: t96ITecHMdK4Jx61H5qFIA-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, qemu-devel@nongnu.org Subject: [PULL 12/13] coroutine: use QEMU_DEFINE_STATIC_CO_TLS() Date: Wed, 4 May 2022 16:25:21 +0200 Message-Id: <20220504142522.167506-13-kwolf@redhat.com> In-Reply-To: <20220504142522.167506-1-kwolf@redhat.com> References: <20220504142522.167506-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.85 on 10.11.54.9 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1651675137285100001 From: Stefan Hajnoczi Thread-Local Storage variables cannot be used directly from coroutine code because the compiler may optimize TLS variable accesses across qemu_coroutine_yield() calls. When the coroutine is re-entered from another thread the TLS variables from the old thread must no longer be used. Use QEMU_DEFINE_STATIC_CO_TLS() for the current and leader variables. The alloc_pool QSLIST needs a typedef so the return value of get_ptr_alloc_pool() can be stored in a local variable. One example of why this code is necessary: a coroutine that yields before calling qemu_coroutine_create() to create another coroutine is affected by the TLS issue. Signed-off-by: Stefan Hajnoczi Message-Id: <20220307153853.602859-3-stefanha@redhat.com> Reviewed-by: Philippe Mathieu-Daud=C3=A9 Signed-off-by: Kevin Wolf --- util/qemu-coroutine.c | 41 ++++++++++++++++++++++++----------------- 1 file changed, 24 insertions(+), 17 deletions(-) diff --git a/util/qemu-coroutine.c b/util/qemu-coroutine.c index c03b2422ff..f3e8300c8d 100644 --- a/util/qemu-coroutine.c +++ b/util/qemu-coroutine.c @@ -18,6 +18,7 @@ #include "qemu/atomic.h" #include "qemu/coroutine.h" #include "qemu/coroutine_int.h" +#include "qemu/coroutine-tls.h" #include "block/aio.h" =20 /** Initial batch size is 64, and is increased on demand */ @@ -29,17 +30,20 @@ enum { static QSLIST_HEAD(, Coroutine) release_pool =3D QSLIST_HEAD_INITIALIZER(p= ool); static unsigned int pool_batch_size =3D POOL_INITIAL_BATCH_SIZE; static unsigned int release_pool_size; -static __thread QSLIST_HEAD(, Coroutine) alloc_pool =3D QSLIST_HEAD_INITIA= LIZER(pool); -static __thread unsigned int alloc_pool_size; -static __thread Notifier coroutine_pool_cleanup_notifier; + +typedef QSLIST_HEAD(, Coroutine) CoroutineQSList; +QEMU_DEFINE_STATIC_CO_TLS(CoroutineQSList, alloc_pool); +QEMU_DEFINE_STATIC_CO_TLS(unsigned int, alloc_pool_size); +QEMU_DEFINE_STATIC_CO_TLS(Notifier, coroutine_pool_cleanup_notifier); =20 static void coroutine_pool_cleanup(Notifier *n, void *value) { Coroutine *co; Coroutine *tmp; + CoroutineQSList *alloc_pool =3D get_ptr_alloc_pool(); =20 - QSLIST_FOREACH_SAFE(co, &alloc_pool, pool_next, tmp) { - QSLIST_REMOVE_HEAD(&alloc_pool, pool_next); + QSLIST_FOREACH_SAFE(co, alloc_pool, pool_next, tmp) { + QSLIST_REMOVE_HEAD(alloc_pool, pool_next); qemu_coroutine_delete(co); } } @@ -49,27 +53,30 @@ Coroutine *qemu_coroutine_create(CoroutineEntry *entry,= void *opaque) Coroutine *co =3D NULL; =20 if (CONFIG_COROUTINE_POOL) { - co =3D QSLIST_FIRST(&alloc_pool); + CoroutineQSList *alloc_pool =3D get_ptr_alloc_pool(); + + co =3D QSLIST_FIRST(alloc_pool); if (!co) { if (release_pool_size > qatomic_read(&pool_batch_size)) { /* Slow path; a good place to register the destructor, too= . */ - if (!coroutine_pool_cleanup_notifier.notify) { - coroutine_pool_cleanup_notifier.notify =3D coroutine_p= ool_cleanup; - qemu_thread_atexit_add(&coroutine_pool_cleanup_notifie= r); + Notifier *notifier =3D get_ptr_coroutine_pool_cleanup_noti= fier(); + if (!notifier->notify) { + notifier->notify =3D coroutine_pool_cleanup; + qemu_thread_atexit_add(notifier); } =20 /* This is not exact; there could be a little skew between * release_pool_size and the actual size of release_pool. = But * it is just a heuristic, it does not need to be perfect. */ - alloc_pool_size =3D qatomic_xchg(&release_pool_size, 0); - QSLIST_MOVE_ATOMIC(&alloc_pool, &release_pool); - co =3D QSLIST_FIRST(&alloc_pool); + set_alloc_pool_size(qatomic_xchg(&release_pool_size, 0)); + QSLIST_MOVE_ATOMIC(alloc_pool, &release_pool); + co =3D QSLIST_FIRST(alloc_pool); } } if (co) { - QSLIST_REMOVE_HEAD(&alloc_pool, pool_next); - alloc_pool_size--; + QSLIST_REMOVE_HEAD(alloc_pool, pool_next); + set_alloc_pool_size(get_alloc_pool_size() - 1); } } =20 @@ -93,9 +100,9 @@ static void coroutine_delete(Coroutine *co) qatomic_inc(&release_pool_size); return; } - if (alloc_pool_size < qatomic_read(&pool_batch_size)) { - QSLIST_INSERT_HEAD(&alloc_pool, co, pool_next); - alloc_pool_size++; + if (get_alloc_pool_size() < qatomic_read(&pool_batch_size)) { + QSLIST_INSERT_HEAD(get_ptr_alloc_pool(), co, pool_next); + set_alloc_pool_size(get_alloc_pool_size() + 1); return; } } --=20 2.35.1 From nobody Sun May 19 06:23:11 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1651675081; cv=none; d=zohomail.com; s=zohoarc; b=UMJp06kyonndmtRztZYb5zntfAebI2blIrxATxsxvV/kFYeMoGY+/vhy1aWgOucucWIXavF/Zqx0P8o9WVOyBossc+IdS16+HQI6HWyRngBg/XFVovsG2AZdWal10mNsBXw6PcwewlEBJaCbGb0z9xhFAStvwSJjE6s7z08B3RY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1651675081; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=WLs/ZyOmTap6tSoe0X8sZsyHCHNLeD5jO0y/BaAN5Uo=; b=oBaIc5yX6rQiyuwtaeLfdYDSu84PZYPtHOI1Amiio5b97DNkYSgIX2H0i/gTpvYRNOr8kQNwFt/byQMlJKgpwb4IitRWJgIVMumSqxTbpxBx0a38KpXpj0jABUX0T65FbL1FNIHe+87xZ8pFpbr1XFlIIu5ks6ElylOXDzOuiH4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1651675081230502.0602001720828; Wed, 4 May 2022 07:38:01 -0700 (PDT) Received: from localhost ([::1]:57916 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nmG8e-0006t1-6N for importer@patchew.org; Wed, 04 May 2022 10:38:00 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44254) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nmFwn-0000v8-6I for qemu-devel@nongnu.org; Wed, 04 May 2022 10:25:45 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:45616) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nmFwk-0007I2-JQ for qemu-devel@nongnu.org; Wed, 04 May 2022 10:25:44 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-561-A-edhbaSMZ-g1fMyii9IOg-1; Wed, 04 May 2022 10:25:40 -0400 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id A46A5801E80; Wed, 4 May 2022 14:25:39 +0000 (UTC) Received: from merkur.str.redhat.com (dhcp-192-180.str.redhat.com [10.33.192.180]) by smtp.corp.redhat.com (Postfix) with ESMTP id 254D7402189; Wed, 4 May 2022 14:25:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1651674341; 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=WLs/ZyOmTap6tSoe0X8sZsyHCHNLeD5jO0y/BaAN5Uo=; b=fqSjv00vhtDKWdrJXObWrwxK7Lf3Rjg9mjBuHssZ4UGL18GcZdzSnQ3HlCb6/4GJPrEtjo 2WMN56Wp3UBfv6dJwf4QOtklF/z266c0oMVj+61cy8BX1FXyCo0tYuJQn0mMXxvH5KSEKl kiTjviO602rkkvRsa6i7CfwYMAs3F7I= X-MC-Unique: A-edhbaSMZ-g1fMyii9IOg-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, qemu-devel@nongnu.org Subject: [PULL 13/13] coroutine-win32: use QEMU_DEFINE_STATIC_CO_TLS() Date: Wed, 4 May 2022 16:25:22 +0200 Message-Id: <20220504142522.167506-14-kwolf@redhat.com> In-Reply-To: <20220504142522.167506-1-kwolf@redhat.com> References: <20220504142522.167506-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.85 on 10.11.54.9 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1651675082985100001 From: Stefan Hajnoczi Thread-Local Storage variables cannot be used directly from coroutine code because the compiler may optimize TLS variable accesses across qemu_coroutine_yield() calls. When the coroutine is re-entered from another thread the TLS variables from the old thread must no longer be used. Use QEMU_DEFINE_STATIC_CO_TLS() for the current and leader variables. I think coroutine-win32.c could get away with __thread because the variables are only used in situations where either the stale value is correct (current) or outside coroutine context (loading leader when current is NULL). Due to the difficulty of being sure that this is really safe in all scenarios it seems worth converting it anyway. Signed-off-by: Stefan Hajnoczi Message-Id: <20220307153853.602859-4-stefanha@redhat.com> Reviewed-by: Philippe Mathieu-Daud=C3=A9 Signed-off-by: Kevin Wolf --- util/coroutine-win32.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/util/coroutine-win32.c b/util/coroutine-win32.c index c196f956d2..7db2e8f8c8 100644 --- a/util/coroutine-win32.c +++ b/util/coroutine-win32.c @@ -24,6 +24,7 @@ =20 #include "qemu/osdep.h" #include "qemu/coroutine_int.h" +#include "qemu/coroutine-tls.h" =20 typedef struct { @@ -33,8 +34,8 @@ typedef struct CoroutineAction action; } CoroutineWin32; =20 -static __thread CoroutineWin32 leader; -static __thread Coroutine *current; +QEMU_DEFINE_STATIC_CO_TLS(CoroutineWin32, leader); +QEMU_DEFINE_STATIC_CO_TLS(Coroutine *, current); =20 /* This function is marked noinline to prevent GCC from inlining it * into coroutine_trampoline(). If we allow it to do that then it @@ -51,7 +52,7 @@ qemu_coroutine_switch(Coroutine *from_, Coroutine *to_, CoroutineWin32 *from =3D DO_UPCAST(CoroutineWin32, base, from_); CoroutineWin32 *to =3D DO_UPCAST(CoroutineWin32, base, to_); =20 - current =3D to_; + set_current(to_); =20 to->action =3D action; SwitchToFiber(to->fiber); @@ -88,14 +89,21 @@ void qemu_coroutine_delete(Coroutine *co_) =20 Coroutine *qemu_coroutine_self(void) { + Coroutine *current =3D get_current(); + if (!current) { - current =3D &leader.base; - leader.fiber =3D ConvertThreadToFiber(NULL); + CoroutineWin32 *leader =3D get_ptr_leader(); + + current =3D &leader->base; + set_current(current); + leader->fiber =3D ConvertThreadToFiber(NULL); } return current; } =20 bool qemu_in_coroutine(void) { + Coroutine *current =3D get_current(); + return current && current->caller; } --=20 2.35.1