Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp2037432pxb; Thu, 11 Feb 2021 02:40:00 -0800 (PST) X-Google-Smtp-Source: ABdhPJxPI/HRLFr7YqTLmrKvWGbfhbXi1Di8e3jQ8O6cN7jPU/+6wEdOmhobUdXvthmvbjkbeNvP X-Received: by 2002:a17:907:20a8:: with SMTP id pw8mr7350554ejb.9.1613040000531; Thu, 11 Feb 2021 02:40:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1613040000; cv=none; d=google.com; s=arc-20160816; b=uxG8kGaU+SkuJiCAeDbRpoDcJK8VuUZtRIeohcO2ZeVlpxq0aZcGias/ZF1SOG0Bs5 VCWW8A31TCJ1E/4oAG7JdRiHJPj92j5+EutiARG45pkqC0cg7e+giRoY82KvAp5WgZSc DaZ4p8ubHNlFkGo4yKSTLU0WAoc6R2QKQTaj4n6sAmcugQYquHcTzEOnfr4/3doZ9lMo jXcYCk4CG4SkxyYlC2kmdIUAg4Pve0NN+NZz93CwRmenin860ushPCvsjFE5JVOInMVL OHR5rIMhiyHMqy9yUVwTdG5kntTBKfpgYFSUoDPMjoJ5PAlDaENOVT7qmxfYo/F8dTd6 F+7Q== 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=0zryVSf9BEpYZDoHCjM7Bw/ytwe45JOkhBFfbg+Rbpo=; b=rCQSLaCjV3NpQ6in3nHbomVmdrMMGpCtXKKvLNLPMGntvLLvT74+J3B/vySwZT7xYI f2djawDJ+MdGLzFjReeE81jQz25+qH7xzZvDOLogNH7Xvy3YaiQ4zvwpn3wauYmKF2/S 4M0Z2nLwGHdkSxDqhUY5UnWSMhnlXfE5mMuC1eE84qvpc9iNOz7ypfH/LLg2Pm7gnlx7 ypd1y8L2MGwU8kDMsQiLnbWVStXlTAX2mhGOlXzfGnuVZWgIy4zhLuYXc/SFokvRY6Qr 2MbTjhdhjHVhh/G5fBUG3iKYHEPgZyt9WDaaQOztAzRjct8msGGnFjHHa655stb7peVc cFyA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=l78m0+5G; 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 s20si3853956eji.61.2021.02.11.02.39.36; Thu, 11 Feb 2021 02:40:00 -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=l78m0+5G; 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 S229965AbhBKKin (ORCPT + 99 others); Thu, 11 Feb 2021 05:38:43 -0500 Received: from mail.kernel.org ([198.145.29.99]:52916 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229793AbhBKKeO (ORCPT ); Thu, 11 Feb 2021 05:34:14 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id F0B3964E01; Thu, 11 Feb 2021 10:33:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1613039609; bh=cXsCKIo6t7y9suqyuT1kz/DnYOo45INEomlNnDReod0=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=l78m0+5GidaiYGieGogBdTs74ImmqQBrQQJ55JXksub3LWxcV1jc5QF0ipcqjU2Jn yKyfijvxh19Vjo1xCvxZDimVgtdj+Tjlsw3CMgoyVAHCrlap8MVTJETQVOTPwhjtdQ JgPxRRQdAnIWqAkaynezCQY//nEI/3+w3wKmOkt0= Date: Thu, 11 Feb 2021 11:33:25 +0100 From: Greg Kroah-Hartman To: Gustavo Pimentel Cc: "linux-doc@vger.kernel.org" , "linux-pci@vger.kernel.org" , "linux-kernel@vger.kernel.org" , Derek Kiernan , Dragan Cvetic , Arnd Bergmann , Andrew Morton , Jonathan Corbet , Bjorn Helgaas Subject: Re: [PATCH v5 1/6] misc: Add Synopsys DesignWare xData IP driver Message-ID: References: <02835da8fc8c9293fecbe666a8db3fb79276fdde.1613034397.git.gustavo.pimentel@synopsys.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 Thu, Feb 11, 2021 at 10:21:07AM +0000, Gustavo Pimentel wrote: > On Thu, Feb 11, 2021 at 9:59:26, Greg Kroah-Hartman > wrote: > > > On Thu, Feb 11, 2021 at 09:50:33AM +0000, Gustavo Pimentel wrote: > > > On Thu, Feb 11, 2021 at 9:30:16, Greg Kroah-Hartman > > > wrote: > > > > > > > On Thu, Feb 11, 2021 at 10:08:38AM +0100, Gustavo Pimentel wrote: > > > > > +static ssize_t write_show(struct device *dev, struct device_attribute *attr, > > > > > + char *buf) > > > > > +{ > > > > > + struct pci_dev *pdev = to_pci_dev(dev); > > > > > + struct dw_xdata *dw = pci_get_drvdata(pdev); > > > > > + u64 rate; > > > > > + > > > > > + mutex_lock(&dw->mutex); > > > > > + dw_xdata_perf(dw, &rate, true); > > > > > + mutex_unlock(&dw->mutex); > > > > > + > > > > > + return sysfs_emit(buf, "%llu MB/s\n", rate); > > > > > > > > Do not put units in a sysfs file, that should be in the documentation, > > > > otherwise this forces userspace to "parse" the units which is a mess. > > > > > > Okay. > > > > > > > > > > > Same for the other sysfs file. > > > > > > > > And why do you need a lock for this show function? > > > > > > Maybe I understood it wrongly, please correct me in that case. The > > > dw_xdata_perf() is called on the write_show() and read_show(), to avoid a > > > possible race condition between those calls, I have added this mutex. > > > > What race? If the value changes with a write right after a read, what > > does it matter? > > > > What exactly are you trying to protect with this lock? > > The write_store() does a procedure to enable the traffic on the write > direction, however, the write_show() does a different procedure to > calculate the link throughput speed, which uses a different set of > registers on the HW. > > Similar happens on the read_store() (which enable the traffic on the read > direction) and on the read_show() > > To summarize write_store() follows the same approach of read_store() and > the write_show() of the read_show(). I added the mutex on those functions > for instance to avoid while during the write_show() call the possibility > of been called the read_show() messing up the link throughput speed > calculation. > Or while during the write_store() call to be called the read_store or > even the write_show() for the same reasons. If you need to protect these types of things, but the lock down in the function that does this, not above it which forces people to audit everything and manually try to determine what lock is doing what for what. Make it impossible to get wrong, as it is, you have to do extra work here to keep things working properly, always a bad idea in an api. thanks, greg k-h