From patchwork Fri Jun 17 22:54:47 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Pali_Roh=C3=A1r?= X-Patchwork-Id: 9185119 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id A7B82608A7 for ; Fri, 17 Jun 2016 22:56:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 97D6527EED for ; Fri, 17 Jun 2016 22:56:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8C19D280B0; Fri, 17 Jun 2016 22:56:34 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 20BA228236 for ; Fri, 17 Jun 2016 22:56:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755258AbcFQW4d (ORCPT ); Fri, 17 Jun 2016 18:56:33 -0400 Received: from mail-wm0-f67.google.com ([74.125.82.67]:33972 "EHLO mail-wm0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753495AbcFQWzb (ORCPT ); Fri, 17 Jun 2016 18:55:31 -0400 Received: by mail-wm0-f67.google.com with SMTP id 187so1042259wmz.1; Fri, 17 Jun 2016 15:55:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=E7NcEbQlkRSVLD+94cQYWEAQnaMEXv/W5ix8LyDV7A0=; b=aKmIyLe8OYXGfpf479il2fHVCBBWRI9gJjwgpmBxCvtskXImoMGVpg6yEfc0TZpWPI ljFZgUpbT6nkl9Q5NnUZhM2+1I/ZSSps47zJvmq1G6wcx0YJBu8pq8vZk9yB9uLlM5S2 tCLwPTaPGcEx+JZEoHX2lnTY8hadXW+Igj0s9FUYSNXAhhAAP7YrbCO9bRXSgOudj+AX 1qFFE+TBFCaBgGqqpQsOMuCca7C8+MjcSm+PSg0wl6as3vAjSPoTJ142ZLoWFhQd9g6w 29xJOM8Z9k7V0LnjAz5IJrsJJ7ycGZNHplQGDiPi58ABrFu9fJnzOoWNG2EqVjHmoP15 +dEA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=E7NcEbQlkRSVLD+94cQYWEAQnaMEXv/W5ix8LyDV7A0=; b=WUVE8YvquCh6eD+6il2jFcD24GGWeck5wfYVPXMVvnRIBlDzFW5ZNFOKENVTc/5Sg3 kJu+ltCq1998PNwTBTQys7zouGq6YrkTmL7YxpWa3REl1EkziUeYIoDGo0SuKtxWQ/Yw jfGsHlkRcWMWvhYSXZINHASotqItiGUhYvkDvrPU0OqEyjawTjQedoKnhLk9NuABlgjs vnRurpGv6CW+7LCdr6g6c5FP0OfjPeTX2dLdPy7nFVaQCOgVUO9hrdeTHCmGqQyPYbsQ OuF7XK6k2lrwzovuDLp2cmFXwnXraFlhkSN6lBEtuhtUkC0pwrl/qQylFO8Y29Mtzqkt jz+Q== X-Gm-Message-State: ALyK8tI5C5gHLJsGiRN/+H4h3qdWPb1MwP3JkkxXveSXX+Z1fqXouyP/9CoASsoZGDL2Cw== X-Received: by 10.194.221.37 with SMTP id qb5mr4055726wjc.171.1466204129763; Fri, 17 Jun 2016 15:55:29 -0700 (PDT) Received: from Pali-Latitude.lan (pali.kolej.mff.cuni.cz. [78.128.193.202]) by smtp.gmail.com with ESMTPSA id d137sm806128wmd.12.2016.06.17.15.55.28 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 17 Jun 2016 15:55:29 -0700 (PDT) From: =?UTF-8?q?Pali=20Roh=C3=A1r?= To: Jean Delvare , Guenter Roeck , Jan C Peters , Thorsten Leemhuis , =?UTF-8?q?David=20Santamar=C3=ADa=20Rogado?= , Peter Saunderson , Tolga Cakir , "Austin S. Hemmelgarn" , Mario_Limonciello@dell.com, Gabriele Mazzotta , =?UTF-8?q?Micha=C5=82=20K=C4=99pie=C5=84?= , Dakota Whipple , Leon Yu Cc: linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org, =?UTF-8?q?Pali=20Roh=C3=A1r?= Subject: [PATCH 4/6] hwmon: (dell-smm) Cache fan_type() calls and change fan detection Date: Sat, 18 Jun 2016 00:54:47 +0200 Message-Id: <1466204089-17030-5-git-send-email-pali.rohar@gmail.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1466204089-17030-1-git-send-email-pali.rohar@gmail.com> References: <1466204089-17030-1-git-send-email-pali.rohar@gmail.com> MIME-Version: 1.0 Sender: linux-hwmon-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP On more Dell machines (e.g. Dell Precision M3800) fan_type() call is too expensive (CPU is too long in SMM mode) and cause kernel to hang. This is bug in Dell SMM or BIOS. This patch caches type for each fan (as it should not change) and changes the way how fan presense is detected. First it try function fan_status() as was before commit f989e55452c7 ("i8k: Add support for fan labels"). And if that fails fallback to fan_type(). *_status() functions can fail in case fan is not currently accessible (e.g. present on GPU which is currently turned off). Reported-by: Tolga Cakir Signed-off-by: Pali Rohár Link: https://bugzilla.kernel.org/show_bug.cgi?id=112021 Cc: stable@vger.kernel.org # v4.0+, will need backport Tested-by: Tolga Cakir --- drivers/hwmon/dell-smm-hwmon.c | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/drivers/hwmon/dell-smm-hwmon.c b/drivers/hwmon/dell-smm-hwmon.c index 4bbc587..2ac87d5 100644 --- a/drivers/hwmon/dell-smm-hwmon.c +++ b/drivers/hwmon/dell-smm-hwmon.c @@ -238,7 +238,7 @@ static int i8k_get_fan_speed(int fan) /* * Read the fan type. */ -static int i8k_get_fan_type(int fan) +static int _i8k_get_fan_type(int fan) { struct smm_regs regs = { .eax = I8K_SMM_GET_FAN_TYPE, }; @@ -249,6 +249,17 @@ static int i8k_get_fan_type(int fan) return i8k_smm(®s) ? : regs.eax & 0xff; } +static int i8k_get_fan_type(int fan) +{ + /* I8K_SMM_GET_FAN_TYPE SMM call is expensive, so cache values */ + static int types[2] = { INT_MIN, INT_MIN }; + + if (types[fan] == INT_MIN) + types[fan] = _i8k_get_fan_type(fan); + + return types[fan]; +} + /* * Read the fan nominal rpm for specific fan speed. */ @@ -782,13 +793,17 @@ static int __init i8k_init_hwmon(void) if (err >= 0) i8k_hwmon_flags |= I8K_HWMON_HAVE_TEMP4; - /* First fan attributes, if fan type is OK */ - err = i8k_get_fan_type(0); + /* First fan attributes, if fan status or type is OK */ + err = i8k_get_fan_status(0); + if (err < 0) + err = i8k_get_fan_type(0); if (err >= 0) i8k_hwmon_flags |= I8K_HWMON_HAVE_FAN1; - /* Second fan attributes, if fan type is OK */ - err = i8k_get_fan_type(1); + /* Second fan attributes, if fan status or type is OK */ + err = i8k_get_fan_status(1); + if (err < 0) + err = i8k_get_fan_type(1); if (err >= 0) i8k_hwmon_flags |= I8K_HWMON_HAVE_FAN2;