From patchwork Tue Oct 13 09:49:38 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Paoloni, Gabriele" X-Patchwork-Id: 11835269 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4D5D014D5 for ; Tue, 13 Oct 2020 09:50:16 +0000 (UTC) Received: from web01.groups.io (web01.groups.io [66.175.222.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id BA5B32078A for ; Tue, 13 Oct 2020 09:50:15 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=lists.elisa.tech header.i=@lists.elisa.tech header.b="cu/BJQy2" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org BA5B32078A Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=intel.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=bounce+72012+93+4688437+8417402@lists.elisa.tech X-Received: by 127.0.0.2 with SMTP id XPrsYY4689772xtUktBq9Xcm; Tue, 13 Oct 2020 02:50:15 -0700 X-Received: from mga14.intel.com (mga14.intel.com []) by mx.groups.io with SMTP id smtpd.web10.8229.1602582614818797112 for ; Tue, 13 Oct 2020 02:50:15 -0700 IronPort-SDR: 7YE3OhZH19cHbHKaIg6ceyeq5wJRDhx8I6Bl1Y9cSvJLUjBk7jnUCRamjmtX0aBanRU3pA8sIh WkUh9w43figg== X-IronPort-AV: E=McAfee;i="6000,8403,9772"; a="165093423" X-IronPort-AV: E=Sophos;i="5.77,369,1596524400"; d="scan'208";a="165093423" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Oct 2020 02:50:02 -0700 IronPort-SDR: /ztbp2kr8ZOHXgrgY4G413bnBkrCkuvat5Z3qDqmuNfs8d+CFfrNnVr9lyzRooGb2unzhwkuHx qs/zWpIq6MfQ== X-IronPort-AV: E=Sophos;i="5.77,369,1596524400"; d="scan'208";a="463427624" X-Received: from paolonig001.ir.intel.com ([163.33.183.93]) by orsmga004-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Oct 2020 02:50:02 -0700 From: "Paoloni, Gabriele" To: linux-safety@lists.elisa.tech Cc: gabriele.paoloni@intel.com Subject: [linux-safety] [RFC PATCH 2/2] bust_spinlocks: do not decrement oops_in_progress unconditionally Date: Tue, 13 Oct 2020 10:49:38 +0100 Message-Id: <20201013094938.356837-3-gabriele.paoloni@intel.com> In-Reply-To: <20201013094938.356837-1-gabriele.paoloni@intel.com> References: <20201013094938.356837-1-gabriele.paoloni@intel.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: Sender: linux-safety@lists.elisa.tech List-Id: Mailing-List: list linux-safety@lists.elisa.tech; contact linux-safety+owner@lists.elisa.tech Delivered-To: mailing list linux-safety@lists.elisa.tech List-Post: X-Gm-Message-State: zIjr8b0sFiJdTrW9dy2MZ1Yox4688437AA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=lists.elisa.tech; q=dns/txt; s=20140610; t=1602582615; bh=rLmj388HL5yGq9HhZXeEjOkdmz8kYZgud1h156lYFIY=; h=Cc:Content-Type:Date:From:Subject:To; b=cu/BJQy2/4CouEkhNXy4TS5C5QqAbCF2TEOeI5CkhXISAU+zMxVB/ffGmBpBKTEpAZv 5y2e30iy9Wxp1p0ULIZbcjWuQgrN/J7SWG1EWTje1Vm4/zWlNvYhKyG3JuzsQiRZ56b4O 2ChMqP3VIYpttVaeRQStV1s+1DVb273fHYk= In the current implementation if the input flag is 0 oops_in_progress is unconditionally decremented, thus allowing to become a negative number. Since right now oops_in_progress is a global variable used in the kernel as a conditional flag to check if oops, panic(), BUG() or die() is in progress the current unconditional decrement may lead to unexpected behavior in the Kernel paths conditionally executing over this flag. This patch only decrement oops_in_progress if it is non zero Signed-off-by: Gabriele Paoloni --- lib/bust_spinlocks.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/bust_spinlocks.c b/lib/bust_spinlocks.c index 594b270161d9..842633ac9130 100644 --- a/lib/bust_spinlocks.c +++ b/lib/bust_spinlocks.c @@ -23,6 +23,9 @@ * @yes: input flag; if zero decreases oops_in_progress, * otherwise increases it. * + * Note: if oops_in_progress is already 0 it will not + * be decreased + * */ void bust_spinlocks(int yes) { @@ -33,7 +36,9 @@ void bust_spinlocks(int yes) unblank_screen(); #endif console_unblank(); - if (--oops_in_progress == 0) + if (oops_in_progress) + oops_in_progress--; + if (!oops_in_progress) wake_up_klogd(); } }