From patchwork Tue Nov 5 23:55:56 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sami Tolvanen X-Patchwork-Id: 178578 Delivered-To: patch@linaro.org Received: by 2002:a92:38d5:0:0:0:0:0 with SMTP id g82csp1464207ilf; Tue, 5 Nov 2019 15:57:13 -0800 (PST) X-Google-Smtp-Source: APXvYqwpwPq5LYDUax4iW3WelEtTo4962vLWktwrH9oUU+ad7edWoRdA9HM1BNqhe9b49TGagbVW X-Received: by 2002:a50:cd4a:: with SMTP id d10mr6817772edj.42.1572998232900; Tue, 05 Nov 2019 15:57:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1572998232; cv=none; d=google.com; s=arc-20160816; b=J3dwPWEBE9utidqHtxxSC9S8fjG4f8+FbdgkJNp1j/BMJnBpr2ei8rgSJpNGWN9aJM BD0E5HAPrmQnTyUXlAeXCB2Png3piVnMLZhryxPg65/tPkZwNtbO8pbkMD/GgbyQNbWO BPBAfbuk50bMJHc0VFyeW+sSGU1khjuiD72ChSpPkrJg+ERN9L64WuSv2WKfMjmXAQHh nwuKJ23GFY7u9gLpBsiJIeIsnlQeZl23krVQ3gqQMXwCPlCl6jK4h6pO/WMhso0VAWTi 3qVcTKB9zv6RvaVQKRau4gaJdsHabT02PkpYE/aMInVkn6OI6A65ZyWnQx02BhF0wD9B C/WA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:from:subject:references :mime-version:message-id:in-reply-to:date:dkim-signature; bh=OH2SjYe0B8esWxTAcCgR+62MsPomBC+RzRSTMU1rFk8=; b=Z1xTg4+XfP7X2VYwaGDO6hzp/TrWgf7/Jtwgnlj329PGFy9CC3iCWdBgpg1cYBQz3+ jmARlRjB7AGVTyglVBHQFcMHl2uMKFN3PbhJw2MPp8RI8KEcZ7unwr+NRBB8N5OK0OYL RsqIK0bshon++xqOG97T4rUR+sA6OcrgSxYu8hDx+tWxLUSbvgrDjWNxNAz4BqunahAf TqsoRlEzH1amXlR+CsH6dD7kD3+Mlw18YliATQlEPHzHsl8ipqMEDDAMnMcegj7FxZ+7 8q2ooJufx7/goHTb7Mg5fF4anbKGzajJKIph8V/hJusW75qct0z56fbN1jdmvNp/kDv1 2WVg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=LANLIsSL; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k22si8852839eji.282.2019.11.05.15.57.12; Tue, 05 Nov 2019 15:57:12 -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; dkim=pass header.i=@google.com header.s=20161025 header.b=LANLIsSL; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730624AbfKEX4Y (ORCPT + 26 others); Tue, 5 Nov 2019 18:56:24 -0500 Received: from mail-vk1-f202.google.com ([209.85.221.202]:44629 "EHLO mail-vk1-f202.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730543AbfKEX4W (ORCPT ); Tue, 5 Nov 2019 18:56:22 -0500 Received: by mail-vk1-f202.google.com with SMTP id 131so1158607vkb.11 for ; Tue, 05 Nov 2019 15:56:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=OH2SjYe0B8esWxTAcCgR+62MsPomBC+RzRSTMU1rFk8=; b=LANLIsSLRt+jERn9z/YC1fWtMQVX8zCypiEu6yw+A7ph5wykxHwT9wsDMQDlDMl2rg stArYiAU/nb/XpN8wDOhlGyfTc0fdCPVyLoqsctOyYeGq24aghzkvptD+XVbn9Xq4Qx2 yxJPdKckjUE2Le0UST7HQhi45E/yHrtn4L5mNNxo+7JL+AcIOJugxBvuaOWMfQaRKd19 pgc7iEsvYu0XarG32KP1cibZw6Yh6odpoBcAbe/UiVxBTEh1uk9MrGBjI2ktk5L02xPX x9VA45PGyhIT4mZVHxYbG80ZMkQKYGWocfpS2nmfUWNgOvxc1mQu8MLaMnzS4vac3Qt1 JBZw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=OH2SjYe0B8esWxTAcCgR+62MsPomBC+RzRSTMU1rFk8=; b=TUyR+rqVaJspadU916/klyNUk0i8ONOlGv9SZsAV5s9HKza5n91keL9FcWiuFSWWxv Gd4eQABF9uuQ/3Rk6czEkkHKKfoaTH4LNdbLDBEjo/R/BQb8MTT9Ug+8NFPBEycuIPJB eKS3VR32pexg0JOVTPP596UhE6+UM9VmasM9pwTXNAEdwWEssQ7ISPhEMTg12n/4IDdY 2mlEMVFqDhKRxIilPSFphCLY/pC/7OunV3HRiJCYBK04oH5fEO9JhPOLr+YCBZWaQb6Q 6hUR5LzanT4jWQIMYe3sSN3tbLFubi5/R02RrAtx/RucGrPaEPF+AK0mf/cHro90BdcG DUsg== X-Gm-Message-State: APjAAAVu8JcdFwcSSsU3brkkElPcmjrZfHzh0AzJqeVOR0gjxeEH7/nP oj4l8DvJp/gAZfYWR92SvsGmryi2H1I4U/diwME= X-Received: by 2002:a67:ef0c:: with SMTP id j12mr9381038vsr.201.1572998180740; Tue, 05 Nov 2019 15:56:20 -0800 (PST) Date: Tue, 5 Nov 2019 15:55:56 -0800 In-Reply-To: <20191105235608.107702-1-samitolvanen@google.com> Message-Id: <20191105235608.107702-3-samitolvanen@google.com> Mime-Version: 1.0 References: <20191018161033.261971-1-samitolvanen@google.com> <20191105235608.107702-1-samitolvanen@google.com> X-Mailer: git-send-email 2.24.0.rc1.363.gb1bccd3e3d-goog Subject: [PATCH v5 02/14] arm64/lib: copy_page: avoid x18 register in assembler code From: Sami Tolvanen To: Will Deacon , Catalin Marinas , Steven Rostedt , Masami Hiramatsu , Ard Biesheuvel Cc: Dave Martin , Kees Cook , Laura Abbott , Mark Rutland , Marc Zyngier , Nick Desaulniers , Jann Horn , Miguel Ojeda , Masahiro Yamada , clang-built-linux@googlegroups.com, kernel-hardening@lists.openwall.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Sami Tolvanen Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Ard Biesheuvel Register x18 will no longer be used as a caller save register in the future, so stop using it in the copy_page() code. Link: https://patchwork.kernel.org/patch/9836869/ Signed-off-by: Ard Biesheuvel [Sami: changed the offset and bias to be explicit] Signed-off-by: Sami Tolvanen Reviewed-by: Mark Rutland --- arch/arm64/lib/copy_page.S | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) -- 2.24.0.rc1.363.gb1bccd3e3d-goog diff --git a/arch/arm64/lib/copy_page.S b/arch/arm64/lib/copy_page.S index bbb8562396af..290dd3c5266c 100644 --- a/arch/arm64/lib/copy_page.S +++ b/arch/arm64/lib/copy_page.S @@ -34,45 +34,45 @@ alternative_else_nop_endif ldp x14, x15, [x1, #96] ldp x16, x17, [x1, #112] - mov x18, #(PAGE_SIZE - 128) + add x0, x0, #256 add x1, x1, #128 1: - subs x18, x18, #128 + tst x0, #(PAGE_SIZE - 1) alternative_if ARM64_HAS_NO_HW_PREFETCH prfm pldl1strm, [x1, #384] alternative_else_nop_endif - stnp x2, x3, [x0] + stnp x2, x3, [x0, #-256] ldp x2, x3, [x1] - stnp x4, x5, [x0, #16] + stnp x4, x5, [x0, #16 - 256] ldp x4, x5, [x1, #16] - stnp x6, x7, [x0, #32] + stnp x6, x7, [x0, #32 - 256] ldp x6, x7, [x1, #32] - stnp x8, x9, [x0, #48] + stnp x8, x9, [x0, #48 - 256] ldp x8, x9, [x1, #48] - stnp x10, x11, [x0, #64] + stnp x10, x11, [x0, #64 - 256] ldp x10, x11, [x1, #64] - stnp x12, x13, [x0, #80] + stnp x12, x13, [x0, #80 - 256] ldp x12, x13, [x1, #80] - stnp x14, x15, [x0, #96] + stnp x14, x15, [x0, #96 - 256] ldp x14, x15, [x1, #96] - stnp x16, x17, [x0, #112] + stnp x16, x17, [x0, #112 - 256] ldp x16, x17, [x1, #112] add x0, x0, #128 add x1, x1, #128 - b.gt 1b + b.ne 1b - stnp x2, x3, [x0] - stnp x4, x5, [x0, #16] - stnp x6, x7, [x0, #32] - stnp x8, x9, [x0, #48] - stnp x10, x11, [x0, #64] - stnp x12, x13, [x0, #80] - stnp x14, x15, [x0, #96] - stnp x16, x17, [x0, #112] + stnp x2, x3, [x0, #-256] + stnp x4, x5, [x0, #16 - 256] + stnp x6, x7, [x0, #32 - 256] + stnp x8, x9, [x0, #48 - 256] + stnp x10, x11, [x0, #64 - 256] + stnp x12, x13, [x0, #80 - 256] + stnp x14, x15, [x0, #96 - 256] + stnp x16, x17, [x0, #112 - 256] ret ENDPROC(copy_page) From patchwork Tue Nov 5 23:55:57 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sami Tolvanen X-Patchwork-Id: 178579 Delivered-To: patch@linaro.org Received: by 2002:a92:38d5:0:0:0:0:0 with SMTP id g82csp1464314ilf; Tue, 5 Nov 2019 15:57:22 -0800 (PST) X-Google-Smtp-Source: APXvYqw8gBlcJnD+fCOZTgsuP4tUxuVy1t6MhzwHKCiwAl+RciSK02SrpDWs7vFe/C/MoAsInQM3 X-Received: by 2002:a17:906:411:: with SMTP id d17mr30855800eja.299.1572998242017; Tue, 05 Nov 2019 15:57:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1572998242; cv=none; d=google.com; s=arc-20160816; b=D7NA/R58JcfVzbBFWhO5hANF3Bff/4bKnLEw7eB09b3ZqxGPqa1eGF9TAcOM51z9zD 6Y1sbQZwMedxUp4pxE3LFqfYRpGC8FlnJtzznECRq8i5MJW9wG5yfdfLbAZBnj1uTN/X ixJ1UMqPyLByROnUmZfqHH7MSpiahZ7n8oHl48TpwNp4cHOVEBCUmkoT7InmL+u0A6Cv DYxpWK3VVLt6k8r5KtmZRF87qbazp91ijPLKvvnX9+4jKWf8L1pvDJCMfwD5JNja63hF aLAFDvMfmI6buVIySxie2Z/uhAd6xw9fClC+TfwaTUn2xsbknDuuA/TBqh4jg4gQpcTC VC3Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:from:subject:references :mime-version:message-id:in-reply-to:date:dkim-signature; bh=dHd2oAd25v1QFamm49bKYnI+SDWrPmb9Vs4EgTfDEXk=; b=uw6dx6swyqhWLTCt7NGtXuopV0Jd7zw8BOa7EqOfSpeBZwnHDOm8XRRMxIQe4mLxu6 B+kojRmvHTvlWOIX1NJ7cYwLsi0EADiypsBmljOMWGzbK7roBCPghy5co7tmPXlRWieZ FE+WLXA0ypog6RQAl4ud3ctEi+3wB+mG7w7yBh4yHycGMJ/wKDAAcD58YHsurUPsYNEm I5HuL1qrm+gZ3EHRyn3FNZuttoiYBcnKG0zTAo2yG2SgnJoMggUFuBfE71wfFgrN2IdF +jmCsihdtJ7J+OgmotHnExjQr2lJBoHXbDJ2FIUo5HwDQfBOYYwmljrAAEfSmuAy3Wzy UkQA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=bDliSoyY; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k22si8852839eji.282.2019.11.05.15.57.14; Tue, 05 Nov 2019 15:57:22 -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; dkim=pass header.i=@google.com header.s=20161025 header.b=bDliSoyY; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730755AbfKEX5N (ORCPT + 26 others); Tue, 5 Nov 2019 18:57:13 -0500 Received: from mail-pf1-f201.google.com ([209.85.210.201]:53189 "EHLO mail-pf1-f201.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730576AbfKEX4Y (ORCPT ); Tue, 5 Nov 2019 18:56:24 -0500 Received: by mail-pf1-f201.google.com with SMTP id 20so17467264pfp.19 for ; Tue, 05 Nov 2019 15:56:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=dHd2oAd25v1QFamm49bKYnI+SDWrPmb9Vs4EgTfDEXk=; b=bDliSoyYGxx43rEjkFDy5V4ntr7XfyvBRO13dbvsBo0S8JQUy+CqxbLaHNdLfREnCw a0I8taTdiam8ApYbUculPMioDAysaU8DW84rQmV6vlUONLQUEhV8wGdC9CtCyCEtcyXZ zFMpPoI1eGpbZbiga1Th/X377A0R2Az7nA63db6p9Ay7zYwET083itnXUljV0iaN0/Qz 3izH+/Yw9gDCV9sWl9Wgc4I4gMwOn+2k1tVCgkrd6MAFSPLlao809xh49sSGLtt0qEy2 S+2sqJnqZhdClVXEacu79v4G5BJbF1/6V1tkhH9qEzhiNW9ETU59eVlVQfWrcC5/QOpD IKUA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=dHd2oAd25v1QFamm49bKYnI+SDWrPmb9Vs4EgTfDEXk=; b=gxV282kpn/mVKsdqdRE5Ak90QExloHl3yXniOFiguzEJK0+b/m/tUIjU+FcdXbW0Za mdxI45ke3r9LpiOvVGObu/fEXdS4L/qcV96r9wKEoe4aPKF2bHyN5zT7epgFnSRsg8sE xeyLUEE1yR8kiqsNd/zf/ndZTe7r7z2sENnOP4TiO4iPhiUi6l6XDW5gsgZoBVwGWrA3 SVrsXwFfkUyPsXPTSwQhssiqXkst01iEkycDDN2nGXvDmQsL/giarbLrn3YKiA7ayhn2 IQqqvX8uTvV6EvuonWcRmV1lrLS+lZQVpuslO6SOrq7QhExPDmDCJzYx5IXQEjQ1yO/K BjcQ== X-Gm-Message-State: APjAAAVJayFmd2+uultC9gJ5vtXJFc/ywqCMo1N1OTZKSkjoBC/UGUSH YVL93R1Buu3ILA5Q7NWSDg9ifzLNgppVTO8veY0= X-Received: by 2002:a63:750f:: with SMTP id q15mr14598354pgc.422.1572998183307; Tue, 05 Nov 2019 15:56:23 -0800 (PST) Date: Tue, 5 Nov 2019 15:55:57 -0800 In-Reply-To: <20191105235608.107702-1-samitolvanen@google.com> Message-Id: <20191105235608.107702-4-samitolvanen@google.com> Mime-Version: 1.0 References: <20191018161033.261971-1-samitolvanen@google.com> <20191105235608.107702-1-samitolvanen@google.com> X-Mailer: git-send-email 2.24.0.rc1.363.gb1bccd3e3d-goog Subject: [PATCH v5 03/14] arm64: kvm: stop treating register x18 as caller save From: Sami Tolvanen To: Will Deacon , Catalin Marinas , Steven Rostedt , Masami Hiramatsu , Ard Biesheuvel Cc: Dave Martin , Kees Cook , Laura Abbott , Mark Rutland , Marc Zyngier , Nick Desaulniers , Jann Horn , Miguel Ojeda , Masahiro Yamada , clang-built-linux@googlegroups.com, kernel-hardening@lists.openwall.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Sami Tolvanen Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Ard Biesheuvel In preparation of reserving x18, 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. Link: https://patchwork.kernel.org/patch/9836891/ Signed-off-by: Ard Biesheuvel [Sami: updated commit message, switched from x18 to x29 for the guest context] Signed-off-by: Sami Tolvanen Reviewed-by: Kees Cook Reviewed-by: Marc Zyngier Reviewed-by: Mark Rutland --- arch/arm64/kvm/hyp/entry.S | 45 ++++++++++++++++++++------------------ 1 file changed, 24 insertions(+), 21 deletions(-) -- 2.24.0.rc1.363.gb1bccd3e3d-goog diff --git a/arch/arm64/kvm/hyp/entry.S b/arch/arm64/kvm/hyp/entry.S index e5cc8d66bf53..0c6832ec52b1 100644 --- a/arch/arm64/kvm/hyp/entry.S +++ b/arch/arm64/kvm/hyp/entry.S @@ -22,7 +22,12 @@ .text .pushsection .hyp.text, "ax" +/* + * We treat x18 as callee-saved as the host may use it as a platform + * register (e.g. for shadow call stack). + */ .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)] @@ -32,6 +37,8 @@ .endm .macro restore_callee_saved_regs ctxt + // We require \ctxt is not x18-x28 + ldr x18, [\ctxt, #CPU_XREG_OFFSET(18)] ldp x19, x20, [\ctxt, #CPU_XREG_OFFSET(19)] ldp x21, x22, [\ctxt, #CPU_XREG_OFFSET(21)] ldp x23, x24, [\ctxt, #CPU_XREG_OFFSET(23)] @@ -48,7 +55,7 @@ ENTRY(__guest_enter) // x0: vcpu // x1: host context // x2-x17: clobbered by macros - // x18: guest context + // x29: guest context // Store the host regs save_callee_saved_regs x1 @@ -67,31 +74,28 @@ alternative_else_nop_endif ret 1: - add x18, x0, #VCPU_CONTEXT + add x29, x0, #VCPU_CONTEXT // Macro ptrauth_switch_to_guest format: // ptrauth_switch_to_guest(guest cxt, tmp1, tmp2, tmp3) // The below macro to restore guest keys is not implemented in C code // as it may cause Pointer Authentication key signing mismatch errors // when this feature is enabled for kernel code. - ptrauth_switch_to_guest x18, x0, x1, x2 + ptrauth_switch_to_guest x29, x0, x1, x2 // Restore guest regs x0-x17 - ldp x0, x1, [x18, #CPU_XREG_OFFSET(0)] - ldp x2, x3, [x18, #CPU_XREG_OFFSET(2)] - ldp x4, x5, [x18, #CPU_XREG_OFFSET(4)] - ldp x6, x7, [x18, #CPU_XREG_OFFSET(6)] - ldp x8, x9, [x18, #CPU_XREG_OFFSET(8)] - ldp x10, x11, [x18, #CPU_XREG_OFFSET(10)] - ldp x12, x13, [x18, #CPU_XREG_OFFSET(12)] - ldp x14, x15, [x18, #CPU_XREG_OFFSET(14)] - ldp x16, x17, [x18, #CPU_XREG_OFFSET(16)] - - // Restore guest regs x19-x29, lr - restore_callee_saved_regs x18 - - // Restore guest reg x18 - ldr x18, [x18, #CPU_XREG_OFFSET(18)] + ldp x0, x1, [x29, #CPU_XREG_OFFSET(0)] + ldp x2, x3, [x29, #CPU_XREG_OFFSET(2)] + ldp x4, x5, [x29, #CPU_XREG_OFFSET(4)] + ldp x6, x7, [x29, #CPU_XREG_OFFSET(6)] + ldp x8, x9, [x29, #CPU_XREG_OFFSET(8)] + ldp x10, x11, [x29, #CPU_XREG_OFFSET(10)] + ldp x12, x13, [x29, #CPU_XREG_OFFSET(12)] + ldp x14, x15, [x29, #CPU_XREG_OFFSET(14)] + ldp x16, x17, [x29, #CPU_XREG_OFFSET(16)] + + // Restore guest regs x18-x29, lr + restore_callee_saved_regs x29 // Do not touch any register after this! eret @@ -114,7 +118,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)] @@ -123,9 +127,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 get_host_ctxt x2, x3 From patchwork Tue Nov 5 23:55:58 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sami Tolvanen X-Patchwork-Id: 178577 Delivered-To: patch@linaro.org Received: by 2002:a92:38d5:0:0:0:0:0 with SMTP id g82csp1463546ilf; Tue, 5 Nov 2019 15:56:30 -0800 (PST) X-Google-Smtp-Source: APXvYqxNxxqI2alIM7Z2dZyjsXllhtPOYTv0bziqvOf763OzeMATnok9IpDaEQ1VMYP6Ihz5Y/GJ X-Received: by 2002:a50:fe96:: with SMTP id d22mr39573669edt.227.1572998189941; Tue, 05 Nov 2019 15:56:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1572998189; cv=none; d=google.com; s=arc-20160816; b=eD7uuu/zAhcSiJRZxIl2zv52kckM40N5CK93B3xPyk/ml6InCxd/pCZpwdifVUOQL4 jM5zPcb1muTLEDFJEav1p+35dqLJduiR86PVzGVR3dVE0lhGBn8gDLEkhzwAK76ib2Jy dLPR0kAcaeYjWnH08wZJUg+DRJyvdB1Qfdy9Oq1WPf/FCCl3tWusKQ876y9AcZ5B/L+B EGx03MvnAxiXpU3enPmLi0Dc4pRD31n5mnoSY3quDywj0OEFXAcuZ3TdUBAt+Rr7BtMa LHeBr0ClgnkxCnG2GDTukkoJzm0a97kH06ljsTYbpgqK/Hkteuc5wHDbdICLjhpXYGFY ea6w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:from:subject:references :mime-version:message-id:in-reply-to:date:dkim-signature; bh=E806Ihq7Qr5kwAxZ8O8jq/5GK0i44oON304BuEfvZ08=; b=e/n4Wpyy96Hes+rVQe/owfC7jDAIyEW5l+JeB1NIk3U2KliQtHosWYvHSnrdLUyuVw 3irG+1CbUQFDyY3bHYMJ6d1Hdk+xqmwxJu6yJG+Wky1jL1TrmciIOn/qVj+3/5wFXbW3 DnR0olat2RfKvwu89kB0Y4cwtNh5gg5LRqDK6QZtbhhGbhIX6vlCL92Wn1cDeAI9QbDo vnZF4Gn/TTgXV4s/sZ9khpd+AC8KDxl1gPMV9336BBbHV7IFw80ZSE4l/Bz3BQalTjOo vfwRCTd0QBe5bmDbkNrurkPelFhN3MlXQqmHdC8svPRoT88GkvYiIwFbh9e/ospP/pKS OLaA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=QDgKQccA; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l8si15194537ejr.125.2019.11.05.15.56.29; Tue, 05 Nov 2019 15:56:29 -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; dkim=pass header.i=@google.com header.s=20161025 header.b=QDgKQccA; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730679AbfKEX42 (ORCPT + 26 others); Tue, 5 Nov 2019 18:56:28 -0500 Received: from mail-qt1-f202.google.com ([209.85.160.202]:55933 "EHLO mail-qt1-f202.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730579AbfKEX41 (ORCPT ); Tue, 5 Nov 2019 18:56:27 -0500 Received: by mail-qt1-f202.google.com with SMTP id u23so24225651qtb.22 for ; Tue, 05 Nov 2019 15:56:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=E806Ihq7Qr5kwAxZ8O8jq/5GK0i44oON304BuEfvZ08=; b=QDgKQccAQsH+R5h45PS8H6bNgjwH8RGSJOkAG/AGuoy5YWBicw4QukLKRyaCj/ZX4C S4zge4BSm47qikuijSk/1DeLDJdEzJKyjjpMkCVFyBe8iRT+BVtRIzaIEOM4Sg8kMqqp 19PNx89unPNFUWHLbXlCN0veqqqj3T/UMrnqvSODWT2d26uSn9YoutJHq9olqlmfvgF9 quHA5kvZggYfAPkKhiPNj+ueCkFnNP+twN85T1uWZaZ2Qu7624dIYDxVRZ2i6SnFYV+M zMwC8p5EGVUt8lQAk9+5QoxNLcfzBFJJ4Q7ld+hIBbOPsyda1IzIoSUjKf8hfnCm4zFw faOg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=E806Ihq7Qr5kwAxZ8O8jq/5GK0i44oON304BuEfvZ08=; b=KDaaHpjqn0eo66FEnhZbH0C3dKP1BVw++RMdFvmLUAe1g0AIJWviZlnVjoaNmG7kzV TRQw4MWTk1MhpcpIF0ZC0jM3sFp2aTZVwtV2QRpazwb9rvLNjM5mOAPK9IU0F1JBzsFB h4LR/on7QRYI4aTGTnlJQ412TrKxZ/SzkT7Vp4XI9ZhIXVUGrjKvcutxPQkoTudPaePx Ml1XYBsHbkkmihr3jJ/U2Yh1Gj3HhtruRM6jtIakMkAsyCUi8XPr0U6Yy1ae/gVDDxMY iXq9X60vM07Ax2Isxv6gk2GsV8JDOeH7qvNO/+78KLH6xf9wxEODeiffjkD8vFZrqLoj MZtQ== X-Gm-Message-State: APjAAAVvhgBXl9lQjMsniO7fBbXmjshQFt44PTLyieRcIPH7KygXBs7P +l36mQmXrg3ZzvYhn5Xo4nyan8Ve6RFxqqTfmgk= X-Received: by 2002:aed:22c8:: with SMTP id q8mr21652726qtc.0.1572998186120; Tue, 05 Nov 2019 15:56:26 -0800 (PST) Date: Tue, 5 Nov 2019 15:55:58 -0800 In-Reply-To: <20191105235608.107702-1-samitolvanen@google.com> Message-Id: <20191105235608.107702-5-samitolvanen@google.com> Mime-Version: 1.0 References: <20191018161033.261971-1-samitolvanen@google.com> <20191105235608.107702-1-samitolvanen@google.com> X-Mailer: git-send-email 2.24.0.rc1.363.gb1bccd3e3d-goog Subject: [PATCH v5 04/14] arm64: kernel: avoid x18 in __cpu_soft_restart From: Sami Tolvanen To: Will Deacon , Catalin Marinas , Steven Rostedt , Masami Hiramatsu , Ard Biesheuvel Cc: Dave Martin , Kees Cook , Laura Abbott , Mark Rutland , Marc Zyngier , Nick Desaulniers , Jann Horn , Miguel Ojeda , Masahiro Yamada , clang-built-linux@googlegroups.com, kernel-hardening@lists.openwall.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Sami Tolvanen Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Ard Biesheuvel The code in __cpu_soft_restart() uses x18 as an arbitrary temp register, which will shortly be disallowed. So use x8 instead. Link: https://patchwork.kernel.org/patch/9836877/ Signed-off-by: Ard Biesheuvel [Sami: updated commit message] Signed-off-by: Sami Tolvanen Reviewed-by: Mark Rutland Reviewed-by: Kees Cook --- arch/arm64/kernel/cpu-reset.S | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) -- 2.24.0.rc1.363.gb1bccd3e3d-goog diff --git a/arch/arm64/kernel/cpu-reset.S b/arch/arm64/kernel/cpu-reset.S index 6ea337d464c4..32c7bf858dd9 100644 --- a/arch/arm64/kernel/cpu-reset.S +++ b/arch/arm64/kernel/cpu-reset.S @@ -42,11 +42,11 @@ ENTRY(__cpu_soft_restart) mov x0, #HVC_SOFT_RESTART hvc #0 // no return -1: mov x18, x1 // entry +1: mov x8, x1 // entry mov x0, x2 // arg0 mov x1, x3 // arg1 mov x2, x4 // arg2 - br x18 + br x8 ENDPROC(__cpu_soft_restart) .popsection