Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp687718ybv; Thu, 13 Feb 2020 07:47:19 -0800 (PST) X-Google-Smtp-Source: APXvYqyHosP5J69Fqd1ucJmxtJZO/V5PFVqBFThJMboU7ZEcsfJU56rDig8/7wuqpHwa8L2mxFcs X-Received: by 2002:aca:c415:: with SMTP id u21mr3352078oif.49.1581608838893; Thu, 13 Feb 2020 07:47:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581608838; cv=none; d=google.com; s=arc-20160816; b=tHgaieNobmj1Sy1P/5ytfWSNkTFABuIVOuMgMzL6f4i5nFgVFP+SA7tKlvsnlqTSQq nk+EvYxu1x7vZF6Y9ENrqDRpmJwgVoxcwlTuJVJQwChWI5VEs4Z2DrnQNnZh/ol5qTUR Bi5JkU+OKm2X7+yk6csaeS5g+hsD/d2X+7lJ+pa0Rg8r0usgMzNNGbmf1u3/ZuibmG1F Q6Ohd/bsnV6LOE2MQ4hZjMBp7CyhIpGingWWZkHGy/sbYYwtaXS/Lca+K76yykQSaMe1 cBbZ+IuT3y5oKY3GzFzuHwi3TQ6RG+803Pp0M0zA90cviGbJpQRrhEXbXMQW/uF5I9FL QSOw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=Z8kc+RBew4EnP4K3pTInP2aqyZYNYYQusEerE6YvJYA=; b=EGDX5T3AuW+E+q7gxii9PBbnBKK6xZJifJUhqHlAWAbMXaNRwlCZDh+n0oEJHBLVpz VgI9k1b7Y/aIh9dl6HpelGkTOzxror0XhxUZjeNo3h5rYmUXR+wGJH00rCZsm+Fn3bab EgJBzWbJSbQwszIFvWuu3EvG5YT/qg9Ue1QVdJESknecbwJzsQLVNAlPMcW34JfEq5EL /hzxYCuH0mI+jchh1w0glNxW3a6Pm+1SsYhFlBzK6mnGSfcxLZA7tq1esiJmfib7TrFg lR/8w5LDaBZMb0aEuqlVJRcPL2QG62cTKbzKTheJPkciab0gUexEbC0qiAHRX8AEVHkX Bv8g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=AgzMhJyM; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n9si1200901ota.103.2020.02.13.07.47.05; Thu, 13 Feb 2020 07:47:18 -0800 (PST) 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=@kernel.org header.s=default header.b=AgzMhJyM; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729315AbgBMP1M (ORCPT + 99 others); Thu, 13 Feb 2020 10:27:12 -0500 Received: from mail.kernel.org ([198.145.29.99]:40312 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728948AbgBMPZO (ORCPT ); Thu, 13 Feb 2020 10:25:14 -0500 Received: from localhost (unknown [104.132.1.104]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 32AE9246B3; Thu, 13 Feb 2020 15:25:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1581607513; bh=LDJ2gcdsdapsSCLe6d3TJz1woS6LRNQhKicWstxjU3M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AgzMhJyMhkqLfp+O/Pi/8flbzqIqR8nK+pek0OTUjsihqvTFHnZQrD+ZUIIUp0R3h zh5/803NZgGp/JLkMzF2nStq/YRyhhasnv7wMNdMmHzfS4ZZqBUIn4+nCAAkzMBhWG p65cFfUdG3GkH3P17l+Ar8DNr8XKQ0y/B+BW6SFo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Herbert Xu , Daniel Jordan , Sasha Levin Subject: [PATCH 4.14 057/173] padata: Remove broken queue flushing Date: Thu, 13 Feb 2020 07:19:20 -0800 Message-Id: <20200213151948.275124464@linuxfoundation.org> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200213151931.677980430@linuxfoundation.org> References: <20200213151931.677980430@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Herbert Xu [ Upstream commit 07928d9bfc81640bab36f5190e8725894d93b659 ] The function padata_flush_queues is fundamentally broken because it cannot force padata users to complete the request that is underway. IOW padata has to passively wait for the completion of any outstanding work. As it stands flushing is used in two places. Its use in padata_stop is simply unnecessary because nothing depends on the queues to be flushed afterwards. The other use in padata_replace is more substantial as we depend on it to free the old pd structure. This patch instead uses the pd->refcnt to dynamically free the pd structure once all requests are complete. Fixes: 2b73b07ab8a4 ("padata: Flush the padata queues actively") Cc: Signed-off-by: Herbert Xu Reviewed-by: Daniel Jordan Signed-off-by: Herbert Xu Signed-off-by: Sasha Levin --- kernel/padata.c | 46 ++++++++++++---------------------------------- 1 file changed, 12 insertions(+), 34 deletions(-) diff --git a/kernel/padata.c b/kernel/padata.c index 87540ce72aea6..ef4ba3d664dab 100644 --- a/kernel/padata.c +++ b/kernel/padata.c @@ -34,6 +34,8 @@ #define MAX_OBJ_NUM 1000 +static void padata_free_pd(struct parallel_data *pd); + static int padata_index_to_cpu(struct parallel_data *pd, int cpu_index) { int cpu, target_cpu; @@ -292,6 +294,7 @@ static void padata_serial_worker(struct work_struct *serial_work) struct padata_serial_queue *squeue; struct parallel_data *pd; LIST_HEAD(local_list); + int cnt; local_bh_disable(); squeue = container_of(serial_work, struct padata_serial_queue, work); @@ -301,6 +304,8 @@ static void padata_serial_worker(struct work_struct *serial_work) list_replace_init(&squeue->serial.list, &local_list); spin_unlock(&squeue->serial.lock); + cnt = 0; + while (!list_empty(&local_list)) { struct padata_priv *padata; @@ -310,9 +315,12 @@ static void padata_serial_worker(struct work_struct *serial_work) list_del_init(&padata->list); padata->serial(padata); - atomic_dec(&pd->refcnt); + cnt++; } local_bh_enable(); + + if (atomic_sub_and_test(cnt, &pd->refcnt)) + padata_free_pd(pd); } /** @@ -435,8 +443,7 @@ static struct parallel_data *padata_alloc_pd(struct padata_instance *pinst, setup_timer(&pd->timer, padata_reorder_timer, (unsigned long)pd); atomic_set(&pd->seq_nr, -1); atomic_set(&pd->reorder_objects, 0); - atomic_set(&pd->refcnt, 0); - pd->pinst = pinst; + atomic_set(&pd->refcnt, 1); spin_lock_init(&pd->lock); return pd; @@ -460,31 +467,6 @@ static void padata_free_pd(struct parallel_data *pd) kfree(pd); } -/* Flush all objects out of the padata queues. */ -static void padata_flush_queues(struct parallel_data *pd) -{ - int cpu; - struct padata_parallel_queue *pqueue; - struct padata_serial_queue *squeue; - - for_each_cpu(cpu, pd->cpumask.pcpu) { - pqueue = per_cpu_ptr(pd->pqueue, cpu); - flush_work(&pqueue->work); - } - - del_timer_sync(&pd->timer); - - if (atomic_read(&pd->reorder_objects)) - padata_reorder(pd); - - for_each_cpu(cpu, pd->cpumask.cbcpu) { - squeue = per_cpu_ptr(pd->squeue, cpu); - flush_work(&squeue->work); - } - - BUG_ON(atomic_read(&pd->refcnt) != 0); -} - static void __padata_start(struct padata_instance *pinst) { pinst->flags |= PADATA_INIT; @@ -498,10 +480,6 @@ static void __padata_stop(struct padata_instance *pinst) pinst->flags &= ~PADATA_INIT; synchronize_rcu(); - - get_online_cpus(); - padata_flush_queues(pinst->pd); - put_online_cpus(); } /* Replace the internal control structure with a new one. */ @@ -522,8 +500,8 @@ static void padata_replace(struct padata_instance *pinst, if (!cpumask_equal(pd_old->cpumask.cbcpu, pd_new->cpumask.cbcpu)) notification_mask |= PADATA_CPU_SERIAL; - padata_flush_queues(pd_old); - padata_free_pd(pd_old); + if (atomic_dec_and_test(&pd_old->refcnt)) + padata_free_pd(pd_old); if (notification_mask) blocking_notifier_call_chain(&pinst->cpumask_change_notifier, -- 2.20.1