From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58978) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bAg2l-0005pN-Uo for qemu-devel@nongnu.org; Wed, 08 Jun 2016 12:09:25 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bAg2g-0007r6-PX for qemu-devel@nongnu.org; Wed, 08 Jun 2016 12:09:22 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:37597 helo=mx0a-001b2d01.pphosted.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bAg2g-0007r0-KE for qemu-devel@nongnu.org; Wed, 08 Jun 2016 12:09:18 -0400 Received: from pps.filterd (m0098419.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.11/8.16.0.11) with SMTP id u58G90Do054824 for ; Wed, 8 Jun 2016 12:09:18 -0400 Received: from e33.co.us.ibm.com (e33.co.us.ibm.com [32.97.110.151]) by mx0b-001b2d01.pphosted.com with ESMTP id 23e9m3w0k0-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Wed, 08 Jun 2016 12:09:18 -0400 Received: from localhost by e33.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 8 Jun 2016 10:09:17 -0600 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Michael Roth In-Reply-To: <20160608155002.GD8861@in.ibm.com> References: <1465276743-7340-1-git-send-email-bharata@linux.vnet.ibm.com> <20160607233728.713.97557@loki> <20160608023554.GA8861@in.ibm.com> <20160608150512.665.12735@loki> <20160608155002.GD8861@in.ibm.com> Date: Wed, 08 Jun 2016 11:09:11 -0500 Message-Id: <20160608160911.665.29938@loki> Subject: Re: [Qemu-devel] [PATCH v3] spapr: Ensure all LMBs are represented in ibm, dynamic-memory List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: bharata@linux.vnet.ibm.comBharata B Rao Cc: qemu-devel@nongnu.org, david@gibson.dropbear.id.au, nfont@linux.vnet.ibm.com, aik@ozlabs.ru, qemu-ppc@nongnu.org Quoting Bharata B Rao (2016-06-08 10:50:03) > On Wed, Jun 08, 2016 at 10:05:12AM -0500, Michael Roth wrote: > > Quoting Bharata B Rao (2016-06-07 21:35:54) > > > On Tue, Jun 07, 2016 at 06:37:28PM -0500, Michael Roth wrote: > > > > Quoting Bharata B Rao (2016-06-07 00:19:03) > > > > > Memory hotplug can fail for some combinations of RAM and maxmem w= hen > > > > > 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= currently > > > > > being calculated wrongly by the guest kernel routine memory_hotpl= ug_max(). > > > > > While there is an attempt to fix the guest kernel, this patch wor= ks > > > > > around the problem within QEMU itself. > > > > > = > > > > > memory_hotplug_max() routine in the guest kernel arrives at max > > > > > addressable memory by multiplying lmb-size with the lmb-count obt= ained > > > > > from ibm,dynamic-memory property. There are two assumptions here: > > > > > = > > > > > - All LMBs are part of ibm,dynamic memory: This is not true for P= owerKVM > > > > > where only hot-pluggable LMBs are present in this property. > > > > > - The memory area comprising of RAM and hotplug region is contigu= ous: This > > > > > needn't be true always for PowerKVM as there can be gap between > > > > > boot time RAM and hotplug region. > > > > > = > > > > > To work around this guest kernel bug, ensure that ibm,dynamic-mem= ory > > > > > 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). > > > > > = > > > > > RMA is represented separately by memory@0 node. Hence mark RMA LM= Bs > > > > > and also the LMBs for the gap b/n RAM and hotpluggable region as > > > > > reserved so that these LMBs are not recounted/counted by guest. > > > > > = > > > > > Signed-off-by: Bharata B Rao > > > > > --- > > > > > Changes in v3: > > > > > = > > > > > - Not touching spapr_create_lmb_dr_connectors() so that we contin= ue > > > > > to have DRC objects for only hotpluggable LMBs. > > > > > - Simplified the logic of creating dynamic-memory node based on c= omments > > > > > from Michael Roth and David Gibson. > > > > > = > > > > > v2: https://lists.gnu.org/archive/html/qemu-devel/2016-06/msg0131= 6.html > > > > > = > > > > > hw/ppc/spapr.c | 51 ++++++++++++++++++++++++++++++++----= -------------- > > > > > include/hw/ppc/spapr.h | 5 +++-- > > > > > 2 files changed, 36 insertions(+), 20 deletions(-) > > > > > = > > > > > diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c > > > > > index 0636642..9d1d43d 100644 > > > > > --- a/hw/ppc/spapr.c > > > > > +++ b/hw/ppc/spapr.c > > > > > @@ -762,14 +762,17 @@ static int spapr_populate_drconf_memory(sPA= PRMachineState *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_si= ze)/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; > > > > > = > > > > > /* > > > > > - * 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; > > > > > } > > > > > = > > > > > @@ -805,24 +808,36 @@ static int spapr_populate_drconf_memory(sPA= PRMachineState *spapr, void *fdt) > > > > > for (i =3D 0; i < nr_lmbs; i++) { > > > > > sPAPRDRConnector *drc; > > > > > sPAPRDRConnectorClass *drck; > > > > = > > > > Since these ^ are only used if (i >=3D hotplug_lmb_start), it might= be > > > > clearer to move them there now. > > > = > > > Yes. > > > = > > > > = > > > > > - uint64_t addr =3D i * lmb_size + spapr->hotplug_memory.b= ase;; > > > > > + uint64_t addr =3D i * lmb_size; > > > > > uint32_t *dynamic_memory =3D cur_index; > > > > > = > > > > > - 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, NU= LL)); > > > > > - if (addr < machine->ram_size || > > > > > - memory_region_present(get_system_memory(), a= ddr)) { > > > > > - dynamic_memory[5] =3D cpu_to_be32(SPAPR_LMB_FLAGS_AS= SIGNED); > > > > > + if (i >=3D hotplug_lmb_start) { > > > > > + drc =3D spapr_dr_connector_by_id(SPAPR_DR_CONNECTOR_= TYPE_LMB, > > > > > + addr / lmb_size); > > > > = > > > > Could just be i > > > = > > > Hmm I thought I got all such occurances covered :( > > > = > > > > = > > > > > + 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(dr= c)); > > > > > + 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_FLAG= S_ASSIGNED); > > > > > + } 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. > > > > > + */ > > > > > + dynamic_memory[0] =3D cpu_to_be32(0); > > > > > + dynamic_memory[1] =3D cpu_to_be32(0); > > > > = > > > > Are we sure we shouldn't still encode the addr here? > > > = > > > Since kernel won't look at reserved LMBs, I thought it should be fine. > > > We could populate the addr, but we don't have DRC for them and hence > > > no DRC index, so anyway we will not have full information. > > = > > The 'DRC invalid' bit seems to suggests it's a perfectly valid scenario > > to have LMBs with no backing drc, so I would think the other fields > > should still be filled out appropriately, even if it might not get > > used by guest either way. > = > addr can be populated, yes, but since there are no backing DRCs for > RMA and rest of the boot-time RAM, we can't be populating DRC index. > = > 'DRC Invalid' in Table 248 of LoPAPR reads: If b '0/1', the DRC field of > "ibm,dynamic-memory" property is valid/invalid. > = > In ibm,dyanmic-memory, anything sounding close to "DRC field" is DRC inde= x, > so it should be ok to have 0 for DRC index for such LMBs I suppose. Agreed, for the drc index case I think leaving it 0/unset is the only sensible approach, but if there's a flag to denote this situation we should probably make use of it. > = > > = > > I think an argument could be made for not setting addr for LMBs to used > > to cover the RAM->hotplug gap, since that's padding rather than real > > memory. But effectively re-using addr 0 seems like more of a liability > > than a safeguard. If 'reserved' flag is doing what we expect, then it's > > probably best not to deviate from normal values any more than necessary, > > IMO. > = > Fine. > = > > = > > > = > > > > = > > > > > + 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_RE= SERVED); > > > > = > > > > LoPAPR Table 248 defines a "DRC invalid" bit at 0x00000020, which I > > > > think is what we'll want for cases where there's no backing DRC. > > > = > > > Seems to work. I started with reserved based on Nathan's original > > > suggestion. > > > = > > > So Nathan, which would be more appropriate here from kernel point of = view ? > > > Reserved or 'DRC Invalid' ? > > = > > Wouldn't we want an OR of both? > = > To be fully sure that these LMBs would never be enumerated by the guest ? I think 'reserved' flag covers that aspect, I'm really only suggesting 'drc invalid' flag also be included in the unlikely case that some drmgr-like tool out there attempts to interpret the DRC index field as a real index otherwise. > = > Regards, > Bharata. >=20