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: 96539 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1397946vqo; Fri, 19 May 2023 10:22:57 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7czOBf9iibvP4SbVRrLGBG+5MwGVdmHcsXKO99iJRFmRxjSj4yGjMQENL8wLOBcQ4PJFwM X-Received: by 2002:a17:902:b705:b0:1a9:20d6:3c3f with SMTP id d5-20020a170902b70500b001a920d63c3fmr3181253pls.55.1684516975635; Fri, 19 May 2023 10:22:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684516975; cv=none; d=google.com; s=arc-20160816; b=kXmRrNPt4JPuTz8wYQ9CTw09PyWE7LjxzklxuqP56r6n6qN2u0XjKzsAindr7DWpMf gQSF2Woym4Dh3fKpbDAyHVu/DWajuNfQYj30l7ZdG+1qIcuFU4iG2jf5+CbNdxZlW2GN Kgz1RFrK2gDEUUoZM4vaNn2FBsuwTfPIO44lg6vnGJhylDcCDgyDkX/U7Htu/2YA68Vf om/6Vz+uEEltWmUpiyROx9gMwwaWioIuTCV5qr+oWwErMxmjK6YkG3GpNAAt17mJNagW QTpOLMV17RkX5cdQmTXIxsIq89kRLGuc0oDc93SO1pjvxU7N3nLUUOxSvCJTbt4dQmOY KHZg== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=FtWewuf5QmwEoMrp2heDkMSCLJmOGom4IGUit5Qgo0E=; b=y+rzo8HaPP76W+n9ocioubBMu8RPWJYitTJCtXfwWkCrA2Tiz821P+/U1zVCgWq9Nh k4lbV+IC+S2SvFixj904/Z9d/bpKWe5nUUocKyb8VlLaBvdc1Mch1gLnFJeQnUpJu5Kt kKfoJZTJIY8WnTpTxUdOVU1i7b9MhHtz6BlRKhRxWjQxrXHa+HItQ36N3UM0N6pNq7h5 Vs9LHWHMFjzZB8dIldMnreXTbpIlxBF7y6nxO/m9guYBccPJiJKVfvQ6RehsJIDsXaS4 XthmnopehAD7vat8IcOfO0LzR+hRm9wKYbAdUwA+0IhNsAtFDUMtSih7ECekdK4meEht O7Eg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=j+odxpth; 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=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a10-20020a170902ee8a00b001aaffa9923asi3716760pld.306.2023.05.19.10.22.37; Fri, 19 May 2023 10:22:55 -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=@chromium.org header.s=google header.b=j+odxpth; 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=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230049AbjESRVM (ORCPT + 99 others); Fri, 19 May 2023 13:21:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59250 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230072AbjESRU4 (ORCPT ); Fri, 19 May 2023 13:20:56 -0400 Received: from mail-pj1-x1034.google.com (mail-pj1-x1034.google.com [IPv6:2607:f8b0:4864:20::1034]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 65E8D19F for ; Fri, 19 May 2023 10:20:52 -0700 (PDT) Received: by mail-pj1-x1034.google.com with SMTP id 98e67ed59e1d1-2537909d28cso909108a91.0 for ; Fri, 19 May 2023 10:20:52 -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=lyWQ51fEe8FD5OsVOMwRMViMwJ2Gjq4jWm7MJIkLriTGUkbF3a1p3kf55Lzah/5IkC jJlIkMX7A8huNJW18pZ8iCO+aEObkWhS4dVM4a5sOx/5LEOtW/gCzw5qUZVa4KE14l8h ZXFCBWRbgz342rZpz6lq6r7kRa0OePDX7kTaLWu8r/AdjN7muzvtdE5Q93gqQfcGriJi Xf/eeyu7Q67e2cyQTmU7x59WnX/WXymnMyB/IvhsILNwX+QsPxUHr6BEnd/MEuLa552G hyjSEavhN63egBx9eDkRr9Fb3rfCSmmVeVZ64N6HThh1xHeGp3lB3WBRJ+8+HFGfH915 D8OA== X-Gm-Message-State: AC+VfDx6hzBtIfw/akprS+mnLuSvIvKKLK2hMH4i6zbJ20iSM5DAWLOT cUgA3dT7o/CFOAfDa2NpuS50LA== 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-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=unavailable 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1766344071817925364?= X-GMAIL-MSGID: =?utf-8?q?1766344071817925364?= 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);