All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Michael S. Tsirkin" <mst@redhat.com>
To: Isaku Yamahata <yamahata@valinux.co.jp>
Cc: qemu-devel@nongnu.org
Subject: [Qemu-devel] Re: [PATCH 38/61] pci: fix pci_default_write_config()
Date: Wed, 30 Sep 2009 12:44:46 +0200	[thread overview]
Message-ID: <20090930104445.GA18802@redhat.com> (raw)
In-Reply-To: <1254305917-14784-39-git-send-email-yamahata@valinux.co.jp>

On Wed, Sep 30, 2009 at 07:18:14PM +0900, Isaku Yamahata wrote:
> When updated ROM expantion address of header type 0,
> it missed to update mappings.

Can the bugfix be separated from proposed optimization please?
It should be a one-liner.

> By using helper functions this patch also avoids memcpy() and memcmp().

I expect this is all slow-path done during boot, so an extra memcpy
operation can not hurt.

I actually think keeping the original copy around is a good thing,
we probably should put it in PCI structure, so that devices can easily
check whether some value was changed.

For example, in your patch pci_update_mappings is called even if none of
the values are changed, or if memory is disabled, and
you also don't seem to update mappings when memory is enabled/disabled.

> Cc: Michael S. Tsirkin <mst@redhat.com>
> Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp>
> ---
>  hw/pci.c |   11 +++++------
>  hw/pci.h |    9 ++++++++-
>  2 files changed, 13 insertions(+), 7 deletions(-)
> 
> diff --git a/hw/pci.c b/hw/pci.c
> index 757fe7b..2a59667 100644
> --- a/hw/pci.c
> +++ b/hw/pci.c
> @@ -627,20 +627,19 @@ uint32_t pci_default_read_config(PCIDevice *d,
>  
>  void pci_default_write_config(PCIDevice *d, uint32_t addr, uint32_t val, int l)
>  {
> -    uint8_t orig[PCI_CONFIG_SPACE_SIZE];
>      int i;
>      uint32_t config_size = pcie_config_size(d);
>  
> -    /* not efficient, but simple */
> -    memcpy(orig, d->config, PCI_CONFIG_SPACE_SIZE);
>      for(i = 0; i < l && addr < config_size; val >>= 8, ++i, ++addr) {
>          uint8_t wmask = d->wmask[addr];
>          d->config[addr] = (d->config[addr] & ~wmask) | (val & wmask);
>      }
> -    if (memcmp(orig + PCI_BASE_ADDRESS_0, d->config + PCI_BASE_ADDRESS_0, 24)
> -        || ((orig[PCI_COMMAND] ^ d->config[PCI_COMMAND])
> -            & (PCI_COMMAND_MEMORY | PCI_COMMAND_IO)))
> +
> +    if (pci_config_changed(addr, l,
> +                           PCI_BASE_ADDRESS_0, PCI_BASE_ADDRESS_5 + 4) ||

How can pci_config_changed know whether some value was
actually changed without looking at original and new value?
IMO it's better to keep the original array around,
and use simple memcmp.

> +        pci_config_changed_with_size(addr, l, PCI_ROM_ADDRESS, 4)) {
>          pci_update_mappings(d);
> +    }
>  }
>  
>  static PCIBus *pci_find_bus_from(PCIBus *from, int bus_num)
> diff --git a/hw/pci.h b/hw/pci.h
> index 26c15c5..3327905 100644
> --- a/hw/pci.h
> +++ b/hw/pci.h
> @@ -121,7 +121,12 @@ static inline int pci_bar_is_64bit(const PCIIORegion *r)
>  #define  PCI_HEADER_TYPE_BRIDGE		1
>  #define  PCI_HEADER_TYPE_CARDBUS	2
>  #define  PCI_HEADER_TYPE_MULTI_FUNCTION 0x80
> -#define PCI_BASE_ADDRESS_0	0x10	/* 32 bits */
> +#define PCI_BASE_ADDRESS_0      0x10    /* 32 bits */
> +#define PCI_BASE_ADDRESS_1      0x14    /* 32 bits [htype 0,1 only] */
> +#define PCI_BASE_ADDRESS_2      0x18    /* 32 bits [htype 0 only] */
> +#define PCI_BASE_ADDRESS_3      0x1c    /* 32 bits */
> +#define PCI_BASE_ADDRESS_4      0x20    /* 32 bits */
> +#define PCI_BASE_ADDRESS_5      0x24    /* 32 bits */
>  #define PCI_PRIMARY_BUS		0x18	/* Primary bus number */
>  #define PCI_SECONDARY_BUS	0x19	/* Secondary bus number */
>  #define PCI_SEC_STATUS		0x1e	/* Secondary status register, only bit 14 used */
> @@ -141,7 +146,9 @@ static inline int pci_bar_is_64bit(const PCIIORegion *r)
>  #define PCI_SUBVENDOR_ID        0x2c    /* obsolete, use PCI_SUBSYSTEM_VENDOR_ID */
>  #define PCI_SUBDEVICE_ID        0x2e    /* obsolete, use PCI_SUBSYSTEM_ID */
>  
> +#define PCI_ROM_ADDRESS         0x30    /* Bits 31..11 are address, 10..1 reserved */
>  #define  PCI_ROM_ADDRESS_ENABLE 0x01
> +#define PCI_ROM_ADDRESS_MASK    (~0x7ffUL)
>  
>  /* Bits in the PCI Status Register (PCI 2.3 spec) */
>  #define PCI_STATUS_RESERVED1	0x007
> -- 
> 1.6.0.2

  reply	other threads:[~2009-09-30 10:47 UTC|newest]

Thread overview: 84+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-09-30 10:17 [Qemu-devel] [PATCH 00/61] Q35 chip set and stuff Isaku Yamahata
2009-09-30 10:17 ` [Qemu-devel] [PATCH 01/61] acpi: split out pc smbus routines from acpi.c into pc_smbus.c Isaku Yamahata
2009-09-30 10:17 ` [Qemu-devel] [PATCH 02/61] acpi: split out apm register emulation from acpi.c Isaku Yamahata
2009-09-30 10:17 ` [Qemu-devel] [PATCH 03/61] acpi: add acpi constants from linux header files and use them Isaku Yamahata
2009-09-30 10:17 ` [Qemu-devel] [PATCH 04/61] acpi: split acpi.c into the common part and the piix4 part Isaku Yamahata
2009-09-30 10:17 ` [Qemu-devel] [PATCH 05/61] acpi_piix4: remove unused variable in get_pmsts() Isaku Yamahata
2009-09-30 10:17 ` [Qemu-devel] [PATCH 06/61] pc: fix file stream leak in multiboot loader Isaku Yamahata
2009-09-30 10:17 ` [Qemu-devel] [PATCH 07/61] pc, i440fx: Make smm enable/disable function i440fx independent Isaku Yamahata
2009-09-30 10:17 ` [Qemu-devel] [PATCH 08/61] pc: make an unnecessary global variable, pit, local Isaku Yamahata
2009-09-30 10:17 ` [Qemu-devel] [PATCH 09/61] pc: remove a global variable, floppy_controller Isaku Yamahata
2009-09-30 10:17 ` [Qemu-devel] [PATCH 10/61] pc: remove a global variable, RTCState *rtc_state Isaku Yamahata
2009-09-30 10:17 ` [Qemu-devel] [PATCH 11/61] pc: introduce a function to allocate cpu irq Isaku Yamahata
2009-09-30 10:17 ` [Qemu-devel] [PATCH 12/61] pc: make pc_init1() not refer ferr_irq directly Isaku Yamahata
2009-09-30 10:17 ` [Qemu-devel] [PATCH 13/61] pc: split out cpu initialization from pc_init1() into pc_cpus_init() Isaku Yamahata
2009-09-30 10:17 ` [Qemu-devel] [PATCH 14/61] pc: split out memory allocation from pc_init1() into pc_memory_init() Isaku Yamahata
2009-09-30 10:17 ` [Qemu-devel] [PATCH 15/61] pc: split out vga initialization from pc_init1() into pc_vga_init() Isaku Yamahata
2009-09-30 10:17 ` [Qemu-devel] [PATCH 16/61] pc: split out basic device init from pc_init1() into pc_basic_device_init() Isaku Yamahata
2009-09-30 10:17 ` [Qemu-devel] [PATCH 17/61] pc: split out pci device init from pc_init1() into pc_pci_device_init() Isaku Yamahata
2009-09-30 10:17 ` [Qemu-devel] [PATCH 18/61] pc: split out piix specific part from pc.c into pc_piix.c Isaku Yamahata
2009-09-30 10:17 ` [Qemu-devel] [PATCH 19/61] pc_piix: initialize ioapic before use Isaku Yamahata
2009-09-30 10:17 ` [Qemu-devel] [PATCH 20/61] pci: fix PCI_DPRINTF() wrt variadic macro Isaku Yamahata
2009-09-30 10:17 ` [Qemu-devel] [PATCH 21/61] pci: introduce constant PCI_NUM_PINS for the number of interrupt pins, 4 Isaku Yamahata
2009-09-30 10:17 ` [Qemu-devel] [PATCH 22/61] pci: use appropriate PRIs in PCI_DPRINTF() Isaku Yamahata
2009-09-30 11:55   ` [Qemu-devel] " Michael S. Tsirkin
2009-10-01  7:22     ` Isaku Yamahata
2009-10-01  8:57       ` Michael S. Tsirkin
2009-09-30 10:17 ` [Qemu-devel] [PATCH 23/61] pci: use PCI_SLOT() and PCI_FUNC() Isaku Yamahata
2009-09-30 10:18 ` [Qemu-devel] [PATCH 24/61] pci: define a constant to represent a unmapped bar and use it Isaku Yamahata
2009-09-30 10:18 ` [Qemu-devel] [PATCH 25/61] pci: use uint64_t for bar addr and size instead of uint32_t Isaku Yamahata
2009-09-30 14:55   ` malc
2009-10-01  5:34     ` Isaku Yamahata
2009-09-30 10:18 ` [Qemu-devel] [PATCH 26/61] pci: 64bit bar support Isaku Yamahata
2009-09-30 10:18 ` [Qemu-devel] [PATCH 27/61] pci: clean up of pci_update_mappings() Isaku Yamahata
2009-09-30 10:18 ` [Qemu-devel] [PATCH 28/61] pci: factor out while(bus) bus->next loop logic into pci_find_bus_from() Isaku Yamahata
2009-09-30 10:18 ` [Qemu-devel] [PATCH 29/61] pci: factor out the logic to get pci device from address Isaku Yamahata
2009-09-30 10:18 ` [Qemu-devel] [PATCH 30/61] pci_host.h: split non-inline static function in pci_host.h into pci_host_c.h Isaku Yamahata
2009-09-30 10:18 ` [Qemu-devel] [PATCH 31/61] pci: pcie host and mmcfg support Isaku Yamahata
2009-09-30 10:18 ` [Qemu-devel] [PATCH 32/61] pci: helper functions to access PCIDevice::config Isaku Yamahata
2009-09-30 10:47   ` [Qemu-devel] " Michael S. Tsirkin
2009-09-30 10:18 ` [Qemu-devel] [PATCH 33/61] pci: use the symbolic constant, PCI_ROM_ADDRESS_ENABLE instead of 1 Isaku Yamahata
2009-09-30 10:18 ` [Qemu-devel] [PATCH 34/61] pci: introduce pci_swizzle_map_irq_fn() for interrupt pin swizzle Isaku Yamahata
2009-09-30 10:18 ` [Qemu-devel] [PATCH 35/61] piix_pci: use pci_swizzle_map_irq_fn() Isaku Yamahata
2009-09-30 10:18 ` [Qemu-devel] [PATCH 36/61] pci: use QLIST_ macro instead of direct list manipulation Isaku Yamahata
2009-09-30 11:54   ` [Qemu-devel] " Michael S. Tsirkin
2009-09-30 10:18 ` [Qemu-devel] [PATCH 37/61] pci: add helper function for pci config write function to check address Isaku Yamahata
2009-09-30 11:50   ` [Qemu-devel] " Michael S. Tsirkin
2009-09-30 10:18 ` [Qemu-devel] [PATCH 38/61] pci: fix pci_default_write_config() Isaku Yamahata
2009-09-30 10:44   ` Michael S. Tsirkin [this message]
2009-09-30 11:09     ` [Qemu-devel] " Isaku Yamahata
2009-09-30 12:50       ` Michael S. Tsirkin
2009-09-30 10:18 ` [Qemu-devel] [PATCH 39/61] pci: factor out config update logic Isaku Yamahata
2009-09-30 10:18 ` [Qemu-devel] [PATCH 40/61] pci: use qdev to get parent bus with PCIBus Isaku Yamahata
2009-09-30 10:18 ` [Qemu-devel] [PATCH 41/61] pci: make bar update function aware of pci bridge Isaku Yamahata
2009-09-30 10:18 ` [Qemu-devel] [PATCH 42/61] pci/brdige: qdevfy and initialize secondary bus and subordinate bus Isaku Yamahata
2009-09-30 10:18 ` [Qemu-devel] [PATCH 43/61] pci: add helper function to initialize wmask Isaku Yamahata
2009-09-30 10:18 ` [Qemu-devel] [PATCH 44/61] pci: initialize wmask according to pci header type Isaku Yamahata
2009-09-30 10:18 ` [Qemu-devel] [PATCH 45/61] pci/monitor: print out bridge's filtering values and so on Isaku Yamahata
2009-09-30 10:18 ` [Qemu-devel] [PATCH 46/61] pci/bridge: implement intel 82801ba bridge Isaku Yamahata
2009-09-30 10:18 ` [Qemu-devel] [PATCH 47/61] pci.h: add more status constats Isaku Yamahata
2009-09-30 10:18 ` [Qemu-devel] [PATCH 48/61] pci id: add subclass codes for serial device Isaku Yamahata
2009-09-30 10:18 ` [Qemu-devel] [PATCH 49/61] pci hot add: pass opaque argument to callback Isaku Yamahata
2009-09-30 10:18 ` [Qemu-devel] [PATCH 50/61] pci hotadd, acpi_piix4: remove global variables Isaku Yamahata
2009-09-30 10:18 ` [Qemu-devel] [PATCH 51/61] vmstate: add a macro for pointer to struct, VMSTATE_STRUCT_POINTER Isaku Yamahata
2009-09-30 10:18 ` [Qemu-devel] [PATCH 52/61] pci: add a hook to replace default pci bus instead of 0 bus Isaku Yamahata
2009-09-30 10:18 ` [Qemu-devel] [PATCH 53/61] pc q35 based chipset emulator Isaku Yamahata
2009-10-05 10:30   ` [Qemu-devel] " Michael S. Tsirkin
2009-09-30 10:18 ` [Qemu-devel] [PATCH 54/61] pci: add opaque argument to pci_map_irq_fn() Isaku Yamahata
2009-09-30 10:18 ` [Qemu-devel] [PATCH 55/61] ioapic: make ioapic_set_irq() static Isaku Yamahata
2009-09-30 10:18 ` [Qemu-devel] [PATCH 56/61] ioapic: clean up of #ifdef DEBUG_IOAPIC Isaku Yamahata
2009-09-30 10:18 ` [Qemu-devel] [PATCH 57/61] ioapic: add callback when entry is set or ioapic is reset Isaku Yamahata
2009-10-01 13:37   ` Gleb Natapov
2009-10-01 16:04     ` Avi Kivity
2009-09-30 10:18 ` [Qemu-devel] [PATCH 58/61] ioapic: make the number of pins configurable Isaku Yamahata
2009-09-30 10:18 ` [Qemu-devel] [PATCH 59/61] ioapic: make irr accept more than 32 pins Isaku Yamahata
2009-10-01  8:52   ` Avi Kivity
2009-09-30 10:18 ` [Qemu-devel] [PATCH 60/61] pci: add opaque arg to pci_map_irq_fn Isaku Yamahata
2009-09-30 10:18 ` [Qemu-devel] [PATCH 61/61] pc_q35: apic mode for pci interrupt routing Isaku Yamahata
2009-10-01  8:50   ` Avi Kivity
2009-10-01 16:33     ` Avi Kivity
2009-09-30 12:00 ` [Qemu-devel] Re: [PATCH 00/61] Q35 chip set and stuff Michael S. Tsirkin
2009-09-30 12:08 ` [Qemu-devel] " Aurelien Jarno
2009-10-01  5:40   ` Isaku Yamahata
2009-09-30 18:37 ` Blue Swirl
2009-09-30 20:53 ` [Qemu-devel] " Anthony Liguori

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=20090930104445.GA18802@redhat.com \
    --to=mst@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=yamahata@valinux.co.jp \
    /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.