Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp6998622rwb; Mon, 5 Dec 2022 22:50:36 -0800 (PST) X-Google-Smtp-Source: AA0mqf5BdNxMR/yJxDzWzfUEgXaQWnqHsC5YczMdfaP/6qotXh68Oxh477IK54n1wp6X8TCAnw/J X-Received: by 2002:a63:145e:0:b0:473:c377:b82 with SMTP id 30-20020a63145e000000b00473c3770b82mr61289534pgu.113.1670309436328; Mon, 05 Dec 2022 22:50:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670309436; cv=none; d=google.com; s=arc-20160816; b=xU2Z9Uh76hQdjU4Whi8gYyA44DbqtYZXXMhndLLP8WolPkMHu8e+5uT9ltwThJsczk tD9Ka8gRjuPMO9bVO5qD3NfTEvkYqlxVJfWbNH4GjwbPr1TXKecxL+Us0xKImJE2rNkO FgwLX6F+44C4zrBPrmQGKx7piFGDMvg1NETtI+yRIMxW/tpv5UqnJKlEAt913tM3yyT7 1iUDXxJBIcVbQw5vqXJju93HhBiQwjtj07iyC+BuHQ4UULLC9pWaPRK9bwOyW0YMszfB GLXWiEYuS6qmB+3qGMw1IvyLt1aD31GLi/J9GfvyhNQvQ40fdlwZ4vxBqWW3oI7WybVX 9MXg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:sender:hmm_source_type:hmm_attache_num :hmm_source_ip; bh=y2hNal97KdKoNUNb6I4grWzKIw6nsuKc98uBLzv7dMc=; b=EUJoybU1i3fQCCw896did4aUBezmG72EUN6TiHlSDro/Rd81J4WofKJDf8S3WhP0ei v+rplYwVHgLT9Viu/F/0A/TEt/Y8IiFi/iSt7r9vnqz8aYPH2baFvX9E+k/2CzTkXyPM QU3VmvKoZ8aB1MKBOZPBSsCD3Jy0YVhmlMwdokEtfII0jAm8QtsHETh2lDrLFEtLTzqu 0uvHSvkOILIviG+sGuenFYArgPotD1hZbyAj+eB5ugEY8RbxFxuFl5olkpLQTGOrxbY2 7J4fsLY/tUAwDtuAHet+M8sAFcktj3MfBGE9WpVJLfFQrVHPiIZP9oAjphqIvHRb73+H txxA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k63-20020a638442000000b00476d1591b76si16782333pgd.119.2022.12.05.22.50.25; Mon, 05 Dec 2022 22:50:36 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231715AbiLFGCH (ORCPT + 79 others); Tue, 6 Dec 2022 01:02:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46122 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233084AbiLFGCC (ORCPT ); Tue, 6 Dec 2022 01:02:02 -0500 Received: from 189.cn (ptr.189.cn [183.61.185.102]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 7519527157; Mon, 5 Dec 2022 22:01:57 -0800 (PST) HMM_SOURCE_IP: 10.64.8.43:55518.1873184978 HMM_ATTACHE_NUM: 0000 HMM_SOURCE_TYPE: SMTP Received: from clientip-123.150.8.42 (unknown [10.64.8.43]) by 189.cn (HERMES) with SMTP id 25246100302; Tue, 6 Dec 2022 14:01:54 +0800 (CST) Received: from ([123.150.8.42]) by gateway-153622-dep-6cffbd87dd-f7vjc with ESMTP id 5f66b60e48754f84901a8e6e8468e94a for arnd@arndb.de; Tue, 06 Dec 2022 14:01:55 CST X-Transaction-ID: 5f66b60e48754f84901a8e6e8468e94a X-Real-From: chensong_2000@189.cn X-Receive-IP: 123.150.8.42 X-MEDUSA-Status: 0 Sender: chensong_2000@189.cn Message-ID: <0903321f-e0cf-fd7b-bbdd-fc4fdc0f05a0@189.cn> Date: Tue, 6 Dec 2022 14:01:53 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.4.2 Subject: Re: [PATCH v3 3/4] include/asm-generic/io.h: remove performing pointer arithmetic on a null pointer To: Arnd Bergmann , Steven Rostedt , Masami Hiramatsu , Niklas Schnelle Cc: linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, Linux-Arch References: <1670229006-4063-1-git-send-email-chensong_2000@189.cn> <2a3d3359-a5fd-453b-81f1-35c7a35fc12d@app.fastmail.com> Content-Language: en-US From: Song Chen In-Reply-To: <2a3d3359-a5fd-453b-81f1-35c7a35fc12d@app.fastmail.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, FREEMAIL_ENVFROM_END_DIGIT,FREEMAIL_FROM,NICE_REPLY_A, RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, 在 2022/12/5 18:04, Arnd Bergmann 写道: > On Mon, Dec 5, 2022, at 09:30, Song Chen wrote: >> kernel test robot reports below warnings: >> >> In file included from kernel/trace/trace_events_synth.c:18: >> In file included from include/linux/trace_events.h:9: >> In file included from include/linux/hardirq.h:11: >> In file included from ./arch/hexagon/include/generated/asm/hardirq.h:1: >> In file included from include/asm-generic/hardirq.h:17: >> In file included from include/linux/irq.h:20: >> In file included from include/linux/io.h:13: >> In file included from arch/hexagon/include/asm/io.h:334: >> include/asm-generic/io.h:547:31: warning: performing pointer arithmetic >> on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] >> val = __raw_readb(PCI_IOBASE + addr); >> ~~~~~~~~~~ ^ >> include/asm-generic/io.h:560:61: warning: performing pointer arithmetic >> on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] >> val = __le16_to_cpu((__le16 __force)__raw_readw(PCI_IOBASE + addr)); >> ~~~~~~~~~~ ^ >> include/uapi/linux/byteorder/little_endian.h:37:51: note: >> expanded from macro '__le16_to_cpu' >> #define __le16_to_cpu(x) ((__force __u16)(__le16)(x)) >> >> The reason could be constant literal zero converted to any pointer type decays >> into the null pointer constant. >> >> I'm not sure why those warnings are only triggered when building hexagon instead >> of x86 or arm, but anyway, i found a work around: >> >> void *pci_iobase = PCI_IOBASE; >> val = __raw_readb(pci_iobase + addr); >> >> The pointer is not evaluated at compile time, so the warnings are removed. >> >> Signed-off-by: Song Chen >> Reported-by: kernel test robot > > The code is still wrong, you just hide the warning, so no, this is > not a correct fix. When PCI_IOBASE is NULL, any call to > inb() etc is a NULL pointer dereference that immediately crashes > the kernel, so the correct solution is to not allow building code > that uses port I/O on kernels that are configured not to > support port I/O. > > We have discussed this bit multiple times, and Niklas Schnelle > last posted his series to fix this as an RFC in [1]. > > Arnd > > [1] https://lore.kernel.org/lkml/20220429135108.2781579-1-schnelle@linux.ibm.com/ > Trace triggers the warning accidentally by including io.h indirectly because of the absence of PCI_IOBASE in hexagon. So what trace can do in this case is either to suppress warning or just ignore it, the warning will go away as long as hexagon has put PCI_IOBASE in place or implemented its own inb() etc, i think they will do it sooner or later. Introducing HAS_IOPORT to trace seems no necessary and too much impact. /Song