Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp239995iob; Wed, 18 May 2022 00:50:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyrQPljEi8083vunldDZkuwH77oRY2TmDOn6zKwSIA6D5RINrwjoI61EUmATQFWW7fTs5nt X-Received: by 2002:a63:a4d:0:b0:3db:7de7:58b0 with SMTP id z13-20020a630a4d000000b003db7de758b0mr23203805pgk.128.1652860202884; Wed, 18 May 2022 00:50:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652860202; cv=none; d=google.com; s=arc-20160816; b=erYfgxrEZKEZo1fg4MlDMzX03iDx7bcp+LsrYXqR3cr3ga7E9tXxWSTqn+9nyqMcy6 gpdyHAbZwo1Rm3vCwn9LS22PpjN6wUl7zbDw2lKjSyg2nnkYqVQJzlbrCi9HnmgOM0mR 0rPe0+zyrCnC3MFlgXAUB/nwxkrdTY0MqF+UHXAiu+52JuB/3Jf5l995gHKTzI1HHyw/ AnhQbv0Q/A5qEUqxLvSBEgmCMPlenP51F+rzp0N6f3C9hOnSbkJoW2JsG+tLUhDqp7fB t/S6FeNho/9rhHYbc/uAC5bZhcbryEoaN+qVSC87Ei0eDj2OaaIelOB2H04lVfHNDTa1 kMbg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=lSIe3VyW9rMeUh0m88iIR7bL+fGEX4/7scgZGDYUqTo=; b=LzkGHNUbXScUWys6H5K+x3nOgIAbPoJtU0vKntFP4XzCSb//Bm9ZVCntyIVpr7k3NC 5bikm5zNmga0z8DZMysm+a/qZgoyA7sW2mUHjIBNihlnSdVPSRrnnXE6OtjuD9VPqDIu T6Ed2ZyVRwS37tSAF3xkjJKvXElMhcVmKV7xy5p6GWm0Cmfz/ddzGThTKVvn1Jogvqf5 i8SxqVSuCB0ksRLbxsgJi/qjj661A3ZzAsMR+xl55ehDU4KHAq0T2sq2zJz9oXpL8M8a 7UfkmcQbEozyDCPdBkAVrn7gUtRRsmX85ikyfeyKPl5GzMwRELE7cFZme0adqyDDnCmp OaFg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcdkim header.b=uniKWtko; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id h18-20020a170902f71200b001590829860dsi1784417plo.400.2022.05.18.00.50.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 May 2022 00:50:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcdkim header.b=uniKWtko; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id D4A55122B60; Wed, 18 May 2022 00:49:57 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232583AbiERHtp (ORCPT + 99 others); Wed, 18 May 2022 03:49:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53654 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232566AbiERHtn (ORCPT ); Wed, 18 May 2022 03:49:43 -0400 Received: from alexa-out-sd-02.qualcomm.com (alexa-out-sd-02.qualcomm.com [199.106.114.39]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 993AD122B47; Wed, 18 May 2022 00:49:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; i=@quicinc.com; q=dns/txt; s=qcdkim; t=1652860182; x=1684396182; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=lSIe3VyW9rMeUh0m88iIR7bL+fGEX4/7scgZGDYUqTo=; b=uniKWtko1U15hq26Pc97dk32cb/2DgbGq8AzopcSzEqXWnFVBo5eRxvT 4LY69pQjZChG9ZBm78Yk8ofRluRWgY9oPXx6AObkdiapiBszGy20vu3k1 MhCGi8wfIs4UGetnuiMSx5apcy0Iy+RNRw3/4Hqn3NmHNSu9L0Y4fA5pG g=; Received: from unknown (HELO ironmsg01-sd.qualcomm.com) ([10.53.140.141]) by alexa-out-sd-02.qualcomm.com with ESMTP; 18 May 2022 00:49:42 -0700 X-QCInternal: smtphost Received: from unknown (HELO nasanex01a.na.qualcomm.com) ([10.52.223.231]) by ironmsg01-sd.qualcomm.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 May 2022 00:49:42 -0700 Received: from blr-ubuntu-185.qualcomm.com (10.80.80.8) by nasanex01a.na.qualcomm.com (10.52.223.231) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.22; Wed, 18 May 2022 00:49:33 -0700 From: Vivek Kumar To: , , , , , , , , , , , , , CC: , , , , , , , , , , , , , , Vivek Kumar , Prasanna Kumar Subject: [RFC 5/6] Hibernate: Add check for pte_valid in saveable page Date: Wed, 18 May 2022 13:18:40 +0530 Message-ID: <1652860121-24092-6-git-send-email-quic_vivekuma@quicinc.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1652860121-24092-1-git-send-email-quic_vivekuma@quicinc.com> References: <1652860121-24092-1-git-send-email-quic_vivekuma@quicinc.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.80.80.8] X-ClientProxiedBy: nasanex01a.na.qualcomm.com (10.52.223.231) To nasanex01a.na.qualcomm.com (10.52.223.231) X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add check for pte_valid in saveable page after being checked for the rest. This is required as PTE is removed for pages allocated with dma_alloc_coherent with DMA_ATTR_NO_KERNEL_MAPPING flag set. This patch makes sure that these pages are not considered for snapshot. Signed-off-by: Vivek Kumar Signed-off-by: Prasanna Kumar --- kernel/power/snapshot.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/kernel/power/snapshot.c b/kernel/power/snapshot.c index 2a40675..a6ad2a5 100644 --- a/kernel/power/snapshot.c +++ b/kernel/power/snapshot.c @@ -1308,6 +1308,41 @@ static inline void *saveable_highmem_page(struct zone *z, unsigned long p) } #endif /* CONFIG_HIGHMEM */ +static bool kernel_pte_present(struct page *page) +{ + pgd_t *pgdp; + p4d_t *p4dp; + pud_t *pudp, pud; + pmd_t *pmdp, pmd; + pte_t *ptep; + unsigned long addr = (unsigned long)page_address(page); + + pgdp = pgd_offset_k(addr); + if (pgd_none(READ_ONCE(*pgdp))) + return false; + + p4dp = p4d_offset(pgdp, addr); + if (p4d_none(READ_ONCE(*p4dp))) + return false; + + pudp = pud_offset(p4dp, addr); + pud = READ_ONCE(*pudp); + if (pud_none(pud)) + return false; + if (pud_sect(pud)) + return true; + + pmdp = pmd_offset(pudp, addr); + pmd = READ_ONCE(*pmdp); + if (pmd_none(pmd)) + return false; + if (pmd_sect(pmd)) + return true; + + ptep = pte_offset_kernel(pmdp, addr); + return pte_valid(READ_ONCE(*ptep)); +} + /** * saveable_page - Check if the given page is saveable. * @@ -1341,6 +1376,14 @@ static struct page *saveable_page(struct zone *zone, unsigned long pfn) && (!kernel_page_present(page) || pfn_is_nosave(pfn))) return NULL; + /* + * Even if page is not reserved and if it's not present in kernel PTE; + * don't snapshot it ! This happens to the pages allocated using + * __dma_alloc_coherent with DMA_ATTR_NO_KERNEL_MAPPING flag set. + */ + if (!kernel_pte_present(page)) + return NULL; + if (page_is_guard(page)) return NULL; -- 2.7.4