Received: by 2002:a05:6358:bb9e:b0:b9:5105:a5b4 with SMTP id df30csp788901rwb; Sat, 3 Sep 2022 02:51:22 -0700 (PDT) X-Google-Smtp-Source: AA6agR7F3k1qcr7OliN9KCZDu+OF1fhoFVvqRgIVOhto11rFs8pJb6FS7P+T9aKMteEPD4tHKHFg X-Received: by 2002:a05:6402:198:b0:442:da5a:6716 with SMTP id r24-20020a056402019800b00442da5a6716mr35801480edv.5.1662198682436; Sat, 03 Sep 2022 02:51:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662198682; cv=none; d=google.com; s=arc-20160816; b=nzFedPibTfZZechnv+aJW6Ibs0DM8aHd63WjPmHGyINb4i4p6IDnuW3eurqIRCbWXq Cm/3N7LQS9P0vCAk7PKT8k/aL6aRcVNMrC4aJh1yqqAsTta0yy0G18KvcR7/I7iyDE1P RhG5w9pMrO/uCQ+jRpSJIZ8u+CyiTSClIcXz+yNB2SVgjfs5PnO6SU5cO4/joysfeDs9 Oc4Us0X/rVc7cOLuZPdHJn0nERn3cEFEE2t/h0VmjH/H2yaFcSIQO30qO9RgXOOdO/YP NfYTAKhe08e0aquVtkLMQJEg+r9Mq59g4aKFeWBGIl3MFGIwoTLb77k3FQnxapNqOgiH PCzA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=dccgenCLdaldLGNe2nW0rKf95nJyRR69M0nwfddNDug=; b=elM9g2kViPsyK0fw4bjUf8vjCbhvRynen3az3TgC6T6pXrHQgedZG6igQEuVGFg67x 1B08vS9CL+NanoBMCytd3mFg8WGnkLSBhU7wTQGotgC+uo2O0987/QvdnW6iNG8ECzvh 4ZGknYMe+QpluR1LuUWFA0jy19xSZKuT86mnGly6GwitVfWocYo00RvAz3WD97ShmRlW ydbtpQ6N1XIKtmEowNFa2JlJvLFxIh1//tzAj8LrmgPAtkHPA4eregb3EJ+XSb4flBp7 AJEvcJNZnS2FE86uQ1Z2hsidaB73wvjGNLCgdsceE2cR2CbQ0I3bXj3Ma6sMXhBYeF3x DdfA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b=HJ9It8VP; 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; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=mediatek.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id hq37-20020a1709073f2500b0073dd2106f6dsi2140015ejc.11.2022.09.03.02.50.48; Sat, 03 Sep 2022 02:51:22 -0700 (PDT) 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; dkim=pass header.i=@mediatek.com header.s=dk header.b=HJ9It8VP; 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; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=mediatek.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232790AbiICJeg (ORCPT + 99 others); Sat, 3 Sep 2022 05:34:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58666 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231535AbiICJea (ORCPT ); Sat, 3 Sep 2022 05:34:30 -0400 Received: from mailgw01.mediatek.com (unknown [60.244.123.138]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CEDC8DF9; Sat, 3 Sep 2022 02:34:24 -0700 (PDT) X-UUID: b80dc9603d70496ca9d518010329f5df-20220903 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mediatek.com; s=dk; h=Content-Type:MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:CC:To:From; bh=dccgenCLdaldLGNe2nW0rKf95nJyRR69M0nwfddNDug=; b=HJ9It8VPnfLqwxBnGc71fIZTmyT0Nd3VRv3JmVYC6B5+20MBYv9bKdvEJj64EsOF9VlA/qrKRlQe3Kr849no+MCr0mJM0sQjVE5Puoc5ITTQVQwBGFLCh2vPsHNac6BgBDoaPV/uS0xep/4ji5rl4Nx+++BAO8ImRnNj9tkXh0s=; X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.10,REQID:6d4da491-4928-46a9-b5c4-67201287da1c,OB:0,L OB:0,IP:0,URL:0,TC:0,Content:-25,EDM:0,RT:0,SF:95,FILE:0,BULK:0,RULE:Relea se_Ham,ACTION:release,TS:70 X-CID-INFO: VERSION:1.1.10,REQID:6d4da491-4928-46a9-b5c4-67201287da1c,OB:0,LOB :0,IP:0,URL:0,TC:0,Content:-25,EDM:0,RT:0,SF:95,FILE:0,BULK:0,RULE:Spam_GS 981B3D,ACTION:quarantine,TS:70 X-CID-META: VersionHash:84eae18,CLOUDID:714b86d0-20bd-4e5e-ace8-00692b7ab380,C OID:171e9c4a6f6e,Recheck:0,SF:28|17|19|48,TC:nil,Content:0,EDM:-3,IP:nil,U RL:0,File:nil,Bulk:nil,QS:nil,BEC:nil,COL:0 X-UUID: b80dc9603d70496ca9d518010329f5df-20220903 Received: from mtkmbs10n1.mediatek.inc [(172.21.101.34)] by mailgw01.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 1384698886; Sat, 03 Sep 2022 17:34:19 +0800 Received: from mtkmbs11n2.mediatek.inc (172.21.101.187) by mtkmbs11n2.mediatek.inc (172.21.101.187) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.792.15; Sat, 3 Sep 2022 17:34:17 +0800 Received: from mtksdccf07.mediatek.inc (172.21.84.99) by mtkmbs11n2.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.2.792.15 via Frontend Transport; Sat, 3 Sep 2022 17:34:17 +0800 From: Lecopzer Chen To: , , , , CC: , , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v7 3/6] kernel/watchdog_hld: Ensure CPU-bound context when creating hardlockup detector event Date: Sat, 3 Sep 2022 17:34:12 +0800 Message-ID: <20220903093415.15850-4-lecopzer.chen@mediatek.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20220903093415.15850-1-lecopzer.chen@mediatek.com> References: <20220903093415.15850-1-lecopzer.chen@mediatek.com> MIME-Version: 1.0 Content-Type: text/plain X-MTK: N X-Spam-Status: No, score=-1.6 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS, T_SCC_BODY_TEXT_LINE,UNPARSEABLE_RELAY,URIBL_CSS autolearn=no 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 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 --- 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 247bf0b1582c..96b717205952 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); -- 2.34.1