Received: by 2002:a05:6a10:d5a5:0:0:0:0 with SMTP id gn37csp3921953pxb; Mon, 4 Oct 2021 12:42:33 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy+zWxAmbk5oJyFOnYZgbeIFJuUEov+B44W466tyY2ejuooR754LdDd4drgMcQKyA9LQAF3 X-Received: by 2002:a05:6402:1d49:: with SMTP id dz9mr7311726edb.55.1633376553277; Mon, 04 Oct 2021 12:42:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633376553; cv=none; d=google.com; s=arc-20160816; b=MSbCpap4HAbCpZf2GXURYkSkezmcFxvmAqdVpqF744mbRoFy6JJEopirG5lbRTOvLE bfkFc9r8/W1EyngkvWfA9Guj6dkxDG8aDqNwMtAJpDz8t9hHC4p4g2JOyOkTo9/WTiQR rBxDbQtnU9K7z7hpizGEreuntPEZJYow3bqvPVKPJ+5Py3zKa9W/eNuUdagn5ZM1l1UB 2QWBlqt7cWADYIwj1VpcQgkvzHhHBP0Fwvz/pKigq50DeBFc+lydGGpRb+XnhvNXwbUO 8mTpzyvXZ2NXzRjRhn2v4hSsdvOIHCC8RRfkunr3haEsgBUKBStrpxd5Cz0OotvvMlpm glng== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=XiD+afiiLyuhyLeHqpR6VFM9oAVsKc1mquERPqNQV1s=; b=LRHVfALaQApkmE0+f2qM1wcR/1Rodx3Awmwp91e6pJluGM3LCqqTnyFPmlOdUVYvdU HiXZvd/j+Ns63fjVgN1oG7Bx0zGiunfma4Ti9R8rd6eLMkBk7v3go4FQrTCcskf9RDWA Syyj3ZoLqX4HpbEc7tomSXDUeZO0T/41cmhTJi179ZKYwOYQewyRnQl6FfqnIMB4Y1iR X3YKtzlOrUxYEUUAm9lCjZjvSzjc+6YbluZKfH64K9d6G7RieyyhsMmuV6rCNoAZcCcn xlmPpxx0CBzlbYPGdZB7XN9k33aiJ5Hl0EJ6PJsfHMmVj7We7CHpE8lXjcbxq+O8fuq7 vcmQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=fUySvCna; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=suse.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id l21si17059419edw.448.2021.10.04.12.42.08; Mon, 04 Oct 2021 12:42:33 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=fUySvCna; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=suse.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230405AbhJDMel (ORCPT + 99 others); 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