Received: by 2002:a05:6a10:9afc:0:0:0:0 with SMTP id t28csp256486pxm; Tue, 22 Feb 2022 09:59:59 -0800 (PST) X-Google-Smtp-Source: ABdhPJwgJ/uGouQ9+Q9DAKAp/hp8Wa/XxcasnNecQBhwXeOvGvsDwb6ElXazuUsAOX1L8a2Ip14U X-Received: by 2002:a17:907:98a8:b0:6d0:e8ad:a801 with SMTP id ju8-20020a17090798a800b006d0e8ada801mr13360956ejc.433.1645552799256; Tue, 22 Feb 2022 09:59:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645552799; cv=none; d=google.com; s=arc-20160816; b=ti1ZWYPqC1lCGpae2p2wAS9lc270Gbutt0KGwYzHSpe+KlHwjVNYc4gXFOXRuNOBJO w/QwGi0x1BcXn3Q4456O+NYjTwtqMMbJTGqjxR4MtkPS+Xbl6ArWXQfibM3/uJ9E/Bju BrKz3BTpTvLUW2z70YzuvW2ZDt2F/vHRZdRg/N9SBz9aHzGP5i3c1NHduB0NhzeHEu8t +ZqIOH+NYb8UaKSt/P/4lGEQmXnbceMc6cRuRGEmOzcYOK+jqTY2xWPa0y9fC73gFirY 9RCm+dsQvxKkllYAyd8HWIxYGd2LDfnMob5zue6+aMFsgPNxZ7pxcvr+i+esDWFPe6G6 mQCg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:to:cc:from:subject:references:mime-version :message-id:in-reply-to:date:dkim-signature; bh=LdOkseL/SVBmCmTgjcnNq9QzVzqqoPlVFVsUav/JFK0=; b=HbZeqqexcRI1oNSVcXjXRNxT7rFlUA7uPWGr3h8fGjca3+3sXbGj/LQXzlhwgcVb4w oGkACqFWeEBBwUBIASCbrBYh1toqYNpqh/tyyMpugsDRJ9SOWT832MXm4HX8goGy4TbZ jH2KoCynzo0g/t62tBAHSn66jL90/GN1vsOp09CFRoSkN2vu/PX4oDBRfiKQ1tC07NdW EVW8pcCxPnhIyh62wvCrv/3i+4c6+SS3dy8O1jj7Kjs8w2SF+CqoyheHmMYB6gUx44dX 5EAPFTZ5hwVw2CcX5vbbZpdCX2RRlQMbeRyySbMxHYHlOsD24hEHE436cvOBPNc0KHpy v6PA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=FNoLI1yt; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d18si12691184edt.644.2022.02.22.09.59.36; Tue, 22 Feb 2022 09:59:59 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=FNoLI1yt; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S234035AbiBVQ6z (ORCPT + 99 others); Tue, 22 Feb 2022 11:58:55 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49644 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231211AbiBVQ6x (ORCPT ); Tue, 22 Feb 2022 11:58:53 -0500 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 481E116C4C4 for ; Tue, 22 Feb 2022 08:58:27 -0800 (PST) Received: by mail-yb1-xb4a.google.com with SMTP id i205-20020a2522d6000000b00622c778ac7cso24923379ybi.3 for ; Tue, 22 Feb 2022 08:58:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:cc; bh=LdOkseL/SVBmCmTgjcnNq9QzVzqqoPlVFVsUav/JFK0=; b=FNoLI1ytq66gPDfA9ohgBGXwe3ZXAMfQPU+vmETuazTxn1eRt4sfndjKQl5vNg1s6N aKsNQ+NyKz9hsu+jiKv0znYXLeJd3n/+di/bVx097otwKJ+Pm8qhNs67V2lcMqwTVhI1 wW9Xhb5tkIIU2yAp/NzXxghYQ+kMzgy+o2wG8PnfZAZIib9of+6+4qFBo+n7HfiKcBUT zgEVEI8Bx5lOplWa+VY0r+2kHSy9Bk1YC2Ipw+jivWuz7/saxNwcRLetDoqydMzCZ/+o DlsgOQQ986VSJnpFZSHCEQu861DTK2XF2rz2ttpajHfiMXQ90DWFxCmT05fG0qHlS8Nr E9dA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:cc; bh=LdOkseL/SVBmCmTgjcnNq9QzVzqqoPlVFVsUav/JFK0=; b=P5iEr0f8TTnbCkU9p3fC0NrZsPOvuP/tcgxLu7dXMMuTm7e+6s1fNbVfxs82gU/B8H sk0168bIWP1Jzg4/yxaKC5xkmFXQgrPJV11eTD/cVB11GXi0g4Gvvso9zkLf2u57ge43 utTntKwW4WHkVj6lr260XMvOyesN7H2fzpAVnKM53F8PyC+WdnKkeYQyxE2OiDfeClqv fUsFdZQCudLYvXSLdsbPKMFeaHL5HtMn32hr8LFQHgQRUXJ5xrJeF85oo6rNzfsCJjQO 0p0KXkOdTkau6A2e0/pD2QNWblUDacsODfhdfndHbThK11KrF3vws2pAuuH3r9Xov7iM /oBg== X-Gm-Message-State: AOAM530wnHpdhOsOq718ZP46ZPdULo83PRerX5xXTcwVuiaW8wSchdN+ ixTapr5qIwMop7UlI5rld3S/1whvFD2T82nPSw== X-Received: from kaleshsingh.mtv.corp.google.com ([2620:15c:211:200:5db7:1235:b3dd:cfcb]) (user=kaleshsingh job=sendgmr) by 2002:a81:b11:0:b0:2d7:3775:1eb9 with SMTP id 17-20020a810b11000000b002d737751eb9mr10900452ywl.99.1645549106468; Tue, 22 Feb 2022 08:58:26 -0800 (PST) Date: Tue, 22 Feb 2022 08:51:06 -0800 In-Reply-To: <20220222165212.2005066-1-kaleshsingh@google.com> Message-Id: <20220222165212.2005066-6-kaleshsingh@google.com> Mime-Version: 1.0 References: <20220222165212.2005066-1-kaleshsingh@google.com> X-Mailer: git-send-email 2.35.1.473.g83b2b277ed-goog Subject: [PATCH v2 5/9] arm64: asm: Introduce test_sp_overflow macro From: Kalesh Singh Cc: will@kernel.org, maz@kernel.org, qperret@google.com, tabba@google.com, surenb@google.com, kernel-team@android.com, Kalesh Singh , Catalin Marinas , James Morse , Alexandru Elisei , Suzuki K Poulose , Ard Biesheuvel , Mark Rutland , Pasha Tatashin , Joey Gouly , Peter Collingbourne , Andrew Scull , Paolo Bonzini , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, kvmarm@lists.cs.columbia.edu Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-8.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MISSING_HEADERS, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE, USER_IN_DEF_DKIM_WL autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net To: unlisted-recipients:; (no To-header on input) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Quentin Perret The asm entry code in the kernel uses a trick to check if VMAP'd stacks have overflowed by aligning them at THREAD_SHIFT * 2 granularity and checking the SP's THREAD_SHIFT bit. Protected KVM will soon make use of a similar trick to detect stack overflows, so factor out the asm code in a re-usable macro. Signed-off-by: Quentin Perret [Kalesh - Resolve minor conflicts] Signed-off-by: Kalesh Singh --- arch/arm64/include/asm/assembler.h | 11 +++++++++++ arch/arm64/kernel/entry.S | 7 +------ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/arch/arm64/include/asm/assembler.h b/arch/arm64/include/asm/assembler.h index e8bd0af0141c..ad40eb0eee83 100644 --- a/arch/arm64/include/asm/assembler.h +++ b/arch/arm64/include/asm/assembler.h @@ -850,4 +850,15 @@ alternative_endif #endif /* GNU_PROPERTY_AARCH64_FEATURE_1_DEFAULT */ +/* + * Test whether the SP has overflowed, without corrupting a GPR. + */ +.macro test_sp_overflow shift, label + add sp, sp, x0 // sp' = sp + x0 + sub x0, sp, x0 // x0' = sp' - x0 = (sp + x0) - x0 = sp + tbnz x0, #\shift, \label + sub x0, sp, x0 // x0'' = sp' - x0' = (sp + x0) - sp = x0 + sub sp, sp, x0 // sp'' = sp' - x0 = (sp + x0) - x0 = sp +.endm + #endif /* __ASM_ASSEMBLER_H */ diff --git a/arch/arm64/kernel/entry.S b/arch/arm64/kernel/entry.S index 772ec2ecf488..ce99ee30c77e 100644 --- a/arch/arm64/kernel/entry.S +++ b/arch/arm64/kernel/entry.S @@ -53,15 +53,10 @@ alternative_else_nop_endif sub sp, sp, #PT_REGS_SIZE #ifdef CONFIG_VMAP_STACK /* - * Test whether the SP has overflowed, without corrupting a GPR. * Task and IRQ stacks are aligned so that SP & (1 << THREAD_SHIFT) * should always be zero. */ - add sp, sp, x0 // sp' = sp + x0 - sub x0, sp, x0 // x0' = sp' - x0 = (sp + x0) - x0 = sp - tbnz x0, #THREAD_SHIFT, 0f - sub x0, sp, x0 // x0'' = sp' - x0' = (sp + x0) - sp = x0 - sub sp, sp, x0 // sp'' = sp' - x0 = (sp + x0) - x0 = sp + test_sp_overflow THREAD_SHIFT, 0f b el\el\ht\()_\regsize\()_\label 0: -- 2.35.1.473.g83b2b277ed-goog