Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp320574pxf; Thu, 1 Apr 2021 01:54:35 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz7gtPqLNCq06ZThZ3Mgx4o2WwuqEIjfWZYPLaXsFXGJodmJ3CYU4GtaXzLbn0fs7qvlXMu X-Received: by 2002:a17:906:c301:: with SMTP id s1mr7824436ejz.382.1617267274790; Thu, 01 Apr 2021 01:54:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617267274; cv=none; d=google.com; s=arc-20160816; b=aJPyobep1iw54BgDiDksFDO8Bc1reINWA/AxvOcjOKbWPREn9yUD2taC/LNu350OkU wYbYbpzX4U2oumH9yY8La9ko3dc/vBhpdnQ3sAetP/mdyzPiLhcDR7110+2O4/skJZCq LjP8/BPCYVXc3RWdIrjsZQg75T+u9ToZuEpynMeYi+r2tpp+oNtw8G5X9cENvGdSzrwD y4LzENYAlfSANT2fQv1mEQTI0yPdvVp6QoOeu6UGpeXW3f30KtOAbBz6Evmqk+9LipeR XP0WWcWQwXBkey7l+SCU7wWvdR/FepOfAOyr8dMhzU3Iw9+kwy2d/KZTV1rmRGHNwzg9 zk0A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=oAp8KP+PLZpDIKXzQzhXsSAbuzZEHkjTkksMRphxdow=; b=LM8/BM5jn3Z8RSFMOBBFKpt9a2j7TkojZPP/ghoYi2cHp3a2oeSYIR7LoEObFvM3iJ zawqe149QADzuUuFMeH/jam6Yj8hFX0AbsX1JTJu0Ke33A3z2Tf8htTyz2C7hC66rWzJ v1COzuCNtRN6Qg82N/lOWTC+dXXgTv/RY1K1GlrP+ysV/jGJebj8BEIA60CJLpDVScMz pA8L/0Md01LD6iRsAeaoBA0Rt9+FmJQi1oSM0YuI+gNttKNkYyr+44gIdTb8GLnoBn4+ EGDpMP8p0yWCf9p0YkemoRwRh8e4t3KXdrScfvYZTCJdceTX1LW774AmpUWUMkYovqlT cPyQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=LcN30DGw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d12si4028227ejj.594.2021.04.01.01.54.12; Thu, 01 Apr 2021 01:54:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=LcN30DGw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233782AbhDAIxV (ORCPT + 99 others); Thu, 1 Apr 2021 04:53:21 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:33774 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233283AbhDAIw4 (ORCPT ); Thu, 1 Apr 2021 04:52:56 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1617267175; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=oAp8KP+PLZpDIKXzQzhXsSAbuzZEHkjTkksMRphxdow=; b=LcN30DGwvPWBVQBUEwsFq8tnDk4WrafPHMVufy0zA2iwOpQAkCjrTh9Lpa11gxc6I40L7N /flqtKSUMmrp1Yf1B0Og4qmslBIKAOozbxarP7WTftnUHCAShJiyiu0IolVUr51VK9cet3 pCuXtBn0sbh4qUBJ0RcziOc0OYhea2s= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-61-LucLALYfP0SAUJFgksrUTw-1; Thu, 01 Apr 2021 04:52:54 -0400 X-MC-Unique: LucLALYfP0SAUJFgksrUTw-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 63095501FF; Thu, 1 Apr 2021 08:52:52 +0000 (UTC) Received: from laptop.redhat.com (ovpn-112-13.ams2.redhat.com [10.36.112.13]) by smtp.corp.redhat.com (Postfix) with ESMTP id BDEF65D9CC; Thu, 1 Apr 2021 08:52:49 +0000 (UTC) From: Eric Auger To: eric.auger.pro@gmail.com, eric.auger@redhat.com, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, kvmarm@lists.cs.columbia.edu, maz@kernel.org, drjones@redhat.com, alexandru.elisei@arm.com Cc: james.morse@arm.com, suzuki.poulose@arm.com, shuah@kernel.org, pbonzini@redhat.com Subject: [PATCH v4 3/8] KVM: arm64: vgic-v3: Fix error handling in vgic_v3_set_redist_base() Date: Thu, 1 Apr 2021 10:52:33 +0200 Message-Id: <20210401085238.477270-4-eric.auger@redhat.com> In-Reply-To: <20210401085238.477270-1-eric.auger@redhat.com> References: <20210401085238.477270-1-eric.auger@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org vgic_v3_insert_redist_region() may succeed while vgic_register_all_redist_iodevs fails. For example this happens while adding a redistributor region overlapping a dist region. The failure only is detected on vgic_register_all_redist_iodevs when vgic_v3_check_base() gets called in vgic_register_redist_iodev(). In such a case, remove the newly added redistributor region and free it. Signed-off-by: Eric Auger --- v1 -> v2: - fix the commit message and split declaration/assignment of rdreg --- arch/arm64/kvm/vgic/vgic-mmio-v3.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/arch/arm64/kvm/vgic/vgic-mmio-v3.c b/arch/arm64/kvm/vgic/vgic-mmio-v3.c index 013b737b658f8..987e366c80008 100644 --- a/arch/arm64/kvm/vgic/vgic-mmio-v3.c +++ b/arch/arm64/kvm/vgic/vgic-mmio-v3.c @@ -860,8 +860,14 @@ int vgic_v3_set_redist_base(struct kvm *kvm, u32 index, u64 addr, u32 count) * afterwards will register the iodevs when needed. */ ret = vgic_register_all_redist_iodevs(kvm); - if (ret) + if (ret) { + struct vgic_redist_region *rdreg; + + rdreg = vgic_v3_rdist_region_from_index(kvm, index); + list_del(&rdreg->list); + kfree(rdreg); return ret; + } return 0; } -- 2.26.3