Received: by 2002:ab2:69cc:0:b0:1f4:be93:e15a with SMTP id n12csp63622lqp; Fri, 12 Apr 2024 10:30:45 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXOcci8XPnhLMMsJy1/n/OJsi+Yqb0A7Om8XkxiNbW1e4ln64KYszT0DM5DIxX5dkEyizbmOcHwQUFxcqYJqlBXLfCEQPCwZxjoHqrB8Q== X-Google-Smtp-Source: AGHT+IF2dQJyYysf5xDG2fTL4mrlTLH2C7OAmNb1qgkzhAi4paeSgEwND0+xOxAQF2Ywogknx/CK X-Received: by 2002:a05:6359:4a43:b0:17f:5a02:e938 with SMTP id nb3-20020a0563594a4300b0017f5a02e938mr5358784rwb.1.1712943045278; Fri, 12 Apr 2024 10:30:45 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712943045; cv=pass; d=google.com; s=arc-20160816; b=l64nJ3ezgbiSbhHvX2moTOk1bT2kV4iYQ/HT57MCurFZr0inT7MRH0kTk8YrqvAQpj +Uiavp7//idzqbN23R3jZtNMOQtG94E02nnlIIEX/2E8iw/M/nfxY7yo9qfv2cLTn3nB HVjO45b55FRL5bnVoy5oQMF/l9PxcPbloS1mwpikrK7Y2XHMFFMpZP5cm83TcSss8uGy pOWAv8U3pl1JPwLffdjWoFUQrqtXtcer5a+DBanV0Oh/cfwPWU7HcAq4O2ATkSbVR/ep eVDIr5uGowcgodwdbjITTg/UxyuKxTTQSMP3+AcOJcfbbS/EiPzRGUCf7EuJhZU5IuQX V8/w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:message-id:subject:cc:to:from:date; bh=Ma9dSua2uLwFlVh8kwW4Cqo9huVMhRAwK66NtKB/4ek=; fh=ZeyOqU57LDJkQ/3MVqC9Bc0weSI5NE7BH7qhB1D1wlI=; b=ZRE8H15fhs/jvG2dIYzLJP2x5JlEMpBX9yL2OpervBefuo46/9H464A81+vyUPHK9w i0Q5MLBdB75g5Lh1gBoM7aIjFsS0zVkcJHtO4iElpOrBv+YMuCFg35Yrlf+W2MKryFP0 4dVCYhmFMGY0FuzE28h79uXqVzBqXo5ZJtbAqjS0niIptXidHfNIHXWe+0JFsnrpxmQ6 j4/DA03D/KHZbWlSzcYMwt3dvuJx0ZuDomO3CzxOb04K4ge5k0AUbLgsPYlBYU97266p yKBobQ5QI12YNIRsV+YAodNMLdLyq+Dt3mYHl6bMVJktLxP9BjoIkR8vMX4opMTeXShm 0VFg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-143123-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-143123-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id w24-20020a63fb58000000b005dc504b30ecsi3635851pgj.108.2024.04.12.10.30.45 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Apr 2024 10:30:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-143123-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-143123-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-143123-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id E8EA12830E9 for ; Fri, 12 Apr 2024 17:30:44 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 90B6114D6F5; Fri, 12 Apr 2024 17:30:34 +0000 (UTC) Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1393A14C593; Fri, 12 Apr 2024 17:30:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712943034; cv=none; b=V7qHexrnaclAaYN3433gCIG2AxS/hV+2UhiVspm6e8+EgZCjtOG0n53pOu3ZyYUkt+SpV/6furg4tFRPP/dAaPA3ZngVrh8tGXTCZ8TdjdQmIqG+eEloncmBSUCmDiIDHAALDrLTxp6483DCaMmoDNSvGTPKdl6mDWEeqanC/PU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712943034; c=relaxed/simple; bh=Kq4lrOrNh1hYJL8fRJfQOOuOPnNOpM61pSMoxRf+tBk=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=aZaXu34zOlRFQdhtxUI/d4f/WwWC4mSyWkt0k/wpbsYYbFI+HbXnUM+zZQRiCd/ssCo25cMLpDFaJuaA9FjviZPHYLAHMKdfue+ozY6gyhdQIVYXLelYGq/E7AyPi33tnG28DvHbKCizyE8U2imOUrHycJVmAXdUyP9JXJHQRmc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 642CAC113CC; Fri, 12 Apr 2024 17:30:30 +0000 (UTC) Date: Fri, 12 Apr 2024 18:30:27 +0100 From: Catalin Marinas To: Yaxiong Tian <13327272236@163.com> Cc: will@kernel.org, keescook@chromium.org, tianyaxiong@kylinos.cn, xiongxin@kylinos.cn, rppt@kernel.org, tony.luck@intel.com, gpiccoli@igalia.com, songshuaishuai@tinylab.org, wangkefeng.wang@huawei.com, akpm@linux-foundation.org, ardb@kernel.org, david@redhat.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org Subject: Re: [PATCH v2] arm64: hibernate: Fix level3 translation fault in swsusp_save() Message-ID: References: <20240301021924.33210-1-13327272236@163.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20240301021924.33210-1-13327272236@163.com> For some reason I missed the updated patch. On Fri, Mar 01, 2024 at 10:19:24AM +0800, Yaxiong Tian wrote: > From: Yaxiong Tian > > On ARM64 machines using UEFI, if can_set_direct_map() return false by > setting some CONFIGS in kernel build or grub,such as > NO CONFIG_DEBUG_PAGEALLOC_ENABLE_DEFAULT、NO CONFIG_KFENCE > NO CONFIG_RODATA_FULL_DEFAULT_ENABLED.Also with setting rodata=off、 > debug_pagealloc=off in grub and NO CONFIG_KFENCE. > swsusp_save() will fail due to can't finding the map table under the > nomap memory.such as: [...] > [ 48.532162] Call trace: > [ 48.532162] swsusp_save+0x280/0x538 > [ 48.532162] swsusp_arch_suspend+0x148/0x190 > [ 48.532162] hibernation_snapshot+0x240/0x39c > [ 48.532162] hibernate+0xc4/0x378 > [ 48.532162] state_store+0xf0/0x10c > [ 48.532162] kobj_attr_store+0x14/0x24 > > This issue can be reproduced in QEMU using UEFI when booting with > rodata=off、debug_pagealloc=off in grub and NO CONFIG_KFENCE. > > This is because in swsusp_save()->copy_data_pages()->page_is_saveable(), > kernel_page_present() presumes that a page is present when can_set_direct_map() > returns false even for NOMAP ranges.So NOMAP pages will saved in after,and then > cause level3 translation fault in this pages. I can see how kernel_page_present() ended up returning true if !can_set_direct_map(), though based on the function naming only, it feels a bit unintuitive. Is arm64 the only architecture making use of MEMBLOCK_NOMAP? Or is it the only one where kernel_page_present() also returns true if !can_set_direct_map()? > diff --git a/arch/arm64/kernel/hibernate.c b/arch/arm64/kernel/hibernate.c > index 02870beb271e..d90005de1d26 100644 > --- a/arch/arm64/kernel/hibernate.c > +++ b/arch/arm64/kernel/hibernate.c > @@ -94,7 +94,7 @@ int pfn_is_nosave(unsigned long pfn) > unsigned long nosave_end_pfn = sym_to_pfn(&__nosave_end - 1); > > return ((pfn >= nosave_begin_pfn) && (pfn <= nosave_end_pfn)) || > - crash_is_nosave(pfn); > + crash_is_nosave(pfn) || !pfn_is_map_memory(pfn); > } This indeed fixes the problem but it looks like an arm64-specific workaround. I can see at least arm, loongarch and riscv making use of memblock_is_map_memory() (which is what pfn_is_map_memory() calls). Do they not have the same problem? On riscv, for example, kernel_page_present() does not depend on any ARCH_HAS_SET_DIRECT_MAP related options/conditions (neither does x86 though not sure it cares about MEMBLOCK_NOMAP). Should we do the same for arm64 and drop the !can_set_direct_map() condition in kernel_page_present()? -- Catalin