From patchwork Tue Sep 21 01:47:19 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Stabellini X-Patchwork-Id: 12506719 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id EC3FBC433F5 for ; Tue, 21 Sep 2021 01:47:36 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id A51C760F6D for ; Tue, 21 Sep 2021 01:47:36 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org A51C760F6D Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=lists.xenproject.org Received: from list by lists.xenproject.org with outflank-mailman.191271.341226 (Exim 4.92) (envelope-from ) id 1mSUsV-0002H2-BO; Tue, 21 Sep 2021 01:47:23 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 191271.341226; Tue, 21 Sep 2021 01:47:23 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mSUsV-0002Gv-8F; Tue, 21 Sep 2021 01:47:23 +0000 Received: by outflank-mailman (input) for mailman id 191271; Tue, 21 Sep 2021 01:47:22 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mSUsT-0002Gp-WF for xen-devel@lists.xenproject.org; Tue, 21 Sep 2021 01:47:22 +0000 Received: from mail.kernel.org (unknown [198.145.29.99]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id dbc527f2-1a7d-11ec-b893-12813bfff9fa; Tue, 21 Sep 2021 01:47:20 +0000 (UTC) Received: by mail.kernel.org (Postfix) with ESMTPSA id C4D8F60F6D; Tue, 21 Sep 2021 01:47:19 +0000 (UTC) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: dbc527f2-1a7d-11ec-b893-12813bfff9fa DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1632188839; bh=I5VKcWngTdDEZip7JAp1tRcAkJbmXfrVY13T3xHXOaw=; h=Date:From:To:cc:Subject:From; b=UArsbmKda49UVQo/ke0IZJ4ZLMBO6LDdGfa2hHqPsAg8bzzSv6AvvNvDQ6H1/Rc5a 6IaWCq+zlJutCd2Fl6aSGiKMJYgW6lXyFfmUobVI17nUq9u3pD7O+mvtzpgYgcSDti 4UpcI2RkXEFHYzpxB97pVp+gR9Xs8tAMikiLrTUD8JLJjgkYROKqKb1ruvFPR63ri+ pETojKK/bGQU541yqjQhetswKmPeyaDyWUbPaeiLaWcpWNOrfN2jlSGRZVJr3LP0dZ R89HMt3S/5ubbWZv4YpYrN/ST4soZrY3xhNhXTC/Kpgp3fxKUYjWiUsiDydpGfqr2w zsgEZFoCJRigQ== Date: Mon, 20 Sep 2021 18:47:19 -0700 (PDT) From: Stefano Stabellini X-X-Sender: sstabellini@sstabellini-ThinkPad-T480s To: xen-devel@lists.xenproject.org cc: sstabellini@kernel.org, Bertrand.Marquis@arm.com Subject: Example patch to send SGIs with a hypercall Message-ID: User-Agent: Alpine 2.21 (DEB 202 2017-01-01) MIME-Version: 1.0 Content-ID: Hi all, Next week I'll be giving a talk about VM-to-VM communication mechanisms at Embedded Linux Conf in Seattle. One of the techniques I'll discuss, also the simplest, is shared memory and interrupts. Although there is no binding to share memory between dom0less VMs yet, it is already possible to do that with a workaround. But it is not possible to send interrupts between dom0less VMs yet. The attached patch introduces a trivial hypercall to inject SGI interrupts into other Dom0less VMs. It is easy to use for baremetal guests and other kernels without Xen support (no Xen drivers needed). I'd like to share the patch publicly in advance of the talk, so that I can reference it during the presentation. The patch is not meant for upstreaming at this point. Beware that it comes with no usage restrictions (no rate limiting and/or no target limits). Cheers, Stefano From c169e2c287c16d6cdef6f073d12fa02cbd80086c Mon Sep 17 00:00:00 2001 From: Stefano Stabellini Date: Mon, 20 Sep 2021 18:33:45 -0700 Subject: [PATCH] xen/arm: introduce PHYSDEV_sgi_send Introduce a simple hypercall to inject an SGI interrupt into a target domain/vcpu. Please note that the implementation doesn't come with any rate limiting. Signed-off-by: Stefano Stabellini --- xen/arch/arm/physdev.c | 34 ++++++++++++++++++++++++++++++--- xen/arch/arm/traps.c | 2 +- xen/include/asm-arm/hypercall.h | 3 ++- xen/include/public/physdev.h | 19 ++++++++++++++++++ 4 files changed, 53 insertions(+), 5 deletions(-) diff --git a/xen/arch/arm/physdev.c b/xen/arch/arm/physdev.c index e91355fe22..2ee29939d2 100644 --- a/xen/arch/arm/physdev.c +++ b/xen/arch/arm/physdev.c @@ -11,10 +11,38 @@ #include -int do_physdev_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg) +int do_physdev_op(int cmd, uint8_t sgi, uint16_t domid, uint32_t vcpuid) { - gdprintk(XENLOG_DEBUG, "PHYSDEVOP cmd=%d: not implemented\n", cmd); - return -ENOSYS; + int rc = 0; + struct domain *d; + + if ( cmd != PHYSDEV_sgi_send ) + { + gdprintk(XENLOG_DEBUG, "PHYSDEVOP cmd=%d: not implemented\n", cmd); + return -ENOSYS; + } + + if ( sgi >= 16 ) + { + gdprintk(XENLOG_DEBUG, "PHYSDEVOP_sgi_send invalid sgi=%u\n", sgi); + return -EINVAL; + } + + + d = rcu_lock_domain_by_any_id(domid); + if ( d == NULL ) + return -ESRCH; + if ( vcpuid >= d->max_vcpus ) + { + rc = -EINVAL; + goto out; + } + + vgic_inject_irq(d, d->vcpu[vcpuid], sgi, true); + +out: + rcu_unlock_domain(d); + return rc; } /* diff --git a/xen/arch/arm/traps.c b/xen/arch/arm/traps.c index 219ab3c3fb..374ed490a2 100644 --- a/xen/arch/arm/traps.c +++ b/xen/arch/arm/traps.c @@ -1377,7 +1377,7 @@ static arm_hypercall_t arm_hypercall_table[] = { HYPERCALL(xsm_op, 1), HYPERCALL(event_channel_op, 2), HYPERCALL_DEPRECATED(event_channel_op_compat, 1), - HYPERCALL(physdev_op, 2), + HYPERCALL(physdev_op, 4), HYPERCALL_DEPRECATED(physdev_op_compat, 1), HYPERCALL(sysctl, 2), HYPERCALL(hvm_op, 2), diff --git a/xen/include/asm-arm/hypercall.h b/xen/include/asm-arm/hypercall.h index a0c5a31a2f..4299548907 100644 --- a/xen/include/asm-arm/hypercall.h +++ b/xen/include/asm-arm/hypercall.h @@ -2,7 +2,8 @@ #define __ASM_ARM_HYPERCALL_H__ #include /* for arch_do_domctl */ -int do_physdev_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg); + +int do_physdev_op(int cmd, uint8_t sgi, uint16_t domid, uint32_t vcpuid); long do_arm_vcpu_op(int cmd, unsigned int vcpuid, XEN_GUEST_HANDLE_PARAM(void) arg); diff --git a/xen/include/public/physdev.h b/xen/include/public/physdev.h index d271766ad0..64458fe7a1 100644 --- a/xen/include/public/physdev.h +++ b/xen/include/public/physdev.h @@ -340,6 +340,25 @@ struct physdev_dbgp_op { typedef struct physdev_dbgp_op physdev_dbgp_op_t; DEFINE_XEN_GUEST_HANDLE(physdev_dbgp_op_t); +/* + * ARM only hypercall to send an SGI to another VM + * + * int physdev_op(int cmd, uint8_t sgi, uint16_t domid, uint32_t vcpuid) + * + * sgi: SGI number of the interrupt to inject + * domid: target domid + * vcpuid: target vcpusid + * + * example: + * mov x0, #30 // PHYSDEV_sgi_send command + * mov x1, #5 // SGI number 5, can chose any in the range 0-15 + * mov x2, #1 // destination domain id (e.g. 0 for dom0, 1 for first domU) + * mov x3, #0 // destination vcpu id (not physical cpu), typically 0 + * mov x16, #33 // hypercall physdev_op number 33 + * hvc 0xEA1 // hypercall command + */ +#define PHYSDEV_sgi_send 30 + /* * Notify that some PIRQ-bound event channels have been unmasked. * ** This command is obsolete since interface version 0x00030202 and is ** -- 2.17.1