Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CB6BEC636D6 for ; Tue, 7 Feb 2023 11:23:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230014AbjBGLXv (ORCPT ); Tue, 7 Feb 2023 06:23:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45608 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231577AbjBGLXs (ORCPT ); Tue, 7 Feb 2023 06:23:48 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CB6CECDE4; Tue, 7 Feb 2023 03:23:45 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 8A00AB818FF; Tue, 7 Feb 2023 11:23:44 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id EC5D8C433D2; Tue, 7 Feb 2023 11:23:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1675769023; bh=3ODqaHBZp5FJ22eMEpdVmf5CP3x7xF2WSgLTgVHOmlM=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=iSpHwSAeY4ZzLuVXGHdbTfKlE2wIuw6Pe+OwOVybmGLbecytzJUeBRzZK0hqyG4MR Y5VuFx5KV6yuy6orKAmWmIIBl+5UdbMlzNUvqtG2GsTm7Oto87hB6Fi45Cowvelyj9 9IVVLLszQ7gDFSYn3VdXCIYWPxZJIbUmwXwRYLK5POPVSB9alI3mauLkiqJY7FCgRL 0wQPRN1V1nAMobXMMsrv2vIxONuHECBC2VVm57o1QZbajZr+hRPuuxvjx4AI/D7Fzb TlsDR08XaeKhYHKpPGPXHEx00C5zXz8tPjppXSkKTapQA6MZXz/emapV1Sjs7mg9Hu Rwccvkc4286NQ== 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 1pPM4a-008J4O-KK; Tue, 07 Feb 2023 11:23:40 +0000 Date: Tue, 07 Feb 2023 11:23:40 +0000 Message-ID: <86sffhzpkz.wl-maz@kernel.org> From: Marc Zyngier To: Suzuki K Poulose Cc: James Morse , linux-pm@vger.kernel.org, loongarch@lists.linux.dev, kvmarm@lists.linux.dev, kvm@vger.kernel.org, linux-acpi@vger.kernel.org, linux-arch@vger.kernel.org, linux-ia64@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, x86@kernel.org, Thomas Gleixner , Lorenzo Pieralisi , Mark Rutland , Sudeep Holla , Borislav Petkov , H Peter Anvin , Dave Hansen , Ingo Molnar , Will Deacon , Catalin Marinas , Huacai Chen , Oliver Upton , Len Brown , Rafael Wysocki , WANG Xuerui , Salil Mehta , Russell King , Jean-Philippe Brucker Subject: Re: [RFC PATCH 29/32] KVM: arm64: Pass hypercalls to userspace In-Reply-To: <985abd9c-b3f9-3f9d-eec7-df1f26733762@arm.com> References: <20230203135043.409192-1-james.morse@arm.com> <20230203135043.409192-30-james.morse@arm.com> <865ycg1kv2.wl-maz@kernel.org> <86wn4vynyr.wl-maz@kernel.org> <985abd9c-b3f9-3f9d-eec7-df1f26733762@arm.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: suzuki.poulose@arm.com, james.morse@arm.com, linux-pm@vger.kernel.org, loongarch@lists.linux.dev, kvmarm@lists.linux.dev, kvm@vger.kernel.org, linux-acpi@vger.kernel.org, linux-arch@vger.kernel.org, linux-ia64@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, x86@kernel.org, tglx@linutronix.de, lpieralisi@kernel.org, mark.rutland@arm.com, sudeep.holla@arm.com, bp@alien8.de, hpa@zytor.com, dave.hansen@linux.intel.com, mingo@redhat.com, will@kernel.org, catalin.marinas@arm.com, chenhuacai@kernel.org, oliver.upton@linux.dev, lenb@kernel.org, rafael@kernel.org, kernel@xen0n.name, salil.mehta@huawei.com, linux@armlinux.org.uk, jean-philippe@linaro.org X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 07 Feb 2023 09:41:54 +0000, Suzuki K Poulose wrote: > > Hi Marc, > > On 06/02/2023 12:31, Marc Zyngier wrote: > > On Mon, 06 Feb 2023 10:10:41 +0000, > > Suzuki K Poulose wrote: > >> > >> This may not be always possible, e.g., for Realms. GET_ONE_REG is > >> not supported. So using an explicit passing down of the args is > >> preferrable. > > > > What is the blocker for CCA to use GET_ONE_REG? The value obviously > > exists and is made available to the host. pKVM is perfectly able to > > use GET_ONE_REG and gets a bunch of zeroes for things that the > > hypervisor has decided to hide from the host. > > > > It is not impossible. On a "HOST CALL" (explicit calls to the Host > from Realm), the GPRs are made available to the host and can be > stashed into the vcpu reg state and the request can be > serviced. However, it is a bit odd, to make this exception - "the > GET_ONE_REG is valid now", while in almost all other cases it is > invalid (exception of MMIO). But that's an RMM decision. If the RMM decides to forward the hypercall to the host (irrespective of the potential forwarding to userspace), it makes the GPRs available. If the hypercall is forwarded to userspace, then the host is responsible to check with the RMM that it will be willing to provide the required information (passed as GPRs or not). > Of course we could always return what is stashed in the vcpu state, > which is may be invalid/ 0. But given the construct of "host doesn't > have access to the register state", it may be a good idea to say, > request always fails, to indicate that the Host is probably doing > something wrong, than silently passing on incorrect information. I disagree. Either you fail at the delegation point, or you don't. On getting a hypercall exit to userspace, you are guaranteed that the GPRs are valid. > > Of course, it requires that the hypervisor (the RMM in your case) > > knows about the semantics of the hypercall, but that's obviously > > RMM doesn't care about the semantics of hypercall, other than > considering it just like an SMCCC compliant call. The hypercall > arguments/results are passed down/up by the Realm in a separate > structure. That's because the RMM doesn't use registers to pass the data. But at the end of the day, this is the same thing. The host gets the data from the RMM, stashes it in the GPRs, and exit to userspace. The important thing here is that GET_ONE_REG is valid in the context where it matters. If the VMM tries to use it outside of the context of a hypercall, it gets junk. It's not a bug, it's a feature. Thanks, M. -- Without deviation from the norm, progress is not possible.