Received: by 10.223.148.5 with SMTP id 5csp7255367wrq; Thu, 18 Jan 2018 03:06:13 -0800 (PST) X-Google-Smtp-Source: ACJfBougVXG5rxhMgQZSRfLDdJVSeNNxBVu0Hcp5NY6rMy1OV/B6vKyxmQ3i6L2MpszmTLp2Xn2G X-Received: by 10.84.128.74 with SMTP id 68mr35677111pla.228.1516273573546; Thu, 18 Jan 2018 03:06:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516273573; cv=none; d=google.com; s=arc-20160816; b=072sahsmEFkTAJVD8rzhmN6ccyb1vaTRYHcjHymsEzNsrZuqBAqgW9aKlvyYUZuYaw 4DEhY8QoL0UwjNnwFMjlZDfKfPHlMso7zwDctD82iDwO+tonulK5AfJvNM1fc65U1sEi kV+HdpGPP6LokGAr7gGvUyuwxYQMm4thRDG61jEXTaxvuSRdWjsn7fPAMT4zPS9eCXfM Yy4689x6Fjlhpje9ZC45Q8T9LQd/O6rToOovdeB7HgbSprotXxBmSyBl0wmrCWyXgkv2 DtO/xY/a6Bsd80FsjclzwH2KN9SHIlHEXDB/8YGwgQj+57tl7SKUFcsy38KdqqOg+7QX 3zhw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-disposition :content-transfer-encoding:mime-version:robot-unsubscribe:robot-id :git-commit-id:subject:to:references:in-reply-to:reply-to:cc :message-id:from:date:arc-authentication-results; bh=jhCSm1s3kFI6VSdcJ5YK0xhE0KUodlCFDQsxefbs9Lo=; b=LG6/7vh0BmWZ+wtR5Tr/Vfcvx+q+szKDXz+XU1SXd7xydr4kSXI2imZNsVhh0erORy q4Wtja+rfZNkNoPQniaU7v+l+x3O2WvT66iuG/X6Si8V1FyvB7skhtzzIU1A5YDqgbb7 1tqL5ThT8EyCTlGtUMII4wo+zgVM6xW5sEeJ/RabCQ0HHgfdaCw47pKMwtbnHxuCIuv3 iNjyV+EBLO3oM0mbx3Wx6az16T8O66Wn566jEybh2iaMqNUYrXm94b4PIKbnG8VvZw1l mfGsDoXIo7gyvR4eRGOmiaUEO6xwIfr0cZS3iqx20+8Dpygg+vniAMSng1Oi/naPG+/6 d3nQ== 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 v10si7066617plo.820.2018.01.18.03.05.59; Thu, 18 Jan 2018 03:06:13 -0800 (PST) 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 S1755953AbeARK7K (ORCPT + 99 others); Thu, 18 Jan 2018 05:59:10 -0500 Received: from terminus.zytor.com ([65.50.211.136]:38487 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755924AbeARK7H (ORCPT ); Thu, 18 Jan 2018 05:59:07 -0500 Received: from terminus.zytor.com (localhost [127.0.0.1]) by terminus.zytor.com (8.15.2/8.15.2) with ESMTP id w0IAswUO019707; Thu, 18 Jan 2018 02:54:58 -0800 Received: (from tipbot@localhost) by terminus.zytor.com (8.15.2/8.15.2/Submit) id w0IAswWM019703; Thu, 18 Jan 2018 02:54:58 -0800 Date: Thu, 18 Jan 2018 02:54:58 -0800 X-Authentication-Warning: terminus.zytor.com: tipbot set sender to tipbot@zytor.com using -f From: tip-bot for Tom Lendacky Message-ID: Cc: torvalds@linux-foundation.org, tony.luck@intel.com, jgross@suse.com, dan.j.williams@intel.com, boris.ostrovsky@oracle.com, tglx@linutronix.de, linux-kernel@vger.kernel.org, hpa@zytor.com, arjan@linux.intel.com, rui.zhang@intel.com, dyoung@redhat.com, bhe@redhat.com, bp@alien8.de, yu.c.chen@intel.com, mingo@kernel.org, thomas.lendacky@amd.com Reply-To: torvalds@linux-foundation.org, tony.luck@intel.com, dan.j.williams@intel.com, jgross@suse.com, tglx@linutronix.de, boris.ostrovsky@oracle.com, arjan@linux.intel.com, hpa@zytor.com, linux-kernel@vger.kernel.org, bp@alien8.de, bhe@redhat.com, dyoung@redhat.com, rui.zhang@intel.com, thomas.lendacky@amd.com, mingo@kernel.org, yu.c.chen@intel.com In-Reply-To: <20180117234141.21184.44067.stgit@tlendack-t1.amdoffice.net> References: <20180117234141.21184.44067.stgit@tlendack-t1.amdoffice.net> To: linux-tip-commits@vger.kernel.org Subject: [tip:x86/urgent] x86/mm: Rework wbinvd, hlt operation in stop_this_cpu() Git-Commit-ID: f23d74f6c66c3697e032550eeef3f640391a3a7d X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline X-Spam-Status: No, score=-2.9 required=5.0 tests=ALL_TRUSTED,BAYES_00 autolearn=ham autolearn_force=no version=3.4.1 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on terminus.zytor.com Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: f23d74f6c66c3697e032550eeef3f640391a3a7d Gitweb: https://git.kernel.org/tip/f23d74f6c66c3697e032550eeef3f640391a3a7d Author: Tom Lendacky AuthorDate: Wed, 17 Jan 2018 17:41:41 -0600 Committer: Thomas Gleixner CommitDate: Thu, 18 Jan 2018 11:48:59 +0100 x86/mm: Rework wbinvd, hlt operation in stop_this_cpu() Some issues have been reported with the for loop in stop_this_cpu() that issues the 'wbinvd; hlt' sequence. Reverting this sequence to halt() has been shown to resolve the issue. However, the wbinvd is needed when running with SME. The reason for the wbinvd is to prevent cache flush races between encrypted and non-encrypted entries that have the same physical address. This can occur when kexec'ing from memory encryption active to inactive or vice-versa. The important thing is to not have outside of kernel text memory references (such as stack usage), so the usage of the native_*() functions is needed since these expand as inline asm sequences. So instead of reverting the change, rework the sequence. Move the wbinvd instruction outside of the for loop as native_wbinvd() and make its execution conditional on X86_FEATURE_SME. In the for loop, change the asm 'wbinvd; hlt' sequence back to a halt sequence but use the native_halt() call. Fixes: bba4ed011a52 ("x86/mm, kexec: Allow kexec to be used with SME") Reported-by: Dave Young Signed-off-by: Tom Lendacky Signed-off-by: Thomas Gleixner Tested-by: Dave Young Cc: Juergen Gross Cc: Tony Luck Cc: Yu Chen Cc: Baoquan He Cc: Linus Torvalds Cc: kexec@lists.infradead.org Cc: ebiederm@redhat.com Cc: Borislav Petkov Cc: Rui Zhang Cc: Arjan van de Ven Cc: Boris Ostrovsky Cc: Dan Williams Cc: stable@vger.kernel.org Link: https://lkml.kernel.org/r/20180117234141.21184.44067.stgit@tlendack-t1.amdoffice.net --- arch/x86/kernel/process.c | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c index 832a6ac..cb368c2 100644 --- a/arch/x86/kernel/process.c +++ b/arch/x86/kernel/process.c @@ -380,19 +380,24 @@ void stop_this_cpu(void *dummy) disable_local_APIC(); mcheck_cpu_clear(this_cpu_ptr(&cpu_info)); + /* + * Use wbinvd on processors that support SME. This provides support + * for performing a successful kexec when going from SME inactive + * to SME active (or vice-versa). The cache must be cleared so that + * if there are entries with the same physical address, both with and + * without the encryption bit, they don't race each other when flushed + * and potentially end up with the wrong entry being committed to + * memory. + */ + if (boot_cpu_has(X86_FEATURE_SME)) + native_wbinvd(); for (;;) { /* - * Use wbinvd followed by hlt to stop the processor. This - * provides support for kexec on a processor that supports - * SME. With kexec, going from SME inactive to SME active - * requires clearing cache entries so that addresses without - * the encryption bit set don't corrupt the same physical - * address that has the encryption bit set when caches are - * flushed. To achieve this a wbinvd is performed followed by - * a hlt. Even if the processor is not in the kexec/SME - * scenario this only adds a wbinvd to a halting processor. + * Use native_halt() so that memory contents don't change + * (stack usage and variables) after possibly issuing the + * native_wbinvd() above. */ - asm volatile("wbinvd; hlt" : : : "memory"); + native_halt(); } }