From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43472) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bCeuE-0007ZA-Sg for qemu-devel@nongnu.org; Mon, 13 Jun 2016 23:20:48 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bCeuB-0002EM-I0 for qemu-devel@nongnu.org; Mon, 13 Jun 2016 23:20:46 -0400 Date: Tue, 14 Jun 2016 13:20:35 +1000 From: David Gibson Message-ID: <20160614032035.GK4882@voom.fritz.box> References: <1465535688-29001-1-git-send-email-bharata@linux.vnet.ibm.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="BFVE2HhgxTpCzM8t" Content-Disposition: inline In-Reply-To: <1465535688-29001-1-git-send-email-bharata@linux.vnet.ibm.com> Subject: Re: [Qemu-devel] [PATCH v4] spapr: Ensure all LMBs are represented in ibm, dynamic-memory List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Bharata B Rao Cc: qemu-devel@nongnu.org, mdroth@linux.vnet.ibm.com, nfont@linux.vnet.ibm.com, aik@ozlabs.ru, qemu-ppc@nongnu.org --BFVE2HhgxTpCzM8t Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Fri, Jun 10, 2016 at 10:44:48AM +0530, Bharata B Rao wrote: > Memory hotplug can fail for some combinations of RAM and maxmem when > DDW is enabled in the presence of devices like nec-usb-xhci. DDW depends > on maximum addressable memory returned by guest and this value is current= ly > being calculated wrongly by the guest kernel routine memory_hotplug_max(). > While there is an attempt to fix the guest kernel, this patch works > around the problem within QEMU itself. >=20 > memory_hotplug_max() routine in the guest kernel arrives at max > addressable memory by multiplying lmb-size with the lmb-count obtained > from ibm,dynamic-memory property. There are two assumptions here: >=20 > - All LMBs are part of ibm,dynamic memory: This is not true for PowerKVM > where only hot-pluggable LMBs are present in this property. > - The memory area comprising of RAM and hotplug region is contiguous: This > needn't be true always for PowerKVM as there can be gap between > boot time RAM and hotplug region. >=20 > To work around this guest kernel bug, ensure that ibm,dynamic-memory > has information about all the LMBs (RMA, boot-time LMBs, future > hotpluggable LMBs, and dummy LMBs to cover the gap between RAM and > hotpluggable region). >=20 > RMA is represented separately by memory@0 node. Hence mark RMA LMBs > and also the LMBs for the gap b/n RAM and hotpluggable region as > reserved and as having no valid DRC so that these LMBs are not considered > by the guest. >=20 > Signed-off-by: Bharata B Rao Applied to ppc-for-2.7, thanks. > --- > Changes in v4: >=20 > - Included address information for all LMBs in ibm,dynamic-memory. > - Use both RESERVED and DRC_INVALID flag bits for non-hotpluggable LMBs. >=20 > v3: https://lists.gnu.org/archive/html/qemu-ppc/2016-06/msg00187.html >=20 > hw/ppc/spapr.c | 57 ++++++++++++++++++++++++++++++++------------= ------ > include/hw/ppc/spapr.h | 6 ++++-- > 2 files changed, 41 insertions(+), 22 deletions(-) >=20 > diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c > index 0636642..9a4a803 100644 > --- a/hw/ppc/spapr.c > +++ b/hw/ppc/spapr.c > @@ -762,14 +762,17 @@ static int spapr_populate_drconf_memory(sPAPRMachin= eState *spapr, void *fdt) > int ret, i, offset; > uint64_t lmb_size =3D SPAPR_MEMORY_BLOCK_SIZE; > uint32_t prop_lmb_size[] =3D {0, cpu_to_be32(lmb_size)}; > - uint32_t nr_lmbs =3D (machine->maxram_size - machine->ram_size)/lmb_= size; > + uint32_t hotplug_lmb_start =3D spapr->hotplug_memory.base / lmb_size; > + uint32_t nr_lmbs =3D (spapr->hotplug_memory.base + > + memory_region_size(&spapr->hotplug_memory.mr)) / > + lmb_size; > uint32_t *int_buf, *cur_index, buf_len; > int nr_nodes =3D nb_numa_nodes ? nb_numa_nodes : 1; > =20 > /* > - * Don't create the node if there are no DR LMBs. > + * Don't create the node if there is no hotpluggable memory > */ > - if (!nr_lmbs) { > + if (machine->ram_size =3D=3D machine->maxram_size) { > return 0; > } > =20 > @@ -803,26 +806,40 @@ static int spapr_populate_drconf_memory(sPAPRMachin= eState *spapr, void *fdt) > int_buf[0] =3D cpu_to_be32(nr_lmbs); > cur_index++; > for (i =3D 0; i < nr_lmbs; i++) { > - sPAPRDRConnector *drc; > - sPAPRDRConnectorClass *drck; > - uint64_t addr =3D i * lmb_size + spapr->hotplug_memory.base;; > + uint64_t addr =3D i * lmb_size; > uint32_t *dynamic_memory =3D cur_index; > =20 > - drc =3D spapr_dr_connector_by_id(SPAPR_DR_CONNECTOR_TYPE_LMB, > - addr/lmb_size); > - g_assert(drc); > - drck =3D SPAPR_DR_CONNECTOR_GET_CLASS(drc); > - > - dynamic_memory[0] =3D cpu_to_be32(addr >> 32); > - dynamic_memory[1] =3D cpu_to_be32(addr & 0xffffffff); > - dynamic_memory[2] =3D cpu_to_be32(drck->get_index(drc)); > - dynamic_memory[3] =3D cpu_to_be32(0); /* reserved */ > - dynamic_memory[4] =3D cpu_to_be32(numa_get_node(addr, NULL)); > - if (addr < machine->ram_size || > - memory_region_present(get_system_memory(), addr)) { > - dynamic_memory[5] =3D cpu_to_be32(SPAPR_LMB_FLAGS_ASSIGNED); > + if (i >=3D hotplug_lmb_start) { > + sPAPRDRConnector *drc; > + sPAPRDRConnectorClass *drck; > + > + drc =3D spapr_dr_connector_by_id(SPAPR_DR_CONNECTOR_TYPE_LMB= , i); > + g_assert(drc); > + drck =3D SPAPR_DR_CONNECTOR_GET_CLASS(drc); > + > + dynamic_memory[0] =3D cpu_to_be32(addr >> 32); > + dynamic_memory[1] =3D cpu_to_be32(addr & 0xffffffff); > + dynamic_memory[2] =3D cpu_to_be32(drck->get_index(drc)); > + dynamic_memory[3] =3D cpu_to_be32(0); /* reserved */ > + dynamic_memory[4] =3D cpu_to_be32(numa_get_node(addr, NULL)); > + if (memory_region_present(get_system_memory(), addr)) { > + dynamic_memory[5] =3D cpu_to_be32(SPAPR_LMB_FLAGS_ASSIGN= ED); > + } else { > + dynamic_memory[5] =3D cpu_to_be32(0); > + } > } else { > - dynamic_memory[5] =3D cpu_to_be32(0); > + /* > + * LMB information for RMA, boot time RAM and gap b/n RAM and > + * hotplug memory region -- all these are marked as reserved > + * and as having no valid DRC. > + */ > + dynamic_memory[0] =3D cpu_to_be32(addr >> 32); > + dynamic_memory[1] =3D cpu_to_be32(addr & 0xffffffff); > + dynamic_memory[2] =3D cpu_to_be32(0); > + dynamic_memory[3] =3D cpu_to_be32(0); /* reserved */ > + dynamic_memory[4] =3D cpu_to_be32(-1); > + dynamic_memory[5] =3D cpu_to_be32(SPAPR_LMB_FLAGS_RESERVED | > + SPAPR_LMB_FLAGS_DRC_INVALID); > } > =20 > cur_index +=3D SPAPR_DR_LMB_LIST_ENTRY_SIZE; > diff --git a/include/hw/ppc/spapr.h b/include/hw/ppc/spapr.h > index 971df3d..3ac85c0 100644 > --- a/include/hw/ppc/spapr.h > +++ b/include/hw/ppc/spapr.h > @@ -620,9 +620,11 @@ int spapr_rng_populate_dt(void *fdt); > #define SPAPR_DR_LMB_LIST_ENTRY_SIZE 6 > =20 > /* > - * This flag value defines the LMB as assigned in ibm,dynamic-memory > - * property under ibm,dynamic-reconfiguration-memory node. > + * Defines for flag value in ibm,dynamic-memory property under > + * ibm,dynamic-reconfiguration-memory node. > */ > #define SPAPR_LMB_FLAGS_ASSIGNED 0x00000008 > +#define SPAPR_LMB_FLAGS_DRC_INVALID 0x00000020 > +#define SPAPR_LMB_FLAGS_RESERVED 0x00000080 > =20 > #endif /* !defined (__HW_SPAPR_H__) */ --=20 David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson --BFVE2HhgxTpCzM8t Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQIcBAEBAgAGBQJXX3gDAAoJEGw4ysog2bOSA2oQANo4qi5K46E42CWbHgz116wp c1OxbpJ896QghO2QiXNs8+qey7fMyZSRKPcU/DAXgGkhaGMo06MhfzVQcKRjZrL4 0X7eeSlhqmJVKkXsZ07gKWxDPGKl77zen41W+Gja2waCxdlx5Bew9YDjOi8oVp7p dQTvhfJX2ElRtHUZmdqrziwDv41M4YwLhp9Q8iXjCYUt5vh2QWsmr5zWFXaJeBgd klfDMKS635LUd4GyahHxV/l62LoFNJ/EhtTKI/eN2f9nSASrQatC0gcyG6ydUGKz xrRvUOBL0Zm7yiMKBOaLs38YS3BZDrSg+NCuWY2E5R+sC/xRM/6ebaQqXX1T19mQ PyNsYLh9xF7VhYwDyI1WXKQv5zTWgn9HCpl3SH4daJKyMOHnTZw6jNC3gvFeFLyE G9wCBplyF6M2qoOpmJLVTn8DVTCHfmH+cS24A250qMuvsA8VsF3K7Bf2Px9YDGP0 xjYbX/UXnsGDNsJn/Oc+UOsUjU4grT98E14ERzeq3mqNZgiQrd0H1SabLo8QcHs0 cAyVLaFFjZhf1SBHimfNkndHEoaRAq4NtYUkHd7Hc/uX5USSkINxQViTwz3mcKzH urhYYISaFlmoxXh5u7pSnGt4irNNuoBNrKqTAPDD/Z6BradUDlOfcZ6o4Q4Uwr3x KLQySGvP2YN0GpsxC2Qk =CySL -----END PGP SIGNATURE----- --BFVE2HhgxTpCzM8t--