From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.0 required=3.0 tests=BAYES_00,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6100CC4363A for ; Thu, 29 Oct 2020 16:30:24 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id B2C9B2076E for ; Thu, 29 Oct 2020 16:30:21 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B2C9B2076E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id BE0EB6B005D; Thu, 29 Oct 2020 12:30:20 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B90B76B006E; Thu, 29 Oct 2020 12:30:20 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A646B6B0070; Thu, 29 Oct 2020 12:30:20 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0079.hostedemail.com [216.40.44.79]) by kanga.kvack.org (Postfix) with ESMTP id 70AF86B005D for ; Thu, 29 Oct 2020 12:30:20 -0400 (EDT) Received: from smtpin20.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id C0DBA3624 for ; Thu, 29 Oct 2020 16:30:18 +0000 (UTC) X-FDA: 77425500516.20.error67_600c1a92728e Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin20.hostedemail.com (Postfix) with ESMTP id 91218180C07A3 for ; Thu, 29 Oct 2020 16:30:18 +0000 (UTC) X-HE-Tag: error67_600c1a92728e X-Filterd-Recvd-Size: 8441 Received: from mail-ot1-f65.google.com (mail-ot1-f65.google.com [209.85.210.65]) by imf43.hostedemail.com (Postfix) with ESMTP for ; Thu, 29 Oct 2020 16:30:18 +0000 (UTC) Received: by mail-ot1-f65.google.com with SMTP id f37so2852544otf.12 for ; Thu, 29 Oct 2020 09:30:17 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=ZB07qrLbOJe5x8k5kgwlwyYgrU0au+3LEdR9BcQ+dAw=; b=fWI8tcmVn9RjqV21Hd2rsz1F+0wWkXiJZ9pTMHplPs5ng577LN1qEfH8gpRA+XfKFG L794HwIo6xGjtkaEYd5txz6Vu1e1qNYAyRHgaY3gqP/KQqHmGA/eIr5GPRtrKUpcDuc4 kyqoAVgSlsfv0awsHHmHxmsSPJpWeQHpnshpQ+xIkIDFBHBAKO0YVO9h8YPA2APEUd3G 2nbgbKIMewN2V+MxX/nLb0vNuQuk4mearotsH+zl/7U7pNHs9PcieL4agTYYtwhcVi3M /PXAHsw0LYE6En/81oGZRXjjjQ53cDFiimKIVnyR2hRSNm+IiYGlJ9l4rbYn9oCjTn3D 8k5Q== X-Gm-Message-State: AOAM532VdJGKKOmgR906mhrsrGy2ot70miySfolQ7Pvd4qz9g4JiVQ8L Nmy50itKQ1o2MPoGHS+Dt3tpId1F/9ZrvD3RkWc= X-Google-Smtp-Source: ABdhPJy2gnJASZanadb1mOz1tbg80ys3NM2aGYdvcYIISMX2t1bfCDW4CoQJSVVkimsx+nxAWLJibjXQBAg79vyeqWE= X-Received: by 2002:a9d:734f:: with SMTP id l15mr4119563otk.260.1603989017370; Thu, 29 Oct 2020 09:30:17 -0700 (PDT) MIME-Version: 1.0 References: <20201029161902.19272-1-rppt@kernel.org> <20201029161902.19272-3-rppt@kernel.org> In-Reply-To: <20201029161902.19272-3-rppt@kernel.org> From: "Rafael J. Wysocki" Date: Thu, 29 Oct 2020 17:30:06 +0100 Message-ID: Subject: Re: [PATCH v2 2/4] PM: hibernate: make direct map manipulations more explicit To: Mike Rapoport Cc: Andrew Morton , Albert Ou , Andy Lutomirski , Benjamin Herrenschmidt , Borislav Petkov , Catalin Marinas , Christian Borntraeger , Christoph Lameter , "David S. Miller" , Dave Hansen , David Hildenbrand , David Rientjes , "Edgecombe, Rick P" , "H. Peter Anvin" , Heiko Carstens , Ingo Molnar , Joonsoo Kim , "Kirill A. Shutemov" , Len Brown , Michael Ellerman , Mike Rapoport , Palmer Dabbelt , Paul Mackerras , Paul Walmsley , Pavel Machek , Pekka Enberg , Peter Zijlstra , "Rafael J. Wysocki" , Thomas Gleixner , Vasily Gorbik , Will Deacon , Linux ARM , Linux Kernel Mailing List , Linux Memory Management List , Linux PM , linux-riscv@lists.infradead.org, linux-s390@vger.kernel.org, linuxppc-dev , sparclinux@vger.kernel.org, "the arch/x86 maintainers" Content-Type: text/plain; charset="UTF-8" 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: On Thu, Oct 29, 2020 at 5:19 PM Mike Rapoport wrote: > > From: Mike Rapoport > > When DEBUG_PAGEALLOC or ARCH_HAS_SET_DIRECT_MAP is enabled a page may be > not present in the direct map and has to be explicitly mapped before it > could be copied. > > On arm64 it is possible that a page would be removed from the direct map > using set_direct_map_invalid_noflush() but __kernel_map_pages() will refuse > to map this page back if DEBUG_PAGEALLOC is disabled. > > Introduce hibernate_map_page() that will explicitly use > set_direct_map_{default,invalid}_noflush() for ARCH_HAS_SET_DIRECT_MAP case > and debug_pagealloc_map_pages() for DEBUG_PAGEALLOC case. > > The remapping of the pages in safe_copy_page() presumes that it only > changes protection bits in an existing PTE and so it is safe to ignore > return value of set_direct_map_{default,invalid}_noflush(). > > Still, add a WARN_ON() so that future changes in set_memory APIs will not > silently break hibernation. > > Signed-off-by: Mike Rapoport >From the hibernation support perspective: Acked-by: Rafael J. Wysocki > --- > include/linux/mm.h | 12 ------------ > kernel/power/snapshot.c | 30 ++++++++++++++++++++++++++++-- > 2 files changed, 28 insertions(+), 14 deletions(-) > > diff --git a/include/linux/mm.h b/include/linux/mm.h > index 1fc0609056dc..14e397f3752c 100644 > --- a/include/linux/mm.h > +++ b/include/linux/mm.h > @@ -2927,16 +2927,6 @@ static inline bool debug_pagealloc_enabled_static(void) > #if defined(CONFIG_DEBUG_PAGEALLOC) || defined(CONFIG_ARCH_HAS_SET_DIRECT_MAP) > extern void __kernel_map_pages(struct page *page, int numpages, int enable); > > -/* > - * When called in DEBUG_PAGEALLOC context, the call should most likely be > - * guarded by debug_pagealloc_enabled() or debug_pagealloc_enabled_static() > - */ > -static inline void > -kernel_map_pages(struct page *page, int numpages, int enable) > -{ > - __kernel_map_pages(page, numpages, enable); > -} > - > static inline void debug_pagealloc_map_pages(struct page *page, > int numpages, int enable) > { > @@ -2948,8 +2938,6 @@ static inline void debug_pagealloc_map_pages(struct page *page, > extern bool kernel_page_present(struct page *page); > #endif /* CONFIG_HIBERNATION */ > #else /* CONFIG_DEBUG_PAGEALLOC || CONFIG_ARCH_HAS_SET_DIRECT_MAP */ > -static inline void > -kernel_map_pages(struct page *page, int numpages, int enable) {} > static inline void debug_pagealloc_map_pages(struct page *page, > int numpages, int enable) {} > #ifdef CONFIG_HIBERNATION > diff --git a/kernel/power/snapshot.c b/kernel/power/snapshot.c > index 46b1804c1ddf..054c8cce4236 100644 > --- a/kernel/power/snapshot.c > +++ b/kernel/power/snapshot.c > @@ -76,6 +76,32 @@ static inline void hibernate_restore_protect_page(void *page_address) {} > static inline void hibernate_restore_unprotect_page(void *page_address) {} > #endif /* CONFIG_STRICT_KERNEL_RWX && CONFIG_ARCH_HAS_SET_MEMORY */ > > +static inline void hibernate_map_page(struct page *page, int enable) > +{ > + if (IS_ENABLED(CONFIG_ARCH_HAS_SET_DIRECT_MAP)) { > + unsigned long addr = (unsigned long)page_address(page); > + int ret; > + > + /* > + * This should not fail because remapping a page here means > + * that we only update protection bits in an existing PTE. > + * It is still worth to have WARN_ON() here if something > + * changes and this will no longer be the case. > + */ > + if (enable) > + ret = set_direct_map_default_noflush(page); > + else > + ret = set_direct_map_invalid_noflush(page); > + > + if (WARN_ON(ret)) > + return; > + > + flush_tlb_kernel_range(addr, addr + PAGE_SIZE); > + } else { > + debug_pagealloc_map_pages(page, 1, enable); > + } > +} > + > static int swsusp_page_is_free(struct page *); > static void swsusp_set_page_forbidden(struct page *); > static void swsusp_unset_page_forbidden(struct page *); > @@ -1355,9 +1381,9 @@ static void safe_copy_page(void *dst, struct page *s_page) > if (kernel_page_present(s_page)) { > do_copy_page(dst, page_address(s_page)); > } else { > - kernel_map_pages(s_page, 1, 1); > + hibernate_map_page(s_page, 1); > do_copy_page(dst, page_address(s_page)); > - kernel_map_pages(s_page, 1, 0); > + hibernate_map_page(s_page, 0); > } > } > > -- > 2.28.0 >