Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp27705497rwd; Tue, 4 Jul 2023 06:48:44 -0700 (PDT) X-Google-Smtp-Source: APBJJlHa9gxTrLpI4k2/RmHS1dOtCwdX0VbvI8DvxfI1EFZesglK+iarKb8XB1ZVTcFpTyUN8Ad0 X-Received: by 2002:a17:903:22c6:b0:1b8:a39e:ff4b with SMTP id y6-20020a17090322c600b001b8a39eff4bmr4470792plg.32.1688478523779; Tue, 04 Jul 2023 06:48:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688478523; cv=none; d=google.com; s=arc-20160816; b=PpDaT4+sDRA9ip3YNFdk35kD/f0x7TsjdSoaBQg4sSbiqzCHQM/SW38fcvq3MifFhm MK3cXm0l0YcIcsrLLOP99ibvG2AQjwXlhakeZPZsjMjf0EVdJ4Km2JY3+LwNBI4qJ9Yk 7Zcz0Em7C+K8Z3RDkfIB5voYlfd2MmKIJmB+BLLoZHIyGAXyHANt6C7Dexp7tMCyiV+y BkjS5FH7BMZjVvNN/o++S45HyEbp8qFOx7LX6Uq3elhkE4iX4ckq44oc135QQXtHmaX6 11zCmgYuvfSBzMamr59uttEKEhDUcDcqrV1A2vujCj2a58shFK9BTe1QsNSZpJciKF6w lVeg== 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=Kxhfiz2/LbyNrdU09QS9bqAjboVWv1Jsa9jEYs3RUSw=; fh=cCyoa7ET4pkWsY2uok5Y1BDqU9u/05CwIlSI5IY9cpY=; b=yenIeqwsmWO5xdK7FctGT7e8yJvsK1ON4Qb7ChUz3KVq1tanPhtqkDSoUfVivLCqR9 JT7b8zH0aHx3X7zJ8BAyv9tBPtd/7WOMylPNwCoTHDt3FA+G8LrdcpH9JBYEei0SGKJy TncVOwoIzCLcYDgLy4uvHYZPFbXmHQ9GXkoXpm2g88JjEpyr62DRCYD7RHnTP3cef7sO W/cvHXHl5c1UT7YQhqHwujG9aqZV2oSIRKs+OdGu9IUGg6ZKr6OY5n7zAdwSuoqKmJW4 fch032KgC79a+rM/xchnHPeV1IAsA+F4KUfkDHLAbh4dq51RCAmLjQ7Ft5wJ9VAcMLUO s/9w== 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 p21-20020a63e655000000b0053439c1712esi19805544pgj.713.2023.07.04.06.48.31; Tue, 04 Jul 2023 06:48:43 -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 S231312AbjGDNlm (ORCPT + 99 others); Tue, 4 Jul 2023 09:41:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52424 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231281AbjGDNll (ORCPT ); Tue, 4 Jul 2023 09:41:41 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id DC570E6B for ; Tue, 4 Jul 2023 06:41:40 -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 E97351480; Tue, 4 Jul 2023 06:42:22 -0700 (PDT) Received: from bogus (e103737-lin.cambridge.arm.com [10.1.197.49]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 9523B3F663; Tue, 4 Jul 2023 06:41:38 -0700 (PDT) Date: Tue, 4 Jul 2023 14:41:36 +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 Subject: Re: [PATCH v3] KVM: arm64: Use BTI for nvhe Message-ID: <20230704134136.a5znw4jupt5yp5kg@bogus> References: <20230530150845.2856828-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: <20230530150845.2856828-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 Tue, May 30, 2023 at 03:08:45PM +0000, Mostafa Saleh wrote: > CONFIG_ARM64_BTI_KERNEL compiles the kernel to support ARMv8.5-BTI. > However, the nvhe code doesn't make use of it as it doesn't map any > pages with Guarded Page(GP) bit. > > kvm pgtable code is modified to map executable pages with GP bit > if BTI is enabled for the kernel. > > At hyp init, SCTLR_EL2.BT is set to 1 to match EL1 configuration > (SCTLR_EL1.BT1) set in bti_enable(). > > One difference between kernel and nvhe code, is that the kernel maps > .text with GP while nvhe maps all the executable pages, this makes > nvhe code need to deal with special initialization code coming from > other executable sections (.idmap.text). > For this we need to add bti instruction at the beginning of > __kvm_handle_stub_hvc as it can be called by __host_hvc through > branch instruction(br) and unlike SYM_FUNC_START, SYM_CODE_START > doesn’t add bti instruction at the beginning, and it can’t be modified > to add it as it is used with vector tables. > Another solution which is more intrusive is to convert > __kvm_handle_stub_hvc to a function and inject “bti jc” instead of > “bti c” in SYM_FUNC_START > I was chasing a bug in linux-next yesterday with protected nVHE(pKVM) and cpuidle enabled. The system fails to boot. I just bisected the issue to this patch and also saw this patch landed in the linus tree yesterday/today. Not sure if this is something to do with the fact that pKVM skips to __kvm_handle_stub_hvc in __host_hvc. Let me know if you want be to try something. -- Regards, Sudeep