Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp906889ybi; Fri, 14 Jun 2019 05:28:10 -0700 (PDT) X-Google-Smtp-Source: APXvYqxaTQD9cY1j2vegN/jQ+Ys00bdmHj9MIFKnKG6Bf5UEDn6L5XnDHV5JKrLVcyI9ZAChy8fQ X-Received: by 2002:a17:902:4481:: with SMTP id l1mr94812713pld.121.1560515290892; Fri, 14 Jun 2019 05:28:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560515290; cv=none; d=google.com; s=arc-20160816; b=fHRhJg1vr47ivoxUzpJNu6icp6/YyECMoc7vXo4zvkYr4Hfx7ydCJ+c6jZrNYr9f8J YFCQUqHg8HJ9oz1GtS6l1p+AL7fD0ejstdKSEMv7XHdKaZA/1SYSSOrF8j4f+3Gayn1y jQDB9BgWxprAU7z5zoOWOGtgfVuTQDo/VIc+TjQAicToPIHoIBHeLpjSSsQK5zYq53jq xttz9zVxPPFYWDpb9Ysr0vudJYpiqluFlJogZ3Hs1P3pJvn8Fu03oIIItU0MKQ1QlgJd appzsxL7MOJ3EUhmazzuKZ5Z6hsiEBBqQtgzNpLF/u1nAlx6V6vOuNbEv4nX7/wi424w Vfhw== 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 :in-reply-to:references:mime-version:dkim-signature; bh=9YnMPbwL4s/jQR8V1f8H97ZkPj3o349XbfXjq85CLy4=; b=Un97Mh3XeLK2DH86pWHkd7MfX6jiV8kwg+1nPIMp52cFGRJQFVForeELEeYIr4UIl3 HUxk7lwkiULO56j09qqwVEiGg9JIpHyzpEhoHr3IU8PMtY6WPz87+/82g0lSYRsgPeKC sAhV6HmmSAbaYu2dD0ZQsYShRlvjWnpNfMWJJHsK9QDL6N2+B2seyW2WPFEq+ShJLHhi suO7fOseJzmXzp9boU5zy8LS2zesB6XktglOJQweXVskJvT4/6RRSkCcUjFQK6LCobBr /LBxK6lri+Fr4eWkEjq5mdT5WNmEwUwh2Gq01lj4n8tHqmT3xacDX46JCa2S49Hiv4pH 87vA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=mNgRqR9R; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s101si2292433pjc.5.2019.06.14.05.27.54; Fri, 14 Jun 2019 05:28:10 -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=@google.com header.s=20161025 header.b=mNgRqR9R; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727800AbfFNM1r (ORCPT + 99 others); Fri, 14 Jun 2019 08:27:47 -0400 Received: from mail-yw1-f65.google.com ([209.85.161.65]:42392 "EHLO mail-yw1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727635AbfFNM1r (ORCPT ); Fri, 14 Jun 2019 08:27:47 -0400 Received: by mail-yw1-f65.google.com with SMTP id s5so1003606ywd.9 for ; Fri, 14 Jun 2019 05:27:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=9YnMPbwL4s/jQR8V1f8H97ZkPj3o349XbfXjq85CLy4=; b=mNgRqR9R4DILLyqKfkVzOgJZ558rQ3fTtTduD85c7js1UgGft5GNAd816Q6FK8mo27 4B5TKaIrjEDF8XWyOy4XS4zeSiXcXTPc4LsLS7qQNXBnnLLs4eHrXi8qofhzr733h90K kJetXj7RLB6agorrJqqdWTnURyuv31SiSs17c+vxXJJbM7nquA2MaagNH1bNA6BWY8V6 t+OM0CwA0oDdHkzN0rh4N+8F1rpwN9/V2f8wYNR8s3jBECXCdW1wW3SOggULdCeTf/GI mcbTRYp4BUNf/lQtelsV8+OsjLZCv8MHK8QdXavpr38I/YCzXMBBCTmkexjv5YO5ij7X 0Rnw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=9YnMPbwL4s/jQR8V1f8H97ZkPj3o349XbfXjq85CLy4=; b=LBdWo9wFgLCVwCMmCLLEWXE8p4/J7We7PfKPtgMM7y2/CqgSTmNG7MA3oV9EWLWtMj WfytDjUTzrL+2w6R4rUw9RnxAuBJ6Jq4JisySUwRauGOoZx7IxzT3Ks/gaQnFra7V4LV i4fPmcsEWXEH/Oba39B+1q3QWBLK7N1sYhratD7ipXWbvTQ/DpXp0ApYzbBBsrKRpdZn eDaOv5EsKJEeDX4Gq7gMo1llkPv8Z74x1+h4FHtfoxpZKGB8S5e8esGO3+DCsCU1BRG6 alzM7v282A+Q7Z58LF+G/uMOnrKB3ohN+b+0sQ/4seZcGCHXGArXjqn4knzcVUZrSwS8 r5lg== X-Gm-Message-State: APjAAAWPwxz6dHDnAyQg4Pfm52kSx2PPbOwA0XdElvQb1qVXISmhleBt 71W06oC58b7SemUZuu70Ui5L/b/FXTM4T5HzSAiSKNCYypQ= X-Received: by 2002:a0d:dfc4:: with SMTP id i187mr8597935ywe.146.1560515266154; Fri, 14 Jun 2019 05:27:46 -0700 (PDT) MIME-Version: 1.0 References: <20190612035715.166676-1-maowenan@huawei.com> <6de5d6d8-e481-8235-193e-b12e7f511030@huawei.com> <6aa69ab5-ed81-6a7f-2b2b-214e44ff0ada@gmail.com> <52025f94-04d3-2a44-11cd-7aa66ebc7e27@huawei.com> In-Reply-To: <52025f94-04d3-2a44-11cd-7aa66ebc7e27@huawei.com> From: Eric Dumazet Date: Fri, 14 Jun 2019 05:27:34 -0700 Message-ID: Subject: Re: [PATCH net v2] tcp: avoid creating multiple req socks with the same tuples To: maowenan Cc: Eric Dumazet , David Miller , netdev , LKML 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 Fri, Jun 14, 2019 at 2:35 AM maowenan wrote: > > > > On 2019/6/14 12:28, Eric Dumazet wrote: > > > > > > On 6/13/19 9:19 PM, maowenan wrote: > >> > >> > >> @Eric, for this issue I only want to check TCP_NEW_SYN_RECV sk, is it OK like below? > >> + if (!osk && sk->sk_state == TCP_NEW_SYN_RECV) > >> + reqsk = __inet_lookup_established(sock_net(sk), &tcp_hashinfo, > >> + sk->sk_daddr, sk->sk_dport, > >> + sk->sk_rcv_saddr, sk->sk_num, > >> + sk->sk_bound_dev_if, sk->sk_bound_dev_if); > >> + if (unlikely(reqsk)) { > >> > > > > Not enough. > > > > If we have many cpus here, there is a chance another cpu has inserted a request socket, then > > replaced it by an ESTABLISH socket for the same 4-tuple. > > I try to get more clear about the scene you mentioned. And I have do some testing about this, it can work well > when I use multiple cpus. > > The ESTABLISH socket would be from tcp_check_req->tcp_v4_syn_recv_sock->tcp_create_openreq_child, > and for this path, inet_ehash_nolisten pass osk(NOT NULL), my patch won't call __inet_lookup_established in inet_ehash_insert(). > > When TCP_NEW_SYN_RECV socket try to inset to hash table, it will pass osk with NULL, my patch will check whether reqsk existed > in hash table or not. If reqsk is existed, it just removes this reqsk and dose not insert to hash table. Then the synack for this > reqsk can't be sent to client, and there is no chance to receive the ack from client, so ESTABLISH socket can't be replaced in hash table. > > So I don't see the race when there are many cpus. Can you show me some clue? This is a bit silly. You focus on some crash you got on a given system, but do not see the real bug. CPU A SYN packet lookup finds nothing. Create a NEW_SYN_RECV CPU B SYN packet -> inserts a NEW_SYN_RECV sends a SYNACK ACK packet -> replaces the NEW_SYN_RECV by ESTABLISH socket CPU A resumes. Basically a lookup (after taking the bucket spinlock) could either find : - Nothing (typical case where there was no race) - A NEW_SYN_RECV - A ESTABLISHED socket - A TIME_WAIT socket. You can not simply fix the "NEW_SYN_RECV" state case, and possibly add hard crashes (instead of current situation leading to RST packets)