Received: by 2002:ab2:687:0:b0:1f4:6588:b3a7 with SMTP id s7csp188258lqe; Tue, 9 Apr 2024 21:00:17 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCV24QYlz4Ut0zwUI/YUSosk3gsLKN6nYMLphkvpnkt6yfHcWlnN/vGI327qGfAxDjJdcJQ660pBmnQWdpRQTw5IMmXZIX8V8VQe1h5iFQ== X-Google-Smtp-Source: AGHT+IF0/SVugUqOf8h3fND9GJt9I1I9KVN62dt1QAxEn5QQe6LGn9EVSEGsVt97kyAwYSchNAjz X-Received: by 2002:a50:d693:0:b0:568:d19e:7ab0 with SMTP id r19-20020a50d693000000b00568d19e7ab0mr1280126edi.36.1712721617293; Tue, 09 Apr 2024 21:00:17 -0700 (PDT) Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id i17-20020a508711000000b0056e0de10a40si5546453edb.115.2024.04.09.21.00.17 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Apr 2024 21:00:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-137871-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20230601 header.b=TzMuyXVP; arc=fail (body hash mismatch); spf=pass (google.com: domain of linux-kernel+bounces-137871-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-137871-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.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 am.mirrors.kernel.org (Postfix) with ESMTPS id 0B22C1F25219 for ; Wed, 10 Apr 2024 04:00:17 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 71A21C13C; Wed, 10 Apr 2024 04:00:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="TzMuyXVP" Received: from mail-wr1-f41.google.com (mail-wr1-f41.google.com [209.85.221.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EA2C5C2C6; Wed, 10 Apr 2024 04:00:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.41 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712721610; cv=none; b=CZpMKZNiB4nBBqyMJdZQ2yBwEmIgK08wyIU3iDS9i6jhrQ3VjXEJRpHh8RAVr3+8NWiuIyVWhkL9qf0OqiXGXaBhsACzSrtmYzPSN1sciXNC7VE69o69clBN07glPPhQjEJjZmAcXYm+4T3wOw4RmnzDGojxmpQ5XgydK1FD4GU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712721610; c=relaxed/simple; bh=NtI0xN3dWIHgnuVFP5emBfSv80l93K/NAVupuO8w05w=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=hXpBqgl2T0W2Xf3pH/ye4Zntbv6eOa0uNIZTm9q4NMqYyfRYc+5vAjye5zsJRSRGwuB+XA91dKPFd0CAf+XAc+rWEOVkbYa+cfbayYugoDx7p6SNEClWYWydS8UhXyExGi86WKN63OXKzF0avqsrFr5JyyGY+RGz056HoHEZcVc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=TzMuyXVP; arc=none smtp.client-ip=209.85.221.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-wr1-f41.google.com with SMTP id ffacd0b85a97d-343e70dd405so4250947f8f.3; Tue, 09 Apr 2024 21:00:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1712721607; x=1713326407; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=NtI0xN3dWIHgnuVFP5emBfSv80l93K/NAVupuO8w05w=; b=TzMuyXVPReh6DoIvrctOKcWk0w7xJVEd8NRoNH3SKPTbgqV+gX0iNBKJg6YdiA+6fD 6Iia9fI9u/vuGzlGdTPE20inRNUcKU6ghCEqGOoJaS5P/w/zxaf6d7E0hn97v9IqUnA7 KlLcHGIhs+xUUgTt+D+V2UcNMcZjJuy1+JDC9gCVxSYcyv/bc/qZ5z9AJeqheQLa5mcQ HPRHc/rw/wN2ggYyq3o/BiSrimUpJ2AkFN97ZMnvljIZ1t9iZfHYWCh2dP22j2TeB/ms afWddYQbXxcAfyD+spO7qp+0GlVK803tewmR9roToyCcR/7RY0eDLlGi7hVLces58OHZ L4yw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712721607; x=1713326407; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=NtI0xN3dWIHgnuVFP5emBfSv80l93K/NAVupuO8w05w=; b=qBnup8g61CoZglgBdpSmfGfL8S18dmeq0UPWLp0zB7qbRdPAlWASU1qSFT25dfpTNX Jcfh6CmGN97yWpLjC/ldNL+Fv0wg6zVhuHC/JrU6qXMNCmL1eJgOd3XZiKHZlzBNAQ6P 3uG6YbglvnUQeUpjpo3LPiLdYVap7VneF9xq3V98cjScJO+u5A31pD9lHo5UFEZp3Gn+ OY53+Nd0gmY0Pv0kP8UcPLwqvq7nQGQ9kygD49kqshhpfgngce3xjdRMkcPjxSj0ZnIE EbaMr6WeAmEmzG7o5SxTrOhdN7LgyzX3+LwdjxmSyT+nXDsRmE1Z4OJbOt2kWe5qHu4h 3lwQ== X-Forwarded-Encrypted: i=1; AJvYcCVZ3mBiyPa0TwCsfvtwKY9pOWXdIVlZbsZcHiszQ/qhCrtEQ7S+883kjIGWJuqMh+rG/PQxQQRiiiGsOxGiJhDHZHBXoY6kBLpCSuMR4Af8/tJ8hS4e5KtopCpURtbspn8TPC4VABRNpu6h X-Gm-Message-State: AOJu0YzNHTuerAd/qRiSNmbRuEOBvhQikRpWFwThvt2QltY8KUoviU5g jUZcM6bQjHXblyCGckIri71XZdR+hvA87ee2WM+LROW2mgPjCEy0/60xRWlz3GiUIoC+H5Ch4dc I8UuysnyiGnqRVIpAXIPCQ4C/c0Y= X-Received: by 2002:a05:6000:2a3:b0:343:8551:8d90 with SMTP id l3-20020a05600002a300b0034385518d90mr1602342wry.34.1712721607135; Tue, 09 Apr 2024 21:00:07 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240409020326.2125332-1-liu.yec@h3c.com> <20240410020615.2885000-1-liu.yec@h3c.com> In-Reply-To: <20240410020615.2885000-1-liu.yec@h3c.com> From: Andy Shevchenko Date: Wed, 10 Apr 2024 06:59:30 +0300 Message-ID: Subject: Re: [PATCH V10] kdb: Fix the deadlock issue in KDB debugging. To: liu.yec@h3c.com Cc: daniel.thompson@linaro.org, gregkh@linuxfoundation.org, dianders@chromium.org, jason.wessel@windriver.com, jirislaby@kernel.org, kgdb-bugreport@lists.sourceforge.net, linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Wed, Apr 10, 2024 at 5:07=E2=80=AFAM wrote: > > From: LiuYe > > Currently, if CONFIG_KDB_KEYBOARD is enabled, then kgdboc will > attempt to use schedule_work() to provoke a keyboard reset when > transitioning out of the debugger and back to normal operation. > This can cause deadlock because schedule_work() is not NMI-safe. > > The stack trace below shows an example of the problem. In this > case the master cpu is not running from NMI but it has parked > the slave CPUs using an NMI and the parked CPUs is holding > spinlocks needed by schedule_work(). > > Example: > BUG: spinlock lockup suspected on CPU#0. owner_cpu: 1 > CPU1: Call Trace: > __schedule > schedule > schedule_hrtimeout_range_clock > mutex_unlock > ep_scan_ready_list > schedule_hrtimeout_range > ep_poll > wake_up_q > SyS_epoll_wait > entry_SYSCALL_64_fastpath > > CPU0: Call Trace: > dump_stack > spin_dump > do_raw_spin_lock > _raw_spin_lock > try_to_wake_up > wake_up_process > insert_work > __queue_work > queue_work_on > kgdboc_post_exp_handler > kgdb_cpu_enter > kgdb_handle_exception > __kgdb_notify > kgdb_notify > notifier_call_chain > notify_die > do_int3 > int3 > > We fix the problem by using irq_work to call schedule_work() > instead of calling it directly. This is because we cannot > resynchronize the keyboard state from the hardirq context > provided by irq_work. This must be done from the task context > in order to call the input subsystem. > > Therefore, we have to defer the work twice. First, safely > switch from the debug trap context (similar to NMI) to the > hardirq, and then switch from the hardirq to the system work queue. .. > Signed-off-by: Greg KH > Signed-off-by: Andy Shevchenko > V9 -> V10 : Add Signed-off-by of Greg KH and Andy Shevchenko, Acked-by of= Daniel Thompson Huh?! --=20 With Best Regards, Andy Shevchenko