Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp449537ybz; Tue, 21 Apr 2020 12:13:15 -0700 (PDT) X-Google-Smtp-Source: APiQypIrEUICTBzNahK9xCJ3wNIj/XheJK/NH7mLt+liQqyLArzuQjX8v7yv7aGMYi4m/WC0YMat X-Received: by 2002:a17:906:85d3:: with SMTP id i19mr21994238ejy.153.1587496395162; Tue, 21 Apr 2020 12:13:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587496395; cv=none; d=google.com; s=arc-20160816; b=j9MzQFZurdL7VsLyklt+2L32HPmd6oPsHEI8vJ+Be8warPFFg7utd1ddiQag6ftKBK B2hLJNabasVNiiMGxXSPfV3lMacJiPEjmUDGomPd+qOmcmaDQ/j+46Cd5ERePpDXACFo AzOHGc/zNzuWXQsimBi91FgcCngeAgnnzhdwgr7WPXdER/eY9GM4CWPghvBRR/7EI52W Wm5mwRAD7ERFxxvF3WTgn9CRfVSFEpFDGPbOeWP6g69Lp8A+5C26Ev1ed2OpO/XX7ijd ouxJuSqRYj89rpx/T9/QsyiEfhuzcSBf0Pnc0PnwxN+Bly1uU4f3LSn2qLbJ9X4g93y0 aOPQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:to:references:message-id :content-transfer-encoding:cc:date:in-reply-to:from:subject :mime-version:dkim-signature; bh=1b/gE5Wx8BbM9MjbWUVMc+EWAcqscOsveJTWROOiXcU=; b=X7OrLX5xLtn5oFpynCOQAafC1V0/nb29bEC3T3l0kCFNJ8PVsOlLUzobDC/vKi3TA/ TJkwo2MrKFYjvB1U5LExmCpcXlYnn/LYKhcdlBJhsJHUEcCnYz88s+6hhzzvlBANxj/b ILumXGjIMxyK9HuxcDlKmUgG5FbkMbWU0lfYr4S0QKHJqFLBEWRktLwt07Gp6vCNV7Rq 1LSyRRU1yCcSkrCBOf6bQCgCj2iQuaDAOw+ArSmTg6DWhjLpXH/gmX6Jf45Xozx0x7T9 IDP30epHra+/OMuGcuEtJFk38mSLtHZ9VOvgCQfTXkLU7rkU0EZo94QaPyrs/+rF6w9G 1CgA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail (test mode) header.i=@codeweavers.com header.s=6377696661 header.b=mpSnJHUl; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=codeweavers.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id l7si2139959ejb.42.2020.04.21.12.12.51; Tue, 21 Apr 2020 12:13:15 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=fail (test mode) header.i=@codeweavers.com header.s=6377696661 header.b=mpSnJHUl; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=codeweavers.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726240AbgDUTJK (ORCPT + 99 others); Tue, 21 Apr 2020 15:09:10 -0400 Received: from mail.codeweavers.com ([50.203.203.244]:38176 "EHLO mail.codeweavers.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726195AbgDUTJJ (ORCPT ); Tue, 21 Apr 2020 15:09:09 -0400 X-Greylist: delayed 940 seconds by postgrey-1.27 at vger.kernel.org; Tue, 21 Apr 2020 15:09:08 EDT DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=codeweavers.com; s=6377696661; h=To:References:Message-Id: Content-Transfer-Encoding:Cc:Date:In-Reply-To:From:Subject:Mime-Version: Content-Type:Sender:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=1b/gE5Wx8BbM9MjbWUVMc+EWAcqscOsveJTWROOiXcU=; b=mpSnJHUlfSqJPnjT8h6x4C7fE We3wKZiZLGFQ1xcnsq/C0IBE4WGisZhe88IY3giPRkkftch2C1+XmXc5nUk38XIlw3CMADOOxSbKP EN+svioBW8pNgNMM/+82Lu5NiU7rTAir/yfofa0Nk9GLhEd1BY5Z3XpxX2QE/wEwAW+84=; Received: from cpe-107-184-2-226.socal.res.rr.com ([107.184.2.226] helo=[192.168.2.117]) by mail.codeweavers.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1jQy1K-0003fV-A3; Tue, 21 Apr 2020 13:53:23 -0500 Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 12.4 \(3445.104.14\)) Subject: Re: BUG: ff_effects lost after a fork From: Brendan Shanks In-Reply-To: <20191127101008.GA327265@nuka.localdomain> Date: Tue, 21 Apr 2020 11:53:19 -0700 Cc: dmitry.torokhov@gmail.com, rydberg@bitmath.org, linux-kernel@vger.kernel.org, Mathieu Maret , mmaret@pixium-vision.com Content-Transfer-Encoding: quoted-printable Message-Id: <5404D7D5-47EF-4399-B0D9-B3C68A3D5895@codeweavers.com> References: <20191127101008.GA327265@nuka.localdomain> To: linux-input@vger.kernel.org X-Mailer: Apple Mail (2.3445.104.14) X-Spam-Score: -25.7 X-Spam-Report: Spam detection software, running on the system "mail.codeweavers.com", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: > On Nov 27, 2019, at 2:10 AM, Mathieu Maret wrote: > > Hi, > > I'm using evdev for vibrator interface. > I can register ff_effect and play them. > But, if I do any kind of f [...] Content analysis details: (-25.7 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -20 USER_IN_WHITELIST From: address is in the user's white-list -6.0 ALL_TRUSTED Passed through trusted hosts only via SMTP -0.5 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] 0.8 AWL AWL: Adjusted score from AWL reputation of From: address Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org > On Nov 27, 2019, at 2:10 AM, Mathieu Maret = wrote: >=20 > Hi, >=20 > I'm using evdev for vibrator interface. > I can register ff_effect and play them. > But, if I do any kind of fork, all the effects are flush and cannot be > used. >=20 > You can find, below, an example of such a program. > =46rom some trace have put in the kernel, it's seems that at the end = of > the system() call, evdev_flush get called. >=20 > evdev_flush() will call flush_effects() that will remove all the > registered effects. >=20 > I've only one device with vibrator and it's a imx6 4.1.15 kernel. But > code looks the same that in linus master that why I'm posting it here. = I > hope that it will not waste people time >=20 Hi everyone, I=E2=80=99m also hitting this bug with games that use force-feedback = steering wheels under Wine/Proton. It typically shows up as EVIOCSFF = ioctls failing with EINVAL, since all the effects were unexpectedly = flushed. The problem is that input_ff_flush() is called whenever a file = descriptor is closed, but there can be multiple descriptors open to the = same file description (through fork(), dup(), etc). input_ff_flush() = removes all effects added by that file description, which the users of = the other descriptors certainly don't expect. As for the fix, maybe fd_ops->flush() shouldn=E2=80=99t be implemented = at all? In the current design, effects =E2=80=9Cbelong=E2=80=9D to a file = description (a struct file *), not a descriptor. This seems sensible to = me: a process could open a device, upload an effect, then fork(), and it = makes sense that the child would have full control of the effects = created by the parent. It seems to me like nothing should be done when a = descriptor is closed, and input_ff_flush() should be called only when = the whole struct file is released. I=E2=80=99ve attached a modified copy of Mathieu=E2=80=99s code, which = reproduces the problem for me with a Logitech G25 steering wheel. Brendan Shanks CodeWeavers #include #include #include #include #include #include #include #include #include #define DEV_PATH "/dev/input/event10" int main(int argc, char *argv[]) { int fd =3D open(DEV_PATH, O_RDWR); if (fd < 0) { printf("Cannot open " DEV_PATH); } // Register an effect struct ff_effect effects; memset(&effects, 0, sizeof(effects)); effects.type =3D FF_CONSTANT; effects.id =3D -1; effects.replay.length =3D 1000; effects.replay.delay =3D 0; if (ioctl(fd, EVIOCSFF, &effects) < 0) { printf("Cannot upload effect %s\n", strerror(errno)); return -1; } int fd2 =3D dup(fd); close(fd2); // ioctl fails with EINVAL if (ioctl(fd, EVIOCSFF, &effects) < 0) { printf("Cannot upload effect %s\n", strerror(errno)); return -1; } close(fd); return 0; }=