From nobody Thu Dec 26 13:38:46 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=1718127483; cv=none; d=zohomail.com; s=zohoarc; b=jIqpnVwf42nHAST+9Ayh6RThipuDVjd5oQ0ola6uJkhX56Lq8RrssplzcfxauRDexOwoLHJP7nXfUYwXUQpRppicHOG87ScAi6WI/hGidfEgRqL6gGVRrakzdI/5GGE27hKQFf+WksJUuzGiNa/godCKoqVyNuPyZezH+QrcXwI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1718127483; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=GI9aEThs+cRVwRm5YK4mlwGuoe8zKLuRigi6QSO8Qvs=; b=N/SPr9ERv8SMXiAIdeTb+X2zkpf/STiEdDns9AyEFVhBhG9TCAvJ0Xdj6Sev/1p+aIxN1czeVObyJp0NRQUyOHd9P4LB5I5rOj5voRwdmhmLcBd/tc/rmeiZNEAZ03ZRnQ4O8jqeknH7auEPiXiDjVjFOp5WmW4AjfTQGNIw2HI= 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 1718127483476726.6637159437659; Tue, 11 Jun 2024 10:38:03 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sH5Qn-0008VX-06; Tue, 11 Jun 2024 13:37:13 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sH5Ql-0008UU-BL for qemu-devel@nongnu.org; Tue, 11 Jun 2024 13:37:11 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sH5Qj-0008Ri-MB for qemu-devel@nongnu.org; Tue, 11 Jun 2024 13:37:11 -0400 Received: from mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-615-Aqw7AMyHP32jO7VECNKMUw-1; Tue, 11 Jun 2024 13:37:06 -0400 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id B25A219560B9; Tue, 11 Jun 2024 17:37:05 +0000 (UTC) Received: from merkur.fritz.box (unknown [10.39.192.130]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id D01AD19560AB; Tue, 11 Jun 2024 17:37:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1718127429; 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=GI9aEThs+cRVwRm5YK4mlwGuoe8zKLuRigi6QSO8Qvs=; b=Ef/ESZxeCFwB8XBqYmDgDSux1xb9MIRWaAuGMvxoXUBt+arrRFaOKLjGZ7ZFXpXNXq07p2 5DnGftiiPGgqMk6m/9ehySkIrs2DZROUPLVbod+tUiWWWl/ig15k3cNsLyOG3u6eZDTts8 Lmjl/4iLwZ8z8mdjDSIAAIfHVSIIMiM= X-MC-Unique: Aqw7AMyHP32jO7VECNKMUw-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, qemu-devel@nongnu.org Subject: [PULL 1/8] block: drop force_dup parameter of raw_reconfigure_getfd() Date: Tue, 11 Jun 2024 19:36:51 +0200 Message-ID: <20240611173658.231831-2-kwolf@redhat.com> In-Reply-To: <20240611173658.231831-1-kwolf@redhat.com> References: <20240611173658.231831-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 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: 11 X-Spam_score: 1.1 X-Spam_bar: + X-Spam_report: (1.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.141, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_SBL_CSS=3.335, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no 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-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1718127485466100006 Content-Type: text/plain; charset="utf-8" From: "Denis V. Lunev via" Since commit 72373e40fbc, this parameter is always passed as 'false' from the caller. Signed-off-by: Denis V. Lunev CC: Andrey Zhadchenko CC: Kevin Wolf CC: Hanna Reitz Message-ID: <20240430170213.148558-1-den@openvz.org> Reviewed-by: Kevin Wolf Signed-off-by: Kevin Wolf --- block/file-posix.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/block/file-posix.c b/block/file-posix.c index 35684f7e21..5c46938936 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -1039,8 +1039,7 @@ static int fcntl_setfl(int fd, int flag) } =20 static int raw_reconfigure_getfd(BlockDriverState *bs, int flags, - int *open_flags, uint64_t perm, bool forc= e_dup, - Error **errp) + int *open_flags, uint64_t perm, Error **e= rrp) { BDRVRawState *s =3D bs->opaque; int fd =3D -1; @@ -1068,7 +1067,7 @@ static int raw_reconfigure_getfd(BlockDriverState *bs= , int flags, assert((s->open_flags & O_ASYNC) =3D=3D 0); #endif =20 - if (!force_dup && *open_flags =3D=3D s->open_flags) { + if (*open_flags =3D=3D s->open_flags) { /* We're lucky, the existing fd is fine */ return s->fd; } @@ -3748,8 +3747,7 @@ static int raw_check_perm(BlockDriverState *bs, uint6= 4_t perm, uint64_t shared, int ret; =20 /* We may need a new fd if auto-read-only switches the mode */ - ret =3D raw_reconfigure_getfd(bs, input_flags, &open_flags, perm, - false, errp); + ret =3D raw_reconfigure_getfd(bs, input_flags, &open_flags, perm, errp= ); if (ret < 0) { return ret; } else if (ret !=3D s->fd) { --=20 2.45.2 From nobody Thu Dec 26 13:38:46 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=1718127541; cv=none; d=zohomail.com; s=zohoarc; b=gQfB9M8aVSCEIKWCwWMmvULSP42/NkEuD3rx9bZR58WKDIHPQiWtZQ7pyVXVIlguM5EcC5695It17rHxp2S0QiTQd7e6DZaJ9494FGVizAeRvgHRxvt67o6Y+OJfiNT/jP72pfcKGUuCUcZWPoE7gAZgbbS38exYVRe3VDXaJGc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1718127541; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=EDPviX5iCZw8qqN1UwxNpLLXgI2B2YRvbWcSGkLKba0=; b=QgMsxp7TNSNvbDrwg0mClPPRPMc/tabRDlLNhe2xxfI9LpCDkyru4VUPovdaXLjmnMHbaUZj24yE71LXPnI+czpLyQTF219EjDYMtsXDD8D2tLEH1/kvWjmwROUM4yPujOW4tsh2yDJLX3kY0+bBhhmcwvDePX3aNodULQB6bZ4= 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 171812754180542.8611303566945; Tue, 11 Jun 2024 10:39:01 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sH5Qo-0008W5-Dj; Tue, 11 Jun 2024 13:37:14 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sH5Qn-0008Vd-Bn for qemu-devel@nongnu.org; Tue, 11 Jun 2024 13:37:13 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sH5Ql-0008SC-Pt for qemu-devel@nongnu.org; Tue, 11 Jun 2024 13:37:13 -0400 Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-128-gAvFlpdHNGCL709YToLZjg-1; Tue, 11 Jun 2024 13:37:09 -0400 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 781C11956094; Tue, 11 Jun 2024 17:37:08 +0000 (UTC) Received: from merkur.fritz.box (unknown [10.39.192.130]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id D813F19560AB; Tue, 11 Jun 2024 17:37:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1718127431; 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=EDPviX5iCZw8qqN1UwxNpLLXgI2B2YRvbWcSGkLKba0=; b=OOlZGsIYps3RdC9RNaZumOl6lJ4RK2EDZv7hzzEiQBPyP+LqeuTcv00e7/rJZS+Osru7P7 OYm/vXf5ndJtPt5GCm9eFetcvTnsHpq9av7GurUpM944EGYad0ek0lqP5qtpFmod7DCIQq y9Y4vJV1kTZoFQMCTecHmaZvJLCes1o= X-MC-Unique: gAvFlpdHNGCL709YToLZjg-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, qemu-devel@nongnu.org Subject: [PULL 2/8] Revert "monitor: use aio_co_reschedule_self()" Date: Tue, 11 Jun 2024 19:36:52 +0200 Message-ID: <20240611173658.231831-3-kwolf@redhat.com> In-Reply-To: <20240611173658.231831-1-kwolf@redhat.com> References: <20240611173658.231831-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 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: 11 X-Spam_score: 1.1 X-Spam_bar: + X-Spam_report: (1.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.141, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_SBL_CSS=3.335, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no 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-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1718127543767100007 Content-Type: text/plain; charset="utf-8" From: Stefan Hajnoczi Commit 1f25c172f837 ("monitor: use aio_co_reschedule_self()") was a code cleanup that uses aio_co_reschedule_self() instead of open coding coroutine rescheduling. Bug RHEL-34618 was reported and Kevin Wolf identified the root cause. I missed that aio_co_reschedule_self() -> qemu_get_current_aio_context() only knows about qemu_aio_context/IOThread AioContexts and not about iohandler_ctx. It does not function correctly when going back from the iohandler_ctx to qemu_aio_context. Go back to open coding the AioContext transitions to avoid this bug. This reverts commit 1f25c172f83704e350c0829438d832384084a74d. Cc: qemu-stable@nongnu.org Buglink: https://issues.redhat.com/browse/RHEL-34618 Signed-off-by: Stefan Hajnoczi Message-ID: <20240506190622.56095-2-stefanha@redhat.com> Reviewed-by: Kevin Wolf Signed-off-by: Kevin Wolf --- qapi/qmp-dispatch.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/qapi/qmp-dispatch.c b/qapi/qmp-dispatch.c index f3488afeef..176b549473 100644 --- a/qapi/qmp-dispatch.c +++ b/qapi/qmp-dispatch.c @@ -212,7 +212,8 @@ QDict *coroutine_mixed_fn qmp_dispatch(const QmpCommand= List *cmds, QObject *requ * executing the command handler so that it can make progress = if it * involves an AIO_WAIT_WHILE(). */ - aio_co_reschedule_self(qemu_get_aio_context()); + aio_co_schedule(qemu_get_aio_context(), qemu_coroutine_self()); + qemu_coroutine_yield(); } =20 monitor_set_cur(qemu_coroutine_self(), cur_mon); @@ -226,7 +227,9 @@ QDict *coroutine_mixed_fn qmp_dispatch(const QmpCommand= List *cmds, QObject *requ * Move back to iohandler_ctx so that nested event loops for * qemu_aio_context don't start new monitor commands. */ - aio_co_reschedule_self(iohandler_get_aio_context()); + aio_co_schedule(iohandler_get_aio_context(), + qemu_coroutine_self()); + qemu_coroutine_yield(); } } else { /* --=20 2.45.2 From nobody Thu Dec 26 13:38:46 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=1718127498; cv=none; d=zohomail.com; s=zohoarc; b=Nt3D99tzOF5X2UcIcLaV0KZEoY5KT1N4nFjRQoPZzszH7UtfBS1Jk2lbGJnGTHJL8rOuMO8IpyEmvsCyblKZhF8Z1HoXesV0YYl3SxEhr66vaumRPlV0jA1n2g+V4Qyo7fgEcgHMYsQe8E1C9GJT0/YLuWFwPMaLVnPas9MsODo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1718127498; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=ekDyI0XrbGkORk/+Y7DVMqIWcACoq55sA4lf/J9YDMA=; b=Qv7t8jqn7sIRP+Ji2K5qoTgg7CMYoHRRCJeNA/BY92O8Owc8vPPKCc0d9MBq4Sl9enYrRIClISeywSN06IG7/X0u8GlTEl5c5ditPyDpqXc3qajroQVYAqUjz8328qgMszg4FEAuHKScSvbOJbPmiDh1O0EkjbSktCkTi592/rg= 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 1718127498776297.8955995033716; Tue, 11 Jun 2024 10:38:18 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sH5Qv-00007x-4w; Tue, 11 Jun 2024 13:37:21 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sH5Qt-00006t-Sq for qemu-devel@nongnu.org; Tue, 11 Jun 2024 13:37:19 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sH5Qs-0008UT-Gr for qemu-devel@nongnu.org; Tue, 11 Jun 2024 13:37:19 -0400 Received: from mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-90-4Nn3CKfaPj-wGpzR5HfSNQ-1; Tue, 11 Jun 2024 13:37:11 -0400 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 2E5A619560BD; Tue, 11 Jun 2024 17:37:10 +0000 (UTC) Received: from merkur.fritz.box (unknown [10.39.192.130]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id D2B5619560AB; Tue, 11 Jun 2024 17:37:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1718127437; 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=ekDyI0XrbGkORk/+Y7DVMqIWcACoq55sA4lf/J9YDMA=; b=RnIB1mEXWpT7SomabiltiMKd2L5cLuvVdal/YvYqEt8tDzEA0T5Yx+AXVVGHNv7gu3V0ra UXolKcQunMBIja73cLbCr21Qcmkz2Ni8JjK2E//dlw3r2soon8yxleog8ad/Y73/cmYr08 aPwnVObMt/doI+UEru9XruWLKg5lorc= X-MC-Unique: 4Nn3CKfaPj-wGpzR5HfSNQ-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, qemu-devel@nongnu.org Subject: [PULL 3/8] aio: warn about iohandler_ctx special casing Date: Tue, 11 Jun 2024 19:36:53 +0200 Message-ID: <20240611173658.231831-4-kwolf@redhat.com> In-Reply-To: <20240611173658.231831-1-kwolf@redhat.com> References: <20240611173658.231831-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 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: 11 X-Spam_score: 1.1 X-Spam_bar: + X-Spam_report: (1.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.141, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_SBL_CSS=3.335, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no 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-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1718127499503100003 Content-Type: text/plain; charset="utf-8" From: Stefan Hajnoczi The main loop has two AioContexts: qemu_aio_context and iohandler_ctx. The main loop runs them both, but nested aio_poll() calls on qemu_aio_context exclude iohandler_ctx. Which one should qemu_get_current_aio_context() return when called from the main loop? Document that it's always qemu_aio_context. This has subtle effects on functions that use qemu_get_current_aio_context(). For example, aio_co_reschedule_self() does not work when moving from iohandler_ctx to qemu_aio_context because qemu_get_current_aio_context() does not differentiate these two AioContexts. Document this in order to reduce the chance of future bugs. Signed-off-by: Stefan Hajnoczi Message-ID: <20240506190622.56095-3-stefanha@redhat.com> Reviewed-by: Kevin Wolf Signed-off-by: Kevin Wolf --- include/block/aio.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/include/block/aio.h b/include/block/aio.h index 8378553eb9..4ee81936ed 100644 --- a/include/block/aio.h +++ b/include/block/aio.h @@ -629,6 +629,9 @@ void aio_co_schedule(AioContext *ctx, Coroutine *co); * * Move the currently running coroutine to new_ctx. If the coroutine is al= ready * running in new_ctx, do nothing. + * + * Note that this function cannot reschedule from iohandler_ctx to + * qemu_aio_context. */ void coroutine_fn aio_co_reschedule_self(AioContext *new_ctx); =20 @@ -661,6 +664,9 @@ void aio_co_enter(AioContext *ctx, Coroutine *co); * If called from an IOThread this will be the IOThread's AioContext. If * called from the main thread or with the "big QEMU lock" taken it * will be the main loop AioContext. + * + * Note that the return value is never the main loop's iohandler_ctx and t= he + * return value is the main loop AioContext instead. */ AioContext *qemu_get_current_aio_context(void); =20 --=20 2.45.2 From nobody Thu Dec 26 13:38:46 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=1718127541; cv=none; d=zohomail.com; s=zohoarc; b=L121HqkHSMQrXCK4hxn7uJv92B8oTFfiRwKU+IZ+fcgIxoQiQ6+k4oH+gWbK4g5PWtA6t0n1ookhRKaps5hip7jg07MX28uOyQiQu6OokVg/kBJsyhQRn68odsTYoWf2hh0tGQMB1e7T1JhtFq9iKuxwUgmafluSYDE798u5T3Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1718127541; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=FJaqIGhVpINR8HgGtOg7iThzOx8v1LlBfHCauXsWLWw=; b=YEPFMmVHpfz+xg4XA7iCsnrvl6542qaft45R2Ruk82Gja1OGbhBoGFrFmw8zIFp0dHq7iJ61uFvazD7e9rsN3R1FkMBS70Zi9XEb8IGrOnDXq4tPYFyV8nUTdG9UmScSKEiCEo/hALqiDG7ISKLWUoeeT8effvi3WELkebLrW4o= 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 1718127541301983.136676304317; Tue, 11 Jun 2024 10:39:01 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sH5Qv-00008T-ST; Tue, 11 Jun 2024 13:37:21 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sH5Qu-000078-GW for qemu-devel@nongnu.org; Tue, 11 Jun 2024 13:37:20 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sH5Qs-0008Ua-NE for qemu-devel@nongnu.org; Tue, 11 Jun 2024 13:37:20 -0400 Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-421-Mwc_56U2NX-uHg2rhw68ZA-1; Tue, 11 Jun 2024 13:37:13 -0400 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 4DFA31956086; Tue, 11 Jun 2024 17:37:12 +0000 (UTC) Received: from merkur.fritz.box (unknown [10.39.192.130]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 0123E19560AF; Tue, 11 Jun 2024 17:37:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1718127438; 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=FJaqIGhVpINR8HgGtOg7iThzOx8v1LlBfHCauXsWLWw=; b=Iuh9DGiFcPz5A5kK+yeR1de8Hcmo2DtmRBs3Kn4qpQ+vQCTxgv/yP/LxkBHH0suhRlZZZp ZoWHl1TL6+0yMnkq+wh2Elwv8G2VgEuLPVUqOOJtskj601lBqBnli7Vv4ydvpuzgRsTlej vVkrhs8tPemIgeohty9vmVSOflHOq2E= X-MC-Unique: Mwc_56U2NX-uHg2rhw68ZA-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, qemu-devel@nongnu.org Subject: [PULL 4/8] qemu-io: add cvtnum() error handling for zone commands Date: Tue, 11 Jun 2024 19:36:54 +0200 Message-ID: <20240611173658.231831-5-kwolf@redhat.com> In-Reply-To: <20240611173658.231831-1-kwolf@redhat.com> References: <20240611173658.231831-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 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: 11 X-Spam_score: 1.1 X-Spam_bar: + X-Spam_report: (1.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.141, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_SBL_CSS=3.335, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no 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-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1718127541734100001 Content-Type: text/plain; charset="utf-8" From: Stefan Hajnoczi cvtnum() parses positive int64_t values and returns a negative errno on failure. Print errors and return early when cvtnum() fails. While we're at it, also reject nr_zones values greater or equal to 2^32 since they cannot be represented. Reported-by: Peter Maydell Cc: Sam Li Signed-off-by: Stefan Hajnoczi Message-ID: <20240507180558.377233-1-stefanha@redhat.com> Reviewed-by: Sam Li Reviewed-by: Kevin Wolf Signed-off-by: Kevin Wolf --- qemu-io-cmds.c | 48 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) diff --git a/qemu-io-cmds.c b/qemu-io-cmds.c index f5d7202a13..e2fab57183 100644 --- a/qemu-io-cmds.c +++ b/qemu-io-cmds.c @@ -1739,12 +1739,26 @@ static int zone_report_f(BlockBackend *blk, int arg= c, char **argv) { int ret; int64_t offset; + int64_t val; unsigned int nr_zones; =20 ++optind; offset =3D cvtnum(argv[optind]); + if (offset < 0) { + print_cvtnum_err(offset, argv[optind]); + return offset; + } ++optind; - nr_zones =3D cvtnum(argv[optind]); + val =3D cvtnum(argv[optind]); + if (val < 0) { + print_cvtnum_err(val, argv[optind]); + return val; + } + if (val > UINT_MAX) { + printf("Number of zones must be less than 2^32\n"); + return -ERANGE; + } + nr_zones =3D val; =20 g_autofree BlockZoneDescriptor *zones =3D NULL; zones =3D g_new(BlockZoneDescriptor, nr_zones); @@ -1780,8 +1794,16 @@ static int zone_open_f(BlockBackend *blk, int argc, = char **argv) int64_t offset, len; ++optind; offset =3D cvtnum(argv[optind]); + if (offset < 0) { + print_cvtnum_err(offset, argv[optind]); + return offset; + } ++optind; len =3D cvtnum(argv[optind]); + if (len < 0) { + print_cvtnum_err(len, argv[optind]); + return len; + } ret =3D blk_zone_mgmt(blk, BLK_ZO_OPEN, offset, len); if (ret < 0) { printf("zone open failed: %s\n", strerror(-ret)); @@ -1805,8 +1827,16 @@ static int zone_close_f(BlockBackend *blk, int argc,= char **argv) int64_t offset, len; ++optind; offset =3D cvtnum(argv[optind]); + if (offset < 0) { + print_cvtnum_err(offset, argv[optind]); + return offset; + } ++optind; len =3D cvtnum(argv[optind]); + if (len < 0) { + print_cvtnum_err(len, argv[optind]); + return len; + } ret =3D blk_zone_mgmt(blk, BLK_ZO_CLOSE, offset, len); if (ret < 0) { printf("zone close failed: %s\n", strerror(-ret)); @@ -1830,8 +1860,16 @@ static int zone_finish_f(BlockBackend *blk, int argc= , char **argv) int64_t offset, len; ++optind; offset =3D cvtnum(argv[optind]); + if (offset < 0) { + print_cvtnum_err(offset, argv[optind]); + return offset; + } ++optind; len =3D cvtnum(argv[optind]); + if (len < 0) { + print_cvtnum_err(len, argv[optind]); + return len; + } ret =3D blk_zone_mgmt(blk, BLK_ZO_FINISH, offset, len); if (ret < 0) { printf("zone finish failed: %s\n", strerror(-ret)); @@ -1855,8 +1893,16 @@ static int zone_reset_f(BlockBackend *blk, int argc,= char **argv) int64_t offset, len; ++optind; offset =3D cvtnum(argv[optind]); + if (offset < 0) { + print_cvtnum_err(offset, argv[optind]); + return offset; + } ++optind; len =3D cvtnum(argv[optind]); + if (len < 0) { + print_cvtnum_err(len, argv[optind]); + return len; + } ret =3D blk_zone_mgmt(blk, BLK_ZO_RESET, offset, len); if (ret < 0) { printf("zone reset failed: %s\n", strerror(-ret)); --=20 2.45.2 From nobody Thu Dec 26 13:38:46 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=1718127484; cv=none; d=zohomail.com; s=zohoarc; b=D6tIJiIt2kejfFAZr4fnVqcYxjX52/fVlkPDcpiilFZPxZPPwCaUH0ZG34WscQPis+bN8GNdPgMsF3pRxB15Lp8aXJQ6gysuc/ZKuh+cmlnG8fvxaE7stlJwk7szgR07LGXHod8Yc1TAOPR6G6qRsE41+PZx7n+Dlq75UMzpCdM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1718127484; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=193HeBPP9dVSfVwQtrX9rCBKDVSTtth8L3GESbEZ8WA=; b=EOzWSi6N2de3GrhzEAbwYzJ0pYw7BG4JH/lAIeMhQ40PKhrFInNAJK0fxNSvUB3uHTyXThK1NQ3HcgxCyoX5vuWXm/dPXl24rhtJE8BZOfgQVzhGTN0mmxQM7SYh8eRnnpWiPS5VVhVHq7/RMaJtJRCrrRwYTldpvHiecOKJFpE= 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 1718127484489561.2498022720171; Tue, 11 Jun 2024 10:38:04 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sH5Qv-00008O-Me; Tue, 11 Jun 2024 13:37:21 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sH5Qu-000074-BE for qemu-devel@nongnu.org; Tue, 11 Jun 2024 13:37:20 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sH5Qs-0008UW-H4 for qemu-devel@nongnu.org; Tue, 11 Jun 2024 13:37:20 -0400 Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-653-rGRZfUjHPkW7X0pr_WDx0A-1; Tue, 11 Jun 2024 13:37:15 -0400 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 56FFB19560BD; Tue, 11 Jun 2024 17:37:14 +0000 (UTC) Received: from merkur.fritz.box (unknown [10.39.192.130]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 91B2319560B4; Tue, 11 Jun 2024 17:37:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1718127437; 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=193HeBPP9dVSfVwQtrX9rCBKDVSTtth8L3GESbEZ8WA=; b=Af0kIeAUGxV4dSuDCBd3jkjPYsjZTeGBmR3sTXe4IRB0ESig6htcl4/N263OM4ofmiCwqS HjZEvSH6daIo0XeRbzDSHGTbA6AenVimqOL8HpellmduxCDIpdekANx/d37qgsEQZ/HT6J G1JNtIEb/svSRuzL8ivJ1zXzllZhw9M= X-MC-Unique: rGRZfUjHPkW7X0pr_WDx0A-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, qemu-devel@nongnu.org Subject: [PULL 5/8] block/copy-before-write: use uint64_t for timeout in nanoseconds Date: Tue, 11 Jun 2024 19:36:55 +0200 Message-ID: <20240611173658.231831-6-kwolf@redhat.com> In-Reply-To: <20240611173658.231831-1-kwolf@redhat.com> References: <20240611173658.231831-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 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: 11 X-Spam_score: 1.1 X-Spam_bar: + X-Spam_report: (1.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.141, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_SBL_CSS=3.335, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no 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-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1718127485466100005 From: Fiona Ebner rather than the uint32_t for which the maximum is slightly more than 4 seconds and larger values would overflow. The QAPI interface allows specifying the number of seconds, so only values 0 to 4 are safe right now, other values lead to a much lower timeout than a user expects. The block_copy() call where this is used already takes a uint64_t for the timeout, so no change required there. Fixes: 6db7fd1ca9 ("block/copy-before-write: implement cbw-timeout option") Reported-by: Friedrich Weber Signed-off-by: Fiona Ebner Message-ID: <20240429141934.442154-1-f.ebner@proxmox.com> Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Kevin Wolf Signed-off-by: Kevin Wolf --- block/copy-before-write.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/block/copy-before-write.c b/block/copy-before-write.c index cd65524e26..853e01a1eb 100644 --- a/block/copy-before-write.c +++ b/block/copy-before-write.c @@ -43,7 +43,7 @@ typedef struct BDRVCopyBeforeWriteState { BlockCopyState *bcs; BdrvChild *target; OnCbwError on_cbw_error; - uint32_t cbw_timeout_ns; + uint64_t cbw_timeout_ns; bool discard_source; =20 /* --=20 2.45.2 From nobody Thu Dec 26 13:38:46 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=1718127524; cv=none; d=zohomail.com; s=zohoarc; b=RZli3r2FuIXfWtIdOtFNLMIqzy1EmSqhIRBuCLsrPO5Dtuh2571ayKyOAGqUaJBmsACMWnhWoKnmkujbMnbds+SkK2OqAevJbhznTwHUxqfFCqcr3m5mWpz3oRrwMH8xvdbBm8VtXOLeiY5xKMzkeX8fIawr85TqT8A7lwklqtk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1718127524; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=Pic+NTGR2xDZGvJdSIIWUg6ye59mZnjGjver02Rud84=; b=PnbroQKz+mCJiNtwOmbXYJNuTRyo+AuPnQH0R7evs/h6Y9nY9yadsHQUu6OtjaFPbai6CGDvH99e4FUOl6siqydmKQLJv9Na+spY5oDJ3+Gjn50CgRemSnaUY7FUuZI6dh/H4ylu0q1JzxWZSFKfSEQnMTM3HCTcQILrsIihflo= 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 1718127524496245.14343294923412; Tue, 11 Jun 2024 10:38:44 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sH5Qw-00008h-9I; Tue, 11 Jun 2024 13:37:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sH5Qu-00007f-P9 for qemu-devel@nongnu.org; Tue, 11 Jun 2024 13:37:20 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sH5Qt-0008Ul-2K for qemu-devel@nongnu.org; Tue, 11 Jun 2024 13:37:20 -0400 Received: from mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-170-FUDJC3w9OQaijwwYgsIhrA-1; Tue, 11 Jun 2024 13:37:16 -0400 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id CEA7A19560BC; Tue, 11 Jun 2024 17:37:15 +0000 (UTC) Received: from merkur.fritz.box (unknown [10.39.192.130]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 9B38B19560AF; Tue, 11 Jun 2024 17:37:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1718127438; 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=Pic+NTGR2xDZGvJdSIIWUg6ye59mZnjGjver02Rud84=; b=JNBSZ6KpPTXcX2sYEBJ7C9irFR3XhyG3rWxJ2d5TGAVjEDgK+yYs35rHY9pIKFIwNyDNaN 6f/UEoFOMg38Q87ZIMVuhiZ8EYBCO7c/rteAI1lZgD+95vQuQrLQDzAVu+uZYu9NfBbLZP 8TrwoC51hthba4SI6uUgHdvJ6ZY1v/U= X-MC-Unique: FUDJC3w9OQaijwwYgsIhrA-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, qemu-devel@nongnu.org Subject: [PULL 6/8] linux-aio: add IO_CMD_FDSYNC command support Date: Tue, 11 Jun 2024 19:36:56 +0200 Message-ID: <20240611173658.231831-7-kwolf@redhat.com> In-Reply-To: <20240611173658.231831-1-kwolf@redhat.com> References: <20240611173658.231831-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 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: 11 X-Spam_score: 1.1 X-Spam_bar: + X-Spam_report: (1.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.141, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_SBL_CSS=3.335, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no 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-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1718127525643100005 Content-Type: text/plain; charset="utf-8" From: Prasad Pandit Libaio defines IO_CMD_FDSYNC command to sync all outstanding asynchronous I/O operations, by flushing out file data to the disk storage. Enable linux-aio to submit such aio request. When using aio=3Dnative without fdsync() support, QEMU creates pthreads, and destroying these pthreads results in TLB flushes. In a real-time guest environment, TLB flushes cause a latency spike. This patch helps to avoid such spikes. Reviewed-by: Stefan Hajnoczi Signed-off-by: Prasad Pandit Message-ID: <20240425070412.37248-1-ppandit@redhat.com> Reviewed-by: Kevin Wolf Signed-off-by: Kevin Wolf --- include/block/raw-aio.h | 1 + block/file-posix.c | 9 +++++++++ block/linux-aio.c | 21 ++++++++++++++++++++- 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/include/block/raw-aio.h b/include/block/raw-aio.h index 20e000b8ef..626706827f 100644 --- a/include/block/raw-aio.h +++ b/include/block/raw-aio.h @@ -60,6 +60,7 @@ void laio_cleanup(LinuxAioState *s); int coroutine_fn laio_co_submit(int fd, uint64_t offset, QEMUIOVector *qio= v, int type, uint64_t dev_max_batch); =20 +bool laio_has_fdsync(int); void laio_detach_aio_context(LinuxAioState *s, AioContext *old_context); void laio_attach_aio_context(LinuxAioState *s, AioContext *new_context); #endif diff --git a/block/file-posix.c b/block/file-posix.c index 5c46938936..be25e35ff6 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -159,6 +159,7 @@ typedef struct BDRVRawState { bool has_discard:1; bool has_write_zeroes:1; bool use_linux_aio:1; + bool has_laio_fdsync:1; bool use_linux_io_uring:1; int page_cache_inconsistent; /* errno from fdatasync failure */ bool has_fallocate; @@ -718,6 +719,9 @@ static int raw_open_common(BlockDriverState *bs, QDict = *options, ret =3D -EINVAL; goto fail; } + if (s->use_linux_aio) { + s->has_laio_fdsync =3D laio_has_fdsync(s->fd); + } #else if (s->use_linux_aio) { error_setg(errp, "aio=3Dnative was specified, but is not supported= " @@ -2598,6 +2602,11 @@ static int coroutine_fn raw_co_flush_to_disk(BlockDr= iverState *bs) if (raw_check_linux_io_uring(s)) { return luring_co_submit(bs, s->fd, 0, NULL, QEMU_AIO_FLUSH); } +#endif +#ifdef CONFIG_LINUX_AIO + if (s->has_laio_fdsync && raw_check_linux_aio(s)) { + return laio_co_submit(s->fd, 0, NULL, QEMU_AIO_FLUSH, 0); + } #endif return raw_thread_pool_submit(handle_aiocb_flush, &acb); } diff --git a/block/linux-aio.c b/block/linux-aio.c index ec05d946f3..e3b5ec9aba 100644 --- a/block/linux-aio.c +++ b/block/linux-aio.c @@ -384,6 +384,9 @@ static int laio_do_submit(int fd, struct qemu_laiocb *l= aiocb, off_t offset, case QEMU_AIO_READ: io_prep_preadv(iocbs, fd, qiov->iov, qiov->niov, offset); break; + case QEMU_AIO_FLUSH: + io_prep_fdsync(iocbs, fd); + break; /* Currently Linux kernel does not support other operations */ default: fprintf(stderr, "%s: invalid AIO request type 0x%x.\n", @@ -412,7 +415,7 @@ int coroutine_fn laio_co_submit(int fd, uint64_t offset= , QEMUIOVector *qiov, AioContext *ctx =3D qemu_get_current_aio_context(); struct qemu_laiocb laiocb =3D { .co =3D qemu_coroutine_self(), - .nbytes =3D qiov->size, + .nbytes =3D qiov ? qiov->size : 0, .ctx =3D aio_get_linux_aio(ctx), .ret =3D -EINPROGRESS, .is_read =3D (type =3D=3D QEMU_AIO_READ), @@ -486,3 +489,19 @@ void laio_cleanup(LinuxAioState *s) } g_free(s); } + +bool laio_has_fdsync(int fd) +{ + struct iocb cb; + struct iocb *cbs[] =3D {&cb, NULL}; + + io_context_t ctx =3D 0; + io_setup(1, &ctx); + + /* check if host kernel supports IO_CMD_FDSYNC */ + io_prep_fdsync(&cb, fd); + int ret =3D io_submit(ctx, 1, cbs); + + io_destroy(ctx); + return (ret =3D=3D -EINVAL) ? false : true; +} --=20 2.45.2 From nobody Thu Dec 26 13:38:46 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=1718127499; cv=none; d=zohomail.com; s=zohoarc; b=ixENbDz12Imrg1LUFjq9AXyUYvvUaf2CWaQ29eGCFeTkzNcpAcfm91NMbTTR7+AYvevX7418NohchrqfMTKljjYm3JiyyW6g2fkiTu8f2FNqc6Hjp1kcubzQl1PXS+HrPi1q0uoSC4kauN58hxC7UshSqd12/6figZVWsbirqC0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1718127499; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=XcRdTc4kHZtT5Qcayg+eHXjNJM4Q40Gt/VxgdWyG7ks=; b=X089NDE7hv7rSkNJbg3msIBkg8bK++6yOypGqtqdt7MLu7JOvFq2RFY2rp8dK/iIxvOzOSjg1WJMRrsg4FY0Ff4Jn7ylm2JrvhGKtQCT9SHGobpGgoUKuIDL/Rp0usj/d2l0r4k18IKkCEgpaVzf1KO2QcrD9EGATW1FrV6+e6o= 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 1718127499900833.8763863485921; Tue, 11 Jun 2024 10:38:19 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sH5R0-0000CI-6D; Tue, 11 Jun 2024 13:37:26 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sH5Qy-0000Bs-2p for qemu-devel@nongnu.org; Tue, 11 Jun 2024 13:37:24 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sH5Qv-0008VT-Hx for qemu-devel@nongnu.org; Tue, 11 Jun 2024 13:37:23 -0400 Received: from mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-356-ej_3CoUqNCyAR6EyAQPnfQ-1; Tue, 11 Jun 2024 13:37:19 -0400 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 687181955F30; Tue, 11 Jun 2024 17:37:18 +0000 (UTC) Received: from merkur.fritz.box (unknown [10.39.192.130]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 3999819560AB; Tue, 11 Jun 2024 17:37:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1718127441; 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=XcRdTc4kHZtT5Qcayg+eHXjNJM4Q40Gt/VxgdWyG7ks=; b=GY0PVxJQ+09Q3KhxaGIJ2Nq/MpUvE03wYUmjR+8B/s1f4eJBQBOGv5kOYCw7mNMcrPRSbR oQb/BRjywHst0tMVoHziUGLUZVRJn5ejEmASRTOUVtWHHqSn5qxmRCr43DId31BekX51TY 95QMMqyHA1MS/ItqFM8LZgM8vAAz7Ng= X-MC-Unique: ej_3CoUqNCyAR6EyAQPnfQ-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, qemu-devel@nongnu.org Subject: [PULL 7/8] block/crypto: create ciphers on demand Date: Tue, 11 Jun 2024 19:36:57 +0200 Message-ID: <20240611173658.231831-8-kwolf@redhat.com> In-Reply-To: <20240611173658.231831-1-kwolf@redhat.com> References: <20240611173658.231831-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 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: 11 X-Spam_score: 1.1 X-Spam_bar: + X-Spam_report: (1.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.141, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_SBL_CSS=3.335, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no 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-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1718127501593100007 From: Stefan Hajnoczi Ciphers are pre-allocated by qcrypto_block_init_cipher() depending on the given number of threads. The -device virtio-blk-pci,iothread-vq-mapping=3D feature allows users to assign multiple IOThreads to a virtio-blk device, but the association between the virtio-blk device and the block driver happens after the block driver is already open. When the number of threads given to qcrypto_block_init_cipher() is smaller than the actual number of threads at runtime, the block->n_free_ciphers > 0 assertion in qcrypto_block_pop_cipher() can fail. Get rid of qcrypto_block_init_cipher() n_thread's argument and allocate ciphers on demand. Reported-by: Qing Wang Buglink: https://issues.redhat.com/browse/RHEL-36159 Signed-off-by: Stefan Hajnoczi Message-ID: <20240527155851.892885-2-stefanha@redhat.com> Reviewed-by: Kevin Wolf Acked-by: Daniel P. Berrang=C3=A9 Signed-off-by: Kevin Wolf --- crypto/blockpriv.h | 12 +++-- crypto/block-luks.c | 3 +- crypto/block-qcow.c | 2 +- crypto/block.c | 111 ++++++++++++++++++++++++++------------------ 4 files changed, 78 insertions(+), 50 deletions(-) diff --git a/crypto/blockpriv.h b/crypto/blockpriv.h index 836f3b4726..4bf6043d5d 100644 --- a/crypto/blockpriv.h +++ b/crypto/blockpriv.h @@ -32,8 +32,14 @@ struct QCryptoBlock { const QCryptoBlockDriver *driver; void *opaque; =20 - QCryptoCipher **ciphers; - size_t n_ciphers; + /* Cipher parameters */ + QCryptoCipherAlgorithm alg; + QCryptoCipherMode mode; + uint8_t *key; + size_t nkey; + + QCryptoCipher **free_ciphers; + size_t max_free_ciphers; size_t n_free_ciphers; QCryptoIVGen *ivgen; QemuMutex mutex; @@ -130,7 +136,7 @@ int qcrypto_block_init_cipher(QCryptoBlock *block, QCryptoCipherAlgorithm alg, QCryptoCipherMode mode, const uint8_t *key, size_t nkey, - size_t n_threads, Error **errp); + Error **errp); =20 void qcrypto_block_free_cipher(QCryptoBlock *block); =20 diff --git a/crypto/block-luks.c b/crypto/block-luks.c index 3ee928fb5a..3357852c0a 100644 --- a/crypto/block-luks.c +++ b/crypto/block-luks.c @@ -1262,7 +1262,6 @@ qcrypto_block_luks_open(QCryptoBlock *block, luks->cipher_mode, masterkey, luks->header.master_key_len, - n_threads, errp) < 0) { goto fail; } @@ -1456,7 +1455,7 @@ qcrypto_block_luks_create(QCryptoBlock *block, /* Setup the block device payload encryption objects */ if (qcrypto_block_init_cipher(block, luks_opts.cipher_alg, luks_opts.cipher_mode, masterkey, - luks->header.master_key_len, 1, errp) < = 0) { + luks->header.master_key_len, errp) < 0) { goto error; } =20 diff --git a/crypto/block-qcow.c b/crypto/block-qcow.c index 4d7cf36a8f..02305058e3 100644 --- a/crypto/block-qcow.c +++ b/crypto/block-qcow.c @@ -75,7 +75,7 @@ qcrypto_block_qcow_init(QCryptoBlock *block, ret =3D qcrypto_block_init_cipher(block, QCRYPTO_CIPHER_ALG_AES_128, QCRYPTO_CIPHER_MODE_CBC, keybuf, G_N_ELEMENTS(keybuf), - n_threads, errp); + errp); if (ret < 0) { ret =3D -ENOTSUP; goto fail; diff --git a/crypto/block.c b/crypto/block.c index 506ea1d1a3..ba6d1cebc7 100644 --- a/crypto/block.c +++ b/crypto/block.c @@ -20,6 +20,7 @@ =20 #include "qemu/osdep.h" #include "qapi/error.h" +#include "qemu/lockable.h" #include "blockpriv.h" #include "block-qcow.h" #include "block-luks.h" @@ -57,6 +58,8 @@ QCryptoBlock *qcrypto_block_open(QCryptoBlockOpenOptions = *options, { QCryptoBlock *block =3D g_new0(QCryptoBlock, 1); =20 + qemu_mutex_init(&block->mutex); + block->format =3D options->format; =20 if (options->format >=3D G_N_ELEMENTS(qcrypto_block_drivers) || @@ -76,8 +79,6 @@ QCryptoBlock *qcrypto_block_open(QCryptoBlockOpenOptions = *options, return NULL; } =20 - qemu_mutex_init(&block->mutex); - return block; } =20 @@ -92,6 +93,8 @@ QCryptoBlock *qcrypto_block_create(QCryptoBlockCreateOpti= ons *options, { QCryptoBlock *block =3D g_new0(QCryptoBlock, 1); =20 + qemu_mutex_init(&block->mutex); + block->format =3D options->format; =20 if (options->format >=3D G_N_ELEMENTS(qcrypto_block_drivers) || @@ -111,8 +114,6 @@ QCryptoBlock *qcrypto_block_create(QCryptoBlockCreateOp= tions *options, return NULL; } =20 - qemu_mutex_init(&block->mutex); - return block; } =20 @@ -227,37 +228,42 @@ QCryptoCipher *qcrypto_block_get_cipher(QCryptoBlock = *block) * This function is used only in test with one thread (it's safe to sk= ip * pop/push interface), so it's enough to assert it here: */ - assert(block->n_ciphers <=3D 1); - return block->ciphers ? block->ciphers[0] : NULL; + assert(block->max_free_ciphers <=3D 1); + return block->free_ciphers ? block->free_ciphers[0] : NULL; } =20 =20 -static QCryptoCipher *qcrypto_block_pop_cipher(QCryptoBlock *block) +static QCryptoCipher *qcrypto_block_pop_cipher(QCryptoBlock *block, + Error **errp) { - QCryptoCipher *cipher; - - qemu_mutex_lock(&block->mutex); - - assert(block->n_free_ciphers > 0); - block->n_free_ciphers--; - cipher =3D block->ciphers[block->n_free_ciphers]; - - qemu_mutex_unlock(&block->mutex); + /* Usually there is a free cipher available */ + WITH_QEMU_LOCK_GUARD(&block->mutex) { + if (block->n_free_ciphers > 0) { + block->n_free_ciphers--; + return block->free_ciphers[block->n_free_ciphers]; + } + } =20 - return cipher; + /* Otherwise allocate a new cipher */ + return qcrypto_cipher_new(block->alg, block->mode, block->key, + block->nkey, errp); } =20 =20 static void qcrypto_block_push_cipher(QCryptoBlock *block, QCryptoCipher *cipher) { - qemu_mutex_lock(&block->mutex); + QEMU_LOCK_GUARD(&block->mutex); =20 - assert(block->n_free_ciphers < block->n_ciphers); - block->ciphers[block->n_free_ciphers] =3D cipher; - block->n_free_ciphers++; + if (block->n_free_ciphers =3D=3D block->max_free_ciphers) { + block->max_free_ciphers++; + block->free_ciphers =3D g_renew(QCryptoCipher *, + block->free_ciphers, + block->max_free_ciphers); + } =20 - qemu_mutex_unlock(&block->mutex); + block->free_ciphers[block->n_free_ciphers] =3D cipher; + block->n_free_ciphers++; } =20 =20 @@ -265,24 +271,31 @@ int qcrypto_block_init_cipher(QCryptoBlock *block, QCryptoCipherAlgorithm alg, QCryptoCipherMode mode, const uint8_t *key, size_t nkey, - size_t n_threads, Error **errp) + Error **errp) { - size_t i; + QCryptoCipher *cipher; =20 - assert(!block->ciphers && !block->n_ciphers && !block->n_free_ciphers); + assert(!block->free_ciphers && !block->max_free_ciphers && + !block->n_free_ciphers); =20 - block->ciphers =3D g_new0(QCryptoCipher *, n_threads); + /* Stash away cipher parameters for qcrypto_block_pop_cipher() */ + block->alg =3D alg; + block->mode =3D mode; + block->key =3D g_memdup2(key, nkey); + block->nkey =3D nkey; =20 - for (i =3D 0; i < n_threads; i++) { - block->ciphers[i] =3D qcrypto_cipher_new(alg, mode, key, nkey, err= p); - if (!block->ciphers[i]) { - qcrypto_block_free_cipher(block); - return -1; - } - block->n_ciphers++; - block->n_free_ciphers++; + /* + * Create a new cipher to validate the parameters now. This reduces the + * chance of cipher creation failing at I/O time. + */ + cipher =3D qcrypto_block_pop_cipher(block, errp); + if (!cipher) { + g_free(block->key); + block->key =3D NULL; + return -1; } =20 + qcrypto_block_push_cipher(block, cipher); return 0; } =20 @@ -291,19 +304,23 @@ void qcrypto_block_free_cipher(QCryptoBlock *block) { size_t i; =20 - if (!block->ciphers) { + g_free(block->key); + block->key =3D NULL; + + if (!block->free_ciphers) { return; } =20 - assert(block->n_ciphers =3D=3D block->n_free_ciphers); + /* All popped ciphers were eventually pushed back */ + assert(block->n_free_ciphers =3D=3D block->max_free_ciphers); =20 - for (i =3D 0; i < block->n_ciphers; i++) { - qcrypto_cipher_free(block->ciphers[i]); + for (i =3D 0; i < block->max_free_ciphers; i++) { + qcrypto_cipher_free(block->free_ciphers[i]); } =20 - g_free(block->ciphers); - block->ciphers =3D NULL; - block->n_ciphers =3D block->n_free_ciphers =3D 0; + g_free(block->free_ciphers); + block->free_ciphers =3D NULL; + block->max_free_ciphers =3D block->n_free_ciphers =3D 0; } =20 QCryptoIVGen *qcrypto_block_get_ivgen(QCryptoBlock *block) @@ -311,7 +328,7 @@ QCryptoIVGen *qcrypto_block_get_ivgen(QCryptoBlock *blo= ck) /* ivgen should be accessed under mutex. However, this function is use= d only * in test with one thread, so it's enough to assert it here: */ - assert(block->n_ciphers <=3D 1); + assert(block->max_free_ciphers <=3D 1); return block->ivgen; } =20 @@ -446,7 +463,10 @@ int qcrypto_block_decrypt_helper(QCryptoBlock *block, Error **errp) { int ret; - QCryptoCipher *cipher =3D qcrypto_block_pop_cipher(block); + QCryptoCipher *cipher =3D qcrypto_block_pop_cipher(block, errp); + if (!cipher) { + return -1; + } =20 ret =3D do_qcrypto_block_cipher_encdec(cipher, block->niv, block->ivge= n, &block->mutex, sectorsize, offset= , buf, @@ -465,7 +485,10 @@ int qcrypto_block_encrypt_helper(QCryptoBlock *block, Error **errp) { int ret; - QCryptoCipher *cipher =3D qcrypto_block_pop_cipher(block); + QCryptoCipher *cipher =3D qcrypto_block_pop_cipher(block, errp); + if (!cipher) { + return -1; + } =20 ret =3D do_qcrypto_block_cipher_encdec(cipher, block->niv, block->ivge= n, &block->mutex, sectorsize, offset= , buf, --=20 2.45.2 From nobody Thu Dec 26 13:38:46 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=1718127524; cv=none; d=zohomail.com; s=zohoarc; b=ZioYYMA8AiBuR+2BlpBEyyNtSJ0JdpvS0n0LBIbgxn56clQryLtsrJF7QEzhISa59hmDLpL9tEbPEvWPRBEFb3CGAT6pBK8x8gYRDKuP/DLaFfuIrIp6bwNrr/DS2Qf+fjIpZ9nQv9Ik9r/5I67fUM+nR7zUWoUo4SiIewNb9n8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1718127524; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=lv65QFUQSYP8QtBV0oK5wLlGxJlscP+ME8lnikpyAKI=; b=XZeT3eAEu8KQJbiSIsx+xQM4mhvCTid7lgniNCGJRjmpPmxkNsr13OXhJnqTD38S/A/nUERMEhsRRT28Yo3hbuBDcRER4VqBL+iMhTmJfV8vt+mGiHuW03xl0D5e7FUn1SyGFhwvnOvyNoRu+geypRMpd3c0NeWxpZGPREfy6B8= 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 1718127524420229.98846770180353; Tue, 11 Jun 2024 10:38:44 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sH5R2-0000E8-Bl; Tue, 11 Jun 2024 13:37:28 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sH5R0-0000Cv-V3 for qemu-devel@nongnu.org; Tue, 11 Jun 2024 13:37:26 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sH5Qz-00005v-7h for qemu-devel@nongnu.org; Tue, 11 Jun 2024 13:37:26 -0400 Received: from mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-212-1K0sGGBHNOKk_ZSS8-hPRA-1; Tue, 11 Jun 2024 13:37:20 -0400 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id DCB071955D82; Tue, 11 Jun 2024 17:37:19 +0000 (UTC) Received: from merkur.fritz.box (unknown [10.39.192.130]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id A8BC419560AB; Tue, 11 Jun 2024 17:37:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1718127444; 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=lv65QFUQSYP8QtBV0oK5wLlGxJlscP+ME8lnikpyAKI=; b=RQAOUr2GFo25N59Ff0Y9IJvrIGlvTUHWMML9R2fuvwjVs3cSqAdq8hPil5D61Df1JzgTsx b9N63jeVkGK7JXGfcwyK5cSsegFdqpvZfibuD+Wj7c/lfm1VKvA4T/5NPzCpnbAex2gBYs NkICwkcJ+qC+KQRF2ysnfWAQ6lI5qVM= X-MC-Unique: 1K0sGGBHNOKk_ZSS8-hPRA-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, qemu-devel@nongnu.org Subject: [PULL 8/8] crypto/block: drop qcrypto_block_open() n_threads argument Date: Tue, 11 Jun 2024 19:36:58 +0200 Message-ID: <20240611173658.231831-9-kwolf@redhat.com> In-Reply-To: <20240611173658.231831-1-kwolf@redhat.com> References: <20240611173658.231831-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 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: 11 X-Spam_score: 1.1 X-Spam_bar: + X-Spam_report: (1.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.141, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_SBL_CSS=3.335, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no 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-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1718127525672100007 From: Stefan Hajnoczi The n_threads argument is no longer used since the previous commit. Remove it. Signed-off-by: Stefan Hajnoczi Message-ID: <20240527155851.892885-3-stefanha@redhat.com> Reviewed-by: Kevin Wolf Acked-by: Daniel P. Berrang=C3=A9 Signed-off-by: Kevin Wolf --- crypto/blockpriv.h | 1 - include/crypto/block.h | 2 -- block/crypto.c | 1 - block/qcow.c | 2 +- block/qcow2.c | 5 ++--- crypto/block-luks.c | 1 - crypto/block-qcow.c | 6 ++---- crypto/block.c | 3 +-- tests/unit/test-crypto-block.c | 4 ---- 9 files changed, 6 insertions(+), 19 deletions(-) diff --git a/crypto/blockpriv.h b/crypto/blockpriv.h index 4bf6043d5d..b8f77cb5eb 100644 --- a/crypto/blockpriv.h +++ b/crypto/blockpriv.h @@ -59,7 +59,6 @@ struct QCryptoBlockDriver { QCryptoBlockReadFunc readfunc, void *opaque, unsigned int flags, - size_t n_threads, Error **errp); =20 int (*create)(QCryptoBlock *block, diff --git a/include/crypto/block.h b/include/crypto/block.h index 92e823c9f2..5b5d039800 100644 --- a/include/crypto/block.h +++ b/include/crypto/block.h @@ -76,7 +76,6 @@ typedef enum { * @readfunc: callback for reading data from the volume * @opaque: data to pass to @readfunc * @flags: bitmask of QCryptoBlockOpenFlags values - * @n_threads: allow concurrent I/O from up to @n_threads threads * @errp: pointer to a NULL-initialized error object * * Create a new block encryption object for an existing @@ -113,7 +112,6 @@ QCryptoBlock *qcrypto_block_open(QCryptoBlockOpenOption= s *options, QCryptoBlockReadFunc readfunc, void *opaque, unsigned int flags, - size_t n_threads, Error **errp); =20 typedef enum { diff --git a/block/crypto.c b/block/crypto.c index 21eed909c1..4eed3ffa6a 100644 --- a/block/crypto.c +++ b/block/crypto.c @@ -363,7 +363,6 @@ static int block_crypto_open_generic(QCryptoBlockFormat= format, block_crypto_read_func, bs, cflags, - 1, errp); =20 if (!crypto->block) { diff --git a/block/qcow.c b/block/qcow.c index ca8e1d5ec8..c2f89db055 100644 --- a/block/qcow.c +++ b/block/qcow.c @@ -211,7 +211,7 @@ static int qcow_open(BlockDriverState *bs, QDict *optio= ns, int flags, cflags |=3D QCRYPTO_BLOCK_OPEN_NO_IO; } s->crypto =3D qcrypto_block_open(crypto_opts, "encrypt.", - NULL, NULL, cflags, 1, errp); + NULL, NULL, cflags, errp); if (!s->crypto) { ret =3D -EINVAL; goto fail; diff --git a/block/qcow2.c b/block/qcow2.c index 956128b409..10883a2494 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -321,7 +321,7 @@ qcow2_read_extensions(BlockDriverState *bs, uint64_t st= art_offset, } s->crypto =3D qcrypto_block_open(s->crypto_opts, "encrypt.", qcow2_crypto_hdr_read_func, - bs, cflags, QCOW2_MAX_THREADS, = errp); + bs, cflags, errp); if (!s->crypto) { return -EINVAL; } @@ -1701,8 +1701,7 @@ qcow2_do_open(BlockDriverState *bs, QDict *options, i= nt flags, cflags |=3D QCRYPTO_BLOCK_OPEN_NO_IO; } s->crypto =3D qcrypto_block_open(s->crypto_opts, "encrypt.", - NULL, NULL, cflags, - QCOW2_MAX_THREADS, errp); + NULL, NULL, cflags, errp); if (!s->crypto) { ret =3D -EINVAL; goto fail; diff --git a/crypto/block-luks.c b/crypto/block-luks.c index 3357852c0a..5b777c15d3 100644 --- a/crypto/block-luks.c +++ b/crypto/block-luks.c @@ -1189,7 +1189,6 @@ qcrypto_block_luks_open(QCryptoBlock *block, QCryptoBlockReadFunc readfunc, void *opaque, unsigned int flags, - size_t n_threads, Error **errp) { QCryptoBlockLUKS *luks =3D NULL; diff --git a/crypto/block-qcow.c b/crypto/block-qcow.c index 02305058e3..42e9556e42 100644 --- a/crypto/block-qcow.c +++ b/crypto/block-qcow.c @@ -44,7 +44,6 @@ qcrypto_block_qcow_has_format(const uint8_t *buf G_GNUC_U= NUSED, static int qcrypto_block_qcow_init(QCryptoBlock *block, const char *keysecret, - size_t n_threads, Error **errp) { char *password; @@ -100,7 +99,6 @@ qcrypto_block_qcow_open(QCryptoBlock *block, QCryptoBlockReadFunc readfunc G_GNUC_UNUSED, void *opaque G_GNUC_UNUSED, unsigned int flags, - size_t n_threads, Error **errp) { if (flags & QCRYPTO_BLOCK_OPEN_NO_IO) { @@ -115,7 +113,7 @@ qcrypto_block_qcow_open(QCryptoBlock *block, return -1; } return qcrypto_block_qcow_init(block, options->u.qcow.key_secret, - n_threads, errp); + errp); } } =20 @@ -135,7 +133,7 @@ qcrypto_block_qcow_create(QCryptoBlock *block, return -1; } /* QCow2 has no special header, since everything is hardwired */ - return qcrypto_block_qcow_init(block, options->u.qcow.key_secret, 1, e= rrp); + return qcrypto_block_qcow_init(block, options->u.qcow.key_secret, errp= ); } =20 =20 diff --git a/crypto/block.c b/crypto/block.c index ba6d1cebc7..3bcc4270c3 100644 --- a/crypto/block.c +++ b/crypto/block.c @@ -53,7 +53,6 @@ QCryptoBlock *qcrypto_block_open(QCryptoBlockOpenOptions = *options, QCryptoBlockReadFunc readfunc, void *opaque, unsigned int flags, - size_t n_threads, Error **errp) { QCryptoBlock *block =3D g_new0(QCryptoBlock, 1); @@ -73,7 +72,7 @@ QCryptoBlock *qcrypto_block_open(QCryptoBlockOpenOptions = *options, block->driver =3D qcrypto_block_drivers[options->format]; =20 if (block->driver->open(block, options, optprefix, - readfunc, opaque, flags, n_threads, errp) < 0) + readfunc, opaque, flags, errp) < 0) { g_free(block); return NULL; diff --git a/tests/unit/test-crypto-block.c b/tests/unit/test-crypto-block.c index 6cfc817a92..42cfab6067 100644 --- a/tests/unit/test-crypto-block.c +++ b/tests/unit/test-crypto-block.c @@ -303,7 +303,6 @@ static void test_block(gconstpointer opaque) test_block_read_func, &header, 0, - 1, NULL); g_assert(blk =3D=3D NULL); =20 @@ -312,7 +311,6 @@ static void test_block(gconstpointer opaque) test_block_read_func, &header, QCRYPTO_BLOCK_OPEN_NO_IO, - 1, &error_abort); =20 g_assert(qcrypto_block_get_cipher(blk) =3D=3D NULL); @@ -327,7 +325,6 @@ static void test_block(gconstpointer opaque) test_block_read_func, &header, 0, - 1, &error_abort); g_assert(blk); =20 @@ -384,7 +381,6 @@ test_luks_bad_header(gconstpointer data) test_block_read_func, &buf, 0, - 1, &err); g_assert(!blk); g_assert(err); --=20 2.45.2