Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp27780887rwd; Tue, 4 Jul 2023 07:47:17 -0700 (PDT) X-Google-Smtp-Source: APBJJlEpYEd3eVc+UMCv0uiBGzQ1KsbHr3zYQnFXEgoP0uCNE0NWwTR8scI5bZ+53qukc/eI5Xv9 X-Received: by 2002:a17:903:32cd:b0:1b8:a67f:1c0f with SMTP id i13-20020a17090332cd00b001b8a67f1c0fmr1325521plr.39.1688482037581; Tue, 04 Jul 2023 07:47:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688482037; cv=none; d=google.com; s=arc-20160816; b=qiVEhgCkEpGP7MlHOL5xPn+l4vHpVIDBp5TtxGQBIn2Vu2+J5xAs5ITkbZ6dlYcnzj MVjvIiE3L5RG5VQJrqaw6UqOPCjrPvqV3fQDsJW1j8Qd489P24M6AVS90iPyX8opz/uj YeAZzbYFyw07z9O1/mIbUzZ9rIi2aFtY4wRpdjE/I4fdDL+v9mEH/rz50IN9ObeA97Cj oNe2txo97qjNr76cLUj07+qCyVHlJ1wzu5qQ+s4oI4rUcD8WN9NG/oGiPpbv9//X5Y2n fDj6A2z1P+HWiQ5WM3GOf6WxWSi787DtBdfR41Cc7TONhzuda2er9sCdF6WdL3eeuazt Qbsw== 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=6xXXf3hAUA5o75o+nEb0JO15WtYr8E/NDqRlddf2SSE=; fh=XM8L/y1mpl6LSeRJOpjgjim+qtvj1m5m/vWnpeXu3uM=; b=k4QXfIy29kvx4MWa53BKK/vEtbTFpAl8Tr3qohabapofUxolgfj+0mVBn4bq6ATP8m mZhYk39E2ss05knsYLMy9OmUsGsrfML7SzjrUW6TrGD+CyB6thbkpA1rNgantS1eZTPk EpLh5OeT3dKIprrI2U+R7UxPgSYzBpTfxtY3hLjxyYxtRxUx9MQTwKICftWPb+Vjh6/o cLCl8y2dQCQJJT+fP6bLYEJT2S50xbsVgedtdJ5TglIGpP1JuhvdASYD/B8BwO7dd59m Zjb+TUGMeUMmnmnA7MEuy4VA92REfQzTK44HZVPtoD/dyF9xvzrL1GK0/kR3qop2juhs 6esw== 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 jd18-20020a170903261200b001b7e493c63fsi19777297plb.135.2023.07.04.07.47.02; Tue, 04 Jul 2023 07:47:17 -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 S231792AbjGDOdr (ORCPT + 99 others); Tue, 4 Jul 2023 10:33:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51550 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230200AbjGDOdp (ORCPT ); Tue, 4 Jul 2023 10:33:45 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 8B3B9E47 for ; Tue, 4 Jul 2023 07:33:44 -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 BCD7B1516; Tue, 4 Jul 2023 07:34:26 -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 4C9103F73F; Tue, 4 Jul 2023 07:33:42 -0700 (PDT) Date: Tue, 4 Jul 2023 15:33:39 +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 v3] KVM: arm64: Use BTI for nvhe Message-ID: <20230704143339.cqrvntq7rmmb2on3@bogus> References: <20230530150845.2856828-1-smostafa@google.com> <20230704134136.a5znw4jupt5yp5kg@bogus> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: 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 Hi Mostafa, On Tue, Jul 04, 2023 at 02:18:09PM +0000, Mostafa Saleh wrote: > Hi Sudeep, > > On Tue, Jul 04, 2023 at 02:41:36PM +0100, Sudeep Holla wrote: > > 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. > > One of the challenges of BTI is that we need to add explicit BTI instructions > for assembly code. I checked the code to make sure that nothing was missing, > but maybe this is not the case. > Can you please share more about the issue (is ESR a Branch Target Exception, > call stack...) if possible. I haven't debugged it any further, just reported it as soon as I bisected it. Reverting this get back the booting system. I am not sure if anything is going wrong when the CPU is entering suspend(highly unlikely in normal scenario but I am not so sure with pKVM trapping these PSCI calls now) or when it is woken up and resuming back. IIUC this now will happen via kvm_hyp_cpu_resume-> __kvm_hyp_init_cpu->___kvm_hyp_init. > Also, is this with CONFIG_ARM_PSCI_CPUIDLE? Yes, basically the cpus can enter cpu_suspend which IIUC pKVM traps and handle for the host. > > > Not sure if this is something to do with the fact that pKVM skips to > > __kvm_handle_stub_hvc in __host_hvc. Sorry, my bad. I meant pKVM skips calling __kvm_handle_stub_hvc in __host_hvc and jumps to __host_exit directly. Sorry for that, one wrong "to" changed the whole meaning. > __kvm_handle_stub_hvc is called from __host_hvc with "br x5" > That's why "bti j" was added at the beginning of __kvm_handle_stub_hvc, > so this should be fine. > Yes I saw that and understood that but I wanted to tell the above which went horribly wrong before. -- Regards, Sudeep