Skip to contentSkip to conversation

DAX: bug in COW no page fault?

PATCH Jared Hulbert 3 participants 8 messages Jan 29, 2016 – Feb 1, 2016

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

Why isn't this required?

fs/dax.c +1 -0
index a7f77e1..30f2abe 100644
@@ -416,6 +416,7 @@ int __dax_fault(struct vm_area_struct *vma, struct vm_fault
                                error = -EIO;
                                goto out;
                        }
+                       i_mmap_unlock_read(mapping);
                }
                return VM_FAULT_LOCKED;
        }
#1 lore raw

RE: bug in COW no page fault?

Because we need to hold the i_mmap_sem until the page is inserted into the page tables to avoid racing with truncate. Therefore it is unlocked by the MM code.

Did you try this patch? It should have BUGged immediately that you hit this case. If not, you have insufficient CONFIG_DEBUG enabled.

________________________________________
From: Jared Hulbert [[email protected]]
Sent: January 29, 2016 1:38 PM
To: [email protected]; Wilcox, Matthew R; [email protected]
Subject: DAX: bug in COW no page fault?

Why isn't this required?

fs/dax.c +1 -0
index a7f77e1..30f2abe 100644
@@ -416,6 +416,7 @@ int __dax_fault(struct vm_area_struct *vma, struct vm_fault
                                error = -EIO;
                                goto out;
                        }
+                       i_mmap_unlock_read(mapping);
                }
                return VM_FAULT_LOCKED;
        }
#2 lore raw

Re: bug in COW no page fault?

Which page? The unmatched call for i_mmap_lock_read() is only called if(!page). Ahh, are we locking for the cow_page? Okay, then why don't we lock when page != NULL in the COW case?

Quoted 24 lines · Matthew R

Because we need to hold the i_mmap_sem until the page is inserted into the page tables to avoid racing with truncate. Therefore it is unlocked by the MM code.

Did you try this patch? It should have BUGged immediately that you hit this case. If not, you have insufficient CONFIG_DEBUG enabled.

________________________________________
From: Jared Hulbert [[email protected]]
Sent: January 29, 2016 1:38 PM
To: [email protected]; Wilcox, Matthew R; [email protected]
Subject: DAX: bug in COW no page fault?

Why isn't this required?

fs/dax.c +1 -0
index a7f77e1..30f2abe 100644
@@ -416,6 +416,7 @@ int __dax_fault(struct vm_area_struct *vma, struct vm_fault
                                error = -EIO;
                                goto out;
                        }
+                       i_mmap_unlock_read(mapping);
                }
                return VM_FAULT_LOCKED;
        }
#3 lore raw

RE: bug in COW no page fault?

Because then we lock the page instead of the i_mmap_sem. The code in mm/memory.c isn't /that/ hard to understand, is it?
________________________________________
From: Jared Hulbert [[email protected]]
Sent: January 29, 2016 2:12 PM
To: Wilcox, Matthew R
Cc: [email protected]; [email protected]
Subject: Re: bug in COW no page fault?

Which page? The unmatched call for i_mmap_lock_read() is only called if(!page). Ahh, are we locking for the cow_page? Okay, then why don't we lock when page != NULL in the COW case?

Quoted 24 lines · Matthew R

Because we need to hold the i_mmap_sem until the page is inserted into the page tables to avoid racing with truncate. Therefore it is unlocked by the MM code.

Did you try this patch? It should have BUGged immediately that you hit this case. If not, you have insufficient CONFIG_DEBUG enabled.

________________________________________
From: Jared Hulbert [[email protected]]
Sent: January 29, 2016 1:38 PM
To: [email protected]; Wilcox, Matthew R; [email protected]
Subject: DAX: bug in COW no page fault?

Why isn't this required?

fs/dax.c +1 -0
index a7f77e1..30f2abe 100644
@@ -416,6 +416,7 @@ int __dax_fault(struct vm_area_struct *vma, struct vm_fault
                                error = -EIO;
                                goto out;
                        }
+                       i_mmap_unlock_read(mapping);
                }
                return VM_FAULT_LOCKED;
        }
#4 lore raw

Re: bug in COW no page fault?

oh... Look! There it is, right where it should be. Sorry.

Recovering from years of Android and VMware, please be patient.

Quoted 38 lines · Matthew R

Because then we lock the page instead of the i_mmap_sem. The code in mm/memory.c isn't /that/ hard to understand, is it?
________________________________________
From: Jared Hulbert [[email protected]]
Sent: January 29, 2016 2:12 PM
To: Wilcox, Matthew R
Cc: [email protected]; [email protected]
Subject: Re: bug in COW no page fault?

Which page? The unmatched call for i_mmap_lock_read() is only called if(!page). Ahh, are we locking for the cow_page? Okay, then why don't we lock when page != NULL in the COW case?

Quoted 24 lines · Matthew R

Because we need to hold the i_mmap_sem until the page is inserted into the page tables to avoid racing with truncate. Therefore it is unlocked by the MM code.

Did you try this patch? It should have BUGged immediately that you hit this case. If not, you have insufficient CONFIG_DEBUG enabled.

________________________________________
From: Jared Hulbert [[email protected]]
Sent: January 29, 2016 1:38 PM
To: [email protected]; Wilcox, Matthew R; [email protected]
Subject: DAX: bug in COW no page fault?

Why isn't this required?

fs/dax.c +1 -0
index a7f77e1..30f2abe 100644
@@ -416,6 +416,7 @@ int __dax_fault(struct vm_area_struct *vma, struct vm_fault
                                error = -EIO;
                                goto out;
                        }
