From nobody Thu Nov 30 16:09:53 2023 X-Original-To: freebsd-wireless@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 4Sh1PT3M1Zz52FYB for ; Thu, 30 Nov 2023 16:10:21 +0000 (UTC) (envelope-from farhan@farhan.codes) Received: from out1-smtp.messagingengine.com (out1-smtp.messagingengine.com [66.111.4.25]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 4Sh1PS3r4yz4T1x for ; Thu, 30 Nov 2023 16:10:20 +0000 (UTC) (envelope-from farhan@farhan.codes) Authentication-Results: mx1.freebsd.org; dkim=pass header.d=farhan.codes header.s=fm3 header.b=k97HRkcT; dkim=pass header.d=messagingengine.com header.s=fm1 header.b=DcRsCKga; spf=pass (mx1.freebsd.org: domain of farhan@farhan.codes designates 66.111.4.25 as permitted sender) smtp.mailfrom=farhan@farhan.codes; dmarc=none Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.nyi.internal (Postfix) with ESMTP id 24C345C0367; Thu, 30 Nov 2023 11:10:19 -0500 (EST) Received: from imap45 ([10.202.2.95]) by compute5.internal (MEProxy); Thu, 30 Nov 2023 11:10:19 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=farhan.codes; h= cc:cc:content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:sender :subject:subject:to:to; s=fm3; t=1701360619; x=1701447019; bh=F1 H6XzgOog5hrHPP7BFjxP5PquJ26/VRvc9HSjdDZzI=; b=k97HRkcTr1NaC0xwAt Nvuu/75gUpQ/UMUOnFPpWWeCjIqwhBJFUjURFCmEKnyvvVEqBAziiNUstrPme5zS /t5hOx69v3vWxfeSB6HPT3uPfJzXp+BUwH2DotvSVcpDN2ANKX/SSbUerElMVG9E 5W6FmKKKbFqYH8okU+preZBHrY7GevQG9z1MNWZXUQn+3io8n1g7Sv+5mJsKOMsU pTpbiHz1CxyAHOG2ekDp28JORZKeLGtVX6bHjGe020teXg2xr25WXd2BJZjUFDbX vVlr3yII3P3vS0LNjzYeiJy0JBRpVd67FagCjZHfFO+Y/+Pbfw/ZGhxus3Q/o57M ciPw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:sender:subject :subject:to:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm1; t=1701360619; x=1701447019; bh=F1H6XzgOog5hr HPP7BFjxP5PquJ26/VRvc9HSjdDZzI=; b=DcRsCKga4JCd1LKf06Saxx/dgD1bj BZm50UGg/bbzSInSdlhFzepvTPIfgCaiZMTYzqt0sT5EunGk9wBqMytkcwSzvsao 22nY/x0x9Wq0ujmqa0Gkr/HVDGpLA1bZY1jX1RvSE2Qcqm90F+FlY+CrmpXimeyA zU1Fp755n05DfFZ2XFoGK4dP3iY7x1GXiWlEmTvIxIGhseWJKhnwV53S7O/2WHRk SEA2URUoWzhnhA3KnPHfXdK98C7ZWLGbOPEb+eA8Ax3JJJJqmBOFzcP9APyJqXPH 4LfvC/Pi8jNLN6POsa+gLMtIK1Jl6t+mSjD7Eeyp+GhvLlczAV5amvsDw== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvkedrudeijedgkeehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepofgfggfkjghffffhvfevufgtsehttdertderredtnecuhfhrohhmpedfhfgr rhhhrghnucfmhhgrnhdfuceofhgrrhhhrghnsehfrghrhhgrnhdrtghouggvsheqnecugg ftrfgrthhtvghrnhepuedtffetlefgiedtteeileduieekgfegteektdelteegueevgeeu udfhtefhhedunecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrh homhepfhgrrhhhrghnsehfrghrhhgrnhdrtghouggvsh X-ME-Proxy: Feedback-ID: i61914458:Fastmail Received: by mailuser.nyi.internal (Postfix, from userid 501) id A3DCB272007C; Thu, 30 Nov 2023 11:10:18 -0500 (EST) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.9.0-alpha0-1238-g6cccb1fa34-fm-20231128.002-g6cccb1fa List-Id: Discussions List-Archive: https://lists.freebsd.org/archives/freebsd-wireless List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-freebsd-wireless@freebsd.org X-BeenThere: freebsd-wireless@freebsd.org MIME-Version: 1.0 Message-Id: In-Reply-To: References: <629e3534-705a-4dcc-ad16-edba170da251@app.fastmail.com> Date: Thu, 30 Nov 2023 11:09:53 -0500 From: "Farhan Khan" To: "Adrian Chadd" Cc: freebsd-wireless Subject: Re: Why newstate handler runs IEEE80211_LOCK/UNLOCK? Content-Type: text/plain X-Spamd-Result: default: False [-3.69 / 15.00]; NEURAL_HAM_LONG(-1.00)[-1.000]; SUBJECT_ENDS_QUESTION(1.00)[]; DWL_DNSWL_LOW(-1.00)[messagingengine.com:dkim]; NEURAL_HAM_MEDIUM(-1.00)[-1.000]; NEURAL_HAM_SHORT(-1.00)[-1.000]; R_SPF_ALLOW(-0.20)[+ip4:66.111.4.25]; R_DKIM_ALLOW(-0.20)[farhan.codes:s=fm3,messagingengine.com:s=fm1]; RCVD_IN_DNSWL_LOW(-0.10)[66.111.4.25:from]; RWL_MAILSPIKE_GOOD(-0.10)[66.111.4.25:from]; MIME_GOOD(-0.10)[text/plain]; XM_UA_NO_VERSION(0.01)[]; ARC_NA(0.00)[]; DMARC_NA(0.00)[farhan.codes]; FROM_HAS_DN(0.00)[]; TAGGED_RCPT(0.00)[]; ASN(0.00)[asn:19151, ipnet:66.111.4.0/24, country:US]; TO_MATCH_ENVRCPT_SOME(0.00)[]; DKIM_TRACE(0.00)[farhan.codes:+,messagingengine.com:+]; TO_DN_ALL(0.00)[]; RCVD_COUNT_THREE(0.00)[3]; RCVD_TLS_LAST(0.00)[]; RCPT_COUNT_TWO(0.00)[2]; FROM_EQ_ENVFROM(0.00)[]; FREEMAIL_TO(0.00)[gmail.com]; MIME_TRACE(0.00)[0:+]; MLMMJ_DEST(0.00)[freebsd-wireless@freebsd.org] X-Rspamd-Queue-Id: 4Sh1PS3r4yz4T1x X-Spamd-Bar: --- On Thu, Nov 30, 2023, at 1:24 AM, Adrian Chadd wrote: > On Wed, 29 Nov 2023 at 22:12, Farhan Khan wrote: >> Hi all, >> >> I'm studying the implementations of net80211 and noticed that in all newstate handlers the code begins by running IEEE80211_UNLOCK(ic) and ends with IEEE80211_LOCK(ic). I was not clear on why this was, I would have expected the opposite order. Also, why not just use the softc device-wide mutex over one for ieee80211com. Overall, I do not seem to understand the intent of the unlock and am seeking clarification. > > That part of the net80211 locking handling is ... unfortunately unfun. > Without doing that, there'd be lots of lock order inversion issues and > sleeping whilst lock held issues (since it's a mutex, not a sleep lock.) > The newstate code in net80211 at least (now?) runs in a taskqueue, so > whenever something changes state, it isn't happening in a random > drivers rx/tx/ioctl path. That way newstate transitions are at > hopefully serialised and not running in overlapping/concurrent threads. I'm still a little unclear here. Why does it inverted UNLOCK first? Wouldn't that mean the state /can/ change until still be a LOCK first? And, why not just do a softc-wide lock, why IEEE80211's lock function? But then there is also a driver softc lock, which confuses me. I'm also not understanding the double lock mechanism. > > However, since drivers do a /lot/ of potentially sleeping work in the > newstate path - think all the sleeping that goes on when things wait > for firmware commands to complete - you can't hold a mutex across those. This seems relevant but I did not understand. :/ -- Farhan Khan PGP Fingerprint: 1312 89CE 663E 1EB2 179C 1C83 C41D 2281 F8DA C0DE