NetBSD Problem Report #58593

From www@netbsd.org  Wed Aug 14 01:55:19 2024
Return-Path: <www@netbsd.org>
Received: from mail.netbsd.org (mail.netbsd.org [199.233.217.200])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256
	 client-signature RSA-PSS (2048 bits) client-digest SHA256)
	(Client CN "mail.NetBSD.org", Issuer "mail.NetBSD.org CA" (not verified))
	by mollari.NetBSD.org (Postfix) with ESMTPS id F1F0F1A9242
	for <gnats-bugs@gnats.NetBSD.org>; Wed, 14 Aug 2024 01:55:18 +0000 (UTC)
Message-Id: <20240814015517.DF47B1A9243@mollari.NetBSD.org>
Date: Wed, 14 Aug 2024 01:55:17 +0000 (UTC)
From: campbell+netbsd@mumble.net
Reply-To: campbell+netbsd@mumble.net
To: gnats-bugs@NetBSD.org
Subject: tegra_cpufreq lacks memory barriers in bespoke locking
X-Send-Pr-Version: www-1.0

>Number:         58593
>Category:       port-arm
>Synopsis:       tegra_cpufreq lacks memory barriers in bespoke locking
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    port-arm-maintainer
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Wed Aug 14 02:00:00 +0000 2024
>Originator:     Taylor R Campbell
>Release:        current, 10
>Organization:
The NvidiaBSD Frequentegra
>Environment:
>Description:
    153 	if (atomic_cas_uint(&cpufreq_busy, 0, 1) != 0)
    154 		return EBUSY;
    155 
    156 	error = cpufreq_set_rate(fq);
    157 	if (error == 0) {
    158 		pmf_event_inject(NULL, PMFE_SPEED_CHANGED);
    159 	}
    160 
    161 	atomic_dec_uint(&cpufreq_busy);

https://nxr.netbsd.org/xref/src/sys/arch/arm/nvidia/tegra_cpufreq.c?r=1.5#153

This doesn't provide adequate memory ordering.
>How-To-Repeat:
code inspection
>Fix:
Two options:

1. After atomic_cas_uint, add membar_acquire; and add membar_release before atomic_dec_uint.

2. Just use mutex(9).

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.47 2022/09/11 19:34:41 kim Exp $
$NetBSD: gnats_config.sh,v 1.9 2014/08/02 14:16:04 spz Exp $
Copyright © 1994-2024 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.