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=-7.0 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED 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 5C27DC0650E for ; Thu, 4 Jul 2019 08:21:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3B6CA218A4 for ; Thu, 4 Jul 2019 08:21:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727159AbfGDIVD (ORCPT ); Thu, 4 Jul 2019 04:21:03 -0400 Received: from foss.arm.com ([217.140.110.172]:36284 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726908AbfGDIVC (ORCPT ); Thu, 4 Jul 2019 04:21:02 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id BFFDC344; Thu, 4 Jul 2019 01:21:01 -0700 (PDT) Received: from big-swifty.misterjones.org (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 1378E3F703; Thu, 4 Jul 2019 01:20:57 -0700 (PDT) Date: Thu, 04 Jul 2019 09:20:54 +0100 Message-ID: <86wogynrbt.wl-marc.zyngier@arm.com> From: Marc Zyngier To: Dave Martin , Paolo Bonzini , Radim =?UTF-8?B?S3LEjW3DocWZ?= Cc: , , Alex =?UTF-8?B?QmVubsOpZQ==?= , Ard Biesheuvel , Christoffer Dall , Will Deacon , Julien Grall , Catalin Marinas , Peter Maydell , "Okamoto\ Takayuki" , Zhang Lei , Viresh Kumar , kvm Subject: Re: [PATCH] KVM: arm64/sve: Fix vq_present() macro to yield a bool In-Reply-To: <1562175770-10952-1-git-send-email-Dave.Martin@arm.com> References: <1562175770-10952-1-git-send-email-Dave.Martin@arm.com> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL/10.8 EasyPG/1.0.0 Emacs/26 (aarch64-unknown-linux-gnu) MULE/6.0 (HANACHIRUSATO) Organization: ARM Ltd MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: text/plain; charset=US-ASCII Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org +KVM, Paolo and Radim, Guys, do you mind picking this single patch and sending it to Linus? That's the only fix left for 5.2. Alternatively, I can send you a pull request, but it feels overkill. Either way, please let me know. Thanks, M. On Wed, 03 Jul 2019 18:42:50 +0100, Dave Martin wrote: > > From: Zhang Lei > > The original implementation of vq_present() relied on aggressive > inlining in order for the compiler to know that the code is > correct, due to some const-casting issues. This was causing sparse > and clang to complain, while GCC compiled cleanly. > > Commit 0c529ff789bc addressed this problem, but since vq_present() > is no longer a function, there is now no implicit casting of the > returned value to the return type (bool). > > In set_sve_vls(), this uncast bit value is compared against a bool, > and so may spuriously compare as unequal when both are nonzero. As > a result, KVM may reject valid SVE vector length configurations as > invalid, and vice versa. > > Fix it by forcing the returned value to a bool. > > Signed-off-by: Zhang Lei > Fixes: 0c529ff789bc ("KVM: arm64: Implement vq_present() as a macro") > Signed-off-by: Dave Martin [commit message rewrite] > Cc: Viresh Kumar > > --- > > Posting this under Zhang Lei's authorship, due to the need to turn this > fix around quickly. The fix is as per the original suggestion [1]. > > Originally observed with the QEMU KVM SVE support under review: > https://lists.gnu.org/archive/html/qemu-devel/2019-06/msg04945.html > > Bug reproduced and fix tested on the Arm Fast Model, with > http://linux-arm.org/git?p=kvmtool-dm.git;a=shortlog;h=refs/heads/sve/v3/head > (After rerunning util/update_headers.sh.) > > (the --sve-vls command line argument was removed in v4 of the > kvmtool patches). > > [1] http://lists.infradead.org/pipermail/linux-arm-kernel/2019-July/664633.html > --- > arch/arm64/kvm/guest.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/arch/arm64/kvm/guest.c b/arch/arm64/kvm/guest.c > index c2afa79..dfd6264 100644 > --- a/arch/arm64/kvm/guest.c > +++ b/arch/arm64/kvm/guest.c > @@ -208,7 +208,7 @@ static int set_core_reg(struct kvm_vcpu *vcpu, const struct kvm_one_reg *reg) > > #define vq_word(vq) (((vq) - SVE_VQ_MIN) / 64) > #define vq_mask(vq) ((u64)1 << ((vq) - SVE_VQ_MIN) % 64) > -#define vq_present(vqs, vq) ((vqs)[vq_word(vq)] & vq_mask(vq)) > +#define vq_present(vqs, vq) (!!((vqs)[vq_word(vq)] & vq_mask(vq))) > > static int get_sve_vls(struct kvm_vcpu *vcpu, const struct kvm_one_reg *reg) > { > -- > 2.1.4 > -- Jazz is not dead, it just smells funny.