Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp6967134imm; Wed, 27 Jun 2018 17:11:07 -0700 (PDT) X-Google-Smtp-Source: AAOMgpfzb/5m3tEhUhjePVC7YgdEaJ+wyEcWKHm0dOwmxH0cmtwEc8rPTr6gTlZliog1Jw8APNQj X-Received: by 2002:a62:2fc4:: with SMTP id v187-v6mr7941027pfv.100.1530144667625; Wed, 27 Jun 2018 17:11:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530144667; cv=none; d=google.com; s=arc-20160816; b=F8KtN5i9sXrUmith0ctyPuIwLBQaahtHEB3L99LkH5ZOqECZtxKFrUa7QmCEDExBX3 jNeWPC1f/ggxS8dCQczErUh6qyju0QeejtjCroCNOJ41b+ZngqqQ7iQoPOHZUdHQsPqW 2GxgyUnfoI8oCEAmwoMg+OxSSpgcxoPim1A39eCn88EVu+EjAMgv/sLLLBcCWWZw6uLJ ghdOciivptQf2b8Xx6VDYLluYrf4ohKpgdCPfgSzduBR4kHMtfpOnleEoGQpfuexIQ9z Q/eQGNcNTDdw9FxHVzpM+pFyRUpsYnRP7oydjKdExooD2W/cN159hZg9IxWU20SUzlZM vx0Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature :arc-authentication-results; bh=IFKn6xRsSTgFny6QNWq55VDDsA/uwx1hLmdthIHzmu8=; b=gDGHcDa+Iz5j307aIR8dzvBBC3OiUQXswN7Sbxv0pLxB7lw2McrPupdSuBbCVTeQZT dfQ/icQIKMjmYpQ8ciCAfUE/fvu58Xl+K9czMISkpBPZL/2eQAqWQ/MOxuZJ9PduyUxP MRgaBTbaB3+mafwHs/o5Z+5hc516o05eq6EWm09InqSZXfb83Rz7foZI8q/qclmUjG8G WtabToww0H5gFyg/iS1xwOPPktDhuGZ385Ma2hiZ4eDdbBVKZKNYIkgBY03QsftEE1mg OfOb0posZDYXyF1TiJ2Xl0Jf6FbK8UFzxlBtPyaKovlTx7P4IRqCh1uQz4KnCSzUkko/ jAow== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=1WBfto+y; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k6-v6si2772904pgp.127.2018.06.27.17.10.52; Wed, 27 Jun 2018 17:11:07 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=1WBfto+y; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S966073AbeF0VXy (ORCPT + 99 others); Wed, 27 Jun 2018 17:23:54 -0400 Received: from mail.kernel.org ([198.145.29.99]:38854 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S966033AbeF0VXt (ORCPT ); Wed, 27 Jun 2018 17:23:49 -0400 Received: from mail-yw0-f182.google.com (mail-yw0-f182.google.com [209.85.161.182]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 81098244E3; Wed, 27 Jun 2018 21:23:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1530134628; bh=C3PpiBRhgcJvs3jsJWwbiZzWKfAkJRfGton/zYKcjM8=; h=In-Reply-To:References:From:Date:Subject:To:Cc:From; b=1WBfto+yDbfYaFNhg2XZ1zKGEfk2WFmCaUYdExdV2BkJCd+zZVpO9/B73cSxB864i 1qOeRcg4zjQwSkN3O2XS8I7P0dnw80ZJxU+HFPC5pf3PbHlOVWpGgRCL0SVf68tfNh BhBOV9NVki1xQZedXXbvwsuAN+GcjFJC5MelEFaw= Received: by mail-yw0-f182.google.com with SMTP id t18-v6so1225144ywg.2; Wed, 27 Jun 2018 14:23:48 -0700 (PDT) X-Gm-Message-State: APt69E3ysjZargR2Zc8wveQbEx90Tbb+GVfXt0uRe+I3EyTd6iRyIFgO +ETZqh9yTM4tenUdTYGU6gM5ZEfG1/tZGJozc3Q= X-Received: by 2002:a0d:d451:: with SMTP id w78-v6mr531153ywd.370.1530134627741; Wed, 27 Jun 2018 14:23:47 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a25:8182:0:0:0:0:0 with HTTP; Wed, 27 Jun 2018 14:23:07 -0700 (PDT) In-Reply-To: <1569671.PEFH9RgftX@pcbe13614> References: <4617134.5euanDEBgJ@pcbe13614> <22840601.TEhG8FuRZq@pcbe13614> <1569671.PEFH9RgftX@pcbe13614> From: Alan Tull Date: Wed, 27 Jun 2018 16:23:07 -0500 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: fpga: fpga_mgr_get() buggy ? To: federico.vaga@cern.ch Cc: Moritz Fischer , linux-fpga@vger.kernel.org, linux-kernel Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jun 27, 2018 at 4:25 AM, Federico Vaga wrote: > Hi Alan, > > On Tuesday, 26 June 2018 23:00:46 CEST Alan Tull wrote: >> On Fri, Jun 22, 2018 at 2:53 AM, Federico Vaga >> wrote: >> >> Hi Federico, >> >> >> > What is buggy is the function fpga_mgr_get(). >> >> > That patch has been done to allow multiple FPGA manager >> >> > instances >> >> > to be linked to the same device (PCI it says). But function >> >> > fpga_mgr_get() will return only the first found: what about the >> >> > others? >> >> I've had more time with this, I agree with you. I didn't intend to >> limit us to one manager per parent device. >> >> >> > Then, all load kernel-doc comments says: >> >> > >> >> > "This code assumes the caller got the mgr pointer from >> >> > of_fpga_mgr_get() or fpga_mgr_get()" >> >> > >> >> > but that function does not allow me to get, for instance, the >> >> > second FPGA manager on my card. >> >> > >> >> > Since, thanks to this patch I'm actually the creator of the >> >> > fpga_manager structure, I do not need to use fpga_mgr_get() to >> >> > retrieve that data structure. >> >> > Despite this, I believe we still need to increment the module >> >> > reference counter (which is done by fpga_mgr_get()). >> >> > >> >> > We can fix this function by just replacing the argument from >> >> > 'device' to 'fpga_manager' (the one returned by create() ). >> >> >> >> At first thought, that's what I'd want. >> >> >> >> > Alternatively, we >> >> > can add an 'owner' field in "struct fpga_manager_ops" and 'get' >> >> > it >> >> > when we use it. Or again, just an 'owner' argument in the >> >> > create() >> >> > function. >> >> >> >> It seems like we shouldn't have to do that. >> > >> > Why? >> >> OK yes, I agree; the kernel has a lot of examples of doing this. >> >> I'll have to play with it, I'll probably add the owner arg to the >> create function, add owner to struct fpga_manager, and save. > > I have two though about this. > > 1. file_operation like approach. The onwer is associated to the FPGA > manager operation. Whenever the FPGA manager wants to use an operation > it get/put the module owner of these operations (because this is what > we need to protect). With this the user is not directly involved, read > it as less code, less things to care about. And probably there is no > need for fpga_manager_get(). How does try_module_get fit into this scheme? I think this proposal #1 is missing the point of what the reference count increment is meant to do. Or am I misunderstanding? How does that keep the module from being unloaded 1/3 way through programming a FPGA? IIUC you are saying that the reference count would be incremented before doing the manager ops .write_init, then decremented again afterwards, incremented before each call to .write, decremented afterwards, then the same for .write_complete. > > 2. fpga_manager onwer, we can still play the game above but > conceptually, from the user point of view, I see it like the driver > that creates the fpga_manager instance becomes the owner of it. I think that's what's happening. And can continue to happen, adding the owner parameter to fpga_mgr_create. > I > think that this is not true, How do you figure that? fpga_mgr_create() is called with pdev->dev from each of the FPGA manager's probe functions. It stores dev as the parent: mgr->dev.parent = dev; > the fpga_manager structure is completely > used by the FPGA manager module and the driver use it as a token to > access the FPGA manager API. I hope my point is clear :) > > I'm more for the solution 1. > >> >> > I'm proposing these alternatives because I'm not sure that >> >> > >> >> > this is correct: >> >> > if (!try_module_get(dev->parent->driver->owner)) >> >> > >> >> > What if the device does not have a driver? Do we consider the >> >> > following a valid use case? >> >> > >> >> > >> >> > probe(struct device *dev) { >> >> > >> >> > struct device *mydev; >> >> > >> >> > mydev->parent = dev; >> >> > device_register(mydev); >> >> > fpga_mrg_create(mydev, ....); >> >> > >> >> > } >> >> Sure >> >> >> When would you want to do that? >> > >> > Not sure when, I'm in the middle of some other development and I >> > stumbled into this issue. But of course I can do it ... at some >> > point> >> > :) >> >> I was meaning to ask something else. > > I see, you meant the example about the "virtual device" without > driver. I do not have a true example, but this is a possible case I > think we should support it or not (check this on register()) I think we should support this use, yes. Alan > >> I don't mind writing this and would be interested in your review/ >> feedback. Thanks again for seeing this and for the thoughtful >> analysis. > > I'm here for any feedback/review :)