Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp290695ybi; Thu, 20 Jun 2019 23:13:04 -0700 (PDT) X-Google-Smtp-Source: APXvYqwykNzVAGjvKSYMFQA2agO2ovCtGAG59KFVGozQDaUnSTobYbtIOqcOhRG0isz1POZpd5HY X-Received: by 2002:a17:902:7c03:: with SMTP id x3mr104964174pll.242.1561097583960; Thu, 20 Jun 2019 23:13:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561097583; cv=none; d=google.com; s=arc-20160816; b=rheryQJ8aTCtjzeHmgpc4he+zyRfbxsYxDanTgHrMtFPc8P870vKkqubf0U+395Z8g qfGkLlBYTnc4G8N5kAZ3PEr2JziX2T9p1ht/ne8hI5jzyIJuVGSaVKYWUu5byk+vQEe8 SjOn8Z95C1zjHBwTBraDILrhY6etQe6flzdhl4Eb5u3l3kO74E1oJeFNfcU0fr3NfDRJ 1K/lmoJlI4DaGoCebare3fOWAO2aS3YOi8J6lZseo5WfBwM7d1pT4T9Im5oDcFD4uxEc EYOSu78tInb5i7Xywa3MPwKZwTWsRQX4BEBjOjsIT/ETA/5JXg++kD+Q3i7wKSuBEy9Y JD5Q== 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:subject:cc:to :from:date:message-id:mime-version:dkim-signature; bh=XQC2vWYEYxVCAdoqaVl6sGe93jBERWNKKPMelCZgp70=; b=YuOASFFHrrAnT4VW/oEXC00otk++J5bOOVdMtYyXzCszi6SoMVYz7NqB6BSMWapEC9 hCv2U+p2I2z7Dj9qOCEbeLwlY8sVTYZYu8QAlkBgRpiEkupdMreqmlDQu2T5FqrBPO9a 14YFY3eiEgVoD71Tcgcv/Z1ML0OIlI3aiUq2PIaVjtzic3su2x860miLaN6bCvdTByMC cNIybFnZU/Iq3qhJ86v+KizqTesNl5uksRJ4xly0kIlmnZDz9XlDsLYxp5g6f/GFOmAQ EfiRkMTgRFmOp+nDVNdJFUszKPVvyanEAmPsu5POLHfA4eXmEHHXP4cz+RADmTnXkRHg njPQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2018-07-02 header.b="yml/HzIf"; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f9si1592698pgc.1.2019.06.20.23.12.48; Thu, 20 Jun 2019 23:13:03 -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=@oracle.com header.s=corp-2018-07-02 header.b="yml/HzIf"; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726254AbfFUGLR (ORCPT + 99 others); Fri, 21 Jun 2019 02:11:17 -0400 Received: from aserp2120.oracle.com ([141.146.126.78]:53418 "EHLO aserp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726037AbfFUGLQ (ORCPT ); Fri, 21 Jun 2019 02:11:16 -0400 Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x5L63hwT133989; Fri, 21 Jun 2019 06:10:54 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=mime-version : message-id : date : from : to : cc : subject : content-type : content-transfer-encoding; s=corp-2018-07-02; bh=XQC2vWYEYxVCAdoqaVl6sGe93jBERWNKKPMelCZgp70=; b=yml/HzIfevjcHdXvGkL+F1EBoLnXH+xKybo8yYqgNvrF4fPeXVBFo8srb9b4vrkrp3hA v+4U1TIyat3oDkzYZC2rTKtlxHsx0S/Qeu8+ovo8wNwoK0YPchErb5ElP1VE75Bg5WHa /ANN7n6LXJkbWbbTenZcvSGUZvIUAGpggjfA9POK7CR22phZebRloPwzX/FiYLaJ623k T3cNUNY/E2GRjoYgy+Ex8Ix5qLLXlKYNQDAOCyb3sRxoOQreozGXfckMjqKirjuMPQyd 6d5WMh06ygydHWQnfddmz2cy0PExXRo+66qwlF4RTd66QE83DyspKQqfUbZcuBMzKRkh 2A== Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by aserp2120.oracle.com with ESMTP id 2t7809mkcc-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 21 Jun 2019 06:10:53 +0000 Received: from pps.filterd (userp3030.oracle.com [127.0.0.1]) by userp3030.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x5L69pPM175378; Fri, 21 Jun 2019 06:10:53 GMT Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by userp3030.oracle.com with ESMTP id 2t77yp0x75-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 21 Jun 2019 06:10:53 +0000 Received: from abhmp0018.oracle.com (abhmp0018.oracle.com [141.146.116.24]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id x5L6Ands010731; Fri, 21 Jun 2019 06:10:49 GMT Received: from z2.cn.oracle.com (/10.182.69.87) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 20 Jun 2019 23:10:28 -0700 MIME-Version: 1.0 Message-ID: <1561011237-12312-1-git-send-email-zhenzhong.duan@oracle.com> Date: Wed, 19 Jun 2019 23:13:57 -0700 (PDT) From: Zhenzhong Duan To: linux-kernel@vger.kernel.org Cc: tglx@linutronix.de, mingo@kernel.org, bp@alien8.de, x86@kernel.org, hpa@zytor.com, jgross@suse.com, ndesaulniers@google.com, gregkh@linuxfoundation.org, srinivas.eeda@oracle.com, Zhenzhong Duan Subject: [PATCH] x86/speculation/mds: Flush store buffer after wake up from sleep X-Mailer: git-send-email 1.8.3.1 Content-Type: text/plain; charset=ascii Content-Transfer-Encoding: 7bit X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9294 signatures=668687 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=1 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=817 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1906210052 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9294 signatures=668687 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=1 phishscore=0 bulkscore=0 spamscore=0 clxscore=1011 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=860 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1906210052 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Intel document says: "When a thread wakes from a sleep state, the store buffer is repartitioned again. This causes the store buffer to transfer store buffer entries from the thread that was already active to the one which just woke up." To avoid data leak from sibling thread to the woken thread, flush store buffer right after wake up. Move mds_idle_clear_cpu_buffers() after trace_hardirqs_on() to ensure all store buffer entries are flushed before sleep. Signed-off-by: Zhenzhong Duan --- arch/x86/include/asm/irqflags.h | 2 ++ arch/x86/include/asm/mwait.h | 6 ++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/arch/x86/include/asm/irqflags.h b/arch/x86/include/asm/irqflags.h index 8a0e56e..641c4d8 100644 --- a/arch/x86/include/asm/irqflags.h +++ b/arch/x86/include/asm/irqflags.h @@ -58,12 +58,14 @@ static inline __cpuidle void native_safe_halt(void) { mds_idle_clear_cpu_buffers(); asm volatile("sti; hlt": : :"memory"); + mds_idle_clear_cpu_buffers(); } static inline __cpuidle void native_halt(void) { mds_idle_clear_cpu_buffers(); asm volatile("hlt": : :"memory"); + mds_idle_clear_cpu_buffers(); } #endif diff --git a/arch/x86/include/asm/mwait.h b/arch/x86/include/asm/mwait.h index eb0f80c..1d145d9 100644 --- a/arch/x86/include/asm/mwait.h +++ b/arch/x86/include/asm/mwait.h @@ -46,6 +46,7 @@ static inline void __mwait(unsigned long eax, unsigned long ecx) /* "mwait %eax, %ecx;" */ asm volatile(".byte 0x0f, 0x01, 0xc9;" :: "a" (eax), "c" (ecx)); + mds_idle_clear_cpu_buffers(); } /* @@ -86,12 +87,13 @@ static inline void __mwaitx(unsigned long eax, unsigned long ebx, static inline void __sti_mwait(unsigned long eax, unsigned long ecx) { - mds_idle_clear_cpu_buffers(); - trace_hardirqs_on(); + + mds_idle_clear_cpu_buffers(); /* "mwait %eax, %ecx;" */ asm volatile("sti; .byte 0x0f, 0x01, 0xc9;" :: "a" (eax), "c" (ecx)); + mds_idle_clear_cpu_buffers(); } /* -- 1.8.3.1