From mboxrd@z Thu Jan 1 00:00:00 1970 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 74943C433EF for ; Mon, 4 Oct 2021 12:32:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4F3E96124C for ; Mon, 4 Oct 2021 12:32:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233038AbhJDMel (ORCPT ); Mon, 4 Oct 2021 08:34:41 -0400 Received: from smtp-out2.suse.de ([195.135.220.29]:37034 "EHLO smtp-out2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229486AbhJDMek (ORCPT ); Mon, 4 Oct 2021 08:34:40 -0400 Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id D9CF01FFE8; Mon, 4 Oct 2021 12:32:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1633350770; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=XiD+afiiLyuhyLeHqpR6VFM9oAVsKc1mquERPqNQV1s=; b=fUySvCnaU5OayYMjijzgKvZtS6YVpcj7fAqjvUviE8RPJUntQhxX9YTK/KdQ5S8KBPXEJf +nBLN2SrYjAszjqUQz92phaXTgt3CogjM/g8iwfaINFeemWhiGiz0DP+s/rYSt4HLhEzMG drvbNJqgdzfFBcC7sClw3lV57CAJIHE= Received: from suse.cz (unknown [10.100.224.162]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by relay2.suse.de (Postfix) with ESMTPS id D2339A3B8A; Mon, 4 Oct 2021 12:32:49 +0000 (UTC) Date: Mon, 4 Oct 2021 14:32:47 +0200 From: Petr Mladek To: Pingfan Liu Cc: linux-kernel@vger.kernel.org, Andrew Morton , Wang Qing , "Peter Zijlstra (Intel)" , Santosh Sivaraj , linux-arm-kernel@lists.infradead.org Subject: Re: [PATCHv2 2/4] kernel/watchdog_hld: clarify the condition in hardlockup_detector_event_create() Message-ID: References: <20210923140951.35902-1-kernelfans@gmail.com> <20210923140951.35902-3-kernelfans@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210923140951.35902-3-kernelfans@gmail.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu 2021-09-23 22:09:49, Pingfan Liu wrote: > As for the context, there are two arguments to change > debug_smp_processor_id() to is_percpu_thread(). > > -1. watchdog_ev is percpu, and migration will frustrate the attempt > which try to bind a watchdog_ev to a cpu by protecting this func inside > the pair of preempt_disable()/preempt_enable(). > > -2. hardlockup_detector_event_create() indirectly calls > kmem_cache_alloc_node(), which is blockable. > > So here, spelling out the really planned context "is_percpu_thread()". The description is pretty hard to understand. I would suggest something like: Subject: kernel/watchdog_hld: Ensure CPU-bound context when creating hardlockup detector event 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 > Cc: Petr Mladek > Cc: Andrew Morton > Cc: Wang Qing > Cc: "Peter Zijlstra (Intel)" > Cc: Santosh Sivaraj > Cc: linux-arm-kernel@lists.infradead.org > To: linux-kernel@vger.kernel.org > --- > kernel/watchdog_hld.c | 5 ++++- > 1 file changed, 4 insertions(+), 1 deletion(-) > > diff --git a/kernel/watchdog_hld.c b/kernel/watchdog_hld.c > index 247bf0b1582c..df010df76576 100644 > --- a/kernel/watchdog_hld.c > +++ b/kernel/watchdog_hld.c > @@ -165,10 +165,13 @@ 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; > > + /* This function plans to execute in cpu bound kthread */ This does not explain why it is needed. I suggest something like: /* * 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); > Othrewise the change looks good to me. Best Regards, Petr From mboxrd@z Thu Jan 1 00:00:00 1970 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 73B99C433F5 for ; Mon, 4 Oct 2021 12:34:41 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 33FC661350 for ; Mon, 4 Oct 2021 12:34:41 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 33FC661350 Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=suse.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.infradead.org 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:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=tW/b2wtaTuQ8otrz54WiDsViQobWFRNVrtNhtWg8jMY=; b=QMzqojnfEqq2Gk ZknKGdIUPoPc3kV9sswIit3o5jLXtl/GAgWtOj+GxvybH9MUDHnZXN51wDD6JpNTKtIGWYuD/72QE knI6203IMv6Oyjt1rb73tUH2L5N2zdH+d2IpLaKYo/AK51PODiJfbODOQPrkHcOXIAhh67lBiYsW7 79LsvRstUcjA8j64AHUWS5GmTd2hHD75jkJZbvM4IbXGaf0Z90H4Gcj652FWg7hfYDDdg9IMqlowQ 0bKmIIURNROWj895T4xteIC/wRzawgn+OJejy3gUcIotihKjXF7tH5IoTL9JNbGQneLYxbeKlLB9l 23loiuDeLY1HIcvGIq3Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mXN9P-006S8R-CF; Mon, 04 Oct 2021 12:32:59 +0000 Received: from smtp-out2.suse.de ([195.135.220.29]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mXN9L-006S7M-Ft for linux-arm-kernel@lists.infradead.org; Mon, 04 Oct 2021 12:32:56 +0000 Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id D9CF01FFE8; Mon, 4 Oct 2021 12:32:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1633350770; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=XiD+afiiLyuhyLeHqpR6VFM9oAVsKc1mquERPqNQV1s=; b=fUySvCnaU5OayYMjijzgKvZtS6YVpcj7fAqjvUviE8RPJUntQhxX9YTK/KdQ5S8KBPXEJf +nBLN2SrYjAszjqUQz92phaXTgt3CogjM/g8iwfaINFeemWhiGiz0DP+s/rYSt4HLhEzMG drvbNJqgdzfFBcC7sClw3lV57CAJIHE= Received: from suse.cz (unknown [10.100.224.162]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by relay2.suse.de (Postfix) with ESMTPS id D2339A3B8A; Mon, 4 Oct 2021 12:32:49 +0000 (UTC) Date: Mon, 4 Oct 2021 14:32:47 +0200 From: Petr Mladek To: Pingfan Liu Cc: linux-kernel@vger.kernel.org, Andrew Morton , Wang Qing , "Peter Zijlstra (Intel)" , Santosh Sivaraj , linux-arm-kernel@lists.infradead.org Subject: Re: [PATCHv2 2/4] kernel/watchdog_hld: clarify the condition in hardlockup_detector_event_create() Message-ID: References: <20210923140951.35902-1-kernelfans@gmail.com> <20210923140951.35902-3-kernelfans@gmail.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20210923140951.35902-3-kernelfans@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211004_053255_705355_6D19CE31 X-CRM114-Status: GOOD ( 26.16 ) 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: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Thu 2021-09-23 22:09:49, Pingfan Liu wrote: > As for the context, there are two arguments to change > debug_smp_processor_id() to is_percpu_thread(). > > -1. watchdog_ev is percpu, and migration will frustrate the attempt > which try to bind a watchdog_ev to a cpu by protecting this func inside > the pair of preempt_disable()/preempt_enable(). > > -2. hardlockup_detector_event_create() indirectly calls > kmem_cache_alloc_node(), which is blockable. > > So here, spelling out the really planned context "is_percpu_thread()". The description is pretty hard to understand. I would suggest something like: Subject: kernel/watchdog_hld: Ensure CPU-bound context when creating hardlockup detector event 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 > Cc: Petr Mladek > Cc: Andrew Morton > Cc: Wang Qing > Cc: "Peter Zijlstra (Intel)" > Cc: Santosh Sivaraj > Cc: linux-arm-kernel@lists.infradead.org > To: linux-kernel@vger.kernel.org > --- > kernel/watchdog_hld.c | 5 ++++- > 1 file changed, 4 insertions(+), 1 deletion(-) > > diff --git a/kernel/watchdog_hld.c b/kernel/watchdog_hld.c > index 247bf0b1582c..df010df76576 100644 > --- a/kernel/watchdog_hld.c > +++ b/kernel/watchdog_hld.c > @@ -165,10 +165,13 @@ 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; > > + /* This function plans to execute in cpu bound kthread */ This does not explain why it is needed. I suggest something like: /* * 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); > Othrewise the change looks good to me. Best Regards, Petr _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel