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 145A3C5478C for ; Fri, 1 Mar 2024 07:54:15 +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:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=zEsMbY/NDH8KDZ3iiQds5txQbEoEUCazMzxR0sIqTmg=; b=Sx/4Fiz0A3mMQ7 /cVc8heNQF8oXnRt1MQUzhARTwQ9OIc89sGNqIMaCApQ3FMTYIOzKIyOjw19l4tEG+SBKWn374kIt KNZo+8Ha8RIVwXMz6NvvkhvHwIkbuW9CGFa6uXMvJJDYOk49Yl8lDSz5ta75s2vSOqR3AWVFLarD8 n+5sxDUR13yzh/1pmDpFcouL4vlPCcC10gG39o8hUXnaYSKo9iGKcXGJooB9ndXs7vBW3B/8r0/W+ ERoj61LWxWYxctYQTbg8cvZqm/bsr9qipiPQACsxg9hRG4lZiAWYItGgMlC9I3qqj5kslVcfvTPmb KjxaZBeBxMwOxjJsTqyA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rfxiT-0000000Gnl4-1sQ1; Fri, 01 Mar 2024 07:54:01 +0000 Received: from mail-wm1-x32d.google.com ([2a00:1450:4864:20::32d]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rfxiQ-0000000GnkW-2OCR for linux-arm-kernel@lists.infradead.org; Fri, 01 Mar 2024 07:54:00 +0000 Received: by mail-wm1-x32d.google.com with SMTP id 5b1f17b1804b1-412c286be35so8034205e9.0 for ; Thu, 29 Feb 2024 23:53:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1709279636; x=1709884436; darn=lists.infradead.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=rSYv96IWt9LEMG90iwKiTTPdrctB2BTQeORfL64Mr6I=; b=u0aR2lfMYFhUU3ZL4bJjXhfiDFlCDx4AbCUc+yoeee18xnsjd/+b1UlkBx8GxjrpHq ZG8LBaR7XPqwStE5Xnq7RXArCDTtVjXdY6W5CcDlxL9oFFoS1DHCdrsl3a6prJbGrANO Ir0Be6yQF3sNdMjNdYNL+w60rku9ZyNGt5pLElwrTbiiKlI/+Njw5GL3vg2NRVWeK6pq Fss2/OH5PdXPEMckBfNUqW7O+4w4X/kPJTSMygQ8LCwoXd9Yb/jl2BFzCMPI8gB+nbm6 oTe3ffHU8qYc9qCXd6P9Xd+SLgsfzwrN6LPNx3IXksN/rg1iOrQtnKJN/CZya5scQHHb Gxyw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709279636; x=1709884436; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=rSYv96IWt9LEMG90iwKiTTPdrctB2BTQeORfL64Mr6I=; b=roBjnXfCoILDbf2t795qjHvTH0BrIZIb8RnS1hvPSWCH3BVP83bHNWbP49aP+N/rF1 T1hSxvkzyI96nb4pI83T5zukCHBL0wDYx7AlHVAEXkOovGxu1fFE0tOjbeLUx1Ibmp6T HQ1DQ1O4oDTvhIWBWbo0O+ftdgtlexgUUL07cATAcjzEAb+nBp1mXyrRQenVrlD1XJAn k43w2T5WOg5NJ5UA/+lj8JdCx0SF++QI4pJSvbnInH5LEYOElbcsfWUesoGflZnSiN7j TiEafZK4DgIIBaOB2c0UuZ76bCM17yufurITNJCjvGH/RtGcL6h+Gb6JtLpVYtCYFMow XR+g== X-Forwarded-Encrypted: i=1; AJvYcCXjec+uQNwolXOpa5I8WMmrNN82OvkgSYSxi286POhE1h/6UUXhwSW81YyNyjoQ1JTpdQcBzAwFGlIwfpNlwWVuRrhBuynwUYtc1c/33kbHOgetpH4= X-Gm-Message-State: AOJu0YydyDnIoRCaa4XPdLyKzFxwKjLZ73XXnltMpv7YDORQusTu+lVH +S9OXjKfBp5pOzB6xt4wZb9ge5DMpjpsmpHc3g10owpnzp5hjkEEehZyIOpyrIM= X-Google-Smtp-Source: AGHT+IHLR64ehnwPVQ8P3YXUfrq2R5hUPIOvrsM1puSwkA493sbXl9zSjclBkmvynEEGWvwhqfKiKw== X-Received: by 2002:a05:600c:474a:b0:412:7489:c8c0 with SMTP id w10-20020a05600c474a00b004127489c8c0mr695084wmo.34.1709279636162; Thu, 29 Feb 2024 23:53:56 -0800 (PST) Received: from localhost ([102.222.70.76]) by smtp.gmail.com with ESMTPSA id by1-20020a056000098100b0033e22341942sm255997wrb.78.2024.02.29.23.53.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Feb 2024 23:53:55 -0800 (PST) Date: Fri, 1 Mar 2024 10:53:52 +0300 From: Dan Carpenter To: "Jain, Ronak" Cc: "Buddhabhatti, Jay" , "haribabu.gattem@xilinx.com" , "Simek, Michal" , "linux-arm-kernel@lists.infradead.org" Subject: Re: [bug report] soc: xilinx: Fix for call trace due to the usage of smp_processor_id() Message-ID: References: <52a41911-7c7d-4164-aeb7-aba5eddfeea9@moroto.mountain> <1c8fb4b3-c5a7-453c-b032-ac2a495faff0@moroto.mountain> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240229_235358_712463_E077BB3B X-CRM114-Status: GOOD ( 43.42 ) 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 On Thu, Feb 29, 2024 at 08:39:57AM +0000, Jain, Ronak wrote: > Hi Dan, > > > -----Original Message----- > > From: Dan Carpenter > > Sent: Tuesday, February 27, 2024 5:06 PM > > To: Jain, Ronak > > Cc: Buddhabhatti, Jay ; > > haribabu.gattem@xilinx.com; Simek, Michal ; > > linux-arm-kernel@lists.infradead.org > > Subject: Re: [bug report] soc: xilinx: Fix for call trace due to the usage of > > smp_processor_id() > > > > On Tue, Feb 27, 2024 at 10:10:45AM +0000, Jain, Ronak wrote: > > > Hi Dan, > > > > > > > -----Original Message----- > > > > From: Buddhabhatti, Jay > > > > Sent: Tuesday, February 27, 2024 3:25 PM > > > > To: Dan Carpenter ; > > > > haribabu.gattem@xilinx.com; Jain, Ronak > > > > Cc: Simek, Michal ; linux-arm- > > > > kernel@lists.infradead.org > > > > Subject: RE: [bug report] soc: xilinx: Fix for call trace due to the usage of > > > > smp_processor_id() > > > > > > > > +@Jain, Ronak > > > > > > > > > -----Original Message----- > > > > > From: Dan Carpenter > > > > > Sent: Thursday, February 1, 2024 5:50 PM > > > > > To: haribabu.gattem@xilinx.com > > > > > Cc: Buddhabhatti, Jay ; Simek, Michal > > > > > ; linux-arm-kernel@lists.infradead.org > > > > > Subject: [bug report] soc: xilinx: Fix for call trace due to the usage of > > > > > smp_processor_id() > > > > > > > > > > Hello HariBabu Gattem, > > > > > > > > > > The patch daed80ed0758: "soc: xilinx: Fix for call trace due to the usage > > of > > > > > smp_processor_id()" from Oct 26, 2023 (linux-next), leads to the > > following > > > > > Smatch static checker warning: > > > > > > > > > > kernel/irq/manage.c:2614 __request_percpu_irq() > > > > > warn: sleeping in atomic context > > > > > > > > > > drivers/soc/xilinx/xlnx_event_manager.c > > > > > 610 cpu = get_cpu(); > > > > > ^^^^^^^^^^^^^^^ > > > > > The patch adds get_cpu() which disables preemption. > > > > > > > > > > 611 per_cpu(cpu_number1, cpu) = cpu; > > > > > 612 ret = request_percpu_irq(virq_sgi, xlnx_event_handler, > > > > > "xlnx_event_mgmt", > > > > > ^^^^^^^^^^^^^^^^^^ > > > > > request_percpu_irq() does a sleeping allocation so it's a sleeping in > > atomic > > > > bug. > > > > > > > > > > 613 &cpu_number1); > > > > > 614 put_cpu(); > > > > > > > > > > > I am working on this issue, and I tried to reproduce the issue but I > > > couldn't. First, I tried enabling the below config flags for kernel > > > preemption and then ran the smatch command but didn't get the warning > > > you were mentioning. > > > > > > The configs I enabled, > > > CONFIG_DEBUG_ATOMIC_SLEEP=y > > > > This config would detect the issue at runtime. > > > > > CONFIG_PREEMPT_RT=y > > > CONFIG_PREEMPT=y > > > CONFIG_PREEMPT_COUNT=y > > > CONFIG_PREEMPTION=y > > > CONFIG_PREEMPT_RCU=y > > > CONFIG_DEBUG_PREEMPT=y > > > > > > The smatch command I ran, > > > ~/smatch/smatch_scripts/kchecker --spammy > > drivers/soc/xilinx/xlnx_event_manager.c > > > ~/smatch/smatch_scripts/kchecker --spammy kernel/irq/manage.c > > > make ARCH=arm64 CHECK="~/smatch/smatch -p=kernel" C=2 > > drivers/soc/xilinx/xlnx_event_manager.o > > > > > > Could you please help me with the config you used for this issue and > > > would be good if you could share the complete steps(the smatch > > > commands) to reproduce the issue. > > > > I'm sorry, to generate this warning you need to rebuild the cross > > function database a few times. Which is simple enough, but each time > > you rebuild the database takes something like 6 hours. > > > > smatch_scripts/build_kernel_data.sh > > > > Each time you rebuild it, it adds one more branch to the call trees. In > > this case building it twice would work I guess. Then it would be: > > ~/smatch/smatch_scripts/kchecker --spammy kernel/irq/manage.c > > > > That prints the warning quoted above and then I do: > > > > ~/smatch/smatch_data/db/smdb.py preempt __request_percpu_irq > > xlnx_event_init_sgi() <- disables preempt > > -> request_percpu_irq() > > -> __request_percpu_irq() > > > I tried the steps you suggested but didn't get the warning you reported. > > First, I tried to build a database using "smatch_scripts/build_kernel_data.sh" and then ran "~/smatch/smatch_scripts/kchecker --spammy kernel/irq/manage.c" multiple times but didn't encounter the original warning. Also, you mentioned that the building of the database takes around 6 hours to complete but for me, it took around 15 minutes for Xilinx internal repo and 1 hour for upstream repo i.e. linux-next. > > Let me describe the overall steps I followed, > > - Clone upstream linux-repo i.e. linux-next > - export ARCH=arm64 > - export CROSS_COMPILE="aarch64-linux-gnu-" > - make menuconfig (kept the default configs) > Or > - make xilinx_defconfig (Xilinx specific config) > - ~/smatch/smatch_scripts/build_kernel_data.sh > - wait for completion > - ~/smatch/smatch_scripts/kchecker --spammy kernel/irq/manage.c > Logs after running the kchecker > > CHECK scripts/mod/empty.c > CALL scripts/checksyscalls.sh > CHECK arch/arm64/kernel/vdso/vgettimeofday.c > CC kernel/irq/manage.o > CHECK kernel/irq/manage.c > kernel/irq/manage.c:583 irq_set_affinity_notifier() warn: 'old_notify' was already freed. > kernel/irq/manage.c:583 irq_set_affinity_notifier() warn: 'old_notify' was already freed. > kernel/irq/manage.c:583 irq_set_affinity_notifier() error: dereferencing freed memory 'old_notify' > kernel/irq/manage.c:2210 request_threaded_irq() warn: calling kfree() when 'action->secondary' is always NULL. > > Can you please review the overall steps I followed? Hm... That's strange. What happens if you type: ~/smatch/smatch_data/db/smdb.py preempt request_percpu_irq It should say that xlnx_event_init_sgi() calls it with preempt disabled. This command should work as well if the database has been rebuilt twice but evidently it doesn't. :/ ~/smatch/smatch_data/db/smdb.py preempt __request_percpu_irq You have CONFIG_PREEMPT_COUNT=y so Smatch should have all the information necessary to track this. The use after free warning is because Smatch assumes kref_put() will call the free function unless the refcount is incremented within the same function. On my system I don't get the 'action->secondary' warning because the cross function database has been built more... I would have thought that building the cross function database twice would silence that warning because the first build would add irq_setup_forced_threading() and the next one would add __setup_irq(). $ smdb.py return_states irq_setup_forced_threading | grep "secondary " kernel/irq/manage.c | irq_setup_forced_threading | 687 | 0| PARAM_ADD | 0 | $->secondary | 2784508726059343872 | $ smdb.py return_states __setup_irq | grep "secondary " kernel/irq/manage.c | __setup_irq | 756 | 0| PARAM_ADD | 2 | $->secondary | 0,4096-ptr_max | But to be honest, I hadn't realized that warning was published. I should delete it. Calling kfree() on a NULL is not a bug. regards, dan carpenter _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel