Received: by 2002:a4a:311b:0:0:0:0:0 with SMTP id k27-v6csp4807059ooa; Tue, 14 Aug 2018 10:49:19 -0700 (PDT) X-Google-Smtp-Source: AA+uWPyO4X5Dex08PKbdrD4y/mlMeIaE2pkczipoIhKU5XvfaYW+XHrVSOWcSUNhRK1Kcoycax/5 X-Received: by 2002:a63:d704:: with SMTP id d4-v6mr21985792pgg.312.1534268959889; Tue, 14 Aug 2018 10:49:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1534268959; cv=none; d=google.com; s=arc-20160816; b=eC6liLiD70MCYoVpUhlEtra/NNUilwtCuEHvBMjU4NjlZ32CuKbWqrdzt6AWvyRcqt vEu4Zn9byDexVzP8OWu5nJMIk2c6cZJnp1mj/DxGPkp3I30AOZ/uyjLn63iEORdQiD15 Nw4hfV/iU3QCPuFbFj3ksMFP5dBbVXLfUmz27GM0GtCWqtNh5fL+90bhLh88ku+apmJG 6mxOAHstioB0X9UxuHepWHwzTx+Fzatb91gXLTGXtikaJCuC4p7kF+RfokqB2VF1iBlQ ZAzpwAsBwx+mjJV/BQmwuP+5TdRW9tpuf7WCyHWxieCfD3hlDVIjrZx8/kCb2ad8n7Ok 6w7w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=ySNr4rQnYgpG6Zas2Fju3ubHVDY0L++tI7E7/Amu8uE=; b=CqlbQJ1di6KqFbgFQoTRJRb8w+afQTvlF5V+Gio/3iHQdEUyT6w8lIfXaknU0V1n61 PQVdOoUGinwgM3Sl8xcWjd6D0JVTxQkyCT4jwx0e+8GheaNnb7/dK2BwsWbHZ+1x78yd 5f21BJ00g0Tnp9J+qCdrCaRPtMvoxF1aFKAW6yIy65K/AzqyvVF9HeRMv1arwot577b8 MH4eiNgQh1cu6zhLjJRHzv2NbxqbCCAR7smSX437SCx1fT3kTnRWK4qxuu+3ejkLJX7m 6J3WSS/PVH444DLN4Rsd5QcLSXwtGUiPG8O3IfAUcHoMsTHASiRpiUWq61x9KrGvQwpk dYBQ== ARC-Authentication-Results: i=1; mx.google.com; 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 i184-v6si19374908pfg.250.2018.08.14.10.49.04; Tue, 14 Aug 2018 10:49:19 -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; 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 S2391120AbeHNUez (ORCPT + 99 others); Tue, 14 Aug 2018 16:34:55 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:60526 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390706AbeHNUez (ORCPT ); Tue, 14 Aug 2018 16:34:55 -0400 Received: from localhost (unknown [194.244.16.108]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 2675EAF3; Tue, 14 Aug 2018 17:46:42 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Dave Hansen , Andrew Morton , Andy Lutomirski , Borislav Petkov , Brian Gerst , Dave Hansen , Denys Vlasenko , "H. Peter Anvin" , Josh Poimboeuf , Linus Torvalds , "Luis R. Rodriguez" , Peter Zijlstra , Thomas Gleixner , Toshi Kani , dave.hansen@intel.com, linux-mm@kvack.org, mhocko@suse.com, Ingo Molnar , Guenter Roeck Subject: [PATCH 4.4 22/43] x86/mm: Move swap offset/type up in PTE to work around erratum Date: Tue, 14 Aug 2018 19:17:58 +0200 Message-Id: <20180814171518.589533556@linuxfoundation.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180814171517.014285600@linuxfoundation.org> References: <20180814171517.014285600@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.4-stable review patch. If anyone has any objections, please let me know. ------------------ From: Dave Hansen commit 00839ee3b299303c6a5e26a0a2485427a3afcbbf upstream This erratum can result in Accessed/Dirty getting set by the hardware when we do not expect them to be (on !Present PTEs). Instead of trying to fix them up after this happens, we just allow the bits to get set and try to ignore them. We do this by shifting the layout of the bits we use for swap offset/type in our 64-bit PTEs. It looks like this: bitnrs: | ... | 11| 10| 9|8|7|6|5| 4| 3|2|1|0| names: | ... |SW3|SW2|SW1|G|L|D|A|CD|WT|U|W|P| before: | OFFSET (9-63) |0|X|X| TYPE(1-5) |0| after: | OFFSET (14-63) | TYPE (9-13) |0|X|X|X| X| X|X|X|0| Note that D was already a don't care (X) even before. We just move TYPE up and turn its old spot (which could be hit by the A bit) into all don't cares. We take 5 bits away from the offset, but that still leaves us with 50 bits which lets us index into a 62-bit swapfile (4 EiB). I think that's probably fine for the moment. We could theoretically reclaim 5 of the bits (1, 2, 3, 4, 7) but it doesn't gain us anything. Signed-off-by: Dave Hansen Cc: Andrew Morton Cc: Andy Lutomirski Cc: Borislav Petkov Cc: Brian Gerst Cc: Dave Hansen Cc: Denys Vlasenko Cc: H. Peter Anvin Cc: Josh Poimboeuf Cc: Linus Torvalds Cc: Luis R. Rodriguez Cc: Peter Zijlstra Cc: Thomas Gleixner Cc: Toshi Kani Cc: dave.hansen@intel.com Cc: linux-mm@kvack.org Cc: mhocko@suse.com Link: http://lkml.kernel.org/r/20160708001911.9A3FD2B6@viggo.jf.intel.com Signed-off-by: Ingo Molnar Signed-off-by: Guenter Roeck Signed-off-by: Greg Kroah-Hartman --- arch/x86/include/asm/pgtable_64.h | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) --- a/arch/x86/include/asm/pgtable_64.h +++ b/arch/x86/include/asm/pgtable_64.h @@ -163,18 +163,32 @@ static inline int pgd_large(pgd_t pgd) { #define pte_offset_map(dir, address) pte_offset_kernel((dir), (address)) #define pte_unmap(pte) ((void)(pte))/* NOP */ -/* Encode and de-code a swap entry */ +/* + * Encode and de-code a swap entry + * + * | ... | 11| 10| 9|8|7|6|5| 4| 3|2|1|0| <- bit number + * | ... |SW3|SW2|SW1|G|L|D|A|CD|WT|U|W|P| <- bit names + * | OFFSET (14->63) | TYPE (10-13) |0|X|X|X| X| X|X|X|0| <- swp entry + * + * G (8) is aliased and used as a PROT_NONE indicator for + * !present ptes. We need to start storing swap entries above + * there. We also need to avoid using A and D because of an + * erratum where they can be incorrectly set by hardware on + * non-present PTEs. + */ +#define SWP_TYPE_FIRST_BIT (_PAGE_BIT_PROTNONE + 1) #define SWP_TYPE_BITS 5 -#define SWP_OFFSET_SHIFT (_PAGE_BIT_PROTNONE + 1) +/* Place the offset above the type: */ +#define SWP_OFFSET_FIRST_BIT (SWP_TYPE_FIRST_BIT + SWP_TYPE_BITS + 1) #define MAX_SWAPFILES_CHECK() BUILD_BUG_ON(MAX_SWAPFILES_SHIFT > SWP_TYPE_BITS) -#define __swp_type(x) (((x).val >> (_PAGE_BIT_PRESENT + 1)) \ +#define __swp_type(x) (((x).val >> (SWP_TYPE_FIRST_BIT)) \ & ((1U << SWP_TYPE_BITS) - 1)) -#define __swp_offset(x) ((x).val >> SWP_OFFSET_SHIFT) +#define __swp_offset(x) ((x).val >> SWP_OFFSET_FIRST_BIT) #define __swp_entry(type, offset) ((swp_entry_t) { \ - ((type) << (_PAGE_BIT_PRESENT + 1)) \ - | ((offset) << SWP_OFFSET_SHIFT) }) + ((type) << (SWP_TYPE_FIRST_BIT)) \ + | ((offset) << SWP_OFFSET_FIRST_BIT) }) #define __pte_to_swp_entry(pte) ((swp_entry_t) { pte_val((pte)) }) #define __swp_entry_to_pte(x) ((pte_t) { .pte = (x).val })