From patchwork Fri Nov 1 22:11:35 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sami Tolvanen X-Patchwork-Id: 178339 Delivered-To: patch@linaro.org Received: by 2002:a92:409a:0:0:0:0:0 with SMTP id d26csp1101227ill; Fri, 1 Nov 2019 15:12:04 -0700 (PDT) X-Google-Smtp-Source: APXvYqxzrLuc8Rbq33w7KSa9YciPe5uuWse0TRf2AENKwVJ1IionUqLCTPGUMmK0qWWXmvoQhLv/ X-Received: by 2002:a50:a695:: with SMTP id e21mr15451670edc.39.1572646324783; Fri, 01 Nov 2019 15:12:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1572646324; cv=none; d=google.com; s=arc-20160816; b=duIv5u61eiMScVBB+TZNbU0M/yVTxmMa+28/NFQJvEs7BDMbpRyW7FwEhll6ZtkHIS HkJ6ijJ+YXaDaZatqmCzW2kxSTu9PLARpsXEnTg9bHvMiuvhgJoX6ofoYZDcp9533Bt/ 849v1KK3DqTtfKjO+RATLkoRwiNe/MHs2GBROjQCyKVMgnJBFq3M42vvHZ7MJ7qG07pB 9JCuZn0Qko1rRCLrUVqkaNrNE7zN6/iBJi97w7hFbSKwLrw+N2vrr/rMAvIDMe938GVr swlhnVrfWX/W5xDWjfyw0lMhZQfuExiqe3dTyPN6Zh9BGR0u88bGscorJl86f1+LrDaK wHaQ== 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=P6+pLmlKjSTP6//IxIk68+JxjjIs1AKzbseVfP+Dv8K/sN8R3tYXMY91s5rrF9hDg9 5jrzN1MGqqZ9xjq3xEITAbXa9ZeUAbPf1mMojkG0mp1cM1KVigIvKtIGxK6ah64ByE/d 2r3AMDQHq24t5NhENH36j+hs72wm6GQ/CHb97Ai7BK+vGYQRbbg/18x5heh0c2TwKhVu 0Rm4IZdzHZLKfJna9R+u2gujseRIDhvDmAfXM2Jdhqqmak/8lrl6MxUWE7QchJBlrF9j Cg0ub4IGYaNnJY6FNGRg+WZ6/cLHkr0UlqJ6O0WtnaitTokUiQaIJLg8EnB3nPQKfAbN BYkA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=Q0ypX2RR; 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 m17si6766611eja.415.2019.11.01.15.12.04; Fri, 01 Nov 2019 15:12:04 -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=@google.com header.s=20161025 header.b=Q0ypX2RR; 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 S1727654AbfKAWMD (ORCPT + 26 others); Fri, 1 Nov 2019 18:12:03 -0400 Received: from mail-pg1-f202.google.com ([209.85.215.202]:33621 "EHLO mail-pg1-f202.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726710AbfKAWMA (ORCPT ); Fri, 1 Nov 2019 18:12:00 -0400 Received: by mail-pg1-f202.google.com with SMTP id b71so8055209pga.0 for ; Fri, 01 Nov 2019 15:12:00 -0700 (PDT) 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=Q0ypX2RRPc9BCIL2STVCLvfQgO8tit2Vbhk/ba4d6hjxn/SWRm9m0P3+RgrNT2Mz6L sR+GG/DQFJrsOpiRvBMZe/oQtxBn0b/Aw4IaKtUdtT9BIZjbq98xY+73BjaIsIx8Adyg M5/Y6BEGGBeU1F0DiCWwVE0YrYEJUkeeSdYpDOR4oINiHvrg4NRPL6mRj2HcLoQWQnuD PYDoVjgxtSwP/n5hXyxm9HZngM/5zcLb8ANWcQjpR6xl/qqaKAenvDZks2pyB05/I9H1 +gQ/L2rTv3QAg1ciPxxnHi9CW/af4LKSwTNtbc9o4woUjjbzkrkmW3ha88Kih8MYyqXD oGUQ== 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=NsUqvKVzK9DpiyQEqQnt0ST8QQL99mB5yDfgS0tA0MgbTNEQVu4+AP2zr26m04Wwci dijPlQXddchyaXVW5+y8PgI7jI6znI3p/oMoxCESnMM1kRtOGiyaQsWiZXEeOF6gF/nX RFv62I/+XeLkf/LG65qdFYdN/Zf2t6xPrbr9OGLJE9znksbmadfJeUd6yXuPlPTga2Py 9LE2Qvp4C3G8/cEf7xekmvSuoym3VZFgNDESih4QJqypfnx8v0pf7xF4dPfmpkUMPj0w gE9Tjoukyn5fk7tjQSV8fPZanBMDHCkOrBSQ1o5F0yoxcRoDrbuqLiSzj5M+R9wRddFB IAew== X-Gm-Message-State: APjAAAVUF6UNTj+pr0Rk3otJbz8j0URwKo9eBrmsEPGUmAm8wg2FnxDK XaxuVTGkT7+1E7gfru5NWBAJ0aWnASRJ/9wFlLs= X-Received: by 2002:a63:e454:: with SMTP id i20mr15822954pgk.319.1572646319823; Fri, 01 Nov 2019 15:11:59 -0700 (PDT) Date: Fri, 1 Nov 2019 15:11:35 -0700 In-Reply-To: <20191101221150.116536-1-samitolvanen@google.com> Message-Id: <20191101221150.116536-3-samitolvanen@google.com> Mime-Version: 1.0 References: <20191018161033.261971-1-samitolvanen@google.com> <20191101221150.116536-1-samitolvanen@google.com> X-Mailer: git-send-email 2.24.0.rc1.363.gb1bccd3e3d-goog Subject: [PATCH v4 02/17] 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 Fri Nov 1 22:11:36 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sami Tolvanen X-Patchwork-Id: 178340 Delivered-To: patch@linaro.org Received: by 2002:a92:409a:0:0:0:0:0 with SMTP id d26csp1101258ill; Fri, 1 Nov 2019 15:12:07 -0700 (PDT) X-Google-Smtp-Source: APXvYqzsZHvau3bUsJPjaJyS9zAraISm/3Hj/uJDvM0Rfv/062yVAaOHOUQVP3mxWpzgglRUqaUt X-Received: by 2002:a17:906:3501:: with SMTP id r1mr11694456eja.301.1572646327348; Fri, 01 Nov 2019 15:12:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1572646327; cv=none; d=google.com; s=arc-20160816; b=HcbHMeYoLeFmkAxoEZbrfilTJgTMqBQo64gZedSu5cMe/5zT/gaMoCZ1sUAtxxrZxx hwNlUSQ80FAbzlh7IVgRPENUz299T4bcp1KXH+OjJ6gmDrG/tDZSQ/QngIupCRAY09Tz z0psfhJGF0s80loA65ImPkCYPL63VG9oAAxDMxIc1RkWMdTIkSUvTQXfa3qPGqex/lke Ohy/BB0ZHzgpFquPglF0REEYPwFE1uLrw/HvcHZ62oyh3ahtP2ZBBsR1G/ebzI33B9Fr Xf7oC9K/r9N0sXsoCDMA+2n3T6E/8p/YsCqxC46aNndNAP9yYJCpn/LC8wMAdMICfB2N dGyA== 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=LP5ER91yDYZoiG1DiO5iJutGGta/8W2YsIEILYrERFw=; b=VRxEaP2X4WqkiKeiEqy7cxjlPokoxW1qvo+i4jbVrJi4xK9FP3x9rTOVP3kWVWeofo C4lP6ontV3jAQLk+LWxuX1L7Oct92t+6IdBs1Mxq6gd3MfmZOxIVXAD33h3Cdte9Y0fH DIyb7C0EhfUZfV3Lh9HLP8VoWZ2PQdh1eIeIkzMWQCZn020kcix+gVD8MruGFZV0QAbW lEizz2wFcBO4ENDxVkxfARgNkw2Sd12aEcaIFwIoZAstUNRFs71m5igL8bhtWclmjwsi vFWi2F6Q/PqU0iyvNWcznKxIrPgY0qFcd8EI1wCdkM3Y2jFZRkDr0BobGf0qvJzz+gDS zFLg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=bzUzyeY2; 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 m17si6766611eja.415.2019.11.01.15.12.07; Fri, 01 Nov 2019 15:12:07 -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=@google.com header.s=20161025 header.b=bzUzyeY2; 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 S1727315AbfKAWMG (ORCPT + 26 others); Fri, 1 Nov 2019 18:12:06 -0400 Received: from mail-pf1-f202.google.com ([209.85.210.202]:47679 "EHLO mail-pf1-f202.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727653AbfKAWMD (ORCPT ); Fri, 1 Nov 2019 18:12:03 -0400 Received: by mail-pf1-f202.google.com with SMTP id i6so8428579pfd.14 for ; Fri, 01 Nov 2019 15:12:03 -0700 (PDT) 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=LP5ER91yDYZoiG1DiO5iJutGGta/8W2YsIEILYrERFw=; b=bzUzyeY2Pb66Afq/YuWOrvYc+P88+Nov5leW00IV55yTXjsAAsOwV4Veo8X/xOJcJ4 ondoceMK37epaHyC4iXnp3iV0xW9o37xNMNCS5+YnzUPDYInCBHdGEQVAgM4EFYIvsze U0KH0R+6LV4HKtRGQKKP/z9BhLOXnUh8+dXJh8b3NCoa0aWnVe395JzHp4ESMni67Vsa qx0mjSBtsBjrh+oThuzhLBL/bX8C2DLD9Oj+4ukb7J9N50N4TT7aG68H5rehFDpazui3 jPyL0/ZCDdN1GkSNCkwcVAq/qh9aaSMW7e8c/YGajhmaqVmrnJc5oqhERJW4y1q7jziQ Z3bw== 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=LP5ER91yDYZoiG1DiO5iJutGGta/8W2YsIEILYrERFw=; b=g5VLJx4642/yDt7RWVMWAlh7D/VEqVHOHfwv901ppyrtUj7wOuDk5z3fDdh7E1Tzm6 mCExxh0CGWCrkwuAw1KvUQPJH9W5A1CKIlBBiEAbQkej3fPKQjYXYiFqJ93t1HXOasOs mugGw6nhDe6z1KLOW+VJdh00s5u20eOT6QnqtFtsUffACKCAlFSaTwWgN4I0eEAK2Rpj R677wB2H9sv2Oe0WsYI57/VWWlbfK4YoMots/x1hqRpk3KufGyzBZ+rVVJYYd8kJUaBg X+OTK5r3MRkJAwzFukJ0DRq1ysLZTCO5Qn9PheKhTfJBiWTPL/j+hPQYtPZH6kpob3dL Mjow== X-Gm-Message-State: APjAAAX27Ds8UNwnJ1gVbj93Jj0TEwZZH8GT6ujkHOnijm3fvULdSfmh s87Up8ED+nj626UgKKAC4JzevwxeJvhnVAfeTdE= X-Received: by 2002:a63:535c:: with SMTP id t28mr6291818pgl.173.1572646322264; Fri, 01 Nov 2019 15:12:02 -0700 (PDT) Date: Fri, 1 Nov 2019 15:11:36 -0700 In-Reply-To: <20191101221150.116536-1-samitolvanen@google.com> Message-Id: <20191101221150.116536-4-samitolvanen@google.com> Mime-Version: 1.0 References: <20191018161033.261971-1-samitolvanen@google.com> <20191101221150.116536-1-samitolvanen@google.com> X-Mailer: git-send-email 2.24.0.rc1.363.gb1bccd3e3d-goog Subject: [PATCH v4 03/17] 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 --- arch/arm64/kvm/hyp/entry.S | 41 +++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 21 deletions(-) -- 2.24.0.rc1.363.gb1bccd3e3d-goog Reviewed-by: Marc Zyngier Reviewed-by: Mark Rutland Reviewed-by: Marc Zyngier diff --git a/arch/arm64/kvm/hyp/entry.S b/arch/arm64/kvm/hyp/entry.S index e5cc8d66bf53..c3c2d842c609 100644 --- a/arch/arm64/kvm/hyp/entry.S +++ b/arch/arm64/kvm/hyp/entry.S @@ -23,6 +23,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)] @@ -32,6 +33,8 @@ .endm .macro restore_callee_saved_regs ctxt + // We assume \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 +51,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 +70,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 +114,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 +123,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 Fri Nov 1 22:11:37 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sami Tolvanen X-Patchwork-Id: 178341 Delivered-To: patch@linaro.org Received: by 2002:a92:409a:0:0:0:0:0 with SMTP id d26csp1101384ill; Fri, 1 Nov 2019 15:12:14 -0700 (PDT) X-Google-Smtp-Source: APXvYqySS8FlL4sLvilTH6magJA59eG/Pz0bulUVS0eppes5sHruezjVmXjBnO48ekLVfC8bNyDo X-Received: by 2002:a17:906:cc94:: with SMTP id oq20mr12345748ejb.263.1572646333894; Fri, 01 Nov 2019 15:12:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1572646333; cv=none; d=google.com; s=arc-20160816; b=yikvL6RJYPwoD6+I/Xy7WEFqoFmplV7r5z36nHc1N9Sx9whDnfVSIVAjSbswN0LbFe q0lBsGGbapcYBl1/nHGr2RKI7SY9b7BaOZcJ7YjLa8psoiMTYdOcXAkpLzRSpMRIzlXU lJsM5Ccbo2XfdGZDNzpuxYDBVq8h8tsU5uCsOaJWnxtV8EDfWn0UyTYyAYQJ6bh6TriU VFj5QipN9786QNP3Fz6jMdqhb5DTMAzJ9JFsH6NxtL5g5o9ZgvMrWZa5a+KoKvyTmcDf v+8AZIKZfk+YoFMOZVvewvZIIOh92ngfLuPW9K5AtXd4fL7fJdITIf8v4cTSpJvsLfq5 sSDA== 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=wnRmFVoT2v0BTdhwPoMM6MSaqT9A+tRVbNViynKqlCbFcJL/PIATIHoIePkdJkusaR I5nb1duNgu68reVF8zA1cURE2yG2FLHu+EmWXfRHbIHmIHTbU+NjQ8VxIQ/Qg+ExWObl T/WcxVTNGaPPsBuCOdFL3u3pFif+H/iO1wEExn3cLG5U52+QDk71HufxB3VTr7ebchfC JvA/GVfIbuDxDHR9Gt9QJi/pcx+lEmWYtx8tsn8sPrpc80tPubmgZ/rndM7QYqUXZHyO 9QImp6sLQDOQNKhMpWthztnYFlGkKMAvvNdD0GstoCETil+osoNIFM/q6G1vh6+kCr6/ ucNw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=q3YTCGLY; 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 y51si1483309edb.29.2019.11.01.15.12.13; Fri, 01 Nov 2019 15:12:13 -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=@google.com header.s=20161025 header.b=q3YTCGLY; 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 S1727747AbfKAWMI (ORCPT + 26 others); Fri, 1 Nov 2019 18:12:08 -0400 Received: from mail-pl1-f202.google.com ([209.85.214.202]:34547 "EHLO mail-pl1-f202.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727673AbfKAWMG (ORCPT ); Fri, 1 Nov 2019 18:12:06 -0400 Received: by mail-pl1-f202.google.com with SMTP id u9so1472257plq.1 for ; Fri, 01 Nov 2019 15:12:06 -0700 (PDT) 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=q3YTCGLY4SwiQs7Dr523GbwXcyS1rOF4ePlC+I2FlqMLdM1nbvtx89eitGKg3+MPv/ /6kpVC7ib3nqYGqEvd/D7Aja0/Oqw9bqK4yY73IHHngPbb8yNTF80TsjwS3dip4BNdjJ vrTCQU+wyHKRY1+9qAAoEBJOivxjjzkaOrEGQr3vnrSW+SARMhsCk1i/tL9jdyhbVr9G N6J/wBNQprJN4QGbaP/iQ1MEafD71JFawBswZkK6umVAzs2YdsoYpup5A4o/8Tk1dVfR JqWRLp00wfY2sTSArmHg6PdT5yupXzlZUV+YXQhkWVfHN9eXitDPORweXPhbmCnVSWKB z5cQ== 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=CJn1m1Jc2+yNpKSwVYoleFM2cnyXzl677bJuAdpciC0ageWccfo1efBrx7bI3CjN4k kCh2ZClv5Q7AhLkuHWGQJb974bGWFDPfprFOx4Mg2sXxXmD1nlyT2ulEv+/biF+pyTl6 85WD3WJ+dkbZyhVZODET2j3SUaVZg87eanmf9kNfFLH5HZbIJquftWvDefIq66GrGpRE ha8INmGbtGLdE3HLYaEV+rZi+9qvCfTkOsKEXfNEHEYgJltzx1M/LIA8VtcYAyWE4inG M8dy07W5Y+P1kmMD6gHJaAjn15Acz1i1VUsqqvyQPXRfLjeUVzWzZe6lcVKq/IxcwV88 4NtQ== X-Gm-Message-State: APjAAAXW2z1mrT4vA2xY8pjNoEYZE23gVhz7cfph4yxIwgyzrF8VQ9WN 07APLN2aTLlgFhlq9+DTq6whey2xontb5aJOtUU= X-Received: by 2002:a63:7015:: with SMTP id l21mr14741976pgc.200.1572646325115; Fri, 01 Nov 2019 15:12:05 -0700 (PDT) Date: Fri, 1 Nov 2019 15:11:37 -0700 In-Reply-To: <20191101221150.116536-1-samitolvanen@google.com> Message-Id: <20191101221150.116536-5-samitolvanen@google.com> Mime-Version: 1.0 References: <20191018161033.261971-1-samitolvanen@google.com> <20191101221150.116536-1-samitolvanen@google.com> X-Mailer: git-send-email 2.24.0.rc1.363.gb1bccd3e3d-goog Subject: [PATCH v4 04/17] arm64: kernel: avoid x18 __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