Received: by 2002:a05:7412:cfc7:b0:fc:a2b0:25d7 with SMTP id by7csp1020623rdb; Mon, 19 Feb 2024 01:17:50 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVHLZQaQ9p/A/2wgfEnc+IJT63BtXprPhqZyejDXTx+XUL4oObanZo9eTtPPYljrF/wPpTr5Q/T2M8w3E2jG0Cj5vsTxerBda5DXAjwnA== X-Google-Smtp-Source: AGHT+IFsGMACYyf+vEO+2oZBgdEbd4n0lR6ZpwEFlS1EOxZqZYqI3R1/tNfzIN7B+/JkAEALN8jD X-Received: by 2002:ac8:5dce:0:b0:42c:3a04:58ca with SMTP id e14-20020ac85dce000000b0042c3a0458camr25459970qtx.11.1708334270004; Mon, 19 Feb 2024 01:17:50 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708334269; cv=pass; d=google.com; s=arc-20160816; b=KbSCSZj0xIjplzv31drdPkEfpX1AsnSp0TKFoaWv+XB42omQPZkyOgNUYQgOW+EDvN KplwgLoHRy7MCF8AMJUIPdOp23ixnF0HuUpy0M2Ar0yZtX70U0/NuBew0AdvcMWSVdYL +dIyXTYBMTz2r81AjPorRaWGwW9WH5uZINdTXUYRmaWxsohkS2fHj2KzGjZtkKKRxedy VRqfl6pGAc7RZ8xgdHBJD+orVcSlRMCM8xHA433rLXSI36VSXcowzn0YSqLj6jDGu2ad zOdyysITfSZz9NkopTos4z3FAblC21w01Wp7gWukWRH0eKE1KTY88aImCoN2NF96xa3M eBFw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:content-language:references :cc:to:subject:from:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id:dkim-signature; bh=BH1GYWZS6Ec7OAeBGtxUqhu8PwfORuAdAisOvqa5C+A=; fh=Lsjxuqh5HipKsU3yce20QdeUTWIXPzY858j58b/G6aU=; b=zQe9qqp9qawA5LJZaztkDe9vHpyiv96TtrcTl8S6YSMaFWszVSOtfoCFHWj8IcJWmy 86/aVwTcoRIXW/esyRShuk+Gkq4Op9ZhfRXxT9/gzN/la6hz/hmXJQlskT2bUnEDE4fg YekaiFsMQv/7SLJu8SCSk9xRev61ucFRryuKuV86jsJb3XZc/BJh0JxEVcl6IssTZtdq hBoTzuD7kX+0+nBsRw7yXbut6W77DbC94jXMxR4XYszz53XKbPDgRCONuUvSgY1k/+dK oH98kyJ51W2+P0CmJr8Bk3moNmlQuFI02/pRdli3UWz43hyFXp94/1uI4g+mVCrs+Bkl TqvA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.alibaba.com header.s=default header.b="Pv/vW1og"; arc=pass (i=1 spf=pass spfdomain=linux.alibaba.com dkim=pass dkdomain=linux.alibaba.com dmarc=pass fromdomain=linux.alibaba.com); spf=pass (google.com: domain of linux-kernel+bounces-71017-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-71017-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.alibaba.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id v12-20020a05622a188c00b0042e1212ec3bsi1867480qtc.0.2024.02.19.01.17.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Feb 2024 01:17:49 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-71017-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.alibaba.com header.s=default header.b="Pv/vW1og"; arc=pass (i=1 spf=pass spfdomain=linux.alibaba.com dkim=pass dkdomain=linux.alibaba.com dmarc=pass fromdomain=linux.alibaba.com); spf=pass (google.com: domain of linux-kernel+bounces-71017-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-71017-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.alibaba.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id BA4281C212F2 for ; Mon, 19 Feb 2024 09:17:49 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C433A22F11; Mon, 19 Feb 2024 09:17:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b="Pv/vW1og" Received: from out30-131.freemail.mail.aliyun.com (out30-131.freemail.mail.aliyun.com [115.124.30.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0152022F00 for ; Mon, 19 Feb 2024 09:17:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.131 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708334256; cv=none; b=F6vRDLf/RF/Z6xTmEzMrDmK1B6shAcSrfFqVWW1HEDs7QZj4RRS/+kVUb0Msw2BX/GK1ROcENRb+0Ca+E+quqPQcM5zyvKtaUSR2talFMhhlHuvNcg5be7n6rp4MXvgdBc5lTCoaJoALlfkB8asJIYhmQ6ieitdfAiw8pYMmYyc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708334256; c=relaxed/simple; bh=epTUfFQwno2wI377j99GIgS7b9HraRzpQgLwFeKbg0Q=; h=Message-ID:Date:MIME-Version:From:Subject:To:Cc:References: In-Reply-To:Content-Type; b=NGD15ryL6b22VWJP+qTCtDfage56275K7bG0FSSwMIr7k/2PK3DEiJqT8XEgFI3g4Z5n/8WiZggLCYWCF5Q/tir8OFoWO/z5LjGZD6khG37Kv+qp0S9eKTtorzryVY7PQT5VMPLO6iytzC7R+zqG0ALt4mTCz7Qsz4wcw1YKgdM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com; spf=pass smtp.mailfrom=linux.alibaba.com; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b=Pv/vW1og; arc=none smtp.client-ip=115.124.30.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.alibaba.com DKIM-Signature:v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1708334246; h=Message-ID:Date:MIME-Version:From:Subject:To:Content-Type; bh=BH1GYWZS6Ec7OAeBGtxUqhu8PwfORuAdAisOvqa5C+A=; b=Pv/vW1ogpCroWsxU68jIz3U2R1ATy4NUW/nUd5wI9juMVbcGaNV6/xz0i0IYIryEHpEtLlW45YddyDaW6TQOFjmKztxp/dHmSUM5M3NEjIx3o7KB/rMU1v+KCdJumt92trqYb6Bd9ej3Knxw82sCJ8K2Thnc6C5yzQJaRaJ2jTA= X-Alimail-AntiSpam:AC=PASS;BC=-1|-1;BR=01201311R111e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018045170;MF=yaoma@linux.alibaba.com;NM=1;PH=DS;RN=8;SR=0;TI=SMTPD_---0W0sMvls_1708333927; Received: from 192.168.0.101(mailfrom:yaoma@linux.alibaba.com fp:SMTPD_---0W0sMvls_1708333927) by smtp.aliyun-inc.com; Mon, 19 Feb 2024 17:12:08 +0800 Message-ID: Date: Mon, 19 Feb 2024 17:12:06 +0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird From: Bitao Hu Subject: Re: [PATCHv7 2/2] watchdog/softlockup: report the most frequent interrupts To: Thomas Gleixner Cc: linux-kernel@vger.kernel.org, Doug Anderson , akpm@linux-foundation.org, Petr Mladek , kernelfans@gmail.com, Liu Song , yaoma@linux.alibaba.com References: <87mss2dkxo.ffs@tglx> Content-Language: en-US In-Reply-To: <87mss2dkxo.ffs@tglx> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Hi, On 2024/2/15 19:30, Thomas Gleixner wrote: > On Wed, Feb 14 2024 at 10:14, Bitao Hu wrote: >> +static void start_counting_irqs(void) >> +{ >> + int i; >> + int local_nr_irqs; >> + struct irq_desc *desc; >> + u32 *counts = __this_cpu_read(hardirq_counts); >> + >> + if (!counts) { >> + /* >> + * nr_irqs has the potential to grow at runtime. We should read >> + * it and store locally to avoid array out-of-bounds access. >> + */ >> + local_nr_irqs = nr_irqs; >> + counts = kcalloc(local_nr_irqs, sizeof(u32), GFP_ATOMIC); > > Seriously? The system has a problem and you allocate memory from the > detection code in hard interrupt context? I want all the changes for this feature to be concentrated within the watchdog module, and I am also unsure whether modifying the irq code for this feature would be justified. Hence, I opted for this approach. However, your reply on V1 demonstrated the proper way to do it, so I will refactor accordingly. >> + for (i = 0; i < NUM_HARDIRQ_REPORT; i++) { >> + if (irq_counts_sorted[i].irq == -1) >> + break; >> + >> + desc = irq_to_desc(irq_counts_sorted[i].irq); >> + if (desc && desc->action) >> + printk(KERN_CRIT "\t#%u: %-10u\tirq#%d(%s)\n", >> + i + 1, irq_counts_sorted[i].counts, >> + irq_counts_sorted[i].irq, desc->action->name); > > You cannot dereference desc->action here: > > 1) It can be NULL'ed between check and dereference. > > 2) Both 'action' and 'action->name' can be freed in parallel > > And no, you cannot take desc->lock here to prevent this. Stop fiddling > in the internals of interrupt descriptors. Thanks for your analysis. However, I have a question. 'action->name' cannot be accessed here, and it seems that merely outputting the irq number provides insufficient information? > > > and the analysis boils down to: > > u64 cnt, sorted[3] = {}; > unsigned int irq, i; > > for_each_active_irq(irq) { > cnt = kstat_get_irq_since_snapshot(irq); > > if (cnt) { > for (cnt = (cnt << 32) + irq, i = 0; i < 3; i++) { > if (cnt > sorted[i]) > swap(cnt, sorted[i]); Hmm, I think the approach here isn't optimal. If some interrupts have the same count, then it effectively results in sorting by the irq number. Is my understanding correct? Best Regards, Bitao