From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 65B85C433ED for ; Thu, 6 May 2021 15:12:03 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id B75F66121F for ; Thu, 6 May 2021 15:12:02 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B75F66121F Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:51800 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1leffV-0001Th-Gq for qemu-devel@archiver.kernel.org; Thu, 06 May 2021 11:12:01 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35322) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lefcY-0007o3-4j for qemu-devel@nongnu.org; Thu, 06 May 2021 11:08:58 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:49151) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lefcP-00034u-Bu for qemu-devel@nongnu.org; Thu, 06 May 2021 11:08:57 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1620313727; 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=m9ewp5iHxi2zbqQP2rkue2ZUEh3U6+WHn2wG8f4/C6w=; b=ORa6GITT1Yq6uYYDw07jeqatPq9gWVJu0p9OS2xuktVLV7toUP+lX2XoR8wjobJZ5/Tvpk vs1jCK/lW0vnKSG+NLnfQjO40lxBEGlc8LUYRTCGLRvKlZmW9GB1iARHGrA0EiQoiVZjEk AZ616suVORP7eGxiNLTar32iginPabk= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-7-5HaQkt4_MJyW9Z20B_Obnw-1; Thu, 06 May 2021 11:08:45 -0400 X-MC-Unique: 5HaQkt4_MJyW9Z20B_Obnw-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 47AE76D5C8; Thu, 6 May 2021 15:08:44 +0000 (UTC) Received: from titinator (ovpn-112-210.ams2.redhat.com [10.36.112.210]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B67AC16909; Thu, 6 May 2021 15:08:38 +0000 (UTC) References: <20210506133758.1749233-1-philmd@redhat.com> <20210506133758.1749233-3-philmd@redhat.com> User-agent: mu4e 1.5.7; emacs 27.1 From: Christophe de Dinechin To: Philippe =?utf-8?Q?Mathieu-Daud=C3=A9?= Subject: Re: [PATCH v2 2/9] backends/tpm: Replace qemu_mutex_lock calls with QEMU_LOCK_GUARD Date: Thu, 06 May 2021 17:07:11 +0200 In-reply-to: <20210506133758.1749233-3-philmd@redhat.com> Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Received-SPF: pass client-ip=216.205.24.124; envelope-from=dinechin@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.69, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kvm@vger.kernel.org, Stefan Berger , qemu-devel@nongnu.org, qemu-arm@nongnu.org, qemu-ppc@nongnu.org, Gerd Hoffmann , Paolo Bonzini , Alex =?utf-8?Q?Benn=C3=A9e?= Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" On 2021-05-06 at 15:37 CEST, Philippe Mathieu-Daud=C3=A9 wrote... > Simplify the tpm_emulator_ctrlcmd() handler by replacing a pair of > qemu_mutex_lock/qemu_mutex_unlock calls by the WITH_QEMU_LOCK_GUARD > macro. > > Signed-off-by: Philippe Mathieu-Daud=C3=A9 > --- > backends/tpm/tpm_emulator.c | 34 +++++++++++++++------------------- > 1 file changed, 15 insertions(+), 19 deletions(-) > > diff --git a/backends/tpm/tpm_emulator.c b/backends/tpm/tpm_emulator.c > index a012adc1934..e5f1063ab6c 100644 > --- a/backends/tpm/tpm_emulator.c > +++ b/backends/tpm/tpm_emulator.c > @@ -30,6 +30,7 @@ > #include "qemu/error-report.h" > #include "qemu/module.h" > #include "qemu/sockets.h" > +#include "qemu/lockable.h" > #include "io/channel-socket.h" > #include "sysemu/tpm_backend.h" > #include "sysemu/tpm_util.h" > @@ -124,31 +125,26 @@ static int tpm_emulator_ctrlcmd(TPMEmulator *tpm, u= nsigned long cmd, void *msg, > uint32_t cmd_no =3D cpu_to_be32(cmd); > ssize_t n =3D sizeof(uint32_t) + msg_len_in; > uint8_t *buf =3D NULL; > - int ret =3D -1; > > - qemu_mutex_lock(&tpm->mutex); > + WITH_QEMU_LOCK_GUARD(&tpm->mutex) { > + buf =3D g_alloca(n); > + memcpy(buf, &cmd_no, sizeof(cmd_no)); > + memcpy(buf + sizeof(cmd_no), msg, msg_len_in); > > - buf =3D g_alloca(n); > - memcpy(buf, &cmd_no, sizeof(cmd_no)); > - memcpy(buf + sizeof(cmd_no), msg, msg_len_in); > - > - n =3D qemu_chr_fe_write_all(dev, buf, n); > - if (n <=3D 0) { > - goto end; > - } > - > - if (msg_len_out !=3D 0) { > - n =3D qemu_chr_fe_read_all(dev, msg, msg_len_out); > + n =3D qemu_chr_fe_write_all(dev, buf, n); > if (n <=3D 0) { > - goto end; > + return -1; > + } > + > + if (msg_len_out !=3D 0) { > + n =3D qemu_chr_fe_read_all(dev, msg, msg_len_out); > + if (n <=3D 0) { > + return -1; > + } > } > } > > - ret =3D 0; > - > -end: > - qemu_mutex_unlock(&tpm->mutex); > - return ret; > + return 0; > } > > static int tpm_emulator_unix_tx_bufs(TPMEmulator *tpm_emu, I really like the improvement, but it looks like it does not belong to the top-level series (i.e. not related to replacing alloca() by g_malloc()). Reviewed-by: Christophe de Dinechin -- Cheers, Christophe de Dinechin (IRC c3d)