From owner-dev-commits-src-main@freebsd.org Wed Aug 11 21:39:12 2021 Return-Path: Delivered-To: dev-commits-src-main@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id B0B2B65C554; Wed, 11 Aug 2021 21:39:12 +0000 (UTC) (envelope-from loos.br@gmail.com) Received: from mail-qk1-x72e.google.com (mail-qk1-x72e.google.com [IPv6:2607:f8b0:4864:20::72e]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "smtp.gmail.com", Issuer "GTS CA 1O1" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4GlNW44Cfmz4Z0t; Wed, 11 Aug 2021 21:39:12 +0000 (UTC) (envelope-from loos.br@gmail.com) Received: by mail-qk1-x72e.google.com with SMTP id y130so4087767qkb.6; Wed, 11 Aug 2021 14:39:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=IUaScHttlBA+yJIMDOi6tDzCrTFy4OQskCs+vt/dO80=; b=f/5U4YXo1yThHQ+S+L1UwhM14rWzbCtsSRl6h+XLzn/yXyDKJC5AWsTW9T4X6D2TM1 LBntozIA51YANR0qceXbP+z4bPbHIu/UxqwrBI8sH/wdvFe+nRTMIky8eTXdvctEr8s1 b+BHEptMikoG7OYFvAVKFn8pF6Jw6XQ9S9qVOGVA165CSpVnxANwzm1uZpGe1yN2Jaml 45pSsmS7GzWnScT6ISenA5Jey6glzalmCbNgQOrQd6oHbAeXFmhqFF3FBJgce2JWife1 WU9nWslKTYIrsq9Dq5i6S3JyMw9GOu0ulA0V7AJPfOWKwoXekurROQoH/si9O/Wm12pp llrQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=IUaScHttlBA+yJIMDOi6tDzCrTFy4OQskCs+vt/dO80=; b=gvnxZkWxBTy0wCDMP0RiorRLtXb1CHA8nw7R3W2Zts70KGc6BY27sxA71xUOJDV9P0 1EYgW0KeSbiJiXBqn1H1qtaSC0XHfZ6T0TmdNt0q0lT3esNJskJrCoMzran/29/XZrCK zAvzqzBwTPjAuW0Rh/iBan2yOk+ydszDSjxnNEGQDNBsVjnDUYEKaftZnIUcqjzzdNvr /YRgqOewShq4KfnHa+BbSeYQW146nsZjykc3kUa7ZngCJK80Wk8dPBYz1v//iRPmENlE g6vA62tg069/IqPV+6BH96Q+nxuL0J2ON+HuQsuMsSJWDYyzALzf0Ufv92JisBtAJcgE 1gIQ== X-Gm-Message-State: AOAM532gJT/rZrYr7QKsgLxngJq/6B6qOUWelnaP/1EJSdkXz8mgmKR4 LK9iXbzW1G903KaOEgDVHeLNJy+T2N1mo4ejKcHe50fG X-Google-Smtp-Source: ABdhPJy7r87VMxE48uJjwdgoMOPsK5wPK/rk3y8l0KFGn2SV+RSJUfbo3yqeWHPEp5J06+laSpwa7UJ9Ga2gLkK5vFc= X-Received: by 2002:a05:620a:14b8:: with SMTP id x24mr1134582qkj.475.1628717945815; Wed, 11 Aug 2021 14:39:05 -0700 (PDT) MIME-Version: 1.0 References: <202108102241.17AMfr63025604@gitrepo.freebsd.org> <9b1ec22c-1545-52ea-7bf9-a96140737711@FreeBSD.org> In-Reply-To: <9b1ec22c-1545-52ea-7bf9-a96140737711@FreeBSD.org> From: Luiz Otavio O Souza Date: Wed, 11 Aug 2021 18:38:55 -0300 Message-ID: Subject: Re: git: 35547df5c786 - main - Call wakeup() with the lock held to avoid missed wakeup races. To: John Baldwin Cc: Scott Long , src-committers , dev-commits-src-all@freebsd.org, dev-commits-src-main@freebsd.org Content-Type: text/plain; charset="UTF-8" X-Rspamd-Queue-Id: 4GlNW44Cfmz4Z0t X-Spamd-Bar: ---- Authentication-Results: mx1.freebsd.org; none X-Spamd-Result: default: False [-4.00 / 15.00]; REPLY(-4.00)[]; TAGGED_FROM(0.00)[] X-BeenThere: dev-commits-src-main@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commit messages for the main branch of the src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 11 Aug 2021 21:39:12 -0000 On Wed, Aug 11, 2021 at 3:49 PM John Baldwin wrote: > > On 8/10/21 3:41 PM, Scott Long wrote: > > The branch main has been updated by scottl: > > > > URL: https://cgit.FreeBSD.org/src/commit/?id=35547df5c78653b2da030f920323c0357056099f > > > > commit 35547df5c78653b2da030f920323c0357056099f > > Author: Scott Long > > AuthorDate: 2021-08-10 22:36:38 +0000 > > Commit: Scott Long > > CommitDate: 2021-08-10 22:36:38 +0000 > > > > Call wakeup() with the lock held to avoid missed wakeup races. > > > > Submitted by: luiz > > Sponsored by: Rubicon Communications, LLC ("Netgate") > > --- > > sys/dev/sdhci/sdhci.c | 2 +- > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > diff --git a/sys/dev/sdhci/sdhci.c b/sys/dev/sdhci/sdhci.c > > index d075c2e05000..573e6949b57e 100644 > > --- a/sys/dev/sdhci/sdhci.c > > +++ b/sys/dev/sdhci/sdhci.c > > @@ -2078,8 +2078,8 @@ sdhci_generic_release_host(device_t brdev __unused, device_t reqdev) > > /* Deactivate led. */ > > WR1(slot, SDHCI_HOST_CONTROL, slot->hostctrl &= ~SDHCI_CTRL_LED); > > slot->bus_busy--; > > - SDHCI_UNLOCK(slot); > > wakeup(slot); > > + SDHCI_UNLOCK(slot); > > return (0); > > } > > Hmm, how does this avoid a race? The sleep is checking bus_busy under > the lock and should never see a stale value and go back to sleep after > the wakeup has occurred: > > SDHCI_LOCK(slot); > while (slot->bus_busy) > msleep(slot, &slot->mtx, 0, "sdhciah", 0); > slot->bus_busy++; > /* Activate led. */ > WR1(slot, SDHCI_HOST_CONTROL, slot->hostctrl |= SDHCI_CTRL_LED); > SDHCI_UNLOCK(slot); > > Dropping the lock before wakeup() is a tiny optimization that avoids > having the second thread wakeup and immediately block on the lock before > it has been released by the first thread. > 'race' is probably wrong here. this change will prevent a second thread from taking the bus before you call wakeup() - poking all other threads unnecessarily. luiz