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 4719EC64ED6 for ; Wed, 8 Feb 2023 14:26:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231510AbjBHO0J (ORCPT ); Wed, 8 Feb 2023 09:26:09 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41182 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231280AbjBHOZv (ORCPT ); Wed, 8 Feb 2023 09:25:51 -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 0AFCB4B1AB; Wed, 8 Feb 2023 06:25:44 -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 BAAD9B81E3A; Wed, 8 Feb 2023 14:25:42 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5819EC433EF; Wed, 8 Feb 2023 14:25:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1675866341; bh=t5jw1fCX4NoFeI2EPmYRhXOtkcVOIpQY0b9/jl5R8zA=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=QgNyeqlpCi/SBDeCi1TjNEdCqZoJFbgr2WJlBzhmFCZPBDl+FvwZLFuUoEtRHiVbv uS4uK4r0XCkRineIPNNP9oNxBtbjMeBbnPgCgvwNC+24iI018JePzQOYQtTUyIy/Mp /qg/12O4pWuU4Ph2uCYFfSRaCoExuPkTdS6885J4+z8cV91aO0N0MHwBMlJryvG9OZ X0le3Z/bcdQT3Q9bcuXnQc0LtSfZRuA6mh3CZD/9kvJpn4wp9UOAU86Mdp+1pChhIx M/bUit0KIlLfw8FTXVwGO//F6H/bwcRj6WGI2Aj+ovZgdrJEnNUillAjBfdPPc/tmo KNXBaoR+knFdw== 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 1pPlOF-008gAy-0C; Wed, 08 Feb 2023 14:25:39 +0000 Date: Wed, 08 Feb 2023 14:25:38 +0000 Message-ID: <86h6vwz125.wl-maz@kernel.org> From: Marc Zyngier To: James Morse Cc: 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 , Suzuki K Poulose , 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: <878rh81rfa.wl-maz@kernel.org> References: <20230203135043.409192-1-james.morse@arm.com> <20230203135043.409192-30-james.morse@arm.com> <865ycg1kv2.wl-maz@kernel.org> <7462738f-e837-cd99-f441-8e7c29d250cd@arm.com> <878rh81rfa.wl-maz@kernel.org> 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: 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, suzuki.poulose@arm.com, 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 Wed, 08 Feb 2023 08:40:09 +0000, Marc Zyngier wrote: > > On Tue, 07 Feb 2023 17:50:58 +0000, > James Morse wrote: > > > > Hi Marc, > > > > On 05/02/2023 10:12, Marc Zyngier wrote: > > > On Fri, 03 Feb 2023 13:50:40 +0000, > > > James Morse wrote: > > >> > > >> From: Jean-Philippe Brucker > > >> > > >> When capability KVM_CAP_ARM_HVC_TO_USER is available, userspace can > > >> request to handle all hypercalls that aren't handled by KVM. With the > > >> help of another capability, this will allow userspace to handle PSCI > > >> calls. > > > > > On top of Oliver's ask not to make this a blanket "steal everything", > > > but instead to have an actual request for ranges of forwarded > > > hypercalls: > > > > > >> Notes on this implementation: > > >> > > >> * A similar mechanism was proposed for SDEI some time ago [1]. This RFC > > >> generalizes the idea to all hypercalls, since that was suggested on > > >> the list [2, 3]. > > >> > > >> * We're reusing kvm_run.hypercall. I copied x0-x5 into > > >> kvm_run.hypercall.args[] to help userspace but I'm tempted to remove > > >> this, because: > > >> - Most user handlers will need to write results back into the > > >> registers (x0-x3 for SMCCC), so if we keep this shortcut we should > > >> go all the way and read them back on return to kernel. > > >> - QEMU doesn't care about this shortcut, it pulls all vcpu regs before > > >> handling the call. > > >> - SMCCC uses x0-x16 for parameters. > > >> x0 does contain the SMCCC function ID and may be useful for fast > > >> dispatch, we could keep that plus the immediate number. > > >> > > >> * Add a flag in the kvm_run.hypercall telling whether this is HVC or > > >> SMC? Can be added later in those bottom longmode and pad fields. > > > > > We definitely need this. A nested hypervisor can (and does) use SMCs > > > as the conduit. > > > > Christoffer's comments last time round on this was that EL2 guests > > get SMC with this, and EL1 guests get HVC. The VMM could never get > > both... > > I agree with the first half of the statement (EL2 guest using SMC), > but limiting EL1 guests to HVC is annoying. On systems that have a > secure side, it would make sense to be able to route the guest's SMC > calls to userspace and allow it to emulate/proxy/deny such calls. You also want to look at the TRNG firmware spec (aka DEN0098), which explicitly calls out for the use of SMC when EL2 and EL3 are implemented (see 1.5 "Invocation considerations"). Is it mad? Yes. But madness seems to be the direction of travel these days. M. -- Without deviation from the norm, progress is not possible.