From nobody Tue Oct 7 02:15:49 2025 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=kernel.org ARC-Seal: i=1; a=rsa-sha256; t=1590090467; cv=none; d=zohomail.com; s=zohoarc; b=kVPripX0gJzqExCT6dPBafVIZI8jlk5Co4N5o4gOFq/G+YwJsB5kIYk6g+2AJdSsocQfVknRgvEGdGo2qkvNp+lhuYObN0H0j5WMLjfKjLdahWwKEH/YaEAIsh9fC4ww1PyWCFkldkLt6nVbiyE6HU0u2LXGnJX2K89B5czAivQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1590090467; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=ts6x+GwzzB2zp3jwCox+QM5F1kzK0sGVKcYCFaNfrZM=; b=PzB3/PF+EcNgqMP5fJU/kslNUEClq6CbbrnATdX8JzLxCwNBH2vD7VKtPFCbjbyFZ4Fi3vFecHDdrEWit+Ni5P0NxJileyOPO0pKVxWvayc+hojKyLGsm5kcYPXuYc8np6v8yrkufs1sMXQDJqZAXv4/cTCZm3qsVFBjcdOdGnI= 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 1590090467104471.2839062863785; Thu, 21 May 2020 12:47:47 -0700 (PDT) Received: from localhost ([::1]:36812 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jbrAP-0003cJ-Qu for importer@patchew.org; Thu, 21 May 2020 15:47:45 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39164) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jbqps-0007xW-NT for qemu-devel@nongnu.org; Thu, 21 May 2020 15:26:32 -0400 Received: from mail.kernel.org ([198.145.29.99]:46348) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jbqpq-0002Yq-BT for qemu-devel@nongnu.org; Thu, 21 May 2020 15:26:32 -0400 Received: from sstabellini-ThinkPad-T480s.hsd1.ca.comcast.net (c-67-164-102-47.hsd1.ca.comcast.net [67.164.102.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id B1F1020823; Thu, 21 May 2020 19:26:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1590089189; bh=OLinQC9iMGghSpuw/kVjTtdK+MSS8ybD0n5V6iGg1R0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Mn2ybyc5RdBn3P9lPA+JIa0Jo3DN94gHiKwtjQptGdwW5ZJqnrLnVXzmvybaAKoEv UzcIWpKiGMXhIgU5G0u9xGmoo+uvNjJN48OxRr5m8L82iYMte3K5x+RN1Oe/YOlJcN P/Rl6hcJ+gHh4IRDkbRX58V8RAehPqMHIlS7ZKsQ= From: Stefano Stabellini To: groug@kaod.org Subject: [PATCH v2 2/3] xen/9pfs: yield when there isn't enough room on the ring Date: Thu, 21 May 2020 12:26:26 -0700 Message-Id: <20200521192627.15259-2-sstabellini@kernel.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: 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=198.145.29.99; envelope-from=sstabellini@kernel.org; helo=mail.kernel.org X-detected-operating-system: by eggs.gnu.org: First seen = 2020/05/21 15:26:19 X-ACL-Warn: Detected OS = Linux 3.11 and newer X-Spam_score_int: -70 X-Spam_score: -7.1 X-Spam_bar: ------- X-Spam_report: (-7.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_HI=-5, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN 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: sstabellini@kernel.org, paul@xen.org, qemu_oss@crudebyte.com, qemu-devel@nongnu.org, anthony.perard@citrix.com, Stefano Stabellini Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Stefano Stabellini Instead of truncating replies, which is problematic, wait until the client reads more data and frees bytes on the reply ring. Do that by calling qemu_coroutine_yield(). The corresponding qemu_coroutine_enter_if_inactive() is called from xen_9pfs_bh upon receiving the next notification from the client. We need to be careful to avoid races in case xen_9pfs_bh and the coroutine are both active at the same time. In xen_9pfs_bh, wait until either the critical section is over (ring->co =3D=3D NULL) or until the coroutine becomes inactive (qemu_coroutine_yield() was called) before continuing. Then, simply wake up the coroutine if it is inactive. Signed-off-by: Stefano Stabellini Reviewed-by: Christian Schoenebeck --- Changes in v2: - add comments on barriers --- hw/9pfs/xen-9p-backend.c | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/hw/9pfs/xen-9p-backend.c b/hw/9pfs/xen-9p-backend.c index fc197f6c8a..3c84c86ab8 100644 --- a/hw/9pfs/xen-9p-backend.c +++ b/hw/9pfs/xen-9p-backend.c @@ -37,6 +37,7 @@ typedef struct Xen9pfsRing { =20 struct iovec *sg; QEMUBH *bh; + Coroutine *co; =20 /* local copies, so that we can read/write PDU data directly from * the ring */ @@ -198,16 +199,20 @@ static void xen_9pfs_init_in_iov_from_pdu(V9fsPDU *pd= u, g_free(ring->sg); =20 ring->sg =3D g_new0(struct iovec, 2); - xen_9pfs_in_sg(ring, ring->sg, &num, pdu->idx, size); + ring->co =3D qemu_coroutine_self(); + /* make sure other threads see ring->co changes before continuing */ + smp_wmb(); =20 +again: + xen_9pfs_in_sg(ring, ring->sg, &num, pdu->idx, size); buf_size =3D iov_size(ring->sg, num); if (buf_size < size) { - xen_pv_printf(&xen_9pfs->xendev, 0, "Xen 9pfs request type %d" - "needs %zu bytes, buffer has %zu\n", pdu->id, size, - buf_size); - xen_be_set_state(&xen_9pfs->xendev, XenbusStateClosing); - xen_9pfs_disconnect(&xen_9pfs->xendev); + qemu_coroutine_yield(); + goto again; } + ring->co =3D NULL; + /* make sure other threads see ring->co changes before continuing */ + smp_wmb(); =20 *piov =3D ring->sg; *pniov =3D num; @@ -292,6 +297,20 @@ static int xen_9pfs_receive(Xen9pfsRing *ring) static void xen_9pfs_bh(void *opaque) { Xen9pfsRing *ring =3D opaque; + bool wait; + +again: + wait =3D ring->co !=3D NULL && qemu_coroutine_entered(ring->co); + /* paired with the smb_wmb barriers in xen_9pfs_init_in_iov_from_pdu */ + smp_rmb(); + if (wait) { + cpu_relax(); + goto again; + } + + if (ring->co !=3D NULL) { + qemu_coroutine_enter_if_inactive(ring->co); + } xen_9pfs_receive(ring); } =20 --=20 2.17.1