Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp3042332pxb; Fri, 12 Feb 2021 07:50:44 -0800 (PST) X-Google-Smtp-Source: ABdhPJxDfORSE9P3+IvHuGjiIlz9x/zJsYIELdVAaeY5su64LWEfFzmY9Fm9eqNr2KN3voXx9pQ8 X-Received: by 2002:a05:600c:4c11:: with SMTP id d17mr3365271wmp.86.1613145043949; Fri, 12 Feb 2021 07:50:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1613145043; cv=none; d=google.com; s=arc-20160816; b=XyrHkU1yg7rIgmM/IydFUqukN4ereSXb797eZ5zrOeKfitRID6odE60sUeEwJgwjpK paDucqWLpFWSJaM634VuOxmXsO+bs7QXp4NrELKOsDeAkSDTwJ7FBP08SRnFJMSR2+XD gzYZhohDPMgiZ3Es1dsvv07OrKzzmV3Raz8E3oVv3MZnEYLeFGjsAZgSg7ccSAm5Sje6 84FnpJ1MAjlLXGimgwWhm5QD+LweznOnMm4zj8qfcNhIu+YrK0ERcO+nezk3j2GQk8fq oIrRC05oUBeXZGKRJbPUwDq7I8Z+fFSzbRltszkU2jeSJB/k7AJrHHK5uJ3lY6v9zvRa 6DTQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=aTFeszovYe2c6vzTI6V8JopupF2zoybJSx7GeZE+ppw=; b=XfujSk4G5+0KbZoaw0xrQJ1r5TMcsR0je9YhbIoKGwtihLEmclzvXfAa3s+dg8L3hC nHGOvOyCXWyeV9f+4/L0YJPTo78X160Vz2IX68Wo7ntAiRtkVjRqGW5+rZ9N7Hg3Qgsh LXv4X7NEqf/8dhOZgoREaY6P8qyD9TKfz1IIfOoUTuv2fueJc/nKf9TrQX0GLDsEcB57 +yuK1STqUZYz70HHL4txpTfUusXwK2D5wuZ/yVm1QgnDloHRATuCeAaofEV+EbHdsuOr /4mECEOH8Hx562N+cvgisF0fUr5FRl6flFLY4ZPI8n7V57Oim+mlCpFvZMRIoyx37EA+ TeQQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=J6Zxe15m; 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=pass (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 c5si6584862edk.64.2021.02.12.07.50.20; Fri, 12 Feb 2021 07:50:43 -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=@linuxfoundation.org header.s=korg header.b=J6Zxe15m; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229558AbhBLPtp (ORCPT + 99 others); Fri, 12 Feb 2021 10:49:45 -0500 Received: from mail.kernel.org ([198.145.29.99]:58932 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231424AbhBLPtl (ORCPT ); Fri, 12 Feb 2021 10:49:41 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 1C3A264E02; Fri, 12 Feb 2021 15:48:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1613144940; bh=mPWU5J6FvfSdf87XeMnvIwDdBegHQnAd+4cz0Zhf7/k=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=J6Zxe15mIrkj4UIWWsMMaLMX4mZkklYfrPxMUuKCk1g49j+b4Lxx7yRiu86k/RKTn 8bFgVXJjWUJ2Q6P+0Qp3vgQMWjhwgVqvYo3UWlkPtsBBfbDypmISlr8Fr1VKsVpAIW HrW28m8dvXj0lco4hV66PanfVN8PEbhp9u+stFhg= Date: Fri, 12 Feb 2021 16:48:58 +0100 From: Greg KH To: Min Li Cc: "derek.kiernan@xilinx.com" , "dragan.cvetic@xilinx.com" , "arnd@arndb.de" , "linux-kernel@vger.kernel.org" Subject: Re: [PATCH net-next v2] misc: Add Renesas Synchronization Management Unit (SMU) support Message-ID: References: <1613092575-17311-1-git-send-email-min.li.xe@renesas.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Feb 12, 2021 at 03:39:03PM +0000, Min Li wrote: > > > + > > > + /* Only one open per device at a time */ > > > + if (!atomic_dec_and_test(&rsmu->open_count)) { > > > + atomic_inc(&rsmu->open_count); > > > + return -EBUSY; > > > > This does not do what you think it does, and does not prevent multiple > > applications from talking to your device at the same time. > > > > There is no need for this at all, as it does not work, sorry. If multiple apps > > talk to your device, it's their fault, not the kernel's fault, that things go > > wrong. > > > > And I thought that Arnd already told you to fix this? > > > > Hi Greg > > Sorry for not replying to the list, I am new so not very familiar with the process. > > Can you elaborate why it doesn't work? I kind of borrow the idea from > xilinx_sdfec.c and I don't see why it doesn't work. xilinx_sdfec.c has: static int xsdfec_dev_open(struct inode *iptr, struct file *fptr) { return 0; } Which isn't even needed at all, but it is NOT trying to keep people from calling open multiple times. As for why the above logic does not work in your driver, think of what happens if someone opens the character device node, and then calls dup(2) on it and passes that file descriptor off to another program. Or just calls it multiple times from different threads in the same program. The kernel does not know what is happening here, and so, "do not allow to be opened multiple times" does not do anything to keep userspace from actually writing to the device node from multiple processes or threads. So don't even try, it's not worth it. > I mean if an application failed at opening the device, how can it > proceed to talk the device without a file descriptor? See above for how to do this. thanks, greg k-h