Received: by 2002:a25:ef43:0:0:0:0:0 with SMTP id w3csp133122ybm; Tue, 26 May 2020 12:35:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz7+SZGgtLkAHRLjYV9PTrvjHGEyvA6ql0ZFcSAdaTuGQSbLXTienfZ3Hc0EiIJCVWRdlKm X-Received: by 2002:a17:906:39a:: with SMTP id b26mr2670241eja.204.1590521742953; Tue, 26 May 2020 12:35:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590521742; cv=none; d=google.com; s=arc-20160816; b=yZrev92lpZSTS9pSM0XG2P1v7YlG1z4YCyM1ESPiDkFD97gOVt0EuUfmq1lJodL1nU aYtUvfVWRaUp5yXEAjmOdx3s/ypCrfmCF6brt455LQDBMf3hXRpWlGAr7yv7NwiFdmPO sfEMhznbKOeYVRz7cNEtyzwldMTdMHO/49UnaxEhw0b4e9PKLmio5UG1n4dasy5sf98k n0udDobly8fh58XpW7xnyO/RL1G82ylu7x/NveuYGVM60JTNNyPPogRgVyRO6XA+YJwU XZHaxsgqV/6TZPG+hQitOm5KZOVyrbcCeDZPy/5SrCOYVCeWP50nKkZuLSEgesx1033V v8zw== 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=8yhzMM30pw1w5zBupW1+HN2yB7D7zlVV9XziQTYwiZY=; b=KnTPtrPcK7jCNcWn1HZC0uBp+ab11BbdCnFxHLno6psI1kNN0kXgUVMkolINyKHG7a oFxHm7bkzUbhiXL/ckMuN3uSUOpqLlGo979KREuvXw4KGjzTzYXXk0YJk5Pxl//SDyRK KZMXNucbMDT8nS0eVRyT1mESl8yZAA+uU9Fotv1KrRzihAjTZ13oRiC22bJvDGMFda2J +x7Cx60phNH8jlTVh/0GBPjuyMfovoKhCLznV/0AwKHzY9jBmCp5DLkTVEnLyC1xIptp U2BV4w1nGiE+Ip9Lz3dUbz0iQCtDjNQBa7FY8lsmmKoHJK+lUofipB3zfCrrguxx0k0p SkHA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=gYhk37g0; 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 cw7si462674edb.2.2020.05.26.12.35.20; Tue, 26 May 2020 12:35:42 -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=gYhk37g0; 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 S2390391AbgEZS6p (ORCPT + 99 others); Tue, 26 May 2020 14:58:45 -0400 Received: from mail.kernel.org ([198.145.29.99]:52256 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389676AbgEZS6n (ORCPT ); Tue, 26 May 2020 14:58: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 5BACB2084C; Tue, 26 May 2020 18:58:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1590519522; bh=XJJyoQtDvFZe4chBEWSdTN/XbaT92U3oizYWFpXeESA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gYhk37g0FtsyxZxpoRhpbsHM6xBZjyL7FcVoWHBAG9VhDEwSbJz3ywYtCaZtJYMEV hX+CBCwBj9KP6Vdy+L3/JlHI0DDdbNuU/8kbx/0NUxVxaZiY11JEb6AenYjZJFauMM onDPHGUHeP6KHQx2HvkAmAOqsF+Y2hl/gU6gArAU= 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.9 05/64] padata: ensure padata_do_serial() runs on the correct CPU Date: Tue, 26 May 2020 20:52:34 +0200 Message-Id: <20200526183914.952284064@linuxfoundation.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200526183913.064413230@linuxfoundation.org> References: <20200526183913.064413230@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 350ef88e7e922354f82a931897ad4a4ce6c686ff upstream. If the algorithm we're parallelizing is asynchronous we might change CPUs between padata_do_parallel() and padata_do_serial(). However, we don't expect this to happen as we need to enqueue the padata object into the per-cpu reorder queue we took it from, i.e. the same-cpu's parallel queue. Ensure we're not switching CPUs for a given padata object by tracking the CPU within the padata object. If the serial callback gets called on the wrong CPU, defer invoking padata_reorder() via a kernel worker on the CPU we're expected to run on. 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 | 20 +++++++++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) --- a/include/linux/padata.h +++ b/include/linux/padata.h @@ -37,6 +37,7 @@ * @list: List entry, to attach to the padata lists. * @pd: Pointer to the internal control structure. * @cb_cpu: Callback cpu for serializatioon. + * @cpu: Cpu for parallelization. * @seq_nr: Sequence number of the parallelized data object. * @info: Used to pass information from the parallel to the serial function. * @parallel: Parallel execution function. @@ -46,6 +47,7 @@ struct padata_priv { struct list_head list; struct parallel_data *pd; int cb_cpu; + int cpu; int info; void (*parallel)(struct padata_priv *padata); void (*serial)(struct padata_priv *padata); --- a/kernel/padata.c +++ b/kernel/padata.c @@ -133,6 +133,7 @@ int padata_do_parallel(struct padata_ins padata->cb_cpu = cb_cpu; target_cpu = padata_cpu_hash(pd); + padata->cpu = target_cpu; queue = per_cpu_ptr(pd->pqueue, target_cpu); spin_lock(&queue->parallel.lock); @@ -376,10 +377,21 @@ void padata_do_serial(struct padata_priv int cpu; struct padata_parallel_queue *pqueue; struct parallel_data *pd; + int reorder_via_wq = 0; pd = padata->pd; cpu = get_cpu(); + + /* We need to run on the same CPU padata_do_parallel(.., padata, ..) + * was called on -- or, at least, enqueue the padata object into the + * correct per-cpu queue. + */ + if (cpu != padata->cpu) { + reorder_via_wq = 1; + cpu = padata->cpu; + } + pqueue = per_cpu_ptr(pd->pqueue, cpu); spin_lock(&pqueue->reorder.lock); @@ -396,7 +408,13 @@ void padata_do_serial(struct padata_priv put_cpu(); - padata_reorder(pd); + /* If we're running on the wrong CPU, call padata_reorder() via a + * kernel worker. + */ + if (reorder_via_wq) + queue_work_on(cpu, pd->pinst->wq, &pqueue->reorder_work); + else + padata_reorder(pd); } EXPORT_SYMBOL(padata_do_serial);