From patchwork Mon Feb 26 08:20:25 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Shi X-Patchwork-Id: 10241599 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id C1D4160386 for ; Mon, 26 Feb 2018 08:40:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B0D6129D2C for ; Mon, 26 Feb 2018 08:40:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A530929D66; Mon, 26 Feb 2018 08:40:34 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 431D629D0E for ; Mon, 26 Feb 2018 08:40:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:List-Subscribe:List-Help: List-Post:List-Archive:List-Unsubscribe:List-Id:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Cc:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=FANRe+xZ387w+2NW5nFOmaPJjclADMw3CkAOdkT1Y5k=; b=W4qQsiz0rmgZED qxe9XYifKdogAVNkf6/dPJBZadPl/TkeXPCmSxv77tG39Y37WNhLr6jCzELqV+Y7KGORKaRC+0m/r Ya4P4xijrkouIzrxGbw5MCfCvz7VS1JKYJtxRIK+KOIqhs5SmlJUjRzOm5kYrFVotPslYIcbslGPc 3O1NWNt+L7+BIIGLL/AY6xqD4m3LfqdcZi1yHHS7dYX5ey32hYCjzMbi7R7Yj6NIhymqGHMysLBsy Yjn5YjEpWR+e10GA9b/StFsrotvn3GQUguFYKs3VZLeQYg1CwtSLtRwlYA2Gj2z8AnSmgJglDnwsp j70kjSxTA4s9CUX8v9aA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.89 #1 (Red Hat Linux)) id 1eqEKk-0007cK-Sm; Mon, 26 Feb 2018 08:40:30 +0000 Received: from mail-pl0-x241.google.com ([2607:f8b0:400e:c01::241]) by bombadil.infradead.org with esmtps (Exim 4.89 #1 (Red Hat Linux)) id 1eqE8d-00055n-Rm for linux-arm-kernel@lists.infradead.org; Mon, 26 Feb 2018 08:28:57 +0000 Received: by mail-pl0-x241.google.com with SMTP id bb3so8871500plb.2 for ; Mon, 26 Feb 2018 00:27:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references; bh=TVG6WlEkeS+IhPzLyRKtulufYo3MBwa/boLRfDGGR6U=; b=D16PV8HTTATeyZl6Ni3Yo6Wioqh3zuHxq2xZnFTqUYLnViWRyw0VIfd2HrfiZuJs+G ogt+dGmsiCyIaXdIMNe3S+YzeN8SgV8C54djUtgwJviaAL8Ez88fUgWVWMEUQkfpSoxr Bra4SXrMnYnQr8PnS9P9bEH2zZaUG2mZO1qxQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=TVG6WlEkeS+IhPzLyRKtulufYo3MBwa/boLRfDGGR6U=; b=KP5Jd0QTrMWug898mK0/2/aVBvBlz3XvNyMkOJCfQGWgbHC8DOVyG+DZDjwdhP9eM0 SdeI4AthM/r9Gi0Caald2m6Si8WZ65h335LkP0sZee64huk+fqf/7h7sfKChl2uk3UgZ CfjaTBSMF1JcF3f/UB6aBgQZJjqQEOHxL0fNcxq9gt4w1LQ2i6AA63IQjU4g536HXi1M YQ4Wbay6u6E/6zktaEExvtYcXXDZQF5aHGJM6+bbQ7e8olmsOnw1f6rlHUBPSj2FwnE7 QzcTxZyXcGiYE2DjAveOJ2OXPNuCU4y2BxPqw/MNW/6+t40uAI8STKL7bZkbj4YWvzH6 P7gg== X-Gm-Message-State: APf1xPAONG57S1KipsotIvyxjEawcfkkjv36GiluZSBelS+x+Lv/Kz3/ /g6uQBUKTJjbTDCmnZeNP4F8RA== X-Google-Smtp-Source: AH8x224M4O1vxd/LYN/xl9O5dhNikRATrb1arMpwsxnDkmDKcry+Gkoi1DGjtXT2Pi2MqpyR0p/bLQ== X-Received: by 2002:a17:902:5e3:: with SMTP id f90-v6mr9954123plf.413.1519633669077; Mon, 26 Feb 2018 00:27:49 -0800 (PST) Received: from localhost.localdomain (176.122.172.82.16clouds.com. [176.122.172.82]) by smtp.gmail.com with ESMTPSA id o86sm1422706pfi.87.2018.02.26.00.27.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 26 Feb 2018 00:27:48 -0800 (PST) From: Alex Shi To: Marc Zyngier , Will Deacon , Ard Biesheuvel , Catalin Marinas , stable@vger.kernel.org, Christoffer Dall , Paolo Bonzini , =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= , Russell King , linux-arm-kernel@lists.infradead.org (moderated list:KERNEL VIRTUAL MACHINE (KVM) FOR ARM), kvmarm@lists.cs.columbia.edu (open list:KERNEL VIRTUAL MACHINE (KVM) FOR ARM), kvm@vger.kernel.org (open list:KERNEL VIRTUAL MACHINE (KVM)), linux-kernel@vger.kernel.org (open list) Subject: [PATCH 51/52] arm: KVM: Invalidate icache on guest exit for Cortex-A15 Date: Mon, 26 Feb 2018 16:20:25 +0800 Message-Id: <1519633227-29832-52-git-send-email-alex.shi@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1519633227-29832-1-git-send-email-alex.shi@linaro.org> References: <1519633227-29832-1-git-send-email-alex.shi@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180226_002800_740674_4E5ECCE9 X-CRM114-Status: GOOD ( 14.66 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP From: Marc Zyngier ** Not yet queued for inclusion in mainline ** In order to avoid aliasing attacks against the branch predictor on Cortex-A15, let's invalidate the BTB on guest exit, which can only be done by invalidating the icache (with ACTLR[0] being set). We use the same hack as for A12/A17 to perform the vector decoding. Signed-off-by: Marc Zyngier Signed-off-by: Will Deacon Signed-off-by: Alex Shi --- arch/arm/include/asm/kvm_mmu.h | 5 +++++ arch/arm/kvm/hyp/hyp-entry.S | 24 ++++++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/arch/arm/include/asm/kvm_mmu.h b/arch/arm/include/asm/kvm_mmu.h index 2887129..a602467 100644 --- a/arch/arm/include/asm/kvm_mmu.h +++ b/arch/arm/include/asm/kvm_mmu.h @@ -235,6 +235,11 @@ static inline void *kvm_get_hyp_vector(void) return kvm_ksym_ref(__kvm_hyp_vector_bp_inv); } + case ARM_CPU_PART_CORTEX_A15: + { + extern char __kvm_hyp_vector_ic_inv[]; + return kvm_ksym_ref(__kvm_hyp_vector_ic_inv); + } #endif default: { diff --git a/arch/arm/kvm/hyp/hyp-entry.S b/arch/arm/kvm/hyp/hyp-entry.S index b6b8cb1..4492768 100644 --- a/arch/arm/kvm/hyp/hyp-entry.S +++ b/arch/arm/kvm/hyp/hyp-entry.S @@ -73,6 +73,28 @@ __kvm_hyp_vector: #ifdef CONFIG_HARDEN_BRANCH_PREDICTOR .align 5 +__kvm_hyp_vector_ic_inv: + .global __kvm_hyp_vector_ic_inv + + /* + * We encode the exception entry in the bottom 3 bits of + * SP, and we have to guarantee to be 8 bytes aligned. + */ + W(add) sp, sp, #1 /* Reset 7 */ + W(add) sp, sp, #1 /* Undef 6 */ + W(add) sp, sp, #1 /* Syscall 5 */ + W(add) sp, sp, #1 /* Prefetch abort 4 */ + W(add) sp, sp, #1 /* Data abort 3 */ + W(add) sp, sp, #1 /* HVC 2 */ + W(add) sp, sp, #1 /* IRQ 1 */ + W(nop) /* FIQ 0 */ + + mcr p15, 0, r0, c7, c5, 0 /* ICIALLU */ + isb + + b decode_vectors + + .align 5 __kvm_hyp_vector_bp_inv: .global __kvm_hyp_vector_bp_inv @@ -92,6 +114,8 @@ __kvm_hyp_vector_bp_inv: mcr p15, 0, r0, c7, c5, 6 /* BPIALL */ isb +decode_vectors: + #ifdef CONFIG_THUMB2_KERNEL /* * Yet another silly hack: Use VPIDR as a temp register.