From: Laurent Vivier Date: Wed, 28 Sep 2016 13:17:14 +0000 Subject: Re: [kvm-unit-tests PATCH] powerpc: Check whether TM is available before running other tests Message-Id: <30c0a905-e990-b920-4524-8923fc705688@redhat.com> List-Id: References: <1475057919-29017-1-git-send-email-thuth@redhat.com> <125fb08e-eba3-0bc9-875a-3127fb0e2d2b@redhat.com> <74e11b21-971a-2639-244f-62f527809b2a@redhat.com> <36a8eb17-70f9-f54f-2f46-bfe941907aff@redhat.com> <7a4f081e-0b7c-ffea-a873-3e5cc38f1c13@redhat.com> In-Reply-To: <7a4f081e-0b7c-ffea-a873-3e5cc38f1c13@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: Thomas Huth , kvm@vger.kernel.org Cc: =?UTF-8?B?UmFkaW0gS3LEjW3DocWZ?= , kvm-ppc@vger.kernel.org, Drew Jones , Suraj Jitindar Singh On 28/09/2016 15:10, Thomas Huth wrote: > On 28.09.2016 14:41, Laurent Vivier wrote: >> >> >> On 28/09/2016 14:23, Thomas Huth wrote: >>> On 28.09.2016 14:13, Laurent Vivier wrote: >>>> >>>> >>>> On 28/09/2016 12:18, Thomas Huth wrote: >>>>> Transactional memory is currently only supported on KVM-HV, and >>>>> not yet on KVM-PR. So it's better to check the device tree first >>>>> and fail gracefully if it's not available. >>>>> >>>>> Signed-off-by: Thomas Huth >>>>> --- >>>>> powerpc/tm.c | 31 +++++++++++++++++++++++++++++++ >>>>> 1 file changed, 31 insertions(+) >>>>> >>>>> diff --git a/powerpc/tm.c b/powerpc/tm.c >>>>> index 6ce750a..83d9d3d 100644 >>>>> --- a/powerpc/tm.c >>>>> +++ b/powerpc/tm.c >>>>> @@ -10,6 +10,32 @@ >>>>> #include >>>>> #include >>>>> #include >>>>> +#include >>>>> +#include >>>>> + >>>>> +/* Check "ibm,pa-features" property of a CPU node for the TM flag */ >>>>> +static void cpu_has_tm(int fdtnode, u32 regval __unused, void *ptr) >>>>> +{ >>>>> + const struct fdt_property *prop; >>>>> + int plen; >>>>> + >>>>> + prop = fdt_get_property(dt_fdt(), fdtnode, "ibm,pa-features", &plen); >>>>> + assert(prop != NULL); >>>>> + >>>>> + if (plen >= 26 && prop->data[1] = 0 && (prop->data[24] & 0x80) != 0) >>>>> + *(int *)ptr += 1; >>>> >>>> Perhaps some comments can help here: >>>> why do you check plen >= 26 and not >= 25? >>>> why do you check prop->data[1]? >>> >>> Well, it's all in the (Lo-)PAPR spec, but I can add a comment there if >>> you like. >> >> Well, even with the spec, it's not really clear. >> >>>> why don't you check prop->data[23] for the size of the attribute? >>> >>> I guess you mean prop->data[0] ? ... sure, I can add that check, too. >> >> No in fact, I didn't understand correctly the spec. :) >> >> So date[0] is the size, should be plen (so no need to add the check) >> date[1] is the type, should be "0" ("attribute-specifier-type", you >> check it) >> and then an array( "attribute-specifier"), where byte 22 and 23 are >> "Level of Transactional Memory Category Support". It's not clear if TM >> bit is in byte 22 (data[24]) or in byte 23 (data[25]). How do you know? > > That's the way how it is encoded in QEMU currently, and the byte the > Linux kernel looks at. So I think it's right. thanks, I think it could be good to have a comment. Reviewed-by: Laurent Vivier