Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp273421pxx; Wed, 28 Oct 2020 04:42:54 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzSwLixX9wrs8xMKOOykxD9v4TzIRxwSDxnsRB9Hl41uGou5XdtFUwaRAeQFwwJqs7INDYf X-Received: by 2002:a17:906:1fda:: with SMTP id e26mr6722594ejt.528.1603885374516; Wed, 28 Oct 2020 04:42:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603885374; cv=none; d=google.com; s=arc-20160816; b=AwT6lPL/9ATJ5fsiT0YdjgzURbLac1R2ZntwGlsJ2OVLRNKgJx8bd5kgkhycWJynrO ElIqQPU5M//zg70TqVa236HpH3vzJnLz6TsxXSCEGxCal81Uaak7euq4HxdQ9kmXaazv gOYLov2SFgaDQuBjJmiiKGbHfLVeNRs1EhBYIJlrEBwrhiLHEkAN9Z+qjCRGb7EEG+7J EUhyIPEThCKwe1GTSmmyJb4R4WGJG49ecINeWBU8QH8RxRVfN8GwnYglDnmF6Fl+U88E aZfI7WGV3Y9CtOtG/6nPH+iOjWNj0JKyM6TbxrkCTg40jLV5jZuDAiNTK/4qSRkOuKcO +LmA== 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=6FmbhCqqzbFcLPq6QXeN/lvlVUwGOR+Wa99lZxlx9SA=; b=djk3pQTkC7ZGfIDVz4r35J2dOm8dYKfarXuOMAJU/sUf35oNQFAE2OfMrj+O+zD0l1 qWuqxwgooO/z2jih3IBB2wBHEwTklyqkvQJTi7xpc5FpCtEPBEEqsNCSAJKApEIgNHu7 FEL/PO9XL/L5axEM3PklxFgPKDi6bROAFOym92WRtpYgBLUj2QfM/dbDq3LVxkfmyM0x VuUtSPP0vxSRxOY9cem61ERhcgo/f09PVmVugWLREtaCC7jVhpoGwNA8ncBzxiUlKIvc +4sx9fuzanP5A/tz9IqAIQSOvF4sF44RltzMbE2GscwB+rgB6zrSiow2yPJ7IaWPko9h ReXw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=apq3Oqpy; 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 g8si3473416ejm.389.2020.10.28.04.42.32; Wed, 28 Oct 2020 04:42:54 -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=apq3Oqpy; 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 S1794158AbgJ0PKO (ORCPT + 99 others); Tue, 27 Oct 2020 11:10:14 -0400 Received: from mail.kernel.org ([198.145.29.99]:37540 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1789833AbgJ0PDL (ORCPT ); Tue, 27 Oct 2020 11:03:11 -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 2AE4220747; Tue, 27 Oct 2020 15:03:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603810989; bh=NRBwGddatv+MfdZJb5wbsyP/OzXrAL3uRMvI8utZBy8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=apq3OqpyMcxmPVmtGPy7uhSgYbNLsFGxGrxAdkpae6Amg4iYPP5DWg5EfyAz6I1Pv Qmfden0XOEsYKAbdi98kOZG5lh2VSsIzsUc9KTxNN/zP+P3xmwSN6swysz0IYbP5aO gWhBUtJPHgTd+3jFJTR7iXHyUfT4AkBVxKC2Sa88= 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.8 334/633] powerpc/pseries: explicitly reschedule during drmem_lmb list traversal Date: Tue, 27 Oct 2020 14:51:17 +0100 Message-Id: <20201027135538.352316674@linuxfoundation.org> X-Mailer: git-send-email 2.29.1 In-Reply-To: <20201027135522.655719020@linuxfoundation.org> References: <20201027135522.655719020@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 414d209f45bbe..1ec6de1a88514 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