From patchwork Thu May 4 22:13:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Doug Anderson X-Patchwork-Id: 13231885 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 B45F9C7EE21 for ; Thu, 4 May 2023 22:41:02 +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=Wou4h4AbE3IASRdZqXvPr1QalU77ydFXqV1U2QtP0SQ=; b=qPMHtdUj1UyoHZ 9BC8rfk7p5VRuNvc/dpe1DiafLSBd1MKogbBs5L1xF+2dCvWep9KE8zeSCer3/DFpByyafisLgj5a 0YGWJEyP4330Nn3fyhwQr29i1Issc4h1T4jzDsJ+dgsYoHhVmlNhM5yPbblPxXjCtwQipcXZs7+h3 N3nBkTMNdkWdQFcZmz2cCNLBOeaVI/lDtnlqlHCd4DeYFVVn1d+2v7A4jG/69j6ENwQT2Frn8hvSb 6uR5ef9i+M0AbPMan+OmvVMQ2xyalcp9xBG0DWSM0vMrJJgUbMSt6+RE6l/bauAYavL1aPQfsy6ek NN4A6VlobwrLFUYNhzkg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1puhcS-009EEz-2B; Thu, 04 May 2023 22:40:12 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1puhcR-009EEU-04 for linux-arm-kernel@bombadil.infradead.org; Thu, 04 May 2023 22:40:11 +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=+7chyR54aRty46RzcCdMbqi2QxR3fWS0cburZo/9gxI=; b=oFFen1iX5yTT/nxfBhaYKMPyZP gqfWUjl/0YagLey66x5jMN7Fe79CvJJuXr3Xmg7AHoIxYcmTW/CCXhNUDoomak2tX+P8k5vn9u2r9 O4PIDzUJwEoUPgjyI7snT7U4tQBITqlAq8ijJliqyLRKJPYdV+ExuIcSrBHaEmmVSWG3OX7unNn07 isYXj+JAGzPnkc6KtWIf+NJKypbKeLMiG8E5VcCW4u1rXpKhGWMQn+pN1dFku4dU+NxFisnvYLoNW Q+zUypNpG2+0uZtBE2EWHXxxpZqmx1mJed3kYkopSongjJk4IpJOx1+Fv5GHlZnW70gARTjfcqRJQ VPl6wVOg==; Received: from mail-pf1-x429.google.com ([2607:f8b0:4864:20::429]) by desiato.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1puhE6-001sqc-1j for linux-arm-kernel@lists.infradead.org; Thu, 04 May 2023 22:15:08 +0000 Received: by mail-pf1-x429.google.com with SMTP id d2e1a72fcca58-63b5465fc13so895806b3a.3 for ; Thu, 04 May 2023 15:14:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1683238496; x=1685830496; 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=+7chyR54aRty46RzcCdMbqi2QxR3fWS0cburZo/9gxI=; b=NQpIfbqEUQKnsAkyEYKExasyztEP9wJ8o+4IEiw9BxrvOoB0l00+ORgkpCBLFkfl+F PivQOONxkj4PAVC2WcZaYn5EMh53GyKpOpu34BApx4vjHnolGOvX4v2oyvAKoW8Y73KU w1j4yU/Hk37qgrXBksSm+ZQ5W6g5IzmgjL538= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683238496; x=1685830496; 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=+7chyR54aRty46RzcCdMbqi2QxR3fWS0cburZo/9gxI=; b=Cr1FWdsAEsJuQVsx8qcDGjSDqVn3vDq64MJWV8zgy5hqKCmEw2dbbdoTM/D583kYAF ePVHPJIxaLjZpZB8SXITmtUFzXQLvObvGN1GDleIAkz8l+IltFRpvAibFTR8W7tLSolq FsAUsYvyBKCmpLWBeO1QNP/BNAd08hb7CV+JgoS/a2FkfsO7aw5xlMXKn+2kQbtZTRJm XHEq9W5LUwuO2HQTj8oEYEiFtnv0ufYwtEee5BQvhJIH5Gqj2xyHs18sgCPuXnOBc3Il Fu31JVhHsF6B7b1GMPht+q81aKKbkTx205wodCACOjjjlYQMFiYjKMAB5cq21c9O+vKr l7Mw== X-Gm-Message-State: AC+VfDzaHYmcW/LR9RJBP7jGIIDUBlkLojd9tMq+S0BnZUMY4UPz8Gr+ v1TLIHfCZ3PYTGIYyRfeT/t0Bw== X-Google-Smtp-Source: ACHHUZ6RrkuuKPBgTlGYVBYmU7JHppwAnr7B5nmjdOCKHM4QBI81WKafubaC+FF4dnrAufHF9KP6jQ== X-Received: by 2002:a05:6a00:2e06:b0:62d:8376:3712 with SMTP id fc6-20020a056a002e0600b0062d83763712mr4427628pfb.28.1683238496089; Thu, 04 May 2023 15:14:56 -0700 (PDT) Received: from tictac2.mtv.corp.google.com ([2620:15c:9d:2:edf0:7321:6b9e:d5e7]) by smtp.gmail.com with ESMTPSA id g26-20020aa7819a000000b006437c0edf9csm169615pfi.16.2023.05.04.15.14.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 May 2023 15:14:55 -0700 (PDT) From: Douglas Anderson To: Petr Mladek , Andrew Morton Cc: Sumit Garg , Mark Rutland , Matthias Kaehlcke , Stephane Eranian , Stephen Boyd , ricardo.neri@intel.com, Tzung-Bi Shih , Lecopzer Chen , kgdb-bugreport@lists.sourceforge.net, Masayoshi Mizuma , Guenter Roeck , Pingfan Liu , Andi Kleen , Ian Rogers , linux-arm-kernel@lists.infradead.org, linux-perf-users@vger.kernel.org, ito-yuichi@fujitsu.com, Randy Dunlap , Chen-Yu Tsai , christophe.leroy@csgroup.eu, davem@davemloft.net, sparclinux@vger.kernel.org, mpe@ellerman.id.au, Will Deacon , ravi.v.shankar@intel.com, npiggin@gmail.com, linuxppc-dev@lists.ozlabs.org, Marc Zyngier , Catalin Marinas , Daniel Thompson , Douglas Anderson Subject: [PATCH v4 04/17] watchdog/perf: Ensure CPU-bound context when creating hardlockup detector event Date: Thu, 4 May 2023 15:13:36 -0700 Message-ID: <20230504151100.v4.4.I654063e53782b11d53e736a8ad4897ffd207406a@changeid> X-Mailer: git-send-email 2.40.1.521.gf1e218fcd8-goog In-Reply-To: <20230504221349.1535669-1-dianders@chromium.org> References: <20230504221349.1535669-1-dianders@chromium.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230504_231503_397745_D870300A X-CRM114-Status: GOOD ( 18.17 ) 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/ 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 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);