From patchwork Thu Oct 14 02:41:53 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pingfan Liu X-Patchwork-Id: 12557679 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 88848C433F5 for ; Thu, 14 Oct 2021 02:45:14 +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 5253561152 for ; Thu, 14 Oct 2021 02:45:13 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 5253561152 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.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: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=WFbOHEI3eS8szaVmvvtjvO2rhy8imXWDfMUFQfz7KOQ=; b=sX32OsaPR79IDY 9lzCxSWRx1MrXQiI7fLTbV1ppkWfv3epSw52XaMnz9ZG0tz2mE48yNtpAE0RhWkfl1oHczcoIlC63 PQJ1oUCboRSiiiKfnc0SagJK/CnafR+nbfDVdsirpDe7Qvg0MeL3BZ10AXcIiSJN87Nsz8qN5iOz6 MslTvgViUxopRLUj/Q317vcjauHWFeYWH9F3ckMAgAnxDg/lGo6kxojdjthRh+LLC7jNp9hRZBUIa LShDyM2+iLpHv904wAisqK2Gyil9WFIc3VFLIIu/0hKVeDFHexDkXg/3m4XCl82PU+igCwlLALv/A /9m0x0+O6ZlcBjDfgkPQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1maqha-001Ii9-OR; Thu, 14 Oct 2021 02:42:38 +0000 Received: from mail-pj1-x1036.google.com ([2607:f8b0:4864:20::1036]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1maqhE-001IcP-Oh for linux-arm-kernel@lists.infradead.org; Thu, 14 Oct 2021 02:42:18 +0000 Received: by mail-pj1-x1036.google.com with SMTP id lk8-20020a17090b33c800b001a0a284fcc2so5870235pjb.2 for ; Wed, 13 Oct 2021 19:42:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=IPEZG1UTOCdMILrBYHfNzu5EIxiMBByUqdY5jycPoxc=; b=lxzz23UgvQBpk6EVby72CERgNBPtwtcWXvKbYgUu9rqY5RRWf2XGRJBkfLNEOq+Hnw CnwMGXIh38ez/Uzs4zVLwymHfqIMRxwZ4dVcvCjovXnjgWH9CHGNRi9xMPB5zim4/PaK cwG1ayqWpQMDNtpteDZifV8y1MZmXOFU0phUK00goB0aeV0MHVOGEnoFJ8iWLlT2kWeb fKLHuGVu15NG8xbCQ8yerKgMcvuUn2kZul02AvSXPkD3BWBY/i4YwU2/LvrFEZUeJppc ZS4gsXuMfnW+LaWjmqgNTiBxM65548wroBcqfTrvuaN5DXFaXfl9D0YQ7oo8aOaz3AGs ihnQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=IPEZG1UTOCdMILrBYHfNzu5EIxiMBByUqdY5jycPoxc=; b=bMbLViHJk6zGDSun5pShpP15V+MA6/L/HaS3IY33cCEiLV3RTCc1WBKo7AhGaZcIAW 91oUKpjFYce1yw5KvUzwc6+IwlMjRsXoLXXt0gwC5D28mL76Tb106i2nYlwr2sTb3HFR C8vaUoPuuMoLMzMuYdIKRS06U1RGIkr8gs3c16XzUry8Fu2Nekuq4SWBJ2Ahviy93NHG YaiVj5OwBQ9Gk5tZ9Yxj0u14OnKSQ9ZLvZ5Xwy346ELLp0PmOVcxDt3y7I+N0qT7bF33 6BUL4P2o0geN0Y0eRurvlohM9WBkl2ImKFvDwgT/qv8HoXtM9HGx1JkqOlAqss9fj+6h garA== X-Gm-Message-State: AOAM532WYCIcXHSmK2PqfKpp4pX4sjj5SHQF+Vba6HdDH3/OPS7GksAo pCw6taeGVIt1L5QjIc0hSg== X-Google-Smtp-Source: ABdhPJyg/U09wdEAopvM6ev2T6v/23FdAJfCe329HDtgHDUz1zy3T2j76fZoYZFWx4+JOF4++xvH0Q== X-Received: by 2002:a17:90b:3850:: with SMTP id nl16mr3351886pjb.127.1634179336371; Wed, 13 Oct 2021 19:42:16 -0700 (PDT) Received: from piliu.users.ipa.redhat.com ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id m28sm818403pgl.9.2021.10.13.19.42.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Oct 2021 19:42:15 -0700 (PDT) From: Pingfan Liu To: linux-kernel@vger.kernel.org Cc: Pingfan Liu , Petr Mladek , Andrew Morton , Wang Qing , "Peter Zijlstra (Intel)" , Santosh Sivaraj , linux-arm-kernel@lists.infradead.org Subject: [PATCHv3 2/4] kernel/watchdog_hld: Ensure CPU-bound context when creating hardlockup detector event Date: Thu, 14 Oct 2021 10:41:53 +0800 Message-Id: <20211014024155.15253-3-kernelfans@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211014024155.15253-1-kernelfans@gmail.com> References: <20211014024155.15253-1-kernelfans@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211013_194216_865568_FB93A818 X-CRM114-Status: GOOD ( 15.36 ) 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 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 */ + 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);