From patchwork Wed Jul 8 19:42:11 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleg Nesterov X-Patchwork-Id: 493131 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 474421402B5 for ; Thu, 9 Jul 2015 05:44:01 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758870AbbGHTnz (ORCPT ); Wed, 8 Jul 2015 15:43:55 -0400 Received: from mx1.redhat.com ([209.132.183.28]:33094 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1758792AbbGHTnp (ORCPT ); Wed, 8 Jul 2015 15:43:45 -0400 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (Postfix) with ESMTPS id 299BDB6A3D; Wed, 8 Jul 2015 19:43:44 +0000 (UTC) Received: from tranklukator.brq.redhat.com (dhcp-1-208.brq.redhat.com [10.34.1.208]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with SMTP id t68JhfwX003573; Wed, 8 Jul 2015 15:43:42 -0400 Received: by tranklukator.brq.redhat.com (nbSMTP-1.00) for uid 500 oleg@redhat.com; Wed, 8 Jul 2015 21:42:13 +0200 (CEST) Date: Wed, 8 Jul 2015 21:42:11 +0200 From: Oleg Nesterov To: Alexei Starovoitov , "David S. Miller" , Eric Dumazet Cc: Jan Stancek , Marcelo Leitner , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/2] net: pktgen: fix race between pktgen_thread_worker() and kthread_stop() Message-ID: <20150708194211.GA26552@redhat.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20150708194154.GA26534@redhat.com> User-Agent: Mutt/1.5.18 (2008-05-17) X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org pktgen_thread_worker() is obviously racy, kthread_stop() can come between the kthread_should_stop() check and set_current_state(). Signed-off-by: Oleg Nesterov Reported-by: Jan Stancek Reported-by: Marcelo Leitner --- net/core/pktgen.c | 4 +++- 1 files changed, 3 insertions(+), 1 deletions(-) diff --git a/net/core/pktgen.c b/net/core/pktgen.c index 508155b..043ea18 100644 --- a/net/core/pktgen.c +++ b/net/core/pktgen.c @@ -3490,8 +3490,10 @@ static int pktgen_thread_worker(void *arg) pktgen_rem_thread(t); /* Wait for kthread_stop */ - while (!kthread_should_stop()) { + for (;;) { set_current_state(TASK_INTERRUPTIBLE); + if (kthread_should_stop()) + break; schedule(); } __set_current_state(TASK_RUNNING);