From patchwork Wed May 12 20:28:06 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: 1477826 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=G285b8MK; 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 4FgRGF5dRJz9tD3 for ; Thu, 13 May 2021 06:29:09 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4FgRGF4hBbz2yyj for ; Thu, 13 May 2021 06:29: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=G285b8MK; 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::733; helo=mail-qk1-x733.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=G285b8MK; dkim-atps=neutral Received: from mail-qk1-x733.google.com (mail-qk1-x733.google.com [IPv6:2607:f8b0:4864:20::733]) (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 4FgRFP1bMSz2yZ2 for ; Thu, 13 May 2021 06:28:23 +1000 (AEST) Received: by mail-qk1-x733.google.com with SMTP id q10so19398864qkc.5 for ; Wed, 12 May 2021 13:28:23 -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=MnLw8z3Y2kRv0K/DZe65NliwkeKzvJ4qLDaYSw1HREM=; b=G285b8MKp4ceo7EgDZt/QITPWr0VudPM5J86sAMYczovNwwVqtRisN7q55zyf3U8kj GFrnIFbFOIsDPUCfJNLHUr0G5H8lUGRA5mwZ9I2FRjVBZbGypKE+j8vNzmCrkL2FfIK0 mRXIpG8Lv3JkBvd4vdXcf1tO4PcJX9UTq9pDqFqd7eyvHzws7zNC0ZVueLvcbltnQVlB VpIPL0HzeDI+Send5WVxOcbweZwWAcm1douhvz2elzfbSoncSy5PnFqhfIuKVvTlULXy YX3uLbPgEAyfX7XdW57Jz3CEAsw00+w46cc8VrKsOUG4lXLIvEIQRdUN1DAixMO2TGXE ANew== 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=MnLw8z3Y2kRv0K/DZe65NliwkeKzvJ4qLDaYSw1HREM=; b=i/3RQRJ/72a4SkdkGZ/zIgeGWLbQkQNx2lZT6wYtQGrE/Px7TQrVHEo/9wkRHxTEgy CGKSjf3dINDeNNVtZp7suUmESKUhiQvS9+bmV0tIuvuKA5F64ygZVb1P8pfcx6ND9f5e 6cLE68Fp6hAkvz8tFyCyRar4T6jErBid62Zlu17QcLC+fRJgZwNsxT4PocQeLz9IJk/6 rWx+bad/lg1q1gyUXv+GG0Un0g7Ys8aZc7+nMgH5UV+a057ZhRoR40rOoEu7H9MzRRJk ScWuKfZtenq4oV2gwTXUZP3qH/ly3c5q6HYIAmyZQmHcLApQZaWcltP5RSm5q/scJNZr RJXw== X-Gm-Message-State: AOAM533a3bJxUIUquYYe4vTkpDJ+bkceNf1jKWXeJMjunLVTgLEXeBo3 dlCSZ4p8ekslfAF6wkIWgnclqKA7JsslUw== X-Google-Smtp-Source: ABdhPJxK5eN4GtjpL1kpPBpCOvcnW4DJ/WxD4CSqq8dH8dJhQ0HWmMZuRe2Zwaq0jmN9scN+C+CrZQ== X-Received: by 2002:a37:e40f:: with SMTP id y15mr36402089qkf.314.1620851300114; Wed, 12 May 2021 13:28:20 -0700 (PDT) Received: from rekt.ibmuc.com ([2804:431:c7c6:fb9a:a1c9:c5a3:1e98:bc69]) by smtp.gmail.com with ESMTPSA id j29sm778317qtv.6.2021.05.12.13.28.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 May 2021 13:28:19 -0700 (PDT) From: Daniel Henrique Barboza To: linuxppc-dev@lists.ozlabs.org Subject: [PATCH v2 1/4] powerpc/pseries: Set UNISOLATE on dlpar_memory_remove_by_ic() error Date: Wed, 12 May 2021 17:28:06 -0300 Message-Id: <20210512202809.95363-2-danielhb413@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210512202809.95363-1-danielhb413@gmail.com> References: <20210512202809.95363-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. Reviewed-by: David Gibson Signed-off-by: Daniel Henrique Barboza --- 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 Wed May 12 20:28:07 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: 1477825 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=oKzYDYCk; 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 4FgRFn3d6sz9t9y for ; Thu, 13 May 2021 06:28:45 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4FgRFn3CGcz3080 for ; Thu, 13 May 2021 06:28:45 +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=oKzYDYCk; 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::82b; helo=mail-qt1-x82b.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=oKzYDYCk; dkim-atps=neutral Received: from mail-qt1-x82b.google.com (mail-qt1-x82b.google.com [IPv6:2607:f8b0:4864:20::82b]) (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 4FgRFP0ksnz2yYv for ; Thu, 13 May 2021 06:28:24 +1000 (AEST) Received: by mail-qt1-x82b.google.com with SMTP id h21so14470539qtu.5 for ; Wed, 12 May 2021 13:28:24 -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=LZlefKr1lV7bmtdSSoz8XhCmkGKvesGkL6F37B8vsmM=; b=oKzYDYCk/jEDeyJZmbBl/FAcgQau5/B/XgiIxxqXoqbKyaAdTWeBOm0+CW6GmBDWJB +9M8l9TL7p39DjpzleAQcWGgZduUsRwbsvklF3FUkvIZ+sDnDjqfKCjWPIS4FlEtNu5i xSNjqr3mtE+0IpBh21yL3Y1s5wQGx876HjnPWfH7tv/sLUmS8d2PZSqlD8fNvhLtJMIu T4hqjGYms1+cDmoLa7hjsOIK2tB8xc9DKWeKXpv9dLimdzDPjAepRsl48RDnSgLKM6ce Nvg2IaTX04fF8khv9JMUALf5rXY8mdtX/wvrJfLI8SNjBwc13f/sSvUX0MowoAAuuWYu eAVA== 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=LZlefKr1lV7bmtdSSoz8XhCmkGKvesGkL6F37B8vsmM=; b=Xmwm2t0jPTFlC1bJtWdH7oF1VHHuKODwRlmWFEL+Cz8vE19t2wCXUAxNJMkdOE/1DT HnP1CcslQCaAOKNx1jWwcAvCKM7Gt0w/VHKH5jfkkT8lC11clhx4VrMeBhHwvMy2ufKD jEeafV4qUl9DdcXFZ77UZWf9aIkF/N5I8jVrNOtKTK4w51YoWnePRYDVn2UShA2mKAiS KaRIhWX4w1/ufMsWh6zfKpn17dPV5+mYXmwNM5yMNd/7PR1uDpkD9y6TFSDcxQGEZx2W OIoT1q7Wovrk9kuXW24JqlJkmI0yGZIH5ZVl/AxAA0J0xveB0lwjh4djw3e0DPRJ5iQ7 YTYg== X-Gm-Message-State: AOAM533yJrCsDt11cDn1W+o4TucxijmLbDlhn64/v/B9EXpaWal7hmuu 6tbCxWdrElwgtEI5lfzrQ2SuWvyuBFExMw== X-Google-Smtp-Source: ABdhPJwyadHXplc1aglxlsfLXCGWgQqhORS9s7IBjThCOr21yeheVAH7WIc+6FFgH+Bd9YJTm15hCg== X-Received: by 2002:a05:622a:1756:: with SMTP id l22mr21902768qtk.367.1620851301952; Wed, 12 May 2021 13:28:21 -0700 (PDT) Received: from rekt.ibmuc.com ([2804:431:c7c6:fb9a:a1c9:c5a3:1e98:bc69]) by smtp.gmail.com with ESMTPSA id j29sm778317qtv.6.2021.05.12.13.28.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 May 2021 13:28:21 -0700 (PDT) From: Daniel Henrique Barboza To: linuxppc-dev@lists.ozlabs.org Subject: [PATCH v2 2/4] powerpc/pseries: check DRCONF_MEM_RESERVED in lmb_is_removable() Date: Wed, 12 May 2021 17:28:07 -0300 Message-Id: <20210512202809.95363-3-danielhb413@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210512202809.95363-1-danielhb413@gmail.com> References: <20210512202809.95363-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" DRCONF_MEM_RESERVED is a flag that represents the "Reserved Memory" status in LOPAR v2.10, section 4.2.8. If a LMB is marked as reserved, quoting LOPAR, "is not to be used or altered by the base OS". This flag is read only in the kernel, being set by the firmware/hypervisor in the DT. As an example, QEMU will set this flag in hw/ppc/spapr.c, spapr_dt_dynamic_memory(). lmb_is_removable() does not check for DRCONF_MEM_RESERVED. This function is used in dlpar_remove_lmb() as a guard before the removal logic. Since it is failing to check for !RESERVED, dlpar_remove_lmb() will fail in a later stage instead of failing in the validation when receiving a reserved LMB as input. lmb_is_removable() is also used in dlpar_memory_remove_by_count() to evaluate if we have enough LMBs to complete the request. The missing !RESERVED check in this case is causing dlpar_memory_remove_by_count() to miscalculate the number of elegible LMBs for the removal, and can make it error out later on instead of failing in the validation with the 'not enough LMBs to satisfy request' message. Making a DRCONF_MEM_RESERVED check in lmb_is_removable() fixes all these issues. Signed-off-by: Daniel Henrique Barboza Reviewed-by: David Gibson --- arch/powerpc/platforms/pseries/hotplug-memory.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/arch/powerpc/platforms/pseries/hotplug-memory.c b/arch/powerpc/platforms/pseries/hotplug-memory.c index bb98574a84a2..c21d9278c1ce 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 From patchwork Wed May 12 20:28:08 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: 1477828 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=mKGdzd/F; 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 4FgRH91w25z9tjs for ; Thu, 13 May 2021 06:29:57 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4FgRH91KfYz3c6V for ; Thu, 13 May 2021 06:29:57 +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=mKGdzd/F; 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::72d; helo=mail-qk1-x72d.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=mKGdzd/F; dkim-atps=neutral Received: from mail-qk1-x72d.google.com (mail-qk1-x72d.google.com [IPv6:2607:f8b0:4864:20::72d]) (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 4FgRFQ4DWCz2yZ2 for ; Thu, 13 May 2021 06:28:26 +1000 (AEST) Received: by mail-qk1-x72d.google.com with SMTP id f18so1700926qko.7 for ; Wed, 12 May 2021 13:28:25 -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=HTXk1a7oJSPPEp2eJBPzk556VZYQl+73aNOZUMvWRVI=; b=mKGdzd/FraRwYy0PSYA48UgY1qDWuV7zGw6Tk3BcAhKGS/rNJS43eV9cLMWE21Ma5k JRkqW2lcC5fjxl1ebkejaQnSLdxjw7B0I4wNDWGPKCpQAG5ePK9s7xAVIXSrQGvYLfcD WGjWTzEITawbejiYbotF6q8JR+0mGLbLCIANPdHqilNZgkzpxIE0HfgrWLxKXrJbiTLp esrTUinuM4uK3Q168AHGgMnM+nCdKJDXG5Rac2qwOQRDP+88F/NgjZEcEFeLqx3Fzikb nEHTzwHzsy0aB6nvMPiPAenhQ7GB1AVqyxyf+933CLo+mgoyj9/ACh0pcNkNHGqBWMgK g4hQ== 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=HTXk1a7oJSPPEp2eJBPzk556VZYQl+73aNOZUMvWRVI=; b=mVPgxc9pKD1QicV3saGkEPxtvZV9fUnI6oSxxku8Eywn8KUbIKG14w0q33rXPJfO92 +hIYC7FcapRFVedGchMpE885V3u1LF1L/v951qJQItn5jDshhBynT1dRiiSfYaXsRsrz 4nctEI5Rbv9GKUx9A8Ie8VX9qVC7Ibo5lmIe38ogokkXjuGvKPvmeZfu6vdWMabXWRzi j3I10Am9GDNh2ZnkbRubrmW1D60bKkh+uexyYVVRpvSfAmza2rC13LXwWVvrl7FrA+gi 6EOoGBz2ZrTazqSOAVyeDj8YnkYxWoLhsPWN/LyVDJwj6kJLUdL4R5HJpn5lerEPZj+W O48Q== X-Gm-Message-State: AOAM5311E7MGf0xJxX2Jvc/ThQzTHIm4Q563HsUGHZy3Bzkc2xsAZ4e4 PGKR4z4LRW/ovIaGXsOC9z6fDrSP6CP6Bg== X-Google-Smtp-Source: ABdhPJz58dAD3woZDtFQZmBtX98ba37mTSqccfkHsz2PCzZrJQN99bThyQr5BMdkI6Rx3yRJvKreEA== X-Received: by 2002:a05:620a:3c8:: with SMTP id r8mr34622746qkm.204.1620851303595; Wed, 12 May 2021 13:28:23 -0700 (PDT) Received: from rekt.ibmuc.com ([2804:431:c7c6:fb9a:a1c9:c5a3:1e98:bc69]) by smtp.gmail.com with ESMTPSA id j29sm778317qtv.6.2021.05.12.13.28.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 May 2021 13:28:23 -0700 (PDT) From: Daniel Henrique Barboza To: linuxppc-dev@lists.ozlabs.org Subject: [PATCH v2 3/4] powerpc/pseries: break early in dlpar_memory_remove_by_count() loops Date: Wed, 12 May 2021 17:28:08 -0300 Message-Id: <20210512202809.95363-4-danielhb413@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210512202809.95363-1-danielhb413@gmail.com> References: <20210512202809.95363-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" After marking the LMBs as reserved depending on dlpar_remove_lmb() rc, we evaluate whether we need to add the LMBs back or if we can release the LMB DRCs. In both cases, a for_each_drmem_lmb() loop without a break condition is used. This means that we're going to cycle through all LMBs of the partition even after we're done with what we were going to do. This patch adds break conditions in both loops to avoid this. The 'lmbs_removed' variable was renamed to 'lmbs_reserved', and it's now being decremented each time a lmb reservation is removed, indicating that the operation we're doing (adding back LMBs or releasing DRCs) is completed. Signed-off-by: Daniel Henrique Barboza Reviewed-by: David Gibson --- arch/powerpc/platforms/pseries/hotplug-memory.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/arch/powerpc/platforms/pseries/hotplug-memory.c b/arch/powerpc/platforms/pseries/hotplug-memory.c index c21d9278c1ce..3c7ce5361ce3 100644 --- a/arch/powerpc/platforms/pseries/hotplug-memory.c +++ b/arch/powerpc/platforms/pseries/hotplug-memory.c @@ -402,7 +402,7 @@ static int dlpar_remove_lmb(struct drmem_lmb *lmb) static int dlpar_memory_remove_by_count(u32 lmbs_to_remove) { struct drmem_lmb *lmb; - int lmbs_removed = 0; + int lmbs_reserved = 0; int lmbs_available = 0; int rc; @@ -436,12 +436,12 @@ static int dlpar_memory_remove_by_count(u32 lmbs_to_remove) */ drmem_mark_lmb_reserved(lmb); - lmbs_removed++; - if (lmbs_removed == lmbs_to_remove) + lmbs_reserved++; + if (lmbs_reserved == lmbs_to_remove) break; } - if (lmbs_removed != lmbs_to_remove) { + if (lmbs_reserved != lmbs_to_remove) { pr_err("Memory hot-remove failed, adding LMB's back\n"); for_each_drmem_lmb(lmb) { @@ -454,6 +454,10 @@ static int dlpar_memory_remove_by_count(u32 lmbs_to_remove) lmb->drc_index); drmem_remove_lmb_reservation(lmb); + + lmbs_reserved--; + if (lmbs_reserved == 0) + break; } rc = -EINVAL; @@ -467,6 +471,10 @@ static int dlpar_memory_remove_by_count(u32 lmbs_to_remove) lmb->base_addr); drmem_remove_lmb_reservation(lmb); + + lmbs_reserved--; + if (lmbs_reserved == 0) + break; } rc = 0; } From patchwork Wed May 12 20:28:09 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: 1477829 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=Rof9PNbs; 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 4FgRHk4xnxz9tD3 for ; Thu, 13 May 2021 06:30:26 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4FgRHk4Rnjz3cCd for ; Thu, 13 May 2021 06:30:26 +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=Rof9PNbs; 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::82e; helo=mail-qt1-x82e.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=Rof9PNbs; dkim-atps=neutral Received: from mail-qt1-x82e.google.com (mail-qt1-x82e.google.com [IPv6:2607:f8b0:4864:20::82e]) (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 4FgRFS0FGlz2yxx for ; Thu, 13 May 2021 06:28:27 +1000 (AEST) Received: by mail-qt1-x82e.google.com with SMTP id c11so18136744qth.2 for ; Wed, 12 May 2021 13:28:27 -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=Dsy3PfYJ190WRITM13ezUcXmWtPBC6Plo+PBzZJW2rE=; b=Rof9PNbssi13Gw1S0Y09j4Sp0RBDCq8IJgnSr98HwGeBg0m65EDUJVgaVmEyS/+ZzZ zyQq3reW08EhD/dM2o4I99rj9aBw6Xk/AJ6+Slb6bqeKRhx3Yd3bPkLxLkIlz9HwERr6 d1o3+gmJIQ8lsgxv9Tn1Dlu0SHQRpVMyw2CW4+lRl7QHIJZbUT/prIILunoaizJM2NQX WsNu/hB4m/w3fG3jf70DP/EcgWCQ/iKmTC3SB5ktOCuRBjwil+SC+HqWRiShzx8FZFFF SPgeoyGIAQyCJVETgK5l1RMGbD09UVnJY8H839GaOxczLdSTT3+3T1yGZ1h+f2nD66b5 SGdQ== 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=Dsy3PfYJ190WRITM13ezUcXmWtPBC6Plo+PBzZJW2rE=; b=qvyPBXhP6T6GPcEqOJHsmJm0J6mwIvydoT6wviNam1EzosArwObFdapVxo/M+is7Nx y9ZdYSE1jGIwA7ntbALjlrGy9Luu25GXsG3uSGojALOtNrKj9H13HO5MV7KYcHr80DnV sEo0Cz7TJj6YQ/WydESOqCaYdISKkIlMvZEqxG84RLTzOCQ2SKtYcWfuIe5gdOO52vJ/ x14tqZeYM8m/8EKovDywla9HQhhcPK2MkqVMckXKSfTZoMggxCNNQU73iLpFSELUcbrQ 4H8PAbEejYMpUo2ittgWA95uyK7TXd5FIUinfhaFJgWBwusHla8C13O4DLbcCindaDlb GjWQ== X-Gm-Message-State: AOAM533x4BXXtkFFWGhO0LsySYkKHLHZ/+lTYzZOEwStAL+2zr0gIM44 QNqpI4AxRQKlwP7vmXFWhKnvLEuiYE5zrQ== X-Google-Smtp-Source: ABdhPJwjkAztWLoP1FWpueqEJjMTiMAV3XkPm5stV3GkNcpNn77TW9J+ZrDstIXcRZIpM96qXijpNQ== X-Received: by 2002:ac8:5cc4:: with SMTP id s4mr34130376qta.214.1620851305294; Wed, 12 May 2021 13:28:25 -0700 (PDT) Received: from rekt.ibmuc.com ([2804:431:c7c6:fb9a:a1c9:c5a3:1e98:bc69]) by smtp.gmail.com with ESMTPSA id j29sm778317qtv.6.2021.05.12.13.28.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 May 2021 13:28:25 -0700 (PDT) From: Daniel Henrique Barboza To: linuxppc-dev@lists.ozlabs.org Subject: [PATCH v2 4/4] powerpc/pseries: minor enhancements in dlpar_memory_remove_by_ic() Date: Wed, 12 May 2021 17:28:09 -0300 Message-Id: <20210512202809.95363-5-danielhb413@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210512202809.95363-1-danielhb413@gmail.com> References: <20210512202809.95363-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" We don't need the 'lmbs_available' variable to count the valid LMBs and to check if we have less than 'lmbs_to_remove'. We must ensure that the entire LMB range must be removed, so we can error out immediately if any LMB in the range is marked as reserved. Add a couple of comments explaining the reasoning behind the differences we have in this function in contrast to what it is done in its sister function, dlpar_memory_remove_by_count(). Signed-off-by: Daniel Henrique Barboza Reviewed-by: David Gibson --- .../platforms/pseries/hotplug-memory.c | 28 +++++++++++++------ 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/arch/powerpc/platforms/pseries/hotplug-memory.c b/arch/powerpc/platforms/pseries/hotplug-memory.c index 3c7ce5361ce3..ee88c1540fba 100644 --- a/arch/powerpc/platforms/pseries/hotplug-memory.c +++ b/arch/powerpc/platforms/pseries/hotplug-memory.c @@ -517,7 +517,6 @@ static int dlpar_memory_remove_by_index(u32 drc_index) 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", @@ -530,18 +529,29 @@ static int dlpar_memory_remove_by_ic(u32 lmbs_to_remove, u32 drc_index) if (rc) return -EINVAL; - /* Validate that there are enough LMBs to satisfy the request */ + /* + * Validate that all LMBs in range are not reserved. Note that it + * is ok if they are !ASSIGNED since our goal here is to remove the + * LMB range, regardless of whether some LMBs were already removed + * by any other reason. + * + * This is a contrast to what is done in remove_by_count() where we + * check for both RESERVED and !ASSIGNED (via lmb_is_removable()), + * because we want to remove a fixed amount of LMBs in that function. + */ for_each_drmem_lmb_in_range(lmb, start_lmb, end_lmb) { - if (lmb->flags & DRCONF_MEM_RESERVED) - break; - - lmbs_available++; + if (lmb->flags & DRCONF_MEM_RESERVED) { + pr_err("Memory at %llx (drc index %x) is reserved\n", + lmb->base_addr, lmb->drc_index); + return -EINVAL; + } } - if (lmbs_available < lmbs_to_remove) - return -EINVAL; - for_each_drmem_lmb_in_range(lmb, start_lmb, end_lmb) { + /* + * dlpar_remove_lmb() will error out if the LMB is already + * !ASSIGNED, but this case is a no-op for us. + */ if (!(lmb->flags & DRCONF_MEM_ASSIGNED)) continue;