Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp833060pxb; Tue, 3 Nov 2020 13:52:10 -0800 (PST) X-Google-Smtp-Source: ABdhPJzXro7tGVUHUIXaa79JsDsoq4bE09kuGhyfZEO6kCYofvuc5P51xnpEZTaw576nfPzfSNco X-Received: by 2002:aa7:d709:: with SMTP id t9mr9136937edq.305.1604440329951; Tue, 03 Nov 2020 13:52:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604440329; cv=none; d=google.com; s=arc-20160816; b=WKXCz063PreoNsgVNn4i5OR6qsbk9u8mJkO0kT2AvSmL8SsCEknfltgVLKqLIujQPf iRutB4omSFqpqCW8nVf+7VVjtjrIy017SN1tH/rV+I1Di/4ZqlN5OtNwsTIySj+f7B9v 1jYgVtxlUDpDy6eUkZulHjjkLJGTlc2xN0PxOJbGNmBnNdrt1LY9MaLGiQYbzWDEkZer hGBZ0zp4Jy98bkWa+Xz20u6I3YtFdghyenJenowMERafbN/kNk4marc8SPetze3LOSVU 5rfo7TQUXFLoDE5hf7f+2/m+rfM+vHdDQ+EcOzKkbftjQ5XBt/dRLkMXHA4/k1FrA9n5 wl5g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=fbPOUO2q/hak6mHSov9/mQ+Eetly7Ah8bXQ3cr+J7AQ=; b=u9JS0CW6H6vLmiNP//JEvEwt0gIxHItv7iBaE9I5arJV6eqtWKPFNepTR2oa0nzCZy /bsiEYNyToGE3P2l70ZuMqQ5ktzxAOIaHUKc0P5PbA1Z/DKaK2pUIFHJfIe6D+/+t3Xq NdwF/Ia5+uxkzUr1JMkRbxS15qAHnqzen/HJyjZIw9e66XpCw52L2fDdV40yGA9w9pYB GxEZ+kLB4U7shgUe9rb4Wp8DeJ2vTHdYqJplMU3kVuy0d7ra/KzJeE8HZ8048rn75mih SIt8P+AVWvE48yiUq3fq8kdZdIOV0c34PfiJ4uxWyYMqH9s8v7cbjSTMWRwBrZSE4NH2 7pQQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=2VQtO8zZ; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id j12si13788045edy.584.2020.11.03.13.51.47; Tue, 03 Nov 2020 13:52:09 -0800 (PST) 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=2VQtO8zZ; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731624AbgKCUto (ORCPT + 99 others); Tue, 3 Nov 2020 15:49:44 -0500 Received: from mail.kernel.org ([198.145.29.99]:42772 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731607AbgKCUtg (ORCPT ); Tue, 3 Nov 2020 15:49:36 -0500 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id C73A922404; Tue, 3 Nov 2020 20:49:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1604436576; bh=1C8r9xI3AEIUJPKi37mcrxU88njAYtT2vNbfJ4mxwQU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=2VQtO8zZ7B9UfCsRYMy6I/AsU+ZD/IX4d0soDJVreqc5B3skjiUDzVwiBQitxF0iq OPAJC0J+1yvzIyu4w88YMsrOxD35n+9vvN0FP1J0jatmqltNUFNWrRV7ph8UurbZjU lUs5W3cHuwHAgmofg3aBp7mvrYKks4U3acGOX2Q0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Vineet Gupta Subject: [PATCH 5.9 311/391] ARC: perf: redo the pct irq missing in device-tree handling Date: Tue, 3 Nov 2020 21:36:02 +0100 Message-Id: <20201103203408.096030270@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201103203348.153465465@linuxfoundation.org> References: <20201103203348.153465465@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Vineet Gupta commit 8c42a5c02bec6c7eccf08957be3c6c8fccf9790b upstream. commit feb92d7d3813456c11dce21 "(ARC: perf: don't bail setup if pct irq missing in device-tree)" introduced a silly brown-paper bag bug: The assignment and comparison in an if statement were not bracketed correctly leaving the order of evaluation undefined. | | if (has_interrupts && (irq = platform_get_irq(pdev, 0) >= 0)) { | ^^^ ^^^^ And given such a chance, the compiler will bite you hard, fully entitled to generating this piece of beauty: | | # if (has_interrupts && (irq = platform_get_irq(pdev, 0) >= 0)) { | | bl.d @platform_get_irq <-- irq returned in r0 | | setge r2, r0, 0 <-- r2 is bool 1 or 0 if irq >= 0 true/false | brlt.d r0, 0, @.L114 | | st_s r2,[sp] <-- irq saved is bool 1 or 0, not actual return val | st 1,[r3,160] # arc_pmu.18_29->irq <-- drops bool and assumes 1 | | # return __request_percpu_irq(irq, handler, 0, | | bl.d @__request_percpu_irq; | mov_s r0,1 <-- drops even bool and assumes 1 which fails With the snafu fixed, everything is as expected. | bl.d @platform_get_irq <-- returns irq in r0 | | mov_s r2,r0 | brlt.d r2, 0, @.L112 | | st_s r0,[sp] <-- irq isaved is actual return value above | st r0,[r13,160] #arc_pmu.18_27->irq | | bl.d @__request_percpu_irq <-- r0 unchanged so actual irq returned | add r4,r4,r12 #, tmp363, __ptr Cc: Signed-off-by: Vineet Gupta Signed-off-by: Greg Kroah-Hartman --- arch/arc/kernel/perf_event.c | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) --- a/arch/arc/kernel/perf_event.c +++ b/arch/arc/kernel/perf_event.c @@ -562,7 +562,7 @@ static int arc_pmu_device_probe(struct p { struct arc_reg_pct_build pct_bcr; struct arc_reg_cc_build cc_bcr; - int i, has_interrupts, irq; + int i, has_interrupts, irq = -1; int counter_size; /* in bits */ union cc_name { @@ -637,18 +637,27 @@ static int arc_pmu_device_probe(struct p .attr_groups = arc_pmu->attr_groups, }; - if (has_interrupts && (irq = platform_get_irq(pdev, 0) >= 0)) { + if (has_interrupts) { + irq = platform_get_irq(pdev, 0); + if (irq >= 0) { + int ret; + + arc_pmu->irq = irq; + + /* intc map function ensures irq_set_percpu_devid() called */ + ret = request_percpu_irq(irq, arc_pmu_intr, "ARC perf counters", + this_cpu_ptr(&arc_pmu_cpu)); + + if (!ret) + on_each_cpu(arc_cpu_pmu_irq_init, &irq, 1); + else + irq = -1; + } - arc_pmu->irq = irq; - - /* intc map function ensures irq_set_percpu_devid() called */ - request_percpu_irq(irq, arc_pmu_intr, "ARC perf counters", - this_cpu_ptr(&arc_pmu_cpu)); + } - on_each_cpu(arc_cpu_pmu_irq_init, &irq, 1); - } else { + if (irq == -1) arc_pmu->pmu.capabilities |= PERF_PMU_CAP_NO_INTERRUPT; - } /* * perf parser doesn't really like '-' symbol in events name, so let's