Received: by 2002:a25:b794:0:0:0:0:0 with SMTP id n20csp2989082ybh; Mon, 5 Aug 2019 10:06:04 -0700 (PDT) X-Google-Smtp-Source: APXvYqy2GoMKSqOCFF7pjWhigH0tfUNZielGGhYLD95wZGd5u7RLdt1BRNTcn30RZLnmwKsMh+OP X-Received: by 2002:a65:5b8e:: with SMTP id i14mr135828882pgr.188.1565024764044; Mon, 05 Aug 2019 10:06:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565024764; cv=none; d=google.com; s=arc-20160816; b=kZJKo2dEdifrTmTVIGEuzc8wLgzUJ6mLoxSfi3OJMqUv5TUGzHvGddZUG1r34yyBWt 1NCGBb5rNKg+pITyWmVNxNvBeCO2NgqEZQeJahmcw7ILnS7gvhcJfvkGHwHjBinJ4as+ 7j1Y9gOYyYrAVEgsmsFGm90WzjpwgMw8k7OUPMNTfftRYpuLiMJx0iL6h1zrodbqmCNN i+bVJ7Mlmt62CPvtJiDmnvys6fPufGOln/kUm8Qy3ciXKoXhie3hqKvQ78ldM7TMQ5ei ODIB9u7hdp1z8FeEXfuEUmBBTA5zbdN3i3W/N9pcIWuKQ1zp6DwPH/hYxejC49Nsm19v 2+wA== 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=TQNMUirJy1i9vvFDq+aJmmpFXoG6P1u5bE3bfRRfdIMtoY4Hq42PVTb0LTDnSVKNby bogS21U0OSLD1vlSRMk25gHsViAUnCtHW+j7D3ZW26VaByitFYqwUuhbrEWRbf4WHDVP 01uv6VjonRkcGqQfX080t7TDU/7YToyz1VT7edIJM8kCmEhy2Vs92U7/StUsKZDMPrVD A3xeLaSy+xVUcwScio8497dFyjepQM85zGgmUJHKx7ypkeKIdmjlB5GknQc+G1wAF41l U6w2WJFKZ49gbQp4eUCwrjnPe94dpL1uTrNscEETikac1H8Bfe8xA5lbRARb+q9pkhU8 fMZA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@joelfernandes.org header.s=google header.b=aRQhDf6h; 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 l6si19984729pgp.391.2019.08.05.10.05.49; Mon, 05 Aug 2019 10:06:04 -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=aRQhDf6h; 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 S1729992AbfHERFK (ORCPT + 99 others); Mon, 5 Aug 2019 13:05:10 -0400 Received: from mail-pf1-f194.google.com ([209.85.210.194]:40375 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729942AbfHERFJ (ORCPT ); Mon, 5 Aug 2019 13:05:09 -0400 Received: by mail-pf1-f194.google.com with SMTP id p184so39954310pfp.7 for ; Mon, 05 Aug 2019 10:05:09 -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=aRQhDf6hWMIwFNIsdofuz4dUydkk4193Ae5APGLROO3pABy9OrZWfS49Oc1/HtwlK8 zBW4GUhb8QcOqCuMoUCb51aRgkOp2HCURDKAYJrVPy5wQgbMci9jK3qx0YEVG/MV2GGY McthzaBpFY1H9f9O58G6IjguBX4lH5u33NOZo= 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=TPXVywXrF5FlYjXldxc9dJISmoW5NtqZzPfPqe/YiY6zjepPXMF22LCuJJGlunib7E Sh4Jt5+3LZ6NsFQMeDB0B8xZFVTQm+nrxsR53TI9cFrzZQA5lMS4oPlo9yRT46dAIm22 iD6Jfgq58PKdgqPvHqZPGhR0kp+IZhql+9YHnhmapQEqPLjXfK4ZTpfonL7Z+2Yu/h+/ M/qnNO+aDQSuuXXG1H5jNBgSG9RJ8mIzkJ0qdd0UNn3jIOfI60Ra7e5wrOvjwiazPrcP 7FgDSg9zyI/8bFlGkybb3AcAj/EtAZOcuW8YetamrKciHhuGP+v1CINCdqbLFHLIK1w2 bAjA== X-Gm-Message-State: APjAAAU2jFgbvuI8r4hiYv2MyCcoJhAzIq5A6ryGFoH0rNKOXCxppeP3 tG2B7kt8oE/ySu3XQ8J/lvjpzfkZ X-Received: by 2002:a63:ff65:: with SMTP id s37mr94810810pgk.102.1565024708684; Mon, 05 Aug 2019 10:05:08 -0700 (PDT) Received: from joelaf.cam.corp.google.com ([2620:15c:6:12:9c46:e0da:efbf:69cc]) by smtp.gmail.com with ESMTPSA id p23sm89832934pfn.10.2019.08.05.10.05.05 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Mon, 05 Aug 2019 10:05:07 -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 v4 2/5] [RFC] x86: Add support for idle bit in swap PTE Date: Mon, 5 Aug 2019 13:04:48 -0400 Message-Id: <20190805170451.26009-2-joel@joelfernandes.org> X-Mailer: git-send-email 2.22.0.770.g0f2c4a37fd-goog In-Reply-To: <20190805170451.26009-1-joel@joelfernandes.org> References: <20190805170451.26009-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