From patchwork Mon Jun 20 14:29:01 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 9187785 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 6BC8F601C0 for ; Mon, 20 Jun 2016 15:18:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5901B26861 for ; Mon, 20 Jun 2016 15:18:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4C10B271FD; Mon, 20 Jun 2016 15:18:49 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id DED9226861 for ; Mon, 20 Jun 2016 15:18:48 +0000 (UTC) Received: from localhost ([::1]:44291 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bF0yN-0003ih-Cz for patchwork-qemu-devel@patchwork.kernel.org; Mon, 20 Jun 2016 11:18:47 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54030) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bF0CW-00089O-US for qemu-devel@nongnu.org; Mon, 20 Jun 2016 10:29:22 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bF0CM-0003Az-Rr for qemu-devel@nongnu.org; Mon, 20 Jun 2016 10:29:19 -0400 Received: from mail-wm0-x243.google.com ([2a00:1450:400c:c09::243]:36300) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bF0CM-0003Av-Kt for qemu-devel@nongnu.org; Mon, 20 Jun 2016 10:29:10 -0400 Received: by mail-wm0-x243.google.com with SMTP id c82so11608396wme.3 for ; Mon, 20 Jun 2016 07:29:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=xHMBBrdj/P6bBtPlIP4+KCV+PU5YX4oDW4yf5xIHZ5U=; b=beBdjhQXIdudr84C6j0pkBrMF3a/DpQIHVB/9l34jDvr5EPfPWeEnMMpbc2wJJVolh F0C5pmyzt9erbspgwrTlqR7OQt9SjVpanTG2FS7majtM8RsTYalVDtHbcZ285MErXIdZ 3O+41Z2PgXn5DAbzcyoWhAHKavc0LlLGt/NP2a8TWdolbtpteQDZ1dKwbz+NSGtCZ7ay acczCsS1jDUBWsZWC16zNCbxvYxRQfXAJf97Ru2sae1cGx5z3ggIh5u75BjZdgyR6nW2 ndcAMgAhP/JRwH6SF21D3DMQp3vz6BL6Q5kGTxtgiM4ZYMWxr45VVZe8V/G9M/+wLJiW RZAg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=xHMBBrdj/P6bBtPlIP4+KCV+PU5YX4oDW4yf5xIHZ5U=; b=VtlwvHdZyq3O53L8953MfpMYtZtsl4+G9Qd5bFmhdMfyMda2C8b5l2/1TXQJXKRMil r81zLR4H9YDYc9W+JmEeYDprqBsv4AC0YHypiwoBBXNJ0I9RaestoIPmMHZ05hU5qTLz wEX/KKdv6ioBSYaVWVCrMtojwANVQabELmXeSkn6elQyXsWEiGEhyJBRaPGPab0GrNeG cS8lHBSZH8bAwnca2kpD15IsdyrRRmIa0Af0MIhhYNGVpFCW/mxImiNU6KU0+ukV0dSH tBb8/rLOD6cXeXrmBh+nnPus66LLYSse2oYSR5mcN0O8y3pzHQviUGBfKrtJxUrfKRoA /dCQ== X-Gm-Message-State: ALyK8tKVkepd6Q9ypX7LEmKEGyPwgtE38u1mj33gwpXDNsqaKN8wJiHGBvwbXCjG3xoYKw== X-Received: by 10.28.157.1 with SMTP id g1mr12002230wme.34.1466432949992; Mon, 20 Jun 2016 07:29:09 -0700 (PDT) Received: from donizetti.lan (94-39-188-118.adsl-ull.clienti.tiscali.it. [94.39.188.118]) by smtp.gmail.com with ESMTPSA id bb4sm24359892wjb.32.2016.06.20.07.29.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 20 Jun 2016 07:29:08 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Mon, 20 Jun 2016 16:29:01 +0200 Message-Id: <1466432945-28682-3-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 2.5.5 In-Reply-To: <1466432945-28682-1-git-send-email-pbonzini@redhat.com> References: <1466432945-28682-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a00:1450:400c:c09::243 Subject: [Qemu-devel] [PATCH 2/6] serial: reinstate watch after migration X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: bcketchum@gmail.com, dgilbert@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Otherwise, a serial port can get stuck if it is migrated while flow control is in effect. Signed-off-by: Paolo Bonzini --- hw/char/serial.c | 16 ++++++++++++++-- include/hw/char/serial.h | 1 + 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/hw/char/serial.c b/hw/char/serial.c index e65e9e0..6f0a49e 100644 --- a/hw/char/serial.c +++ b/hw/char/serial.c @@ -639,8 +639,20 @@ static int serial_post_load(void *opaque, int version_id) if (s->thr_ipending == -1) { s->thr_ipending = ((s->iir & UART_IIR_ID) == UART_IIR_THRI); } - if (s->tsr_retry > MAX_XMIT_RETRY) { - s->tsr_retry = MAX_XMIT_RETRY; + + if (s->tsr_retry > 0) { + /* tsr_retry > 0 implies LSR.TEMT = 0 (transmitter not empty). */ + if (s->lsr & UART_LSR_TEMT) { + return -1; + } + + assert(s->watch_tag == 0); + s->watch_tag = qemu_chr_fe_add_watch(s->chr, G_IO_OUT|G_IO_HUP, serial_xmit, s); + } else { + /* tsr_retry == 0 implies LSR.TEMT = 1 (transmitter empty). */ + if (!(s->lsr & UART_LSR_TEMT)) { + return -1; + } } s->last_break_enable = (s->lcr >> 6) & 1; diff --git a/include/hw/char/serial.h b/include/hw/char/serial.h index ef90615..2ab835c 100644 --- a/include/hw/char/serial.h +++ b/include/hw/char/serial.h @@ -56,6 +56,7 @@ struct SerialState { int it_shift; int baudbase; unsigned tsr_retry; + unsigned watch_tag; uint32_t wakeup; /* Time when the last byte was successfully sent out of the tsr */