Received: by 2002:a25:ef43:0:0:0:0:0 with SMTP id w3csp134144ybm; Tue, 26 May 2020 12:37:18 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxsFOQrC5bVfg1FFbBixrfT5M30cR9cjj/lsWxMt5Z2RxIAHuR4iFwEznKOwzFZQfYEhGaQ X-Received: by 2002:a17:906:63c9:: with SMTP id u9mr2631123ejk.487.1590521838556; Tue, 26 May 2020 12:37:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590521838; cv=none; d=google.com; s=arc-20160816; b=R/tCf1zw/pHnbPv0ZwzbwAH8xQRkjqA70eCnrvaXpnRvRIhvWHPt+ch7WoIpwRG8p0 +VjObQmBu2wcpHasjbvGz0GI81SjnUbzonQOKVprxeng7bImR7BiCW6GppXHD8xkDH1v Nw4PdwJPQEj1ikxJZLBh37ivJidCGgu2TKSO6JVmIfiL2Hyazd/KA/a2FuAtOaQyyL4e CKvociACygICGfjf+kuEzwiDJygP5dHKAZ7hmcGp04WL5LlvWTHfHuKko3+ioTeHfCG1 2Na0RtCa6w3nZJWGT9sNUD5qbwwnYljKcC0NIww0f0Y097blHEkQlBoff3/SaDw/mzl0 Uo/A== 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=Ge3MbSK2T1y+3qS4q3J1x9s5Kqjb2X+PWIpNsAPhvKo=; b=Fc/iP6Jiz3VBcH3usZFNHyCEfnPW5UiAzyUwvxWubJiqN2r2pGTLY84PqZ1NiJBre/ S0wCd+xjYX9FOkTJn+HOnXKP1gdC85m3Y92aaF4s8V6BhhXfvim+RWFTv5OOLeml8Av6 +PSLdFUqqVDX4eR2iXvDEsZCsQQF7z0yEEOf2qAbcdmoehizrwAvPZXOgCOLxmVM6haA sSWe2k0H8mMmfyGizqbPoZsa8aIXcAyv2gHrL2t3Snp6Nzn4qFYsnwhUZTAtFfTLvnLb F4JOZMnl4OtQ9UrquZyoRyluVCMNC5trOWyed3UdTGgmq7yf2D+IUgLKzxcphpoHJnbg BIRw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=v+X5BY9k; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a7si519239edb.445.2020.05.26.12.36.55; Tue, 26 May 2020 12:37:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=v+X5BY9k; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389635AbgEZSzq (ORCPT + 99 others); Tue, 26 May 2020 14:55:46 -0400 Received: from mail.kernel.org ([198.145.29.99]:48174 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389614AbgEZSzn (ORCPT ); Tue, 26 May 2020 14:55:43 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (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 E60DE20849; Tue, 26 May 2020 18:55:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1590519342; bh=30hosN3XGqyhYAlpFUcyInwX7uz4bI0skliC9qihkSY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=v+X5BY9kO0lcdQGndCJd80Jf7v/aWCA/nKhbdFT67yzJ/yyFqCY1EzdKVMhxKwY94 rEPtqMOlOSgxsEbBg7FocTsk2Gt7k9vW/WYhKBUTotPfdrfxO0XSj8mkUYRwYjXpsZ 6Z+NDJd7gVfCyVRGw5CGOk6BjnRGfyo/KuC7TDmA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Mathias Krause , Herbert Xu , Ben Hutchings Subject: [PATCH 4.4 04/65] padata: ensure the reorder timer callback runs on the correct CPU Date: Tue, 26 May 2020 20:52:23 +0200 Message-Id: <20200526183907.883106465@linuxfoundation.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200526183905.988782958@linuxfoundation.org> References: <20200526183905.988782958@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: Mathias Krause commit cf5868c8a22dc2854b96e9569064bb92365549ca upstream. The reorder timer function runs on the CPU where the timer interrupt was handled which is not necessarily one of the CPUs of the 'pcpu' CPU mask set. Ensure the padata_reorder() callback runs on the correct CPU, which is one in the 'pcpu' CPU mask set and, preferrably, the next expected one. Do so by comparing the current CPU with the expected target CPU. If they match, call padata_reorder() right away. If they differ, schedule a work item on the target CPU that does the padata_reorder() call for us. Signed-off-by: Mathias Krause Signed-off-by: Herbert Xu Cc: Ben Hutchings Signed-off-by: Greg Kroah-Hartman --- include/linux/padata.h | 2 ++ kernel/padata.c | 43 ++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 44 insertions(+), 1 deletion(-) --- a/include/linux/padata.h +++ b/include/linux/padata.h @@ -85,6 +85,7 @@ struct padata_serial_queue { * @swork: work struct for serialization. * @pd: Backpointer to the internal control structure. * @work: work struct for parallelization. + * @reorder_work: work struct for reordering. * @num_obj: Number of objects that are processed by this cpu. * @cpu_index: Index of the cpu. */ @@ -93,6 +94,7 @@ struct padata_parallel_queue { struct padata_list reorder; struct parallel_data *pd; struct work_struct work; + struct work_struct reorder_work; atomic_t num_obj; int cpu_index; }; --- a/kernel/padata.c +++ b/kernel/padata.c @@ -281,11 +281,51 @@ static void padata_reorder(struct parall return; } +static void invoke_padata_reorder(struct work_struct *work) +{ + struct padata_parallel_queue *pqueue; + struct parallel_data *pd; + + local_bh_disable(); + pqueue = container_of(work, struct padata_parallel_queue, reorder_work); + pd = pqueue->pd; + padata_reorder(pd); + local_bh_enable(); +} + static void padata_reorder_timer(unsigned long arg) { struct parallel_data *pd = (struct parallel_data *)arg; + unsigned int weight; + int target_cpu, cpu; - padata_reorder(pd); + cpu = get_cpu(); + + /* We don't lock pd here to not interfere with parallel processing + * padata_reorder() calls on other CPUs. We just need any CPU out of + * the cpumask.pcpu set. It would be nice if it's the right one but + * it doesn't matter if we're off to the next one by using an outdated + * pd->processed value. + */ + weight = cpumask_weight(pd->cpumask.pcpu); + target_cpu = padata_index_to_cpu(pd, pd->processed % weight); + + /* ensure to call the reorder callback on the correct CPU */ + if (cpu != target_cpu) { + struct padata_parallel_queue *pqueue; + struct padata_instance *pinst; + + /* The timer function is serialized wrt itself -- no locking + * needed. + */ + pinst = pd->pinst; + pqueue = per_cpu_ptr(pd->pqueue, target_cpu); + queue_work_on(target_cpu, pinst->wq, &pqueue->reorder_work); + } else { + padata_reorder(pd); + } + + put_cpu(); } static void padata_serial_worker(struct work_struct *serial_work) @@ -412,6 +452,7 @@ static void padata_init_pqueues(struct p __padata_list_init(&pqueue->reorder); __padata_list_init(&pqueue->parallel); INIT_WORK(&pqueue->work, padata_parallel_worker); + INIT_WORK(&pqueue->reorder_work, invoke_padata_reorder); atomic_set(&pqueue->num_obj, 0); } }