From nobody Tue Sep 13 16:03:58 2022 X-Original-To: freebsd-hackers@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4MRpDm5j34z4bkpW for ; Tue, 13 Sep 2022 16:04:08 +0000 (UTC) (envelope-from jo@bruelltuete.com) Received: from email.jo-t.de (seppel.jo-t.de [45.132.244.126]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 4MRpDl4PT3z47cc for ; Tue, 13 Sep 2022 16:04:07 +0000 (UTC) (envelope-from jo@bruelltuete.com) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=bruelltuete.com; s=bruelltuete18a; t=1663085041; bh=T3LCkgOpmm3OJqJpxNutxlNjcpdH3ncQyC7CY1pvAK8=; h=Message-ID:Date:MIME-Version:To:From:Subject:From; b=A/WpmJEyNewr7QUaIk3He3dGih9XaxknnauccQzxq+hX786Sq5hrqzQCSSJh2RGgF xe7VVx5ft7AVCU4Q3gKeShyOImosVYVtNhGame4MrB9kssNOYrZNacYvmCQ29xRAYK 3O5fomDDYELqjvfFZLShf3DJUM7NtrXiWypwWmSt22jdYx+jflSNy5Qcxro8lz8INz 0erErh92W3c/u5GYX4by+a8dm/50PdqVcGmaJ5PasvYxjFmrolY2Mi7WF8JQBstEQ4 OjxKM1PA/3EtkpS5u+sDQ1ymJSkpbGmDDEd8vKP+w2YvY4xpsBimEWf5ZCeuHQjjew JuxYFhbnhYA6Q== Message-ID: <9b87dd66-de57-f363-279e-dc33134c0fa6@bruelltuete.com> Date: Tue, 13 Sep 2022 17:03:58 +0100 List-Id: Technical discussions relating to FreeBSD List-Archive: https://lists.freebsd.org/archives/freebsd-hackers List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-freebsd-hackers@freebsd.org MIME-Version: 1.0 Content-Language: en-GB To: freebsd-hackers@FreeBSD.org From: Johannes Totz Subject: How to sync/mutex with acpi_tz_get_temperature() Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Rspamd-Queue-Id: 4MRpDl4PT3z47cc X-Spamd-Bar: --- Authentication-Results: mx1.freebsd.org; dkim=pass header.d=bruelltuete.com header.s=bruelltuete18a header.b="A/WpmJEy"; dmarc=pass (policy=none) header.from=bruelltuete.com; spf=pass (mx1.freebsd.org: domain of jo@bruelltuete.com designates 45.132.244.126 as permitted sender) smtp.mailfrom=jo@bruelltuete.com X-Spamd-Result: default: False [-3.69 / 15.00]; NEURAL_HAM_MEDIUM(-1.00)[-1.000]; NEURAL_HAM_SHORT(-1.00)[-0.998]; NEURAL_HAM_LONG(-0.69)[-0.695]; DMARC_POLICY_ALLOW(-0.50)[bruelltuete.com,none]; R_SPF_ALLOW(-0.20)[+mx]; R_DKIM_ALLOW(-0.20)[bruelltuete.com:s=bruelltuete18a]; MIME_GOOD(-0.10)[text/plain]; MLMMJ_DEST(0.00)[freebsd-hackers@FreeBSD.org]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_COUNT_ZERO(0.00)[0]; ARC_NA(0.00)[]; RCPT_COUNT_ONE(0.00)[1]; ASN(0.00)[asn:197540, ipnet:45.132.244.0/22, country:DE]; FROM_HAS_DN(0.00)[]; DKIM_TRACE(0.00)[bruelltuete.com:+]; TO_MATCH_ENVRCPT_ALL(0.00)[]; TO_DN_NONE(0.00)[]; MID_RHS_MATCH_FROM(0.00)[] X-ThisMailContainsUnwantedMimeParts: N Hi there, I would like to make sure that some of my code does not run concurrently with acpi_tz_get_temperature() [https://github.com/freebsd/freebsd-src/blob/main/sys/dev/acpica/acpi_thermal.c#L465]. What's the best way to achieve that? I wrote a small driver for one of those SuperIO hardware monitors that measures fan speed, voltage, temperature etc. That works fine. But looking at my board/BIOS's ASL, invoking _TMP is not safe to do concurrently with my driver. [see footnote] Ultimately, acpi_tz_thread() [https://github.com/freebsd/freebsd-src/blob/main/sys/dev/acpica/acpi_thermal.c#L949] is calling acpi_tz_get_temperature() with a few hops in-between. There are a few instances of ACPI_LOCK(thermal) etc but nothing that guards acpi_tz_get_temperature() specifically. Anyone have ideas/pointers? thanks, Johannes footnote: Reading from that chip is stateful, as in you need to do I/O to select which register you want to read/write and then read/write from another location to access the value of that register. Try to do that from 2 threads at the same time, one of them will read/write the wrong register, thus you can glitch ACPI into doing something disruptive/destructive.