All of lore.kernel.org
 help / color / mirror / Atom feed
From: Greg Kurz <groug@kaod.org>
To: David Gibson <david@gibson.dropbear.id.au>
Cc: pbonzini@redhat.com, qemu-devel@nongnu.org, qemu-ppc@nongnu.org,
	lvivier@redhat.com, agraf@suse.de, stefanha@redhat.com,
	mst@redhat.com, aik@ozlabs.ru, mdroth@linux.vnet.ibm.com,
	thuth@redhat.com
Subject: Re: [Qemu-devel] [PATCHv5 11/12] tests: Don't assume structure of PCI IO base in ahci-test
Date: Tue, 25 Oct 2016 10:58:34 +0200	[thread overview]
Message-ID: <20161025105834.65485dc3@bahia> (raw)
In-Reply-To: <1477285201-10244-12-git-send-email-david@gibson.dropbear.id.au>

On Mon, 24 Oct 2016 16:00:00 +1100
David Gibson <david@gibson.dropbear.id.au> wrote:

> In a couple of places ahci-test makes assumptions about how the tokens
> returned from qpci_iomap() are formatted in ways it probably shouldn't.
> 
> First in verify_state() it uses a non-NULL token to indicate that the AHCI
> device has been enabled (part of enabling is to iomap()).  This changes it
> to use an explicit 'enabled' flag instead.
> 
> Second, it uses the fact that the token contains a PCI address, stored when
> the BAR is mapped during initialization to check that the BAR has the same
> value after a migration.  This changes it to explicitly read the BAR
> register before and after the migration and compare.
> 
> Together, these changes will  make the test more robust against changes to
> the internals of the libqos PCI layer.
> 
> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
> ---

Reviewed-by: Greg Kurz <groug@kaod.org>

