From patchwork Fri Mar 11 19:07:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nadav Amit X-Patchwork-Id: 12778535 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 211D3C433FE for ; Fri, 11 Mar 2022 19:07:07 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6B01C8D0002; Fri, 11 Mar 2022 14:07:06 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 65FB68D0001; Fri, 11 Mar 2022 14:07:06 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5016A8D0002; Fri, 11 Mar 2022 14:07:06 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0178.hostedemail.com [216.40.44.178]) by kanga.kvack.org (Postfix) with ESMTP id 4280A8D0001 for ; Fri, 11 Mar 2022 14:07:06 -0500 (EST) Received: from smtpin30.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id F327C89073 for ; Fri, 11 Mar 2022 19:07:05 +0000 (UTC) X-FDA: 79233038052.30.1596704 Received: from mail-pg1-f173.google.com (mail-pg1-f173.google.com [209.85.215.173]) by imf10.hostedemail.com (Postfix) with ESMTP id 7DD74C0021 for ; Fri, 11 Mar 2022 19:07:05 +0000 (UTC) Received: by mail-pg1-f173.google.com with SMTP id 132so8210549pga.5 for ; Fri, 11 Mar 2022 11:07:05 -0800 (PST) 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=sDJ/41RHMLJzc98gGAPcQbU38m8lJtFcZEeAQmDlWXg=; b=eB2fEtFzdgN9cXc57alBRC4gluos4heUHZd/NkibI+iQkHVIgyj9X/N3a59R9POFfz FZAEGeEoGaP/DiE1VKnvbdnQHI9dsGk0DFE/1tJBP3Sg24jyuIIvJsZyw+uOYNNaDR5P 62e/plny9+qhehr27OSqyhSf3wCMDRZ8k+gXY2FT3fY2V9dgrCAExF8mufrS9LbOWuWG ZUrU5JjD8b6cLYG9WZwCfsop5Xvm/ntnuXh5WrZOXYdeHzkZypMKytBFZb4inGRjlDos e0K7M+qmuOJCczhU20fTRaMNq2L8nicOYYEVQJ0yt3APiBEMLeIJacTtxNqhnQWbHep3 AxFA== 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=sDJ/41RHMLJzc98gGAPcQbU38m8lJtFcZEeAQmDlWXg=; b=h/cymkXKpGoxPXoF7MUrL0UjNUAPTaCWXZz3XLw1+ogmUmKcfqtC9IvEEM5OFDdZqX seiaYGPUExwmHCF7fpp41DHJHnfq8580MN7JmRrm0tHKsZMGuR/07qDQ0BhpH1vtRElp vDqPPpJOCzfYAqjcPlsoIgTeXZXypig6pmrwsS2QAUxAEPlnXWtZGNM9J1i1RH3FVaMb 18TQG1ZEektA5yWGbkdg01lXblV6GwqujTJPsH8mEzHX/dnzpEev+KWnJ6nHZdlBQGrL tNTjLNN2UbyjNDdnUVU10N71YVqgz+q3+wHja7zHygc9hj9aIgJZ9lmPm4fl3kdJqTZB l0mw== X-Gm-Message-State: AOAM531qh/1zQNxrCoHfsnfaaPFcPt5Tclivd1XA+7sRc50zIV7S+kxI 1nQGpvrTG0+YjfpjF7gfb8Vy4r8woTuu+Q== X-Google-Smtp-Source: ABdhPJyTK8Dn5ndOR70NtnVBIdFNMmT84r6IAuEigLqvHxRv905ZSZ5+Jzeb5r4L2W+TCEADjvwsUg== X-Received: by 2002:a63:f90b:0:b0:378:a292:3951 with SMTP id h11-20020a63f90b000000b00378a2923951mr9594408pgi.312.1647025624006; Fri, 11 Mar 2022 11:07:04 -0800 (PST) Received: from sc2-haas01-esx0118.eng.vmware.com ([66.170.99.1]) by smtp.gmail.com with ESMTPSA id a5-20020a621a05000000b004f79f8f795fsm857329pfa.0.2022.03.11.11.07.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Mar 2022 11:07:03 -0800 (PST) From: Nadav Amit X-Google-Original-From: Nadav Amit To: linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org, Andrew Morton , Nadav Amit , Andi Kleen , Andrea Arcangeli , Andrew Cooper , Andy Lutomirski , Dave Hansen , Peter Xu , Peter Zijlstra , Thomas Gleixner , Will Deacon , Yu Zhao , Nick Piggin , x86@kernel.org Subject: [RESEND PATCH v3 1/5] x86: Detection of Knights Landing A/D leak Date: Fri, 11 Mar 2022 11:07:45 -0800 Message-Id: <20220311190749.338281-2-namit@vmware.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220311190749.338281-1-namit@vmware.com> References: <20220311190749.338281-1-namit@vmware.com> MIME-Version: 1.0 X-Stat-Signature: ctnruiax6pe55wiu9epggeqgwoud88up Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=eB2fEtFz; spf=none (imf10.hostedemail.com: domain of mail-pg1-f173.google.com has no SPF policy when checking 209.85.215.173) smtp.helo=mail-pg1-f173.google.com; dmarc=pass (policy=none) header.from=gmail.com X-Rspam-User: X-Rspamd-Server: rspam11 X-Rspamd-Queue-Id: 7DD74C0021 X-HE-Tag: 1647025625-295252 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 a following patch. 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 67ef0e81c7dc..184b299dbf12 100644 --- a/arch/x86/include/asm/cpufeatures.h +++ b/arch/x86/include/asm/cpufeatures.h @@ -442,5 +442,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..74780fef3f12 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 == INTEL_FAM6_XEON_PHI_KNL) { + 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)