From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <jia.guo@intel.com>
Received: from mga17.intel.com (mga17.intel.com [192.55.52.151])
 by dpdk.org (Postfix) with ESMTP id 685D537B0
 for <dev@dpdk.org>; Thu,  4 Oct 2018 07:05:36 +0200 (CEST)
X-Amp-Result: SKIPPED(no attachment in message)
X-Amp-File-Uploaded: False
Received: from fmsmga008.fm.intel.com ([10.253.24.58])
 by fmsmga107.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384;
 03 Oct 2018 22:05:34 -0700
X-ExtLoop1: 1
X-IronPort-AV: E=Sophos;i="5.54,338,1534834800"; d="scan'208";a="76068406"
Received: from jguo15x-mobl.ccr.corp.intel.com (HELO [10.249.174.2])
 ([10.249.174.2])
 by fmsmga008.fm.intel.com with ESMTP; 03 Oct 2018 22:05:30 -0700
To: "Burakov, Anatoly" <anatoly.burakov@intel.com>,
 stephen@networkplumber.org, bruce.richardson@intel.com,
 ferruh.yigit@intel.com, konstantin.ananyev@intel.com,
 gaetan.rivet@6wind.com, jingjing.wu@intel.com, thomas@monjalon.net,
 motih@mellanox.com, matan@mellanox.com, harry.van.haaren@intel.com,
 qi.z.zhang@intel.com, shaopeng.he@intel.com, bernard.iremonger@intel.com,
 arybchenko@solarflare.com
Cc: jblunck@infradead.org, shreyansh.jain@nxp.com, dev@dpdk.org,
 helin.zhang@intel.com, jerin.jacob@caviumnetworks.com
References: <1534503091-31910-1-git-send-email-jia.guo@intel.com>
 <1538485138-98076-1-git-send-email-jia.guo@intel.com>
 <1538485138-98076-5-git-send-email-jia.guo@intel.com>
 <628bc5ca-de09-0b54-8e1a-c0742ddb6890@intel.com>
From: Jeff Guo <jia.guo@intel.com>
Message-ID: <0cee54a9-99ec-c316-8d60-6169caf2c904@intel.com>
Date: Thu, 4 Oct 2018 13:05:30 +0800
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0) Gecko/20100101
 Thunderbird/60.0
MIME-Version: 1.0
In-Reply-To: <628bc5ca-de09-0b54-8e1a-c0742ddb6890@intel.com>
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 8bit
Content-Language: en-US
Subject: Re: [dpdk-dev] [PATCH v3 4/4] vfio: enable vfio hotplug by req
	notifier handler
X-BeenThere: dev@dpdk.org
X-Mailman-Version: 2.1.15
Precedence: list
List-Id: DPDK patches and discussions <dev.dpdk.org>
List-Unsubscribe: <https://mails.dpdk.org/options/dev>,
 <mailto:dev-request@dpdk.org?subject=unsubscribe>
List-Archive: <http://mails.dpdk.org/archives/dev/>
List-Post: <mailto:dev@dpdk.org>
List-Help: <mailto:dev-request@dpdk.org?subject=help>
List-Subscribe: <https://mails.dpdk.org/listinfo/dev>,
 <mailto:dev-request@dpdk.org?subject=subscribe>
X-List-Received-Date: Thu, 04 Oct 2018 05:05:38 -0000


On 10/2/2018 10:15 PM, Burakov, Anatoly wrote:
> On 02-Oct-18 1:58 PM, Jeff Guo wrote:
>> When device is be hot-unplugged, the vfio kernel module will sent req
>> notifier to request user space to release the allocated resources at
>> first. After that, vfio kernel module will detect the device disappear,
>> and then delete the device in kernel.
>>
>> This patch aim to add req notifier processing to enable hotplug for 
>> vfio.
>> By enable the req notifier monitoring and register the notifier 
>> callback,
>> when device be hot-unplugged, the hot-unplug handler will be called to
>> process hotplug for vfio.
>>
>> Signed-off-by: Jeff Guo <jia.guo@intel.com>
>> ---
>> v3->v2:
>> change some code style and typo.
>> ---
>
> <snip>
>
>> +/* enable notifier (only enable req now) */
>> +static int
>> +pci_vfio_enable_notifier(struct rte_pci_device *dev, int vfio_dev_fd)
>> +{
>> +    int ret;
>> +    int fd = -1;
>> +
>> +    /* set up an eventfd for req notifier */
>> +    fd = eventfd(0, EFD_NONBLOCK | EFD_CLOEXEC);
>> +    if (fd < 0) {
>> +        RTE_LOG(ERR, EAL, "Cannot set up eventfd, error %i (%s)\n",
>> +            errno, strerror(errno));
>> +        return -1;
>> +    }
>> +
>> +    dev->req_notifier_handler.fd = fd;
>> +    dev->req_notifier_handler.type = RTE_INTR_HANDLE_VFIO_REQ;
>> +    dev->req_notifier_handler.vfio_dev_fd = vfio_dev_fd;
>> +    ret = rte_intr_callback_register(&dev->req_notifier_handler,
>> +                     pci_vfio_req_handler,
>> +                     (void *)&dev->device);
>> +    if (ret) {
>> +        RTE_LOG(ERR, EAL, "Fail to register req notifier handler.\n");
>> +        goto error;
>
> At this point (and further down as well), if we go to error, we've 
> already modified the req_notifier_handler data. Do we need to 
> overwrite it? Maybe just do these operations on a local struct, and 
> then do a memcpy into dev->req_notifier_handler on success?
>

I think just overwrite it in error process should be clear and simple.