From patchwork Fri Apr 30 12:09:15 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Henrique Barboza X-Patchwork-Id: 1472200 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=112.213.38.117; helo=lists.ozlabs.org; envelope-from=linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=S35mwL2E; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4FWrmv67tMz9t1X for ; Fri, 30 Apr 2021 22:10:55 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4FWrmh6hXsz3bs9 for ; Fri, 30 Apr 2021 22:10:44 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=S35mwL2E; dkim-atps=neutral X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::f30; helo=mail-qv1-xf30.google.com; envelope-from=danielhb413@gmail.com; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=S35mwL2E; dkim-atps=neutral Received: from mail-qv1-xf30.google.com (mail-qv1-xf30.google.com [IPv6:2607:f8b0:4864:20::f30]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4FWrlM6RTsz2yjS for ; Fri, 30 Apr 2021 22:09:34 +1000 (AEST) Received: by mail-qv1-xf30.google.com with SMTP id t14so4143035qvl.10 for ; Fri, 30 Apr 2021 05:09:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ammUdlr+/AWGv6OKuoANx3/D8JbixebRyuO/wvvbQiI=; b=S35mwL2EEuMXAH5yoOoHXlS1oU7FXmMPU5Nw/TLWYmRB58ZClaTu/VEI6x55dizFrW RnA8j0aZ5E/Os17+SrIL53AjKlxBlrE5827QZrjT7HOKws+oOYmKggazpMpmwYj8ZC5A NJxzzggxOqdPwNIk1uB+gSeZAA4j2gXhBOr9BXRxW5YXcddQSQGg6OgAQHJ2Qp24vMAZ lURkK89qIh+lb9JzgAy6zO2U7Vh01fiukpPULqGnk9xxFqVhdrxx7ckRm2HzzKi9y/da 0ZWOrapvRonlzyKSPZ2rua2JQLKMs7V2fwItqBsX1XQEjVWNm//ZE7ZGFIfqHF4XtpGW SfKw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ammUdlr+/AWGv6OKuoANx3/D8JbixebRyuO/wvvbQiI=; b=k2E2O1ploI2ljXAqPoLSsW3/4IdEkQe1/BBufHHgrkbeK7LrMgWT0ElT7iO0K63YeO V58/g+uSgQwvlhF9BzkjYGS69XtX6EjdX12gp5UDQZ+HUDAQ/G8Y420TTVk7sSCzm32z yi5px24VQWVAwP+qLUVw54MdYSmZEFp0NlTm2cwsyS7Jh47BUm2uifLi1KAMiaBSCA/C SKdwTYmA+o/9GPjob7m5DDCGcN9bIxEUx+U06KHZiDg2j8Y6er1PH956u51gXXJvIeQq ErA2zLcJN0YYP9fPnZDftOFlvalGCXLp8u4bD/Z+nO3l7xpNaKWC0F5oD/6ecMcifRp4 u7vA== X-Gm-Message-State: AOAM533i7UMQ6ytf03GBTXu+h+Nge4gsVrDK/8bEv0f4KWh7is4/85JJ 70pmnelESI/omIKB6kgUxGbodc33oOKrKw== X-Google-Smtp-Source: ABdhPJxCTlzp4XdUbJYxTyI/3h+DeOXfoStpanoHnvq9HjdttY9fcq9DmrISAA7yac1TI2Q2/OgExA== X-Received: by 2002:a05:6214:ace:: with SMTP id g14mr4861505qvi.43.1619784570766; Fri, 30 Apr 2021 05:09:30 -0700 (PDT) Received: from rekt.ibmuc.com ([2804:431:c7c7:6de0:3db1:1b8e:b097:6036]) by smtp.gmail.com with ESMTPSA id p190sm928951qke.13.2021.04.30.05.09.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Apr 2021 05:09:30 -0700 (PDT) From: Daniel Henrique Barboza To: linuxppc-dev@lists.ozlabs.org Subject: [PATCH 1/3] powerpc/pseries: Set UNISOLATE on dlpar_memory_remove_by_ic() error Date: Fri, 30 Apr 2021 09:09:15 -0300 Message-Id: <20210430120917.217951-2-danielhb413@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210430120917.217951-1-danielhb413@gmail.com> References: <20210430120917.217951-1-danielhb413@gmail.com> MIME-Version: 1.0 X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Daniel Henrique Barboza , david@gibson.dropbear.id.au Errors-To: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" As previously done in dlpar_cpu_remove() for CPUs, this patch changes dlpar_memory_remove_by_ic() to unisolate the LMB DRC when the LMB is failed to be removed. The hypervisor, seeing a LMB DRC that was supposed to be removed being unisolated instead, can do error recovery on its side. This change is done in dlpar_memory_remove_by_ic() only because, as of today, only QEMU is using this code path for error recovery (via the PSERIES_HP_ELOG_ID_DRC_IC event). phyp treats it as a no-op. Signed-off-by: Daniel Henrique Barboza Reviewed-by: David Gibson --- arch/powerpc/platforms/pseries/hotplug-memory.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/arch/powerpc/platforms/pseries/hotplug-memory.c b/arch/powerpc/platforms/pseries/hotplug-memory.c index 8377f1f7c78e..bb98574a84a2 100644 --- a/arch/powerpc/platforms/pseries/hotplug-memory.c +++ b/arch/powerpc/platforms/pseries/hotplug-memory.c @@ -551,6 +551,13 @@ static int dlpar_memory_remove_by_ic(u32 lmbs_to_remove, u32 drc_index) if (!drmem_lmb_reserved(lmb)) continue; + /* + * Setting the isolation state of an UNISOLATED/CONFIGURED + * device to UNISOLATE is a no-op, but the hypervisor can + * use it as a hint that the LMB removal failed. + */ + dlpar_unisolate_drc(lmb->drc_index); + rc = dlpar_add_lmb(lmb); if (rc) pr_err("Failed to add LMB, drc index %x\n", From patchwork Fri Apr 30 12:09:16 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Henrique Barboza X-Patchwork-Id: 1472199 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=2404:9400:2:0:216:3eff:fee1:b9f1; helo=lists.ozlabs.org; envelope-from=linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=mNqisGyU; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2404:9400:2:0:216:3eff:fee1:b9f1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4FWrmJ38Xvz9sCD for ; Fri, 30 Apr 2021 22:10:24 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4FWrmF2Rxcz2yy4 for ; Fri, 30 Apr 2021 22:10:21 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=mNqisGyU; dkim-atps=neutral X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::f32; helo=mail-qv1-xf32.google.com; envelope-from=danielhb413@gmail.com; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=mNqisGyU; dkim-atps=neutral Received: from mail-qv1-xf32.google.com (mail-qv1-xf32.google.com [IPv6:2607:f8b0:4864:20::f32]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4FWrlM5qQKz2xMd for ; Fri, 30 Apr 2021 22:09:35 +1000 (AEST) Received: by mail-qv1-xf32.google.com with SMTP id a30so7487727qvb.12 for ; Fri, 30 Apr 2021 05:09:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=FCHEd8Oh4sCwiIDjkXQVGV2uAW8LNQRKR2dIMMW/YVA=; b=mNqisGyUH3dJi+bN/KUV3DwODntofLI7rFtbngQQ1nIR4Eu7uapEv3QmBLkBsoidAb Nh7+H87wEe12m8N3grJ7QdH854m1QMjOSHCK7MHFqUI40YQukrrFy2DecdGkDyo/qNDj L/v7vb/KCNxu8sgKOJn2IfvCgVMpRh04huj+Haed5SSLnj1Q6IfUnuCLKvLyfxcUCS33 IYawWWHenCJw+7Um7cwNvPKOmor4jtlrE6wmPU4tJ/zXPTaBYto92aHkwC8Kek9OFxI1 qaGGgAXsHeZECk1sFlAXT62pVjtAdP5NeIovoNwJcdW90633FXN9VVD96CcaF2hn5Lef Rx9A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=FCHEd8Oh4sCwiIDjkXQVGV2uAW8LNQRKR2dIMMW/YVA=; b=DHbHNuU+jqz2xaTJ5EAmKSaGVhw/pWJnl/dmHKC19VCQWv9CgZO42vZfbtH6P7sE2T 6OmGr0wb/dA2H3HGBx41UD+5qsBy0pWzV9UWVb0hZqVJTgUVHLShf/W1K869B1r6jrQr 1Du/JYROAXwR1rrMIByZAyjhxjqUs1Z7zZh7skuTd0qKLtTjUlIJnTZ9qvGzgEYjH9Eb Rj16m6gxXkdZgn7V2bxB+t36nfSiBWtgKqzIMp7TkWUvj7cOtuK+ctZ09DeSE1yyS2CU gPO9jK4rJjZvzod5WbHQaXu7DqvHNXcKAaQHWgvuS83m53+hGFUbZZyvds7No0+AzqsH JUmQ== X-Gm-Message-State: AOAM533kMesU/dc6Rfa/hqDuOFd3uM7IViowbAEEfodnupTyg1AaoENf A51dV4cOwRYrAa5J9S5NcXoObkQTtiazSw== X-Google-Smtp-Source: ABdhPJzycOGUzsZ66+ljhJQeLti3DPpXtuu2D00aaJN3x01NpFKDJVB7EEj/OumbB3XlCDEVyJ9H8g== X-Received: by 2002:a0c:9e17:: with SMTP id p23mr5264983qve.7.1619784572456; Fri, 30 Apr 2021 05:09:32 -0700 (PDT) Received: from rekt.ibmuc.com ([2804:431:c7c7:6de0:3db1:1b8e:b097:6036]) by smtp.gmail.com with ESMTPSA id p190sm928951qke.13.2021.04.30.05.09.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Apr 2021 05:09:32 -0700 (PDT) From: Daniel Henrique Barboza To: linuxppc-dev@lists.ozlabs.org Subject: [PATCH 2/3] hotplug-memory.c: enhance dlpar_memory_remove* LMB checks Date: Fri, 30 Apr 2021 09:09:16 -0300 Message-Id: <20210430120917.217951-3-danielhb413@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210430120917.217951-1-danielhb413@gmail.com> References: <20210430120917.217951-1-danielhb413@gmail.com> MIME-Version: 1.0 X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Daniel Henrique Barboza , david@gibson.dropbear.id.au Errors-To: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" dlpar_memory_remove_by_ic() validates the amount of LMBs to be removed by checking !DRCONF_MEM_RESERVED, and in the following loop before dlpar_remove_lmb() a check for DRCONF_MEM_ASSIGNED is made before removing it. This means that a LMB that is both !DRCONF_MEM_RESERVED and !DRCONF_MEM_ASSIGNED will be counted as valid, but then not being removed. The function will end up not removing all 'lmbs_to_remove' LMBs while also not reporting any errors. Comparing it to dlpar_memory_remove_by_count(), the validation is done via lmb_is_removable(), which checks for DRCONF_MEM_ASSIGNED and fadump constraints. No additional check is made afterwards, and DRCONF_MEM_RESERVED is never checked before dlpar_remove_lmb(). The function doesn't have the same 'check A for validation, then B for removal' issue as remove_by_ic(), but it's not checking if the LMB is reserved. There is no reason for these functions to validate the same operation in two different manners. This patch addresses that by changing lmb_is_removable() to also check for DRCONF_MEM_RESERVED to tell if a lmb is removable, making dlpar_memory_remove_by_count() take the reservation state into account when counting the LMBs. lmb_is_removable() is then used in the validation step of dlpar_memory_remove_by_ic(), which is already checking for both states but in different stages, to avoid counting a LMB that is not assigned as eligible for removal. We can then skip the check before dlpar_remove_lmb() since we're validating all LMBs beforehand. Signed-off-by: Daniel Henrique Barboza --- arch/powerpc/platforms/pseries/hotplug-memory.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/arch/powerpc/platforms/pseries/hotplug-memory.c b/arch/powerpc/platforms/pseries/hotplug-memory.c index bb98574a84a2..4e6d162c3f1a 100644 --- a/arch/powerpc/platforms/pseries/hotplug-memory.c +++ b/arch/powerpc/platforms/pseries/hotplug-memory.c @@ -348,7 +348,8 @@ static int pseries_remove_mem_node(struct device_node *np) static bool lmb_is_removable(struct drmem_lmb *lmb) { - if (!(lmb->flags & DRCONF_MEM_ASSIGNED)) + if ((lmb->flags & DRCONF_MEM_RESERVED) || + !(lmb->flags & DRCONF_MEM_ASSIGNED)) return false; #ifdef CONFIG_FA_DUMP @@ -523,7 +524,7 @@ static int dlpar_memory_remove_by_ic(u32 lmbs_to_remove, u32 drc_index) /* Validate that there are enough LMBs to satisfy the request */ for_each_drmem_lmb_in_range(lmb, start_lmb, end_lmb) { - if (lmb->flags & DRCONF_MEM_RESERVED) + if (!lmb_is_removable(lmb)) break; lmbs_available++; @@ -533,9 +534,6 @@ static int dlpar_memory_remove_by_ic(u32 lmbs_to_remove, u32 drc_index) return -EINVAL; for_each_drmem_lmb_in_range(lmb, start_lmb, end_lmb) { - if (!(lmb->flags & DRCONF_MEM_ASSIGNED)) - continue; - rc = dlpar_remove_lmb(lmb); if (rc) break; From patchwork Fri Apr 30 12:09:17 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Henrique Barboza X-Patchwork-Id: 1472201 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=2404:9400:2:0:216:3eff:fee1:b9f1; helo=lists.ozlabs.org; envelope-from=linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=CYVIxRPt; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2404:9400:2:0:216:3eff:fee1:b9f1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4FWrnC6HZkz9t1C for ; Fri, 30 Apr 2021 22:11:11 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4FWrn92Yq2z3by1 for ; Fri, 30 Apr 2021 22:11:09 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=CYVIxRPt; dkim-atps=neutral X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::f34; helo=mail-qv1-xf34.google.com; envelope-from=danielhb413@gmail.com; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=CYVIxRPt; dkim-atps=neutral Received: from mail-qv1-xf34.google.com (mail-qv1-xf34.google.com [IPv6:2607:f8b0:4864:20::f34]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4FWrlP1bcKz2xMd for ; Fri, 30 Apr 2021 22:09:36 +1000 (AEST) Received: by mail-qv1-xf34.google.com with SMTP id j3so34207316qvs.1 for ; Fri, 30 Apr 2021 05:09:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=qWb3iMxKG0SSu3D8RWOJus3sgC3/X5T1NmRjRP8LfMk=; b=CYVIxRPtWrZ74CLfdDSgEbYnyZb5D1teR9WBUXmMS3cmILa3msCkDQq1PtmBMT87UO hXC6LMHw99Hg8jA8IzEq2aHQpWPgOntptY3fzOGMFUvST7P7QhHugRBOefqiGr9oGbOj 9toWDHp16NXGwpCrQDJwO4xQSS7ghxekwfATUwMKCbH25tFIL2RSSyW47c9rG1vHtIeZ PbHOp4bwt0K6lYoyPF/+CXrjgSxhsohckGSP2ryqM5Jtpwi9Uq14ErmCUqhUM7Tze1xd +03kd9nZXHGpETch3JDxSylydb2lh/nKFl1hfoO9aj3Fy4YFHyIdmcqs2OoHXiA3FeTn o8/g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=qWb3iMxKG0SSu3D8RWOJus3sgC3/X5T1NmRjRP8LfMk=; b=c/3sNunaa7Qs9zYTuPifGWp/Pk8Ucv5zigcLV1GxmhouyibxuaJdd+XT0xo2dX/NC9 jAwoofuW6bu+jc0UV4DNEcj6xT23J4FRzFLRtxE9EfTGLwzi3kIwf4AGL+X2b02jitYQ gh8gNli7HOY/aTdaI26Nvc3N7QHX/ZMLJBb5GXfTtv2ORmT8Y/TAXyg9H56Slte3dCvv Qhe8KWvLUas969NSXjrO+R7TxJUbOBgDDusnTF9abwlEp0/c2z1yk4VakPLlf0Cj5Nwp /OGPpCAUW+vpfuwg9A1V7+FvBDzOY9oa9dq4rT3Lh0qZL2QjNiHDqDFJbxyC2yPWx1PS fCTg== X-Gm-Message-State: AOAM531qPzOoLzRWSelQzkjq8IovwVm6RiPjmo5uNhrguQ3+f3XLixyG xEF8bkJceIFKEEWXHQCvI3vdAv4AJCnVtg== X-Google-Smtp-Source: ABdhPJx/AjtwsICBZBrgmBue2+zMVHxk5egpzXiqWFDV0PJNoGdf409/DhkaSWU7Pr7ATpLl3SyodA== X-Received: by 2002:ad4:5bef:: with SMTP id k15mr5161805qvc.16.1619784574162; Fri, 30 Apr 2021 05:09:34 -0700 (PDT) Received: from rekt.ibmuc.com ([2804:431:c7c7:6de0:3db1:1b8e:b097:6036]) by smtp.gmail.com with ESMTPSA id p190sm928951qke.13.2021.04.30.05.09.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Apr 2021 05:09:33 -0700 (PDT) From: Daniel Henrique Barboza To: linuxppc-dev@lists.ozlabs.org Subject: [PATCH 3/3] pseries/hotplug-memory.c: adding dlpar_memory_remove_lmbs_common() Date: Fri, 30 Apr 2021 09:09:17 -0300 Message-Id: <20210430120917.217951-4-danielhb413@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210430120917.217951-1-danielhb413@gmail.com> References: <20210430120917.217951-1-danielhb413@gmail.com> MIME-Version: 1.0 X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Daniel Henrique Barboza , david@gibson.dropbear.id.au Errors-To: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" One difference between dlpar_memory_remove_by_count() and dlpar_memory_remove_by_ic() is that the latter, added in commit 753843471cbb, removes the LMBs in a contiguous block. This was done because QEMU works with DIMMs, which is nothing more than a set of LMBs, that must be added or removed together. Failing to remove one LMB must fail the removal of the entire set of LMBs. Another difference is that dlpar_memory_remove_by_ic() is going to set the LMB DRC to unisolate in case of a removal error, which is a no-op for the hypervisors that doesn't care about this error handling knob, and could be called by remove_by_count() without issues. Aside from that, the logic is the same for both functions, and yet we keep them separated and having to duplicate LMB removal logic in both. This patch introduces a helper called dlpar_memory_remove_lmbs_common() to be used by both functions. The helper handles the case of block removal of remove_by_ic() by failing earlier in the validation and removal steps if the helper was called by remove_by_ic() (i.e. it was called with a drc_index) while preserving the more relaxed behavior of remove_by_count() if drc_index is 0. Signed-off-by: Daniel Henrique Barboza --- .../platforms/pseries/hotplug-memory.c | 163 +++++++----------- 1 file changed, 67 insertions(+), 96 deletions(-) diff --git a/arch/powerpc/platforms/pseries/hotplug-memory.c b/arch/powerpc/platforms/pseries/hotplug-memory.c index 4e6d162c3f1a..a031993725ca 100644 --- a/arch/powerpc/platforms/pseries/hotplug-memory.c +++ b/arch/powerpc/platforms/pseries/hotplug-memory.c @@ -399,25 +399,43 @@ static int dlpar_remove_lmb(struct drmem_lmb *lmb) return 0; } -static int dlpar_memory_remove_by_count(u32 lmbs_to_remove) +static int dlpar_memory_remove_lmbs_common(u32 lmbs_to_remove, u32 drc_index) { - struct drmem_lmb *lmb; - int lmbs_removed = 0; + struct drmem_lmb *lmb, *start_lmb, *end_lmb; int lmbs_available = 0; + int lmbs_removed = 0; int rc; - - pr_info("Attempting to hot-remove %d LMB(s)\n", lmbs_to_remove); + /* + * dlpar_memory_remove_by_ic() wants to remove all + * 'lmbs_to_remove' LMBs, starting from drc_index, in a + * contiguous block. + */ + bool block_removal; if (lmbs_to_remove == 0) return -EINVAL; + block_removal = drc_index != 0; + + if (block_removal) { + rc = get_lmb_range(drc_index, lmbs_to_remove, &start_lmb, &end_lmb); + if (rc) + return -EINVAL; + } else { + start_lmb = &drmem_info->lmbs[0]; + end_lmb = &drmem_info->lmbs[drmem_info->n_lmbs]; + } + /* Validate that there are enough LMBs to satisfy the request */ - for_each_drmem_lmb(lmb) { - if (lmb_is_removable(lmb)) + for_each_drmem_lmb_in_range(lmb, start_lmb, end_lmb) { + if (lmb_is_removable(lmb)) { lmbs_available++; - if (lmbs_available == lmbs_to_remove) + if (lmbs_available == lmbs_to_remove) + break; + } else if (block_removal) { break; + } } if (lmbs_available < lmbs_to_remove) { @@ -426,28 +444,40 @@ static int dlpar_memory_remove_by_count(u32 lmbs_to_remove) return -EINVAL; } - for_each_drmem_lmb(lmb) { + for_each_drmem_lmb_in_range(lmb, start_lmb, end_lmb) { rc = dlpar_remove_lmb(lmb); - if (rc) - continue; - /* Mark this lmb so we can add it later if all of the - * requested LMBs cannot be removed. - */ - drmem_mark_lmb_reserved(lmb); + if (!rc) { + /* Mark this lmb so we can add it later if all of the + * requested LMBs cannot be removed. + */ + drmem_mark_lmb_reserved(lmb); - lmbs_removed++; - if (lmbs_removed == lmbs_to_remove) + lmbs_removed++; + if (lmbs_removed == lmbs_to_remove) + break; + } else if (block_removal) { break; + } } if (lmbs_removed != lmbs_to_remove) { - pr_err("Memory hot-remove failed, adding LMB's back\n"); + if (block_removal) + pr_err("Memory indexed-count-remove failed, adding any removed LMBs\n"); + else + pr_err("Memory hot-remove failed, adding LMB's back\n"); - for_each_drmem_lmb(lmb) { + for_each_drmem_lmb_in_range(lmb, start_lmb, end_lmb) { if (!drmem_lmb_reserved(lmb)) continue; + /* + * Setting the isolation state of an UNISOLATED/CONFIGURED + * device to UNISOLATE is a no-op, but the hypervisor can + * use it as a hint that the LMB removal failed. + */ + dlpar_unisolate_drc(lmb->drc_index); + rc = dlpar_add_lmb(lmb); if (rc) pr_err("Failed to add LMB back, drc index %x\n", @@ -458,13 +488,13 @@ static int dlpar_memory_remove_by_count(u32 lmbs_to_remove) rc = -EINVAL; } else { - for_each_drmem_lmb(lmb) { + for_each_drmem_lmb_in_range(lmb, start_lmb, end_lmb) { if (!drmem_lmb_reserved(lmb)) continue; dlpar_release_drc(lmb->drc_index); - pr_info("Memory at %llx was hot-removed\n", - lmb->base_addr); + pr_info("Memory at %llx (drc index %x) was hot-removed\n", + lmb->base_addr, lmb->drc_index); drmem_remove_lmb_reservation(lmb); } @@ -474,6 +504,21 @@ static int dlpar_memory_remove_by_count(u32 lmbs_to_remove) return rc; } +static int dlpar_memory_remove_by_count(u32 lmbs_to_remove) +{ + pr_info("Attempting to hot-remove %d LMB(s)\n", lmbs_to_remove); + + return dlpar_memory_remove_lmbs_common(lmbs_to_remove, 0); +} + +static int dlpar_memory_remove_by_ic(u32 lmbs_to_remove, u32 drc_index) +{ + pr_info("Attempting to hot-remove %u LMB(s) at %x\n", + lmbs_to_remove, drc_index); + + return dlpar_memory_remove_lmbs_common(lmbs_to_remove, drc_index); +} + static int dlpar_memory_remove_by_index(u32 drc_index) { struct drmem_lmb *lmb; @@ -506,80 +551,6 @@ static int dlpar_memory_remove_by_index(u32 drc_index) return rc; } -static int dlpar_memory_remove_by_ic(u32 lmbs_to_remove, u32 drc_index) -{ - struct drmem_lmb *lmb, *start_lmb, *end_lmb; - int lmbs_available = 0; - int rc; - - pr_info("Attempting to hot-remove %u LMB(s) at %x\n", - lmbs_to_remove, drc_index); - - if (lmbs_to_remove == 0) - return -EINVAL; - - rc = get_lmb_range(drc_index, lmbs_to_remove, &start_lmb, &end_lmb); - if (rc) - return -EINVAL; - - /* Validate that there are enough LMBs to satisfy the request */ - for_each_drmem_lmb_in_range(lmb, start_lmb, end_lmb) { - if (!lmb_is_removable(lmb)) - break; - - lmbs_available++; - } - - if (lmbs_available < lmbs_to_remove) - return -EINVAL; - - for_each_drmem_lmb_in_range(lmb, start_lmb, end_lmb) { - rc = dlpar_remove_lmb(lmb); - if (rc) - break; - - drmem_mark_lmb_reserved(lmb); - } - - if (rc) { - pr_err("Memory indexed-count-remove failed, adding any removed LMBs\n"); - - - for_each_drmem_lmb_in_range(lmb, start_lmb, end_lmb) { - if (!drmem_lmb_reserved(lmb)) - continue; - - /* - * Setting the isolation state of an UNISOLATED/CONFIGURED - * device to UNISOLATE is a no-op, but the hypervisor can - * use it as a hint that the LMB removal failed. - */ - dlpar_unisolate_drc(lmb->drc_index); - - rc = dlpar_add_lmb(lmb); - if (rc) - pr_err("Failed to add LMB, drc index %x\n", - lmb->drc_index); - - drmem_remove_lmb_reservation(lmb); - } - rc = -EINVAL; - } else { - for_each_drmem_lmb_in_range(lmb, start_lmb, end_lmb) { - if (!drmem_lmb_reserved(lmb)) - continue; - - dlpar_release_drc(lmb->drc_index); - pr_info("Memory at %llx (drc index %x) was hot-removed\n", - lmb->base_addr, lmb->drc_index); - - drmem_remove_lmb_reservation(lmb); - } - } - - return rc; -} - #else static inline int pseries_remove_memblock(unsigned long base, unsigned long memblock_size)