>  tests/ahci-test.c   | 13 +++++++------
>  tests/libqos/ahci.c |  1 +
>  tests/libqos/ahci.h |  1 +
>  3 files changed, 9 insertions(+), 6 deletions(-)
> 
> diff --git a/tests/ahci-test.c b/tests/ahci-test.c
> index 9c0adce..70bcafa 100644
> --- a/tests/ahci-test.c
> +++ b/tests/ahci-test.c
> @@ -78,25 +78,23 @@ static void string_bswap16(uint16_t *s, size_t bytes)
>  /**
>   * Verify that the transfer did not corrupt our state at all.
>   */
> -static void verify_state(AHCIQState *ahci)
> +static void verify_state(AHCIQState *ahci, uint64_t hba_old)
>  {
>      int i, j;
>      uint32_t ahci_fingerprint;
>      uint64_t hba_base;
> -    uint64_t hba_stored;
>      AHCICommandHeader cmd;
>  
>      ahci_fingerprint = qpci_config_readl(ahci->dev, PCI_VENDOR_ID);
>      g_assert_cmphex(ahci_fingerprint, ==, ahci->fingerprint);
>  
>      /* If we haven't initialized, this is as much as can be validated. */
> -    if (!ahci->hba_base) {
> +    if (!ahci->enabled) {
>          return;
>      }
>  
>      hba_base = (uint64_t)qpci_config_readl(ahci->dev, PCI_BASE_ADDRESS_5);
> -    hba_stored = (uint64_t)(uintptr_t)ahci->hba_base;
> -    g_assert_cmphex(hba_base, ==, hba_stored);
> +    g_assert_cmphex(hba_base, ==, hba_old);
>  
>      g_assert_cmphex(ahci_rreg(ahci, AHCI_CAP), ==, ahci->cap);
>      g_assert_cmphex(ahci_rreg(ahci, AHCI_CAP2), ==, ahci->cap2);
> @@ -119,12 +117,15 @@ static void ahci_migrate(AHCIQState *from, AHCIQState *to, const char *uri)
>      QOSState *tmp = to->parent;
>      QPCIDevice *dev = to->dev;
>      char *uri_local = NULL;
> +    uint64_t hba_old;
>  
>      if (uri == NULL) {
>          uri_local = g_strdup_printf("%s%s", "unix:", mig_socket);
>          uri = uri_local;
>      }
>  
> +    hba_old = (uint64_t)qpci_config_readl(from->dev, PCI_BASE_ADDRESS_5);
> +
>      /* context will be 'to' after completion. */
>      migrate(from->parent, to->parent, uri);
>  
> @@ -141,7 +142,7 @@ static void ahci_migrate(AHCIQState *from, AHCIQState *to, const char *uri)
>      from->parent = tmp;
>      from->dev = dev;
>  
> -    verify_state(to);
> +    verify_state(to, hba_old);
>      g_free(uri_local);
>  }
>  
> diff --git a/tests/libqos/ahci.c b/tests/libqos/ahci.c
> index 716ab79..8e789d8 100644
> --- a/tests/libqos/ahci.c
> +++ b/tests/libqos/ahci.c
> @@ -351,6 +351,7 @@ void ahci_hba_enable(AHCIQState *ahci)
>      reg = ahci_rreg(ahci, AHCI_GHC);
>      ASSERT_BIT_SET(reg, AHCI_GHC_IE);
>  
> +    ahci->enabled = true;
>      /* TODO: The device should now be idling and waiting for commands.
>       * In the future, a small test-case to inspect the Register D2H FIS
>       * and clear the initial interrupts might be good. */
> diff --git a/tests/libqos/ahci.h b/tests/libqos/ahci.h
> index c69fb5a..9b0c1d7 100644
> --- a/tests/libqos/ahci.h
> +++ b/tests/libqos/ahci.h
> @@ -327,6 +327,7 @@ typedef struct AHCIQState {
>      uint32_t cap;
>      uint32_t cap2;
>      AHCIPortQState port[32];
> +    bool enabled;
>  } AHCIQState;
>  
>  /**

  parent reply	other threads:[~2016-10-25  8:58 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-10-24  4:59 [Qemu-devel] [PATCHv5 00/12] Cleanups to qtest PCI handling David Gibson
2016-10-24  4:59 ` [Qemu-devel] [PATCHv5 01/12] libqos: Give qvirtio_config_read*() consistent semantics David Gibson
2016-10-24  4:59 ` [Qemu-devel] [PATCHv5 02/12] libqos: Handle PCI IO de-multiplexing in common code David Gibson
2016-10-24  4:59 ` [Qemu-devel] [PATCHv5 03/12] libqos: Move BAR assignment to " David Gibson
2016-10-24  4:59 ` [Qemu-devel] [PATCHv5 04/12] libqos: Better handling of PCI legacy IO David Gibson
2016-10-25 12:34   ` Greg Kurz
2016-10-24  4:59 ` [Qemu-devel] [PATCHv5 05/12] tests: Adjust tco-test to use qpci_legacy_iomap() David Gibson
2016-10-25 12:35   ` Greg Kurz
2016-10-24  4:59 ` [Qemu-devel] [PATCHv5 06/12] libqos: Add streaming accessors for PCI MMIO David Gibson
2016-10-24  4:59 ` [Qemu-devel] [PATCHv5 07/12] libqos: Implement mmio accessors in terms of mem{read, write} David Gibson
2016-10-25  6:47   ` Alexey Kardashevskiy
2016-10-25 12:16     ` David Gibson
2016-10-26  1:18       ` Alexey Kardashevskiy
2016-10-26  4:22         ` David Gibson
2016-10-24  4:59 ` [Qemu-devel] [PATCHv5 08/12] tests: Clean up IO handling in ide-test David Gibson
2016-10-25  7:01   ` Alexey Kardashevskiy
2016-10-25 12:25     ` David Gibson
2016-10-26  1:57       ` Alexey Kardashevskiy
2016-10-26  4:11         ` David Gibson
2016-10-25 12:36   ` Greg Kurz
2016-10-24  4:59 ` [Qemu-devel] [PATCHv5 09/12] libqos: Add 64-bit PCI IO accessors David Gibson
2016-10-24  4:59 ` [Qemu-devel] [PATCHv5 10/12] tests: Use qpci_mem{read, write} in ivshmem-test David Gibson
2016-10-25  9:23   ` Greg Kurz
2016-10-24  5:00 ` [Qemu-devel] [PATCHv5 11/12] tests: Don't assume structure of PCI IO base in ahci-test David Gibson
2016-10-24 16:50   ` John Snow
2016-10-25  8:58   ` Greg Kurz [this message]
2016-10-24  5:00 ` [Qemu-devel] [PATCHv5 12/12] libqos: Change PCI accessors to take opaque BAR handle David Gibson
2016-10-25  9:21   ` Greg Kurz
2016-10-25  3:35 ` [Qemu-devel] [PATCHv5 00/12] Cleanups to qtest PCI handling David Gibson
2016-10-25 13:14   ` Greg Kurz
2016-10-26  4:27     ` David Gibson

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=20161025105834.65485dc3@bahia \
    --to=groug@kaod.org \
    --cc=agraf@suse.de \
    --cc=aik@ozlabs.ru \
    --cc=david@gibson.dropbear.id.au \
    --cc=lvivier@redhat.com \
    --cc=mdroth@linux.vnet.ibm.com \
    --cc=mst@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-ppc@nongnu.org \
    --cc=stefanha@redhat.com \
    --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 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.