Received: by 2002:ac0:98c7:0:0:0:0:0 with SMTP id g7-v6csp1592630imd; Sun, 4 Nov 2018 06:00:27 -0800 (PST) X-Google-Smtp-Source: AJdET5e/qwZBXZEkqw55Kmuxsxj2LDU7q6mCR7dYooGkvV3FZgU4ZEfgSbKGhXTzqlk7nUyez+g0 X-Received: by 2002:a62:83c2:: with SMTP id h185-v6mr18517340pfe.187.1541340027815; Sun, 04 Nov 2018 06:00:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541340027; cv=none; d=google.com; s=arc-20160816; b=oKTUyMQ5+NQSefVe+F0jOmsPYx1AITj5ypU/860SYOOTw8oV8bv81F52eeJHJ4HpnG 3/EQ6HMWw7tZm8ANMAcJ9HLoQd76ENnSXENMnfNdbrbSrgaG4ShVke9OrfI+rXob208u TuamevPilHWflCst22++EBSPozKQkkfjyNfrzrJpX9JEzhnZZCeTgz2E4gzmuvwzvNW1 vPMBHKgpW7FNKon/Vhw2z6Jm7XAJcfuYVHlIbOypTNqz0mnZJW81iFQFFcTR8PS94TeE yOX69nxkl8ttaiPXHfi5vLn0T5edMVPDa+ZjPUfn7RAvlmQblx74bHCsLDn5MvTT5J5O Mo/w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=CUeFzmMesNIpn6HCfwQ397rKPiKffJbLRRDESxXK2ks=; b=iCIn2o+W6+hKplRVfYtEaIsszQnUToYCuojdjzpIblLB4JtlDcNd/3V4Jn4ZAhreYd dbd7JmwRr5P4D5LPOSskhWUTRHyoclqtEqZ/zuRvILWeDEVNEHBm+u4GXakuiC+gi1md q40R5rJkveua4/aNOgKysFISU39Mno4ulgJxEv/cTyGZNuUFJtDbCcm1Fmc1l10Y7oAy 9gZCAwJk1IpM3A2FGwBH83WrIP1+2bWC3cPGvGAa+2M9AAC0z0z17GIKNMAeI7dm1qph HNzgApYp8LdPKnbHBPry+cK/bF57bLKJ1KPc4loGWHa0WvEyxlMS/Zu/covOclpqrGEz vGzA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="IW/3C4vE"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id cd9-v6si390733plb.231.2018.11.04.06.00.13; Sun, 04 Nov 2018 06:00:27 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="IW/3C4vE"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731366AbeKDXIy (ORCPT + 99 others); Sun, 4 Nov 2018 18:08:54 -0500 Received: from mail.kernel.org ([198.145.29.99]:48062 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728896AbeKDXIx (ORCPT ); Sun, 4 Nov 2018 18:08:53 -0500 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 559922086C; Sun, 4 Nov 2018 13:53:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1541339628; bh=HRjebZnFl/1mu/usq+S9LejsFOEkF3ldew4bNCocFVI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IW/3C4vE2Rx+MVUAKV5Nj+LdxLG+6a1np9CfXRjXn0ROpAZzz/uHh/RRqdU5nJN5t Wv0taKQzlvepSNZynBKB8ldF+6SE4CG2iLkp7/JNjkNSaCrYegxc/UDVeBF/KjZ77H Mq5vPem82c8/70eK4e6R0LdbjGFA8ia6SRxLgouo= From: Sasha Levin To: stable@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Rashmica Gupta , Michael Ellerman , Sasha Levin Subject: [PATCH AUTOSEL 4.14 23/30] powerpc/memtrace: Remove memory in chunks Date: Sun, 4 Nov 2018 08:53:18 -0500 Message-Id: <20181104135325.88524-23-sashal@kernel.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181104135325.88524-1-sashal@kernel.org> References: <20181104135325.88524-1-sashal@kernel.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Rashmica Gupta [ Upstream commit 3f7daf3d7582dc6628ac40a9045dd1bbd80c5f35 ] When hot-removing memory release_mem_region_adjustable() splits iomem resources if they are not the exact size of the memory being hot-deleted. Adding this memory back to the kernel adds a new resource. Eg a node has memory 0x0 - 0xfffffffff. Hot-removing 1GB from 0xf40000000 results in the single resource 0x0-0xfffffffff being split into two resources: 0x0-0xf3fffffff and 0xf80000000-0xfffffffff. When we hot-add the memory back we now have three resources: 0x0-0xf3fffffff, 0xf40000000-0xf7fffffff, and 0xf80000000-0xfffffffff. This is an issue if we try to remove some memory that overlaps resources. Eg when trying to remove 2GB at address 0xf40000000, release_mem_region_adjustable() fails as it expects the chunk of memory to be within the boundaries of a single resource. We then get the warning: "Unable to release resource" and attempting to use memtrace again gives us this error: "bash: echo: write error: Resource temporarily unavailable" This patch makes memtrace remove memory in chunks that are always the same size from an address that is always equal to end_of_memory - n*size, for some n. So hotremoving and hotadding memory of different sizes will now not attempt to remove memory that spans multiple resources. Signed-off-by: Rashmica Gupta Signed-off-by: Michael Ellerman Signed-off-by: Sasha Levin --- arch/powerpc/platforms/powernv/memtrace.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/arch/powerpc/platforms/powernv/memtrace.c b/arch/powerpc/platforms/powernv/memtrace.c index fc222a0c2ac4..c9a6d4f3403c 100644 --- a/arch/powerpc/platforms/powernv/memtrace.c +++ b/arch/powerpc/platforms/powernv/memtrace.c @@ -119,17 +119,15 @@ static bool memtrace_offline_pages(u32 nid, u64 start_pfn, u64 nr_pages) walk_memory_range(start_pfn, end_pfn, (void *)MEM_OFFLINE, change_memblock_state); - lock_device_hotplug(); - remove_memory(nid, start_pfn << PAGE_SHIFT, nr_pages << PAGE_SHIFT); - unlock_device_hotplug(); return true; } static u64 memtrace_alloc_node(u32 nid, u64 size) { - u64 start_pfn, end_pfn, nr_pages; + u64 start_pfn, end_pfn, nr_pages, pfn; u64 base_pfn; + u64 bytes = memory_block_size_bytes(); if (!NODE_DATA(nid) || !node_spanned_pages(nid)) return 0; @@ -142,8 +140,21 @@ static u64 memtrace_alloc_node(u32 nid, u64 size) end_pfn = round_down(end_pfn - nr_pages, nr_pages); for (base_pfn = end_pfn; base_pfn > start_pfn; base_pfn -= nr_pages) { - if (memtrace_offline_pages(nid, base_pfn, nr_pages) == true) + if (memtrace_offline_pages(nid, base_pfn, nr_pages) == true) { + /* + * Remove memory in memory block size chunks so that + * iomem resources are always split to the same size and + * we never try to remove memory that spans two iomem + * resources. + */ + lock_device_hotplug(); + end_pfn = base_pfn + nr_pages; + for (pfn = base_pfn; pfn < end_pfn; pfn += bytes>> PAGE_SHIFT) { + remove_memory(nid, pfn << PAGE_SHIFT, bytes); + } + unlock_device_hotplug(); return base_pfn << PAGE_SHIFT; + } } return 0; -- 2.17.1