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 mm01.cs.columbia.edu (mm01.cs.columbia.edu [128.59.11.253]) by smtp.lore.kernel.org (Postfix) with ESMTP id 85F6DC433F5 for ; Thu, 16 Dec 2021 10:45:35 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by mm01.cs.columbia.edu (Postfix) with ESMTP id 258BB4B106; Thu, 16 Dec 2021 05:45:35 -0500 (EST) X-Virus-Scanned: at lists.cs.columbia.edu Authentication-Results: mm01.cs.columbia.edu (amavisd-new); dkim=softfail (fail, message has been altered) header.i=@kernel.org Received: from mm01.cs.columbia.edu ([127.0.0.1]) by localhost (mm01.cs.columbia.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id xzeeBfHbFz7j; Thu, 16 Dec 2021 05:45:34 -0500 (EST) Received: from mm01.cs.columbia.edu (localhost [127.0.0.1]) by mm01.cs.columbia.edu (Postfix) with ESMTP id 037674B1FB; Thu, 16 Dec 2021 05:45:34 -0500 (EST) Received: from localhost (localhost [127.0.0.1]) by mm01.cs.columbia.edu (Postfix) with ESMTP id C53A74B106 for ; Thu, 16 Dec 2021 05:45:32 -0500 (EST) X-Virus-Scanned: at lists.cs.columbia.edu Received: from mm01.cs.columbia.edu ([127.0.0.1]) by localhost (mm01.cs.columbia.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id B4hT9ZSa8Zrd for ; Thu, 16 Dec 2021 05:45:31 -0500 (EST) Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by mm01.cs.columbia.edu (Postfix) with ESMTPS id DF3704025B for ; Thu, 16 Dec 2021 05:45:31 -0500 (EST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 6F80861D27; Thu, 16 Dec 2021 10:45:31 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D6499C36AE2; Thu, 16 Dec 2021 10:45:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1639651530; bh=lsuTIb4QAadkxB8JMSkIQ9kqbNzDrbIGstkl5NzJwos=; h=From:To:Cc:Subject:Date:From; b=B0qqq+k/zpavypznn4lXvo8eWd3jIvRsOq1wLuNkkcKE2eCwmxsykIfqoV6UB6glQ fXov3G3Bbiw7lvoqb0D1L1QXsoFqcVESCGRd1QmYpkqvm58c4iIwzNM0wA2FZ2BRiB Py9/ydqN86OSU6WumHXwmiVsxQdqzKfYwPiP4/tIB1uRQKtqLnFn8Vb8iYwkcngok0 rKUA/g3Gg3H9Y58ZLkxEjrUl1gnnxmmImBznoZO3anypRsLrFwQjLGePJ0UeyUfQtH +T3JOg35lDnxAUlipIfz1KubrL5vRZRXGar7zxdFLdzhKAZNa/uBql/AyL0KnV+NnX 7QNz4dQsP6jSw== Received: from cfbb000407.r.cam.camfibre.uk ([185.219.108.64] helo=hot-poop.lan) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1mxoGO-00CUtK-TR; Thu, 16 Dec 2021 10:45:29 +0000 From: Marc Zyngier To: linux-arm-kernel@lists.infradead.org, kvm@vger.kernel.org, kvmarm@lists.cs.columbia.edu Subject: [PATCH] KVM: arm64: vgic-v3: Fix vcpu index comparison Date: Thu, 16 Dec 2021 10:45:26 +0000 Message-Id: <20211216104526.1482124-1-maz@kernel.org> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 X-SA-Exim-Connect-IP: 185.219.108.64 X-SA-Exim-Rcpt-To: linux-arm-kernel@lists.infradead.org, kvm@vger.kernel.org, kvmarm@lists.cs.columbia.edu, james.morse@arm.com, suzuki.poulose@arm.com, alexandru.elisei@arm.com, kernel-team@android.com X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false Cc: kernel-team@android.com X-BeenThere: kvmarm@lists.cs.columbia.edu X-Mailman-Version: 2.1.14 Precedence: list List-Id: Where KVM/ARM decisions are made List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: kvmarm-bounces@lists.cs.columbia.edu Sender: kvmarm-bounces@lists.cs.columbia.edu When handling an error at the point where we try and register all the redistributors, we unregister all the previously registered frames by counting down from the failing index. However, the way the code is written relies on that index being a signed value. Which won't be true once we switch to an xarray-based vcpu set. Since this code is pretty awkward the first place, and that the failure mode is hard to spot, rewrite this loop to iterate over the vcpus upwards rather than downwards. Signed-off-by: Marc Zyngier --- arch/arm64/kvm/vgic/vgic-mmio-v3.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/arch/arm64/kvm/vgic/vgic-mmio-v3.c b/arch/arm64/kvm/vgic/vgic-mmio-v3.c index bf7ec4a78497..9943a3fe1b0a 100644 --- a/arch/arm64/kvm/vgic/vgic-mmio-v3.c +++ b/arch/arm64/kvm/vgic/vgic-mmio-v3.c @@ -763,10 +763,12 @@ static int vgic_register_all_redist_iodevs(struct kvm *kvm) } if (ret) { - /* The current c failed, so we start with the previous one. */ + /* The current c failed, so iterate over the previous ones. */ + int i; + mutex_lock(&kvm->slots_lock); - for (c--; c >= 0; c--) { - vcpu = kvm_get_vcpu(kvm, c); + for (i = 0; i < c; i++) { + vcpu = kvm_get_vcpu(kvm, i); vgic_unregister_redist_iodev(vcpu); } mutex_unlock(&kvm->slots_lock); -- 2.30.2 _______________________________________________ kvmarm mailing list kvmarm@lists.cs.columbia.edu https://lists.cs.columbia.edu/mailman/listinfo/kvmarm 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id ADFECC433F5 for ; Thu, 16 Dec 2021 10:46:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:Cc :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=axjykS9m82akHayAXCpCXezDOVCjE/xfpgEAkt3YuVA=; b=ooTQOyI8a6YbEq Qp9kWS3TtqMOgZlR1IvppuyY7IVqSn1vJy5wOschAEKWEq48X4M9tJBMDD4hgntT8zT8P5b//YZf4 BpFEvECvZSVPviz44WW5z4u+FP6nOLo2YzhvgDmYq7+aAoatGXz4rVdLrlBNYsbZnBm8mrKRUE3HX 3DS6x9APDTDTEtt8tLVRi8dxSP86sNVEBH2ShO+oMFqnknn7ipTkst4BUMeEfEBMde4xaEJNdrOlc MC7qIlON9SeSAUALU5ffvN1ZhQnohLhHzrmVkRV6zEoCqu4kMhLSZT++IcFgeZx5wge2Hhtw47E2C GwMQAOFLyG9zWxdtO2ng==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mxoGV-004uSq-E0; Thu, 16 Dec 2021 10:45:35 +0000 Received: from dfw.source.kernel.org ([139.178.84.217]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mxoGR-004uS2-Tn for linux-arm-kernel@lists.infradead.org; Thu, 16 Dec 2021 10:45:33 +0000 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 6F80861D27; Thu, 16 Dec 2021 10:45:31 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D6499C36AE2; Thu, 16 Dec 2021 10:45:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1639651530; bh=lsuTIb4QAadkxB8JMSkIQ9kqbNzDrbIGstkl5NzJwos=; h=From:To:Cc:Subject:Date:From; b=B0qqq+k/zpavypznn4lXvo8eWd3jIvRsOq1wLuNkkcKE2eCwmxsykIfqoV6UB6glQ fXov3G3Bbiw7lvoqb0D1L1QXsoFqcVESCGRd1QmYpkqvm58c4iIwzNM0wA2FZ2BRiB Py9/ydqN86OSU6WumHXwmiVsxQdqzKfYwPiP4/tIB1uRQKtqLnFn8Vb8iYwkcngok0 rKUA/g3Gg3H9Y58ZLkxEjrUl1gnnxmmImBznoZO3anypRsLrFwQjLGePJ0UeyUfQtH +T3JOg35lDnxAUlipIfz1KubrL5vRZRXGar7zxdFLdzhKAZNa/uBql/AyL0KnV+NnX 7QNz4dQsP6jSw== Received: from cfbb000407.r.cam.camfibre.uk ([185.219.108.64] helo=hot-poop.lan) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1mxoGO-00CUtK-TR; Thu, 16 Dec 2021 10:45:29 +0000 From: Marc Zyngier To: linux-arm-kernel@lists.infradead.org, kvm@vger.kernel.org, kvmarm@lists.cs.columbia.edu Cc: James Morse , Suzuki K Poulose , Alexandru Elisei , kernel-team@android.com Subject: [PATCH] KVM: arm64: vgic-v3: Fix vcpu index comparison Date: Thu, 16 Dec 2021 10:45:26 +0000 Message-Id: <20211216104526.1482124-1-maz@kernel.org> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 X-SA-Exim-Connect-IP: 185.219.108.64 X-SA-Exim-Rcpt-To: linux-arm-kernel@lists.infradead.org, kvm@vger.kernel.org, kvmarm@lists.cs.columbia.edu, james.morse@arm.com, suzuki.poulose@arm.com, alexandru.elisei@arm.com, kernel-team@android.com X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211216_024532_021215_699725B9 X-CRM114-Status: GOOD ( 18.01 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org When handling an error at the point where we try and register all the redistributors, we unregister all the previously registered frames by counting down from the failing index. However, the way the code is written relies on that index being a signed value. Which won't be true once we switch to an xarray-based vcpu set. Since this code is pretty awkward the first place, and that the failure mode is hard to spot, rewrite this loop to iterate over the vcpus upwards rather than downwards. Signed-off-by: Marc Zyngier --- arch/arm64/kvm/vgic/vgic-mmio-v3.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/arch/arm64/kvm/vgic/vgic-mmio-v3.c b/arch/arm64/kvm/vgic/vgic-mmio-v3.c index bf7ec4a78497..9943a3fe1b0a 100644 --- a/arch/arm64/kvm/vgic/vgic-mmio-v3.c +++ b/arch/arm64/kvm/vgic/vgic-mmio-v3.c @@ -763,10 +763,12 @@ static int vgic_register_all_redist_iodevs(struct kvm *kvm) } if (ret) { - /* The current c failed, so we start with the previous one. */ + /* The current c failed, so iterate over the previous ones. */ + int i; + mutex_lock(&kvm->slots_lock); - for (c--; c >= 0; c--) { - vcpu = kvm_get_vcpu(kvm, c); + for (i = 0; i < c; i++) { + vcpu = kvm_get_vcpu(kvm, i); vgic_unregister_redist_iodev(vcpu); } mutex_unlock(&kvm->slots_lock); -- 2.30.2 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel 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 7DEB4C433EF for ; Thu, 16 Dec 2021 10:45:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236213AbhLPKpe (ORCPT ); Thu, 16 Dec 2021 05:45:34 -0500 Received: from ams.source.kernel.org ([145.40.68.75]:47038 "EHLO ams.source.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236195AbhLPKpd (ORCPT ); Thu, 16 Dec 2021 05:45:33 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 0A888B82299 for ; Thu, 16 Dec 2021 10:45:32 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D6499C36AE2; Thu, 16 Dec 2021 10:45:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1639651530; bh=lsuTIb4QAadkxB8JMSkIQ9kqbNzDrbIGstkl5NzJwos=; h=From:To:Cc:Subject:Date:From; b=B0qqq+k/zpavypznn4lXvo8eWd3jIvRsOq1wLuNkkcKE2eCwmxsykIfqoV6UB6glQ fXov3G3Bbiw7lvoqb0D1L1QXsoFqcVESCGRd1QmYpkqvm58c4iIwzNM0wA2FZ2BRiB Py9/ydqN86OSU6WumHXwmiVsxQdqzKfYwPiP4/tIB1uRQKtqLnFn8Vb8iYwkcngok0 rKUA/g3Gg3H9Y58ZLkxEjrUl1gnnxmmImBznoZO3anypRsLrFwQjLGePJ0UeyUfQtH +T3JOg35lDnxAUlipIfz1KubrL5vRZRXGar7zxdFLdzhKAZNa/uBql/AyL0KnV+NnX 7QNz4dQsP6jSw== Received: from cfbb000407.r.cam.camfibre.uk ([185.219.108.64] helo=hot-poop.lan) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1mxoGO-00CUtK-TR; Thu, 16 Dec 2021 10:45:29 +0000 From: Marc Zyngier To: linux-arm-kernel@lists.infradead.org, kvm@vger.kernel.org, kvmarm@lists.cs.columbia.edu Cc: James Morse , Suzuki K Poulose , Alexandru Elisei , kernel-team@android.com Subject: [PATCH] KVM: arm64: vgic-v3: Fix vcpu index comparison Date: Thu, 16 Dec 2021 10:45:26 +0000 Message-Id: <20211216104526.1482124-1-maz@kernel.org> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SA-Exim-Connect-IP: 185.219.108.64 X-SA-Exim-Rcpt-To: linux-arm-kernel@lists.infradead.org, kvm@vger.kernel.org, kvmarm@lists.cs.columbia.edu, james.morse@arm.com, suzuki.poulose@arm.com, alexandru.elisei@arm.com, kernel-team@android.com X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org When handling an error at the point where we try and register all the redistributors, we unregister all the previously registered frames by counting down from the failing index. However, the way the code is written relies on that index being a signed value. Which won't be true once we switch to an xarray-based vcpu set. Since this code is pretty awkward the first place, and that the failure mode is hard to spot, rewrite this loop to iterate over the vcpus upwards rather than downwards. Signed-off-by: Marc Zyngier --- arch/arm64/kvm/vgic/vgic-mmio-v3.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/arch/arm64/kvm/vgic/vgic-mmio-v3.c b/arch/arm64/kvm/vgic/vgic-mmio-v3.c index bf7ec4a78497..9943a3fe1b0a 100644 --- a/arch/arm64/kvm/vgic/vgic-mmio-v3.c +++ b/arch/arm64/kvm/vgic/vgic-mmio-v3.c @@ -763,10 +763,12 @@ static int vgic_register_all_redist_iodevs(struct kvm *kvm) } if (ret) { - /* The current c failed, so we start with the previous one. */ + /* The current c failed, so iterate over the previous ones. */ + int i; + mutex_lock(&kvm->slots_lock); - for (c--; c >= 0; c--) { - vcpu = kvm_get_vcpu(kvm, c); + for (i = 0; i < c; i++) { + vcpu = kvm_get_vcpu(kvm, i); vgic_unregister_redist_iodev(vcpu); } mutex_unlock(&kvm->slots_lock); -- 2.30.2