All of lore.kernel.org
 help / color / mirror / Atom feed
From: Peter Maydell <peter.maydell@linaro.org>
To: Laurent Vivier <laurent@vivier.eu>
Cc: "QEMU Developers" <qemu-devel@nongnu.org>,
	"Richard Henderson" <rth@twiddle.net>,
	"Alex Bennée" <alex.bennee@linaro.org>
Subject: Re: [Qemu-devel] [PULL 23/32] tcg: Support MMU protection regions smaller than TARGET_PAGE_SIZE
Date: Fri, 29 Jun 2018 13:14:50 +0100	[thread overview]
Message-ID: <CAFEAcA8jVXUapKN7nP5eJ0SAP5QWa_PHeZXThZEN3Gn249qRug@mail.gmail.com> (raw)
In-Reply-To: <489d8470-c12f-a441-4e87-b2b3013a3ab8@vivier.eu>

On 28 June 2018 at 23:26, Laurent Vivier <laurent@vivier.eu> wrote:
> ./m68k-softmmu/qemu-system-m68k -M q800 \
>     -serial none -serial mon:stdio \
>     -kernel vmlinux-4.15.0-2-m68k \
>     -nographic

Thanks for the test case. I'm still investigating, but there
are a couple of things happening here.

First, there's a bug in get_page_addr_code()'s "is this a
TLB miss?" condition which was introduced in commit 71b9a45330fe22:

    if (unlikely(env->tlb_table[mmu_idx][index].addr_code !=
                 (addr & (TARGET_PAGE_MASK | TLB_INVALID_MASK)))) {

takes a (not necessarily page aligned) address, and masks out
everything but the page-aligned top half (good) and the
TLB_INVALID bit (not good, because that could be either 0 or 1
depending on the address). This means sometimes we'll incorrectly
decide we got a miss in the TLB and do an unnecessary refill.

The second thing that's going on here is that the m68k target
code writes TLB entries for the same address with different
prot bits without doing a flush in between:

tlb_set_page_with_attrs: vaddr=0029b000 paddr=0x000000000029b000 prot=3 idx=0
tlb_set_page_with_attrs: vaddr=0029b000 paddr=0x000000000029b000 prot=7 idx=0

The tlb_set_page_with_attrs() code isn't expecting this, so
we end up with two TLB entries for the same address, one in
the main TLB and one in the victim cache TLB. The bug above
means that we get this sequence of events:
 * fill main TLB entry with prot=3 entry
 * later, fill main TLB with prot=7 entry, and evict prot=3
   entry to victim cache
 * hit on the prot=7 entry in the main TLB
 * refill condition incorrectly fails, but we hit in the victim cache
 * so we pull the prot=3 entry from victim to main TLB
 * prot=3 means "addr_code == -1", so the check of the TLB_RECHECK
   bit succeeds
 * in the TLB_RECHECK code we do a tlb_fill()
 * that fills in the main TLB with a prot=7 entry again, bouncing
   the prot=3 entry back out to the victim cache
 * prot=7 means the addr_code is correct, so we find ourselves in
   the "TLB_RECHECK but this is RAM" abort code path

I'm not sure whether it's supposed to be the responsibility
of the target code or the common accel/tcg code to ensure
that we don't have multiple TLB entries for the same address.

thanks
-- PMM

  reply	other threads:[~2018-06-29 12:15 UTC|newest]

Thread overview: 43+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-06-26 16:56 [Qemu-devel] [PULL 00/32] target-arm queue Peter Maydell
2018-06-26 16:56 ` [Qemu-devel] [PULL 01/32] aspeed/smc: fix dummy cycles count when in dual IO mode Peter Maydell
2018-06-26 16:56 ` [Qemu-devel] [PULL 02/32] aspeed/smc: fix HW strapping Peter Maydell
2018-06-26 16:56 ` [Qemu-devel] [PULL 03/32] aspeed/smc: rename aspeed_smc_flash_send_addr() to aspeed_smc_flash_setup() Peter Maydell
2018-06-26 16:56 ` [Qemu-devel] [PULL 04/32] MAINTAINERS: Adopt the Gumstix computers-on-module machines Peter Maydell
2018-06-26 16:56 ` [Qemu-devel] [PULL 05/32] xilinx_spips: Make dma transactions as per dma_burst_size Peter Maydell
2018-06-26 16:56 ` [Qemu-devel] [PULL 06/32] MAINTAINERS: Add ASPEED BMCs Peter Maydell
2018-06-26 16:56 ` [Qemu-devel] [PULL 07/32] hw/input/pckbd: Use qemu_log_mask(GUEST_ERROR) instead of fprintf Peter Maydell
2018-06-26 16:56 ` [Qemu-devel] [PULL 08/32] hw/input/tsc2005: " Peter Maydell
2018-06-26 16:56 ` [Qemu-devel] [PULL 09/32] hw/dma/omap_dma: Use qemu_log_mask(UNIMP) instead of printf Peter Maydell
2018-06-26 16:56 ` [Qemu-devel] [PULL 10/32] hw/dma/omap_dma: Use qemu_log_mask(GUEST_ERROR) instead of fprintf Peter Maydell
2018-06-26 16:56 ` [Qemu-devel] [PULL 11/32] hw/ssi/omap_spi: " Peter Maydell
2018-06-26 16:56 ` [Qemu-devel] [PULL 12/32] hw/sd/omap_mmc: Use qemu_log_mask(UNIMP) instead of printf Peter Maydell
2018-06-26 16:56 ` [Qemu-devel] [PULL 13/32] hw/i2c/omap_i2c: Use qemu_log_mask(UNIMP) instead of fprintf Peter Maydell
2018-06-26 16:56 ` [Qemu-devel] [PULL 14/32] hw/arm/omap1: Use qemu_log_mask(GUEST_ERROR) " Peter Maydell
2018-06-26 16:56 ` [Qemu-devel] [PULL 15/32] hw/arm/omap: " Peter Maydell
2018-06-26 16:56 ` [Qemu-devel] [PULL 16/32] hw/arm/stellaris: Use qemu_log_mask(UNIMP) " Peter Maydell
2018-06-26 16:56 ` [Qemu-devel] [PULL 17/32] hw/net/stellaris_enet: Fix a typo Peter Maydell
2018-06-26 16:56 ` [Qemu-devel] [PULL 18/32] hw/net/stellaris_enet: Use qemu_log_mask(GUEST_ERROR) instead of hw_error Peter Maydell
2018-06-26 16:56 ` [Qemu-devel] [PULL 19/32] hw/net/smc91c111: " Peter Maydell
2018-06-26 16:56 ` [Qemu-devel] [PULL 20/32] hw/net/smc91c111: Use qemu_log_mask(UNIMP) instead of fprintf Peter Maydell
2018-06-26 16:56 ` [Qemu-devel] [PULL 21/32] hw/arm/stellaris: Fix gptm_write() error message Peter Maydell
2018-06-26 16:56 ` [Qemu-devel] [PULL 22/32] hw/arm/stellaris: Use HWADDR_PRIx to display register address Peter Maydell
2018-06-26 16:56 ` [Qemu-devel] [PULL 23/32] tcg: Support MMU protection regions smaller than TARGET_PAGE_SIZE Peter Maydell
2018-06-28 13:03   ` Laurent Vivier
2018-06-28 13:23     ` Peter Maydell
2018-06-28 19:23       ` Laurent Vivier
2018-06-28 20:05         ` Peter Maydell
2018-06-28 22:26           ` Laurent Vivier
2018-06-29 12:14             ` Peter Maydell [this message]
2018-06-29 14:07               ` Alex Bennée
2018-06-29 15:28             ` Peter Maydell
2018-06-29 15:52               ` Laurent Vivier
2018-06-26 16:56 ` [Qemu-devel] [PULL 24/32] target/arm: Set page (region) size in get_phys_addr_pmsav7() Peter Maydell
2018-06-26 16:56 ` [Qemu-devel] [PULL 25/32] target/arm: Handle small regions in get_phys_addr_pmsav8() Peter Maydell
2018-06-26 16:56 ` [Qemu-devel] [PULL 26/32] hw/arm/smmuv3: Fix translate error handling Peter Maydell
2018-06-26 16:56 ` [Qemu-devel] [PULL 27/32] hw/arm/smmuv3: Cache/invalidate config data Peter Maydell
2018-06-26 16:56 ` [Qemu-devel] [PULL 28/32] hw/arm/smmuv3: IOTLB emulation Peter Maydell
2018-06-26 16:56 ` [Qemu-devel] [PULL 29/32] hw/arm/smmuv3: Add notifications on invalidation Peter Maydell
2018-06-26 16:56 ` [Qemu-devel] [PULL 30/32] aspeed/scu: introduce clock frequencies Peter Maydell
2018-06-26 16:56 ` [Qemu-devel] [PULL 31/32] aspeed: initialize the SCU controller first Peter Maydell
2018-06-26 16:56 ` [Qemu-devel] [PULL 32/32] aspeed/timer: use the APB frequency from the SCU Peter Maydell
2018-06-26 18:19 ` [Qemu-devel] [PULL 00/32] target-arm queue Peter Maydell

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=CAFEAcA8jVXUapKN7nP5eJ0SAP5QWa_PHeZXThZEN3Gn249qRug@mail.gmail.com \
    --to=peter.maydell@linaro.org \
    --cc=alex.bennee@linaro.org \
    --cc=laurent@vivier.eu \
    --cc=qemu-devel@nongnu.org \
    --cc=rth@twiddle.net \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.