+                       i_mmap_unlock_read(mapping);
                }
                return VM_FAULT_LOCKED;
        }
#5 lore raw

RE: bug in COW no page fault?

I remembered that Ross had a similar question, so it must be hard to understand. How does this comment work for both of you?

+ /*

+                * A truncate must remove COWs of pages that are removed
+                * from the file.  If we have a struct page, the normal
+                * page lock mechanism prevents truncate from missing the
+                * COWed page.  If not, the i_mmap_lock can provide the
+                * same guarantee.  It is dropped by the caller after the
+                * page is safely in the page tables.
+                */

________________________________________
From: Jared Hulbert [[email protected]]
Sent: January 29, 2016 3:16 PM
To: Wilcox, Matthew R
Cc: [email protected]; [email protected]
Subject: Re: bug in COW no page fault?

oh... Look! There it is, right where it should be. Sorry.

Recovering from years of Android and VMware, please be patient.

Quoted 38 lines · Matthew R

Because then we lock the page instead of the i_mmap_sem. The code in mm/memory.c isn't /that/ hard to understand, is it?
________________________________________
From: Jared Hulbert [[email protected]]
Sent: January 29, 2016 2:12 PM
To: Wilcox, Matthew R
Cc: [email protected]; [email protected]
Subject: Re: bug in COW no page fault?

Which page? The unmatched call for i_mmap_lock_read() is only called if(!page). Ahh, are we locking for the cow_page? Okay, then why don't we lock when page != NULL in the COW case?

Quoted 24 lines · Matthew R

Because we need to hold the i_mmap_sem until the page is inserted into the page tables to avoid racing with truncate. Therefore it is unlocked by the MM code.

Did you try this patch? It should have BUGged immediately that you hit this case. If not, you have insufficient CONFIG_DEBUG enabled.

________________________________________
From: Jared Hulbert [[email protected]]
Sent: January 29, 2016 1:38 PM
To: [email protected]; Wilcox, Matthew R; [email protected]
Subject: DAX: bug in COW no page fault?

Why isn't this required?

fs/dax.c +1 -0
index a7f77e1..30f2abe 100644
@@ -416,6 +416,7 @@ int __dax_fault(struct vm_area_struct *vma, struct vm_fault
                                error = -EIO;
                                goto out;
                        }
+                       i_mmap_unlock_read(mapping);
                }
                return VM_FAULT_LOCKED;
        }
#6 lore raw

Re: bug in COW no page fault?

That's helpful. Thanks.

Quoted 62 lines · Matthew R

I remembered that Ross had a similar question, so it must be hard to understand. How does this comment work for both of you?

(quoted diff) +8 -0
+               /*
+                * A truncate must remove COWs of pages that are removed
+                * from the file.  If we have a struct page, the normal
+                * page lock mechanism prevents truncate from missing the
+                * COWed page.  If not, the i_mmap_lock can provide the
+                * same guarantee.  It is dropped by the caller after the
+                * page is safely in the page tables.
+                */

________________________________________
From: Jared Hulbert [[email protected]]
Sent: January 29, 2016 3:16 PM
To: Wilcox, Matthew R
Cc: [email protected]; [email protected]
Subject: Re: bug in COW no page fault?

oh... Look! There it is, right where it should be. Sorry.

Recovering from years of Android and VMware, please be patient.

Quoted 38 lines · Matthew R

Because then we lock the page instead of the i_mmap_sem. The code in mm/memory.c isn't /that/ hard to understand, is it?
________________________________________
From: Jared Hulbert [[email protected]]
Sent: January 29, 2016 2:12 PM
To: Wilcox, Matthew R
Cc: [email protected]; [email protected]
Subject: Re: bug in COW no page fault?

Which page? The unmatched call for i_mmap_lock_read() is only called if(!page). Ahh, are we locking for the cow_page? Okay, then why don't we lock when page != NULL in the COW case?

Quoted 24 lines · Matthew R

Because we need to hold the i_mmap_sem until the page is inserted into the page tables to avoid racing with truncate. Therefore it is unlocked by the MM code.

Did you try this patch? It should have BUGged immediately that you hit this case. If not, you have insufficient CONFIG_DEBUG enabled.

________________________________________
From: Jared Hulbert [[email protected]]
Sent: January 29, 2016 1:38 PM
To: [email protected]; Wilcox, Matthew R; [email protected]
Subject: DAX: bug in COW no page fault?

Why isn't this required?

fs/dax.c +1 -0
index a7f77e1..30f2abe 100644
@@ -416,6 +416,7 @@ int __dax_fault(struct vm_area_struct *vma, struct vm_fault
                                error = -EIO;
                                goto out;
                        }
+                       i_mmap_unlock_read(mapping);
                }
                return VM_FAULT_LOCKED;
        }
#7 lore raw

Re: bug in COW no page fault?

In reply to Wilcox, Matthew R

Review

Quoted 10 lines · Matthew R

I remembered that Ross had a similar question, so it must be hard to understand. How does this comment work for both of you?

(quoted diff) +8 -0
+               /*
+                * A truncate must remove COWs of pages that are removed
+                * from the file.  If we have a struct page, the normal
+                * page lock mechanism prevents truncate from missing the
+                * COWed page.  If not, the i_mmap_lock can provide the
+                * same guarantee.  It is dropped by the caller after the
+                * page is safely in the page tables.
+                */

Yep, this makes sense. It may be worthwhile to explicitly say "It is dropped by do_cow_fault() after the page is safely in the page tables." so the less experienced among us (me) can easily find the match to the i_mmap_lock_read().