From patchwork Fri Aug 3 06:06:00 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rashmica Gupta X-Patchwork-Id: 953045 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 41hc6W2dvpz9s2g for ; Fri, 3 Aug 2018 16:08:19 +1000 (AEST) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="kZ632Whc"; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 41hc6W0PlVzF2DN for ; Fri, 3 Aug 2018 16:08:19 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="kZ632Whc"; 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 (mailfrom) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::544; helo=mail-pg1-x544.google.com; envelope-from=rashmica.g@gmail.com; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="kZ632Whc"; dkim-atps=neutral Received: from mail-pg1-x544.google.com (mail-pg1-x544.google.com [IPv6:2607:f8b0:4864:20::544]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 41hc4B45gWzF12N for ; Fri, 3 Aug 2018 16:06:18 +1000 (AEST) Received: by mail-pg1-x544.google.com with SMTP id y4-v6so2331596pgp.9 for ; Thu, 02 Aug 2018 23:06:18 -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; bh=Ol5MiMtiDV4dNyWF/Luf9xpxROZ02fl/kaWU5GDpmaM=; b=kZ632Whc5DFpQIsNKYrk+CDwjWAOS7IjiRHaVbKgWaovcLiR/L/68RHJQoateaIIB2 QDzGy3bA09fXaMG8wbKzFVm8Ognq726bmBTeOfMvO2/dcKqSWpRaXDD8AyUPxpSJsDJR ID1UojGRchtVV8/K+nnbqNvuHCQ6qIZmZNuZVRyaHlbzqy97/LnLll3fjr6+sgoZ7v2L Z/qR259QkrhdUKcubtboGVhA/S8JfUuwQRqlzsQ3jW3SaPNaKevngO4D63LYUfLsEMhD JV7YOBFhSmem2lAw6/5W0AP0Mi9HB+34ZX+C6NZ5rL0KkBjHDpba86rGkEmyRV7hNV9k B8sg== 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; bh=Ol5MiMtiDV4dNyWF/Luf9xpxROZ02fl/kaWU5GDpmaM=; b=hSrnM7CHTlUYRVlGDt9v7S77m48rh7hXtT90mYV7CSiR+emps7LmClHgLuEarxvpLK vJG8OK35Za9NmlPo3Mn/UO9VvWJwQI9XilPlpsSJPKUkUnOL1nm210jtATQFvVstUjkl 2MghVaer1Z0f5UkPH1N2pF81i3qbySBIHVJWXzNu8oZuQ/qZt8ZHId8XKthUKQwUx/VY M03TQFa/UtcSLkRrsfT1qin3wi5KseRElaYwrPY4pEPSxNmPCbHLPghoH+ZZ1C2XtKHL YHIfZQN5cieFL+0uGMy+T0iVvzmlMigjOWXSjpOAogmIpOjYWz1SwoGtX3i4x0kVE0Im M60g== X-Gm-Message-State: AOUpUlGffEXmfZH+tdU93oyfRqiRhg2fDIgbJg+MZbYwkZMq6/W7vRib etV9hJDYUuenJlTQkw1XZAOBkK/Q X-Google-Smtp-Source: AAOMgpfn2PGzmREAKiIi+df9b2hjtkzi+UBvENAlz1if0fr20QnRC9Hvv3kH9nLSB0MRXGIcfZh5DQ== X-Received: by 2002:a62:998:: with SMTP id 24-v6mr2778683pfj.99.1533276376403; Thu, 02 Aug 2018 23:06:16 -0700 (PDT) Received: from rashmica.ozlabs.ibm.com ([122.99.82.10]) by smtp.gmail.com with ESMTPSA id z4-v6sm7154415pfl.11.2018.08.02.23.06.13 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 02 Aug 2018 23:06:15 -0700 (PDT) From: Rashmica Gupta To: linuxppc-dev@lists.ozlabs.org, mpe@ellerman.id.au, mikey@neuling.org, benh@kernel.crashing.org, paulus@samba.org, bsingharora@gmail.com Subject: [PATCH 1/2] powerpc: Allow memory that has been hot-removed to be hot-added Date: Fri, 3 Aug 2018 16:06:00 +1000 Message-Id: <20180803060601.724-1-rashmica.g@gmail.com> X-Mailer: git-send-email 2.14.4 X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Rashmica Gupta Errors-To: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" This patch allows the memory removed by memtrace to be readded to the kernel. So now you don't have to reboot your system to add the memory back to the kernel or to have a different amount of memory removed. Signed-off-by: Rashmica Gupta Tested-by: Michael Neuling --- To remove 1GB from each node: echo 1073741824 > /sys/kernel/debug/powerpc/memtrace/enable To add this memory back and remove 2GB: echo 2147483648 > /sys/kernel/debug/powerpc/memtrace/enable To just re-add memory: echo 0 > /sys/kernel/debug/powerpc/memtrace/enable arch/powerpc/platforms/powernv/memtrace.c | 93 ++++++++++++++++++++++++++++--- 1 file changed, 86 insertions(+), 7 deletions(-) diff --git a/arch/powerpc/platforms/powernv/memtrace.c b/arch/powerpc/platforms/powernv/memtrace.c index b99283df8584..51fe0862dcab 100644 --- a/arch/powerpc/platforms/powernv/memtrace.c +++ b/arch/powerpc/platforms/powernv/memtrace.c @@ -206,8 +206,11 @@ static int memtrace_init_debugfs(void) snprintf(ent->name, 16, "%08x", ent->nid); dir = debugfs_create_dir(ent->name, memtrace_debugfs_dir); - if (!dir) + if (!dir) { + pr_err("Failed to create debugfs directory for node %d\n", + ent->nid); return -1; + } ent->dir = dir; debugfs_create_file("trace", 0400, dir, ent, &memtrace_fops); @@ -218,18 +221,94 @@ static int memtrace_init_debugfs(void) return ret; } +static int online_mem_block(struct memory_block *mem, void *arg) +{ + return device_online(&mem->dev); +} + +/* + * Iterate through the chunks of memory we have removed from the kernel + * and attempt to add them back to the kernel. + */ +static int memtrace_online(void) +{ + int i, ret = 0; + struct memtrace_entry *ent; + + for (i = memtrace_array_nr - 1; i >= 0; i--) { + ent = &memtrace_array[i]; + + /* We have onlined this chunk previously */ + if (ent->nid == -1) + continue; + + /* Remove from io mappings */ + if (ent->mem) { + iounmap(ent->mem); + ent->mem = 0; + } + + if (add_memory(ent->nid, ent->start, ent->size)) { + pr_err("Failed to add trace memory to node %d\n", + ent->nid); + ret += 1; + continue; + } + + /* + * If kernel isn't compiled with the auto online option + * we need to online the memory ourselves. + */ + if (!memhp_auto_online) { + walk_memory_range(PFN_DOWN(ent->start), + PFN_UP(ent->start + ent->size - 1), + NULL, online_mem_block); + } + + /* + * Memory was added successfully so clean up references to it + * so on reentry we can tell that this chunk was added. + */ + debugfs_remove_recursive(ent->dir); + pr_info("Added trace memory back to node %d\n", ent->nid); + ent->size = ent->start = ent->nid = -1; + } + if (ret) + return ret; + + /* If all chunks of memory were added successfully, reset globals */ + kfree(memtrace_array); + memtrace_array = NULL; + memtrace_size = 0; + memtrace_array_nr = 0; + return 0; + +} + static int memtrace_enable_set(void *data, u64 val) { - if (memtrace_size) + uint64_t bytes; + + /* + * Don't attempt to do anything if size isn't aligned to a memory + * block or equal to zero. + */ + bytes = memory_block_size_bytes(); + if (val & (bytes - 1)) { + pr_err("Value must be aligned with 0x%llx\n", bytes); return -EINVAL; + } - if (!val) - return -EINVAL; + /* Re-add/online previously removed/offlined memory */ + if (memtrace_size) { + if (memtrace_online()) + return -EAGAIN; + } - /* Make sure size is aligned to a memory block */ - if (val & (memory_block_size_bytes() - 1)) - return -EINVAL; + if (!val) + return 0; + /* Offline and remove memory */ if (memtrace_init_regions_runtime(val)) return -EINVAL;