From patchwork Tue Sep 25 09:14:56 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 10613771 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 9ACD06CB for ; Tue, 25 Sep 2018 09:15:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 900C0299D5 for ; Tue, 25 Sep 2018 09:15:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 841C929B3C; Tue, 25 Sep 2018 09:15:51 +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 19490299D5 for ; Tue, 25 Sep 2018 09:15:51 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E2BD98E0087; Tue, 25 Sep 2018 05:15:49 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id D849A8E0072; Tue, 25 Sep 2018 05:15:49 -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 C4F368E0087; Tue, 25 Sep 2018 05:15:49 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-qk1-f198.google.com (mail-qk1-f198.google.com [209.85.222.198]) by kanga.kvack.org (Postfix) with ESMTP id 9641C8E0072 for ; Tue, 25 Sep 2018 05:15:49 -0400 (EDT) Received: by mail-qk1-f198.google.com with SMTP id y130-v6so25485711qka.1 for ; Tue, 25 Sep 2018 02:15:49 -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=uqGXcrSAuHaJugA2adZl27ACNF7YkUQ582WajK9llWg=; b=PF/QCp6ouOLglILVYo83aty0WAgDrLkd+on0xuVRh77cKFoKoYg+JT4CMfMZtneHs9 XX/9cgXTW6ztywfGlmzu5Zij/7OpPD0g1ydc6Mo44B0S3r74Cj3FHcj37fURv/2SrpP+ lLrLcqwrqDbec3FQkidOIF6wMEkSATM4FCGf7LcKv2uQ/CM+aDwCp1oXXZdZlxAlk4VH 6sZvtMMwwqTt83umK5I+Azr8XI20upZI8yOQmjnfFYt3rsulaQGy0CXw6VBZPaPNnQ5Y 1I8FpRPtFYw11zUrdZZkfFpkDQ8+6XSo1Zcg3aYqVi5MX5Ai48nUaQNbu3Qq1LHCOw3h s0pg== 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: ABuFfogYrQDTMurSkMuW+EY1AVlhPEHbfYtI0gYfO3w5A0M44XIaW9b7 K5FaS1yjRmPYOWk7FYfGVBmhu4Ox/5pNeBXU3hblu2ssCFbwFE/hTtTdWZmyS2m5eeRvtQf8Rdd 8pOH1fqvsM1cQKR7VrTRQkQYNVuGMIEJhSuoBn5HJo3hwypLReXBRVhIGQDhmAYf/ZQ== X-Received: by 2002:a0c:e74c:: with SMTP id g12-v6mr74272qvn.118.1537866949394; Tue, 25 Sep 2018 02:15:49 -0700 (PDT) X-Google-Smtp-Source: ACcGV60Tk4aFKhHJ/4EO3475eUQPSl2PhQGx4PlHrecncMazTbUb38ukwFgaxueWUnBwSQAyePol X-Received: by 2002:a0c:e74c:: with SMTP id g12-v6mr74260qvn.118.1537866948942; Tue, 25 Sep 2018 02:15:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537866948; cv=none; d=google.com; s=arc-20160816; b=NLemigGZqHeCvysK1vzrFVMWoi4CO8OifILXXkUZW4FqL4Av8qOFbjwYzncPLmPqpY SEGo2eSh7zmo5l5INwaLmJkUtLaPlkY6geNkC7N/CQn/kqEF64hKUMP1zo4XWI2Q3l8/ HL39vKaFvL3rhotuK6UXjnxSnDiJiUwc7zT/GWyxz70S8E3Bqv5p0vPpUvQt+xUAtcS3 i7p0ySCB6dbX+wxeeTc0hebqP2SCstYd4XFypgM5dX7Fo+bx4c1eJ4j0xVDnyeeo4H+f k2HF1tzGAt4vy2+womOPLureAMOXlXRdXkxUkcDbuePEVUpVRDNHLv0FWPfIdJwDyuo6 J9hg== 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=uqGXcrSAuHaJugA2adZl27ACNF7YkUQ582WajK9llWg=; b=MtNS1vFpgqHH1UJcGcR3g0B5YNLnIqS0+NqWtnQOAc4vlDIZa6mfpHXticy2gJFbj0 cMic3F1NQ+sMbIjyCLxsd1T0bFlCTsFOeJqKH7/9UBfvoRljzKdf1n8hir+BIfgzXpQq dEiYfyJl6Z+26vQQS0ohfelEx1V7NlJ9zfm+8nxav12m9VbVFMUHGeG01ANRXC2Pqll4 DyecTFActm5jNowiKDft2GdcxPeBlHoSv7thqa1Yhvja9ngzb/F2JcCIm2NY0xgI9YRK qEtKFRj3iI2lDNZxOA4Ld+BxUaaHRxAh9jH1YVVSuovYIhM3egtEKXQzszAkxfSyHbGv wWkQ== 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 x5-v6si1353666qte.88.2018.09.25.02.15.48 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 25 Sep 2018 02:15:48 -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-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 05889356F9; Tue, 25 Sep 2018 09:15:48 +0000 (UTC) Received: from t460s.redhat.com (ovpn-117-161.ams2.redhat.com [10.36.117.161]) by smtp.corp.redhat.com (Postfix) with ESMTP id C50CD308BE75; Tue, 25 Sep 2018 09:15:41 +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 v2 5/6] powerpc/powernv: hold device_hotplug_lock when calling memtrace_offline_pages() Date: Tue, 25 Sep 2018 11:14:56 +0200 Message-Id: <20180925091457.28651-6-david@redhat.com> In-Reply-To: <20180925091457.28651-1-david@redhat.com> References: <20180925091457.28651-1-david@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.24 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Tue, 25 Sep 2018 09:15:48 +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 Signed-off-by: David Hildenbrand Acked-by: Balbir Singh --- 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..d84d09c56af9 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; @@ -111,6 +112,7 @@ 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) { + lock_device_hotplug(); if (memtrace_offline_pages(nid, base_pfn, nr_pages) == true) { /* * Remove memory in memory block size chunks so that @@ -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); @@ -126,6 +127,7 @@ static u64 memtrace_alloc_node(u32 nid, u64 size) unlock_device_hotplug(); return base_pfn << PAGE_SHIFT; } + unlock_device_hotplug(); } return 0;