Skip to content

Commit 2d1b7fd

Browse files
hansendcKernel Patches Daemon
authored andcommitted
tcp: Remove mmap_lock fallback path
Previously, the per-VMA locking could fail in the face of writers which necessitates a fallback to mmap_lock. The new lock_vma_under_rcu_wait() will wait for writers instead of failing. Use the new helper. Wait for writers. Remove the fallback to mmap_lock. This really is a nice cleanup. It removes the need to pass the lock state back and forth to find_tcp_vma(). Signed-off-by: Dave Hansen <dave.hansen@linux.intel.com> Acked-by: Lorenzo Stoakes <ljs@kernel.org> Reviewed-by: Suren Baghdasaryan <surenb@google.com> Cc: Andrew Morton <akpm@linux-foundation.org> Cc: "Liam R. Howlett" <Liam.Howlett@oracle.com> Cc: Vlastimil Babka <vbabka@kernel.org> Cc: Shakeel Butt <shakeel.butt@linux.dev> Cc: linux-mm@kvack.org Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Cc: Arve Hjønnevåg <arve@android.com> Cc: Todd Kjos <tkjos@android.com> Cc: Christian Brauner <christian@brauner.io> Cc: Carlos Llamas <cmllamas@google.com> Cc: Alice Ryhl <aliceryhl@google.com> Cc: "David S. Miller" <davem@davemloft.net> Cc: David Ahern <dsahern@kernel.org> Cc: netdev@vger.kernel.org
1 parent 4ce5443 commit 2d1b7fd

1 file changed

Lines changed: 9 additions & 22 deletions

File tree

net/ipv4/tcp.c

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2168,27 +2168,18 @@ static void tcp_zc_finalize_rx_tstamp(struct sock *sk,
21682168
}
21692169

21702170
static struct vm_area_struct *find_tcp_vma(struct mm_struct *mm,
2171-
unsigned long address,
2172-
bool *mmap_locked)
2171+
unsigned long address)
21732172
{
2174-
struct vm_area_struct *vma = lock_vma_under_rcu(mm, address);
2173+
struct vm_area_struct *vma = vma_start_read_unlocked(mm, address);
21752174

2176-
if (vma) {
2177-
if (vma->vm_ops != &tcp_vm_ops) {
2178-
vma_end_read(vma);
2179-
return NULL;
2180-
}
2181-
*mmap_locked = false;
2182-
return vma;
2183-
}
2175+
if (!vma)
2176+
return NULL;
21842177

2185-
mmap_read_lock(mm);
2186-
vma = vma_lookup(mm, address);
2187-
if (!vma || vma->vm_ops != &tcp_vm_ops) {
2188-
mmap_read_unlock(mm);
2178+
if (vma->vm_ops != &tcp_vm_ops) {
2179+
vma_end_read(vma);
21892180
return NULL;
21902181
}
2191-
*mmap_locked = true;
2182+
21922183
return vma;
21932184
}
21942185

@@ -2209,7 +2200,6 @@ static int tcp_zerocopy_receive(struct sock *sk,
22092200
u32 seq = tp->copied_seq;
22102201
u32 total_bytes_to_map;
22112202
int inq = tcp_inq(sk);
2212-
bool mmap_locked;
22132203
int ret;
22142204

22152205
zc->copybuf_len = 0;
@@ -2234,7 +2224,7 @@ static int tcp_zerocopy_receive(struct sock *sk,
22342224
return 0;
22352225
}
22362226

2237-
vma = find_tcp_vma(current->mm, address, &mmap_locked);
2227+
vma = find_tcp_vma(current->mm, address);
22382228
if (!vma)
22392229
return -EINVAL;
22402230

@@ -2316,10 +2306,7 @@ static int tcp_zerocopy_receive(struct sock *sk,
23162306
zc, total_bytes_to_map);
23172307
}
23182308
out:
2319-
if (mmap_locked)
2320-
mmap_read_unlock(current->mm);
2321-
else
2322-
vma_end_read(vma);
2309+
vma_end_read(vma);
23232310
/* Try to copy straggler data. */
23242311
if (!ret)
23252312
copylen = tcp_zc_handle_leftover(zc, sk, skb, &seq, copybuf_len, tss);

0 commit comments

Comments
 (0)