Received: by 2002:a25:b794:0:0:0:0:0 with SMTP id n20csp5747421ybh; Wed, 7 Aug 2019 10:43:09 -0700 (PDT) X-Google-Smtp-Source: APXvYqxk7shEXypznnQ/30xb98Tdkc0cI8ZGHrLCkvCsmuesvdJ8JCL4g516ZjSgFfqP6iIKeDlM X-Received: by 2002:a65:5348:: with SMTP id w8mr8671835pgr.176.1565199788875; Wed, 07 Aug 2019 10:43:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565199788; cv=none; d=google.com; s=arc-20160816; b=qddzzhcKVQZiudIxjcxGiVRdcMZqSqkScNkgqGJzC7QUZ/YS53jlggrQzyi/f4KNtJ eHqJU/xU8xc2jB/HvzYpUsqsaLCvIhr38R1y2LEfxSpfKNkPSV6/SOOLFx1dzcBl/NRo gnwIgTsecl1l/vUbOnaJGyfyaQJDDLowAe7eZDUCUxNIpNAWHRZa5PJ5iSSYe79F6Yi/ 1F7GLtGAPNsErTS/QmnE31fX0E4mXK6fZTh5jYBBNjuXiHiXRxafAGwVgIPYYXFii5F9 OHTlpEGYqQ405UmdAM+c9m0WaQ0JY1puDnqV73B+XqUoJGaPjb3YYButxXau5LUycn0B 8axQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=1UeFCEkBe8WB1WXsCYwcP/7nKnryRnwhqxRiHu1oF/s=; b=s211xIZkH7HcNzK6OVjhecwa5FqCt+uD2qzGDGy4w7q46zKQCtpHwc9/vbrCn2DK+y 2JHbbdm/qexiXWNPMaS82S0b1Rl8cy2rT8yUp1bMZDQJiqpljrq5UrpOeOHqA/FAz3jN FYCKnWcnJX4En0EcnYhERD/9ZB7Gq8uWuRC9R5c4er5iiiCA75aB7gu2nqKfU6MFJOeV IFxrm5zetTAR/UVOsmiALRavFQGflQ5oyxKgTzPhXQXdNZmJBtloJJlmHzf186Yv4Yau WiL8qT3egO9qQoRcnJcr0Ap6AofjYcPGkaauzYlmQKmAhCRCKZzF0zlhsOX0wfDRi6bt BebQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@joelfernandes.org header.s=google header.b=HcPjW0Di; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j192si52820380pge.393.2019.08.07.10.42.53; Wed, 07 Aug 2019 10:43:08 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@joelfernandes.org header.s=google header.b=HcPjW0Di; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389042AbfHGRQS (ORCPT + 99 others); Wed, 7 Aug 2019 13:16:18 -0400 Received: from mail-pl1-f194.google.com ([209.85.214.194]:37591 "EHLO mail-pl1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389006AbfHGRQR (ORCPT ); Wed, 7 Aug 2019 13:16:17 -0400 Received: by mail-pl1-f194.google.com with SMTP id b3so41801793plr.4 for ; Wed, 07 Aug 2019 10:16:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=joelfernandes.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=1UeFCEkBe8WB1WXsCYwcP/7nKnryRnwhqxRiHu1oF/s=; b=HcPjW0DivADdEfHkyp4B3Mi8RU+x160HluTp+508rUVD+SzJgBrJq6t1BUOsPiC8sf fsTMIHTi5sb49Zvfxvz+q0a3vrz9N1UySTOGDCYAfcU7uD8iy1sWRdXzXXFJ6HB9lday L8GmF1g24wM+UOHJXMd0arOKopP7Q91uFDxtM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=1UeFCEkBe8WB1WXsCYwcP/7nKnryRnwhqxRiHu1oF/s=; b=NmgQqSw6k1uz54FiZ6mGFmS+R1VPiq0vd+6/ZhdUWUX6Avk/sYgrR4wC6xR+obxP68 2jTQ0hLu2bFXrYsXazl+fySNg96Ngpd63iz5gWa/98MRfXWWUoEcxpFZTTPuuuBmcwNu NAY5oZrn2A45ql9obIwU5cZcKBQL5FLdCNP7EOhyWV7fqKeps/tmKrC/RIuETUg5CGaU KcsrFWVpFT9RmavIaY55m1pCbTfhwipfdZFM93wt5Sk4OX1ABmF3+3B39fpL+shT4eJK r5KYuhot1LOaR5I4XnJR0i0uSmNZf/cK71GAoI66piR51RQ/wP3DnK7PsSrnNvoPG3d0 4rkw== X-Gm-Message-State: APjAAAVoAm18pYGB4eQ58svmoe1PA6+hjFyYhe/XzQj5/0Xoe4gxh0YP 7WOSWPCjNi6ZJM1cNapbJ/YsgpUGDhY= X-Received: by 2002:aa7:8817:: with SMTP id c23mr10572797pfo.146.1565198175976; Wed, 07 Aug 2019 10:16:15 -0700 (PDT) Received: from joelaf.cam.corp.google.com ([2620:15c:6:12:9c46:e0da:efbf:69cc]) by smtp.gmail.com with ESMTPSA id a1sm62692130pgh.61.2019.08.07.10.16.12 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Wed, 07 Aug 2019 10:16:15 -0700 (PDT) From: "Joel Fernandes (Google)" To: linux-kernel@vger.kernel.org Cc: "Joel Fernandes (Google)" , Alexey Dobriyan , Andrew Morton , Borislav Petkov , Brendan Gregg , Catalin Marinas , Christian Hansen , dancol@google.com, fmayer@google.com, "H. Peter Anvin" , Ingo Molnar , joelaf@google.com, Jonathan Corbet , Kees Cook , kernel-team@android.com, linux-api@vger.kernel.org, linux-doc@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, Michal Hocko , Mike Rapoport , minchan@kernel.org, namhyung@google.com, paulmck@linux.ibm.com, Robin Murphy , Roman Gushchin , Stephen Rothwell , surenb@google.com, Thomas Gleixner , tkjos@google.com, Vladimir Davydov , Vlastimil Babka , Will Deacon Subject: [PATCH v5 3/6] [RFC] x86: Add support for idle bit in swap PTE Date: Wed, 7 Aug 2019 13:15:56 -0400 Message-Id: <20190807171559.182301-3-joel@joelfernandes.org> X-Mailer: git-send-email 2.22.0.770.g0f2c4a37fd-goog In-Reply-To: <20190807171559.182301-1-joel@joelfernandes.org> References: <20190807171559.182301-1-joel@joelfernandes.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This bit will be used by idle page tracking code to correctly identify if a page that was swapped out was idle before it got swapped out. Without this PTE bit, we lose information about if a page is idle or not since the page frame gets unmapped and the page gets freed. Bits 2-6 are unused in the swap PTE (see the comment in arch/x86/include/asm/pgtable_64.h). Bit 2 corresponds to _PAGE_USER. Use it for swap PTE purposes. Signed-off-by: Joel Fernandes (Google) --- arch/x86/Kconfig | 1 + arch/x86/include/asm/pgtable.h | 15 +++++++++++++++ arch/x86/include/asm/pgtable_types.h | 6 ++++++ 3 files changed, 22 insertions(+) diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig index 222855cc0158..728f22370f17 100644 --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig @@ -139,6 +139,7 @@ config X86 select HAVE_ARCH_MMAP_RND_COMPAT_BITS if MMU && COMPAT select HAVE_ARCH_COMPAT_MMAP_BASES if MMU && COMPAT select HAVE_ARCH_PREL32_RELOCATIONS + select HAVE_ARCH_PTE_SWP_PGIDLE select HAVE_ARCH_SECCOMP_FILTER select HAVE_ARCH_THREAD_STRUCT_WHITELIST select HAVE_ARCH_STACKLEAK diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h index 0bc530c4eb13..ef3e662cee4a 100644 --- a/arch/x86/include/asm/pgtable.h +++ b/arch/x86/include/asm/pgtable.h @@ -1371,6 +1371,21 @@ static inline pmd_t pmd_swp_clear_soft_dirty(pmd_t pmd) #endif #endif +static inline pte_t pte_swp_mkpage_idle(pte_t pte) +{ + return pte_set_flags(pte, _PAGE_SWP_PGIDLE); +} + +static inline int pte_swp_page_idle(pte_t pte) +{ + return pte_flags(pte) & _PAGE_SWP_PGIDLE; +} + +static inline pte_t pte_swp_clear_mkpage_idle(pte_t pte) +{ + return pte_clear_flags(pte, _PAGE_SWP_PGIDLE); +} + #define PKRU_AD_BIT 0x1 #define PKRU_WD_BIT 0x2 #define PKRU_BITS_PER_PKEY 2 diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h index b5e49e6bac63..6739cba4c900 100644 --- a/arch/x86/include/asm/pgtable_types.h +++ b/arch/x86/include/asm/pgtable_types.h @@ -100,6 +100,12 @@ #define _PAGE_SWP_SOFT_DIRTY (_AT(pteval_t, 0)) #endif +#ifdef CONFIG_IDLE_PAGE_TRACKING +#define _PAGE_SWP_PGIDLE _PAGE_USER +#else +#define _PAGE_SWP_PGIDLE (_AT(pteval_t, 0)) +#endif + #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE) #define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_NX) #define _PAGE_DEVMAP (_AT(u64, 1) << _PAGE_BIT_DEVMAP) -- 2.22.0.770.g0f2c4a37fd-goog