Skip to contentSkip to conversation

vhost: Fix `struct file' leakage in `eventfd_link'

PATCH Applied Pavel Boldin 3 participants 22 messages Mar 23, 2015 – Mar 27, 2015 8 messages not in the archive

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 vhost: Fix `struct file' leakage in `eventfd_link'

Due to increased struct file's reference counter subsequent call to filp_close' does not free the struct file'. Prepend fput' call to decrease the reference counter.

---
 lib/librte_vhost/eventfd_link/eventfd_link.c | 1 +
 1 file changed, 1 insertion(+)
lib/librte_vhost/eventfd_link/eventfd_link.c +1 -0
index 7755dd6..62c45c8 100644
@@ -117,6 +117,7 @@ eventfd_link_ioctl(struct file *f, unsigned int ioctl, unsigned long arg)
 		 * Release the existing eventfd in the source process
 		 */
 		spin_lock(&files->file_lock);
+		fput(file);
 		filp_close(file, files);
 		fdt = files_fdtable(files);
 		fdt->fd[eventfd_copy.source_fd] = NULL;
Signature · 1 line
1.9.1
#1 lore raw
Quoted 14 lines · Pavel Boldin

Due to increased struct file's reference counter subsequent call to filp_close' does not free the struct file'. Prepend fput' call to decrease the reference counter.

---
 lib/librte_vhost/eventfd_link/eventfd_link.c | 1 +
 1 file changed, 1 insertion(+)
lib/librte_vhost/eventfd_link/eventfd_link.c +0 -0
index 7755dd6..62c45c8 100644

lib/librte_vhost/eventfd_link/eventfd_link.c eventfd_link_ioctl(struct file *f, unsigned int ioctl, unsigned long arg) · line 120

Quoted 4 lines
lib/librte_vhost/eventfd_link/eventfd_link.c +1 -0
@@ -117,6 +117,7 @@ eventfd_link_ioctl(struct file *f, unsigned int ioctl, unsigned long arg)
 		 * Release the existing eventfd in the source process
 		 */
 		spin_lock(&files->file_lock);
+		fput(file);

Could we just call atomic_long_dec here?

Quoted 3 lines
lib/librte_vhost/eventfd_link/eventfd_link.c +0 -0
 		filp_close(file, files);
 		fdt = files_fdtable(files);
 		fdt->fd[eventfd_copy.source_fd] = NULL;

A message that is not in the archive (sent off-list or not yet received): C37D651A908B024F974696C65296B57B0F3F1E14-0J0gbvR4kThpB2pF5aRoyrfspsVTdybXVpNB7YpNyf8@public.gmane.org

#3 lore raw
Quoted 17 lines · Huawei

Review

Quoted 10 lines · Pavel Boldin

Due to increased struct file's reference counter subsequent call to filp_close' does not free the struct file'. Prepend fput' call to decrease the reference counter.

---
 lib/librte_vhost/eventfd_link/eventfd_link.c | 1 +
 1 file changed, 1 insertion(+)
(quoted diff) +0 -0

b/lib/librte_vhost/eventfd_link/eventfd_link.c

