Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp1290349ybb; Wed, 25 Mar 2020 20:24:04 -0700 (PDT) X-Google-Smtp-Source: ADFU+vuOHwyhSm9w1r5C1YQ4BQAyA8/aSBgEyHJV3kYSIbON1ZQfy3MrrVBeEI0oCJNcdwI1pcbj X-Received: by 2002:aca:a997:: with SMTP id s145mr480084oie.140.1585193044297; Wed, 25 Mar 2020 20:24:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585193044; cv=none; d=google.com; s=arc-20160816; b=I4FseQhY0E8WbNlkjhUfllo546wbdwGauk2Dls7eg7x0eS2//E4SrgpCTZXBOuzvJY bvGay9ehUW88nUeVU0j2LmE/hgZ9YnWgtP9v2Je7szuxl8toEAxFBK7Syz+zc5SVh/rG 777T67LjE9I8rfiZMFnGspF+o9xI8/oIvcEDTLsj2FshXwWi3s3D8PS2VS3bcJsn9ko9 2UF5obCWrRg4/17wD5om9m9kUSlu9QU2/oY8EEn9dI62jkI3LTcP96i3i/xdzpsbYJmr 6VXHOXzi74xL9hh7sYj2jjvE2a1+G421e2VfEJESZ+ctarAtLYRSlI8in+KFFuVk6wZ4 CevQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=YeOy0OBasIdly6oWWvsKSzzwXWKpMwurTBwp+GVkZds=; b=L2eNhfkgaSqyxQH59QtiiAaLQD/ZXVAl7gwc2auQIJv59l/I4e5CNW1z6KsfQ0VCON vDOP3GMMn5SVeEPLsdhC1qwW3RERZInLLaOcRX3+0Kxe3jFbvn9UuniXDtPezMwQlk3i biyM4fwMDH7vU6PbUhuy/kxt/sXF5DXJZSy8z5yMYxOftJMU7UgzYRJHCeYikxBh0g6b g9B/2GMWD6b6L5Hp96AaUfF9RFk+PHOWaknEy4IGxCUchZDbH8Z53afY799mBD4OgvTj VAaHnVQ7uquXHvJhYH9/2m6TaepubqCzgzA7JIAWGqJBETiExlFguA/zLgJy0q+doStg /QUQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=KCmIfvbY; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t83si455247oig.239.2020.03.25.20.23.51; Wed, 25 Mar 2020 20:24:04 -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=@gmail.com header.s=20161025 header.b=KCmIfvbY; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727711AbgCZDW6 (ORCPT + 99 others); Wed, 25 Mar 2020 23:22:58 -0400 Received: from mail-qk1-f196.google.com ([209.85.222.196]:33777 "EHLO mail-qk1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727560AbgCZDW5 (ORCPT ); Wed, 25 Mar 2020 23:22:57 -0400 Received: by mail-qk1-f196.google.com with SMTP id v7so5137759qkc.0; Wed, 25 Mar 2020 20:22:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=YeOy0OBasIdly6oWWvsKSzzwXWKpMwurTBwp+GVkZds=; b=KCmIfvbYyV7j43ojdw2tuBoWEvYIzBj7v7nPy611jNiX7OuPrMWI1OFBiJODURzwPO iIU/LkLvDfZcJ5yqUdM6z97qgBbw+DL5czuJoqk1KdCAzLvvWcJXq2i3wTi6JLIc3KA1 AkvaRfuM7sxuswgbDJGdPO4sKjnc19a3gTVnrvaFX+hlBbK36TCUlRkXzTO9zFRYnmgs gPeJGy04xFJwAMAokTAZ4KO40eX/DDfgg2cf3ffgtwNYkkrcjaWTG6T4VuSF4JVEr/PY aHjhSF0712u6Mv5Fc+oi7pDIn6226qGec2iu2g8QzFU/Mj++QPrGgD3h5WWsgOEWk/wQ iFQQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=YeOy0OBasIdly6oWWvsKSzzwXWKpMwurTBwp+GVkZds=; b=s4kk8tGoK4NcvpSejZ8uWiWLpZMC9wPsj4itBktbTWL3r/ajwd7dLKGfRkzVSTl8lq 0fByktlQoiDtruoe8uM7eRH762q6FsMcYUKMvQYhpezNyM4xoyLnLQE1z5QYHPXBhXTx VCRSYy6RXVSJppOgwdjmpF8T2QUUIMM+mtwwqb2IxvX5b+C38NUulvl8te+tdVrq0vZe EgpEvfxh9icaiSRLxUJP9rqXsJXlZOQv9xpcNdi2hkSp7yWr8R7mugaDAr5nHj7KFNea V+XGGlftW6g9+UGzE4qyCoS0/0CF9By1e07HilVnv4ocHTp6pz+RhdaSeN/cEAK90O6X daGw== X-Gm-Message-State: ANhLgQ3teMoYXMoZJLjcBvHmScGrCx1n3rOeiyiFSS/DtUKBE+hvr7NQ CBVSuw/cj5sJtHn+9z9SU4I= X-Received: by 2002:a37:7e82:: with SMTP id z124mr5941475qkc.360.1585192976039; Wed, 25 Mar 2020 20:22:56 -0700 (PDT) Received: from localhost.localdomain ([2001:1284:f028:d8e3:b319:cf5:7776:b4d9]) by smtp.gmail.com with ESMTPSA id t140sm619143qke.48.2020.03.25.20.22.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Mar 2020 20:22:55 -0700 (PDT) Received: by localhost.localdomain (Postfix, from userid 1000) id EC155C5CE4; Thu, 26 Mar 2020 00:22:52 -0300 (-03) Date: Thu, 26 Mar 2020 00:22:52 -0300 From: Marcelo Ricardo Leitner To: Qiujun Huang Cc: "David S. Miller" , vyasevich@gmail.com, nhorman@tuxdriver.com, Jakub Kicinski , linux-sctp@vger.kernel.org, netdev , LKML , anenbupt@gmail.com Subject: Re: [PATCH v4] sctp: fix refcount bug in sctp_wfree Message-ID: <20200326032252.GI3756@localhost.localdomain> References: <20200322090425.6253-1-hqjagain@gmail.com> <20200326001416.GH3756@localhost.localdomain> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Mar 26, 2020 at 09:30:08AM +0800, Qiujun Huang wrote: > On Thu, Mar 26, 2020 at 8:14 AM Marcelo Ricardo Leitner > wrote: > > > > On Sun, Mar 22, 2020 at 05:04:25PM +0800, Qiujun Huang wrote: > > > sctp_sock_migrate should iterate over the datamsgs to modify > > > all trunks(skbs) to newsk. For this, out_msg_list is added to > > > > s/trunks/chunks/ > > My :p. > > > > > > sctp_outq to maintain datamsgs list. > > > > It is an interesting approach. It speeds up the migration, yes, but it > > will also use more memory per datamsg, for an operation that, when > > performed, the socket is usually calm. > > > > It's also another list to be handled, and I'm not seeing the patch > > here move the datamsg itself now to the new outq. It would need > > something along these lines: > > Are all the rx chunks in the rx queues? Yes, even with GSO. > > > sctp_sock_migrate() > > { > > ... > > /* Move any messages in the old socket's receive queue that are for the > > * peeled off association to the new socket's receive queue. > > */ > > sctp_skb_for_each(skb, &oldsk->sk_receive_queue, tmp) { > > event = sctp_skb2event(skb); > > ... > > /* Walk through the pd_lobby, looking for skbs that > > * need moved to the new socket. > > */ > > sctp_skb_for_each(skb, &oldsp->pd_lobby, tmp) { > > event = sctp_skb2event(skb); > > > > That said, I don't think it's worth this new list. > > About this case: > datamsg > ->chunk0 chunk1 > chunk2 > queue ->transmitted ->retransmit > ->not in any queue We always can find it through the other chunks, otherwise it's freed. > > Also need to maintain a datamsg list to record which datamsg is > processed avoiding repetitive > processing. Right, but for that we can add a simple check on sctp_for_each_tx_datamsg() based on a parameter. > So, list it to outq. Maybe it will be used sometime. We can change it when the time comes. For now, if we can avoid growing sctp_datamsg, it's better. With this patch, it grows from 40 to 56 bytes, leaving just 8 left before it starts using a slab of 128 bytes for it. The patched list_for_each_entry() can/should be factored out into __sctp_for_each_tx_datachunk, whose first parameter then is the queue instead the asoc. ---8<--- diff --git a/net/sctp/socket.c b/net/sctp/socket.c index fed26a1e9518..62f401799709 100644 --- a/net/sctp/socket.c +++ b/net/sctp/socket.c @@ -148,19 +148,30 @@ static void sctp_clear_owner_w(struct sctp_chunk *chunk) } static void sctp_for_each_tx_datachunk(struct sctp_association *asoc, + bool clear, void (*cb)(struct sctp_chunk *)) { + struct sctp_datamsg *msg, *prev_msg = NULL; struct sctp_outq *q = &asoc->outqueue; + struct sctp_chunk *chunk, *c; struct sctp_transport *t; - struct sctp_chunk *chunk; list_for_each_entry(t, &asoc->peer.transport_addr_list, transports) list_for_each_entry(chunk, &t->transmitted, transmitted_list) cb(chunk); - list_for_each_entry(chunk, &q->retransmit, transmitted_list) - cb(chunk); + list_for_each_entry(chunk, &q->sacked, transmitted_list) { + msg = chunk->msg; + if (msg == prev_msg) + continue; + list_for_each_entry(c, &msg->chunks, frag_list) { + if ((clear && asoc->base.sk == c->skb->sk) || + (!clear && asoc->base.sk != c->skb->sk)) + cb(c); + } + prev_msg = msg; + } list_for_each_entry(chunk, &q->sacked, transmitted_list) cb(chunk); @@ -9574,9 +9585,9 @@ static int sctp_sock_migrate(struct sock *oldsk, struct sock *newsk, * paths won't try to lock it and then oldsk. */ lock_sock_nested(newsk, SINGLE_DEPTH_NESTING); - sctp_for_each_tx_datachunk(assoc, sctp_clear_owner_w); + sctp_for_each_tx_datachunk(assoc, true, sctp_clear_owner_w); sctp_assoc_migrate(assoc, newsk); - sctp_for_each_tx_datachunk(assoc, sctp_set_owner_w); + sctp_for_each_tx_datachunk(assoc, false, sctp_set_owner_w); /* If the association on the newsk is already closed before accept() * is called, set RCV_SHUTDOWN flag.