Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp223510pxx; Wed, 28 Oct 2020 03:18:42 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwOn1sl2aQoxmuA3t+bmwUlyBgZtxsjYDjMZFqxV7hZ7VgWOgkXYNwDOTYfkHc6jpQRkN3h X-Received: by 2002:aa7:d548:: with SMTP id u8mr6794393edr.321.1603880322121; Wed, 28 Oct 2020 03:18:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603880322; cv=none; d=google.com; s=arc-20160816; b=SQdeehzVyUm0HMVhXNXqY53RmIOTfEJZcahR+TT9MXI2TCfejmqjwlf/zwZT++6m2p soj0FKlskrecMMOcYP5btUwjE+BtJ+FO2yR5cxsAP1TeS1bvkpStSYs3noTrH4d/obyx /ovJ7yhhXPuqoufX4iPyUM2VvY0jRW89kdXVRG4q5+/vrjxfPqrqDBEV0kkNNJUZhqYj shLCPSidZNWljvG1DXM9cZaqR4shVr2ib6nFngspNH4fMBt555X7RBcPaOn932Zh2urh w45j4feM+1X2Udus4osprVVzoUyVtv7RwDcag5oFAT2H47kGMHz+O+vtG60gXAADZp+N D8vg== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=Oru2FlWehkw0hagZUG/AnoigLrXkOCOq4302uwOVdtY=; b=LxhXCTw2AXb2/wOKiCCqDBnNultsSto7JPz50zlf43QkQmjne6aTjCiRol9VpJT5cU qwirqdGrajAYpmOscjexsBwwGITU+ElXjuG/k+9HH5NNyUgkExKouY8YNC7rhNpB0NPQ UxbZOT84YK50lgCdi3qoGHsslDeLNa3blN+DXDjgf0JNKCRLyuNgS+3xGhEh1VAYSlR8 1KHfR2wMOu33YivobbpeRPD+VWrWIrLTyRUHNPunbhfcNItCdxUyX5GNBkxTh7AybL8P 5rhDiuO33ojN8hL9gVZ9EibPF8CPku40cDC44Ql54KyDNSR9K3sLMifE50VJTLVbwyCW Q41g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=QzsZJ2hi; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id s18si2795558ejd.147.2020.10.28.03.18.20; Wed, 28 Oct 2020 03:18: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=QzsZJ2hi; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1761072AbgJ0Ohv (ORCPT + 99 others); Tue, 27 Oct 2020 10:37:51 -0400 Received: from mail.kernel.org ([198.145.29.99]:36912 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1761056AbgJ0Ohs (ORCPT ); Tue, 27 Oct 2020 10:37:48 -0400 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (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 3D813207BB; Tue, 27 Oct 2020 14:37:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603809467; bh=caehzLcFJ81Qcd8lml6VlP0wX1r5SUkrnd8s6ZAUruk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QzsZJ2hi4InQc0NoXIyXb5ScHu3IeKQyFUW3MYqX5aMF9DZzXVlU8wFJoRgKQTK0Q A7Cjr6KUhD06bpebo3IucsGOu0EV4WVaNXqGS27Uv9eMYpajMZG/1Jgg55j5qqPQe0 RmMskIfkCGgovQCcjuzUcBjm7NQ/TiG7BN0QTWGE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Nathan Lynch , Christophe Leroy , Michael Ellerman , Sasha Levin Subject: [PATCH 5.4 206/408] powerpc/pseries: explicitly reschedule during drmem_lmb list traversal Date: Tue, 27 Oct 2020 14:52:24 +0100 Message-Id: <20201027135504.655837265@linuxfoundation.org> X-Mailer: git-send-email 2.29.1 In-Reply-To: <20201027135455.027547757@linuxfoundation.org> References: <20201027135455.027547757@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Nathan Lynch [ Upstream commit 9d6792ffe140240ae54c881cc4183f9acc24b4df ] The drmem lmb list can have hundreds of thousands of entries, and unfortunately lookups take the form of linear searches. As long as this is the case, traversals have the potential to monopolize the CPU and provoke lockup reports, workqueue stalls, and the like unless they explicitly yield. Rather than placing cond_resched() calls within various for_each_drmem_lmb() loop blocks in the code, put it in the iteration expression of the loop macro itself so users can't omit it. Introduce a drmem_lmb_next() iteration helper function which calls cond_resched() at a regular interval during array traversal. Each iteration of the loop in DLPAR code paths can involve around ten RTAS calls which can each take up to 250us, so this ensures the check is performed at worst every few milliseconds. Fixes: 6c6ea53725b3 ("powerpc/mm: Separate ibm, dynamic-memory data from DT format") Signed-off-by: Nathan Lynch Reviewed-by: Christophe Leroy Signed-off-by: Michael Ellerman Link: https://lore.kernel.org/r/20200813151131.2070161-1-nathanl@linux.ibm.com Signed-off-by: Sasha Levin --- arch/powerpc/include/asm/drmem.h | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/arch/powerpc/include/asm/drmem.h b/arch/powerpc/include/asm/drmem.h index 28c3d936fdf32..dcd6ac098a6e4 100644 --- a/arch/powerpc/include/asm/drmem.h +++ b/arch/powerpc/include/asm/drmem.h @@ -8,6 +8,8 @@ #ifndef _ASM_POWERPC_LMB_H #define _ASM_POWERPC_LMB_H +#include + struct drmem_lmb { u64 base_addr; u32 drc_index; @@ -26,8 +28,22 @@ struct drmem_lmb_info { extern struct drmem_lmb_info *drmem_info; +static inline struct drmem_lmb *drmem_lmb_next(struct drmem_lmb *lmb, + const struct drmem_lmb *start) +{ + /* + * DLPAR code paths can take several milliseconds per element + * when interacting with firmware. Ensure that we don't + * unfairly monopolize the CPU. + */ + if (((++lmb - start) % 16) == 0) + cond_resched(); + + return lmb; +} + #define for_each_drmem_lmb_in_range(lmb, start, end) \ - for ((lmb) = (start); (lmb) < (end); (lmb)++) + for ((lmb) = (start); (lmb) < (end); lmb = drmem_lmb_next(lmb, start)) #define for_each_drmem_lmb(lmb) \ for_each_drmem_lmb_in_range((lmb), \ -- 2.25.1