Received: by 10.213.65.68 with SMTP id h4csp563860imn; Tue, 13 Mar 2018 13:12:02 -0700 (PDT) X-Google-Smtp-Source: AG47ELt2By+dDhckMGbrp5cxfOAfuGWVKDmgT77zabvsnc1n+Snj1aMa266Qe5s8S4B+89A++2BW X-Received: by 10.98.194.87 with SMTP id l84mr1800555pfg.6.1520971922691; Tue, 13 Mar 2018 13:12:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1520971922; cv=none; d=google.com; s=arc-20160816; b=aAG1udvP6f7FtLYoui9iRRenOt0IxZYphq9VA1Q9GfRsPu6sKr5KAp9oovIzJjTNx6 WjhQWWkwBjwth5O9VVKfksKsMZ7RC32NA2FVos2bHnWNB4eLdDsKjULVjFzClBZh6pRA zAsM1MMNHF3b6kNThHfghRGge8AYLub/KGIqyyr4Zkv4+PzT44BFn48r5nWb8YY5q3xe igorM2SM1eNHAMFMUa7EW3gNvtiqvvuUa8i00KZ9G8fnR8iBx4Yv/lplIKUfSEaRTuZJ CI03YYN2HrTflumQcxsNuacPdStF6IuvzbF5HXQECY1k5On/N+fmQfZ6bDsLy8zokAAK 25rw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature :arc-authentication-results; bh=pHMq1rj40OZRg5pbAWZlQA5tLvdO2BS7XnUYA+jkWKA=; b=TdcnG7Z1GpBkQdcQJc5nKxyfJ4108R1YfGn5TWj+LtzrMuWPE89hc0zXRd2q42vRtL 57lH6SVXlFGP8ftlRoOnCMEw88ZKKzXibvBqroxpdBchEN8kLVGu0CPLWCp8fGOL1dBx 1TomLxhSLpyCGr2uYIzFl8BPUJrHMPKV7UFf/VDAX7MHr5i04He69ud2IPiC2UP/dgGG GJEvb42zIWJHJqOHNdmQ9PwqlPhNcFm2vyEgwGfZwgvDHwfdcfVGPmW0v4K2gIkOvTNp WmTJDeWTGejp1S5QMyQYgmYnuP9SaY9Px+dgnrrNBL3/HUbEsQG5ifP8No+LwTdb3ufM ZIKg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=jCR2uBb/; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w66si709586pfi.23.2018.03.13.13.11.47; Tue, 13 Mar 2018 13:12:02 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=jCR2uBb/; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932687AbeCMUKZ (ORCPT + 99 others); Tue, 13 Mar 2018 16:10:25 -0400 Received: from mail-io0-f194.google.com ([209.85.223.194]:40125 "EHLO mail-io0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932257AbeCMUKY (ORCPT ); Tue, 13 Mar 2018 16:10:24 -0400 Received: by mail-io0-f194.google.com with SMTP id v6so1590332iog.7 for ; Tue, 13 Mar 2018 13:10:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc; bh=pHMq1rj40OZRg5pbAWZlQA5tLvdO2BS7XnUYA+jkWKA=; b=jCR2uBb/OFPT+il218dSOhs8FUvvho6HnvrOab9VXuIJnhHJHw75J07zZxAwtXozck /GjzCHklByqoFAz0hAS+KMXqMTBanbbSdwHgN/5oV6f71pRPteUGpGehbAIOT9aSOPFD PpGKpgg3cgH2TwIIMl05D59nG4IA5o5fs0WFB5PvcwytChN6ruZLwShTUpnKS7xOr+8C r8wKGYXrI0w07N54AUo8IXeDcM2vw4zoLz+dcGSRkHM4eW9HJRM7DU3zpCuWWU24u1dd zUvrdsdqswtkmoxuoUTLVrM0NR21KM8V3oUzOmwHe9ofh0hWNfEPxE5MJa2xOdM/Tt6S LtQw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:sender:in-reply-to:references:from :date:message-id:subject:to:cc; bh=pHMq1rj40OZRg5pbAWZlQA5tLvdO2BS7XnUYA+jkWKA=; b=T0MQn2AveaS5L6QaRwG8VHY1cnSJhL/KpuDjOFQCSkM4VXMBfyifg9So74ByKN7Y46 Khnlhk3kDy05iCdAMI3jZ81cjde4ksn85Swpa9hlEbxaYWGCRgCvZ8QzmLpCLhqmyr/d WuyyStx1RTD7/7ANyR54gadPusugAiw51Hmncl6SmO4nbJ6cMA+54G8Gqr32qzkM0OpS eCCdEGAYgZNj8ZCzA3TQcxA8sX5NE1d48yoZxdG19W3qW2IdGDfZQNCSWjWqH2vXGGHW aQLlM5VcFan2qyrxsm+Kbh3TEJ+YZW4BvUVvP+6Z9F27nLscWlE9XoogS9/eEwFVsU+z Tz0g== X-Gm-Message-State: AElRT7G38tXDwedB6lAJ5gbVLQspBTDT2uqzEM4EDz9/b/RLIKtpeE45 9iIVmNwzQteDWMsnfYacPUq8J1jXSmlKnOZSOiY= X-Received: by 10.107.97.21 with SMTP id v21mr2122093iob.22.1520971823196; Tue, 13 Mar 2018 13:10:23 -0700 (PDT) MIME-Version: 1.0 Received: by 10.79.34.71 with HTTP; Tue, 13 Mar 2018 13:10:22 -0700 (PDT) In-Reply-To: References: <20180313161952.552083-1-arnd@arndb.de> From: Arnd Bergmann Date: Tue, 13 Mar 2018 21:10:22 +0100 X-Google-Sender-Auth: 0i9L1T7zZ70MjjH0n4fRRW1ZPas Message-ID: Subject: Re: [Intel-gfx] [PATCH] [v2] drm/i915/pmu: avoid -Wmaybe-uninitialized warning To: Tvrtko Ursulin Cc: Jani Nikula , Joonas Lahtinen , Rodrigo Vivi , David Airlie , Intel Graphics , Linux Kernel Mailing List , dri-devel Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Mar 13, 2018 at 6:46 PM, Tvrtko Ursulin wrote: > > On 13/03/2018 16:19, Arnd Bergmann wrote: >> >> The conditional spinlock confuses gcc into thinking the 'flags' value >> might contain uninitialized data: >> >> drivers/gpu/drm/i915/i915_pmu.c: In function '__i915_pmu_event_read': >> arch/x86/include/asm/paravirt_types.h:573:3: error: 'flags' may be used >> uninitialized in this function [-Werror=maybe-uninitialized] > > > Hm, how does paravirt_types.h comes into the picture? spin_unlock_irqrestore() calls arch_local_irq_restore() >> The code is correct, but it's easy to see how the compiler gets confused >> here. This avoids the problem by pulling the lock outside of the function >> into its only caller. > > > Is it specific gcc version, specific options, or specific kernel config that > this happens? Not gcc version specific (same result with gcc-4.9 through 8, didn't test earlier versions that are currently broken). > Strange that it hasn't been seen so far. It seems to be a relatively rare 'randconfig' combination. Looking at the preprocessed sources, I find: static u64 get_rc6(struct drm_i915_private *i915, bool locked) { unsigned long flags; u64 val; if (intel_runtime_pm_get_if_in_use(i915)) { val = __get_rc6(i915); intel_runtime_pm_put(i915); if (!locked) do { do { ({ unsigned long __dummy; typeof(flags) __dummy2; (void)(&__dummy == &__dummy2); 1; }); do { do { do { ({ unsigned long __dummy; typeof(flags) __dummy2; (void)(&__dummy == &__dummy2); 1; }); flags = arch_local_irq_save(); } while (0); trace_hardirqs_off(); } while (0); do { __asm__ __volatile__("": : :"memory"); do { (void)0; (void)(spinlock_check(&i915->pmu.lock)); } while (0); } while (0); } while (0); } while (0); } while (0); if (val >= i915->pmu.sample[__I915_SAMPLE_RC6_ESTIMATED].cur) { i915->pmu.sample[__I915_SAMPLE_RC6_ESTIMATED].cur = 0; i915->pmu.sample[__I915_SAMPLE_RC6].cur = val; } else { val = i915->pmu.sample[__I915_SAMPLE_RC6_ESTIMATED].cur; } if (!locked) spin_unlock_irqrestore(&i915->pmu.lock, flags); } else { struct pci_dev *pdev = i915->drm.pdev; struct device *kdev = &pdev->dev; unsigned long flags2; # 455 "/git/arm-soc/drivers/gpu/drm/i915/i915_pmu.c" if (!locked) do { do { ({ unsigned long __dummy; typeof(flags) __dummy2; (void)(&__dummy == &__dummy2); 1; }); do { do { do { ({ unsigned long __dummy; typeof(flags) __dummy2; (void)(&__dummy == &__dummy2); 1; }); flags = arch_local_irq_save(); } while (0); trace_hardirqs_off(); } while (0); do { __asm__ __volatile__("": : :"memory"); do { (void)0; (void)(spinlock_check(&i915->pmu.lock)); } while (0); } while (0); } while (0); } while (0); } while (0); do { do { ({ unsigned long __dummy; typeof(flags2) __dummy2; (void)(&__dummy == &__dummy2); 1; }); do { do { do { ({ unsigned long __dummy; typeof(flags2) __dummy2; (void)(&__dummy == &__dummy2); 1; }); flags2 = arch_local_irq_save(); } while (0); trace_hardirqs_off(); } while (0); do { __asm__ __volatile__("": : :"memory"); do { (void)0; (void)(spinlock_check(&kdev->power.lock)); } while (0); } while (0); } while (0); } while (0); } while (0); if (!i915->pmu.sample[__I915_SAMPLE_RC6_ESTIMATED].cur) i915->pmu.suspended_jiffies_last = kdev->power.suspended_jiffies; val = kdev->power.suspended_jiffies - i915->pmu.suspended_jiffies_last; val += jiffies - kdev->power.accounting_timestamp; spin_unlock_irqrestore(&kdev->power.lock, flags2); val = jiffies_to_nsecs(val); val += i915->pmu.sample[__I915_SAMPLE_RC6].cur; i915->pmu.sample[__I915_SAMPLE_RC6_ESTIMATED].cur = val; if (!locked) spin_unlock_irqrestore(&i915->pmu.lock, flags); } return val; } so it seems that the spin_lock_irqsave() is completely inlined through a macro while the unlock is not, and the lock contains a memory barrier (among other things) that might tell the compiler that the state of the 'locked' flag could changed underneath it. It could also be the problem that arch_local_irq_restore() uses __builtin_expect() in PVOP_TEST_NULL(op) when CONFIG_PARAVIRT_DEBUG is enabled, see static inline __attribute__((unused)) __attribute__((no_instrument_function)) __attribute__((no_instrument_function)) void arch_local_irq_restore(unsigned long f) { ({ unsigned long __eax = __eax, __edx = __edx, __ecx = __ecx;; do { if (__builtin_expect(!!(pv_irq_ops.restore_fl.func == ((void *)0)), 0)) do { do { asm volatile("1:\t" ".byte 0x0f, 0x0b" "\n" ".pushsection __bug_table,\"aw\"\n" "2:\t" ".long " "1b" "\t# bug_entry::bug_addr\n" "\t" ".long " "%c0" "\t# bug_entry::file\n" "\t.word %c1" "\t# bug_entry::line\n" "\t.word %c2" "\t# bug_entry::flags\n" "\t.org 2b+%c3\n" ".popsection" : : "i" ("/git/arm-soc/arch/x86/include/asm/paravirt.h"), "i" (783), "i" (0), "i" (sizeof(struct bug_entry))); } while (0); do { ; asm volatile(""); __builtin_unreachable(); } while (0); } while (0); } while (0); asm volatile("" "771:\n\t" "999:\n\t" ".pushsection .discard.retpoline_safe\n\t" " " ".long" " " " 999b\n\t" ".popsection\n\t" "call *%c[paravirt_opptr];" "\n" "772:\n" ".pushsection .parainstructions,\"a\"\n" " " ".balign 4" " " "\n" " " ".long" " " " 771b\n" " .byte " "%c[paravirt_typenum]" "\n" " .byte 772b-771b\n" " .short " "%c[paravirt_clobber]" "\n" ".popsection\n" "" : "=a" (__eax), "=d" (__edx), "+r" (current_stack_pointer) : [paravirt_typenum] "i" ((__builtin_offsetof(struct paravirt_patch_template, pv_irq_ops.restore_fl.func) / sizeof(void *))), [paravirt_opptr] "i" (&(pv_irq_ops.restore_fl.func)), [paravirt_clobber] "i" (((1 << 0) | (1 << 2))), "a" ((unsigned long)(f)) : "memory", "cc" ); }); } this seems to frequently confuse gcc, and turning off that NULL check avoids the warning as well. If you want to analyze it further, see https://pastebin.com/T2yLRqU5 for the .config file, but I'm pretty sure this is a known problem with gcc that happens to be very hard to fix. Arnd