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 X-Spam-Level: X-Spam-Status: No, score=-20.2 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,MENTIONS_GIT_HOSTING,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_SANE_2 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C77D5C433B4 for ; Thu, 1 Apr 2021 05:53:06 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id D7B7861001 for ; Thu, 1 Apr 2021 05:53:05 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D7B7861001 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=kaod.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:50356 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lRqGO-0004pw-OK for qemu-devel@archiver.kernel.org; Thu, 01 Apr 2021 01:53:04 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35920) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lRqFU-0004IO-97 for qemu-devel@nongnu.org; Thu, 01 Apr 2021 01:52:08 -0400 Received: from 1.mo51.mail-out.ovh.net ([178.32.121.110]:55779) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lRqFN-0003wF-PW for qemu-devel@nongnu.org; Thu, 01 Apr 2021 01:52:08 -0400 Received: from mxplan5.mail.ovh.net (unknown [10.109.156.35]) by mo51.mail-out.ovh.net (Postfix) with ESMTPS id DF2D327A912; Thu, 1 Apr 2021 07:51:57 +0200 (CEST) Received: from kaod.org (37.59.142.106) by DAG8EX1.mxp5.local (172.16.2.71) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2106.2; Thu, 1 Apr 2021 07:51:56 +0200 Authentication-Results: garm.ovh; auth=pass (GARM-106R006286b2b47-9e79-43ca-b58f-aa332cd287af, A2907451AC51A4EFF4C4D6DD6E02A54F207D12BE) smtp.auth=groug@kaod.org X-OVh-ClientIp: 78.197.208.248 Date: Thu, 1 Apr 2021 07:51:55 +0200 From: Greg Kurz To: David Gibson Subject: Re: [PATCH v2] ppc/spapr: Add support for implement support for H_SCM_HEALTH Message-ID: <20210401075155.44b9267d@bahia.lan> In-Reply-To: References: <20210401010519.7225-1-vaibhav@linux.ibm.com> X-Mailer: Claws Mail 3.17.8 (GTK+ 2.24.32; x86_64-redhat-linux-gnu) MIME-Version: 1.0 Content-Type: multipart/signed; boundary="Sig_/7qo0K+59=sl2FU82aBhc9E8"; protocol="application/pgp-signature"; micalg=pgp-sha256 X-Originating-IP: [37.59.142.106] X-ClientProxiedBy: DAG6EX1.mxp5.local (172.16.2.51) To DAG8EX1.mxp5.local (172.16.2.71) X-Ovh-Tracer-GUID: d02a1d92-91ff-4346-b061-cafd730401e7 X-Ovh-Tracer-Id: 6880655809270487483 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: -100 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgeduledrudeifedgleelucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuqfggjfdpvefjgfevmfevgfenuceurghilhhouhhtmecuhedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhepfffhvffukfgjfhfogggtihesghdtreerredtvdenucfhrhhomhepifhrvghgucfmuhhriicuoehgrhhouhhgsehkrghougdrohhrgheqnecuggftrfgrthhtvghrnhepgfejudetffetgfekveekvefhieekheekgefgvdelleelhffggeetfeeigffhleegnecuffhomhgrihhnpehkvghrnhgvlhdrohhrghenucfkpheptddrtddrtddrtddpfeejrdehledrudegvddruddtieenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhhouggvpehsmhhtphdqohhuthdphhgvlhhopehmgihplhgrnhehrdhmrghilhdrohhvhhdrnhgvthdpihhnvghtpedtrddtrddtrddtpdhmrghilhhfrhhomhepghhrohhugheskhgrohgurdhorhhgpdhrtghpthhtohepmhgrrhgtvghlrdgrphhfvghlsggruhhmsehgmhgrihhlrdgtohhm Received-SPF: pass client-ip=178.32.121.110; envelope-from=groug@kaod.org; helo=1.mo51.mail-out.ovh.net X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: xiaoguangrong.eric@gmail.com, mst@redhat.com, aneesh.kumar@linux.ibm.com, bharata@linux.vnet.ibm.com, qemu-devel@nongnu.org, kvm-ppc@vger.kernel.org, shivaprasadbhat@gmail.com, qemu-ppc@nongnu.org, imammedo@redhat.com, Vaibhav Jain , ehabkost@redhat.com Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" --Sig_/7qo0K+59=sl2FU82aBhc9E8 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable On Thu, 1 Apr 2021 13:26:11 +1100 David Gibson wrote: > On Thu, Apr 01, 2021 at 06:35:19AM +0530, Vaibhav Jain wrote: > > Add support for H_SCM_HEALTH hcall described at [1] for spapr > > nvdimms. This enables guest to detect the 'unarmed' status of a > > specific spapr nvdimm identified by its DRC and if its unarmed, mark > > the region backed by the nvdimm as read-only. > >=20 > > The patch adds h_scm_health() to handle the H_SCM_HEALTH hcall which > > returns two 64-bit bitmaps (health bitmap, health bitmap mask) derived > > from 'struct nvdimm->unarmed' member. > >=20 > > Linux kernel side changes to enable handling of 'unarmed' nvdimms for > > ppc64 are proposed at [2]. > >=20 > > References: > > [1] "Hypercall Op-codes (hcalls)" > > https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/= tree/Documentation/powerpc/papr_hcalls.rst#n220 > > [2] "powerpc/papr_scm: Mark nvdimm as unarmed if needed during probe" > > https://lore.kernel.org/linux-nvdimm/20210329113103.476760-1-vaibha= v@linux.ibm.com/ > >=20 > > Signed-off-by: Vaibhav Jain >=20 > As well as the handful of comments below, this will definitely need to > wait for ppc-6.1 at this point. >=20 > > --- > > Changelog > >=20 > > v2: > > * Added a check for drc->dev to ensure that the dimm is plugged in > > when servicing H_SCM_HEALTH. [ Shiva ] > > * Instead of accessing the 'nvdimm->unarmed' member directly use the > > object_property_get_bool accessor to fetch it. [ Shiva ] > > * Update the usage of PAPR_PMEM_UNARMED* macros [ Greg ] > > * Updated patch description reference#1 to point appropriate section > > in the documentation. [ Greg ] > > --- > > hw/ppc/spapr_nvdimm.c | 38 ++++++++++++++++++++++++++++++++++++++ > > include/hw/ppc/spapr.h | 3 ++- > > 2 files changed, 40 insertions(+), 1 deletion(-) > >=20 > > diff --git a/hw/ppc/spapr_nvdimm.c b/hw/ppc/spapr_nvdimm.c > > index b46c36917c..34096e4718 100644 > > --- a/hw/ppc/spapr_nvdimm.c > > +++ b/hw/ppc/spapr_nvdimm.c > > @@ -31,6 +31,13 @@ > > #include "qemu/range.h" > > #include "hw/ppc/spapr_numa.h" > > =20 > > +/* DIMM health bitmap bitmap indicators. Taken from kernel's papr_scm.= c */ > > +/* SCM device is unable to persist memory contents */ > > +#define PAPR_PMEM_UNARMED (1ULL << (63 - 0)) >=20 > You can use PPC_BIT() for more clarity here. >=20 I had already suggested PPC_BIT(0) but since this macro was copied from the kernel source, I've let Vaibhav decide whether to use PPC_BIT() or keep the macro and comment it comes from the kernel. I agree I prefer PPC_BIT(0) :-) > > +/* Bits status indicators for health bitmap indicating unarmed dimm */ > > +#define PAPR_PMEM_UNARMED_MASK (PAPR_PMEM_UNARMED) >=20 > I'm not sure why you want two equal #defines here. >=20 Especially, this define doesn't make sense for the hypervisor IMHO. It is _just_ the mask of bits for the "unarmed" state in the kernel. > > + > > bool spapr_nvdimm_validate(HotplugHandler *hotplug_dev, NVDIMMDevice *= nvdimm, > > uint64_t size, Error **errp) > > { > > @@ -467,6 +474,36 @@ static target_ulong h_scm_unbind_all(PowerPCCPU *c= pu, SpaprMachineState *spapr, > > return H_SUCCESS; > > } > > =20 > > +static target_ulong h_scm_health(PowerPCCPU *cpu, SpaprMachineState *s= papr, > > + target_ulong opcode, target_ulong *ar= gs) > > +{ > > + uint32_t drc_index =3D args[0]; > > + SpaprDrc *drc =3D spapr_drc_by_index(drc_index); > > + NVDIMMDevice *nvdimm; > > + > > + if (drc && spapr_drc_type(drc) !=3D SPAPR_DR_CONNECTOR_TYPE_PMEM) { >=20 > This will fail badly if !drc (given index is way out of bounds). I'm > pretty sure you want > if (!drc || spapr_drc_type(drc) !=3D SPAPR_DR_CONNECTOR_TYPE_PMEM) { >=20 >=20 > > + return H_PARAMETER; > > + } > > + > > + /* Ensure that the dimm is plugged in */ > > + if (!drc->dev) { > > + return H_HARDWARE; >=20 > H_HARDWARE doesn't seem right - it's the guest that has chosen to > attempt this on an unplugged LMB, not the (virtual) hardware's fault. >=20 Yes. As already suggested, simply do the same as in other hcall implementations in this file, e.g. from h_scm_bind_mem() : if (!drc || !drc->dev || spapr_drc_type(drc) !=3D SPAPR_DR_CONNECTOR_TYPE_PMEM) { return H_PARAMETER; } > > + } > > + > > + nvdimm =3D NVDIMM(drc->dev); > > + > > + args[0] =3D 0; > > + /* Check if the nvdimm is unarmed and send its status via health b= itmaps */ Not sure this comment is super useful. > > + if (object_property_get_bool(OBJECT(nvdimm), NVDIMM_UNARMED_PROP, = NULL)) { > > + args[0] |=3D PAPR_PMEM_UNARMED; > > + } > > + > > + /* Update the health bitmap with the applicable mask */ > > + args[1] =3D PAPR_PMEM_UNARMED_MASK; I still think this is a misuse of PAPR_PMEM_UNARMED_MASK... The meaning of args[1] is "health-bit-valid-bitmap indicate which bits in health-bitmap are valid" according to the documentation. https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Doc= umentation/powerpc/papr_hcalls.rst#n228 Without any further detail, I tend to consider this as a hint to the guest on the bits supported by the hypervisor. Since we can only set PAPR_PMEM_UNARMED, for now, args[1] should be set to just that bit PAPR_PMEM_UNARMED. Other bits can be added later if QEMU supports more of them. > > + > > + return H_SUCCESS; > > +} > > + > > static void spapr_scm_register_types(void) > > { > > /* qemu/scm specific hcalls */ > > @@ -475,6 +512,7 @@ static void spapr_scm_register_types(void) > > spapr_register_hypercall(H_SCM_BIND_MEM, h_scm_bind_mem); > > spapr_register_hypercall(H_SCM_UNBIND_MEM, h_scm_unbind_mem); > > spapr_register_hypercall(H_SCM_UNBIND_ALL, h_scm_unbind_all); > > + spapr_register_hypercall(H_SCM_HEALTH, h_scm_health); > > } > > =20 > > type_init(spapr_scm_register_types) > > diff --git a/include/hw/ppc/spapr.h b/include/hw/ppc/spapr.h > > index 47cebaf3ac..6e1eafb05d 100644 > > --- a/include/hw/ppc/spapr.h > > +++ b/include/hw/ppc/spapr.h > > @@ -538,8 +538,9 @@ struct SpaprMachineState { > > #define H_SCM_BIND_MEM 0x3EC > > #define H_SCM_UNBIND_MEM 0x3F0 > > #define H_SCM_UNBIND_ALL 0x3FC > > +#define H_SCM_HEALTH 0x400 > > =20 > > -#define MAX_HCALL_OPCODE H_SCM_UNBIND_ALL > > +#define MAX_HCALL_OPCODE H_SCM_HEALTH > > =20 > > /* The hcalls above are standardized in PAPR and implemented by pHyp > > * as well. >=20 --Sig_/7qo0K+59=sl2FU82aBhc9E8 Content-Type: application/pgp-signature Content-Description: OpenPGP digital signature -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEtIKLr5QxQM7yo0kQcdTV5YIvc9YFAmBlX3sACgkQcdTV5YIv c9YBlA//S0kZnzRddcnbSPO/BIdgPu/FpvEbVCzApps8NIrR/lNT59nRz2+B62Lq vKwq+ueubX/Hj3ipYRMeIQouk7FsJNi+ZbDvvlO4htEeNrswm7BOMUIMZRJt2+Cz NDNfkQwfCPIdKPWiUUGIv6ZOSESMcaHBs6VrVeqiqPG+YOmXcrhwDtjEk+fw1NCf iX6inkhCeBcK+C7L+YcwXIypyAL28PWUwAyEHjk6M+TQGa+WXo4QiUSYyJnXr+no um8RqSdSejrcmM4DEtEi8k+Rg9Yr3nf2fc4vGXiT1eqbkHSATg9gy6lO7fZOp0p8 nQPWY95Q7ghm7CSUpwTJv2bjL0bDVGIJ0/kD4m4+MhrBSnAapM/Hr8FtY18DvKng 5qSApuVDlY0XwUEPXtKBahIHlwT1o0O/EozsA8ybVx7TsXJBZ1gLbfqNOQn1UTDi 01QviqIKCAROXt4tBRqr2l359XoD1So/e5BoEPP71Dfi1LipOoMM9chuRB58cD+D qI+sDH9kcxiQMUEhjUSqXo53ADHFFexK8LIYL0h51fDBT4P0/4mYT9zwlWEIXRCo 0AHdhgYWpby09pS8N8A8BQStTnQC306i5C34bPnYFbs8t25QFL4BY7B44qzb3aF+ 52yfDjcBtBy85NuNPlQitbwIkG5KyQUUZ5HBu2y7UCrsx7S/L5w= =Qqjn -----END PGP SIGNATURE----- --Sig_/7qo0K+59=sl2FU82aBhc9E8--