public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: "Nicholas Piggin" <npiggin@gmail.com>
To: "Thomas Huth" <thuth@redhat.com>,
	"Andrew Jones" <andrew.jones@linux.dev>,
	"Alexandru Elisei" <alexandru.elisei@arm.com>,
	"Eric Auger" <eric.auger@redhat.com>, <kvm@vger.kernel.org>
Cc: <kvmarm@lists.linux.dev>
Subject: Re: [kvm-unit-tests PATCH] lib/arm/io: Fix calling getchar() multiple times
Date: Sun, 18 Feb 2024 00:28:01 +1000	[thread overview]
Message-ID: <CZ7FAVZ6J6DF.22SLKG0NAG6HL@wheely> (raw)
In-Reply-To: <20240216140210.70280-1-thuth@redhat.com>

On Sat Feb 17, 2024 at 12:02 AM AEST, Thomas Huth wrote:
> getchar() can currently only be called once on arm since the implementation
> is a little bit too  naïve: After the first character has arrived, the
> data register never gets set to zero again. To properly check whether a
> byte is available, we need to check the "RX fifo empty" on the pl011 UART
> or the "RX data ready" bit on the ns16550a UART instead.
>
> With this proper check in place, we can finally also get rid of the
> ugly assert(count < 16) statement here.
>

Thanks, this seems to work well. But arm64 still behaves strangely
with QEMU migration. It seems some odd corruption around __getchar,
but this turns out not to have anything to do with the MMIO read,
but it's just because the test case generally is spinning there
when a migration happens.

I modified __getchar() to the following, which removes the MMIO
entirely and just waits a number of times called before returning
a getchar, chosen to be enough time for QEMU migration to complete
on my system...

int __getchar(void)
{
        static int i;
        static volatile int locked;
        int ret = -1;

        assert(!locked);
        locked = 1;
        assert(locked);
        cpu_relax();
        assert(locked);

        i++;
        if (i >= 3000000) {
                i = 0;
                ret = 1;
        }

        assert(locked);
        locked = 0;
        assert(!locked);

        return ret;
}

I get asserts on the line right after cpu_relax() on arm64 after a
few migrations on migration selftest.

Without the cpu_relax() it takes longer to hit an assert and it's
usually the first one. I expect this is related to TCG translation
blocks and where it exits back to be migrated. Something is very
strange, I suspect it's QEMU migration bug.

Thanks,
Nick

  parent reply	other threads:[~2024-02-17 14:28 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-16 14:02 [kvm-unit-tests PATCH] lib/arm/io: Fix calling getchar() multiple times Thomas Huth
2024-02-17 10:43 ` Nicholas Piggin
2024-02-19  6:59   ` Thomas Huth
2024-02-19 11:58     ` Nicholas Piggin
2024-02-19 13:46       ` Andrew Jones
2024-02-17 14:28 ` Nicholas Piggin [this message]
2024-02-19 14:22 ` Andrew Jones
2024-02-19 16:56 ` Alexandru Elisei
2024-02-20  1:37   ` Nicholas Piggin
2024-02-20  8:51   ` Nicholas Piggin
2024-02-20 10:22     ` Alexandru Elisei
2024-02-21  3:39 ` Nicholas Piggin
2024-02-21  7:42 ` Andrew Jones

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CZ7FAVZ6J6DF.22SLKG0NAG6HL@wheely \
    --to=npiggin@gmail.com \
    --cc=alexandru.elisei@arm.com \
    --cc=andrew.jones@linux.dev \
    --cc=eric.auger@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=kvmarm@lists.linux.dev \
    --cc=thuth@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox