Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp38198328rwd; Wed, 12 Jul 2023 04:38:58 -0700 (PDT) X-Google-Smtp-Source: APBJJlEYp22RW6IcdJZ39PE0VXas+QS7IEHX5FM8P/XeW0vDkixrhX1Qq56VRIE3wd1Foeh+TtYV X-Received: by 2002:a19:381a:0:b0:4f8:5905:8e0a with SMTP id f26-20020a19381a000000b004f859058e0amr12311657lfa.6.1689161938508; Wed, 12 Jul 2023 04:38:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689161938; cv=none; d=google.com; s=arc-20160816; b=UMoaSC1a4qvNHbxbTfDfzrLZQgErWwfR6DiXBTdfRiR0FxhmqBemqxLvdmEFXFzKrJ E7/hy1vyZxHu9rXORPb0odSflWbNGr0P4xhuyoo4QhYj2z34mb9z5yQbMHdH1I4tsWtO CjgUWAIPuWLLXmLDyPvM9dJLN7MhxkT8VZA3SMxBbj+dgqtbuFjCS8CcQz/jmwS/XKJq 8lgNyNugm38OagDxQvIKMZA6EivvZIqi/9BTLW4w3bOCg9XRyLpE204oCbT7QbIlV6Ia Yuv1h+tV7EVgujDM+KH4AR1B7g55X12JlcDZxht0g52u9cwcz8xJs1O+6rJ/shSlGyq9 uKdg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent:references:in-reply-to :subject:cc:to:from:message-id:date:dkim-signature; bh=jwPg1p6tStEORM+fPLy25RkDHkC7XlMPHcn7Sufdh8Q=; fh=elxNtc16L0r8Yr7IG+6NY/kKM/OC0TQ6JqfyPch2KfY=; b=EAOE8pzJE+RIofaF+P2WVdqDBWoVshadKSRAbCXX5RdJKJtPcaQBStgKpOOSceiCA6 HJHHQsinpgfmWWWRq8ejQbXeT8jXkgmbbjV2txbzCMCTGiNZKxt+6XgXrz3z8MLfTGUD Fetgi046D/rTPfFU2aEKQk+twQwd4xtRE2DEkFPAmO3IjWHtH2lFxrpWRPeWqfLT0btT yc0TSO2XN0eFXzpUWN6DubneKXnoCBQ7K4DoVwijZAED9QSAh+v/dCOld9nZ03V98pwl qBp87H95ds4xBPW0jnjUSHJ5n1IgRBhDdIzZRgRf4yGJYnTq2gkxcVSFM5wd8hCUf6TQ P/nQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=YtmfBZZO; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n5-20020a056402514500b0051e339bd2b1si4320510edd.435.2023.07.12.04.38.34; Wed, 12 Jul 2023 04:38:58 -0700 (PDT) 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=@kernel.org header.s=k20201202 header.b=YtmfBZZO; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230048AbjGLKtN (ORCPT + 99 others); Wed, 12 Jul 2023 06:49:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33544 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232769AbjGLKtF (ORCPT ); Wed, 12 Jul 2023 06:49:05 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 54DBF1998 for ; Wed, 12 Jul 2023 03:49:04 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id DD65161729 for ; Wed, 12 Jul 2023 10:49:03 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4AABAC433C7; Wed, 12 Jul 2023 10:49:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1689158943; bh=TRqNVlNQ2a89UC4lYv5F5uUENkyKDpT2EMyTJTWiwno=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=YtmfBZZOTdBbjLSsPW6gSrEQ3L5uE9NhbFjJN9N432vA8co0LnFyjjqtQ00RrFdWU QQQ/5HKs7vyuK5tpPgb2RMWmw4O8NH9JCaEi45g+VXVWZYYPU5Fx6QY+5Juy5cSp1I apHrnwO0opPJ0lHX8tgGiyHxEm66JHjD2y+tzUHe8qxFDSHnDvWSoim2hpleP0H8aV v0Jh1voBexsGkj3PZf8GwoahvaaKUO38HOw/O8eLQ6hXfRcVsH8Xnl3SE3msmtJOXy lMSVPy1BHY1mTnmTUhFmdbrTNyD48lLdRPGEPtE512KR/ZXZyCSzS4G6mdSTOq+jLq QSjEzRcoSOuUg== Received: from sofa.misterjones.org ([185.219.108.64] helo=goblin-girl.misterjones.org) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1qJXP3-00CPdq-0R; Wed, 12 Jul 2023 11:49:01 +0100 Date: Wed, 12 Jul 2023 11:49:00 +0100 Message-ID: <86351twgkj.wl-maz@kernel.org> From: Marc Zyngier To: Mostafa Saleh Cc: oliver.upton@linux.dev, linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-kernel@vger.kernel.org, tabba@google.com, qperret@google.com, will@kernel.org, catalin.marinas@arm.com, yuzenghui@huawei.com, suzuki.poulose@arm.com, james.morse@arm.com, bgardon@google.com, gshan@redhat.com, sudeep.holla@arm.com Subject: Re: [PATCH v2] KVM: arm64: Add missing BTI instructions In-Reply-To: <20230706152240.685684-1-smostafa@google.com> References: <20230706152240.685684-1-smostafa@google.com> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM-LB/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL-LB/10.8 EasyPG/1.0.0 Emacs/28.2 (aarch64-unknown-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: text/plain; charset=US-ASCII X-SA-Exim-Connect-IP: 185.219.108.64 X-SA-Exim-Rcpt-To: smostafa@google.com, oliver.upton@linux.dev, linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-kernel@vger.kernel.org, tabba@google.com, qperret@google.com, will@kernel.org, catalin.marinas@arm.com, yuzenghui@huawei.com, suzuki.poulose@arm.com, james.morse@arm.com, bgardon@google.com, gshan@redhat.com, sudeep.holla@arm.com X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 06 Jul 2023 16:22:40 +0100, Mostafa Saleh wrote: > > Some bti instructions were missing from > commit b53d4a272349 ("KVM: arm64: Use BTI for nvhe") > > 1) kvm_host_psci_cpu_entry > kvm_host_psci_cpu_entry is called from __kvm_hyp_init_cpu through "br" > instruction as __kvm_hyp_init_cpu resides in idmap section while > kvm_host_psci_cpu_entry is in hyp .text so the offset is larger than > 128MB range covered by "b". > Which means that this function should start with "bti j" instruction. > > LLVM which is the only compiler supporting BTI for Linux, adds "bti j" > for jump tables or by when taking the address of the block [1]. > Same behaviour is observed with GCC. > > As kvm_host_psci_cpu_entry is a C function, this must be done in > assembly. > > Another solution is to use X16/X17 with "br", as according to ARM > ARM DDI0487I.a RLJHCL/IGMGRS, PACIASP has an implicit branch > target identification instruction that is compatible with > PSTATE.BTYPE 0b01 which includes "br X16/X17" > And the kvm_host_psci_cpu_entry has PACIASP as it is an external > function. > Although, using explicit "bti" makes it more clear than relying on > which register is used. > > A third solution is to clear SCTLR_EL2.BT, which would make PACIASP > compatible PSTATE.BTYPE 0b11 ("br" to other registers). > However this deviates from the kernel behaviour (in bti_enable()). > > 2) Spectre vector table > "br" instructions are generated at runtime for the vector table > (__bp_harden_hyp_vecs). > These branches would land on vectors in __kvm_hyp_vector at offset 8. > As all the macros are defined with valid_vect/invalid_vect, it is > sufficient to add "bti j" at the correct offset. > > [1] https://reviews.llvm.org/D52867 > > Fixes: b53d4a272349 ("KVM: arm64: Use BTI for nvhe") > Signed-off-by: Mostafa Saleh > Reported-by: Sudeep Holla > --- > v1 -> v2: > - Add another missing bti in spectre vector table. > v1: https://lore.kernel.org/all/20230705171632.3912123-1-smostafa@google.com/ Acked-by: Marc Zyngier M. -- Without deviation from the norm, progress is not possible.