From patchwork Thu Oct 21 12:21:08 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nadav Amit X-Patchwork-Id: 12576361 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 91D77C433FE for ; Thu, 21 Oct 2021 19:52:51 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 3DB396103D for ; Thu, 21 Oct 2021 19:52:51 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 3DB396103D Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id C38336B006C; Thu, 21 Oct 2021 15:52:50 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id BE69B940007; Thu, 21 Oct 2021 15:52:50 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AD4C16B0073; Thu, 21 Oct 2021 15:52:50 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0005.hostedemail.com [216.40.44.5]) by kanga.kvack.org (Postfix) with ESMTP id A12D36B006C for ; Thu, 21 Oct 2021 15:52:50 -0400 (EDT) Received: from smtpin08.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 31755183381FE for ; Thu, 21 Oct 2021 19:52:50 +0000 (UTC) X-FDA: 78721492500.08.1949CBA Received: from mail-pg1-f180.google.com (mail-pg1-f180.google.com [209.85.215.180]) by imf04.hostedemail.com (Postfix) with ESMTP id 9BCE65000303 for ; Thu, 21 Oct 2021 19:52:46 +0000 (UTC) Received: by mail-pg1-f180.google.com with SMTP id g184so1262950pgc.6 for ; Thu, 21 Oct 2021 12:52:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=2owe5n0pN7M447a4f5gtFpdAO84GGDezTjkbshsV/5A=; b=NJDNLISDqCS6DWtuKe+YL6u25O9QPnbwfEMv6fi/FTzhN7VZCfvtRP1YGKBc0+XjMh YCazBLUWtRkWc81D2XisUekNzNGZaZaRAzPypK2TOhTwjkA/YUpKCRlrLvtfrQM5Pna6 OryIRAJXIdg5dmnUvNdYU7M0QYPu9QFqpiRmNRY0U5mYE5NsJZOIMzM+a3ROsX7Vumyb 1M0zHT3yzYTM1R3GOd2RDmG99sGCnvZCnjZ1jWU7BEQssUH2pLHmL6SJ+O4x90sMvFGB JO/Ut/ZDjB7YA0eUMqECF9o/RU7AsYnkSG+l2ESCEmCFZWO0AcsdEVfdHTAwybrMkUwG bT5w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=2owe5n0pN7M447a4f5gtFpdAO84GGDezTjkbshsV/5A=; b=wRZzhgqjF8sO0a9vMSZFnmXMhrILp4CndOVucHqn46Yh3MOEzY4DP+6VwtszHPQo9m AStKj4TY/0+fYHzSQWcGGesrB7is6oK4kZ3H7T8iaB4sDLtFBK8SdZyHfnidbVAEq4C1 T199kHUvcDvh0oLl425CnVT3QysV3PGNIr49ei+kEu9ZeROcY8de90FqyK4nAO5JQavF 0pjxi3pJvD7FNvOJKhkUqt+NTwlCdm+TAr7TpZafYXdZYiJMkzxatmBp6TEePkn020yP 82OXcY+n5qlBgpGktK18+L4W9WH/tVOXVgevTvoAtQ15f9fNz1exrIuHMkp9EjwJkW6P 8kXw== X-Gm-Message-State: AOAM531bB/AwX4pYNQ/pNCt8U9yegi14p29wcnLs6RtEgBIryYwLYyuH JnTOFyJjGpsKGa3HOwEJ2xH7O2X/SFQ= X-Google-Smtp-Source: ABdhPJwDn3L/Z/hX4WazYQ273fY7J6ervyUBeTkfMNwrqmDOEOlhO9clSXfesU4EUXHWpvcLXdAWhg== X-Received: by 2002:a63:9554:: with SMTP id t20mr5888260pgn.153.1634845968105; Thu, 21 Oct 2021 12:52:48 -0700 (PDT) Received: from sc2-haas01-esx0118.eng.vmware.com ([66.170.99.1]) by smtp.gmail.com with ESMTPSA id n202sm7098078pfd.160.2021.10.21.12.52.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Oct 2021 12:52:47 -0700 (PDT) From: Nadav Amit X-Google-Original-From: Nadav Amit To: linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org, Nadav Amit , Andi Kleen , Andrea Arcangeli , Andrew Cooper , Andrew Morton , Andy Lutomirski , Dave Hansen , Peter Xu , Peter Zijlstra , Thomas Gleixner , Will Deacon , Yu Zhao , Nick Piggin , x86@kernel.org Subject: [PATCH v2 1/5] x86: Detection of Knights Landing A/D leak Date: Thu, 21 Oct 2021 05:21:08 -0700 Message-Id: <20211021122112.592634-2-namit@vmware.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211021122112.592634-1-namit@vmware.com> References: <20211021122112.592634-1-namit@vmware.com> MIME-Version: 1.0 X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 9BCE65000303 X-Stat-Signature: o8uqgqe4odnrho68qp48a3dwuk5mkhz4 Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=NJDNLISD; dmarc=pass (policy=none) header.from=gmail.com; spf=none (imf04.hostedemail.com: domain of mail-pg1-f180.google.com has no SPF policy when checking 209.85.215.180) smtp.helo=mail-pg1-f180.google.com X-HE-Tag: 1634845966-729158 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: Nadav Amit Knights Landing has a issue that a thread setting A or D bits may not do so atomically against checking the present bit. A thread which is going to page fault may still set those bits, even though the present bit was already atomically cleared. This implies that when the kernel clears present atomically, some time later the supposed to be zero entry could be corrupted with stray A or D bits. Since the PTE could be already used for storing a swap index, or a NUMA migration index, this cannot be tolerated. Most of the time the kernel detects the problem, but in some rare cases it may not. This patch adds an interface to detect the bug, which will be used in the following patch. [ Based on a patch by Andi Kleen ] Cc: Andi Kleen Cc: Andrea Arcangeli Cc: Andrew Cooper Cc: Andrew Morton Cc: Andy Lutomirski Cc: Dave Hansen Cc: Peter Xu Cc: Peter Zijlstra Cc: Thomas Gleixner Cc: Will Deacon Cc: Yu Zhao Cc: Nick Piggin Cc: x86@kernel.org Link: https://lore.kernel.org/lkml/1465919919-2093-1-git-send-email-lukasz.anaczkowski@intel.com/ Signed-off-by: Nadav Amit --- arch/x86/include/asm/cpufeatures.h | 1 + arch/x86/kernel/cpu/intel.c | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/arch/x86/include/asm/cpufeatures.h b/arch/x86/include/asm/cpufeatures.h index d0ce5cfd3ac1..32d0aabd788d 100644 --- a/arch/x86/include/asm/cpufeatures.h +++ b/arch/x86/include/asm/cpufeatures.h @@ -436,5 +436,6 @@ #define X86_BUG_TAA X86_BUG(22) /* CPU is affected by TSX Async Abort(TAA) */ #define X86_BUG_ITLB_MULTIHIT X86_BUG(23) /* CPU may incur MCE during certain page attribute changes */ #define X86_BUG_SRBDS X86_BUG(24) /* CPU may leak RNG bits if not mitigated */ +#define X86_BUG_PTE_LEAK X86_BUG(25) /* PTE may leak A/D bits after clear */ #endif /* _ASM_X86_CPUFEATURES_H */ diff --git a/arch/x86/kernel/cpu/intel.c b/arch/x86/kernel/cpu/intel.c index 8321c43554a1..40bcba6e3641 100644 --- a/arch/x86/kernel/cpu/intel.c +++ b/arch/x86/kernel/cpu/intel.c @@ -296,6 +296,11 @@ static void early_init_intel(struct cpuinfo_x86 *c) } } + if (c->x86_model == 87) { + pr_info_once("Enabling PTE leaking workaround\n"); + set_cpu_bug(c, X86_BUG_PTE_LEAK); + } + /* * Intel Quark Core DevMan_001.pdf section 6.4.11 * "The operating system also is required to invalidate (i.e., flush)