From patchwork Thu Sep 27 09:25:53 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 10617713 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id BF30A14BD for ; Thu, 27 Sep 2018 09:26:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AEC8F2AFF0 for ; Thu, 27 Sep 2018 09:26:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A0F7B2AFFB; Thu, 27 Sep 2018 09:26:44 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2EEA02AFF0 for ; Thu, 27 Sep 2018 09:26:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9CDAD8E0007; Thu, 27 Sep 2018 05:26:42 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 9A3758E0001; Thu, 27 Sep 2018 05:26:42 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8BA928E0007; Thu, 27 Sep 2018 05:26:42 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-qk1-f199.google.com (mail-qk1-f199.google.com [209.85.222.199]) by kanga.kvack.org (Postfix) with ESMTP id 5E9BC8E0001 for ; Thu, 27 Sep 2018 05:26:42 -0400 (EDT) Received: by mail-qk1-f199.google.com with SMTP id u195-v6so1900528qka.14 for ; Thu, 27 Sep 2018 02:26:42 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id:in-reply-to:references; bh=YaNu97MflHn/yt/ZRUeLi3WloF/HIoO1fgdEBWBwJm8=; b=NmvDdqvfxQ8FuFrJ635wHEU7myvzWTNWKTLzTv7lQ7ESQ2etcngb7zz3WgilnmuRIk iZsuDbBAiggkY7bmhCBrV/6xCxbN07q/fkVrHDWIq1PRpvWTetM0meYBaaPZi7d/ZRWJ 2x7xWQWUUYNt8oGzh2oYLoluMPJ0F7buG1dnwokWapXQ5WUPFJwSocTVL+oy8w8r1Q6W QwPod3ZZaw3cQ7RMD6i8SBVFs3v5ksjJYogBZ2ja+l7EyB+T8uWKIY4SnDCcq1ttt2w2 PS0aBuYqKpgJd5e9QTIPo0cYtvSMeVBu8t6pK8Rgg+gb0S2Sy/sh/SaI+1rdWQjfWyex HR0g== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of david@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com X-Gm-Message-State: ABuFfogBkdnmMibjhrvSsNrgMtZCYJrPJMChu/EO9CAetU3wTA35Uzff sMAfp2hBEtU75424Xe0QdjApd/8PeJ+6/4DanLNN9z8pCYlcC1/z/CuolmqV3rg6R6+kZ8FZ9SO Fa6wNdrh5/qb+mJRaZ6JejXBz/dKFNlr10BjOVKANzPKIlDRrQXB+FjTHl6I88TNQyQ== X-Received: by 2002:ac8:744a:: with SMTP id h10-v6mr7449752qtr.194.1538040402180; Thu, 27 Sep 2018 02:26:42 -0700 (PDT) X-Google-Smtp-Source: ACcGV6137tC/5OCEw+T1reeJqFsa4gaPOVmZvmtBf7U2WyER+LD6tHAHiagqBqgLRbrDIvUr/EDf X-Received: by 2002:ac8:744a:: with SMTP id h10-v6mr7449743qtr.194.1538040401759; Thu, 27 Sep 2018 02:26:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1538040401; cv=none; d=google.com; s=arc-20160816; b=OXZ8yMpi1Rn0NxjUVRBypYTzds68CKMAI7QINZnUiVJcHBhUfoZaq1jaC89LAFDiNw wa6++d/gj6PuG1RzuXHseSxkMR+2thOjUMbGvMdz5MPHyCmZ/mtzDuI3fXVzSzlQFCRg uJz8/QLU2Esf3x0eOk9kO0MgDyzK1m/mFSzCH10NY/Yn81olq0MS7AZOs9s4+Gab72ZN 6mWEzXd70T+3uOl6xF5EdRZs/H58uLbD5HJ7ZiVf8TuJYPx/wN64SNsOLfe7F2sFyfkb NOrA7gFo8stgplvmYZ49u+tA2ESBgyu1mWuYx+U0hCT5eQENSvXiDCIs9JEaSlAVjdUc Engg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from; bh=YaNu97MflHn/yt/ZRUeLi3WloF/HIoO1fgdEBWBwJm8=; b=GI3d1swgeUMJzqqm5FKCjIs0JBmYiUBnrcnL3nN4XYwvrf0kEJXG8Qi26m2wr3gFuC ELFlGY8HK/EjBGIalwRvwsHzxKrC0op18fhANFGXxZ0uIvab7pg4+KbF33f1rb2x8Mfv XpWmWCHbnIScTST1onWEJqA0y7Ttohxayi+jS781xLu/C79EBYvrkxp1vBi9AQrjmdfZ xvWLpUBoBonxAR2D3GoHOHudEiIlN+HWTYlZ+75Uq6j2KA+V8N+APXDChasebnYp320i VhTvg1GXu/rFS0XxgV1D6k7CoZSTyLF36DvC4jUCePSJmlaMckMGn3GjTAftooqm9v5t GM2A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of david@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from mx1.redhat.com (mx1.redhat.com. [209.132.183.28]) by mx.google.com with ESMTPS id u6-v6si1045603qkd.354.2018.09.27.02.26.41 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 27 Sep 2018 02:26:41 -0700 (PDT) Received-SPF: pass (google.com: domain of david@redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; Authentication-Results: mx.google.com; spf=pass (google.com: domain of david@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.25]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id DD78A30039BC; Thu, 27 Sep 2018 09:26:40 +0000 (UTC) Received: from t460s.redhat.com (ovpn-116-205.ams2.redhat.com [10.36.116.205]) by smtp.corp.redhat.com (Postfix) with ESMTP id A85BE20154E7; Thu, 27 Sep 2018 09:26:37 +0000 (UTC) From: David Hildenbrand To: linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-acpi@vger.kernel.org, xen-devel@lists.xenproject.org, devel@linuxdriverproject.org, David Hildenbrand , Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman , Rashmica Gupta , Balbir Singh , Michael Neuling Subject: [PATCH v3 5/6] powerpc/powernv: hold device_hotplug_lock when calling memtrace_offline_pages() Date: Thu, 27 Sep 2018 11:25:53 +0200 Message-Id: <20180927092554.13567-6-david@redhat.com> In-Reply-To: <20180927092554.13567-1-david@redhat.com> References: <20180927092554.13567-1-david@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.25 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.46]); Thu, 27 Sep 2018 09:26:41 +0000 (UTC) X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP Let's perform all checking + offlining + removing under device_hotplug_lock, so nobody can mess with these devices via sysfs concurrently. Cc: Benjamin Herrenschmidt Cc: Paul Mackerras Cc: Michael Ellerman Cc: Rashmica Gupta Cc: Balbir Singh Cc: Michael Neuling Reviewed-by: Pavel Tatashin Reviewed-by: Rashmica Gupta Acked-by: Balbir Singh Signed-off-by: David Hildenbrand --- arch/powerpc/platforms/powernv/memtrace.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/arch/powerpc/platforms/powernv/memtrace.c b/arch/powerpc/platforms/powernv/memtrace.c index fdd48f1a39f7..84d038ed3882 100644 --- a/arch/powerpc/platforms/powernv/memtrace.c +++ b/arch/powerpc/platforms/powernv/memtrace.c @@ -70,6 +70,7 @@ static int change_memblock_state(struct memory_block *mem, void *arg) return 0; } +/* called with device_hotplug_lock held */ static bool memtrace_offline_pages(u32 nid, u64 start_pfn, u64 nr_pages) { u64 end_pfn = start_pfn + nr_pages - 1; @@ -110,6 +111,7 @@ static u64 memtrace_alloc_node(u32 nid, u64 size) /* Trace memory needs to be aligned to the size */ end_pfn = round_down(end_pfn - nr_pages, nr_pages); + lock_device_hotplug(); for (base_pfn = end_pfn; base_pfn > start_pfn; base_pfn -= nr_pages) { if (memtrace_offline_pages(nid, base_pfn, nr_pages) == true) { /* @@ -118,7 +120,6 @@ static u64 memtrace_alloc_node(u32 nid, u64 size) * 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); @@ -127,6 +128,7 @@ static u64 memtrace_alloc_node(u32 nid, u64 size) return base_pfn << PAGE_SHIFT; } } + unlock_device_hotplug(); return 0; }