From patchwork Fri May 19 17:18:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Doug Anderson X-Patchwork-Id: 13248740 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 4E5FCC7EE2D for ; Fri, 19 May 2023 18:31:04 +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:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=7i4y5SZULh3JrbmXcmbjcm5pLTeqj4y84n4C7+Nz/QI=; b=rqkXAvxG2WCdZR NJJXMSBQ1Fc9VBPcks6qOOS9WdPEzbkGZh0T+eZyyc1Y0peRmM5dNCvFTb4+a0z0+NZveaxrheSeV GFG2eaNdhpMSfhSKjbfUGln0o9J7JKJKp0dxTK+OE5XymVQBWJuaUfr4KcLl+hOXX5b0y6pqFYyLq FkWwDl8LIaEsU6nFte8iKdUIvQA+oyh1ZCiVXA5sXl9wGveXrv7y8v/fUwTUAuJir3tZee3N3Z8RX wDWux/09TFOF+a5LnENbvqRdSOvV2EHAD/+FXn2S40BFri8PR0HueT1F6QBS0lzauzTBjhPzkYHc5 TH9GahcYxLYgLyNMqhaA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1q04sU-00Gz4L-08; Fri, 19 May 2023 18:30:58 +0000 Received: from desiato.infradead.org ([90.155.92.199]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1q03mj-00GqHN-2P for linux-arm-kernel@bombadil.infradead.org; Fri, 19 May 2023 17:20:57 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Transfer-Encoding:MIME-Version :References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=FtWewuf5QmwEoMrp2heDkMSCLJmOGom4IGUit5Qgo0E=; b=dulMo6KJ2sYE8CTJtmeeoH2lyw UKj3uVM92/c0t7o9H1HaUEpnlFMDqn8t+kPK1aexoMvJS/FCmtc9sabgGni9RuH9xLw0mXm0GOc8g m8DpZlH+GEBUljNJODbyQRa/iR6k4MAo+Oob8MsaLlmsB2YkZcepBrow6+hes0d6/DAKWckYU5ZMb h1IqLAkoSUtlgmXth3TYlPeSbSrgZ+CAMVaRPXvCW/kgAdwvamL6uL7iN7GE8OLELQnuRUlav/cnD 8OinK4za3jpPUnvOxP5EvSrOGEDkL+rK6lCbDMp0Jt9GmnXypAp1OpwdfddY144FZQT8wFwzpEc/g 9odnHEUw==; Received: from mail-pj1-x1034.google.com ([2607:f8b0:4864:20::1034]) by desiato.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1q03mf-00Fxqo-2R for linux-arm-kernel@lists.infradead.org; Fri, 19 May 2023 17:20:55 +0000 Received: by mail-pj1-x1034.google.com with SMTP id 98e67ed59e1d1-2533ed4f1dcso2484143a91.1 for ; Fri, 19 May 2023 10:20:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1684516852; x=1687108852; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=FtWewuf5QmwEoMrp2heDkMSCLJmOGom4IGUit5Qgo0E=; b=j+odxpthVu1r88NdkoBBLHCCZHxAILIoHvQRbo0BYOGU+caYf7G5t8oS+/sutWAb06 0/3y15G9V4rAsqVAUplESKZYanhl/sYpq1QJSiIK9RoB3l+LfJCDMdhxu4jHA6BiwsiY AK/xV8IKz/okxdjnmVpntud8VcNkXW2UnoYD8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684516852; x=1687108852; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=FtWewuf5QmwEoMrp2heDkMSCLJmOGom4IGUit5Qgo0E=; b=Ict4V8256RfH1U16pVzKc5dRnPLDI0DlfOyF1e8HlHP0IM/g4kA7qCQfTrRGxudRnk f9DDLEQHjFgBzXUPo+5idyAxdTEAobZQYAedgmW1fVbXUpTJEwqoi1JPQ23BxLcLuefa ZxfX7kn+HT0szOfrVgoWWFFearvStdupTibHA85YyzW0N47haxEyRNuVLhH6U2M2cKEq Y6qUvKtdDkNhwOyj0etF+4AQ/gfssXr11B/NfIsBgP2uKDkf9JgxIOLlsMBNSc3tLXj+ LSZ7KDPpvC7TO3R/D3U+XQxpSLH4CWv6U+x3RCnL3p87qLAprcLma3HqCxmNdZmV40ov /WFw== X-Gm-Message-State: AC+VfDx+w0jWJqgYxJhEUVv4ftIrlWut3QkZyhboXiPNCvhY2fdbCZI1 iOG0p0WEV+C15d1QFFlcnS3tSg== X-Google-Smtp-Source: ACHHUZ7LqONQqbo1f32uROMOmBD1YwxsC0hUaPEyZAYzC5eD1qH0xMLrKy1PKFruL4ixUcNA0i2quA== X-Received: by 2002:a17:90a:8b0e:b0:253:8796:3322 with SMTP id y14-20020a17090a8b0e00b0025387963322mr1959543pjn.27.1684516851906; Fri, 19 May 2023 10:20:51 -0700 (PDT) Received: from tictac2.mtv.corp.google.com ([2620:15c:9d:2:9b89:2dd0:d160:429d]) by smtp.gmail.com with ESMTPSA id gj19-20020a17090b109300b0024e4f169931sm1763835pjb.2.2023.05.19.10.20.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 May 2023 10:20:51 -0700 (PDT) From: Douglas Anderson To: Petr Mladek , Andrew Morton Cc: Matthias Kaehlcke , kgdb-bugreport@lists.sourceforge.net, Stephane Eranian , mpe@ellerman.id.au, Tzung-Bi Shih , Daniel Thompson , Mark Rutland , linuxppc-dev@lists.ozlabs.org, Sumit Garg , npiggin@gmail.com, davem@davemloft.net, Marc Zyngier , Stephen Boyd , sparclinux@vger.kernel.org, christophe.leroy@csgroup.eu, Catalin Marinas , ravi.v.shankar@intel.com, Randy Dunlap , Pingfan Liu , Guenter Roeck , Lecopzer Chen , Ian Rogers , ito-yuichi@fujitsu.com, ricardo.neri@intel.com, linux-arm-kernel@lists.infradead.org, linux-perf-users@vger.kernel.org, Will Deacon , Chen-Yu Tsai , linux-kernel@vger.kernel.org, Masayoshi Mizuma , Andi Kleen , Douglas Anderson Subject: [PATCH v5 05/18] watchdog/perf: Ensure CPU-bound context when creating hardlockup detector event Date: Fri, 19 May 2023 10:18:29 -0700 Message-ID: <20230519101840.v5.5.I654063e53782b11d53e736a8ad4897ffd207406a@changeid> X-Mailer: git-send-email 2.40.1.698.g37aff9b760-goog In-Reply-To: <20230519101840.v5.18.Ia44852044cdcb074f387e80df6b45e892965d4a1@changeid> References: <20230519101840.v5.18.Ia44852044cdcb074f387e80df6b45e892965d4a1@changeid> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230519_182053_887011_CFC3B49B X-CRM114-Status: GOOD ( 18.19 ) 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: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Pingfan Liu hardlockup_detector_event_create() should create perf_event on the current CPU. Preemption could not get disabled because perf_event_create_kernel_counter() allocates memory. Instead, the CPU locality is achieved by processing the code in a per-CPU bound kthread. Add a check to prevent mistakes when calling the code in another code path. Signed-off-by: Pingfan Liu Co-developed-by: Lecopzer Chen Signed-off-by: Lecopzer Chen Reviewed-by: Petr Mladek Signed-off-by: Douglas Anderson --- I yanked this patch from the mailing lists [1] into my series just to make it easier to avoid conflicts between my series and the one adding the arm64 perf hardlockup detector, in case someone wanted to test them both together. This is a nice cleanup and could land together with the rest of my series if that makes sense. I changed the patch prefix to match others in my series. [1] https://lore.kernel.org/r/20220903093415.15850-4-lecopzer.chen@mediatek.com/ (no changes since v4) Changes in v4: - Pulled ("Ensure CPU-bound context when creating ...") into my series for v4. kernel/watchdog_hld.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/kernel/watchdog_hld.c b/kernel/watchdog_hld.c index 1e8a49dc956e..2125b09e09d7 100644 --- a/kernel/watchdog_hld.c +++ b/kernel/watchdog_hld.c @@ -165,10 +165,16 @@ static void watchdog_overflow_callback(struct perf_event *event, static int hardlockup_detector_event_create(void) { - unsigned int cpu = smp_processor_id(); + unsigned int cpu; struct perf_event_attr *wd_attr; struct perf_event *evt; + /* + * Preemption is not disabled because memory will be allocated. + * Ensure CPU-locality by calling this in per-CPU kthread. + */ + WARN_ON(!is_percpu_thread()); + cpu = raw_smp_processor_id(); wd_attr = &wd_hw_attr; wd_attr->sample_period = hw_nmi_get_sample_period(watchdog_thresh);