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=-15.3 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=unavailable 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 7347BC43460 for ; Tue, 13 Apr 2021 06:06:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5310F613AB for ; Tue, 13 Apr 2021 06:06:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344855AbhDMGGa (ORCPT ); Tue, 13 Apr 2021 02:06:30 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:15671 "EHLO szxga04-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343930AbhDMGGZ (ORCPT ); Tue, 13 Apr 2021 02:06:25 -0400 Received: from DGGEMS410-HUB.china.huawei.com (unknown [172.30.72.60]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4FKFQP1sdyznWcp; Tue, 13 Apr 2021 14:03:09 +0800 (CST) Received: from [10.174.187.224] (10.174.187.224) by DGGEMS410-HUB.china.huawei.com (10.3.19.210) with Microsoft SMTP Server id 14.3.498.0; Tue, 13 Apr 2021 14:05:58 +0800 Subject: Re: [PATCH] KVM: arm/arm64: Fix KVM_VGIC_V3_ADDR_TYPE_REDIST read To: Eric Auger , , , , , , , , References: <20210412150034.29185-1-eric.auger@redhat.com> CC: , From: Keqian Zhu Message-ID: Date: Tue, 13 Apr 2021 14:05:47 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.7.1 MIME-Version: 1.0 In-Reply-To: <20210412150034.29185-1-eric.auger@redhat.com> Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Originating-IP: [10.174.187.224] X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2021/4/12 23:00, Eric Auger wrote: > When reading the base address of the a REDIST region > through KVM_VGIC_V3_ADDR_TYPE_REDIST we expect the > redistributor region list to be populated with a single > element. > > However list_first_entry() expects the list to be non empty. Indeed, list_first_entry() always return a non-null ptr. If the list is empty, it will mistake the list head as the first element. > Instead we should use list_first_entry_or_null which effectively > returns NULL if the list is empty. > > Fixes: dbd9733ab674 ("KVM: arm/arm64: Replace the single rdist region by a list") > Cc: # v4.18+ > Signed-off-by: Eric Auger > Reported-by: Gavin Shan > --- > arch/arm64/kvm/vgic/vgic-kvm-device.c | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > > diff --git a/arch/arm64/kvm/vgic/vgic-kvm-device.c b/arch/arm64/kvm/vgic/vgic-kvm-device.c > index 44419679f91a..5eaede3e3b5a 100644 > --- a/arch/arm64/kvm/vgic/vgic-kvm-device.c > +++ b/arch/arm64/kvm/vgic/vgic-kvm-device.c > @@ -87,8 +87,8 @@ int kvm_vgic_addr(struct kvm *kvm, unsigned long type, u64 *addr, bool write) > r = vgic_v3_set_redist_base(kvm, 0, *addr, 0); > goto out; > } > - rdreg = list_first_entry(&vgic->rd_regions, > - struct vgic_redist_region, list); > + rdreg = list_first_entry_or_null(&vgic->rd_regions, > + struct vgic_redist_region, list); > if (!rdreg) > addr_ptr = &undef_value; > else >