From nobody Mon Feb 9 16:53:03 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=oracle.com ARC-Seal: i=1; a=rsa-sha256; t=1587616342; cv=none; d=zohomail.com; s=zohoarc; b=euLnuJsIMm1WbFUcuXC+fdbDm12pVfnWNRvyIpLqe1ajs1q1a9JbPvSn2pDIgNN3dc0SdCTm6v7tzvPq7VMxfqQqzHucGuLR1nAAoMuQokCDjn8L+NtAUxW3piuOGKQVczShwZKQdaA14eAMHdPYQFmluE0Cd2Rf25i6yxTSIsI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1587616342; 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=6MI7OMXkw4mkbhw+Rl2Uw8cIgWTp5a9k/egU8WM9EAU=; b=aN2bEVVVdwacMrwoj696vt4Oa1O5NhmHnGY4VaY7fi73dxiB1IwbP/9GxDqUyGgN7lxA5DO+cpTuW7a9hlxHJfegc2yUn4xg7ZtpI4IEznYw3CNU/bBrUPTycSEBGTaIHg442KLJl8sjv8xqGi93WxNvx651rWGL67R64q4R2eQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1587616342093978.1854361020402; Wed, 22 Apr 2020 21:32:22 -0700 (PDT) Received: from localhost ([::1]:35740 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jRTXA-0002H5-HH for importer@patchew.org; Thu, 23 Apr 2020 00:32:20 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50434) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jRTII-0003S3-Ho for qemu-devel@nongnu.org; Thu, 23 Apr 2020 00:16:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.90_1) (envelope-from ) id 1jRTIH-0002hK-Qs for qemu-devel@nongnu.org; Thu, 23 Apr 2020 00:16:58 -0400 Received: from userp2130.oracle.com ([156.151.31.86]:56018) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jRTIH-0002e0-6C for qemu-devel@nongnu.org; Thu, 23 Apr 2020 00:16:57 -0400 Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 03N4CV7O064315; Thu, 23 Apr 2020 04:16:50 GMT Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by userp2130.oracle.com with ESMTP id 30grpgtrwx-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 23 Apr 2020 04:16:50 +0000 Received: from pps.filterd (userp3030.oracle.com [127.0.0.1]) by userp3030.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 03N4CIho089325; Thu, 23 Apr 2020 04:14:49 GMT Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by userp3030.oracle.com with ESMTP id 30gb1ku7uy-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 23 Apr 2020 04:14:49 +0000 Received: from abhmp0020.oracle.com (abhmp0020.oracle.com [141.146.116.26]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id 03N4Elbo020761; Thu, 23 Apr 2020 04:14:47 GMT Received: from flaka.hsd1.ca.comcast.net (/67.180.143.163) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 22 Apr 2020 21:14:47 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=corp-2020-01-29; bh=6MI7OMXkw4mkbhw+Rl2Uw8cIgWTp5a9k/egU8WM9EAU=; b=Yxi7nRIyxTLpxYYw/5rEnfATmOyp1qiQdeEBxV+RNDOSW2e+Mq2+baOKQYUPHdUuNGbg H4ZCiM5KRWYXAF95N3QuDPKWNZ6m4Dm0scEEYtEeGAR4PHZnL1jhXPUN1gXEPjl/ZjK3 Cr9J+8ZN9JT2Y5mK+3qMV4iWW+XgAl1SFwoT/0OX/QoiMnq0MPCPX64DCuEOrv9cjiv8 KF2HtgCBtZmlRlQrp38Edp3ZYEOgZ42NoCDF3SJissKyTQe1Jt6ZuRBe3fA72PFpZBP8 fVGSuzoUpwv1vWS75uS9WDomNGjYPprGFFPK0ulcpOEg87NxLJcCg0t+CLqhou5i/b+P ww== From: elena.ufimtseva@oracle.com To: qemu-devel@nongnu.org Subject: [PATCH RESEND v6 12/36] multi-process: add functions to synchronize proxy and remote endpoints Date: Wed, 22 Apr 2020 21:13:47 -0700 Message-Id: <7542e59e646421515051902fcd05fbb69fa4d866.1587614626.git.elena.ufimtseva@oracle.com> X-Mailer: git-send-email 2.25.GIT In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9599 signatures=668686 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 suspectscore=1 spamscore=0 mlxlogscore=999 mlxscore=0 malwarescore=0 bulkscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2003020000 definitions=main-2004230027 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9599 signatures=668686 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 mlxscore=0 lowpriorityscore=0 adultscore=0 suspectscore=1 bulkscore=0 clxscore=1015 malwarescore=0 phishscore=0 spamscore=0 priorityscore=1501 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2003020000 definitions=main-2004230027 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=156.151.31.86; envelope-from=elena.ufimtseva@oracle.com; helo=userp2130.oracle.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/04/23 00:14:28 X-ACL-Warn: Detected OS = Linux 3.x [generic] [fuzzy] X-Received-From: 156.151.31.86 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: elena.ufimtseva@oracle.com, fam@euphon.net, swapnil.ingle@nutanix.com, john.g.johnson@oracle.com, kraxel@redhat.com, jag.raman@oracle.com, quintela@redhat.com, mst@redhat.com, armbru@redhat.com, kanth.ghatraju@oracle.com, felipe@nutanix.com, thuth@redhat.com, ehabkost@redhat.com, konrad.wilk@oracle.com, dgilbert@redhat.com, liran.alon@oracle.com, stefanha@redhat.com, thanos.makatos@nutanix.com, rth@twiddle.net, kwolf@redhat.com, berrange@redhat.com, mreitz@redhat.com, ross.lagerwall@citrix.com, marcandre.lureau@gmail.com, pbonzini@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" From: Jagannathan Raman In some cases, for example MMIO read, QEMU has to wait for the remote to complete a command before proceeding. An eventfd based mechanism is added to synchronize QEMU & remote process. Signed-off-by: John G Johnson Signed-off-by: Jagannathan Raman Signed-off-by: Elena Ufimtseva --- include/io/mpqemu-link.h | 7 +++++ io/mpqemu-link.c | 61 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+) diff --git a/include/io/mpqemu-link.h b/include/io/mpqemu-link.h index af401e640c..ef95599bca 100644 --- a/include/io/mpqemu-link.h +++ b/include/io/mpqemu-link.h @@ -124,4 +124,11 @@ void mpqemu_link_set_callback(MPQemuLinkState *s, void mpqemu_start_coms(MPQemuLinkState *s, MPQemuChannel* chan); bool mpqemu_msg_valid(MPQemuMsg *msg); =20 +#define GET_REMOTE_WAIT eventfd(0, EFD_CLOEXEC) +#define PUT_REMOTE_WAIT(wait) close(wait) +#define PROXY_LINK_WAIT_DONE 1 + +uint64_t wait_for_remote(int efd); +void notify_proxy(int fd, uint64_t val); + #endif diff --git a/io/mpqemu-link.c b/io/mpqemu-link.c index 48f53a8928..cc0a7aecd4 100644 --- a/io/mpqemu-link.c +++ b/io/mpqemu-link.c @@ -10,6 +10,7 @@ =20 #include "qemu/osdep.h" #include "qemu-common.h" +#include =20 #include "qemu/module.h" #include "io/mpqemu-link.h" @@ -204,6 +205,66 @@ int mpqemu_msg_recv(MPQemuMsg *msg, MPQemuChannel *cha= n) return rc; } =20 +/* + * wait_for_remote() Synchronizes QEMU and the remote process. The maximum + * wait time is 1s, after which the wait times out. + * The function alse returns a 64 bit return value after + * the wait. The function uses eventfd() to do the wait + * and pass the return values. eventfd() can't return a + * value of '0'. Therefore, all return values are offset + * by '1' at the sending end, and corrected at the + * receiving end. + */ + +uint64_t wait_for_remote(int efd) +{ + struct pollfd pfd =3D { .fd =3D efd, .events =3D POLLIN }; + uint64_t val; + int ret; + + ret =3D poll(&pfd, 1, 1000); + + switch (ret) { + case 0: + qemu_log_mask(LOG_REMOTE_DEBUG, "Error wait_for_remote: Timed out\= n"); + /* TODO: Kick-off error recovery */ + return UINT64_MAX; + case -1: + qemu_log_mask(LOG_REMOTE_DEBUG, "Poll error wait_for_remote: %s\n", + strerror(errno)); + return UINT64_MAX; + default: + if (read(efd, &val, sizeof(val)) =3D=3D -1) { + qemu_log_mask(LOG_REMOTE_DEBUG, "Error wait_for_remote: %s\n", + strerror(errno)); + return UINT64_MAX; + } + } + + /* + * The remote process could write a non-zero value + * to the eventfd to wake QEMU up. However, the drawback of using even= tfd + * for this purpose is that a return value of zero wouldn't wake QEMU = up. + * Therefore, we offset the return value by one at the remote process = and + * correct it in the QEMU end. + */ + val =3D (val =3D=3D UINT64_MAX) ? val : (val - 1); + + return val; +} + +void notify_proxy(int efd, uint64_t val) +{ + val =3D (val =3D=3D UINT64_MAX) ? val : (val + 1); + ssize_t len =3D -1; + + len =3D write(efd, &val, sizeof(val)); + if (len =3D=3D -1 || len !=3D sizeof(val)) { + qemu_log_mask(LOG_REMOTE_DEBUG, "Error notify_proxy: %s\n", + strerror(errno)); + } +} + static gboolean mpqemu_link_handler_prepare(GSource *gsrc, gint *timeout) { g_assert(timeout); --=20 2.25.GIT