From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-dy1-f171.google.com (mail-dy1-f171.google.com [74.125.82.171]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9F59A1F4181 for ; Mon, 23 Mar 2026 02:47:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.171 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774234066; cv=none; b=BqaNxFmDNIRxtBM7G3SLesZlKog03UTVo5VD589W2bdx3DHpZCqBLcanh3iHb/3XXpIm80m/GffyrJejYaAfQh3uxUOUHFe8uQiWKOjIJFXx5Tq481U2V2f3vjjdXXGFTx/XxFB6mjaENaAUiypreQc7Pnaby5Jyne09KiofjKE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774234066; c=relaxed/simple; bh=uGt1822Gs4JX22LdOGOly/rmWuNE9tMIJScOYjWcIpY=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=g5EvBn330kGC4SqF3bzqvK85sWbCkm43EN7GN63XQq/wsTZ5+yzmv2gqFuN30F++/AfWY5WT3+aJvZxBrNpAzcUAOg95/LvoVBbndGeNiVUqeKxSVm5fcmmA+ouHTANRUZ6hh0RTpS59ICB6ukg0ov1SeC+e5dG4LzBc4ZQegVM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=T/BH2WAb; arc=none smtp.client-ip=74.125.82.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="T/BH2WAb" Received: by mail-dy1-f171.google.com with SMTP id 5a478bee46e88-2c0ecaae7dfso6337324eec.1 for ; Sun, 22 Mar 2026 19:47:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1774234065; x=1774838865; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=BMsYmw2dDOcnd+1GHXLJahL+aBwqfC4EnffKGWzIRoM=; b=T/BH2WAbUPT3sx2GDny9p3zUY94lzbG2TLhJRzFTsvNyYHA+5UCjS9Xp6KKEmyGVwg aqV5FyYsii3FAlgkK1gCZyCQaYywjohR7s4E6IMk0DVKsJGjl6o86PRgQ3WUTV2oRUzH fhYMdY7mCWRMRK+IQvsR72VobTrvRu7AWkxVDgR85f9P0Fa7p1K8D5xj14TcD0XpgBZY UwnvmaOzYZqoXtnoGZu2OE0KiwGnY4pC3Ck8hc4hFvdwvVY4s2xwjSOclaGKB476gNpo HqKFOt5mK0Lqk+j5B8Ujt3ca36CkhIlb6H/F0tbxqjjKUKVN9Rptr/Ul3y11MzMO1X/b zKDA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774234065; x=1774838865; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=BMsYmw2dDOcnd+1GHXLJahL+aBwqfC4EnffKGWzIRoM=; b=anqzowz6QkGLpE4NSY79aWgc+kNJueMPKjM6KTjGLUaevdDTQsI6/FF+fvpPAGpqak HuNqZt0AGMtRXQIhKvfKojdCZOkEXyGHc8e/J4ZBc6x8TUcjM9ERY9CvYXdqJ2ioypHy jFE23zUmDs7618W0nAdCDsHA96JJB1XZSdMt5DfBwN+QaK9LVCiLF4YAvAcMs+xXFuiC 4DEs1vb8iKdBnNgYXKFvJHA1E3SArWWGpt4xTYZwfme3eiDSbP8+to6LH2vIdPy2PfsV kjI2imdd08W8sPnJb7fNrLJM9+0QCMzWQ2Pm0ve0QThUTgH/pC1tOFyMptvS+zchrUAQ Xz/A== X-Forwarded-Encrypted: i=1; AJvYcCU3vYhsS6Z5AypFh2FXBZnGyU2D41LNY8Ji0d04+I3Q4n2xCHoLDFGOFrVy4beP6FYPEcnSy9GVU2u+z8M=@vger.kernel.org X-Gm-Message-State: AOJu0YwUBzsk4Z7nhtrxmfYdiHX6oH7JDzCsZLdw7qUPQVd61+XLIlu4 00ERwBLyNWL8J03uD+K0oHptp02Apyy6fjbBYcYZps6XQMWzlWsHKEkv X-Gm-Gg: ATEYQzxdVGj4E3BO9WDE+3nMEHD4cPyYm36IuX8Wh4Qg4El8OqLBfzCfvcUFjFLZ3Wj 8pR4WSm5dRXjYKMoIHJD55p3UYfoanQO4jZH7ypeQbj8ix+EoAAVdjhcp8oeASa7lb5cesB2aHy 3+/dP+nBKiNbCYCRZC/VTYRJ2q6+dnc5yygjyDnE0jFYfttHdUi5F8XIBCvmloNI5PPXdiW02HC C6D4rAHoHTVhdwvo6aUyeZpmS7fvqlsXaxtVD0eRliKvM5HZqSWCt9/viPRjbZX9ST15kOFtACr itn9DISJ7RCXbpLJM8yKEhaMlMiUtWk8kHwk2fYo+wU3PjTINqLA1Oy+VgbZ0x5XLTTYIeggE57 E4VIUbn3UxpvJic93IUvV7meIKPJTikbyflcMi3MyrvtyubmI5Wl7WNwwlS8Tbf79og97ztY5UK GeTLP3DmoQh+SjUXjRwd/4xAkZGt6Ij1omvdt7kTfaJeA1tOv4SNE6oaoZccBlw0NW X-Received: by 2002:a05:7301:eab:b0:2c0:c5e4:605f with SMTP id 5a478bee46e88-2c109760fbemr4923608eec.24.1774234064561; Sun, 22 Mar 2026 19:47:44 -0700 (PDT) Received: from google.com ([2a00:79e0:2ebe:8:b768:22ed:3eba:aeb3]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-2c10b2d673asm13158435eec.24.2026.03.22.19.47.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 22 Mar 2026 19:47:44 -0700 (PDT) Date: Sun, 22 Mar 2026 19:47:39 -0700 From: Dmitry Torokhov To: Mikhail Gavrilov Cc: linux-input@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] Input: uinput - fix circular locking dependency with ff-core Message-ID: References: <20260228223628.472208-1-mikhail.v.gavrilov@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20260228223628.472208-1-mikhail.v.gavrilov@gmail.com> Hi Mikhail, On Sun, Mar 01, 2026 at 03:36:28AM +0500, Mikhail Gavrilov wrote: > A lockdep circular locking dependency warning can be triggered > reproducibly when using a force-feedback gamepad with uinput (for > example, playing ELDEN RING under Wine with a Flydigi Vader 5 > controller): > > ff->mutex -> udev->mutex -> input_mutex -> dev->mutex -> ff->mutex > > The cycle is caused by four lock acquisition paths: > > 1. ff upload: input_ff_upload() holds ff->mutex and calls > uinput_dev_upload_effect() -> uinput_request_submit() -> > uinput_request_send(), which acquires udev->mutex. > > 2. device create: uinput_ioctl_handler() holds udev->mutex and calls > uinput_create_device() -> input_register_device(), which acquires > input_mutex. > > 3. device register: input_register_device() holds input_mutex and > calls kbd_connect() -> input_register_handle(), which acquires > dev->mutex. > > 4. evdev release: evdev_release() calls input_flush_device() under > dev->mutex, which calls input_ff_flush() acquiring ff->mutex. > > Fix this by replacing udev->mutex with the existing > udev->requests_lock spinlock in uinput_request_send(). The function > only needs to atomically check device state and queue an input event > into the ring buffer via uinput_dev_event() -- both operations are safe > under a spinlock (ktime_get_ts64() and wake_up_interruptible() do not > sleep). This breaks the ff->mutex -> udev->mutex link since a spinlock > is a leaf in the lock ordering and cannot form cycles with mutexes. > > To keep state transitions visible to uinput_request_send(), protect > writes to udev->state in uinput_create_device() and > uinput_destroy_device() with the same spinlock. Thank you for the patch, it looks solid, however I wonder if creating a separate "state_lock" spinlock would not be better than reusing requests_lock? Thanks. -- Dmitry