From patchwork Wed Jul 12 14:44:17 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 9836891 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 92BE460363 for ; Wed, 12 Jul 2017 14:46:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 82C8220265 for ; Wed, 12 Jul 2017 14:46:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 76FAE284E4; Wed, 12 Jul 2017 14:46:40 +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=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.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 1FA7520265 for ; Wed, 12 Jul 2017 14:46:39 +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:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=6kNosUiSf5SMxorEZ84Xnka6HRJeKZ71LLD4knybD8Y=; b=imgZppl7qg41xNb+pydH1l27D5 +xvMvZ/wLUQ6pU1DJwBVNLJfwLqyMdANEm+C4SfFSOmeEjO41GRsWw4Z6ARi7RcSEZ7R3ldtfoUtL crshgr0/mksYcAfEmUxgyPLFwA4BZ2oenKjAuQZZSFT0pP65v9iISENkDP2TAeu5w5h5LHdaRo722 8148cHkT5t2kNaA2lR6bbPGSvEb03yLJzeR2FkkBlZ1BwzFzu34Bf2Md66AB+UAlNkJneQ9Laz8ZI DWMYmVpJhJfvB99dfE1Xu8jC8DbTV8qodQGa/zR3vyHglksPZR8OUjBVtZnzQWbo/19EdvYp6A06D nQbVG4yQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1dVIuT-0002cJ-Vm; Wed, 12 Jul 2017 14:46:38 +0000 Received: from mail-wr0-x22a.google.com ([2a00:1450:400c:c0c::22a]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1dVItI-0000Ek-54 for linux-arm-kernel@lists.infradead.org; Wed, 12 Jul 2017 14:45:27 +0000 Received: by mail-wr0-x22a.google.com with SMTP id 77so36697905wrb.1 for ; Wed, 12 Jul 2017 07:45:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=qFZl+sAV0U+xNo9qukU7WEiQSwQHGpRixCCFbfkryeE=; b=L+ZD1Z0Ae6lapbG1MkHWHRSNaTr9jkShI4wMihUw6F7DfIRmnZMJDbJDxFxI2LdtHm erjsrSvwvy/W7TTVnmz1d+xgY2TcbBVV8umEUbeX86uSTSzI8Duv7/MN2rWUWjTM0H2p X3UdmswjEckEGngzNbljixAOHnr8oBB2XV6WE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=qFZl+sAV0U+xNo9qukU7WEiQSwQHGpRixCCFbfkryeE=; b=sIThgvCi1KIVcjQQiFAFA87GyCWa5qGVK///y0pqt8nyCpNK8kaAJTc4k9em47LBr3 BnJQqSmuz72WDAOabi/6ZcUDZtIp9tWogFlBQh393Hz2HYgtg6ccH0LVIBwcv8kic6Yo VkMO2wAkcpP3s6aqNlb6RvKVaqbwuupwj6PPyq6Tk2IFUOBowfAqrGuIhWkF4A0PvuwY aqCt3ORd1OWcfRNShL4kSDZwuo5A7Su5QUZYORZyQRO2Inl1K/Bu8+mjhFMqbJhJki3H 5fza2OJc8amWGj4/pbde2Dgxeid4Lbrp+sJxRK9WO5uYC2jihy49mdfinaPsg76zjfZ2 vniA== X-Gm-Message-State: AIVw110H9Ha+ks3x9iS/zS/+4OAoercJ95irN4CwJwKu1pt7yMGAIBAm QtBxx+5Qd2WgwUQ1WPfo2A== X-Received: by 10.223.169.51 with SMTP id u48mr2982560wrc.176.1499870701136; Wed, 12 Jul 2017 07:45:01 -0700 (PDT) Received: from localhost.localdomain ([154.149.70.241]) by smtp.gmail.com with ESMTPSA id m26sm2735851wrm.4.2017.07.12.07.44.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 12 Jul 2017 07:45:00 -0700 (PDT) From: Ard Biesheuvel To: linux-arm-kernel@lists.infradead.org, kernel-hardening@lists.openwall.com Subject: [RFC PATCH 04/10] arm64: kvm: stop treating register x18 as caller save Date: Wed, 12 Jul 2017 15:44:17 +0100 Message-Id: <20170712144424.19528-5-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20170712144424.19528-1-ard.biesheuvel@linaro.org> References: <20170712144424.19528-1-ard.biesheuvel@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170712_074524_642812_27197EC0 X-CRM114-Status: GOOD ( 11.00 ) 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: , Cc: mark.rutland@arm.com, Ard Biesheuvel , catalin.marinas@arm.com, will.deacon@arm.com, dave.martin@arm.com, labbott@fedoraproject.org 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 In preparation of using x18 as a task struct pointer register when running in the kernel, stop treating it as caller save in the KVM guest entry/exit code. Currently, the code assumes there is no need to preserve it for the host, given that it would have been assumed clobbered anyway by the function call to __guest_enter(). Instead, preserve its value and restore it upon return. Signed-off-by: Ard Biesheuvel --- arch/arm64/kvm/hyp/entry.S | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/arch/arm64/kvm/hyp/entry.S b/arch/arm64/kvm/hyp/entry.S index 12ee62d6d410..75d31a161d3e 100644 --- a/arch/arm64/kvm/hyp/entry.S +++ b/arch/arm64/kvm/hyp/entry.S @@ -32,6 +32,7 @@ .pushsection .hyp.text, "ax" .macro save_callee_saved_regs ctxt + str x18, [\ctxt, #CPU_XREG_OFFSET(18)] stp x19, x20, [\ctxt, #CPU_XREG_OFFSET(19)] stp x21, x22, [\ctxt, #CPU_XREG_OFFSET(21)] stp x23, x24, [\ctxt, #CPU_XREG_OFFSET(23)] @@ -47,6 +48,7 @@ ldp x25, x26, [\ctxt, #CPU_XREG_OFFSET(25)] ldp x27, x28, [\ctxt, #CPU_XREG_OFFSET(27)] ldp x29, lr, [\ctxt, #CPU_XREG_OFFSET(29)] + ldr x18, [\ctxt, #CPU_XREG_OFFSET(18)] .endm /* @@ -78,12 +80,9 @@ ENTRY(__guest_enter) ldp x14, x15, [x18, #CPU_XREG_OFFSET(14)] ldp x16, x17, [x18, #CPU_XREG_OFFSET(16)] - // Restore guest regs x19-x29, lr + // Restore guest regs x18-x29, lr restore_callee_saved_regs x18 - // Restore guest reg x18 - ldr x18, [x18, #CPU_XREG_OFFSET(18)] - // Do not touch any register after this! eret ENDPROC(__guest_enter) @@ -104,7 +103,7 @@ ENTRY(__guest_exit) // Retrieve the guest regs x0-x1 from the stack ldp x2, x3, [sp], #16 // x0, x1 - // Store the guest regs x0-x1 and x4-x18 + // Store the guest regs x0-x1 and x4-x17 stp x2, x3, [x1, #CPU_XREG_OFFSET(0)] stp x4, x5, [x1, #CPU_XREG_OFFSET(4)] stp x6, x7, [x1, #CPU_XREG_OFFSET(6)] @@ -113,9 +112,8 @@ ENTRY(__guest_exit) stp x12, x13, [x1, #CPU_XREG_OFFSET(12)] stp x14, x15, [x1, #CPU_XREG_OFFSET(14)] stp x16, x17, [x1, #CPU_XREG_OFFSET(16)] - str x18, [x1, #CPU_XREG_OFFSET(18)] - // Store the guest regs x19-x29, lr + // Store the guest regs x18-x29, lr save_callee_saved_regs x1 // Restore the host_ctxt from the stack