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=-15.2 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_SANE_2 autolearn=ham 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 8EEA4C433E0 for ; Thu, 28 Jan 2021 14:33:24 +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 E997864D9F for ; Thu, 28 Jan 2021 14:33:23 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E997864D9F Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=kaod.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:57276 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l58MM-0001wh-Vu for qemu-devel@archiver.kernel.org; Thu, 28 Jan 2021 09:33:23 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:42206) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l58KX-0000xa-M9 for qemu-devel@nongnu.org; Thu, 28 Jan 2021 09:31:29 -0500 Received: from smtpout1.mo804.mail-out.ovh.net ([79.137.123.220]:45055) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l58KV-0003qr-D4 for qemu-devel@nongnu.org; Thu, 28 Jan 2021 09:31:29 -0500 Received: from mxplan5.mail.ovh.net (unknown [10.108.16.220]) by mo804.mail-out.ovh.net (Postfix) with ESMTPS id A5D5C86B7E2B; Thu, 28 Jan 2021 15:31:24 +0100 (CET) Received: from kaod.org (37.59.142.102) by DAG8EX1.mxp5.local (172.16.2.71) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2106.2; Thu, 28 Jan 2021 15:31:23 +0100 Authentication-Results: garm.ovh; auth=pass (GARM-102R004109fc722-0dd6-4be3-9dd0-7f812e95b8e3, 12ABEFCAB104A9A3990DEAE01579FEA45C2F0BE3) smtp.auth=groug@kaod.org X-OVh-ClientIp: 78.197.208.248 Date: Thu, 28 Jan 2021 15:31:23 +0100 From: Greg Kurz To: Vivek Goyal Subject: Re: [PATCH 2/6] libvhost-user: Use slave_mutex in all slave messages Message-ID: <20210128153123.4aba231c@bahia.lan> In-Reply-To: <20210125180115.22936-3-vgoyal@redhat.com> References: <20210125180115.22936-1-vgoyal@redhat.com> <20210125180115.22936-3-vgoyal@redhat.com> X-Mailer: Claws Mail 3.17.8 (GTK+ 2.24.32; x86_64-redhat-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit X-Originating-IP: [37.59.142.102] X-ClientProxiedBy: DAG8EX2.mxp5.local (172.16.2.72) To DAG8EX1.mxp5.local (172.16.2.71) X-Ovh-Tracer-GUID: da706388-ba99-40a4-87b3-037476a23bd7 X-Ovh-Tracer-Id: 14608551292886096233 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: -100 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgeduledrfedtgdeifecutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfqggfjpdevjffgvefmvefgnecuuegrihhlohhuthemucehtddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjughrpeffhffvuffkjghfofggtgfgihesthejredtredtvdenucfhrhhomhepifhrvghgucfmuhhriicuoehgrhhouhhgsehkrghougdrohhrgheqnecuggftrfgrthhtvghrnhepfedutdeijeejveehkeeileetgfelteekteehtedtieefffevhffflefftdefleejnecukfhppedtrddtrddtrddtpdefjedrheelrddugedvrddutddvnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmohguvgepshhmthhpqdhouhhtpdhhvghlohepmhigphhlrghnhedrmhgrihhlrdhovhhhrdhnvghtpdhinhgvtheptddrtddrtddrtddpmhgrihhlfhhrohhmpehgrhhouhhgsehkrghougdrohhrghdprhgtphhtthhopehmshhtsehrvgguhhgrthdrtghomh Received-SPF: pass client-ip=79.137.123.220; envelope-from=groug@kaod.org; helo=smtpout1.mo804.mail-out.ovh.net X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham 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: mst@redhat.com, qemu-devel@nongnu.org, dgilbert@redhat.com, virtio-fs@redhat.com, stefanha@redhat.com, marcandre.lureau@redhat.com Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" On Mon, 25 Jan 2021 13:01:11 -0500 Vivek Goyal wrote: > dev->slave_mutex needs to be taken when sending messages on slave_fd. > Currently _vu_queue_notify() does not do that. > > Introduce a helper vu_message_slave_send_receive() which sends as well > as receive response. Use this helper in all the paths which send > message on slave_fd channel. > Does this fix any known bug ? > Signed-off-by: Vivek Goyal > --- LGTM Reviewed-by: Greg Kurz > subprojects/libvhost-user/libvhost-user.c | 50 ++++++++++++----------- > 1 file changed, 27 insertions(+), 23 deletions(-) > > diff --git a/subprojects/libvhost-user/libvhost-user.c b/subprojects/libvhost-user/libvhost-user.c > index 4cf4aef63d..7a56c56dc8 100644 > --- a/subprojects/libvhost-user/libvhost-user.c > +++ b/subprojects/libvhost-user/libvhost-user.c > @@ -403,7 +403,7 @@ vu_send_reply(VuDev *dev, int conn_fd, VhostUserMsg *vmsg) > * Processes a reply on the slave channel. > * Entered with slave_mutex held and releases it before exit. > * Returns true on success. > - * *payload is written on success > + * *payload is written on success, if payload is not NULL. > */ > static bool > vu_process_message_reply(VuDev *dev, const VhostUserMsg *vmsg, > @@ -427,7 +427,9 @@ vu_process_message_reply(VuDev *dev, const VhostUserMsg *vmsg, > goto out; > } > > - *payload = msg_reply.payload.u64; > + if (payload) { > + *payload = msg_reply.payload.u64; > + } > result = true; > > out: > @@ -435,6 +437,25 @@ out: > return result; > } > > +/* Returns true on success, false otherwise */ > +static bool > +vu_message_slave_send_receive(VuDev *dev, VhostUserMsg *vmsg, uint64_t *payload) > +{ > + pthread_mutex_lock(&dev->slave_mutex); > + if (!vu_message_write(dev, dev->slave_fd, vmsg)) { > + pthread_mutex_unlock(&dev->slave_mutex); > + return false; > + } > + > + if ((vmsg->flags & VHOST_USER_NEED_REPLY_MASK) == 0) { > + pthread_mutex_unlock(&dev->slave_mutex); > + return true; > + } > + > + /* Also unlocks the slave_mutex */ > + return vu_process_message_reply(dev, vmsg, payload); > +} > + > /* Kick the log_call_fd if required. */ > static void > vu_log_kick(VuDev *dev) > @@ -1340,16 +1361,8 @@ bool vu_set_queue_host_notifier(VuDev *dev, VuVirtq *vq, int fd, > return false; > } > > - pthread_mutex_lock(&dev->slave_mutex); > - if (!vu_message_write(dev, dev->slave_fd, &vmsg)) { > - pthread_mutex_unlock(&dev->slave_mutex); > - return false; > - } > - > - /* Also unlocks the slave_mutex */ > - res = vu_process_message_reply(dev, &vmsg, &payload); > + res = vu_message_slave_send_receive(dev, &vmsg, &payload); > res = res && (payload == 0); > - > return res; > } > > @@ -2395,10 +2408,7 @@ static void _vu_queue_notify(VuDev *dev, VuVirtq *vq, bool sync) > vmsg.flags |= VHOST_USER_NEED_REPLY_MASK; > } > > - vu_message_write(dev, dev->slave_fd, &vmsg); > - if (ack) { > - vu_message_read_default(dev, dev->slave_fd, &vmsg); > - } > + vu_message_slave_send_receive(dev, &vmsg, NULL); > return; > } > > @@ -2942,17 +2952,11 @@ int64_t vu_fs_cache_request(VuDev *dev, VhostUserSlaveRequest req, int fd, > return -EINVAL; > } > > - pthread_mutex_lock(&dev->slave_mutex); > - if (!vu_message_write(dev, dev->slave_fd, &vmsg)) { > - pthread_mutex_unlock(&dev->slave_mutex); > - return -EIO; > - } > - > - /* Also unlocks the slave_mutex */ > - res = vu_process_message_reply(dev, &vmsg, &payload); > + res = vu_message_slave_send_receive(dev, &vmsg, &payload); > if (!res) { > return -EIO; > } > + > /* > * Payload is delivered as uint64_t but is actually signed for > * errors.