Received: by 2002:a05:6622:f08:0:0:0:0 with SMTP id l8csp4488610ivc; Tue, 3 Nov 2020 13:22:25 -0800 (PST) X-Google-Smtp-Source: ABdhPJzrevEYsOdsFlwxeR81HoGPMLrHPAC1MfYumsa94C/2i9L8b8IhZqf4aHlf5k0nUG5LoBln X-Received: by 2002:a50:8a88:: with SMTP id j8mr23772836edj.179.1604438545521; Tue, 03 Nov 2020 13:22:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604438545; cv=none; d=google.com; s=arc-20160816; b=zewmMkQB6J+42bhYedPn0TFR07rYKTItTxQ81+Zox2j9Sm3Lnm50dHlY8vkI7H5jD4 BQnSUXPWPIcbmeH3nbrrVHzLTVqUhZwS2HNvGyXej45tCpcOs/IXkQ8eiKQV6Dm1nJq9 nQGUIKBGVEQD6S6/wQL42LcQKwSbsdaqczDLHIxKbMk45KdFqivSj8sWIhcQRbbYvbT8 fiKrhiYtFCSpLRjlGNFW770RE+3SI7pWhy6pryD5tFARRu0TQO84NfmD0j1EUhi2F5uy ggHcHFRTsp58gfforWpNA4u2m1FSOgm4fUzUVxgZoU8+qPo8s6zDNTsxHWmhrG+/IkXz D7yg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=vNp0JGMDWj+jmaAeTLmZSAB7dtwkA5kH6W37x7ftVcw=; b=QTsXUUEmtpLNHASM3J1G00IGl2ZhebOYxLv/96uz1i7HFZDy41W+Ljq5VzVXrKIAZq +M1S4l1nFpnL8GWD7OoDAXvrDAcuvKGs8H8Vt/eVNsUYpMReOvJb1A1hCdQdxy+F6nWl BqRQwkC+DPhrndm2WtfXJll+5CtTmLfaD7aYVdYavvAb7IIJFDtfaIbIrr0uKFDNMqyC eYcdLMP4oK7Kyg8c816hpqw0djUFZa7oVLt7TP1296UVU5lgABpTT+b/T5+5KPzLowuY oY4UPClaOUaq8xzEM4WiTSXye0bhrf2ZUWLbbdQLtsdavqL7EyijA2g2/dPbMpGkkt2e lJ3A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=CxSzKQ9E; 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=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z11si1510934edr.547.2020.11.03.13.22.03; Tue, 03 Nov 2020 13:22:25 -0800 (PST) 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=pass header.i=@kernel.org header.s=default header.b=CxSzKQ9E; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388671AbgKCVKH (ORCPT + 99 others); Tue, 3 Nov 2020 16:10:07 -0500 Received: from mail.kernel.org ([198.145.29.99]:50604 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388614AbgKCVKE (ORCPT ); Tue, 3 Nov 2020 16:10:04 -0500 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 8C074206B5; Tue, 3 Nov 2020 21:10:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1604437804; bh=/XL4hkKKgI8VIEVaGhzIKtnulfGHlhePJe1s95SEA/k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CxSzKQ9EdVTQpxScGcynDEpbSlZw6FBxJQEoLOry5QYfh46UzA8ZvE4+nqb1zIOsn GedHixeKuqOsFCDaic55z1RJjX3p+n4bpao0cez4EY1VVJe84/M4axTo+x8yJXaoF5 jP1FN+3G1h/yp+lSiJK15oTiwbtPmWm1hA6OIN6w= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Lang Dai , Sasha Levin Subject: [PATCH 4.14 039/125] uio: free uio id after uio file node is freed Date: Tue, 3 Nov 2020 21:36:56 +0100 Message-Id: <20201103203202.675297682@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201103203156.372184213@linuxfoundation.org> References: <20201103203156.372184213@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Lang Dai [ Upstream commit 8fd0e2a6df262539eaa28b0a2364cca10d1dc662 ] uio_register_device() do two things. 1) get an uio id from a global pool, e.g. the id is 2) create file nodes like /sys/class/uio/uio uio_unregister_device() do two things. 1) free the uio id and return it to the global pool 2) free the file node /sys/class/uio/uio There is a situation is that one worker is calling uio_unregister_device(), and another worker is calling uio_register_device(). If the two workers are X and Y, they go as below sequence, 1) X free the uio id 2) Y get an uio id 3) Y create file node /sys/class/uio/uio 4) X free the file note /sys/class/uio/uio Then it will failed at the 3rd step and cause the phenomenon we saw as it is creating a duplicated file node. Failure reports as follows: sysfs: cannot create duplicate filename '/class/uio/uio10' Call Trace: sysfs_do_create_link_sd.isra.2+0x9e/0xb0 sysfs_create_link+0x25/0x40 device_add+0x2c4/0x640 __uio_register_device+0x1c5/0x576 [uio] adf_uio_init_bundle_dev+0x231/0x280 [intel_qat] adf_uio_register+0x1c0/0x340 [intel_qat] adf_dev_start+0x202/0x370 [intel_qat] adf_dev_start_async+0x40/0xa0 [intel_qat] process_one_work+0x14d/0x410 worker_thread+0x4b/0x460 kthread+0x105/0x140 ? process_one_work+0x410/0x410 ? kthread_bind+0x40/0x40 ret_from_fork+0x1f/0x40 Code: 85 c0 48 89 c3 74 12 b9 00 10 00 00 48 89 c2 31 f6 4c 89 ef e8 ec c4 ff ff 4c 89 e2 48 89 de 48 c7 c7 e8 b4 ee b4 e8 6a d4 d7 ff <0f> 0b 48 89 df e8 20 fa f3 ff 5b 41 5c 41 5d 5d c3 66 0f 1f 84 ---[ end trace a7531c1ed5269e84 ]--- c6xxvf b002:00:00.0: Failed to register UIO devices c6xxvf b002:00:00.0: Failed to register UIO devices Signed-off-by: Lang Dai Link: https://lore.kernel.org/r/1600054002-17722-1-git-send-email-lang.dai@intel.com Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sasha Levin --- drivers/uio/uio.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c index 7c18536a3742a..4fc94b5e15ef4 100644 --- a/drivers/uio/uio.c +++ b/drivers/uio/uio.c @@ -1009,8 +1009,6 @@ void uio_unregister_device(struct uio_info *info) idev = info->uio_dev; - uio_free_minor(idev); - mutex_lock(&idev->info_lock); uio_dev_del_attributes(idev); @@ -1022,6 +1020,8 @@ void uio_unregister_device(struct uio_info *info) device_unregister(&idev->dev); + uio_free_minor(idev); + return; } EXPORT_SYMBOL_GPL(uio_unregister_device); -- 2.27.0