Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp30717104rwd; Thu, 6 Jul 2023 09:40:42 -0700 (PDT) X-Google-Smtp-Source: APBJJlF3vZuQqYOZxk2Yk2PVXYDZJhvb8Jwxrva7wbLuDIqHGcu6t72nErK7PrpijavukC3ROamv X-Received: by 2002:a17:90a:fb84:b0:262:b22b:8ab5 with SMTP id cp4-20020a17090afb8400b00262b22b8ab5mr1854967pjb.17.1688661641706; Thu, 06 Jul 2023 09:40:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688661641; cv=none; d=google.com; s=arc-20160816; b=McFYygC+aM1p95k6mwvhnKaQ5UgalYikDUeajAx1T19TbWoFMFKlsD23v3qXYzbwzZ R9YVwHJ6dlTkdLC8nu1aw+bHE1n8hF19F5y8c5/cr5Zszdf/kBbIlpBBQEED0mJCrcHJ jGScP3IjHhRNxQF+EfYaETBZLBTxpbCPl9Sxbvm8N8TEb18Ho3dVpj9lRyzTXZ8H1BO0 BT7ikKtu3w+AfCx6qwYBzr+3TReSgMa8dAfFROuvXzktyxm/5m9jeXqjPvkvsPmwYS42 g7nNcnZ69J80VOWq4L9MVB+wRHWRwEbYsX9NzCEywAOqru30GlZd1+lmlLjUh+fGV2DS Y3Rg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=wArc0Y6xan21MzM7GQIc9YsPPs1j1die4U+Y3AAo1ww=; fh=FdYw1+WfN4Lnf7E7s1AjlIdgnelZUmylGBCv6m+Qo10=; b=KZxwoWKHLXRs1KTUC02Q/BZJn2es2T0fupK6P6tWkHOqGx0opxQ/swFD0ccrT9nefA jpO8rPHoAKpi3J5Uek2pk0k41l8Jd2lKxo+lCemg56RPb7M6joRWPJD+ohP+BM0FWMC1 +WN+E6eCxPuT8rWumHhJvO3vLtfk6JL1ckpuOsiYrp82VIQGFOmKVaLvokRGb6lfcuKL 7PxWrbwqKh/5NOtdhCyNkjKGfTcZvTL8Fvsivmm0v/oNathxijCOTxSfHs1rsu7/ZJm6 jiB/tLIttZTuW9DB32G9QwyrK4G7E4b4lKwXCTX56Y3ZOw4cvCqoeNxEjqEWlF1FHg+9 doxA== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q7-20020a635047000000b005503f266742si1733344pgl.647.2023.07.06.09.40.29; Thu, 06 Jul 2023 09:40:41 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229999AbjGFQXS (ORCPT + 99 others); Thu, 6 Jul 2023 12:23:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35476 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229507AbjGFQXR (ORCPT ); Thu, 6 Jul 2023 12:23:17 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id A8C4EDC for ; Thu, 6 Jul 2023 09:23:15 -0700 (PDT) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id F2C23D75; Thu, 6 Jul 2023 09:23:56 -0700 (PDT) Received: from bogus (unknown [10.57.76.100]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 210013F762; Thu, 6 Jul 2023 09:23:11 -0700 (PDT) Date: Thu, 6 Jul 2023 17:23:08 +0100 From: Sudeep Holla To: Mostafa Saleh Cc: maz@kernel.org, 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 Subject: Re: [PATCH v2] KVM: arm64: Add missing BTI instructions Message-ID: <20230706162308.kyeitspgfaqb6vgn@bogus> References: <20230706152240.685684-1-smostafa@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20230706152240.685684-1-smostafa@google.com> X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE 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, Jul 06, 2023 at 03:22:40PM +0000, 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 Nothing change w.r.t cpu suspend-resume path in v2 anyways, but I assure I tested this again just be absolutely sure and it still fixes the issue I reported ????, so Tested-by: Sudeep Holla -- Regards, Sudeep