Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp742941imm; Thu, 13 Sep 2018 07:07:27 -0700 (PDT) X-Google-Smtp-Source: ANB0VdY0CuCyxvr809W0JKQNNUj6SlS79dAaaTgIfLZmCD2ek6Q2P65mky64jd0pUti8AzgI75Pk X-Received: by 2002:a63:1644:: with SMTP id 4-v6mr7395537pgw.103.1536847647575; Thu, 13 Sep 2018 07:07:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536847647; cv=none; d=google.com; s=arc-20160816; b=VoEZUkCWe+eeE6/j/R9Z2zZcsbiSShIIBNnoU7NnbEM8mV0WgeHByxSqR9ReU93745 a3kVuYPcdasl6PoxEFNPpoR9pDyqE42lYNmxkh0lqlDv0t1IFER+EsVtiXNNum8zZnI5 EgP7nckgcI/Q3tJdSDUEf74cX0gfvgvXIABdoYBx7ffL0Rv8xVP/97PuQSCAGKIpsUNy sbGvrF/6seMf0bG83zwYILs+bHcyNHwvU4x8lRAFsw2g6ncgMORkdhpOwCrQmwqKP8+8 6M4/KrWa+lOQ+PuCaaCYXNJCPBwpExdQtOMOmit2LDr7EzDcoOF2UP1RR8FA+xQGg/uS mA0g== 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:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from; bh=ZVsVd87NMtKRf6blrxGPg3SmCL/D2X2ShH8zowmzYpM=; b=samm2NjRqnCsm4skqhQGl96exP188I2ZDorTf/XC9dYnheeDEM50dOWj2RRqZpP6nZ yXehmERjhPA6p+R4XZ9D+t6WCojndebChV0dVvNbHNNqHNm1PPtr0OVhcWK582EgVEAM 8uNvsRT1nWRMNa8FU3x9sGODJKMmOAeqxZO5QgLGi/bT84KChQRY+aH0QEDho7nSt6y/ eq1zD56dIOg7ppy2V5UfFeNeM/nMibJ/f62XgOVnmpV4Le3LycDS31qcWc3vxhDuJNWw KIZbA9/J4FWifrsR1U/6BNNYDv7L12v443tkCO2rcRxl2E/C2OCz93YUYfWkIz1zwt0y 6w1g== 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 m1-v6si3800819plb.348.2018.09.13.07.07.11; Thu, 13 Sep 2018 07:07:27 -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 S1732260AbeIMTQq (ORCPT + 99 others); Thu, 13 Sep 2018 15:16:46 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:35682 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729096AbeIMTQp (ORCPT ); Thu, 13 Sep 2018 15:16:45 -0400 Received: from localhost (ip-213-127-77-73.ip.prioritytelecom.net [213.127.77.73]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id BC5D6D39; Thu, 13 Sep 2018 14:07:04 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Juergen Gross , Thomas Gleixner , Jan Beulich , Jason Andryuk , Boris Ostrovsky Subject: [PATCH 4.18 191/197] x86/pae: use 64 bit atomic xchg function in native_ptep_get_and_clear Date: Thu, 13 Sep 2018 15:32:20 +0200 Message-Id: <20180913131849.200843577@linuxfoundation.org> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20180913131841.568116777@linuxfoundation.org> References: <20180913131841.568116777@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Juergen Gross commit b2d7a075a1ccef2fb321d595802190c8e9b39004 upstream. Using only 32-bit writes for the pte will result in an intermediate L1TF vulnerable PTE. When running as a Xen PV guest this will at once switch the guest to shadow mode resulting in a loss of performance. Use arch_atomic64_xchg() instead which will perform the requested operation atomically with all 64 bits. Some performance considerations according to: https://software.intel.com/sites/default/files/managed/ad/dc/Intel-Xeon-Scalable-Processor-throughput-latency.pdf The main number should be the latency, as there is no tight loop around native_ptep_get_and_clear(). "lock cmpxchg8b" has a latency of 20 cycles, while "lock xchg" (with a memory operand) isn't mentioned in that document. "lock xadd" (with xadd having 3 cycles less latency than xchg) has a latency of 11, so we can assume a latency of 14 for "lock xchg". Signed-off-by: Juergen Gross Reviewed-by: Thomas Gleixner Reviewed-by: Jan Beulich Tested-by: Jason Andryuk Signed-off-by: Boris Ostrovsky Signed-off-by: Greg Kroah-Hartman --- arch/x86/include/asm/pgtable-3level.h | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) --- a/arch/x86/include/asm/pgtable-3level.h +++ b/arch/x86/include/asm/pgtable-3level.h @@ -2,6 +2,8 @@ #ifndef _ASM_X86_PGTABLE_3LEVEL_H #define _ASM_X86_PGTABLE_3LEVEL_H +#include + /* * Intel Physical Address Extension (PAE) Mode - three-level page * tables on PPro+ CPUs. @@ -147,10 +149,7 @@ static inline pte_t native_ptep_get_and_ { pte_t res; - /* xchg acts as a barrier before the setting of the high bits */ - res.pte_low = xchg(&ptep->pte_low, 0); - res.pte_high = ptep->pte_high; - ptep->pte_high = 0; + res.pte = (pteval_t)arch_atomic64_xchg((atomic64_t *)ptep, 0); return res; }