From patchwork Fri Dec 16 14:07:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcelo Tosatti X-Patchwork-Id: 34021 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:e747:0:0:0:0:0 with SMTP id c7csp1072153wrn; Fri, 16 Dec 2022 08:42:00 -0800 (PST) X-Google-Smtp-Source: AA0mqf5BEskAzwsrkEVCEJ12rPxqd4sMduBeAEJBB+1WI+pgJagn9Dgtw21Zzdzlpx+o0b/Xq4C0 X-Received: by 2002:a17:902:c1c5:b0:185:441f:709c with SMTP id c5-20020a170902c1c500b00185441f709cmr32128671plc.33.1671208920299; Fri, 16 Dec 2022 08:42:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671208920; cv=none; d=google.com; s=arc-20160816; b=v8t5yhvv6Pg72Hrz9hW99re32WtjqnmOXIAjJ0XvtrdyBnZ9xnGs2wp+NmwhvMtmBD bVuEo4+EsM1Z8pNBi2nHvEJh/ust/F8wFazJLxsy7gXtjRcJA6eh6Kt7Q6zHAXCpjhcU bUtvLAUR8zHWfIMCB6o42RpvrTpjWqExPweSIRLKr9pHn4u9phMMcrP32+1dqElTgweI K/44NM1/repEvp4xE5/rJ6mwAWXXtaHdRvCT2lrVaoKvY9Xjkmo8RHLLilCwFMe84/u7 9m4uBcMS3+uSlv7cTplrNbyckl9iSnN6786UIOKaB3c1/k9L8NRrYeTnqDxkbKo8po6g K36A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=iYWX1JVBYSUKLXVYpGQr+eXLajFPQi0WiXT4Nb6R2Yo=; b=DIJ09FZrce5pzdycrtVuYzn0CUF4m79dwvHy75e0PFyZzKnfIM5nueoLeiEy8S42/9 qjenO5DUMHiHftJdwui2cbZUY3xydWZ5e20dEIWzeDc+STO04OtMdTi1S0WXc9SgUfc5 e9OJUNx4DRbgbXdukcT4kLddNoXgQ3O4u6jnsqWR/XoRoC3VYkybK+B2ph1RhR+kQL8M Oz7x6exua4GPRV99mThXIVeeLRTxhxU+0mBwmpW3L+A4es53mPjfyvGSFW1Z6YHbdJev iqgAH1NDC14IsYczOQDhR9YU5ZyP0oLK7fJnI8P1g36IUFDyE2hLQiYvtnnn+deWT4X8 whLQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=cj1BqK0e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a15-20020a170902eccf00b0018890a7e9b5si3244949plh.287.2022.12.16.08.41.47; Fri, 16 Dec 2022 08:42:00 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=cj1BqK0e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231888AbiLPQj1 (ORCPT + 99 others); Fri, 16 Dec 2022 11:39:27 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38984 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231488AbiLPQij (ORCPT ); Fri, 16 Dec 2022 11:38:39 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 123812E687 for ; Fri, 16 Dec 2022 08:37:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1671208672; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=iYWX1JVBYSUKLXVYpGQr+eXLajFPQi0WiXT4Nb6R2Yo=; b=cj1BqK0e0nhFk1HvRAq05kbMPbZBqoKjHPFZCsTPqzDlq7ju4aCUYfPasmBD3YlR4GIkdl 3/zzFzlRNWVRn+/Pkbop+Ihzz8fMncY2KTNmcMUwqmcXZ3h9JucCyJUTOE5z2/3gYQIcSd 4UkKsnIJ6OBG8yTuDYlTpwFEL6+jSbU= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-663-CI_Xdn4APQSUGfk2Kx0WoQ-1; Fri, 16 Dec 2022 11:37:48 -0500 X-MC-Unique: CI_Xdn4APQSUGfk2Kx0WoQ-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 71487857F82; Fri, 16 Dec 2022 16:37:47 +0000 (UTC) Received: from tpad.localdomain (ovpn-112-3.gru2.redhat.com [10.97.112.3]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 45A451401C34; Fri, 16 Dec 2022 16:37:47 +0000 (UTC) Received: by tpad.localdomain (Postfix, from userid 1000) id 66F9B40416677; Fri, 16 Dec 2022 11:07:01 -0300 (-03) Date: Fri, 16 Dec 2022 11:07:01 -0300 From: Marcelo Tosatti To: Guenter Roeck Cc: Fenghua Yu , linux-kernel@vger.kernel.org, linux-hwmon@vger.kernel.org, Frederic Weisbecker Subject: [PATCH v2] hwmon: coretemp: avoid RDMSR interruptions to isolated CPUs Message-ID: References: <68f76ac7-5edd-d437-8bef-e233f2876660@roeck-us.net> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <68f76ac7-5edd-d437-8bef-e233f2876660@roeck-us.net> X-Scanned-By: MIMEDefang 3.1 on 10.11.54.7 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1752284638836949682?= X-GMAIL-MSGID: =?utf-8?q?1752389564643775769?= The coretemp driver uses rdmsr_on_cpu calls to read MSR_IA32_PACKAGE_THERM_STATUS/MSR_IA32_THERM_STATUS registers, which contain information about current core temperature. For certain low latency applications, the RDMSR interruption exceeds the applications requirements. So disallow reading of crit_alarm and temp files via /sys, returning -EINVAL, in case CPU isolation is enabled. Temperature information from the housekeeping cores should be sufficient to infer die temperature. Signed-off-by: Marcelo Tosatti --- v2: improve changelog to mention that an error is returned, and sysfs file is not disabled (Guenter Roeck) diff --git a/drivers/hwmon/coretemp.c b/drivers/hwmon/coretemp.c index 9bee4d33fbdf..30a35f4130d5 100644 --- a/drivers/hwmon/coretemp.c +++ b/drivers/hwmon/coretemp.c @@ -27,6 +27,7 @@ #include #include #include +#include #define DRVNAME "coretemp" @@ -121,6 +122,10 @@ static ssize_t show_crit_alarm(struct device *dev, struct platform_data *pdata = dev_get_drvdata(dev); struct temp_data *tdata = pdata->core_data[attr->index]; + + if (!housekeeping_cpu(tdata->cpu, HK_TYPE_MISC)) + return -EINVAL; + mutex_lock(&tdata->update_lock); rdmsr_on_cpu(tdata->cpu, tdata->status_reg, &eax, &edx); mutex_unlock(&tdata->update_lock); @@ -158,6 +163,8 @@ static ssize_t show_temp(struct device *dev, /* Check whether the time interval has elapsed */ if (!tdata->valid || time_after(jiffies, tdata->last_updated + HZ)) { + if (!housekeeping_cpu(tdata->cpu, HK_TYPE_MISC)) + return -EINVAL; rdmsr_on_cpu(tdata->cpu, tdata->status_reg, &eax, &edx); /* * Ignore the valid bit. In all observed cases the register