From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BF337ECAAA1 for ; Thu, 27 Oct 2022 20:43:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236103AbiJ0UnT (ORCPT ); Thu, 27 Oct 2022 16:43:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58580 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234377AbiJ0UnS (ORCPT ); Thu, 27 Oct 2022 16:43:18 -0400 Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1BE556581D for ; Thu, 27 Oct 2022 13:43:17 -0700 (PDT) Received: from pps.filterd (m0098410.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 29RKg0YG013915; Thu, 27 Oct 2022 20:43:04 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=message-id : subject : from : to : cc : date : in-reply-to : references : content-type : mime-version : content-transfer-encoding; s=pp1; bh=CBERSXABllz3dTGWZ84YxKOdh+5lW7czF/kzoC5n184=; b=gFrniCogH150ZuDLMS1Jw3p53XoQc+vjueCSOSolt1GeKGGJ2F0CA5/0rpn3XFB3eS+V FBFOgdGFIpe2iun/uLCYfK8vg2BgddnvcxzwgKL4tHG60UFqtYyZXKwgtUDcRCArtfzO xv7ggdJxPSt01dLCGsPRDXkhekW9j3h7NGKo+9CQ/AyiOuH913vaxfYit9esRF7/TppN igatn4/9SsmN8MYSc4TJT2OD9x1RWyUHcetAUzpazt50FMLEh9Aaw6FZY7u5GgItSQbk Yrqo2tdtDee4NTB3g0gQC83kb1wDP+w5M6qHdPzMInWr76mhWCGOld3FjJ2jTiXNeFvE IA== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3kg18g80h5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 27 Oct 2022 20:43:03 +0000 Received: from m0098410.ppops.net (m0098410.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 29RKh3me016934; Thu, 27 Oct 2022 20:43:03 GMT Received: from ppma06fra.de.ibm.com (48.49.7a9f.ip4.static.sl-reverse.com [159.122.73.72]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3kg18g80g9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 27 Oct 2022 20:43:02 +0000 Received: from pps.filterd (ppma06fra.de.ibm.com [127.0.0.1]) by ppma06fra.de.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 29RKa6JG023499; Thu, 27 Oct 2022 20:43:00 GMT Received: from b06cxnps3075.portsmouth.uk.ibm.com (d06relay10.portsmouth.uk.ibm.com [9.149.109.195]) by ppma06fra.de.ibm.com with ESMTP id 3kfbg29qtj-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 27 Oct 2022 20:43:00 +0000 Received: from d06av22.portsmouth.uk.ibm.com (d06av22.portsmouth.uk.ibm.com [9.149.105.58]) by b06cxnps3075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 29RKgvmv39584070 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 27 Oct 2022 20:42:57 GMT Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 3E9CD4C044; Thu, 27 Oct 2022 20:42:57 +0000 (GMT) Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 5CE914C040; Thu, 27 Oct 2022 20:42:56 +0000 (GMT) Received: from li-7e0de7cc-2d9d-11b2-a85c-de26c016e5ad.ibm.com (unknown [9.171.94.180]) by d06av22.portsmouth.uk.ibm.com (Postfix) with ESMTP; Thu, 27 Oct 2022 20:42:56 +0000 (GMT) Message-ID: <4c5afcb5754cb829cd8b9ddbf4f74e610d5f6012.camel@linux.ibm.com> Subject: Re: [PATCH v10 2/9] s390x/cpu topology: reporting the CPU topology to the guest From: Janis Schoetterl-Glausch To: Pierre Morel , qemu-s390x@nongnu.org Cc: qemu-devel@nongnu.org, borntraeger@de.ibm.com, pasic@linux.ibm.com, richard.henderson@linaro.org, david@redhat.com, thuth@redhat.com, cohuck@redhat.com, mst@redhat.com, pbonzini@redhat.com, kvm@vger.kernel.org, ehabkost@redhat.com, marcel.apfelbaum@gmail.com, eblake@redhat.com, armbru@redhat.com, seiden@linux.ibm.com, nrb@linux.ibm.com, frankja@linux.ibm.com, berrange@redhat.com, clg@kaod.org Date: Thu, 27 Oct 2022 22:42:56 +0200 In-Reply-To: <20221012162107.91734-3-pmorel@linux.ibm.com> References: <20221012162107.91734-1-pmorel@linux.ibm.com> <20221012162107.91734-3-pmorel@linux.ibm.com> Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.42.4 (3.42.4-2.fc35) MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: 2mEg6wgO-9ZnB2DOuxRIkGIsoZPZwJqS X-Proofpoint-GUID: ljsmVt65CWNw3WFNwknNhLNA6YOrmaVB X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.895,Hydra:6.0.545,FMLib:17.11.122.1 definitions=2022-10-27_07,2022-10-27_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 priorityscore=1501 bulkscore=0 impostorscore=0 mlxscore=0 spamscore=0 adultscore=0 suspectscore=0 phishscore=0 mlxlogscore=999 malwarescore=0 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2210170000 definitions=main-2210270115 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org On Wed, 2022-10-12 at 18:21 +0200, Pierre Morel wrote: > The guest can use the STSI instruction to get a buffer filled > with the CPU topology description. > > Let us implement the STSI instruction for the basis CPU topology > level, level 2. > > Signed-off-by: Pierre Morel > --- > include/hw/s390x/cpu-topology.h | 3 + > target/s390x/cpu.h | 48 ++++++++++++++ > hw/s390x/cpu-topology.c | 8 ++- > target/s390x/cpu_topology.c | 109 ++++++++++++++++++++++++++++++++ > target/s390x/kvm/kvm.c | 6 +- > target/s390x/meson.build | 1 + > 6 files changed, 172 insertions(+), 3 deletions(-) > create mode 100644 target/s390x/cpu_topology.c > > diff --git a/include/hw/s390x/cpu-topology.h b/include/hw/s390x/cpu-topology.h > index 66c171d0bc..61c11db017 100644 > --- a/include/hw/s390x/cpu-topology.h > +++ b/include/hw/s390x/cpu-topology.h > @@ -13,6 +13,8 @@ > #include "hw/qdev-core.h" > #include "qom/object.h" > > +#define S390_TOPOLOGY_POLARITY_H 0x00 > + > typedef struct S390TopoContainer { > int active_count; > } S390TopoContainer; > @@ -29,6 +31,7 @@ struct S390Topology { > S390TopoContainer *socket; > S390TopoTLE *tle; > MachineState *ms; > + QemuMutex topo_mutex; > }; > > #define TYPE_S390_CPU_TOPOLOGY "s390-topology" > diff --git a/target/s390x/cpu.h b/target/s390x/cpu.h > index 7d6d01325b..d604aa9c78 100644 > --- a/target/s390x/cpu.h > +++ b/target/s390x/cpu.h > [...] > + > +/* Maxi size of a SYSIB structure is when all CPU are alone in a container */ Max or Maximum. > +#define S390_TOPOLOGY_SYSIB_SIZE (sizeof(SysIB_151x) + \ > + S390_MAX_CPUS * (sizeof(SysIBTl_container) + \ > + sizeof(SysIBTl_cpu))) Currently this is 16+248*3*8 == 5968 and will grow with books, drawer support to 16+248*5*8 == 9936 ... [...] > > + > +void insert_stsi_15_1_x(S390CPU *cpu, int sel2, __u64 addr, uint8_t ar) > +{ > + uint64_t page[S390_TOPOLOGY_SYSIB_SIZE / sizeof(uint64_t)] = {}; ... so calling this page is a bit misleading. Also why not make it a char[]? And maybe use a union for type punning. > + SysIB_151x *sysib = (SysIB_151x *) page; > + int len; > + > + if (s390_is_pv() || !s390_has_topology() || > + sel2 < 2 || sel2 > S390_TOPOLOGY_MAX_MNEST) { > + setcc(cpu, 3); > + return; > + } > + > + len = setup_stsi(sysib, sel2); This should now be memory safe, but might be larger than 4k, the maximum size of the SYSIB. I guess you want to set cc code 3 in this case and return. > + > + sysib->length = cpu_to_be16(len); > + s390_cpu_virt_mem_write(cpu, addr, ar, sysib, len); > + setcc(cpu, 0); > +} > + > [...]