Received: by 2002:ac0:e350:0:0:0:0:0 with SMTP id g16csp14803imn; Thu, 28 Jul 2022 20:19:15 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vZcYevB4jeCmr3Jqs7VkJ/EVGmJAu0UXtAhHbr+wVq1WnTOdlMmjduyS8dWkjihiqwAE9A X-Received: by 2002:a17:907:7395:b0:72b:86f2:4fd5 with SMTP id er21-20020a170907739500b0072b86f24fd5mr1422497ejc.332.1659064755192; Thu, 28 Jul 2022 20:19:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659064755; cv=none; d=google.com; s=arc-20160816; b=Ef2dIzYJGGx/l7Hs2/ehxHZb5/LGTdYO2N9rCJqnBAdOzc2pDqvWbf4kK5Btaqhhht aGbh3r4ArFwIivEQUIICGLD+9pZdm1HAu0ZDGoGgm6Q8Y+wqdos05GoB7A+GDfx0K06y Y/6zTijt/EH33x4FpbbryZbhE+0287A24N8qwzofIJDz1BWuaqsgXOHT6o4PQhBPqQoO RdFXXoGjSO8l3JI/jbpXxYQvJYIZBybW2l7AGbiDhGTR282832pLPWkiwXoqBt8f6v2o Y0GObKhIUFaay7olhTAA63w8ZJjJQOvWWEGH8DUJdECdXi9nbp+bCSqXyDsMRCyWGiNX LB0g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=+qOwAxSbxSh2WmMt7nYF6poUZ4fzbRnVCZQY0RZKslY=; b=n8vWmeZhlPiLCMpda12CuaXJgy0naNIdE5yluDPOyEJTF836wijfgHT16U2WKSV5PX x0AhXHHraq4peHMDGeAOfE2VoGvxFuFGX9a5jcxMY0FYVfp69iYuAMFwhN7yE/ag4Iir dy56L396zFkvB7jDS6d7wqklqzo2Vv5IFRcj+lQjLwuPEQljXo9xnVVQewua3EoLXctD BJvaVzImwgLsXdrw5b6LS9h3+3APUmEQXd2trjtbiL2wZ7mJWVh0uXu/LxfoeB2p99QT ltzms1sHuCNlUSICgkM/sGv9XZiH82z6HQCLWyPT10qD5w/njH7N00ymIjT+PTa4D0Gh quqQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=CJom+OLY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g11-20020a170906868b00b0072b409233a7si1861392ejx.447.2022.07.28.20.18.50; Thu, 28 Jul 2022 20:19:15 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=CJom+OLY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233986AbiG2DBt (ORCPT + 99 others); Thu, 28 Jul 2022 23:01:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44682 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233929AbiG2DBo (ORCPT ); Thu, 28 Jul 2022 23:01:44 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 42E1F68DD8; Thu, 28 Jul 2022 20:01:43 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id B849BB82654; Fri, 29 Jul 2022 03:01:41 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1FF18C433C1; Fri, 29 Jul 2022 03:01:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1659063700; bh=K9tSEvBx+Ax+pmKxs7VgEeb1Jgj1kHaH3v9iA8cO8RE=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=CJom+OLYBCyBvYOCfegifO3qIzV4jzkcq+ltNrljOz0V8viWKDPdo1tO/DoFaw97b Vka7xYX9f8ZxWeu3ZBsb6aQH2bx8Do/jz+XV4OnCw0VZ76jVT2OuRh5+55yd9z+iuM YXz2JiQ8g/hO5XVDkiM6aSJp+o+Dv9Z4nzwHFJJCe/yI12Y8cRwQAZ47Nbnzk35PNX DGGu++wPnLDeQiu50pXDT6esOfuYxkAC4Z/pv1YiSfZ52xpAXViTLsft0DUYqj0PBX gachM9QO+1xDZrDIQnk+v+8utXjRQGH14RTcFuV+mTGTd6uvGQsxr6VlNDx1pVc6op LECXvg4GV1jww== Date: Thu, 28 Jul 2022 20:01:39 -0700 From: Jakub Kicinski To: Hangyu Hua Cc: davem@davemloft.net, edumazet@google.com, pabeni@redhat.com, kuniyu@amazon.co.jp, richard_siegfried@systemli.org, joannelkoong@gmail.com, socketcan@hartkopp.net, gerrit@erg.abdn.ac.uk, tomasz@grobelny.oswiecenia.net, dccp@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] dccp: put dccp_qpolicy_full() and dccp_qpolicy_push() in the same lock Message-ID: <20220728200139.1e7d9bc6@kernel.org> In-Reply-To: <20220727080609.26532-1-hbh25y@gmail.com> References: <20220727080609.26532-1-hbh25y@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-7.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 27 Jul 2022 16:06:09 +0800 Hangyu Hua wrote: > In the case of sk->dccps_qpolicy == DCCPQ_POLICY_PRIO, dccp_qpolicy_full > will drop a skb when qpolicy is full. And the lock in dccp_sendmsg is > released before sock_alloc_send_skb and then relocked after > sock_alloc_send_skb. The following conditions may lead dccp_qpolicy_push > to add skb to an already full sk_write_queue: > > thread1--->lock > thread1--->dccp_qpolicy_full: queue is full. drop a skb This linie should say "not full"? > thread1--->unlock > thread2--->lock > thread2--->dccp_qpolicy_full: queue is not full. no need to drop. > thread2--->unlock > thread1--->lock > thread1--->dccp_qpolicy_push: add a skb. queue is full. > thread1--->unlock > thread2--->lock > thread2--->dccp_qpolicy_push: add a skb! > thread2--->unlock > > Fix this by moving dccp_qpolicy_full. > > Fixes: 871a2c16c21b ("dccp: Policy-based packet dequeueing infrastructure") This code was added in b1308dc015eb0, AFAICT. Please double check. > Signed-off-by: Hangyu Hua > --- > net/dccp/proto.c | 10 +++++----- > 1 file changed, 5 insertions(+), 5 deletions(-) > > diff --git a/net/dccp/proto.c b/net/dccp/proto.c > index eb8e128e43e8..1a0193823c82 100644 > --- a/net/dccp/proto.c > +++ b/net/dccp/proto.c > @@ -736,11 +736,6 @@ int dccp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len) > > lock_sock(sk); > > - if (dccp_qpolicy_full(sk)) { > - rc = -EAGAIN; > - goto out_release; > - } > - > timeo = sock_sndtimeo(sk, noblock); > > /* > @@ -773,6 +768,11 @@ int dccp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len) > if (rc != 0) > goto out_discard; > > + if (dccp_qpolicy_full(sk)) { > + rc = -EAGAIN; > + goto out_discard; > + } Shouldn't this be earlier, right after relocking? Why copy the data etc. if we know the queue is full? > dccp_qpolicy_push(sk, skb); > /* > * The xmit_timer is set if the TX CCID is rate-based and will expire