Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp4176301pxk; Tue, 22 Sep 2020 12:14:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy9O6h+QqRGoyycirC7oG1mtuP3YsMaKtll8iuUwHf36hXI36mT1wglNoRFrOZ/+O6tQ83V X-Received: by 2002:a17:906:facb:: with SMTP id lu11mr6855380ejb.249.1600802071881; Tue, 22 Sep 2020 12:14:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600802071; cv=none; d=google.com; s=arc-20160816; b=xdBaNyvXuiE4MhrBCHVA+LPUE3vBRaqUrDKdB5lWaId+59AmrBxOdT7cE93dxwE7OV MQuTr+aB1L/0eKW5n02HhfbdbCxofn/TqXeSAS3233i0JjEb4g4EXSEYOIAtFSZH8w7I Nwrst9GGikgsf691QbcdZ3yjjHKJiISjTHurqVUFTMf0wez/sPJpP4kfUKXLVGCByEm5 NFcrGZvnOavPAUNyETi2R/9in07wn7s+K/k0BcKBF/0xrVY9AvLUdUyrf8Dx9t04Yk2n eJyepiEs54WeYWgzfUOMJZW7UJ0U4hKyiEDoKmJt91EkUzDYcoUjv4ozIUD+C3iatHyz VMaQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:autocrypt:from :references:to:subject:reply-to:dkim-signature; bh=lE/qfgSuBxzuZR9stjpPCy0PJ/22M7NK4nz92s2wOmw=; b=MUD1x2jE4cN6XpwNkDx/YVLFy4HpHVrUpCd5hd4E2ozwkIBYKG+x4NbF+kaj13pWPW /CvPgPBgdaaRPy9QA13HKkc6gyjiANe5AxFCNgKmAjeH9slOyuMQM7S/9cnOJNWbX+zj JJRP903CJtQsrDTe6MnKqIPwhn+z88agYHW+aQ5e0lf5T1xcpMGUE7rVB8Oc5TAGvHTM fDuftut37mRTLOkHKAIjKy/xDheT35ukkQNgesUX6JH3Io+L5AwlY1l6DtpwMr2BIT66 0yUdPDN0cz7ouUFHICvjvTSDebAriVTva6m08AZP+MQ5l7UtuUlws2oXrN5Nb751fadf BtBg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=G1KG2ksS; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h17si11660813ejq.747.2020.09.22.12.14.07; Tue, 22 Sep 2020 12:14:31 -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=@kernel.org header.s=default header.b=G1KG2ksS; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726723AbgIVTLS (ORCPT + 99 others); Tue, 22 Sep 2020 15:11:18 -0400 Received: from mail.kernel.org ([198.145.29.99]:52366 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726563AbgIVTLR (ORCPT ); Tue, 22 Sep 2020 15:11:17 -0400 Received: from [192.168.0.20] (cpc89244-aztw30-2-0-cust3082.18-1.cable.virginm.net [86.31.172.11]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 0E9C62068D; Tue, 22 Sep 2020 19:11:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1600801877; bh=2+LOS2Y0GLUTkbHcwy/Lo5qiZDvBCdGrQz6BIl7BQ80=; h=Reply-To:Subject:To:References:From:Date:In-Reply-To:From; b=G1KG2ksSXdNganwYDw5Gm6M4fQrjvBIocwmsnTCw7rlskyEdlL9x8QBLjCu43UMbW ZRWM5sV96uo6MsoxDw5lDfnUmKUcZ+vKM7zvv/9Pa9rVPAeDAxkI6nWaj9t+L1uwRw GBuE/M1RWlDBDi1AG0h6f6RDuOnPAinRVqisuXdY= Reply-To: kbingham@kernel.org Subject: Re: [PATCH] scripts/gdb: fix list_for_each To: "Prekas, George" , Jan Kiszka , linux-kernel@vger.kernel.org References: <3b382958-9f1d-a3d2-a239-09ba084227e6@amazon.com> <2516a051-306f-670b-1f9e-d46fc577c7f8@siemens.com> <109fe98d-4143-cfd3-b145-8d5fee189f63@amazon.com> From: Kieran Bingham Autocrypt: addr=kbingham@kernel.org; keydata= mQINBFYE/WYBEACs1PwjMD9rgCu1hlIiUA1AXR4rv2v+BCLUq//vrX5S5bjzxKAryRf0uHat V/zwz6hiDrZuHUACDB7X8OaQcwhLaVlq6byfoBr25+hbZG7G3+5EUl9cQ7dQEdvNj6V6y/SC rRanWfelwQThCHckbobWiQJfK9n7rYNcPMq9B8e9F020LFH7Kj6YmO95ewJGgLm+idg1Kb3C potzWkXc1xmPzcQ1fvQMOfMwdS+4SNw4rY9f07Xb2K99rjMwZVDgESKIzhsDB5GY465sCsiQ cSAZRxqE49RTBq2+EQsbrQpIc8XiffAB8qexh5/QPzCmR4kJgCGeHIXBtgRj+nIkCJPZvZtf Kr2EAbc6tgg6DkAEHJb+1okosV09+0+TXywYvtEop/WUOWQ+zo+Y/OBd+8Ptgt1pDRyOBzL8 RXa8ZqRf0Mwg75D+dKntZeJHzPRJyrlfQokngAAs4PaFt6UfS+ypMAF37T6CeDArQC41V3ko lPn1yMsVD0p+6i3DPvA/GPIksDC4owjnzVX9kM8Zc5Cx+XoAN0w5Eqo4t6qEVbuettxx55gq 8K8FieAjgjMSxngo/HST8TpFeq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R7rMMq9aUAjyiaEZpmP1qF/2sYenDx0Fg2BSlLvLvXM0vU8pQk3kgDu7kb/7PRYrZvB sr21EIQoIjXbZxDz/o7z95frkP71EaICttZ6k9q5oxxA5WC6sTXcMW8zs8avFNuA9VpXt0Yu pJd2ijtZy2mpZNG02fFVXhIn4G807G7+9mhuC4XG5rKlBBUXTvPUAfYnB4JBDLmLzBFavQfv onSfbitgXwCG3vS+9HEwAjU30Bar1PEOmIbiAoMzuKeRm2LVpmq4WZw01QYHU/GUV/zHJSFk Message-ID: <25111834-a414-e380-1e61-c1b1c0e766cb@kernel.org> Date: Tue, 22 Sep 2020 20:11:13 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: <109fe98d-4143-cfd3-b145-8d5fee189f63@amazon.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-GB Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi George, On 22/09/2020 18:17, Prekas, George wrote: > > On 9/22/2020 9:32 AM, Jan Kiszka wrote: >> >> On 22.09.20 16:28, George Prekas wrote: >>> If the next pointer is NULL, list_for_each gets stuck in an infinite >>> loop. >>> >>> Signed-off-by: George Prekas >>> --- >>>   scripts/gdb/linux/lists.py | 2 ++ >>>   1 file changed, 2 insertions(+) >>> >>> diff --git a/scripts/gdb/linux/lists.py b/scripts/gdb/linux/lists.py >>> index c487ddf09d38..424a91c1aa8b 100644 >>> --- a/scripts/gdb/linux/lists.py >>> +++ b/scripts/gdb/linux/lists.py >>> @@ -27,6 +27,8 @@ def list_for_each(head): >>>           raise TypeError("Must be struct list_head not {}" >>>                              .format(head.type)) >>> >>> +    if head['next'] == 0: >>> +        return >>>       node = head['next'].dereference() >>>       while node.address != head.address: >>>           yield node.address >> >> Obviously, infinite loops are bad and should be avoided. But NULL is >> bug, isn't it? Shouldn't we report such a corruption? >> > > Hi Jan, > > Is it a bug? Or does it mean that the list is empty? A correctly initialised (empty) list_head has the next, and prev pointers pointing to itself See: https://elixir.bootlin.com/linux/latest/source/include/linux/list.h#L33 You can see that the implementation of list_empty() checks for this at: https://elixir.bootlin.com/linux/latest/source/include/linux/list.h#L280 /** * list_empty - tests whether a list is empty * @head: the list to test. */ static inline int list_empty(const struct list_head *head) { return READ_ONCE(head->next) == head; } > Let me give some background. If you do the following: > > $ qemu-system-x86_64 -nographic -m 1024 -kernel > build/arch/x86/boot/bzImage -s -S < /dev/null > /dev/null & > $ gdb -q build/vmlinux -ex 'target remote localhost:1234' -iex 'set > auto-load safe-path /' -ex 'lx-symbols' I suspect this is trying to load modules before the kernel is actually fully loaded and running, so nothing is yet initialised. > You will see: > > loading vmlinux > scanning for modules in /home/ubuntu/linux-5.8.10 > no module object found for '' > > And the last line repeats forever. This happens because modules.next == > NULL. This is the Python stack trace: > >   File ".../symbols.py", line 174, in invoke >     self.load_all_symbols() >   File ".../symbols.py", line 161, in load_all_symbols >     [self.load_module_symbols(module) for module in module_list] >   File ".../symbols.py", line 161, in >     [self.load_module_symbols(module) for module in module_list] >   File ".../modules.py", line 30, in module_list >     for module in lists.list_for_each_entry(modules, module_ptr_type, > "list"): >   File ".../lists.py", line 41, in list_for_each_entry >     for node in list_for_each(head): >   File ".../lists.py", line 31, in list_for_each >     traceback.print_stack() > > This patch tries to fix the above problem. Does it fix it for you ? I expect it allows the boot process to continue, but the lx-symbols command will not have completed successfully (or rather I expect it will not have found anything to load). I suspect adding defensive checks in here might be helpful but I think the reality is the code is being called at the wrong time. The fact that it 'can' be called at the wrong time is where we might need to be more defensive. > George -- Kieran