lib/librte_vhost/eventfd_link/eventfd_link.c eventfd_link_ioctl(struct file *f, unsigned int

Quoted 4 lines

index 7755dd6..62c45c8 100644

lib/librte_vhost/eventfd_link/eventfd_link.c +0 -0
@@ -117,6 +117,7 @@ eventfd_link_ioctl(struct file *f, unsigned int

ioctl, unsigned long arg)

Quoted 6 lines

lib/librte_vhost/eventfd_link/eventfd_link.c eventfd_link_ioctl(struct file *f, unsigned int ioctl, unsigned long arg) · line 120

Quoted 4 lines
lib/librte_vhost/eventfd_link/eventfd_link.c +1 -0
               * Release the existing eventfd in the source process
               */
              spin_lock(&files->file_lock);
+             fput(file);

Could we just call atomic_long_dec here?

We can but I don't like breaking encapsulation (which is broken anyway by the code). So, there is a special method and we should use it in my opinion.

Pavel

Quoted 5 lines
              filp_close(file, files);
Quoted 2 lines
lib/librte_vhost/eventfd_link/eventfd_link.c +0 -0
              fdt = files_fdtable(files);
              fdt->fd[eventfd_copy.source_fd] = NULL;
#4 lore raw

On 3/23/2015 10:37 PM, Pavel Boldin wrote:

On Mon, Mar 23, 2015 at 4:21 PM, Xie, Huawei <[email protected]<mailto:[email protected]>> wrote:

Quoted 14 lines · Pavel Boldin

Due to increased struct file's reference counter subsequent call to filp_close' does not free the struct file'. Prepend fput' call to decrease the reference counter.

---
 lib/librte_vhost/eventfd_link/eventfd_link.c | 1 +
 1 file changed, 1 insertion(+)
lib/librte_vhost/eventfd_link/eventfd_link.c +0 -0
index 7755dd6..62c45c8 100644

lib/librte_vhost/eventfd_link/eventfd_link.c eventfd_link_ioctl(struct file *f, unsigned int ioctl, unsigned long arg) · line 120

Quoted 4 lines
lib/librte_vhost/eventfd_link/eventfd_link.c +1 -0
@@ -117,6 +117,7 @@ eventfd_link_ioctl(struct file *f, unsigned int ioctl, unsigned long arg)
               * Release the existing eventfd in the source process
               */
              spin_lock(&files->file_lock);
+             fput(file);

Could we just call atomic_long_dec here?

We can but I don't like breaking encapsulation (which is broken anyway by the code). So, there is a special method and we should use it in my opinion. it is increased by atomic_long_inc_not_zero so why don't we use the symmetric function?

Pavel

Quoted 3 lines
lib/librte_vhost/eventfd_link/eventfd_link.c +0 -0
              filp_close(file, files);
              fdt = files_fdtable(files);
              fdt->fd[eventfd_copy.source_fd] = NULL;

A message that is not in the archive (sent off-list or not yet received): C37D651A908B024F974696C65296B57B0F3F1F75-0J0gbvR4kThpB2pF5aRoyrfspsVTdybXVpNB7YpNyf8@public.gmane.org

#6 lore raw
Quoted 27 lines · Huawei

On 3/23/2015 10:37 PM, Pavel Boldin wrote:

On Mon, Mar 23, 2015 at 4:21 PM, Xie, Huawei <[email protected]<mailto:
[email protected]>> wrote:

Quoted 5 lines · Pavel Boldin

Due to increased struct file's reference counter subsequent call to filp_close' does not free the struct file'. Prepend fput' call to decrease the reference counter.

pboldin-nYU0QVwCCFFWk0Htik3J/[email protected]>>

Review

Quoted 5 lines
---
 lib/librte_vhost/eventfd_link/eventfd_link.c | 1 +
 1 file changed, 1 insertion(+)
(quoted diff) +0 -0

b/lib/librte_vhost/eventfd_link/eventfd_link.c

lib/librte_vhost/eventfd_link/eventfd_link.c eventfd_link_ioctl(struct file *f, unsigned int

Quoted 4 lines

index 7755dd6..62c45c8 100644

lib/librte_vhost/eventfd_link/eventfd_link.c +0 -0
@@ -117,6 +117,7 @@ eventfd_link_ioctl(struct file *f, unsigned int

ioctl, unsigned long arg)

lib/librte_vhost/eventfd_link/eventfd_link.c eventfd_link_ioctl(struct file *f, unsigned int ioctl, unsigned long arg) · line 120

Quoted 4 lines
lib/librte_vhost/eventfd_link/eventfd_link.c +1 -0
               * Release the existing eventfd in the source process
               */
              spin_lock(&files->file_lock);
+             fput(file);
Quoted 7 lines

Could we just call atomic_long_dec here?

We can but I don't like breaking encapsulation (which is broken anyway by the code). So, there is a special method and we should use it in my opinion. it is increased by atomic_long_inc_not_zero so why don't we use the symmetric function?

The code with atomic_long_inc_not_zero' call is a copy-paste of the fget' function. If we want to make it clear we should make a separate function and name it so: `fget_from_files'.

Second thing is: another thread of the same processor can call the sys_close' on the fd' and this will dereference counter so fput' will correctly free the struct file'. Using atomic_long_dec' will leak a struct file' and print a KERN_ERR message by `filp_close'.

So, the common thing is to use appropriate functions and don't reinvent the wheel.

Pavel

Quoted 11 lines

Pavel

Quoted 3 lines
lib/librte_vhost/eventfd_link/eventfd_link.c +0 -0
              filp_close(file, files);
              fdt = files_fdtable(files);
              fdt->fd[eventfd_copy.source_fd] = NULL;
#7 lore raw

On 3/23/2015 10:52 PM, Pavel Boldin wrote:

On Mon, Mar 23, 2015 at 4:41 PM, Xie, Huawei <[email protected]<mailto:[email protected]>> wrote:
On 3/23/2015 10:37 PM, Pavel Boldin wrote:

On Mon, Mar 23, 2015 at 4:21 PM, Xie, Huawei <[email protected]<mailto:[email protected]><mailto:[email protected]<mailto:[email protected]>>> wrote:

Quoted 14 lines · Pavel Boldin

Due to increased struct file's reference counter subsequent call to filp_close' does not free the struct file'. Prepend fput' call to decrease the reference counter.

---
 lib/librte_vhost/eventfd_link/eventfd_link.c | 1 +
 1 file changed, 1 insertion(+)
lib/librte_vhost/eventfd_link/eventfd_link.c +0 -0
index 7755dd6..62c45c8 100644

lib/librte_vhost/eventfd_link/eventfd_link.c eventfd_link_ioctl(struct file *f, unsigned int ioctl, unsigned long arg) · line 120

Quoted 4 lines
lib/librte_vhost/eventfd_link/eventfd_link.c +1 -0
@@ -117,6 +117,7 @@ eventfd_link_ioctl(struct file *f, unsigned int ioctl, unsigned long arg)
               * Release the existing eventfd in the source process
               */
              spin_lock(&files->file_lock);
+             fput(file);

Could we just call atomic_long_dec here?

We can but I don't like breaking encapsulation (which is broken anyway by the code). So, there is a special method and we should use it in my opinion.
it is increased by atomic_long_inc_not_zero so why don't we use the symmetric function?
The code with atomic_long_inc_not_zero' call is a copy-paste of the fget' function. If we want to make it clear we should make a separate function and name it so: `fget_from_files'.

I don't understand why there is a (exact?) copy&paste of fget there. :).
Maybe you could post a patchset, first replace the copy/paste with fget and then this patch. It will looks much clearer.
Second thing is: another thread of the same processor can call the sys_close' on the fd' and this will dereference counter so fput' will correctly free the struct file'. Using atomic_long_dec' will leak a struct file' and print a KERN_ERR message by `filp_close'.

So, the common thing is to use appropriate functions and don't reinvent the wheel.

Pavel

Pavel

Quoted 3 lines
lib/librte_vhost/eventfd_link/eventfd_link.c +0 -0
              filp_close(file, files);
              fdt = files_fdtable(files);
              fdt->fd[eventfd_copy.source_fd] = NULL;

A message that is not in the archive (sent off-list or not yet received): C37D651A908B024F974696C65296B57B0F3F240D-0J0gbvR4kThpB2pF5aRoyrfspsVTdybXVpNB7YpNyf8@public.gmane.org

#9 lore raw

Huawei,
This thread is unreadable because your mailer is not quoting. Please check. Thanks

2015-03-23 15:16, Xie, Huawei:

Quoted 49 lines · Pavel Boldin

On Mon, Mar 23, 2015 at 4:41 PM, Xie, Huawei <[email protected]<mailto:[email protected]>> wrote:
On 3/23/2015 10:37 PM, Pavel Boldin wrote:

On Mon, Mar 23, 2015 at 4:21 PM, Xie, Huawei <[email protected]<mailto:[email protected]><mailto:[email protected]<mailto:[email protected]>>> wrote:

Quoted 14 lines · Pavel Boldin

Due to increased struct file's reference counter subsequent call to filp_close' does not free the struct file'. Prepend fput' call to decrease the reference counter.

---
 lib/librte_vhost/eventfd_link/eventfd_link.c | 1 +
 1 file changed, 1 insertion(+)
lib/librte_vhost/eventfd_link/eventfd_link.c +0 -0
index 7755dd6..62c45c8 100644

lib/librte_vhost/eventfd_link/eventfd_link.c eventfd_link_ioctl(struct file *f, unsigned int ioctl, unsigned long arg) · line 120

Quoted 4 lines
lib/librte_vhost/eventfd_link/eventfd_link.c +1 -0
@@ -117,6 +117,7 @@ eventfd_link_ioctl(struct file *f, unsigned int ioctl, unsigned long arg)
               * Release the existing eventfd in the source process
               */
              spin_lock(&files->file_lock);
+             fput(file);

Could we just call atomic_long_dec here?

We can but I don't like breaking encapsulation (which is broken anyway by the code). So, there is a special method and we should use it in my opinion.
it is increased by atomic_long_inc_not_zero so why don't we use the symmetric function?
The code with atomic_long_inc_not_zero' call is a copy-paste of the fget' function. If we want to make it clear we should make a separate function and name it so: `fget_from_files'.

I don't understand why there is a (exact?) copy&paste of fget there. :).
Maybe you could post a patchset, first replace the copy/paste with fget and then this patch. It will looks much clearer.
Second thing is: another thread of the same processor can call the sys_close' on the fd' and this will dereference counter so fput' will correctly free the struct file'. Using atomic_long_dec' will leak a struct file' and print a KERN_ERR message by `filp_close'.

So, the common thing is to use appropriate functions and don't reinvent the wheel.

Pavel

Pavel

Quoted 3 lines
lib/librte_vhost/eventfd_link/eventfd_link.c +0 -0
              filp_close(file, files);
              fdt = files_fdtable(files);
              fdt->fd[eventfd_copy.source_fd] = NULL;
#10 lore raw
In reply to a message not in the archive
Quoted 44 lines · Huawei

On 3/23/2015 10:52 PM, Pavel Boldin wrote:

On Mon, Mar 23, 2015 at 4:41 PM, Xie, Huawei <[email protected]<mailto:
[email protected]>> wrote:
On 3/23/2015 10:37 PM, Pavel Boldin wrote:

On Mon, Mar 23, 2015 at 4:21 PM, Xie, Huawei <[email protected]<mailto:
[email protected]><mailto:[email protected]<mailto:
[email protected]>>> wrote:

Quoted 5 lines · Pavel Boldin

Due to increased struct file's reference counter subsequent call to filp_close' does not free the struct file'. Prepend fput' call to decrease the reference counter.

pboldin-nYU0QVwCCFFWk0Htik3J/[email protected]><mailto:pboldin-nYU0QVwCCFFWk0Htik3J/[email protected]<mailto:
pboldin-nYU0QVwCCFFWk0Htik3J/[email protected]>>>

Review

Quoted 5 lines
---
 lib/librte_vhost/eventfd_link/eventfd_link.c | 1 +
 1 file changed, 1 insertion(+)
(quoted diff) +0 -0

b/lib/librte_vhost/eventfd_link/eventfd_link.c

lib/librte_vhost/eventfd_link/eventfd_link.c eventfd_link_ioctl(struct file *f, unsigned int

Quoted 4 lines

index 7755dd6..62c45c8 100644

lib/librte_vhost/eventfd_link/eventfd_link.c +0 -0
@@ -117,6 +117,7 @@ eventfd_link_ioctl(struct file *f, unsigned int

ioctl, unsigned long arg)

lib/librte_vhost/eventfd_link/eventfd_link.c eventfd_link_ioctl(struct file *f, unsigned int · line 120

Quoted 4 lines
lib/librte_vhost/eventfd_link/eventfd_link.c +1 -0
               * Release the existing eventfd in the source process
               */
              spin_lock(&files->file_lock);
+             fput(file);

Could we just call atomic_long_dec here?

We can but I don't like breaking encapsulation (which is broken anyway by the code). So, there is a special method and we should use it in my opinion. it is increased by atomic_long_inc_not_zero so why don't we use the symmetric function?
The code with atomic_long_inc_not_zero' call is a copy-paste of the fget' function. If we want to make it clear we should make a separate function and name it so: `fget_from_files'.

Quoted 4 lines

I don't understand why there is a (exact?) copy&paste of fget there. :). Maybe you could post a patchset, first replace the copy/paste with fget and then this patch. It will looks much clearer.

The code of this module received little to none review and requires some love at the moment.

I wanted to refactor the module completely but Thomas said it is not going to go into the 2.0. So I decided to make a simple one-line fix.

If you are interested this [0] is the latest version of the refactoring patch.

I can provide you with an application that checks that there is indeed no leakage and ensures that the `eventfd' moving works. It is being used in our builds as a test [1]. The code is "heredoc"ed in [2]

[0] http://dpdk.org/dev/patchwork/patch/4113/
[1] https://review.fuel-infra.org/#/c/4639/
[2] https://review.fuel-infra.org/#/c/4639/3/tests/runtests.sh

Pavel

Quoted 23 lines

Second thing is: another thread of the same processor can call the sys_close' on the fd' and this will dereference counter so fput' will correctly free the struct file'. Using atomic_long_dec' will leak a struct file' and print a KERN_ERR message by `filp_close'.

So, the common thing is to use appropriate functions and don't reinvent the wheel.

Pavel

Pavel

Quoted 3 lines
lib/librte_vhost/eventfd_link/eventfd_link.c +0 -0
              filp_close(file, files);
              fdt = files_fdtable(files);
              fdt->fd[eventfd_copy.source_fd] = NULL;
#11 lore raw

On 3/23/2015 11:27 PM, Pavel Boldin wrote:

On Mon, Mar 23, 2015 at 5:16 PM, Xie, Huawei <[email protected]<mailto:[email protected]>> wrote:
On 3/23/2015 10:52 PM, Pavel Boldin wrote:

On Mon, Mar 23, 2015 at 4:41 PM, Xie, Huawei <[email protected]<mailto:[email protected]><mailto:[email protected]<mailto:[email protected]>>> wrote:
On 3/23/2015 10:37 PM, Pavel Boldin wrote:

On Mon, Mar 23, 2015 at 4:21 PM, Xie, Huawei <[email protected]<mailto:[email protected]><mailto:[email protected]<mailto:[email protected]>><mailto:[email protected]<mailto:[email protected]><mailto:[email protected]<mailto:[email protected]>>>> wrote:

Quoted 14 lines · Pavel Boldin

Due to increased struct file's reference counter subsequent call to filp_close' does not free the struct file'. Prepend fput' call to decrease the reference counter.

---
 lib/librte_vhost/eventfd_link/eventfd_link.c | 1 +
 1 file changed, 1 insertion(+)
lib/librte_vhost/eventfd_link/eventfd_link.c +0 -0
index 7755dd6..62c45c8 100644

lib/librte_vhost/eventfd_link/eventfd_link.c eventfd_link_ioctl(struct file *f, unsigned int ioctl, unsigned long arg) · line 120

Quoted 4 lines
lib/librte_vhost/eventfd_link/eventfd_link.c +1 -0
@@ -117,6 +117,7 @@ eventfd_link_ioctl(struct file *f, unsigned int ioctl, unsigned long arg)
               * Release the existing eventfd in the source process
               */
              spin_lock(&files->file_lock);
+             fput(file);

Could we just call atomic_long_dec here?

We can but I don't like breaking encapsulation (which is broken anyway by the code). So, there is a special method and we should use it in my opinion.
it is increased by atomic_long_inc_not_zero so why don't we use the symmetric function?
The code with atomic_long_inc_not_zero' call is a copy-paste of the fget' function. If we want to make it clear we should make a separate function and name it so: `fget_from_files'.

I don't understand why there is a (exact?) copy&paste of fget there. :).
Maybe you could post a patchset, first replace the copy/paste with fget and then this patch. It will looks much clearer. The code of this module received little to none review and requires some love at the moment.

I wanted to refactor the module completely but Thomas said it is not going to go into the 2.0. So I decided to make a simple one-line fix. Another isse is do we really need a src fd here? Could we just allocate a unsed fd in the kernel and installed it with the target eventfd.

If you are interested this [0] is the latest version of the refactoring patch.

I can provide you with an application that checks that there is indeed no leakage and ensures that the `eventfd' moving works. It is being used in our builds as a test [1]. The code is "heredoc"ed in [2]

[0] http://dpdk.org/dev/patchwork/patch/4113/
[1] https://review.fuel-infra.org/#/c/4639/
[2] https://review.fuel-infra.org/#/c/4639/3/tests/runtests.sh

Pavel

Second thing is: another thread of the same processor can call the sys_close' on the fd' and this will dereference counter so fput' will correctly free the struct file'. Using atomic_long_dec' will leak a struct file' and print a KERN_ERR message by `filp_close'.

So, the common thing is to use appropriate functions and don't reinvent the wheel.

Pavel

Pavel

Quoted 3 lines
lib/librte_vhost/eventfd_link/eventfd_link.c +0 -0
              filp_close(file, files);
              fdt = files_fdtable(files);
              fdt->fd[eventfd_copy.source_fd] = NULL;

A message that is not in the archive (sent off-list or not yet received): C37D651A908B024F974696C65296B57B0F3F2694-0J0gbvR4kThpB2pF5aRoyrfspsVTdybXVpNB7YpNyf8@public.gmane.org

#13 lore raw
Quoted 60 lines · Huawei

On 3/23/2015 11:27 PM, Pavel Boldin wrote:

On Mon, Mar 23, 2015 at 5:16 PM, Xie, Huawei <[email protected]<mailto:
[email protected]>> wrote:
On 3/23/2015 10:52 PM, Pavel Boldin wrote:

On Mon, Mar 23, 2015 at 4:41 PM, Xie, Huawei <[email protected]<mailto:
[email protected]><mailto:[email protected]<mailto:
[email protected]>>> wrote:
On 3/23/2015 10:37 PM, Pavel Boldin wrote:

On Mon, Mar 23, 2015 at 4:21 PM, Xie, Huawei <[email protected]<mailto:
[email protected]><mailto:[email protected]<mailto:
[email protected]>><mailto:[email protected]<mailto:
[email protected]><mailto:[email protected]<mailto:
[email protected]>>>> wrote:

Quoted 5 lines · Pavel Boldin

Due to increased struct file's reference counter subsequent call to filp_close' does not free the struct file'. Prepend fput' call to decrease the reference counter.

pboldin-nYU0QVwCCFFWk0Htik3J/[email protected]><mailto:pboldin-nYU0QVwCCFFWk0Htik3J/[email protected]<mailto:
pboldin-nYU0QVwCCFFWk0Htik3J/[email protected]>><mailto:pboldin-nYU0QVwCCFFWk0Htik3J/[email protected]<mailto:
pboldin-nYU0QVwCCFFWk0Htik3J/[email protected]><mailto:pboldin-nYU0QVwCCFFWk0Htik3J/[email protected]<mailto:
pboldin-nYU0QVwCCFFWk0Htik3J/[email protected]>>>>

Review

Quoted 5 lines
---
 lib/librte_vhost/eventfd_link/eventfd_link.c | 1 +
 1 file changed, 1 insertion(+)
(quoted diff) +0 -0

b/lib/librte_vhost/eventfd_link/eventfd_link.c

lib/librte_vhost/eventfd_link/eventfd_link.c eventfd_link_ioctl(struct file *f, unsigned int

Quoted 4 lines

index 7755dd6..62c45c8 100644

lib/librte_vhost/eventfd_link/eventfd_link.c +0 -0
@@ -117,6 +117,7 @@ eventfd_link_ioctl(struct file *f, unsigned int

ioctl, unsigned long arg)

lib/librte_vhost/eventfd_link/eventfd_link.c eventfd_link_ioctl(struct file *f, unsigned int · line 120

Quoted 4 lines
lib/librte_vhost/eventfd_link/eventfd_link.c +1 -0
               * Release the existing eventfd in the source process
               */
              spin_lock(&files->file_lock);
+             fput(file);

Could we just call atomic_long_dec here?

We can but I don't like breaking encapsulation (which is broken anyway by the code). So, there is a special method and we should use it in my opinion. it is increased by atomic_long_inc_not_zero so why don't we use the symmetric function?
The code with atomic_long_inc_not_zero' call is a copy-paste of the fget' function. If we want to make it clear we should make a separate function and name it so: `fget_from_files'.

I don't understand why there is a (exact?) copy&paste of fget there. :). Maybe you could post a patchset, first replace the copy/paste with fget and then this patch. It will looks much clearer.
The code of this module received little to none review and requires some love at the moment.

Quoted 5 lines

I wanted to refactor the module completely but Thomas said it is not going to go into the 2.0. So I decided to make a simple one-line fix. Another isse is do we really need a src fd here? Could we just allocate a unsed fd in the kernel and installed it with the target eventfd.

This is for DPDK team to decide and should be discussed separately.

Pavel

Quoted 39 lines

If you are interested this [0] is the latest version of the refactoring patch.

I can provide you with an application that checks that there is indeed no leakage and ensures that the `eventfd' moving works. It is being used in our builds as a test [1]. The code is "heredoc"ed in [2]

[0] http://dpdk.org/dev/patchwork/patch/4113/
[1] https://review.fuel-infra.org/#/c/4639/
[2] https://review.fuel-infra.org/#/c/4639/3/tests/runtests.sh

Pavel

Second thing is: another thread of the same processor can call the sys_close' on the fd' and this will dereference counter so fput' will correctly free the struct file'. Using atomic_long_dec' will leak a struct file' and print a KERN_ERR message by `filp_close'.

So, the common thing is to use appropriate functions and don't reinvent the wheel.

Pavel

Pavel

Quoted 3 lines
lib/librte_vhost/eventfd_link/eventfd_link.c +0 -0
              filp_close(file, files);
              fdt = files_fdtable(files);
              fdt->fd[eventfd_copy.source_fd] = NULL;
#14 lore raw
In reply to Pavel Boldin
Quoted 14 lines · Pavel Boldin

Due to increased struct file's reference counter subsequent call to filp_close' does not free the struct file'. Prepend fput' call to decrease the reference counter.

---
 lib/librte_vhost/eventfd_link/eventfd_link.c | 1 +
 1 file changed, 1 insertion(+)
lib/librte_vhost/eventfd_link/eventfd_link.c +0 -0
index 7755dd6..62c45c8 100644

lib/librte_vhost/eventfd_link/eventfd_link.c eventfd_link_ioctl(struct file *f, unsigned int ioctl, unsigned long arg) · line 123

Quoted 7 lines
lib/librte_vhost/eventfd_link/eventfd_link.c +1 -0
@@ -117,6 +117,7 @@ eventfd_link_ioctl(struct file *f, unsigned int ioctl, unsigned long arg)
 		 * Release the existing eventfd in the source process
 		 */
 		spin_lock(&files->file_lock);
+		fput(file);
 		filp_close(file, files);
 		fdt = files_fdtable(files);
 		fdt->fd[eventfd_copy.source_fd] = NULL;

Acked-by Huawei Xie <[email protected]>

In future, we should remove the allocation of src eventfd, allocate a free fd from kernel, and install it with target fd.

A message that is not in the archive (sent off-list or not yet received): C37D651A908B024F974696C65296B57B0F3F46FB-0J0gbvR4kThpB2pF5aRoyrfspsVTdybXVpNB7YpNyf8@public.gmane.org

#16 lore raw
Quoted 24 lines · Huawei

Review

Quoted 10 lines · Pavel Boldin

Due to increased struct file's reference counter subsequent call to filp_close' does not free the struct file'. Prepend fput' call to decrease the reference counter.

---
 lib/librte_vhost/eventfd_link/eventfd_link.c | 1 +
 1 file changed, 1 insertion(+)
(quoted diff) +0 -0

b/lib/librte_vhost/eventfd_link/eventfd_link.c

lib/librte_vhost/eventfd_link/eventfd_link.c eventfd_link_ioctl(struct file *f, unsigned int

Quoted 4 lines

index 7755dd6..62c45c8 100644

lib/librte_vhost/eventfd_link/eventfd_link.c +0 -0
@@ -117,6 +117,7 @@ eventfd_link_ioctl(struct file *f, unsigned int

ioctl, unsigned long arg)

lib/librte_vhost/eventfd_link/eventfd_link.c eventfd_link_ioctl(struct file *f, unsigned int ioctl, unsigned long arg) · line 123

Quoted 7 lines
lib/librte_vhost/eventfd_link/eventfd_link.c +1 -0
               * Release the existing eventfd in the source process
               */
              spin_lock(&files->file_lock);
+             fput(file);
              filp_close(file, files);
              fdt = files_fdtable(files);
              fdt->fd[eventfd_copy.source_fd] = NULL;
Quoted 5 lines

Acked-by Huawei Xie <[email protected]>

In future, we should remove the allocation of src eventfd, allocate a free fd from kernel, and install it with target fd.

Well, I don't think this is correct, because this will put too much job for the kernel module making it a combiner.

At the moment I propose to accept module refactoring patch to the upstream.

After that the module can be reworked along with the application code. The reason is I can't work on DPDK since I have no hardware to test application at so I can't help with patch that touches application code.

Pavel

#17 lore raw

On 3/24/2015 7:10 PM, Pavel Boldin wrote:

On Tue, Mar 24, 2015 at 8:28 AM, Xie, Huawei <[email protected]<mailto:[email protected]>> wrote:

Quoted 14 lines · Pavel Boldin

Due to increased struct file's reference counter subsequent call to filp_close' does not free the struct file'. Prepend fput' call to decrease the reference counter.

---
 lib/librte_vhost/eventfd_link/eventfd_link.c | 1 +
 1 file changed, 1 insertion(+)
lib/librte_vhost/eventfd_link/eventfd_link.c +0 -0
index 7755dd6..62c45c8 100644

lib/librte_vhost/eventfd_link/eventfd_link.c eventfd_link_ioctl(struct file *f, unsigned int ioctl, unsigned long arg) · line 123

Quoted 7 lines
lib/librte_vhost/eventfd_link/eventfd_link.c +1 -0
@@ -117,6 +117,7 @@ eventfd_link_ioctl(struct file *f, unsigned int ioctl, unsigned long arg)
               * Release the existing eventfd in the source process
               */
              spin_lock(&files->file_lock);
+             fput(file);
              filp_close(file, files);
              fdt = files_fdtable(files);
              fdt->fd[eventfd_copy.source_fd] = NULL;

Acked-by Huawei Xie <[email protected]<mailto:[email protected]>>

In future, we should remove the allocation of src eventfd, allocate a free fd from kernel, and install it with target fd.

Well, I don't think this is correct, because this will put too much job for the kernel module making it a combiner.

At the moment I propose to accept module refactoring patch to the upstream.

After that the module can be reworked along with the application code. The reason is I can't work on DPDK since I have no hardware to test application at so I can't help with patch that touches application code.

Pavel
Pavel:
I am not asking to do it right now but in future, and i agree we accept the refactoring patch now, so i ack the patch. Huawei

A message that is not in the archive (sent off-list or not yet received): C37D651A908B024F974696C65296B57B0F3F59D7-0J0gbvR4kThpB2pF5aRoyrfspsVTdybXVpNB7YpNyf8@public.gmane.org

#19 lore raw
Quoted 40 lines · Huawei

On 3/24/2015 7:10 PM, Pavel Boldin wrote:

On Tue, Mar 24, 2015 at 8:28 AM, Xie, Huawei <[email protected]<mailto:
[email protected]>> wrote:

Quoted 5 lines · Pavel Boldin

Due to increased struct file's reference counter subsequent call to filp_close' does not free the struct file'. Prepend fput' call to decrease the reference counter.

pboldin-nYU0QVwCCFFWk0Htik3J/[email protected]>>

Review

Quoted 5 lines
---
 lib/librte_vhost/eventfd_link/eventfd_link.c | 1 +
 1 file changed, 1 insertion(+)
(quoted diff) +0 -0

b/lib/librte_vhost/eventfd_link/eventfd_link.c

lib/librte_vhost/eventfd_link/eventfd_link.c eventfd_link_ioctl(struct file *f, unsigned int

Quoted 4 lines

index 7755dd6..62c45c8 100644

lib/librte_vhost/eventfd_link/eventfd_link.c +0 -0
@@ -117,6 +117,7 @@ eventfd_link_ioctl(struct file *f, unsigned int

ioctl, unsigned long arg)

lib/librte_vhost/eventfd_link/eventfd_link.c eventfd_link_ioctl(struct file *f, unsigned int ioctl, unsigned long arg) · line 123

Quoted 7 lines
lib/librte_vhost/eventfd_link/eventfd_link.c +1 -0
               * Release the existing eventfd in the source process
               */
              spin_lock(&files->file_lock);
+             fput(file);
              filp_close(file, files);
              fdt = files_fdtable(files);
              fdt->fd[eventfd_copy.source_fd] = NULL;

Acked-by Huawei Xie <[email protected]<mailto:[email protected]>>

In future, we should remove the allocation of src eventfd, allocate a free fd from kernel, and install it with target fd.

Well, I don't think this is correct, because this will put too much job for the kernel module making it a combiner.

At the moment I propose to accept module refactoring patch to the upstream.

Quoted 9 lines

After that the module can be reworked along with the application code. The reason is I can't work on DPDK since I have no hardware to test application at so I can't help with patch that touches application code.

Pavel
Pavel:
I am not asking to do it right now but in future, and i agree we accept the refactoring patch now, so i ack the patch.

Huawei, this is the refactoring patch [1]. This patch is merely a bugfix.

[1] http://dpdk.org/dev/patchwork/patch/4113/

Quoted 2 lines

Huawei

#20 lore raw

On 3/25/2015 4:08 AM, Pavel Boldin wrote:

On Tue, Mar 24, 2015 at 6:20 PM, Xie, Huawei <[email protected]<mailto:[email protected]>> wrote:
On 3/24/2015 7:10 PM, Pavel Boldin wrote:

On Tue, Mar 24, 2015 at 8:28 AM, Xie, Huawei <[email protected]<mailto:[email protected]><mailto:[email protected]<mailto:[email protected]>>> wrote:

Quoted 14 lines · Pavel Boldin

Due to increased struct file's reference counter subsequent call to filp_close' does not free the struct file'. Prepend fput' call to decrease the reference counter.

---
 lib/librte_vhost/eventfd_link/eventfd_link.c | 1 +
 1 file changed, 1 insertion(+)
lib/librte_vhost/eventfd_link/eventfd_link.c +0 -0
index 7755dd6..62c45c8 100644

lib/librte_vhost/eventfd_link/eventfd_link.c eventfd_link_ioctl(struct file *f, unsigned int ioctl, unsigned long arg) · line 123

Quoted 7 lines
lib/librte_vhost/eventfd_link/eventfd_link.c +1 -0
@@ -117,6 +117,7 @@ eventfd_link_ioctl(struct file *f, unsigned int ioctl, unsigned long arg)
               * Release the existing eventfd in the source process
               */
              spin_lock(&files->file_lock);
+             fput(file);
              filp_close(file, files);
              fdt = files_fdtable(files);
              fdt->fd[eventfd_copy.source_fd] = NULL;

Acked-by Huawei Xie <[email protected]<mailto:[email protected]><mailto:[email protected]<mailto:[email protected]>>>

In future, we should remove the allocation of src eventfd, allocate a free fd from kernel, and install it with target fd.

Well, I don't think this is correct, because this will put too much job for the kernel module making it a combiner.

At the moment I propose to accept module refactoring patch to the upstream.

After that the module can be reworked along with the application code. The reason is I can't work on DPDK since I have no hardware to test application at so I can't help with patch that touches application code.

Pavel
Pavel:
I am not asking to do it right now but in future, and i agree we accept the refactoring patch now, so i ack the patch. Huawei, this is the refactoring patch [1]. This patch is merely a bugfix.

[1] http://dpdk.org/dev/patchwork/patch/4113/

Huawei

Thanks for your patch and fd checking tool. I will re-ack the patch as i see quoting issue in my previous ack.

#21 lore raw
In reply to a message not in the archive
Quoted 6 lines
Quoted 5 lines

Due to increased struct file's reference counter subsequent call to filp_close' does not free the struct file'. Prepend fput' call to decrease the reference counter.

Acked-by Huawei Xie <[email protected]>

Applied, thanks

(already sent this notification but this ack was did many times in detached threads)

#22 lore raw
In reply to Pavel Boldin
Quoted 14 lines · Pavel Boldin

Due to increased struct file's reference counter subsequent call to filp_close' does not free the struct file'. Prepend fput' call to decrease the reference counter.

---
 lib/librte_vhost/eventfd_link/eventfd_link.c | 1 +
 1 file changed, 1 insertion(+)
lib/librte_vhost/eventfd_link/eventfd_link.c +0 -0
index 7755dd6..62c45c8 100644

lib/librte_vhost/eventfd_link/eventfd_link.c eventfd_link_ioctl(struct file *f, unsigned int ioctl, unsigned long arg) · line 123

Quoted 7 lines
lib/librte_vhost/eventfd_link/eventfd_link.c +1 -0
@@ -117,6 +117,7 @@ eventfd_link_ioctl(struct file *f, unsigned int ioctl, unsigned long arg)
 		 * Release the existing eventfd in the source process
 		 */
 		spin_lock(&files->file_lock);
+		fput(file);
 		filp_close(file, files);
 		fdt = files_fdtable(files);
 		fdt->fd[eventfd_copy.source_fd] = NULL;

Acked-by Huawei Xie <[email protected]>

A message that is not in the archive (sent off-list or not yet received): C37D651A908B024F974696C65296B57B0F3FB942-0J0gbvR4kThpB2pF5aRoyrfspsVTdybXVpNB7YpNyf8@public.gmane.org

#24 lore raw
Quoted 25 lines · Huawei

Review

Quoted 10 lines · Pavel Boldin

Due to increased struct file's reference counter subsequent call to filp_close' does not free the struct file'. Prepend fput' call to decrease the reference counter.

---
 lib/librte_vhost/eventfd_link/eventfd_link.c | 1 +
 1 file changed, 1 insertion(+)
(quoted diff) +0 -0

b/lib/librte_vhost/eventfd_link/eventfd_link.c

lib/librte_vhost/eventfd_link/eventfd_link.c eventfd_link_ioctl(struct file *f, unsigned int

Quoted 4 lines

index 7755dd6..62c45c8 100644

lib/librte_vhost/eventfd_link/eventfd_link.c +0 -0
@@ -117,6 +117,7 @@ eventfd_link_ioctl(struct file *f, unsigned int

ioctl, unsigned long arg)

lib/librte_vhost/eventfd_link/eventfd_link.c eventfd_link_ioctl(struct file *f, unsigned int ioctl, unsigned long arg) · line 123

Quoted 7 lines
lib/librte_vhost/eventfd_link/eventfd_link.c +1 -0
               * Release the existing eventfd in the source process
               */
              spin_lock(&files->file_lock);
+             fput(file);
              filp_close(file, files);
              fdt = files_fdtable(files);
              fdt->fd[eventfd_copy.source_fd] = NULL;
Quoted 2 lines

Acked-by Huawei Xie <[email protected]>

The patch is still in "New" stat in patchwork. I think you forgot a ":" between Acked-by and email.

Pavel

#26 lore raw
Quoted 10 lines · Thomas Monjalon
Quoted 7 lines
Quoted 5 lines

Due to increased struct file's reference counter subsequent call to filp_close' does not free the struct file'. Prepend fput' call to decrease the reference counter.

Acked-by Huawei Xie <[email protected]>

Applied, thanks

What should I do with the refactoring patch in your opinion?

Should I split it in parts to ease review?

Pavel

A message that is not in the archive (sent off-list or not yet received): CACf4_B9ims0bL3fqk5Pm6sTHkm7pdHcTgFNXLvKYZf5Gip9LDg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org

#28 lore raw
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 5 lines

Due to increased struct file's reference counter subsequent call to filp_close' does not free the struct file'. Prepend fput' call to decrease the reference counter.

Quoted 7 lines
Quoted 3 lines
Quoted 1 line

Acked-by Huawei Xie <[email protected]>

Applied, thanks

What should I do with the refactoring patch in your opinion?

Should I split it in parts to ease review?

I didn't review it so I have no good advice.
But in general, it's better to split patches in logic units if it makes sense. Note that we are closing 2.0. Refactoring patches are deffered to 2.1.

Acked-by on v1 1/1
#29 lore raw
In reply to Pavel Boldin
Quoted 14 lines · Pavel Boldin

Due to increased struct file's reference counter subsequent call to filp_close' does not free the struct file'. Prepend fput' call to decrease the reference counter.

---
 lib/librte_vhost/eventfd_link/eventfd_link.c | 1 +
 1 file changed, 1 insertion(+)
lib/librte_vhost/eventfd_link/eventfd_link.c +0 -0
index 7755dd6..62c45c8 100644

lib/librte_vhost/eventfd_link/eventfd_link.c eventfd_link_ioctl(struct file *f, unsigned int ioctl, unsigned long arg) · line 123

Quoted 7 lines
lib/librte_vhost/eventfd_link/eventfd_link.c +1 -0
@@ -117,6 +117,7 @@ eventfd_link_ioctl(struct file *f, unsigned int ioctl, unsigned long arg)
 		 * Release the existing eventfd in the source process
 		 */
 		spin_lock(&files->file_lock);
+		fput(file);
 		filp_close(file, files);
 		fdt = files_fdtable(files);
 		fdt->fd[eventfd_copy.source_fd] = NULL;