From nobody Fri Oct 31 03:47:35 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass header.i=teddy.astie@vates.tech; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=reject dis=none) header.from=vates.tech ARC-Seal: i=1; a=rsa-sha256; t=1755789986; cv=none; d=zohomail.com; s=zohoarc; b=ZmlfIyt0q3RV2/6ZWDiMvukBluCr5AfN5WNSPyOKtgMSEIEQm8vrwxYd4V4yKT3HtDAUViZVVFR6rBXzqB9IIwDaUdFGmqzXvJGrvjkPE8mJC5XN9zgQ8w6OcFcemHpN1wgTtFMTmD/TIulFzvdgHN6PVCAKKvmRrLin3LPtyDE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1755789986; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=SbIlPsyNgTEwgIzXTJ1Jn4RTs8uee0L3+cFAML8sLR8=; b=gOjHMezhuRaKWpL2qBvqZrBMdP4vUzKKU5juL07ToxU0JsBkln6WWiZa7F/Hj+kBXsMAqVEhoJk7rGS1dolezsvrqaDjuNS5wOamoU8hp/eGYhsfugT2k26+QaI2rmSYLk73qiu/LzNK122AbgztdPuv4p6grBwba2ahxGWBeq4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=teddy.astie@vates.tech; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1755789986778955.9054079542533; Thu, 21 Aug 2025 08:26:26 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1088817.1446543 (Exim 4.92) (envelope-from ) id 1up7As-0006AB-Oj; Thu, 21 Aug 2025 15:25:58 +0000 Received: by outflank-mailman (output) from mailman id 1088817.1446543; Thu, 21 Aug 2025 15:25:58 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1up7As-00066t-Fc; Thu, 21 Aug 2025 15:25:58 +0000 Received: by outflank-mailman (input) for mailman id 1088817; Thu, 21 Aug 2025 15:25:57 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1up7Ar-0005nU-CD for xen-devel@lists.xenproject.org; Thu, 21 Aug 2025 15:25:57 +0000 Received: from mail137-3.atl71.mandrillapp.com (mail137-3.atl71.mandrillapp.com [198.2.137.3]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 1eb23df8-7ea3-11f0-a32b-13f23c93f187; Thu, 21 Aug 2025 17:25:51 +0200 (CEST) Received: from pmta07.mandrill.prod.atl01.rsglab.com (localhost [127.0.0.1]) by mail137-3.atl71.mandrillapp.com (Mailchimp) with ESMTP id 4c76bL40mbzBsVD7B for ; Thu, 21 Aug 2025 15:25:50 +0000 (GMT) Received: from [37.26.189.201] by mandrillapp.com id 3f408629188242329ca2147b15758713; Thu, 21 Aug 2025 15:25:50 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version 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: 1eb23df8-7ea3-11f0-a32b-13f23c93f187 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mandrillapp.com; s=mte1; t=1755789950; x=1756059950; bh=SbIlPsyNgTEwgIzXTJ1Jn4RTs8uee0L3+cFAML8sLR8=; h=From:Subject:To:Cc:Message-Id:In-Reply-To:References:Feedback-ID: Date:MIME-Version:Content-Type:Content-Transfer-Encoding:CC:Date: Subject:From; b=RrEDColLv3XLiy+Pvl2N0Rkll4OwKpU9CDzpuliBKDNj0dP/muYjABsxULNGI2PeH Tw1PIIy0Evg6Og3RYWkVSnvOLZqBkz0BzD3v3ogYXZorZm/abMLKYsbnHmpRZu2Obn VX5QApBlilJEm/9thqD0gmVW76Oar4QNjr8ukBruQjeqFw9oVlQWzVuO/aHeo2TDjU uRUdGmBZzCI+xl/p3BogKOp0vH7OIn5BTYpo50IWfYqaJv0z+G/S2gqaSuJTzr58C5 ZoWL61+MplY/3PPkq76cQpfiT8y6jcS0mFD74aKCzDCab4jTgYgJWO8jQe4qzuEiWs LDKFj4Ck04HcA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vates.tech; s=mte1; t=1755789950; x=1756050450; i=teddy.astie@vates.tech; bh=SbIlPsyNgTEwgIzXTJ1Jn4RTs8uee0L3+cFAML8sLR8=; h=From:Subject:To:Cc:Message-Id:In-Reply-To:References:Feedback-ID: Date:MIME-Version:Content-Type:Content-Transfer-Encoding:CC:Date: Subject:From; b=buf6aQGC7jf864Xe0EzUrya0YgB08xs1kCH9qIHZ3T9fuFJTI86NIGWDEHRjDQLhs ppY8Qa88CBvW/CUVc/LgKw7mWjCih/AiHaLuTU4fe40FUxGzTc6vEn4Ms0KKat457X yeFhTbXsYv6NGumt34ve8fAIHZHpV0VTPFrd9zOFUnKOtxvobXEP/wgMVt9WJdzmD1 xkNp+bTgvdxDJmLZ6aK7TUDRUWSlXv3kB2/Drg/TL1q1h8dtHrYEAOdem5bvx7tDIb wGeA3ptW/YQvnx51n4peEl6ju1Zdu47X2IwnSYPMdnZor3OCLHzHS5oy0/ZhLT2Pka KoQtTC5cUKJew== From: "Teddy Astie" Subject: =?utf-8?Q?[RFC=20PATCH=201/9]=20x86/hvm:=20Use=20direct=20structures=20instead=20of=20guest=20handles?= X-Mailer: git-send-email 2.50.1 X-Bm-Disclaimer: Yes X-Bm-Milter-Handled: 4ffbd6c1-ee69-4e1b-aabd-f977039bd3e2 X-Bm-Transport-Timestamp: 1755789949800 To: xen-devel@lists.xenproject.org Cc: "Teddy Astie" , "Jan Beulich" , "Andrew Cooper" , "=?utf-8?Q?Roger=20Pau=20Monn=C3=A9?=" Message-Id: In-Reply-To: References: X-Native-Encoded: 1 X-Report-Abuse: =?UTF-8?Q?Please=20forward=20a=20copy=20of=20this=20message,=20including=20all=20headers,=20to=20abuse@mandrill.com.=20You=20can=20also=20report=20abuse=20here:=20https://mandrillapp.com/contact/abuse=3Fid=3D30504962.3f408629188242329ca2147b15758713?= X-Mandrill-User: md_30504962 Feedback-ID: 30504962:30504962.20250821:md Date: Thu, 21 Aug 2025 15:25:50 +0000 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @mandrillapp.com) (identity teddy.astie@vates.tech) X-ZM-MESSAGEID: 1755789987484116600 Content-Type: text/plain; charset="utf-8" Make these functions work with hypervisor-owned pointer rather than guest handles, so the function parameters don't have to live in guest memor= y. No functional changes intended. Signed-off-by: Teddy Astie --- xen/arch/x86/hvm/hvm.c | 126 +++++++++++++++++++++++------------------ 1 file changed, 70 insertions(+), 56 deletions(-) diff --git a/xen/arch/x86/hvm/hvm.c b/xen/arch/x86/hvm/hvm.c index 56c7de3977..8bf59c63fe 100644 --- a/xen/arch/x86/hvm/hvm.c +++ b/xen/arch/x86/hvm/hvm.c @@ -4142,19 +4142,14 @@ static int hvmop_flush_tlb_all(void) return paging_flush_tlb(NULL) ? 0 : -ERESTART; } =20 -static int hvmop_set_evtchn_upcall_vector( - XEN_GUEST_HANDLE_PARAM(xen_hvm_evtchn_upcall_vector_t) uop) +static int hvmop_set_evtchn_upcall_vector(xen_hvm_evtchn_upcall_vector_t o= p) { - xen_hvm_evtchn_upcall_vector_t op; struct domain *d =3D current->domain; struct vcpu *v; =20 if ( !is_hvm_domain(d) ) return -EINVAL; =20 - if ( copy_from_guest(&op, uop, 1) ) - return -EFAULT; - if ( op.vector < 0x10 ) return -EINVAL; =20 @@ -4434,26 +4429,21 @@ static int hvm_set_param(struct domain *d, uint32_t= index, uint64_t value) return rc; } =20 -static int hvmop_set_param( - XEN_GUEST_HANDLE_PARAM(xen_hvm_param_t) arg) +static int hvmop_set_param(struct xen_hvm_param op) { - struct xen_hvm_param a; struct domain *d; int rc; =20 - if ( copy_from_guest(&a, arg, 1) ) - return -EFAULT; - - if ( a.index >=3D HVM_NR_PARAMS ) + if ( op.index >=3D HVM_NR_PARAMS ) return -EINVAL; =20 - d =3D rcu_lock_domain_by_any_id(a.domid); + d =3D rcu_lock_domain_by_any_id(op.domid); if ( d =3D=3D NULL ) return -ESRCH; =20 rc =3D -EINVAL; if ( is_hvm_domain(d) ) - rc =3D hvm_set_param(d, a.index, a.value); + rc =3D hvm_set_param(d, op.index, op.value); =20 rcu_unlock_domain(d); return rc; @@ -4544,31 +4534,21 @@ int hvm_get_param(struct domain *d, uint32_t index,= uint64_t *value) return 0; }; =20 -static int hvmop_get_param( - XEN_GUEST_HANDLE_PARAM(xen_hvm_param_t) arg) +static int hvmop_get_param(struct xen_hvm_param *op) { - struct xen_hvm_param a; struct domain *d; int rc; =20 - if ( copy_from_guest(&a, arg, 1) ) - return -EFAULT; - - if ( a.index >=3D HVM_NR_PARAMS ) + if ( op->index >=3D HVM_NR_PARAMS ) return -EINVAL; =20 - d =3D rcu_lock_domain_by_any_id(a.domid); + d =3D rcu_lock_domain_by_any_id(op->domid); if ( d =3D=3D NULL ) return -ESRCH; =20 rc =3D -EINVAL; - if ( is_hvm_domain(d) && !(rc =3D hvm_get_param(d, a.index, &a.value))= ) - { - rc =3D __copy_to_guest(arg, &a, 1) ? -EFAULT : 0; - - HVM_DBG_LOG(DBG_LEVEL_HCALL, "get param %u =3D %"PRIx64, - a.index, a.value); - } + if ( is_hvm_domain(d) && !(rc =3D hvm_get_param(d, op->index, &op->val= ue)) ) + HVM_DBG_LOG(DBG_LEVEL_HCALL, "get param %u =3D %"PRIx64, a.index, = a.value); =20 rcu_unlock_domain(d); return rc; @@ -5046,18 +5026,13 @@ static int compat_altp2m_op( return rc; } =20 -static int hvmop_get_mem_type( - XEN_GUEST_HANDLE_PARAM(xen_hvm_get_mem_type_t) arg) +static int hvmop_get_mem_type(struct xen_hvm_get_mem_type *op) { - struct xen_hvm_get_mem_type a; struct domain *d; p2m_type_t t; int rc; =20 - if ( copy_from_guest(&a, arg, 1) ) - return -EFAULT; - - d =3D rcu_lock_domain_by_any_id(a.domid); + d =3D rcu_lock_domain_by_any_id(op->domid); if ( d =3D=3D NULL ) return -ESRCH; =20 @@ -5074,25 +5049,22 @@ static int hvmop_get_mem_type( * type, not in allocating or unsharing. That'll happen * on access. */ - get_gfn_query_unlocked(d, a.pfn, &t); + get_gfn_query_unlocked(d, op->pfn, &t); if ( p2m_is_mmio(t) ) - a.mem_type =3D HVMMEM_mmio_dm; + op->mem_type =3D HVMMEM_mmio_dm; else if ( t =3D=3D p2m_ioreq_server ) - a.mem_type =3D HVMMEM_ioreq_server; + op->mem_type =3D HVMMEM_ioreq_server; else if ( p2m_is_readonly(t) ) - a.mem_type =3D HVMMEM_ram_ro; + op->mem_type =3D HVMMEM_ram_ro; else if ( p2m_is_ram(t) ) - a.mem_type =3D HVMMEM_ram_rw; + op->mem_type =3D HVMMEM_ram_rw; else if ( p2m_is_pod(t) ) - a.mem_type =3D HVMMEM_ram_rw; + op->mem_type =3D HVMMEM_ram_rw; else if ( p2m_is_grant(t) ) - a.mem_type =3D HVMMEM_ram_rw; + op->mem_type =3D HVMMEM_ram_rw; else - a.mem_type =3D HVMMEM_mmio_dm; + op->mem_type =3D HVMMEM_mmio_dm; =20 - rc =3D -EFAULT; - if ( __copy_to_guest(arg, &a, 1) ) - goto out; rc =3D 0; =20 out: @@ -5115,28 +5087,70 @@ long do_hvm_op(unsigned long op, XEN_GUEST_HANDLE_P= ARAM(void) arg) switch ( op ) { case HVMOP_set_evtchn_upcall_vector: - rc =3D hvmop_set_evtchn_upcall_vector( - guest_handle_cast(arg, xen_hvm_evtchn_upcall_vector_t)); + { + struct xen_hvm_evtchn_upcall_vector op; + + if ( copy_from_guest(&op, arg, 1) ) + { + rc =3D -EFAULT; + break; + } + + rc =3D hvmop_set_evtchn_upcall_vector(op); break; + } =20 case HVMOP_set_param: - rc =3D hvmop_set_param( - guest_handle_cast(arg, xen_hvm_param_t)); + { + struct xen_hvm_param op; + =20 + if ( copy_from_guest(&op, arg, 1) ) + { + rc =3D -EFAULT; + break; + } + + rc =3D hvmop_set_param(op); break; + } =20 case HVMOP_get_param: - rc =3D hvmop_get_param( - guest_handle_cast(arg, xen_hvm_param_t)); + { + struct xen_hvm_param op; + =20 + if ( copy_from_guest(&op, arg, 1) ) + { + rc =3D -EFAULT; + break; + } + + rc =3D hvmop_get_param(&op); + + if ( !rc && copy_to_guest(arg, &op, 1) ) + rc =3D -EFAULT; break; + } =20 case HVMOP_flush_tlbs: rc =3D guest_handle_is_null(arg) ? hvmop_flush_tlb_all() : -EINVAL; break; =20 case HVMOP_get_mem_type: - rc =3D hvmop_get_mem_type( - guest_handle_cast(arg, xen_hvm_get_mem_type_t)); + { + struct xen_hvm_get_mem_type op; + + if ( copy_from_guest(&op, arg, 1) ) + { + rc =3D -EFAULT; + break; + } + =20 + rc =3D hvmop_get_mem_type(&op); + + if ( !rc && copy_to_guest(arg, &op, 1) ) + rc =3D -EFAULT; break; + } =20 case HVMOP_pagetable_dying: { --=20 2.50.1 Teddy Astie | Vates XCP-ng Developer XCP-ng & Xen Orchestra - Vates solutions web: https://vates.tech From nobody Fri Oct 31 03:47:35 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass header.i=teddy.astie@vates.tech; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=reject dis=none) header.from=vates.tech ARC-Seal: i=1; a=rsa-sha256; t=1755789979; cv=none; d=zohomail.com; s=zohoarc; b=bEKbW11YvTP9v6a+wbS7lPKUEUh/WcqK0MUkEbNQ65w24PyCZQBpPVxFddYbsd1+Ygomazp/UF0z+2rrXNAf/WgKrHVGs5WK+4jEr62PmyVO7dTLhgKirtto/XUTUFsg6qHQg8yTPvL8Zee74F4hHN6XEsl47yut7pW76i4ktG8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1755789979; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=Zc917Cb8fY8/yfL65ARqArQPpJf0Hd7vGTKynVOYYc4=; b=l0IZVk4O6E85ji+zSPhIDo8oDLO6pDQr9cdtZkvubcHgO+1OyRDoCV0/W1EuNw4fbTJAzM5h/Jk7ILmQEVx9YgL97GbiVG3K3PtxSsE7sKbB8EhFPqDjsKK2pqImW9NHFjULf/dBPmVfBY0d5Uj9V+OQguFRvbClCHL+eoXTLhA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=teddy.astie@vates.tech; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1755789979104912.5100085355933; Thu, 21 Aug 2025 08:26:19 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1088814.1446520 (Exim 4.92) (envelope-from ) id 1up7Ap-0005ni-Q4; Thu, 21 Aug 2025 15:25:55 +0000 Received: by outflank-mailman (output) from mailman id 1088814.1446520; Thu, 21 Aug 2025 15:25:55 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1up7Ap-0005nb-NX; Thu, 21 Aug 2025 15:25:55 +0000 Received: by outflank-mailman (input) for mailman id 1088814; Thu, 21 Aug 2025 15:25:54 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1up7Ao-0005nU-Jn for xen-devel@lists.xenproject.org; Thu, 21 Aug 2025 15:25:54 +0000 Received: from mail179-29.suw41.mandrillapp.com (mail179-29.suw41.mandrillapp.com [198.2.179.29]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 1fd633ea-7ea3-11f0-a32b-13f23c93f187; Thu, 21 Aug 2025 17:25:53 +0200 (CEST) Received: from pmta12.mandrill.prod.suw01.rsglab.com (localhost [127.0.0.1]) by mail179-29.suw41.mandrillapp.com (Mailchimp) with ESMTP id 4c76bN13Kkz7lmV4q for ; Thu, 21 Aug 2025 15:25:52 +0000 (GMT) Received: from [37.26.189.201] by mandrillapp.com id b26388fab1ef4df0bf0d61632d7da11d; Thu, 21 Aug 2025 15:25:52 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version 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: 1fd633ea-7ea3-11f0-a32b-13f23c93f187 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mandrillapp.com; s=mte1; t=1755789952; x=1756059952; bh=Zc917Cb8fY8/yfL65ARqArQPpJf0Hd7vGTKynVOYYc4=; h=From:Subject:To:Cc:Message-Id:In-Reply-To:References:Feedback-ID: Date:MIME-Version:Content-Type:Content-Transfer-Encoding:CC:Date: Subject:From; b=o1zBDSwYzZiO6OuCjkC0875v8RXC7LUe4ElG2M6DfEazi4FPUk4dMorHf4xiABzCU +XYveIkzr5LhdOv/Uon5qZUZxi5tjEldB3w9namWGMVyrOYxDlBb9DvsjiuOKbvadO D4zI0GmGm6NT231gf+iUd0NCcI9d8nIJ0vTKinGgGfEvDQQitVSKDhUrJxTd7eXkCB W5BYMzzCoue5Wo7/UlzBHcUoXVJmVlEfEy5edbZvNcjGcaM6lkvyZgPC5g7z9cPR9g SwdeVfsJvUoJgXgeZmCBo2n7tt2wah/SyHMl0vhfdbye4H5jFf9AavRXFojNiT6oC4 am85Lz7NKMUvA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vates.tech; s=mte1; t=1755789952; x=1756050452; i=teddy.astie@vates.tech; bh=Zc917Cb8fY8/yfL65ARqArQPpJf0Hd7vGTKynVOYYc4=; h=From:Subject:To:Cc:Message-Id:In-Reply-To:References:Feedback-ID: Date:MIME-Version:Content-Type:Content-Transfer-Encoding:CC:Date: Subject:From; b=SEVzliy1lDGye0rRf2GGHE9/wTL/Ui6IU7qtxpG+8S7W3A3gkStrde3lccke58+29 ztdcxK1YwpAQW6xkhiGOQNNSmsS8cH1TAv294ask29gHaAqr4Ysa2BTRwHOOUrrQX0 7k1BwyMmM60IrcL8dbp31NVqjA4KXLBCO4TVp+VqD+IYuuczWzbnjJkagAJlT9ZqiP YX8au1opTniiaFNBKVno7QoIVATFUZ4AzMcLXSp8k/F0bz5vV18SdQD2mJiRB54KjY 3Ikpvn+axZpkue6Dbyu95Zh0HeEcGFkteeV9YTL3M7DfT/GF+cbZ/0dRbb1gGo3KnJ uNasdZu8zWpKA== From: "Teddy Astie" Subject: =?utf-8?Q?[RFC=20PATCH=202/9]=20common:=20Isolate=20XENVER=5Fget=5Ffeatures=20into=20a=20separate=20function?= X-Mailer: git-send-email 2.50.1 X-Bm-Disclaimer: Yes X-Bm-Milter-Handled: 4ffbd6c1-ee69-4e1b-aabd-f977039bd3e2 X-Bm-Transport-Timestamp: 1755789951011 To: xen-devel@lists.xenproject.org Cc: "Teddy Astie" , "Andrew Cooper" , "Anthony PERARD" , "Michal Orzel" , "Jan Beulich" , "Julien Grall" , "=?utf-8?Q?Roger=20Pau=20Monn=C3=A9?=" , "Stefano Stabellini" Message-Id: <0bbc0f2df1853bb60f4e93c55d1a0953c6a72496.1755785258.git.teddy.astie@vates.tech> In-Reply-To: References: X-Native-Encoded: 1 X-Report-Abuse: =?UTF-8?Q?Please=20forward=20a=20copy=20of=20this=20message,=20including=20all=20headers,=20to=20abuse@mandrill.com.=20You=20can=20also=20report=20abuse=20here:=20https://mandrillapp.com/contact/abuse=3Fid=3D30504962.b26388fab1ef4df0bf0d61632d7da11d?= X-Mandrill-User: md_30504962 Feedback-ID: 30504962:30504962.20250821:md Date: Thu, 21 Aug 2025 15:25:52 +0000 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @mandrillapp.com) (identity teddy.astie@vates.tech) X-ZM-MESSAGEID: 1755789981446116600 Content-Type: text/plain; charset="utf-8" Make do_xen_version more readable by moving the main XENVER_get_features into a separate function. No functional changes intended. Signed-off-by: Teddy Astie --- xen/common/kernel.c | 84 +++++++++++++++++++++++++-------------------- 1 file changed, 46 insertions(+), 38 deletions(-) diff --git a/xen/common/kernel.c b/xen/common/kernel.c index 5be668ba85..eff6db6c8f 100644 --- a/xen/common/kernel.c +++ b/xen/common/kernel.c @@ -569,6 +569,50 @@ static long xenver_varbuf_op(int cmd, XEN_GUEST_HANDLE= _PARAM(void) arg) return sz; } =20 +static long xenver_get_features(struct domain *d, uint32_t submap_idx, uin= t32_t *submap) +{ + switch ( submap_idx ) + { + case 0: + *submap =3D (1U << XENFEAT_memory_op_vnode_supported) | +#ifdef CONFIG_X86 + (1U << XENFEAT_vcpu_time_phys_area) | +#endif + (1U << XENFEAT_runstate_phys_area); + if ( VM_ASSIST(d, pae_extended_cr3) ) + *submap |=3D (1U << XENFEAT_pae_pgdir_above_4gb); + if ( paging_mode_translate(d) ) + *submap |=3D + (1U << XENFEAT_writable_page_tables) | + (1U << XENFEAT_auto_translated_physmap); + if ( is_hardware_domain(d) ) + *submap |=3D 1U << XENFEAT_dom0; +#ifdef CONFIG_ARM + *submap |=3D (1U << XENFEAT_ARM_SMCCC_supported); +#endif +#ifdef CONFIG_X86 + if ( is_pv_domain(d) ) + *submap |=3D (1U << XENFEAT_mmu_pt_update_preserve_ad) | + (1U << XENFEAT_highmem_assist) | + (1U << XENFEAT_gnttab_map_avail_bits); + else + *submap |=3D (1U << XENFEAT_hvm_safe_pvclock) | + (1U << XENFEAT_hvm_callback_vector) | + (has_pirq(d) ? (1U << XENFEAT_hvm_pirqs) : 0); + *submap |=3D (1U << XENFEAT_dm_msix_all_writes); +#endif + if ( !paging_mode_translate(d) || is_domain_direct_mapped(d) ) + *submap |=3D (1U << XENFEAT_direct_mapped); + else + *submap |=3D (1U << XENFEAT_not_direct_mapped); + break; + default: + return -EINVAL; + } + + return 0; +} + long do_xen_version(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg) { bool deny =3D xsm_xen_version(XSM_OTHER, cmd); @@ -675,45 +719,9 @@ long do_xen_version(int cmd, XEN_GUEST_HANDLE_PARAM(vo= id) arg) if ( copy_from_guest(&fi, arg, 1) ) return -EFAULT; =20 - switch ( fi.submap_idx ) - { - case 0: - fi.submap =3D (1U << XENFEAT_memory_op_vnode_supported) | -#ifdef CONFIG_X86 - (1U << XENFEAT_vcpu_time_phys_area) | -#endif - (1U << XENFEAT_runstate_phys_area); - if ( VM_ASSIST(d, pae_extended_cr3) ) - fi.submap |=3D (1U << XENFEAT_pae_pgdir_above_4gb); - if ( paging_mode_translate(d) ) - fi.submap |=3D - (1U << XENFEAT_writable_page_tables) | - (1U << XENFEAT_auto_translated_physmap); - if ( is_hardware_domain(d) ) - fi.submap |=3D 1U << XENFEAT_dom0; -#ifdef CONFIG_ARM - fi.submap |=3D (1U << XENFEAT_ARM_SMCCC_supported); -#endif -#ifdef CONFIG_X86 - if ( is_pv_domain(d) ) - fi.submap |=3D (1U << XENFEAT_mmu_pt_update_preserve_ad) | - (1U << XENFEAT_highmem_assist) | - (1U << XENFEAT_gnttab_map_avail_bits); - else - fi.submap |=3D (1U << XENFEAT_hvm_safe_pvclock) | - (1U << XENFEAT_hvm_callback_vector) | - (has_pirq(d) ? (1U << XENFEAT_hvm_pirqs) : 0); - fi.submap |=3D (1U << XENFEAT_dm_msix_all_writes); -#endif - if ( !paging_mode_translate(d) || is_domain_direct_mapped(d) ) - fi.submap |=3D (1U << XENFEAT_direct_mapped); - else - fi.submap |=3D (1U << XENFEAT_not_direct_mapped); - break; - default: + if ( xenver_get_features(d, fi.submap_idx, &fi.submap) ) return -EINVAL; - } - + =20 if ( __copy_to_guest(arg, &fi, 1) ) return -EFAULT; return 0; --=20 2.50.1 Teddy Astie | Vates XCP-ng Developer XCP-ng & Xen Orchestra - Vates solutions web: https://vates.tech From nobody Fri Oct 31 03:47:35 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass header.i=teddy.astie@vates.tech; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=reject dis=none) header.from=vates.tech ARC-Seal: i=1; a=rsa-sha256; t=1755789977; cv=none; d=zohomail.com; s=zohoarc; b=VI0VHeKm9KykS/qJdONGAYelo7Yw/O7pi9TlKEke89fG7bCJ16SFeSZsX0pT8Ng9OPnL/9IjhHNWzmsidUTG+jX8+bk4W93qw/SeUjmqfZz0pYBRGA8OmWYyNS/gFhI3aetO50bLTmGe9zxtbF4m7KKnw2zDuwKdAtQpksr/0s8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1755789977; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=MVrRTSIy9uYoaMBKkh7zoQoap19sAiJjJLjg5p6Ic0g=; b=lbi1yq7RCbvP1sK0aozr1EF/LudzPQ+Qww7RbFFIsru68udJ7WMmM8VFZV93y7j/TYc6swBxXSZ+siPPxYgmkIwZVmB9KU1y2ckVDw+6xFJdE91l3mJE1lJegbYP5+2fCXw62WzNTnsPMg8wNrHIzx6xWFNOP56rED4RrMsXDJA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=teddy.astie@vates.tech; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1755789977221293.6107112127261; Thu, 21 Aug 2025 08:26:17 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1088816.1446536 (Exim 4.92) (envelope-from ) id 1up7As-00063o-CF; Thu, 21 Aug 2025 15:25:58 +0000 Received: by outflank-mailman (output) from mailman id 1088816.1446536; Thu, 21 Aug 2025 15:25:58 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1up7As-00062c-6g; Thu, 21 Aug 2025 15:25:58 +0000 Received: by outflank-mailman (input) for mailman id 1088816; Thu, 21 Aug 2025 15:25:56 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1up7Aq-0005na-HL for xen-devel@lists.xenproject.org; Thu, 21 Aug 2025 15:25:56 +0000 Received: from mail179-29.suw41.mandrillapp.com (mail179-29.suw41.mandrillapp.com [198.2.179.29]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 203876e4-7ea3-11f0-b898-0df219b8e170; Thu, 21 Aug 2025 17:25:54 +0200 (CEST) Received: from pmta12.mandrill.prod.suw01.rsglab.com (localhost [127.0.0.1]) by mail179-29.suw41.mandrillapp.com (Mailchimp) with ESMTP id 4c76bP1Cbvz7lmVSh for ; Thu, 21 Aug 2025 15:25:53 +0000 (GMT) Received: from [37.26.189.201] by mandrillapp.com id 9e97327b3e3448aa96280e39b2c50859; Thu, 21 Aug 2025 15:25:53 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version 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: 203876e4-7ea3-11f0-b898-0df219b8e170 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mandrillapp.com; s=mte1; t=1755789953; x=1756059953; bh=MVrRTSIy9uYoaMBKkh7zoQoap19sAiJjJLjg5p6Ic0g=; h=From:Subject:To:Cc:Message-Id:In-Reply-To:References:Feedback-ID: Date:MIME-Version:Content-Type:Content-Transfer-Encoding:CC:Date: Subject:From; b=D2T/lPxz9m6iy5cumbLkrM2qX4+oJFF7v4EcytjbXPe9vYi4dexm4YDKMXy//M24w V41VG0zhJRq8hmIguPTx3VWbGZoobthF2m9uEg0Hp3z3U4Sld1HKHTz2iCbsW9iLlF dkiV6+OtrCfWRDZyBX/DOnamQZsZnPAsBLVu5RNAQjL1EQI+2gQDVYWGtgG1p5KYNk PIAR8/lezfnc/GtR6YPOlezeyAA76/8GVp2se8CzcPmlrQUFXZS31uk0DehVsWvQdq 6ZVZu+IlRoAtmyHcCpbGvF4ZL7N9uLAd/49d9i8y9RsaRJKFi63waNCByTKUVto8s7 ala/oxN8trNCA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vates.tech; s=mte1; t=1755789953; x=1756050453; i=teddy.astie@vates.tech; bh=MVrRTSIy9uYoaMBKkh7zoQoap19sAiJjJLjg5p6Ic0g=; h=From:Subject:To:Cc:Message-Id:In-Reply-To:References:Feedback-ID: Date:MIME-Version:Content-Type:Content-Transfer-Encoding:CC:Date: Subject:From; b=ww6gqMX6PdulhC+7W88CP5mu1tt2Y/0gT5fgjGjY8kqYdRiCur0LurbE/nSLdimqf 56QPqjfAe8jxQCedo+NaZWg8QGKMJCkY4ug0XGiYJFN3/9daFQSilIjBEe0xTkmusi ZBlZ0bUMcLrvrbIk3XllGIeZw2ZSWj2SWRs5J/RC7Pqg5kNBHsfRv/kKGIXbeTGmqC HPKCHaLe0Afz4AcdRFge5eQCK7l2IFCX3fTJA8v1Da/XmOrNSedMoYOci00IIx0lTg 1kU3tuTNcD8zqLZKtnIObGu3+oDcM/d9u7ysc0/RXZykf6uoCc67Ed2Qy5UZxkUon8 tO8ETKr/KYO/A== From: "Teddy Astie" Subject: =?utf-8?Q?[RFC=20PATCH=203/9]=20common/grant=5Ftable:=20Use=20direct=20structures=20instead=20of=20guest=20handles?= X-Mailer: git-send-email 2.50.1 X-Bm-Disclaimer: Yes X-Bm-Milter-Handled: 4ffbd6c1-ee69-4e1b-aabd-f977039bd3e2 X-Bm-Transport-Timestamp: 1755789951955 To: xen-devel@lists.xenproject.org Cc: "Teddy Astie" , "Andrew Cooper" , "Anthony PERARD" , "Michal Orzel" , "Jan Beulich" , "Julien Grall" , "=?utf-8?Q?Roger=20Pau=20Monn=C3=A9?=" , "Stefano Stabellini" Message-Id: <3443dc8528075ce8ed8dd89ee5d0b78515c81e8e.1755785258.git.teddy.astie@vates.tech> In-Reply-To: References: X-Native-Encoded: 1 X-Report-Abuse: =?UTF-8?Q?Please=20forward=20a=20copy=20of=20this=20message,=20including=20all=20headers,=20to=20abuse@mandrill.com.=20You=20can=20also=20report=20abuse=20here:=20https://mandrillapp.com/contact/abuse=3Fid=3D30504962.9e97327b3e3448aa96280e39b2c50859?= X-Mandrill-User: md_30504962 Feedback-ID: 30504962:30504962.20250821:md Date: Thu, 21 Aug 2025 15:25:53 +0000 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity teddy.astie@vates.tech) (identity @mandrillapp.com) X-ZM-MESSAGEID: 1755789980435124100 Content-Type: text/plain; charset="utf-8" Make these functions work with hypervisor-owned pointer rather than guest handles, so the function parameters don't have to live in guest memor= y. No functional changes. Signed-off-by: Teddy Astie --- xen/common/grant_table.c | 68 +++++++++++++++++++++++----------------- 1 file changed, 39 insertions(+), 29 deletions(-) diff --git a/xen/common/grant_table.c b/xen/common/grant_table.c index cf131c43a1..3c3bbca2fc 100644 --- a/xen/common/grant_table.c +++ b/xen/common/grant_table.c @@ -3164,29 +3164,24 @@ static long gnttab_copy( return rc; } =20 -static long -gnttab_set_version(XEN_GUEST_HANDLE_PARAM(gnttab_set_version_t) uop) +static long gnttab_set_version(gnttab_set_version_t *op) { - gnttab_set_version_t op; struct domain *currd =3D current->domain; struct grant_table *gt =3D currd->grant_table; grant_entry_v1_t reserved_entries[GNTTAB_NR_RESERVED_ENTRIES]; int res; unsigned int i, nr_ents; =20 - if ( copy_from_guest(&op, uop, 1) ) - return -EFAULT; - res =3D -EINVAL; - if ( op.version !=3D 1 && op.version !=3D 2 ) + if ( op->version !=3D 1 && op->version !=3D 2 ) goto out; =20 res =3D -ENOSYS; - if ( op.version =3D=3D 2 && gt->max_version =3D=3D 1 ) + if ( op->version =3D=3D 2 && gt->max_version =3D=3D 1 ) goto out; /* Behave as before set_version was introduced. */ =20 res =3D 0; - if ( gt->gt_version =3D=3D op.version ) + if ( gt->gt_version =3D=3D op->version ) goto out; =20 grant_write_lock(gt); @@ -3203,7 +3198,7 @@ gnttab_set_version(XEN_GUEST_HANDLE_PARAM(gnttab_set_= version_t) uop) { gdprintk(XENLOG_WARNING, "tried to change grant table version from %u to %u, b= ut some grant entries still in use\n", - gt->gt_version, op.version); + gt->gt_version, op->version); res =3D -EBUSY; goto out_unlock; } @@ -3268,7 +3263,7 @@ gnttab_set_version(XEN_GUEST_HANDLE_PARAM(gnttab_set_= version_t) uop) break; } =20 - if ( op.version < 2 && gt->gt_version =3D=3D 2 && + if ( op->version < 2 && gt->gt_version =3D=3D 2 && (res =3D gnttab_unpopulate_status_frames(currd, gt)) !=3D 0 ) goto out_unlock; =20 @@ -3279,7 +3274,7 @@ gnttab_set_version(XEN_GUEST_HANDLE_PARAM(gnttab_set_= version_t) uop) /* Restore the first 8 entries (toolstack reserved grants). */ if ( gt->gt_version ) { - switch ( op.version ) + switch ( op->version ) { case 1: memcpy(&shared_entry_v1(gt, 0), reserved_entries, sizeof(reser= ved_entries)); @@ -3300,16 +3295,14 @@ gnttab_set_version(XEN_GUEST_HANDLE_PARAM(gnttab_se= t_version_t) uop) } } =20 - gt->gt_version =3D op.version; + gt->gt_version =3D op->version; =20 out_unlock: grant_write_unlock(gt); =20 out: - op.version =3D gt->gt_version; + op->version =3D gt->gt_version; =20 - if ( __copy_to_guest(uop, &op, 1) ) - res =3D -EFAULT; =20 return res; } @@ -3387,17 +3380,12 @@ gnttab_get_status_frames(XEN_GUEST_HANDLE_PARAM(gnt= tab_get_status_frames_t) uop, return 0; } =20 -static long -gnttab_get_version(XEN_GUEST_HANDLE_PARAM(gnttab_get_version_t) uop) +static long gnttab_get_version(gnttab_get_version_t *op) { - gnttab_get_version_t op; struct domain *d; int rc; =20 - if ( copy_from_guest(&op, uop, 1) ) - return -EFAULT; - - d =3D rcu_lock_domain_by_any_id(op.dom); + d =3D rcu_lock_domain_by_any_id(op->dom); if ( d =3D=3D NULL ) return -ESRCH; =20 @@ -3408,13 +3396,10 @@ gnttab_get_version(XEN_GUEST_HANDLE_PARAM(gnttab_ge= t_version_t) uop) return rc; } =20 - op.version =3D d->grant_table->gt_version; + op->version =3D d->grant_table->gt_version; =20 rcu_unlock_domain(d); =20 - if ( __copy_field_to_guest(uop, &op, version) ) - return -EFAULT; - return 0; } =20 @@ -3749,8 +3734,20 @@ long do_grant_table_op( break; =20 case GNTTABOP_set_version: - rc =3D gnttab_set_version(guest_handle_cast(uop, gnttab_set_versio= n_t)); + { + gnttab_set_version_t op; + if ( copy_from_guest(&op, uop, 1) ) + { + rc =3D -EFAULT; + break; + } + + rc =3D gnttab_set_version(&op); + + if ( copy_to_guest(uop, &op, 1) ) + rc =3D -EFAULT; break; + } =20 case GNTTABOP_get_status_frames: rc =3D gnttab_get_status_frames( @@ -3758,8 +3755,21 @@ long do_grant_table_op( break; =20 case GNTTABOP_get_version: - rc =3D gnttab_get_version(guest_handle_cast(uop, gnttab_get_versio= n_t)); + { + gnttab_get_version_t op; + + if ( copy_from_guest(&op, uop, 1) ) + { + rc =3D -EFAULT; + break; + } + + rc =3D gnttab_get_version(&op); + + if ( copy_to_guest(uop, &op, 1) ) + rc =3D -EFAULT; break; + } =20 case GNTTABOP_swap_grant_ref: { --=20 2.50.1 Teddy Astie | Vates XCP-ng Developer XCP-ng & Xen Orchestra - Vates solutions web: https://vates.tech From nobody Fri Oct 31 03:47:35 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass header.i=teddy.astie@vates.tech; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=reject dis=none) header.from=vates.tech ARC-Seal: i=1; a=rsa-sha256; t=1755789980; cv=none; d=zohomail.com; s=zohoarc; b=G3T9Vpkd7hZEygyx4xb5TOsS8WFa0+dNk48z9GNUqQqBrfAFIZV5xiT7juiwaCSDE9xjR+9fAJUuRDPZeoZzs2kqObiwfRBdCzDMNOnSbNCiAz9hOs77nQ1Q3TinYHwopRjr2swrr5hnDoyRCmsGRLK/S+RFiwRM0BBBI70MViM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1755789980; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=v9693aJ0tIn6PL/KSvi73SLKMBRME6s7Oodg2Swvg4k=; b=N/OB6cMlQkqHS8hcuoNoOZDscFb37gThpJ/9z1XyafWzVyDtpRoqZJcYV00Ysc03rw2hOLzMTruCc6e/8n5FFPc4H1Y5CCoF6KJ4IFPtEvps5NoWTPx5EOevYQJjnTAEJ23jr7qEtV29UY6i1nHs+s1RI/S5QZS6RgQ14MjIwl0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=teddy.astie@vates.tech; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1755789980230548.4154113473022; Thu, 21 Aug 2025 08:26:20 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1088819.1446566 (Exim 4.92) (envelope-from ) id 1up7Au-0006jV-Cj; Thu, 21 Aug 2025 15:26:00 +0000 Received: by outflank-mailman (output) from mailman id 1088819.1446566; Thu, 21 Aug 2025 15:26:00 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1up7Au-0006iw-6A; Thu, 21 Aug 2025 15:26:00 +0000 Received: by outflank-mailman (input) for mailman id 1088819; Thu, 21 Aug 2025 15:25:58 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1up7As-0005na-HO for xen-devel@lists.xenproject.org; Thu, 21 Aug 2025 15:25:58 +0000 Received: from mail137-3.atl71.mandrillapp.com (mail137-3.atl71.mandrillapp.com [198.2.137.3]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 21836de1-7ea3-11f0-b898-0df219b8e170; Thu, 21 Aug 2025 17:25:56 +0200 (CEST) Received: from pmta07.mandrill.prod.atl01.rsglab.com (localhost [127.0.0.1]) by mail137-3.atl71.mandrillapp.com (Mailchimp) with ESMTP id 4c76bQ0wjWzBsVD76 for ; Thu, 21 Aug 2025 15:25:54 +0000 (GMT) Received: from [37.26.189.201] by mandrillapp.com id 5565b7a84c614179b7558ba46b71cf8f; Thu, 21 Aug 2025 15:25:54 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version 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: 21836de1-7ea3-11f0-b898-0df219b8e170 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mandrillapp.com; s=mte1; t=1755789954; x=1756059954; bh=v9693aJ0tIn6PL/KSvi73SLKMBRME6s7Oodg2Swvg4k=; h=From:Subject:To:Cc:Message-Id:In-Reply-To:References:Feedback-ID: Date:MIME-Version:Content-Type:Content-Transfer-Encoding:CC:Date: Subject:From; b=iMHqtkLQWTccEKocnJ30gS94aO+FZnLgcKSPFIynoxhB5ye68HSCIWqqBgTI6648J 5PpdV7fXBTZ5+WY8MI7P6ZswZb8QT90Ou/S6fw7U349KlZIq+GnZRQbv24etXFW+8s 2TM3TEEsVgrPl3eBuyIBNBsrmqDZssHEKOOtpscJXc2oEbvXz4T9jY47Ntvos17siZ J2lhV/AshFpx0f67qYVuCZbLWckervw1ZXrpZd5SXsfaxKcczchYJLUqwZJxCafYp5 yigRqUb+DExo0OMyo++ljNrnLznCo4sUKpcT6R9IetgxAS+cAxOLAM+xpjAogWxWjt OS1RC6hNp1uDg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vates.tech; s=mte1; t=1755789954; x=1756050454; i=teddy.astie@vates.tech; bh=v9693aJ0tIn6PL/KSvi73SLKMBRME6s7Oodg2Swvg4k=; h=From:Subject:To:Cc:Message-Id:In-Reply-To:References:Feedback-ID: Date:MIME-Version:Content-Type:Content-Transfer-Encoding:CC:Date: Subject:From; b=iH0BcE+QR1Uaoadh/SSpJyDJOpz7rEZOK9PHZRIcQcd7FQSuoHHsEP9YxnK6YLBJF V9CZB7oqLjRzXWdUlCzhIzsOKBiYhkRHsQeXqSYpzn66U8dQneGlzgvNiEWWaZQYe5 N9/BPKoE+PMlOavuOwQdJ3idbHJ6kFXgKdokA1kZNnaN659ikq3g0JQq8nK5NqIOd3 DpAwBE/G0BStKl4dcWA5I0oD2QN5jBF4XihFwXY3/4mTxKix0hgOdw4JGkhbzUAvsr SaV2sx1/QWthMhj0M6D4qYJ2WSDhOInkIvEWLpdQSJbY1n4E5Y4jioWoJkEXqB8z7+ /IzqH+tX3xp0w== From: "Teddy Astie" Subject: =?utf-8?Q?[RFC=20PATCH=204/9]=20hvm:=20Introduce=20"fixed=20memory=20layout"=20feature?= X-Mailer: git-send-email 2.50.1 X-Bm-Disclaimer: Yes X-Bm-Milter-Handled: 4ffbd6c1-ee69-4e1b-aabd-f977039bd3e2 X-Bm-Transport-Timestamp: 1755789952853 To: xen-devel@lists.xenproject.org Cc: "Teddy Astie" , "Andrew Cooper" , "Anthony PERARD" , "Michal Orzel" , "Jan Beulich" , "Julien Grall" , "=?utf-8?Q?Roger=20Pau=20Monn=C3=A9?=" , "Stefano Stabellini" , "Juergen Gross" Message-Id: <640223e5e7ee18a73f62152dd27883bf5978fbfe.1755785258.git.teddy.astie@vates.tech> In-Reply-To: References: X-Native-Encoded: 1 X-Report-Abuse: =?UTF-8?Q?Please=20forward=20a=20copy=20of=20this=20message,=20including=20all=20headers,=20to=20abuse@mandrill.com.=20You=20can=20also=20report=20abuse=20here:=20https://mandrillapp.com/contact/abuse=3Fid=3D30504962.5565b7a84c614179b7558ba46b71cf8f?= X-Mandrill-User: md_30504962 Feedback-ID: 30504962:30504962.20250821:md Date: Thu, 21 Aug 2025 15:25:54 +0000 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity teddy.astie@vates.tech) (identity @mandrillapp.com) X-ZM-MESSAGEID: 1755789982529124100 Content-Type: text/plain; charset="utf-8" Currently, guests needs to explicitely map their shared info and grant table through hypercalls. It has proved to be complicated and had been traditionally placed in the Xen PCI Platform device BAR, but has caused confusions regarding MTRR [1]. Introduce a optional feature to let the toolstack map these pages in advance, and exposing their location through the memory map (i.e E820). When this feature is active, guests are expected to not invalidate such mappings (e.g by calling xen_remove_from_physmap); as they may be used by the operating system or firmware (i.e OVMF). Moreover, this feature is useful to allow having a working guest without having to expose to it physmap manipulation. [1] https://lore.kernel.org/xen-devel/20250610162930.89055-1-roger.pau@citr= ix.com/ Signed-off-by: Teddy Astie --- .../x86/fixed-memory-layout.pandoc | 24 ++++++ docs/guest-guide/x86/index.rst | 1 + tools/include/xen-tools/common-macros.h | 4 + tools/libs/guest/xg_dom_x86.c | 84 +++++++++++++++++++ tools/libs/light/libxl_create.c | 1 + tools/libs/light/libxl_types.idl | 1 + tools/libs/light/libxl_x86.c | 71 ++++++++++++++++ tools/xl/xl_parse.c | 1 + xen/include/public/arch-x86/hvm/start_info.h | 7 ++ 9 files changed, 194 insertions(+) create mode 100644 docs/guest-guide/x86/fixed-memory-layout.pandoc diff --git a/docs/guest-guide/x86/fixed-memory-layout.pandoc b/docs/guest-g= uide/x86/fixed-memory-layout.pandoc new file mode 100644 index 0000000000..b394dc1cff --- /dev/null +++ b/docs/guest-guide/x86/fixed-memory-layout.pandoc @@ -0,0 +1,24 @@ +# Fixed memory layout + +When creating a guest with "fixed_mem_layout", the guest has additional sp= ecial +pages mapped in advance. These mappings may be required in some cases due = to FastABI +not providing the ability for the guest to modify its physical memory layo= ut (which is +usually used to map the shared info page or the grant table). + +The guest is informed of such mappings and their location through the memo= ry map using +Xen specific memory map types (in the OEM range of ACPI specification). + +It's expected that these mappings stay stable, therefore, the guest should= n't try to +modify such mappings as it may be actively used by guest firmware or opera= ting system. + + /* Xen-specific types (OEM-specific range of the ACPI spec) */ + #define XEN_HVM_MEMMAP_TYPE_SHARED_INFO 0xF0000001 /* Shared info pa= ge */ + #define XEN_HVM_MEMMAP_TYPE_GRANT_TABLE 0xF0000002 /* Grant table pa= ges */ + #define XEN_HVM_MEMMAP_TYPE_GNTTAB_STATUS 0xF0000003 /* Grant table st= atus page (v2) */ + #define XEN_HVM_MEMMAP_TYPE_FOREIGN_REG 0xF0000004 /* Suitable regio= n for grant mappings */ + /* and foreign ma= ppings */ + +These mappings are likely to be placed outside the 4G range. + +XEN_HVM_MEMMAP_TYPE_FOREIGN_REG is a special region which doesn't contain = any mapping, +but is safe to use for placing grant and foreign mappings. diff --git a/docs/guest-guide/x86/index.rst b/docs/guest-guide/x86/index.rst index 502968490d..6927271e53 100644 --- a/docs/guest-guide/x86/index.rst +++ b/docs/guest-guide/x86/index.rst @@ -7,3 +7,4 @@ x86 :maxdepth: 2 =20 hypercall-abi + fixed-memory-layout diff --git a/tools/include/xen-tools/common-macros.h b/tools/include/xen-to= ols/common-macros.h index 0088208c2e..8b286b3da5 100644 --- a/tools/include/xen-tools/common-macros.h +++ b/tools/include/xen-tools/common-macros.h @@ -72,6 +72,10 @@ #define ROUNDUP(_x,_w) (((unsigned long)(_x)+(1UL<<(_w))-1) & ~((1UL<<(_w)= )-1)) #endif =20 +#ifndef DIV_ROUNDUP +#define DIV_ROUNDUP(n, d) (((n) + (d) - 1) / (d)) +#endif + #define MASK_EXTR(v, m) (((v) & (m)) / ((m) & -(m))) #define MASK_INSR(v, m) (((v) * ((m) & -(m))) & (m)) =20 diff --git a/tools/libs/guest/xg_dom_x86.c b/tools/libs/guest/xg_dom_x86.c index cba01384ae..ab1c5063a4 100644 --- a/tools/libs/guest/xg_dom_x86.c +++ b/tools/libs/guest/xg_dom_x86.c @@ -624,6 +624,82 @@ static void build_hvm_info(void *hvm_info_page, struct= xc_dom_image *dom) hvm_info->checksum =3D -sum; } =20 +/* Prepare special (shared_info, grant table, ...) regions marked in E820.= */ +static int prepare_fixed_special_regions(xc_interface *xch, struct xc_dom_= image *dom) +{ + int rc =3D 0; unsigned int i; + uint32_t domid =3D dom->guest_domid; + gnttab_query_size_t gnttab_query; + size_t gnttab_frame_count, gnttab_status_frame_count; + =20 + gnttab_query.dom =3D domid; + rc =3D xc_gnttab_query_size(xch, &gnttab_query); + + if ( rc !=3D 0 || gnttab_query.status !=3D GNTST_okay ) + { + DOMPRINTF("Unable to query grant table size."); + return rc; + } + + gnttab_frame_count =3D gnttab_query.max_nr_frames; + gnttab_status_frame_count =3D DIV_ROUNDUP( + gnttab_frame_count * (XC_DOM_PAGE_SIZE(dom) / sizeof(grant_entry_v= 2_t)), + XC_DOM_PAGE_SIZE(dom) / sizeof(grant_status_t)); + + for ( i =3D 0; i < dom->e820_entries; i++ ) + { + struct e820entry entry =3D dom->e820[i]; + rc =3D 0; + + switch ( entry.type ) { + case XEN_HVM_MEMMAP_TYPE_SHARED_INFO: + rc =3D xc_domain_add_to_physmap(xch, domid, XENMAPSPACE_shared= _info, + 0, entry.addr >> PAGE_SHIFT); + break; + case XEN_HVM_MEMMAP_TYPE_GRANT_TABLE: + if ( gnttab_frame_count !=3D entry.size >> PAGE_SHIFT ) + { + DOMPRINTF("Invalid grant table memmap region size"); + return -EINVAL; + } + + for ( i =3D 0; i < gnttab_frame_count; i++ ) + { + rc =3D xc_domain_add_to_physmap(xch, domid, XENMAPSPACE_gr= ant_table, i, + (entry.addr >> PAGE_SHIFT) += i); + =20 + if ( rc !=3D 0 ) + break; + } + break; + case XEN_HVM_MEMMAP_TYPE_GNTTAB_STATUS: + { + if ( gnttab_status_frame_count !=3D entry.size >> PAGE_SHIFT ) + { + DOMPRINTF("Invalid grant table status memmap region size"); + return -EINVAL; + } + + for ( i =3D 0; i < gnttab_status_frame_count; i++ ) + { + rc =3D xc_domain_add_to_physmap(xch, domid, XENMAPSPACE_gr= ant_table, + i | XENMAPIDX_grant_table_st= atus, + (entry.addr >> PAGE_SHIFT) += i); + =20 + if ( rc !=3D 0 ) + break; + } + break; + } + } + + if ( rc !=3D 0 ) + break; + } + + return rc; +} + static int alloc_magic_pages_hvm(struct xc_dom_image *dom) { unsigned long i; @@ -718,6 +794,14 @@ static int alloc_magic_pages_hvm(struct xc_dom_image *= dom) goto out; } =20 + rc =3D prepare_fixed_special_regions(xch, dom); + + if ( rc !=3D 0 ) + { + DOMPRINTF("Unable to prepare fixed special regions"); + goto out; + } + /* * Identity-map page table is required for running with CR0.PG=3D0 when * using Intel EPT. Create a 32-bit non-PAE page directory of superpag= es. diff --git a/tools/libs/light/libxl_create.c b/tools/libs/light/libxl_creat= e.c index 8a85fba1cf..5e23e122fc 100644 --- a/tools/libs/light/libxl_create.c +++ b/tools/libs/light/libxl_create.c @@ -2363,6 +2363,7 @@ int libxl_domain_create_restore(libxl_ctx *ctx, libxl= _domain_config *d_config, * configuration. */ libxl_defbool_setdefault(&d_config->b_info.arch_x86.msr_relaxed, true); + libxl_defbool_setdefault(&d_config->b_info.arch_x86.fixed_mem_layout, = false); libxl_defbool_setdefault(&d_config->b_info.u.hvm.pirq, true); =20 return do_domain_create(ctx, d_config, domid, restore_fd, send_back_fd, diff --git a/tools/libs/light/libxl_types.idl b/tools/libs/light/libxl_type= s.idl index a3a79d12b2..74edfdebc1 100644 --- a/tools/libs/light/libxl_types.idl +++ b/tools/libs/light/libxl_types.idl @@ -727,6 +727,7 @@ libxl_domain_build_info =3D Struct("domain_build_info",[ ("nr_spis", uint32, {'init_val': 'LIBXL_NR_= SPIS_DEFAULT'}), ])), ("arch_x86", Struct(None, [("msr_relaxed", libxl_defbool), + ("fixed_mem_layout", libxl_defbool), ])), # Alternate p2m is not bound to any architecture or guest type, as it = is # supported by x86 HVM and ARM support is planned. diff --git a/tools/libs/light/libxl_x86.c b/tools/libs/light/libxl_x86.c index 60d4e8661c..de19f722ab 100644 --- a/tools/libs/light/libxl_x86.c +++ b/tools/libs/light/libxl_x86.c @@ -1,6 +1,7 @@ #include "libxl_internal.h" #include "libxl_arch.h" #include +#include =20 int libxl__arch_domain_prepare_config(libxl__gc *gc, libxl_domain_config *d_config, @@ -50,6 +51,10 @@ static const char *e820_names(int type) case E820_ACPI: return "ACPI"; case E820_NVS: return "ACPI NVS"; case E820_UNUSABLE: return "Unusable"; + case XEN_HVM_MEMMAP_TYPE_SHARED_INFO: return "HVM Shared Info"; + case XEN_HVM_MEMMAP_TYPE_GRANT_TABLE: return "HVM Grant Table"; + case XEN_HVM_MEMMAP_TYPE_GNTTAB_STATUS: return "HVM Grant Status"; + case XEN_HVM_MEMMAP_TYPE_FOREIGN_REG: return "HVM Foreign mapping = region"; default: break; } return "Unknown"; @@ -686,10 +691,31 @@ static int domain_construct_memmap(libxl__gc *gc, /* We always own at least one lowmem entry. */ unsigned int e820_entries =3D 1; struct e820entry *e820 =3D NULL; + uint64_t highmem_start =3D ((uint64_t)1 << 32); uint64_t highmem_size =3D dom->highmem_end ? dom->highmem_end - (1ull << 32) : 0; uint32_t lowmem_start =3D dom->device_model ? GUEST_LOW_MEM_START_DEFA= ULT : 0; unsigned page_size =3D XC_DOM_PAGE_SIZE(dom); + /* Special region starts at the first 1G boundary after the highmem */ + uint64_t special_region_start =3D + (highmem_start + highmem_size + GB(1) - 1) & ~(GB(1) - 1); + uint64_t special_region_offset =3D special_region_start; + size_t gnttab_frame_count, gnttab_status_frame_count; + gnttab_query_size_t gnttab_query; + + gnttab_query.dom =3D domid; + rc =3D xc_gnttab_query_size(dom->xch, &gnttab_query); + + if (rc !=3D 0 || gnttab_query.status !=3D GNTST_okay) + { + gnttab_frame_count =3D 0; + gnttab_status_frame_count =3D 0; + } + + gnttab_frame_count =3D gnttab_query.max_nr_frames; + gnttab_status_frame_count =3D DIV_ROUNDUP( + gnttab_frame_count * (page_size / sizeof(grant_entry_v2_t)), + page_size / sizeof(grant_status_t)); =20 /* Add all rdm entries. */ for (i =3D 0; i < d_config->num_rdms; i++) @@ -703,6 +729,16 @@ static int domain_construct_memmap(libxl__gc *gc, /* If we should have a highmem range. */ if (highmem_size) e820_entries++; + =20 + if (libxl_defbool_val(d_config->b_info.arch_x86.fixed_mem_layout)) + { + e820_entries++; /* XEN_HVM_MEMMAP_TYPE_SHARED_INFO */ + if ( gnttab_frame_count ) + e820_entries++; /* XEN_HVM_MEMMAP_TYPE_GRANT_TABLE */ + if (d_config->b_info.max_grant_version >=3D 2 && gnttab_status_fra= me_count) + e820_entries++; /* XEN_HVM_MEMMAP_TYPE_GNTTAB_STATUS status */ + e820_entries++; /* XEN_HVM_MEMMAP_TYPE_FOREIGN_REG */ + } =20 for (i =3D 0; i < MAX_ACPI_MODULES; i++) if (dom->acpi_modules[i].length) @@ -769,6 +805,40 @@ static int domain_construct_memmap(libxl__gc *gc, e820[nr].type =3D E820_RAM; } =20 + /* Special regions */ + if (libxl_defbool_val(d_config->b_info.arch_x86.fixed_mem_layout)) + { + e820[nr].type =3D XEN_HVM_MEMMAP_TYPE_SHARED_INFO; + e820[nr].addr =3D special_region_offset; + e820[nr].size =3D page_size; + special_region_offset +=3D e820[nr].size; + nr++; + + if ( gnttab_frame_count ) + { + e820[nr].type =3D XEN_HVM_MEMMAP_TYPE_GRANT_TABLE; + e820[nr].addr =3D special_region_offset; + e820[nr].size =3D gnttab_frame_count * page_size; + special_region_offset +=3D e820[nr].size; + nr++; + } + + if (d_config->b_info.max_grant_version >=3D 2 && gnttab_status_fra= me_count) + { + e820[nr].type =3D XEN_HVM_MEMMAP_TYPE_GNTTAB_STATUS; + e820[nr].addr =3D special_region_offset; + e820[nr].size =3D gnttab_status_frame_count * page_size; + special_region_offset +=3D e820[nr].size; + nr++; + } + + e820[nr].type =3D XEN_HVM_MEMMAP_TYPE_FOREIGN_REG; + e820[nr].addr =3D special_region_offset; + e820[nr].size =3D MB(512); + special_region_offset +=3D e820[nr].size; + nr++; + } + if (xc_domain_set_memory_map(CTX->xch, domid, e820, e820_entries) !=3D= 0) { rc =3D ERROR_FAIL; goto out; @@ -819,6 +889,7 @@ int libxl__arch_domain_build_info_setdefault(libxl__gc = *gc, libxl_defbool_setdefault(&b_info->acpi, true); libxl_defbool_setdefault(&b_info->arch_x86.msr_relaxed, false); libxl_defbool_setdefault(&b_info->trap_unmapped_accesses, false); + libxl_defbool_setdefault(&b_info->arch_x86.fixed_mem_layout, false); =20 if (b_info->type =3D=3D LIBXL_DOMAIN_TYPE_HVM) { /* diff --git a/tools/xl/xl_parse.c b/tools/xl/xl_parse.c index 7e11c62ba0..a74cc577e9 100644 --- a/tools/xl/xl_parse.c +++ b/tools/xl/xl_parse.c @@ -2992,6 +2992,7 @@ skip_usbdev: "WARNING: msr_relaxed will be removed in future versio= ns.\n" "If it fixes an issue you are having please report to " "xen-devel@lists.xenproject.org.\n"); + xlu_cfg_get_defbool(config, "fixed_mem_layout", &b_info->arch_x86.fixe= d_mem_layout, 0); =20 xlu_cfg_get_defbool(config, "vpmu", &b_info->vpmu, 0); =20 diff --git a/xen/include/public/arch-x86/hvm/start_info.h b/xen/include/pub= lic/arch-x86/hvm/start_info.h index e33557c0b4..0b3dfe91af 100644 --- a/xen/include/public/arch-x86/hvm/start_info.h +++ b/xen/include/public/arch-x86/hvm/start_info.h @@ -99,6 +99,13 @@ #define XEN_HVM_MEMMAP_TYPE_DISABLED 6 #define XEN_HVM_MEMMAP_TYPE_PMEM 7 =20 +/* Xen-specific types (OEM-specific range of the ACPI spec) */ +#define XEN_HVM_MEMMAP_TYPE_SHARED_INFO 0xF0000001 /* Shared info page */ +#define XEN_HVM_MEMMAP_TYPE_GRANT_TABLE 0xF0000002 /* Grant table pages = */ +#define XEN_HVM_MEMMAP_TYPE_GNTTAB_STATUS 0xF0000003 /* Grant table status= page (v2) */ +#define XEN_HVM_MEMMAP_TYPE_FOREIGN_REG 0xF0000004 /* Suitable region fo= r grant mappings */ + /* and foreign mappin= gs */ + /* * C representation of the x86/HVM start info layout. * --=20 2.50.1 Teddy Astie | Vates XCP-ng Developer XCP-ng & Xen Orchestra - Vates solutions web: https://vates.tech From nobody Fri Oct 31 03:47:35 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass header.i=teddy.astie@vates.tech; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=reject dis=none) header.from=vates.tech ARC-Seal: i=1; a=rsa-sha256; t=1755789979; cv=none; d=zohomail.com; s=zohoarc; b=eB1Fb5yLyrDLq9CYbETkDkMERQXbcIfTKuuYCq26ncHzSZ2//yeomscjszrdMjcEOKbhb7uUhFc5tR6VPSKMUeRrmD7WRYfusBcrhMxAWJDRm1CUayiMdJcC+0hGVuaoeCpk/YV2LNKfzB2xgxXZ2HZizXks6fengvrkokHdg6Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1755789979; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=h1vxOINHJNHHsgrwETVtPerz1HMSIPiyHjC13CAZ9ok=; b=RqLGcmIRPol2uhaV4jGoh9tY0gV/rr5BNcOkG0ub7iHTP/p+ZMvbK1eK6hebPckhhK+vaRXVEAK90pkreCOkbLyFBGlK7p0xMpy0cGyQq7bUl8jo0CdKvQiCbXEi+094jTd4KRaH2xHhrejV0p6pZdnEffEdXJXIhRlSXgfSyMU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=teddy.astie@vates.tech; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1755789979325698.1606855792145; Thu, 21 Aug 2025 08:26:19 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1088818.1446561 (Exim 4.92) (envelope-from ) id 1up7Au-0006h2-2B; Thu, 21 Aug 2025 15:26:00 +0000 Received: by outflank-mailman (output) from mailman id 1088818.1446561; Thu, 21 Aug 2025 15:26:00 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1up7At-0006fq-U1; Thu, 21 Aug 2025 15:25:59 +0000 Received: by outflank-mailman (input) for mailman id 1088818; Thu, 21 Aug 2025 15:25:58 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1up7Ar-0005na-Ux for xen-devel@lists.xenproject.org; Thu, 21 Aug 2025 15:25:58 +0000 Received: from mail179-29.suw41.mandrillapp.com (mail179-29.suw41.mandrillapp.com [198.2.179.29]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 214c3140-7ea3-11f0-b898-0df219b8e170; Thu, 21 Aug 2025 17:25:55 +0200 (CEST) Received: from pmta12.mandrill.prod.suw01.rsglab.com (localhost [127.0.0.1]) by mail179-29.suw41.mandrillapp.com (Mailchimp) with ESMTP id 4c76bQ6yhPz7lmVSj for ; Thu, 21 Aug 2025 15:25:54 +0000 (GMT) Received: from [37.26.189.201] by mandrillapp.com id 841c9db552804ee1bbcff90c2e96fb43; Thu, 21 Aug 2025 15:25:54 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version 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: 214c3140-7ea3-11f0-b898-0df219b8e170 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mandrillapp.com; s=mte1; t=1755789955; x=1756059955; bh=h1vxOINHJNHHsgrwETVtPerz1HMSIPiyHjC13CAZ9ok=; h=From:Subject:To:Cc:Message-Id:In-Reply-To:References:Feedback-ID: Date:MIME-Version:Content-Type:Content-Transfer-Encoding:CC:Date: Subject:From; b=OSXUMs4TNk4CogPQwFVu5iA6nJRI0yKKWnJL39JE3+4vTgIDtDQ2p9zy3gAJzWIW8 enMIN2VM2zKr5zUPaPSTMNYL3d3faLqrN6eE/2EAjfc91fz4GuKEUqwMZa1UlFSitA ki8/CDvG4RwRi0zECF6v9/sVMj1QgJcYdGuFzzeSy/+H2yUrKWYjonOLaDloxMPauQ tZ8vsiiMVF9yh6y3YVf1ZjNJXOSVVOycUggDYGiJh4KZCC4Ikk6p8qOAq43S8cW+fp xs2NPsz96X9mPQzONhTVkYKa+gS3+GDnqsVhlsKU1DbtxyVEo62+YtZGfOa4HmRcZH WyT5tiqiM+flg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vates.tech; s=mte1; t=1755789955; x=1756050455; i=teddy.astie@vates.tech; bh=h1vxOINHJNHHsgrwETVtPerz1HMSIPiyHjC13CAZ9ok=; h=From:Subject:To:Cc:Message-Id:In-Reply-To:References:Feedback-ID: Date:MIME-Version:Content-Type:Content-Transfer-Encoding:CC:Date: Subject:From; b=p9YST2mu+RxKLaTz2ozkd1W5xi4S8wIQArxDjSZMqRaAgWnlCGhZoHIHlrViv1OqQ jgHdyaWElM41OWv2dbf5V4l7eEG1rz+arFzs424qOYC2Rj/U/bKih7Feqg30bKUczu 1ssknsJAehUuzezhIyCIaC0RKczPXHA4fvnpVL7J8BB4GnpvKE/asjwU40SbWMc92J MAVAgm9CjUZ0s/Bk2wvzPouiTO6j0srydk03Vdv5kusKNdbKXA58xkUTnyaV6DT7Vl oMXZxPQOvGcDre41zeEzmarZp80NPb5B7Rro5rygdTMTUgKosZcJUsVingcKbcuUzq CqqeA8JFYD5Gw== From: "Teddy Astie" Subject: =?utf-8?Q?[RFC=20PATCH=205/9]=20docs/x86:=20Introduce=20FastABI?= X-Mailer: git-send-email 2.50.1 X-Bm-Disclaimer: Yes X-Bm-Milter-Handled: 4ffbd6c1-ee69-4e1b-aabd-f977039bd3e2 X-Bm-Transport-Timestamp: 1755789953594 To: xen-devel@lists.xenproject.org Cc: "Teddy Astie" , "Andrew Cooper" , "Anthony PERARD" , "Michal Orzel" , "Jan Beulich" , "Julien Grall" , "=?utf-8?Q?Roger=20Pau=20Monn=C3=A9?=" , "Stefano Stabellini" Message-Id: <64800d22220f31bf052713ce61ecedeaa8a36b6f.1755785258.git.teddy.astie@vates.tech> In-Reply-To: References: X-Native-Encoded: 1 X-Report-Abuse: =?UTF-8?Q?Please=20forward=20a=20copy=20of=20this=20message,=20including=20all=20headers,=20to=20abuse@mandrill.com.=20You=20can=20also=20report=20abuse=20here:=20https://mandrillapp.com/contact/abuse=3Fid=3D30504962.841c9db552804ee1bbcff90c2e96fb43?= X-Mandrill-User: md_30504962 Feedback-ID: 30504962:30504962.20250821:md Date: Thu, 21 Aug 2025 15:25:54 +0000 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity teddy.astie@vates.tech) (identity @mandrillapp.com) X-ZM-MESSAGEID: 1755789982503124100 Content-Type: text/plain; charset="utf-8" FastABI is a alternative ABI designed with performance and coco-enabled guest in mind. It is register-oriented instead of refering to C structures in the guest memory (through a virtual memory pointer). It only focuses on kernel-side hypercalls, it doesn't aim to provide toolst= ack operations. Signed-off-by: Teddy Astie --- docs/guest-guide/x86/fastabi.pandoc | 50 ++++++++++ docs/guest-guide/x86/index.rst | 1 + xen/abi/event_channel.yml | 130 ++++++++++++++++++++++++++ xen/abi/grant_table.yml | 46 +++++++++ xen/abi/hvm.yml | 50 ++++++++++ xen/abi/memory.yml | 11 +++ xen/abi/sched.yml | 48 ++++++++++ xen/abi/vcpu.yml | 139 ++++++++++++++++++++++++++++ xen/abi/version.yml | 15 +++ xen/include/public/arch-x86/cpuid.h | 4 + 10 files changed, 494 insertions(+) create mode 100644 docs/guest-guide/x86/fastabi.pandoc create mode 100644 xen/abi/event_channel.yml create mode 100644 xen/abi/grant_table.yml create mode 100644 xen/abi/hvm.yml create mode 100644 xen/abi/memory.yml create mode 100644 xen/abi/sched.yml create mode 100644 xen/abi/vcpu.yml create mode 100644 xen/abi/version.yml diff --git a/docs/guest-guide/x86/fastabi.pandoc b/docs/guest-guide/x86/fas= tabi.pandoc new file mode 100644 index 0000000000..8ff8609f37 --- /dev/null +++ b/docs/guest-guide/x86/fastabi.pandoc @@ -0,0 +1,50 @@ +# x86 FastABI + +## Introduction + +FastABI is a alternative hypercall ABI designed with performance and confi= dential +computing enabled guests (AMD SEV, Intel TDX, ...) in mind. It provides a = minimal +subset of the traditional ABI that is sufficient for having a working gues= t. + +This hypercall interface is designed around using registers for passing hy= percall +parameters and outputs rather than using pointer to C structures, thus it = avoids +potentially complicated or expensive memory copies from/to the guest. + +This ABI currently only supports HVM/PVH and x86 long mode. + +Each hypercall operation interface is described in a parsable yaml file, w= hich +defines each hypercall suboperation inputs and outputs and eventual metada= ta for +code generation (e.g C stubs). + +## Support + +This interface is only supported if XEN_HVM_CPUID_FASTABI is set. + +## Semantics + +8 registers can be used as either input or output. + +Each hypercall operation (or sub-operation) defines its own set of used in= put and +output registers. There is no implicit clobbering of unused registers, i.e= input +registers are not allowed to be modified by the hypervisor unless it is ex= plicitely +also marked as a output (or cloberred register). + +- reg0: `rax`: IN: hypercall operation index, OUT: error code +- reg1: `rdi`: (if operation has sub-operations) IN: hypercall sub-operati= on index +- reg2: `rsi` +- reg3: `r8` +- reg4: `r9` +- reg5: `r10` +- reg6: `r11` +- reg7: `r12` + +`reg0` input is reserved for hypercall index. +In order to distinguish FastABI with traditional hypercalls or viridian hy= percalls, +reg0 input needs to be OR-ed with 0x40000000 (__HYPERVISOR_FASTABI_MASK). + +`reg0` output is reserved for standard hypercall return code (errno) or re= turned value. + +`reg1` input can be used for identifying a sub-operation. output is availa= ble for use. + +The hypercall uses the native hypercall instruction, which is `vmcall` on = Intel platforms +and `vmmcall` on AMD platforms. \ No newline at end of file diff --git a/docs/guest-guide/x86/index.rst b/docs/guest-guide/x86/index.rst index 6927271e53..aaae42da5a 100644 --- a/docs/guest-guide/x86/index.rst +++ b/docs/guest-guide/x86/index.rst @@ -7,4 +7,5 @@ x86 :maxdepth: 2 =20 hypercall-abi + fastabi fixed-memory-layout diff --git a/xen/abi/event_channel.yml b/xen/abi/event_channel.yml new file mode 100644 index 0000000000..44a769cdbb --- /dev/null +++ b/xen/abi/event_channel.yml @@ -0,0 +1,130 @@ +name: event_channel +hypercall_index: 32 + +subops: + alloc_unbound: + index: 6 + input: + dom: 2 + remote_dom: 3 + output: + port: 4 + c_lang: + struct: evtchn_alloc_unbound + + bind_interdomain: + index: 0 + input: + remote_dom: 2 + remote_port: 3 + output: + local_port: 4 + c_lang: + struct: evtchn_bind_interdomain + + bind_virq: + index: 1 + input: + virq: 2 + vcpu: 3 + output: + port: 4 + c_lang: + struct: evtchn_bind_virq + + bind_ipi: + index: 7 + input: + vcpu: 2 + output: + port: 4 + c_lang: + struct: evtchn_bind_ipi + + bind_pirq: + index: 2 + input: + pirq: 2 + flags: 3 + output: + port: 4 + c_lang: + struct: evtchn_bind_pirq + =20 + close: + index: 3 + input: + port: 2 + c_lang: + struct: evtchn_close + =20 + send: + index: 4 + input: + port: 2 + c_lang: + struct: evtchn_send + + status: + index: 5 + input: + dom: 2 + port: 3 + output: + status: 4 + vcpu: 5 + output1: 6 + output2: 7 + c_lang: + struct: evtchn_status + mapping: + output1: u._output1 + output2: u._output2 + =20 + bind_vcpu: + index: 8 + input: + vcpu: 2 + port: 3 + c_lang: + struct: evtchn_bind_vcpu + =20 + unmask: + index: 9 + input: + port: 2 + c_lang: + struct: evtchn_unmask + =20 + reset: + index: 10 + input: + dom: 2 + c_lang: + struct: evtchn_reset + + init_control: + index: 11 + input: + control_gfn: 2 + offset: 3 + vcpu: 4 + output: + link_bits: 5 + c_lang: + struct: evtchn_init_control + =20 + expand_array: + index: 12 + input: + array_gfn: 2 + c_lang: + struct: evtchn_expand_array + + set_priority: + index: 13 + input: + port: 2 + priority: 3 + c_lang: + struct: evtchn_set_priority diff --git a/xen/abi/grant_table.yml b/xen/abi/grant_table.yml new file mode 100644 index 0000000000..bcedaa966b --- /dev/null +++ b/xen/abi/grant_table.yml @@ -0,0 +1,46 @@ +name: grant_table +hypercall_index: 20 + +subops: + map_grant_ref: + index: 0 + input: + dom: 2 + host_addr: 3 + flags: 4 + ref: 5 + output: + handle: 6 + status: 7 + c_lang: + struct: gnttab_map_grant_ref + =20 + unmap_grant_ref: + index: 1 + input: + host_addr: 3 + handle: 6 + c_lang: + struct: gnttab_unmap_grant_ref + =20 + query_size: + index: 6 + output: + nr_frames: 2 + max_nr_frames: 3 + c_lang: + struct: gnttab_query_size + + set_version: + index: 8 + input: + version: 2 + c_lang: + struct: gnttab_set_version + + get_version: + index: 10 + output: + version: 2 + c_lang: + struct: gnttab_get_version diff --git a/xen/abi/hvm.yml b/xen/abi/hvm.yml new file mode 100644 index 0000000000..20c2421bdf --- /dev/null +++ b/xen/abi/hvm.yml @@ -0,0 +1,50 @@ +name: hvm +hypercall_index: 34 + +subops: + set_param: + index: 0 + input: + domid: 2 + index: 3 + value: 4 + c_lang: + struct: xen_hvm_param + + get_param: + index: 1 + input: + domid: 2 + index: 3 + output: + value: 4 + c_lang: + struct: xen_hvm_param + + flush_tlbs: + index: 5 + + get_time: + index: 10 + output: + now: 2 + c_lang: + struct: xen_hvm_get_time + + get_mem_type: + index: 15 + input: + domid: 2 + pfn: 3 + output: + mem_type: 4 + c_lang: + struct: xen_hvm_get_mem_type + + set_evtchn_upcall_vector: + index: 23 + input: + vcpu: 2 + vector: 3 + c_lang: + struct: xen_hvm_evtchn_upcall_vector diff --git a/xen/abi/memory.yml b/xen/abi/memory.yml new file mode 100644 index 0000000000..8b51490f8a --- /dev/null +++ b/xen/abi/memory.yml @@ -0,0 +1,11 @@ +name: memory +hypercall_index: 12 + +subops: + memory_map: + index: 9 + input: + nr_entries: 2 + buffer: 3 + c_lang: + struct: xen_memory_map diff --git a/xen/abi/sched.yml b/xen/abi/sched.yml new file mode 100644 index 0000000000..1b1ef50c7a --- /dev/null +++ b/xen/abi/sched.yml @@ -0,0 +1,48 @@ +name: sched +hypercall_index: 29 + +subops: + yield: + index: 0 + + block: + index: 1 + + shutdown: + index: 2 + input: + reason: 2 + c_lang: + struct: sched_shutdown + + poll: + index: 3 + input: + timeout: 2 + port: 3 + c_lang: + params: + timeout: uint64_t + port: evtchn_port_t + + shutdown_code: + index: 5 + input: + reason: 2 + c_lang: + struct: sched_shutdown + + watchdog: + index: 6 + input: + id: 2 + timeout: 3 + c_lang: + struct: sched_watchdog + + pin_override: + index: 7 + input: + pcpu: 2 + c_lang: + struct: sched_pin_override diff --git a/xen/abi/vcpu.yml b/xen/abi/vcpu.yml new file mode 100644 index 0000000000..0b4fe4ea1f --- /dev/null +++ b/xen/abi/vcpu.yml @@ -0,0 +1,139 @@ +name: vcpu +hypercall_index: 24 + +subops: + initialise: + index: 0 + input: + vcpuid: 2 + context_gfn: 3 + c_lang: + params: + vcpuid: uint32_t + context_gfn: uint64_t + + up: + index: 1 + input: + vcpuid: 2 + c_lang: + params: + vcpuid: uint32_t + + down: + index: 2 + input: + vcpuid: 2 + c_lang: + params: + vcpuid: uint32_t + + is_up: + index: 3 + input: + vcpuid: 2 + c_lang: + params: + vcpuid: uint32_t + + get_runstate_info: + index: 4 + input: + vcpuid: 2 + output: + state: 2 + state_entry_time: 3 + time[0]: 4 + time[1]: 5 + time[2]: 6 + time[3]: 7 + c_lang: + struct: vcpu_runstate_info + params: + vcpuid: uint32_t + + register_runstate_phys_area: + index: 14 + input: + vcpuid: 2 + addr.p: 3 + c_lang: + struct: vcpu_register_time_memory_area + params: + vcpuid: uint32_t + + set_periodic_timer: + index: 6 + input: + vcpuid: 2 + period_ns: 3 + c_lang: + struct: vcpu_set_periodic_timer + params: + vcpuid: uint32_t + + stop_periodic_timer: + index: 7 + input: + vcpuid: 2 + c_lang: + params: + vcpuid: uint32_t + =20 + set_singleshot_timer: + index: 8 + input: + vcpuid: 2 + timeout_abs_ns: 3 + flags: 4 + c_lang: + struct: vcpu_set_singleshot_timer + params: + vcpuid: uint32_t + + stop_singleshot_timer: + index: 9 + input: + vcpuid: 2 + c_lang: + params: + vcpuid: uint32_t + + register_vcpu_info: + index: 10 + input: + vcpuid: 2 + mfn: 3 + offset: 4 + c_lang: + struct: vcpu_register_vcpu_info + params: + vcpuid: uint32_t + + send_nmi: + index: 11 + input: + vcpuid: 2 + c_lang: + params: + vcpuid: uint32_t + + get_physid: + index: 12 + input: + vcpuid: 2 + phys_id: 3 + c_lang: + struct: vcpu_get_physid + params: + vcpuid: uint32_t + + register_vcpu_time_phys_area: + index: 15 + input: + vcpuid: 2 + addr.p: 3 + c_lang: + struct: vcpu_register_time_memory_area + params: + vcpuid: uint32_t diff --git a/xen/abi/version.yml b/xen/abi/version.yml new file mode 100644 index 0000000000..bce64a4d69 --- /dev/null +++ b/xen/abi/version.yml @@ -0,0 +1,15 @@ +name: version +hypercall_index: 17 + +subops: + version: + index: 0 + + get_features: + index: 6 + input: + submap_idx: 2 + output: + submap: 3 + c_lang: + struct: xen_feature_info diff --git a/xen/include/public/arch-x86/cpuid.h b/xen/include/public/arch-= x86/cpuid.h index 3bb0dd249f..ff44ce0e7b 100644 --- a/xen/include/public/arch-x86/cpuid.h +++ b/xen/include/public/arch-x86/cpuid.h @@ -106,6 +106,10 @@ * bound to event channels. */ #define XEN_HVM_CPUID_UPCALL_VECTOR (1u << 6) +/* + * Support for fast HVM ABI. + */ +#define XEN_HVM_CPUID_FASTABI (1u << 7) =20 /* * Leaf 6 (0x40000x05) --=20 2.50.1 Teddy Astie | Vates XCP-ng Developer XCP-ng & Xen Orchestra - Vates solutions web: https://vates.tech From nobody Fri Oct 31 03:47:35 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass header.i=teddy.astie@vates.tech; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=reject dis=none) header.from=vates.tech ARC-Seal: i=1; a=rsa-sha256; t=1755789980; cv=none; d=zohomail.com; s=zohoarc; b=Sogv4y+3NsjaBcOtk1fcCfGkKMpciC7U0gV74ekNczdneS4rtszTsBk1mwHBCJT6RdkHKDr3+VnAwASUJtTKa4GgdvhH9WltTsVXnbqi9k8INJs1/xo7AEMK8Qrcrcw0syVxptdbEUDPTxHZWfpIViZiqtD4eH+h/CObDYZ9IOc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1755789980; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=/Czx8f0L7Yqqc5qG+Tcn2zb8zTijEnp/eSv/Biuz900=; b=eDYsUb1UWS49+uRllL461gzPkixUmXmuoNhAGBpkqwRVtEARul9UbcElbIzFH0VgtVS8gi/R0I8AVdk8U63QtXqxcXcc89NCRJXDqve+SuYX52BOzc5RKGpX0K7FGBwS1iWNGGS2zgll4od5cvNJkd8vAnNYDNxUJoHVj3mQC+0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=teddy.astie@vates.tech; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1755789980268580.1979759036217; Thu, 21 Aug 2025 08:26:20 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1088820.1446572 (Exim 4.92) (envelope-from ) id 1up7Au-0006qD-S2; Thu, 21 Aug 2025 15:26:00 +0000 Received: by outflank-mailman (output) from mailman id 1088820.1446572; Thu, 21 Aug 2025 15:26:00 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1up7Au-0006o8-JM; Thu, 21 Aug 2025 15:26:00 +0000 Received: by outflank-mailman (input) for mailman id 1088820; Thu, 21 Aug 2025 15:25:58 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1up7As-0005nU-Pv for xen-devel@lists.xenproject.org; Thu, 21 Aug 2025 15:25:58 +0000 Received: from mail137-3.atl71.mandrillapp.com (mail137-3.atl71.mandrillapp.com [198.2.137.3]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 22aa5e85-7ea3-11f0-a32b-13f23c93f187; Thu, 21 Aug 2025 17:25:58 +0200 (CEST) Received: from pmta07.mandrill.prod.atl01.rsglab.com (localhost [127.0.0.1]) by mail137-3.atl71.mandrillapp.com (Mailchimp) with ESMTP id 4c76bQ578pzBsW3G6 for ; Thu, 21 Aug 2025 15:25:54 +0000 (GMT) Received: from [37.26.189.201] by mandrillapp.com id bb370819b5b149d495099cb9f5ca2153; Thu, 21 Aug 2025 15:25:54 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version 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: 22aa5e85-7ea3-11f0-a32b-13f23c93f187 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mandrillapp.com; s=mte1; t=1755789954; x=1756059954; bh=/Czx8f0L7Yqqc5qG+Tcn2zb8zTijEnp/eSv/Biuz900=; h=From:Subject:To:Cc:Message-Id:In-Reply-To:References:Feedback-ID: Date:MIME-Version:Content-Type:Content-Transfer-Encoding:CC:Date: Subject:From; b=WTdQR4K5L6BWIfPcdAWHFo0zZvCS4cAGVXGqbSZRmQgmqt4mLDZ+qxvrQ//3XpzIL j2pdIi5GDO4gEmn+YXMW1NGjeCAfVljMIHyQSXtM4acroEuDLA0p5sIIfYsg2X1uGd 9xqP35TTNZqteTbS+5orl0fedIpEnTWcbMPt/rMhDmd7oADFH5Iz446INNDovqrkS8 XTIFX+OXvRTe4jx79YVhRzI9JOZxrmdRBYqmGZ7WZrU3HZLJa9lCN5SraG7vMWSpdx odlEYRurFBRA8M0lPVXZgcfm5fJIIuP4vpbrCOtQudGBTNoj4TQY6ZNIXuUX9qm1CM AqbBYevNr4Nlw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vates.tech; s=mte1; t=1755789954; x=1756050454; i=teddy.astie@vates.tech; bh=/Czx8f0L7Yqqc5qG+Tcn2zb8zTijEnp/eSv/Biuz900=; h=From:Subject:To:Cc:Message-Id:In-Reply-To:References:Feedback-ID: Date:MIME-Version:Content-Type:Content-Transfer-Encoding:CC:Date: Subject:From; b=amLby1t3+xc6rNfVfowZdIU5xG+rg2l/Cq2si2st6wdmErRVoTUjuzzWzYqhINqg4 tuO/pScW/vzzwflpVCM8OR2rIBOtCtAz43RY/rJQiOR9OQ9EOyXxWm5TFMJPfwMQAC dkt1j7vTF3UrXgIg3ic47eyuAM8c3Uve5hlDKJCZOmLm6GYydGKWU/en7KMnpl9ct3 Bki/KHKQeFv+S6zB5qSXF3Uh1bIFkRLVR/76t86CejQuFW/73ZnDUeBVt992S1OpiD 6bFTInLWMKlLpREFgJvnU6G8+nXoUDQg2qpt9Mwdnni1XT+r8TDNuTsfdp70Oo+IZg sw2uxeWbfX+zA== From: "Teddy Astie" Subject: =?utf-8?Q?[RFC=20PATCH=206/9]=20sched:=20Extract=20do=5Fpoll=20main=20logic=20into=20vcpu=5Fpoll?= X-Mailer: git-send-email 2.50.1 X-Bm-Disclaimer: Yes X-Bm-Milter-Handled: 4ffbd6c1-ee69-4e1b-aabd-f977039bd3e2 X-Bm-Transport-Timestamp: 1755789954201 To: xen-devel@lists.xenproject.org Cc: "Teddy Astie" , "Dario Faggioli" , "Juergen Gross" , "George Dunlap" Message-Id: <812a818e263cb8287634cea5241fe076beacc39f.1755785258.git.teddy.astie@vates.tech> In-Reply-To: References: X-Native-Encoded: 1 X-Report-Abuse: =?UTF-8?Q?Please=20forward=20a=20copy=20of=20this=20message,=20including=20all=20headers,=20to=20abuse@mandrill.com.=20You=20can=20also=20report=20abuse=20here:=20https://mandrillapp.com/contact/abuse=3Fid=3D30504962.bb370819b5b149d495099cb9f5ca2153?= X-Mandrill-User: md_30504962 Feedback-ID: 30504962:30504962.20250821:md Date: Thu, 21 Aug 2025 15:25:54 +0000 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @mandrillapp.com) (identity teddy.astie@vates.tech) X-ZM-MESSAGEID: 1755789981439116600 Content-Type: text/plain; charset="utf-8" do_poll takes sched_poll* as parameter, but that's actually in guest memory (so it's more a guest handle). Split its copy from/to guest logic from the main logic, so that we have a separate vcpu_poll which takes the sched_= poll parameters directly. Signed-off-by: Teddy Astie --- xen/common/sched/core.c | 40 +++++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/xen/common/sched/core.c b/xen/common/sched/core.c index 13fdf57e57..b2c784c60e 100644 --- a/xen/common/sched/core.c +++ b/xen/common/sched/core.c @@ -1437,21 +1437,13 @@ static void vcpu_block_enable_events(void) vcpu_block(); } =20 -static long do_poll(const struct sched_poll *sched_poll) +static long vcpu_poll(unsigned int nr_ports, uint64_t timeout, evtchn_port= _t *ports) { struct vcpu *v =3D current; struct domain *d =3D v->domain; - evtchn_port_t port =3D 0; long rc; unsigned int i; =20 - /* Fairly arbitrary limit. */ - if ( sched_poll->nr_ports > 128 ) - return -EINVAL; - - if ( !guest_handle_okay(sched_poll->ports, sched_poll->nr_ports) ) - return -EFAULT; - set_bit(_VPF_blocked, &v->pause_flags); v->poll_evtchn =3D -1; set_bit(v->vcpu_id, d->poll_mask); @@ -1478,13 +1470,9 @@ static long do_poll(const struct sched_poll *sched_p= oll) if ( local_events_need_delivery() ) goto out; =20 - for ( i =3D 0; i < sched_poll->nr_ports; i++ ) + for ( i =3D 0; i < nr_ports; i++ ) { - rc =3D -EFAULT; - if ( __copy_from_guest_offset(&port, sched_poll->ports, i, 1) ) - goto out; - - rc =3D evtchn_port_poll(d, port); + rc =3D evtchn_port_poll(d, ports[i]); if ( rc ) { if ( rc > 0 ) @@ -1493,11 +1481,11 @@ static long do_poll(const struct sched_poll *sched_= poll) } } =20 - if ( sched_poll->nr_ports =3D=3D 1 ) - v->poll_evtchn =3D port; + if ( nr_ports =3D=3D 1 ) + v->poll_evtchn =3D ports[0]; =20 - if ( sched_poll->timeout !=3D 0 ) - set_timer(&v->poll_timer, sched_poll->timeout); + if ( timeout !=3D 0 ) + set_timer(&v->poll_timer, timeout); =20 TRACE_TIME(TRC_SCHED_BLOCK, d->domain_id, v->vcpu_id); raise_softirq(SCHEDULE_SOFTIRQ); @@ -1511,6 +1499,20 @@ static long do_poll(const struct sched_poll *sched_p= oll) return rc; } =20 +static long do_poll(struct sched_poll *sched_poll) +{ + evtchn_port_t ports[128]; + + /* Fairly arbitrary limit */ + if ( sched_poll->nr_ports > 128 ) + return -EINVAL; + + if ( copy_from_guest(ports, sched_poll->ports, sched_poll->nr_ports) ) + return -EFAULT; + + return vcpu_poll(sched_poll->nr_ports, sched_poll->timeout, ports); +} + /* Voluntarily yield the processor for this allocation. */ long vcpu_yield(void) { --=20 2.50.1 Teddy Astie | Vates XCP-ng Developer XCP-ng & Xen Orchestra - Vates solutions web: https://vates.tech From nobody Fri Oct 31 03:47:35 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass header.i=teddy.astie@vates.tech; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=reject dis=none) header.from=vates.tech ARC-Seal: i=1; a=rsa-sha256; t=1755789985; cv=none; d=zohomail.com; s=zohoarc; b=mNdYyRGxVfumHTpu2w43GrO/549vaOm2xvUqtJmq1HCq/x1F2lUOxLqRx1OW+80aiRKPgH5y9dXnp0Y4V86BjdBXDF7HqjdNIxScbtmmt7wfviqBqv8ekHl1W8p32TEG7XWGS6EurpxIbAo/5/WDgAjNKXf/mYYRpKvHtx7s3vM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1755789985; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=NmIuO1pdpbmW3k7cBEiWCdpAQ2G3SKKK5JzTVol4PfM=; b=T2PhRV/2Zt9rsV1dXWdO4cLl5CHdSKNmoMHaYp8ESYQCIiN6pACl3+pUaIIpf/nL0UD4TkpdYHI76ID6xGserYzZKykPLRmvDE5iBR2myzCoNtIskRtsfAey98m/dXJwUszBuDWAf5Pbgoy+uV3kn2CPvjZIGZxikfIlu79CdlU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=teddy.astie@vates.tech; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1755789985974685.2260393181751; Thu, 21 Aug 2025 08:26:25 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1088821.1446578 (Exim 4.92) (envelope-from ) id 1up7Av-00070x-FI; Thu, 21 Aug 2025 15:26:01 +0000 Received: by outflank-mailman (output) from mailman id 1088821.1446578; Thu, 21 Aug 2025 15:26:01 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1up7Av-0006yV-9x; Thu, 21 Aug 2025 15:26:01 +0000 Received: by outflank-mailman (input) for mailman id 1088821; Thu, 21 Aug 2025 15:26:00 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1up7At-0005nU-Q7 for xen-devel@lists.xenproject.org; Thu, 21 Aug 2025 15:26:00 +0000 Received: from mail137-3.atl71.mandrillapp.com (mail137-3.atl71.mandrillapp.com [198.2.137.3]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 23730422-7ea3-11f0-a32b-13f23c93f187; Thu, 21 Aug 2025 17:25:58 +0200 (CEST) Received: from pmta07.mandrill.prod.atl01.rsglab.com (localhost [127.0.0.1]) by mail137-3.atl71.mandrillapp.com (Mailchimp) with ESMTP id 4c76bS5vfQzBsVD7L for ; Thu, 21 Aug 2025 15:25:56 +0000 (GMT) Received: from [37.26.189.201] by mandrillapp.com id a995d3371d0e467594b68952f829b548; Thu, 21 Aug 2025 15:25:56 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version 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: 23730422-7ea3-11f0-a32b-13f23c93f187 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mandrillapp.com; s=mte1; t=1755789956; x=1756059956; bh=NmIuO1pdpbmW3k7cBEiWCdpAQ2G3SKKK5JzTVol4PfM=; h=From:Subject:To:Cc:Message-Id:In-Reply-To:References:Feedback-ID: Date:MIME-Version:Content-Type:Content-Transfer-Encoding:CC:Date: Subject:From; b=hefq1bT3PwkO2n1bV6dWVWcWp0BSnpsmV09jCqOOKrDIbrz96OGjcKPQtpZ5xehZp KD6Dal0mWLu2ZYl4jOdgMEzkLKvodaCjcsMUmEaviXrqOqJnPBprwD4f7eWIsW1IGU irz+0+U3iKwyEkyhBGBrdB7wBp9Kia3fAQ6DUWyJyQ3uj7jifkU9xNkkW657Pfi9ou 9zH9/rj4NgPHF0SYdeEjba/v1mr1mxUx+1MU8QQvBvf1qmMYq1S9TQAq+ikYtWajGR hdY01G846+Cgtc3hOrmxIaqtyTjt+lBCMzHXxth9UAdGRXci0v+c8efoiMcGFK4iwW VsUGrrTuBuBbQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vates.tech; s=mte1; t=1755789956; x=1756050456; i=teddy.astie@vates.tech; bh=NmIuO1pdpbmW3k7cBEiWCdpAQ2G3SKKK5JzTVol4PfM=; h=From:Subject:To:Cc:Message-Id:In-Reply-To:References:Feedback-ID: Date:MIME-Version:Content-Type:Content-Transfer-Encoding:CC:Date: Subject:From; b=eTE+uSD1oaYojVAl2HYVExe5iaYtwTw0MKMvtrrQ986jgBxuAylwEOaQwVzxwWHV/ q1MyAR2OLxTbne6nbB0dlyQ+oBucKDt1qbyH0+kbrFHwHJFWHFkZERtnjDsYNlfjks vEdz8jD0ZcxD5446S2bzqgIWIzwY2zmvwN7POpACFCMqZ9cz9+b6CLCrjDTYyZEAU5 eNQi+ab0vkX5zilGG+Z0KxGMvIeSzuLgZp8jpTdmUP6T9fIsEUGLcPgctLznADJbno dPXaZqW/ihoCHxsgHRTS4aVlbjNh+JiALCUGoG0Yuz8vgZX5rE7OHZ4+yw79bYMGRN Vw+9aMaxjs/eQ== From: "Teddy Astie" Subject: =?utf-8?Q?[RFC=20PATCH=207/9]=20x86/hvm:=20Introduce=20FastABI=20implementation?= X-Mailer: git-send-email 2.50.1 X-Bm-Disclaimer: Yes X-Bm-Milter-Handled: 4ffbd6c1-ee69-4e1b-aabd-f977039bd3e2 X-Bm-Transport-Timestamp: 1755789955039 To: xen-devel@lists.xenproject.org Cc: "Teddy Astie" , "Jan Beulich" , "Andrew Cooper" , "=?utf-8?Q?Roger=20Pau=20Monn=C3=A9?=" , "Anthony PERARD" , "Michal Orzel" , "Julien Grall" , "Stefano Stabellini" , "Dario Faggioli" , "Juergen Gross" , "George Dunlap" , "Daniel P. Smith" Message-Id: <9da7d600c7cb6c4334f3e01b7724ad106930bc6e.1755785258.git.teddy.astie@vates.tech> In-Reply-To: References: X-Native-Encoded: 1 X-Report-Abuse: =?UTF-8?Q?Please=20forward=20a=20copy=20of=20this=20message,=20including=20all=20headers,=20to=20abuse@mandrill.com.=20You=20can=20also=20report=20abuse=20here:=20https://mandrillapp.com/contact/abuse=3Fid=3D30504962.a995d3371d0e467594b68952f829b548?= X-Mandrill-User: md_30504962 Feedback-ID: 30504962:30504962.20250821:md Date: Thu, 21 Aug 2025 15:25:56 +0000 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity teddy.astie@vates.tech) (identity @mandrillapp.com) X-ZM-MESSAGEID: 1755789988908124100 Content-Type: text/plain; charset="utf-8" Implement FastABI basing on docs/guest-guide/x86/fastabi.pandoc and defined= ABI. Signed-off-by: Teddy Astie --- xen/arch/x86/cpuid.c | 3 + xen/arch/x86/domain.c | 71 ++++++++++ xen/arch/x86/hvm/hvm.c | 81 +++++++++++- xen/arch/x86/hvm/hypercall.c | 22 ++++ xen/arch/x86/include/asm/fastabi.h | 17 +++ xen/common/Kconfig | 6 + xen/common/Makefile | 1 + xen/common/domain.c | 179 ++++++++++++++++++++++++++ xen/common/event_channel.c | 199 +++++++++++++++++++++++++++++ xen/common/fastabi.c | 49 +++++++ xen/common/grant_table.c | 44 +++++++ xen/common/kernel.c | 33 +++++ xen/common/memory.c | 110 ++++++++++++++++ xen/common/sched/core.c | 109 +++++++++++++++- xen/include/public/event_channel.h | 7 + xen/include/public/fastabi.h | 20 +++ xen/include/xen/fastabi.h | 21 +++ 17 files changed, 970 insertions(+), 2 deletions(-) create mode 100644 xen/arch/x86/include/asm/fastabi.h create mode 100644 xen/common/fastabi.c create mode 100644 xen/include/public/fastabi.h create mode 100644 xen/include/xen/fastabi.h diff --git a/xen/arch/x86/cpuid.c b/xen/arch/x86/cpuid.c index 8dc68945f7..b1f90c1d91 100644 --- a/xen/arch/x86/cpuid.c +++ b/xen/arch/x86/cpuid.c @@ -153,6 +153,9 @@ static void cpuid_hypervisor_leaves(const struct vcpu *= v, uint32_t leaf, */ res->a |=3D XEN_HVM_CPUID_UPCALL_VECTOR; =20 + if ( IS_ENABLED(CONFIG_FASTABI) && is_hvm_vcpu(v) ) + res->a |=3D XEN_HVM_CPUID_FASTABI; + break; =20 case 5: /* PV-specific parameters */ diff --git a/xen/arch/x86/domain.c b/xen/arch/x86/domain.c index 56c3816187..44416869a3 100644 --- a/xen/arch/x86/domain.c +++ b/xen/arch/x86/domain.c @@ -71,6 +71,10 @@ #include #include =20 +#ifdef CONFIG_FASTABI +#include +#endif + #ifdef CONFIG_COMPAT #include #endif @@ -1695,6 +1699,73 @@ long do_vcpu_op(int cmd, unsigned int vcpuid, XEN_GU= EST_HANDLE_PARAM(void) arg) return rc; } =20 +#ifdef CONFIG_FASTABI +void do_vcpu_fast_op(struct cpu_user_regs *regs) +{ + long rc =3D 0; + struct domain *d =3D current->domain; + struct vcpu *v; + + unsigned long cmd =3D fastabi_value_n(regs, 1); + unsigned long vcpuid =3D fastabi_value_n(regs, 2); + + if ( (v =3D domain_vcpu(d, vcpuid)) =3D=3D NULL ) + { + fastabi_value_n(regs, 0) =3D -ENOENT; + return; + } + + switch ( cmd ) + { + case VCPUOP_send_nmi: + if ( !test_and_set_bool(v->arch.nmi_pending) ) + vcpu_kick(v); + break; + + + case VCPUOP_register_vcpu_time_phys_area: + { + struct vcpu_register_time_memory_area area =3D { + .addr.p =3D fastabi_value_n(regs, 3) + }; + + rc =3D -ENOSYS; + if ( 0 /* TODO: Dom's XENFEAT_vcpu_time_phys_area setting */ ) + break; + + rc =3D map_guest_area(v, area.addr.p, + sizeof(vcpu_time_info_t), + &v->arch.time_guest_area, + time_area_populate); + break; + } + + case VCPUOP_get_physid: + { + rc =3D -EINVAL; + if ( !is_hwdom_pinned_vcpu(v) ) + break; + + fastabi_value_n(regs, 3) =3D + (uint64_t)x86_cpu_to_apicid[v->vcpu_id] | + ((uint64_t)acpi_get_processor_id(v->vcpu_id) << 32); + + rc =3D 0; + break; + } + + default: + rc =3D common_vcpu_fast_op(regs, cmd, v); + break; + } + + if ( rc =3D=3D -ERESTART ) + fastabi_make_continuation(); + else + fastabi_value_n(regs, 0) =3D rc; +} +#endif + /* * Notes on PV segment handling: * - 32bit: All data from the GDT/LDT. diff --git a/xen/arch/x86/hvm/hvm.c b/xen/arch/x86/hvm/hvm.c index 8bf59c63fe..eca052e109 100644 --- a/xen/arch/x86/hvm/hvm.c +++ b/xen/arch/x86/hvm/hvm.c @@ -68,6 +68,10 @@ =20 #include =20 +#ifdef CONFIG_FASTABI +#include +#endif + bool __read_mostly hvm_enabled; =20 #ifdef DBG_LEVEL_0 @@ -4548,7 +4552,7 @@ static int hvmop_get_param(struct xen_hvm_param *op) =20 rc =3D -EINVAL; if ( is_hvm_domain(d) && !(rc =3D hvm_get_param(d, op->index, &op->val= ue)) ) - HVM_DBG_LOG(DBG_LEVEL_HCALL, "get param %u =3D %"PRIx64, a.index, = a.value); + HVM_DBG_LOG(DBG_LEVEL_HCALL, "get param %u =3D %"PRIx64, op->index= , op->value); =20 rcu_unlock_domain(d); return rc; @@ -5224,6 +5228,81 @@ long do_hvm_op(unsigned long op, XEN_GUEST_HANDLE_PA= RAM(void) arg) return rc; } =20 +#ifdef CONFIG_FASTABI +void do_hvm_fast_op(struct cpu_user_regs *regs) +{ + long rc =3D 0; + unsigned long op =3D fastabi_value_n(regs, 1); + + switch ( op ) + { + case HVMOP_set_evtchn_upcall_vector: + { + struct xen_hvm_evtchn_upcall_vector op =3D { + .vcpu =3D fastabi_value_n(regs, 2), + .vector =3D fastabi_value_n(regs, 3), + }; + + rc =3D hvmop_set_evtchn_upcall_vector(op); + break; + } + + case HVMOP_set_param: + { + struct xen_hvm_param op =3D { + .domid =3D fastabi_value_n(regs, 2), + .index =3D fastabi_value_n(regs, 3), + .value =3D fastabi_value_n(regs, 4), + }; + + rc =3D hvmop_set_param(op); + break; + } + + case HVMOP_get_param: + { + struct xen_hvm_param op =3D { + .domid =3D fastabi_value_n(regs, 2), + .index =3D fastabi_value_n(regs, 3), + }; + + rc =3D hvmop_get_param(&op); + if ( !rc ) + fastabi_value_n(regs, 4) =3D op.value; + break; + } + + case HVMOP_flush_tlbs: + rc =3D hvmop_flush_tlb_all(); + break; + + case HVMOP_get_time: + fastabi_value_n(regs, 2) =3D NOW(); + break; + =20 + case HVMOP_get_mem_type: + { + struct xen_hvm_get_mem_type op =3D { + .domid =3D fastabi_value_n(regs, 2), + .pfn =3D fastabi_value_n(regs, 3), + }; + + rc =3D hvmop_get_mem_type(&op); + + if ( !rc ) + fastabi_value_n(regs, 4) =3D op.mem_type; + break; + } + + default: + rc =3D -ENOSYS; + break; + } + + fastabi_value_n(regs, 0) =3D rc; +} +#endif + int hvm_debug_op(struct vcpu *v, int32_t op) { int rc =3D 0; diff --git a/xen/arch/x86/hvm/hypercall.c b/xen/arch/x86/hvm/hypercall.c index 6f8dfdff4a..3759a1aa58 100644 --- a/xen/arch/x86/hvm/hypercall.c +++ b/xen/arch/x86/hvm/hypercall.c @@ -19,6 +19,10 @@ #include #include =20 +#ifdef CONFIG_FASTABI +#include +#endif + long hvm_memory_op(unsigned long cmd, XEN_GUEST_HANDLE_PARAM(void) arg) { long rc; @@ -155,6 +159,24 @@ int hvm_hypercall(struct cpu_user_regs *regs) =20 curr->hcall_preempted =3D false; =20 + #ifdef CONFIG_FASTABI + if ( eax & 0x40000000U && is_hvm_domain(currd) && mode =3D=3D X86_MODE= _64BIT ) + { + unsigned long index =3D eax & ~0x40000000U; + HVM_DBG_LOG(DBG_LEVEL_HCALL, + "fasthcall%lu(%lx, %lx, %lx, %lx, %lx, %lx, %lx)", + index, fastabi_value_n(regs, 1), fastabi_value_n(regs,= 2), + fastabi_value_n(regs, 3), fastabi_value_n(regs, 4), + fastabi_value_n(regs, 5), fastabi_value_n(regs, 6), + fastabi_value_n(regs, 7)); + + fastabi_dispatch(index, regs); + + hvmemul_cache_restore(curr, token); + return HVM_HCALL_completed; + } + #endif + if ( mode =3D=3D 8 ) { HVM_DBG_LOG(DBG_LEVEL_HCALL, "hcall%lu(%lx, %lx, %lx, %lx, %lx)", diff --git a/xen/arch/x86/include/asm/fastabi.h b/xen/arch/x86/include/asm/= fastabi.h new file mode 100644 index 0000000000..914504c63d --- /dev/null +++ b/xen/arch/x86/include/asm/fastabi.h @@ -0,0 +1,17 @@ +#ifndef XEN_ASM_FASTABI_H +#define XEN_ASM_FASTABI_H + +#include + +#define fastabi_param_reg0 rax +#define fastabi_param_reg1 rdi +#define fastabi_param_reg2 rsi +#define fastabi_param_reg3 r8 +#define fastabi_param_reg4 r9 +#define fastabi_param_reg5 r10 +#define fastabi_param_reg6 r11 +#define fastabi_param_reg7 r12 + +#define fastabi_value_n(regs, n) (regs)->fastabi_param_reg##n + +#endif /* XEN_ASM_FASTABI_H */ \ No newline at end of file diff --git a/xen/common/Kconfig b/xen/common/Kconfig index 65f07289dd..71bb4e4f2d 100644 --- a/xen/common/Kconfig +++ b/xen/common/Kconfig @@ -636,4 +636,10 @@ config PM_STATS Enable collection of performance management statistics to aid in analyzing and tuning power/performance characteristics of the system =20 +config FASTABI + depends on X86 && HVM + bool "Fast HVM ABI (unsupported)" + help + Add support for a alternative fast HVM ABI. + endmenu diff --git a/xen/common/Makefile b/xen/common/Makefile index 98f0873056..362e8f61d7 100644 --- a/xen/common/Makefile +++ b/xen/common/Makefile @@ -62,6 +62,7 @@ obj-y +=3D wait.o obj-bin-y +=3D warning.init.o obj-$(CONFIG_XENOPROF) +=3D xenoprof.o obj-y +=3D xmalloc_tlsf.o +obj-$(CONFIG_FASTABI) +=3D fastabi.o =20 obj-bin-$(CONFIG_X86) +=3D $(foreach n,decompress bunzip2 unxz unlzma lzo = unlzo unlz4 unzstd earlycpio,$(n).init.o) =20 diff --git a/xen/common/domain.c b/xen/common/domain.c index 303c338ef2..5a641403b9 100644 --- a/xen/common/domain.c +++ b/xen/common/domain.c @@ -45,6 +45,10 @@ #include #include =20 +#ifdef CONFIG_FASTABI +#include +#endif + #ifdef CONFIG_X86 #include #endif @@ -2266,6 +2270,181 @@ long common_vcpu_op(int cmd, struct vcpu *v, XEN_GU= EST_HANDLE_PARAM(void) arg) return rc; } =20 +#ifdef CONFIG_FASTABI +long common_vcpu_fast_op(struct cpu_user_regs *regs, int cmd, struct vcpu = *v) +{ + long rc =3D 0; + struct domain *d =3D v->domain; + unsigned int vcpuid =3D v->vcpu_id; + + switch ( cmd ) + { + case VCPUOP_initialise: + rc =3D arch_initialise_vcpu(v, (XEN_GUEST_HANDLE(void)) {=20 + (void *)fastabi_value_n(regs, 2) }); + break; + + case VCPUOP_up: + { + bool wake =3D false; + + domain_lock(d); + if ( !v->is_initialised ) + rc =3D -EINVAL; + else + wake =3D test_and_clear_bit(_VPF_down, &v->pause_flags); + domain_unlock(d); + if ( wake ) + vcpu_wake(v); + } + + break; + + case VCPUOP_down: + for_each_vcpu ( d, v ) + if ( !test_bit(_VPF_down, &v->pause_flags) ) + { + rc =3D 1; + break; + } + + if ( !rc ) /* Last vcpu going down? */ + { + domain_shutdown(d, SHUTDOWN_poweroff); + break; + } + + rc =3D 0; + v =3D d->vcpu[vcpuid]; + + if ( !test_and_set_bit(_VPF_down, &v->pause_flags) ) + vcpu_sleep_nosync(v); + + break; + + case VCPUOP_is_up: + rc =3D !(v->pause_flags & VPF_down); + break; + + case VCPUOP_get_runstate_info: + { + struct vcpu_runstate_info runstate; + vcpu_runstate_get(v, &runstate); + + fastabi_value_n(regs, 2) =3D runstate.state; + fastabi_value_n(regs, 3) =3D runstate.state_entry_time; + fastabi_value_n(regs, 4) =3D runstate.time[0]; + fastabi_value_n(regs, 5) =3D runstate.time[1]; + fastabi_value_n(regs, 6) =3D runstate.time[2]; + fastabi_value_n(regs, 7) =3D runstate.time[3]; + break; + } + + case VCPUOP_set_periodic_timer: + { + uint64_t period_ns =3D fastabi_value_n(regs, 3); + + if ( period_ns < MILLISECS(1) ) + return -EINVAL; + + if ( period_ns > STIME_DELTA_MAX ) + return -EINVAL; + + vcpu_set_periodic_timer(v, period_ns); + + break; + } + + case VCPUOP_stop_periodic_timer: + vcpu_set_periodic_timer(v, 0); + break; + + case VCPUOP_set_singleshot_timer: + { + struct vcpu_set_singleshot_timer set =3D { + .timeout_abs_ns =3D fastabi_value_n(regs, 3), + .flags =3D fastabi_value_n(regs, 4), + }; + + if ( v !=3D current ) + return -EINVAL; + + if ( set.timeout_abs_ns < NOW() ) + { + /* + * Simplify the logic if the timeout has already expired and j= ust + * inject the event. + */ + stop_timer(&v->singleshot_timer); + send_timer_event(v); + break; + } + + migrate_timer(&v->singleshot_timer, smp_processor_id()); + set_timer(&v->singleshot_timer, set.timeout_abs_ns); + + break; + } + + case VCPUOP_stop_singleshot_timer: + if ( v !=3D current ) + return -EINVAL; + + stop_timer(&v->singleshot_timer); + + break; + + case VCPUOP_register_vcpu_info: + { + struct vcpu_register_vcpu_info info =3D { + .mfn =3D fastabi_value_n(regs, 3), + .offset =3D fastabi_value_n(regs, 4) + }; + paddr_t gaddr; + + rc =3D -EINVAL; + gaddr =3D gfn_to_gaddr(_gfn(info.mfn)) + info.offset; + if ( !~gaddr || + gfn_x(gaddr_to_gfn(gaddr)) !=3D info.mfn ) + break; + + /* Preliminary check only; see map_guest_area(). */ + rc =3D -EBUSY; + if ( v->vcpu_info_area.pg ) + break; + + /* See the BUILD_BUG_ON() in vcpu_info_populate(). */ + rc =3D map_guest_area(v, gaddr, sizeof(vcpu_info_t), + &v->vcpu_info_area, vcpu_info_populate); + break; + } + + case VCPUOP_register_runstate_phys_area: + { + struct vcpu_register_runstate_memory_area area =3D { + .addr.p =3D fastabi_value_n(regs, 3) + }; + + rc =3D -ENOSYS; + if ( 0 /* TODO: Dom's XENFEAT_runstate_phys_area setting */ ) + break; + + rc =3D map_guest_area(v, area.addr.p, + sizeof(struct vcpu_runstate_info), + &v->runstate_guest_area, + runstate_area_populate); + break; + } + + default: + rc =3D -ENOSYS; + break; + } + + return rc; +} +#endif + #ifdef arch_vm_assist_valid_mask long do_vm_assist(unsigned int cmd, unsigned int type) { diff --git a/xen/common/event_channel.c b/xen/common/event_channel.c index c8c1bfa615..9c8bc0f354 100644 --- a/xen/common/event_channel.c +++ b/xen/common/event_channel.c @@ -34,6 +34,10 @@ #include #include =20 +#ifdef CONFIG_FASTABI +#include +#endif + #ifdef CONFIG_PV_SHIM #include #endif @@ -1507,6 +1511,201 @@ long do_event_channel_op(int cmd, XEN_GUEST_HANDLE_= PARAM(void) arg) return rc; } =20 +#ifdef CONFIG_FASTABI +void do_event_channel_fast_op(struct cpu_user_regs *regs) +{ + long rc; + uint64_t cmd =3D fastabi_value_n(regs, 1); + + switch ( cmd ) + { + case EVTCHNOP_alloc_unbound: { + struct evtchn_alloc_unbound alloc_unbound =3D { + .dom =3D fastabi_value_n(regs, 2), + .remote_dom =3D fastabi_value_n(regs, 3), + .port =3D 0, + }; + rc =3D evtchn_alloc_unbound(&alloc_unbound, 0); + + if ( !rc ) + fastabi_value_n(regs, 4) =3D alloc_unbound.port; + break; + } + + case EVTCHNOP_bind_interdomain: { + struct evtchn_bind_interdomain bind_interdomain =3D { + .remote_dom =3D fastabi_value_n(regs, 2), + .remote_port =3D fastabi_value_n(regs, 3), + .local_port =3D 0, + }; + rc =3D evtchn_bind_interdomain(&bind_interdomain, current->domain,= 0); + + if ( !rc ) + fastabi_value_n(regs, 4) =3D bind_interdomain.local_port; + break; + } + + case EVTCHNOP_bind_virq: { + struct evtchn_bind_virq bind_virq =3D { + .virq =3D fastabi_value_n(regs, 2), + .vcpu =3D fastabi_value_n(regs, 3), + .port =3D 0, + }; + rc =3D evtchn_bind_virq(&bind_virq, 0); + + if ( !rc ) + fastabi_value_n(regs, 4) =3D bind_virq.port; + break; + } + + case EVTCHNOP_bind_ipi: { + struct evtchn_bind_ipi bind_ipi =3D { + .vcpu =3D fastabi_value_n(regs, 2), + .port =3D 0, + }; + rc =3D evtchn_bind_ipi(&bind_ipi); + + if ( !rc ) + fastabi_value_n(regs, 4) =3D bind_ipi.port; + break; + } + + case EVTCHNOP_bind_pirq: { + struct evtchn_bind_pirq bind_pirq =3D { + .pirq =3D fastabi_value_n(regs, 2), + .flags =3D fastabi_value_n(regs, 3), + }; + rc =3D evtchn_bind_pirq(&bind_pirq); + + if ( !rc ) + fastabi_value_n(regs, 4) =3D bind_pirq.port; + break; + } + + case EVTCHNOP_close: { + struct evtchn_close close =3D { .port =3D fastabi_value_n(regs, 2)= }; + rc =3D evtchn_close(current->domain, close.port, 1); + break; + } + + case EVTCHNOP_send: { + struct evtchn_send send =3D { .port =3D fastabi_value_n(regs, 2) }; + rc =3D evtchn_send(current->domain, send.port); + break; + } + + case EVTCHNOP_status: { + struct evtchn_status status =3D { + .dom =3D fastabi_value_n(regs, 2), + .port =3D fastabi_value_n(regs, 3), + }; + rc =3D evtchn_status(&status); + + if ( !rc ) + { + fastabi_value_n(regs, 4) =3D status.status; + fastabi_value_n(regs, 5) =3D status.vcpu; + + switch (status.status) + { + case EVTCHNSTAT_unbound: + fastabi_value_n(regs, 6) =3D status.u.unbound.dom; + break; + case EVTCHNSTAT_interdomain: + fastabi_value_n(regs, 6) =3D status.u.interdomain.dom; + fastabi_value_n(regs, 7) =3D status.u.interdomain.port; + break; + case EVTCHNSTAT_pirq: + fastabi_value_n(regs, 6) =3D status.u.pirq; + break; + case EVTCHNSTAT_virq: + fastabi_value_n(regs, 6) =3D status.u.virq; + break; + default: + break; + } + } + break; + } + + case EVTCHNOP_bind_vcpu: { + struct evtchn_bind_vcpu bind_vcpu =3D { + .vcpu =3D fastabi_value_n(regs, 2), + .port =3D fastabi_value_n(regs, 3) + }; + rc =3D evtchn_bind_vcpu(bind_vcpu.port, bind_vcpu.vcpu); + break; + } + + case EVTCHNOP_unmask: { + struct evtchn_unmask unmask =3D { .port =3D fastabi_value_n(regs, = 2) }; + rc =3D evtchn_unmask(unmask.port); + break; + } + + case EVTCHNOP_reset: + case EVTCHNOP_reset_cont: { + struct evtchn_reset reset =3D { .dom =3D fastabi_value_n(regs, 2) = }; + struct domain *d; + + d =3D rcu_lock_domain_by_any_id(reset.dom); + if ( d =3D=3D NULL ) + { + rc =3D -ESRCH; + break; + } + + rc =3D xsm_evtchn_reset(XSM_TARGET, current->domain, d); + if ( !rc ) + rc =3D evtchn_reset(d, cmd =3D=3D EVTCHNOP_reset_cont); + + rcu_unlock_domain(d); + + if ( rc =3D=3D -ERESTART ) + { + fastabi_value_n(regs, 1) =3D EVTCHNOP_reset_cont; + fastabi_make_continuation(); + return; + } + break; + } + + case EVTCHNOP_init_control: { + struct evtchn_init_control init_control =3D { + .control_gfn =3D fastabi_value_n(regs, 2), + .offset =3D fastabi_value_n(regs, 3), + .vcpu =3D fastabi_value_n(regs, 4) + }; + rc =3D evtchn_fifo_init_control(&init_control); + + if ( !rc ) + fastabi_value_n(regs, 5) =3D init_control.link_bits; + break; + } + + case EVTCHNOP_expand_array: { + struct evtchn_expand_array expand_array =3D { .array_gfn =3D fasta= bi_value_n(regs, 2) }; + rc =3D evtchn_fifo_expand_array(&expand_array); + break; + } + + case EVTCHNOP_set_priority: { + struct evtchn_set_priority set_priority =3D { + .port =3D fastabi_value_n(regs, 2), + .priority =3D fastabi_value_n(regs, 3), + }; + rc =3D evtchn_set_priority(&set_priority); + break; + } + + default: + rc =3D -ENOSYS; + break; + } + + fastabi_value_n(regs, 0) =3D rc; +} +#endif =20 int alloc_unbound_xen_event_channel( struct domain *ld, unsigned int lvcpu, domid_t remote_domid, diff --git a/xen/common/fastabi.c b/xen/common/fastabi.c new file mode 100644 index 0000000000..96a3b05ee7 --- /dev/null +++ b/xen/common/fastabi.c @@ -0,0 +1,49 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +#include +#include +#include + +#include + +void fastabi_make_continuation(void) +{ + current->hcall_preempted =3D true; +} + +void fastabi_dispatch(unsigned long index, struct cpu_user_regs *regs) +{ + switch (index) { + case __HYPERVISOR_memory_op: + do_memory_fast_op(regs); + break; + + case __HYPERVISOR_xen_version: + do_xen_version_fast_op(regs); + break; + =20 + case __HYPERVISOR_grant_table_op: + do_grant_table_fast_op(regs); + break; + + case __HYPERVISOR_vcpu_op: + do_vcpu_fast_op(regs); + break; + + case __HYPERVISOR_sched_op: + do_sched_fast_op(regs); + break; + + case __HYPERVISOR_event_channel_op: + do_event_channel_fast_op(regs); + break; + + case __HYPERVISOR_hvm_op: + do_hvm_fast_op(regs); + break; + + default: + fastabi_value_n(regs, 0) =3D -ENOSYS; + break; + } +} \ No newline at end of file diff --git a/xen/common/grant_table.c b/xen/common/grant_table.c index 3c3bbca2fc..1476e5e5ca 100644 --- a/xen/common/grant_table.c +++ b/xen/common/grant_table.c @@ -45,6 +45,10 @@ #include #include =20 +#ifdef CONFIG_FASTABI +#include +#endif + #ifdef CONFIG_PV_SHIM #include #endif @@ -3826,6 +3830,46 @@ long do_grant_table_op( return rc; } =20 +#ifdef CONFIG_FASTABI +void do_grant_table_fast_op(struct cpu_user_regs *regs) +{ + long rc =3D 0; + unsigned int cmd =3D fastabi_value_n(regs, 1); + + switch (cmd) + { + case GNTTABOP_query_size: + { + struct grant_table *gt =3D current->domain->grant_table; + + grant_read_lock(gt); + fastabi_value_n(regs, 2) =3D nr_grant_frames(gt); + fastabi_value_n(regs, 3) =3D gt->max_grant_frames; + grant_read_unlock(gt); + break; + } + case GNTTABOP_get_version: + { + struct grant_table *gt =3D current->domain->grant_table; + + fastabi_value_n(regs, 2) =3D gt->gt_version; + break; + } + case GNTTABOP_set_version: + { + gnttab_set_version_t op =3D { .version =3D fastabi_value_n(regs, 2= ) }; + rc =3D gnttab_set_version(&op); + break; + } + default: + rc =3D -ENOSYS; + break; + } + + fastabi_value_n(regs, 0) =3D rc; +} +#endif + #ifdef CONFIG_COMPAT #include "compat/grant_table.c" #endif diff --git a/xen/common/kernel.c b/xen/common/kernel.c index eff6db6c8f..2230ccdcaf 100644 --- a/xen/common/kernel.c +++ b/xen/common/kernel.c @@ -18,6 +18,10 @@ #include #include =20 +#ifdef CONFIG_FASTABI +#include +#endif + #ifdef CONFIG_COMPAT #include =20 @@ -772,6 +776,35 @@ long do_xen_version(int cmd, XEN_GUEST_HANDLE_PARAM(vo= id) arg) return -ENOSYS; } =20 +#ifdef CONFIG_FASTABI +void do_xen_version_fast_op(struct cpu_user_regs *regs) +{ + long cmd =3D fastabi_value_n(regs, 1); + long rc =3D 0; + + switch ( cmd ) { + case XENVER_version: + rc =3D (xen_major_version() << 16) | xen_minor_version(); + break; + case XENVER_get_features: + { + uint32_t submap =3D 0, submap_idx =3D fastabi_value_n(regs, 2); + + rc =3D xenver_get_features(current->domain, submap_idx, &submap); + + if ( !rc ) + fastabi_value_n(regs, 3) =3D submap; + break; + } + default: + rc =3D -ENOSYS; + break; + } + + fastabi_value_n(regs, 0) =3D rc; +} +#endif + /* * Local variables: * mode: C diff --git a/xen/common/memory.c b/xen/common/memory.c index 3688e6dd50..689218390e 100644 --- a/xen/common/memory.c +++ b/xen/common/memory.c @@ -35,6 +35,10 @@ #include #include =20 +#ifdef CONFIG_FASTABI +#include +#endif + #ifdef CONFIG_X86 #include #endif @@ -1864,6 +1868,112 @@ long do_memory_op(unsigned long cmd, XEN_GUEST_HAND= LE_PARAM(void) arg) return rc; } =20 +#ifdef CONFIG_FASTABI +void do_memory_fast_op(struct cpu_user_regs *regs) +{ + unsigned long cmd =3D fastabi_value_n(regs, 1); + unsigned long start_extent =3D cmd >> MEMOP_EXTENT_SHIFT; + long rc; + int op =3D cmd & MEMOP_CMD_MASK; + + switch ( op ) { + case XENMEM_add_to_physmap: + { + struct xen_add_to_physmap xatp =3D { + .size =3D fastabi_value_n(regs, 2), + .space =3D fastabi_value_n(regs, 3), + .idx =3D fastabi_value_n(regs, 4), + .gpfn =3D fastabi_value_n(regs, 5) + }; + + BUILD_BUG_ON((typeof(xatp.size))-1 > (UINT_MAX >> MEMOP_EXTENT_SHI= FT)); + + /* Check for malicious or buggy input. */ + if ( start_extent !=3D (typeof(xatp.size))start_extent ) + { + rc =3D -EDOM; + break; + } + + /* Foreign mapping is only possible via add_to_physmap_batch. */ + if ( xatp.space =3D=3D XENMAPSPACE_gmfn_foreign ) + { + rc =3D -ENOSYS; + break; + } + + rc =3D xatp_permission_check(current->domain, xatp.space); + if ( rc ) + break; + + rc =3D xenmem_add_to_physmap(current->domain, &xatp, start_extent); + + if ( xatp.space =3D=3D XENMAPSPACE_gmfn_range && rc > 0 ) + panic("TODO"); + //rc =3D hypercall_create_continuation( + // __HYPERVISOR_memory_op, "lh", + // op | (rc << MEMOP_EXTENT_SHIFT), arg); + break; + } + =20 + case XENMEM_remove_from_physmap: + { + unsigned long gpfn =3D fastabi_value_n(regs, 5); + struct page_info *page; + + if ( unlikely(start_extent) ) + { + rc =3D -EINVAL; + break; + } + + if ( !paging_mode_translate(current->domain) ) + { + rc =3D -EACCES; + break; + } + + page =3D get_page_from_gfn(current->domain, gpfn, NULL, P2M_ALLOC); + if ( page ) + { + rc =3D guest_physmap_remove_page(current->domain, _gfn(gpfn), + page_to_mfn(page), 0); + put_page(page); + } + else + rc =3D -ENOENT; + + break; + } + =20 + case XENMEM_memory_map: + { + struct domain *d =3D current->domain; + unsigned long nr_entries =3D fastabi_value_n(regs, 2); + paddr_t buffer_addr =3D fastabi_value_n(regs, 3); + + spin_lock(&d->arch.e820_lock); + + if ( nr_entries > d->arch.nr_e820 ) + nr_entries =3D d->arch.nr_e820; + + if ( hvm_copy_to_guest_phys(buffer_addr, d->arch.e820, + nr_entries * sizeof(struct e820entry),= current) ) + rc =3D -EFAULT; + + spin_unlock(&d->arch.e820_lock); + break; + } + + default: + rc =3D -ENOSYS; + break; + } + + fastabi_value_n(regs, 0) =3D rc; +} +#endif + void clear_domain_page(mfn_t mfn) { void *ptr =3D map_domain_page(mfn); diff --git a/xen/common/sched/core.c b/xen/common/sched/core.c index b2c784c60e..51b2fbc00a 100644 --- a/xen/common/sched/core.c +++ b/xen/common/sched/core.c @@ -41,6 +41,10 @@ =20 #include "private.h" =20 +#ifdef CONFIG_FASTABI +#include +#endif + #ifdef CONFIG_XEN_GUEST #include #else @@ -1896,6 +1900,110 @@ void domain_update_node_aff(struct domain *d, struc= t affinity_masks *affinity) =20 typedef long ret_t; =20 +#ifdef CONFIG_FASTABI +void do_sched_fast_op(struct cpu_user_regs *regs) +{ + long ret =3D 0; + unsigned long cmd =3D fastabi_value_n(regs, 1); + + switch ( cmd ) + { + case SCHEDOP_yield: + { + ret =3D vcpu_yield(); + break; + } + + case SCHEDOP_block: + { + vcpu_block_enable_events(); + break; + } + + case SCHEDOP_shutdown: + { + struct sched_shutdown sched_shutdown =3D { + .reason =3D fastabi_value_n(regs, 2) + }; + + TRACE_TIME(TRC_SCHED_SHUTDOWN, current->domain->domain_id, + current->vcpu_id, sched_shutdown.reason); + ret =3D domain_shutdown(current->domain, (u8)sched_shutdown.reason= ); + + break; + } + + case SCHEDOP_shutdown_code: + { + struct sched_shutdown sched_shutdown =3D { + .reason =3D fastabi_value_n(regs, 2) + }; + struct domain *d =3D current->domain; + + TRACE_TIME(TRC_SCHED_SHUTDOWN_CODE, d->domain_id, current->vcpu_id, + sched_shutdown.reason); + + spin_lock(&d->shutdown_lock); + if ( d->shutdown_code =3D=3D SHUTDOWN_CODE_INVALID ) + d->shutdown_code =3D (u8)sched_shutdown.reason; + spin_unlock(&d->shutdown_lock); + + ret =3D 0; + break; + } + + case SCHEDOP_poll: + { + uint64_t timeout =3D fastabi_value_n(regs, 2); + evtchn_port_t port =3D fastabi_value_n(regs, 3); + + ret =3D vcpu_poll(1, timeout, &port); + + break; + } + + case SCHEDOP_watchdog: + { + struct sched_watchdog sched_watchdog =3D { + .id =3D fastabi_value_n(regs, 2), + .timeout =3D fastabi_value_n(regs, 3) + }; + + ret =3D domain_watchdog( + current->domain, sched_watchdog.id, sched_watchdog.timeout); + break; + } + + case SCHEDOP_pin_override: + { + struct sched_pin_override sched_pin_override =3D { + .pcpu =3D fastabi_value_n(regs, 2), + }; + unsigned int cpu; + + ret =3D -EPERM; + if ( !is_hardware_domain(current->domain) ) + break; + + ret =3D -EINVAL; + if ( sched_pin_override.pcpu >=3D NR_CPUS ) + break; + + cpu =3D sched_pin_override.pcpu < 0 ? NR_CPUS : sched_pin_override= .pcpu; + ret =3D vcpu_temporary_affinity(current, cpu, VCPU_AFFINITY_OVERRI= DE); + + break; + } + + default: + ret =3D -ENOSYS; + break; + } + + fastabi_value_n(regs, 0) =3D ret; +} +#endif + #endif /* !COMPAT */ =20 ret_t do_sched_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg) @@ -1961,7 +2069,6 @@ ret_t do_sched_op(int cmd, XEN_GUEST_HANDLE_PARAM(voi= d) arg) break; =20 ret =3D do_poll(&sched_poll); - break; } =20 diff --git a/xen/include/public/event_channel.h b/xen/include/public/event_= channel.h index c5548d206c..969c9ec264 100644 --- a/xen/include/public/event_channel.h +++ b/xen/include/public/event_channel.h @@ -208,10 +208,17 @@ struct evtchn_status { } unbound; /* EVTCHNSTAT_unbound */ struct { domid_t dom; + uint16_t _pad; evtchn_port_t port; } interdomain; /* EVTCHNSTAT_interdomain */ uint32_t pirq; /* EVTCHNSTAT_pirq */ uint32_t virq; /* EVTCHNSTAT_virq */ +#ifndef __XEN__ + struct { + uint32_t _output1; + uint32_t _output2; + }; +#endif } u; }; typedef struct evtchn_status evtchn_status_t; diff --git a/xen/include/public/fastabi.h b/xen/include/public/fastabi.h new file mode 100644 index 0000000000..51f5085ce6 --- /dev/null +++ b/xen/include/public/fastabi.h @@ -0,0 +1,20 @@ +/* SPDX-License-Identifier: MIT */ +#ifndef __XEN_PUBLIC_FASTABI_H__ +#define __XEN_PUBLIC_FASTABI_H__ + +#if defined(__x86_64__) +#define __HYPERVISOR_FASTABI_MASK 0x40000000U + +enum xen_hypercall_vendor { + Intel, + Amd +}; +#else +#define __HYPERVISOR_FASTABI_MASK 0 + +enum xen_hypercall_vendor { + Native +}; +#endif + +#endif diff --git a/xen/include/xen/fastabi.h b/xen/include/xen/fastabi.h new file mode 100644 index 0000000000..83ede943e0 --- /dev/null +++ b/xen/include/xen/fastabi.h @@ -0,0 +1,21 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +#ifndef XEN_FASTABI_H +#define XEN_FASTABI_H + +#include + +void fastabi_dispatch(unsigned long index, struct cpu_user_regs *regs); +void fastabi_make_continuation(void); + +void do_event_channel_fast_op(struct cpu_user_regs *regs); + +long common_vcpu_fast_op(struct cpu_user_regs *regs, int cmd, struct vcpu = *v); +void do_vcpu_fast_op(struct cpu_user_regs *regs); +void do_hvm_fast_op(struct cpu_user_regs *regs); +void do_memory_fast_op(struct cpu_user_regs *regs); +void do_grant_table_fast_op(struct cpu_user_regs *regs); +void do_sched_fast_op(struct cpu_user_regs *regs); +void do_xen_version_fast_op(struct cpu_user_regs *regs); + +#endif /* XEN_FASTABI_H */ \ No newline at end of file --=20 2.50.1 Teddy Astie | Vates XCP-ng Developer XCP-ng & Xen Orchestra - Vates solutions web: https://vates.tech From nobody Fri Oct 31 03:47:35 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass header.i=teddy.astie@vates.tech; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=reject dis=none) header.from=vates.tech ARC-Seal: i=1; a=rsa-sha256; t=1755789986; cv=none; d=zohomail.com; s=zohoarc; b=jGJdFy1nebvblJey9zcCMtMZ9e4evwZJj2ngaTmQwCBuwpCWkR+XcEAy3u3oLambiOrWd/spEIKjS/EY5wltRbUylanUdgCeZ/5ODm2ReuY+HSY3ZrE8+/wWsd8Pct2apNIk8Ke5wHlx92ZKfg6lUecTbKwrLNKiB8XF5tiMS6E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1755789986; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=kpYZUErpssBf7MVl+uYwZzjx0Pc3VDlf3LtSHI87KkE=; b=XczOF3WcgVqGgrL8DwOd8K6PEpkSSwped38qniOaWNPBgLWQSHFxZwZ2iAE+O4lKEnfJ70/VmpRET6xa5ycTu7cwKlYSo5J3OZYQU3b/IHsSsI6PSeDyk2QeUCDlw38M8g8g4S87MD6ejuU3rE+axpVM3iZUmgib9axbi9YUTz4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=teddy.astie@vates.tech; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1755789986406632.4594407692189; Thu, 21 Aug 2025 08:26:26 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1088823.1446599 (Exim 4.92) (envelope-from ) id 1up7Ax-0007OX-3D; Thu, 21 Aug 2025 15:26:03 +0000 Received: by outflank-mailman (output) from mailman id 1088823.1446599; Thu, 21 Aug 2025 15:26:02 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1up7Aw-0007LS-JY; Thu, 21 Aug 2025 15:26:02 +0000 Received: by outflank-mailman (input) for mailman id 1088823; Thu, 21 Aug 2025 15:26:00 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1up7Au-0005nU-Cp for xen-devel@lists.xenproject.org; Thu, 21 Aug 2025 15:26:00 +0000 Received: from mail137-3.atl71.mandrillapp.com (mail137-3.atl71.mandrillapp.com [198.2.137.3]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 240c6faf-7ea3-11f0-a32b-13f23c93f187; Thu, 21 Aug 2025 17:25:59 +0200 (CEST) Received: from pmta07.mandrill.prod.atl01.rsglab.com (localhost [127.0.0.1]) by mail137-3.atl71.mandrillapp.com (Mailchimp) with ESMTP id 4c76bT2FwSzBsVD77 for ; Thu, 21 Aug 2025 15:25:57 +0000 (GMT) Received: from [37.26.189.201] by mandrillapp.com id 47dc19ba76e54838851cc4cccb3d1af9; Thu, 21 Aug 2025 15:25:57 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version 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: 240c6faf-7ea3-11f0-a32b-13f23c93f187 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mandrillapp.com; s=mte1; t=1755789957; x=1756059957; bh=kpYZUErpssBf7MVl+uYwZzjx0Pc3VDlf3LtSHI87KkE=; h=From:Subject:To:Cc:Message-Id:In-Reply-To:References:Feedback-ID: Date:MIME-Version:Content-Type:Content-Transfer-Encoding:CC:Date: Subject:From; b=w/gsmN7H993Gmo656k5OzLLrDVxpNMErKjOux3xEWbglu0H+qrJLLYU2JTx6zvPqz +lryNDur2KmTZN02Bmlk0M0P1OSc+ySINKtbNIUMX5bzxE4RxfnxVfbcUeOam6JFTt wxao0H+1MplBWXu7Zvo5wRSNlZA6nsR3Y1coI6Ph/o3dwM2uuUUxscFtJQcX1Vyjyq FS8UEYmEjzs6GOL4ZGvgpxuDkR7mDucy2L7itCk3+T0MOrASF+dp3LmowkJsLd6t+Y nXNlvhA/PcATyCFho0eMK+o1SemtFruak6npkdB2GCyj7FWv6xAx3MZGdFQrr/0Haa RfNSWCwaOvnJg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vates.tech; s=mte1; t=1755789957; x=1756050457; i=teddy.astie@vates.tech; bh=kpYZUErpssBf7MVl+uYwZzjx0Pc3VDlf3LtSHI87KkE=; h=From:Subject:To:Cc:Message-Id:In-Reply-To:References:Feedback-ID: Date:MIME-Version:Content-Type:Content-Transfer-Encoding:CC:Date: Subject:From; b=UU3kuTzMinmiWb+UF0dk+V+w7aWYJ+6OLeRf4bLis83sMgca93kkHOxp8hQConbxF zR1j2rSyn+L9cw0dSr4ju19liheZ5GvlOdqet4ghW6hoq4oYjdr5MhmPkceV+8rz35 oqJYeyqMZ2XjhzaD26sfwfon9DH9XZlmX7eOCnCDaubCSuiy0pVRgYZitgp2OESQ6g gyRcaf8CssOyZqGv6cqxSHpV8QADNW0YGJgX7IvSqkp77xkPNVQ2WibZKHn2zrqCDo aiTQFE0ABcyAVDeBrCHnK9jt7U03Mt91T6TQdyR27g0THmW2a6Zbqo85VxfD5vsKNA t1iNET+mbmDgg== From: "Teddy Astie" Subject: =?utf-8?Q?[RFC=20PATCH=208/9]=20hvm:=20Introduce=20XEN=5FHVM=5FMEMMAP=5FTYPE=5FHOTPLUG=5FZONE?= X-Mailer: git-send-email 2.50.1 X-Bm-Disclaimer: Yes X-Bm-Milter-Handled: 4ffbd6c1-ee69-4e1b-aabd-f977039bd3e2 X-Bm-Transport-Timestamp: 1755789956401 To: xen-devel@lists.xenproject.org Cc: "Teddy Astie" , "Jan Beulich" , "Andrew Cooper" , "=?utf-8?Q?Roger=20Pau=20Monn=C3=A9?=" Message-Id: <3fe81c78b95f60353a84b8394883ecfeee066732.1755785258.git.teddy.astie@vates.tech> In-Reply-To: References: X-Native-Encoded: 1 X-Report-Abuse: =?UTF-8?Q?Please=20forward=20a=20copy=20of=20this=20message,=20including=20all=20headers,=20to=20abuse@mandrill.com.=20You=20can=20also=20report=20abuse=20here:=20https://mandrillapp.com/contact/abuse=3Fid=3D30504962.47dc19ba76e54838851cc4cccb3d1af9?= X-Mandrill-User: md_30504962 Feedback-ID: 30504962:30504962.20250821:md Date: Thu, 21 Aug 2025 15:25:57 +0000 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @mandrillapp.com) (identity teddy.astie@vates.tech) X-ZM-MESSAGEID: 1755789988736124100 Content-Type: text/plain; charset="utf-8" Allow specifying in memory map a region which can be hotplugged. This will be used by a future memory hotplug feature. Signed-off-by: Teddy Astie --- xen/include/public/arch-x86/hvm/start_info.h | 1 + 1 file changed, 1 insertion(+) diff --git a/xen/include/public/arch-x86/hvm/start_info.h b/xen/include/pub= lic/arch-x86/hvm/start_info.h index 0b3dfe91af..bdae8371d6 100644 --- a/xen/include/public/arch-x86/hvm/start_info.h +++ b/xen/include/public/arch-x86/hvm/start_info.h @@ -105,6 +105,7 @@ #define XEN_HVM_MEMMAP_TYPE_GNTTAB_STATUS 0xF0000003 /* Grant table status= page (v2) */ #define XEN_HVM_MEMMAP_TYPE_FOREIGN_REG 0xF0000004 /* Suitable region fo= r grant mappings */ /* and foreign mappin= gs */ +#define XEN_HVM_MEMMAP_TYPE_HOTPLUG_ZONE 0xF0000005 /* Memory hotpluggabl= e zone */ =20 /* * C representation of the x86/HVM start info layout. --=20 2.50.1 Teddy Astie | Vates XCP-ng Developer XCP-ng & Xen Orchestra - Vates solutions web: https://vates.tech From nobody Fri Oct 31 03:47:35 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass header.i=teddy.astie@vates.tech; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=reject dis=none) header.from=vates.tech ARC-Seal: i=1; a=rsa-sha256; t=1755789980; cv=none; d=zohomail.com; s=zohoarc; b=ZxbGgDV/Atkwloz1jK+hEw/rGCQfrLF8NFyUYDQxhjZYyqQbyuXKDpvlkNajQMalR2Btw/YlTp4hg1XYxAh1pf3CwZAFK4aAKC8h62kCY8tzcvRjeH56a2/Wh7QsYAl74ipPUOxCl+KnKNPxLB2sVwlPZzIo2Z9i7c59v3UHo2I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1755789980; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=dB5KCjXLMLA/zGiXspyIEC0oMRY7D9rqpGbR0gjZJDU=; b=QvCTtVKrR+RSx+sX+kZB1gdbNg4EhtytSu/J/Q2GAtmkcxJZalSaFtq3CL2Aj5eFQ4El9IJRQCAyt+spV9OvHvh46/ZoWMts6GBpK/xbHXoLcx47ce+si1TCr4blFRXI1CzzAPnX7UJYZPBOnIv/nt3DqnfPCERvqXxYIrb3glY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=teddy.astie@vates.tech; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1755789980469429.3777678833743; Thu, 21 Aug 2025 08:26:20 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1088824.1446615 (Exim 4.92) (envelope-from ) id 1up7Ay-0007xV-Ij; Thu, 21 Aug 2025 15:26:04 +0000 Received: by outflank-mailman (output) from mailman id 1088824.1446615; Thu, 21 Aug 2025 15:26:04 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1up7Ay-0007uv-6K; Thu, 21 Aug 2025 15:26:04 +0000 Received: by outflank-mailman (input) for mailman id 1088824; Thu, 21 Aug 2025 15:26:02 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1up7Aw-0005na-D0 for xen-devel@lists.xenproject.org; Thu, 21 Aug 2025 15:26:02 +0000 Received: from mail137-3.atl71.mandrillapp.com (mail137-3.atl71.mandrillapp.com [198.2.137.3]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 24540d96-7ea3-11f0-b898-0df219b8e170; Thu, 21 Aug 2025 17:26:00 +0200 (CEST) Received: from pmta07.mandrill.prod.atl01.rsglab.com (localhost [127.0.0.1]) by mail137-3.atl71.mandrillapp.com (Mailchimp) with ESMTP id 4c76bW5MwRzBsW3G7 for ; Thu, 21 Aug 2025 15:25:59 +0000 (GMT) Received: from [37.26.189.201] by mandrillapp.com id d8fda27edc9d4cb49aff6b07b7f2a894; Thu, 21 Aug 2025 15:25:59 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version 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: 24540d96-7ea3-11f0-b898-0df219b8e170 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mandrillapp.com; s=mte1; t=1755789959; x=1756059959; bh=dB5KCjXLMLA/zGiXspyIEC0oMRY7D9rqpGbR0gjZJDU=; h=From:Subject:To:Cc:Message-Id:In-Reply-To:References:Feedback-ID: Date:MIME-Version:Content-Type:Content-Transfer-Encoding:CC:Date: Subject:From; b=MUdVl9RX3BPRg4F5DxnVIsZNFSEaQBbEEhIMPvXWcuHCWUnudTpppPOql4Yv5Cvs8 oNN5Ji2KNStP1l61idT5LzE88K4/ow2ivY4Pox1dv3pxjZlqGtY0epL7MrEJFqlLql QK/Pt95Gr4llt7k/2uPBWqtB/F/0IZsTI0D8ExOjCDWCS+pTtbUsoMjPlzoDpHSLxG QPCcw+Gy1/AZsvw5Fz18mN3SJebijS69n3yd5plGDzSX7Tu6R7ogAAwX91jMy4RcWa 5W68AXjUpeHb01IgvoNz6VngOJtAKB9grJh8JOSRrMWd4TWhRwOhK20xriSCoyQSZO NEYgdYkuTZYyA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vates.tech; s=mte1; t=1755789959; x=1756050459; i=teddy.astie@vates.tech; bh=dB5KCjXLMLA/zGiXspyIEC0oMRY7D9rqpGbR0gjZJDU=; h=From:Subject:To:Cc:Message-Id:In-Reply-To:References:Feedback-ID: Date:MIME-Version:Content-Type:Content-Transfer-Encoding:CC:Date: Subject:From; b=q9vcWxZv40nZ467ibqaYzqkbfJSn49OCUiqGHAEBVRAgmua6N5qWjRb0LfzZj7yUH gXPKxuKH0aeUHXBha+IES+04VmWhHVSaDSgjRCLwwrA55Ww40YShZVkvcA2ilhvQ0q n/UbW5m4oDkFTlJxt6ZBtNL3GmGE1QNq2TKGj8kLx/unU1OaWtAc4hpAGPr4JMC0zn 9/qDXXs5eO3GdbLszazbU2ihy2GPxa4E7YvRdjQZlKf/1d1YmIVeTVXVAfy7W+PDrO 6Qz9S+W6ZsVgQcF/8V5evs02447CXg4Pu5RxMElfwQW1Hq8y6WEaSThULPZ3Jcd3Mx LC/RZ5JBT5/ug== From: "Teddy Astie" Subject: =?utf-8?Q?[RFC=20PATCH=209/9]=20tools:=20Introduce=20abi-tool?= X-Mailer: git-send-email 2.50.1 X-Bm-Disclaimer: Yes X-Bm-Milter-Handled: 4ffbd6c1-ee69-4e1b-aabd-f977039bd3e2 X-Bm-Transport-Timestamp: 1755789958067 To: xen-devel@lists.xenproject.org Cc: "Teddy Astie" , "Andrew Cooper" , "Anthony PERARD" , "Michal Orzel" , "Jan Beulich" , "Julien Grall" , "=?utf-8?Q?Roger=20Pau=20Monn=C3=A9?=" , "Stefano Stabellini" Message-Id: <20b01deb2f53351103fce2e36a586a6a996a841b.1755785258.git.teddy.astie@vates.tech> In-Reply-To: References: X-Native-Encoded: 1 X-Report-Abuse: =?UTF-8?Q?Please=20forward=20a=20copy=20of=20this=20message,=20including=20all=20headers,=20to=20abuse@mandrill.com.=20You=20can=20also=20report=20abuse=20here:=20https://mandrillapp.com/contact/abuse=3Fid=3D30504962.d8fda27edc9d4cb49aff6b07b7f2a894?= X-Mandrill-User: md_30504962 Feedback-ID: 30504962:30504962.20250821:md Date: Thu, 21 Aug 2025 15:25:59 +0000 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity teddy.astie@vates.tech) (identity @mandrillapp.com) X-ZM-MESSAGEID: 1755789981333116600 Content-Type: text/plain; charset="utf-8" abi-tool is a small Rust tool that is able to parse ABI yaml files and generate C stubs for performing hypercalls. Signed-off-by: Teddy Astie --- Usage : ./abi-tool < abi.yaml > abi.h --- xen/tools/abi-tool/.gitignore | 1 + xen/tools/abi-tool/Cargo.lock | 145 ++++++++++++++++++++++++++ xen/tools/abi-tool/Cargo.toml | 11 ++ xen/tools/abi-tool/src/abi.rs | 23 ++++ xen/tools/abi-tool/src/c_lang.rs | 173 +++++++++++++++++++++++++++++++ xen/tools/abi-tool/src/main.rs | 17 +++ xen/tools/abi-tool/src/spec.rs | 61 +++++++++++ 7 files changed, 431 insertions(+) create mode 100644 xen/tools/abi-tool/.gitignore create mode 100644 xen/tools/abi-tool/Cargo.lock create mode 100644 xen/tools/abi-tool/Cargo.toml create mode 100644 xen/tools/abi-tool/src/abi.rs create mode 100644 xen/tools/abi-tool/src/c_lang.rs create mode 100644 xen/tools/abi-tool/src/main.rs create mode 100644 xen/tools/abi-tool/src/spec.rs diff --git a/xen/tools/abi-tool/.gitignore b/xen/tools/abi-tool/.gitignore new file mode 100644 index 0000000000..1de565933b --- /dev/null +++ b/xen/tools/abi-tool/.gitignore @@ -0,0 +1 @@ +target \ No newline at end of file diff --git a/xen/tools/abi-tool/Cargo.lock b/xen/tools/abi-tool/Cargo.lock new file mode 100644 index 0000000000..056a68f20f --- /dev/null +++ b/xen/tools/abi-tool/Cargo.lock @@ -0,0 +1,145 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version =3D 4 + +[[package]] +name =3D "abi-tool" +version =3D "0.1.0" +dependencies =3D [ + "anyhow", + "bimap", + "indexmap", + "serde", + "serde_yaml", +] + +[[package]] +name =3D "anyhow" +version =3D "1.0.98" +source =3D "registry+https://github.com/rust-lang/crates.io-index" +checksum =3D "e16d2d3311acee920a9eb8d33b8cbc1787ce4a264e85f964c2404b969bdc= d487" + +[[package]] +name =3D "arbitrary" +version =3D "1.4.1" +source =3D "registry+https://github.com/rust-lang/crates.io-index" +checksum =3D "dde20b3d026af13f561bdd0f15edf01fc734f0dafcedbaf42bba506a9517= f223" + +[[package]] +name =3D "bimap" +version =3D "0.6.3" +source =3D "registry+https://github.com/rust-lang/crates.io-index" +checksum =3D "230c5f1ca6a325a32553f8640d31ac9b49f2411e901e427570154868b46d= a4f7" +dependencies =3D [ + "serde", +] + +[[package]] +name =3D "equivalent" +version =3D "1.0.2" +source =3D "registry+https://github.com/rust-lang/crates.io-index" +checksum =3D "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe= 5c0f" + +[[package]] +name =3D "hashbrown" +version =3D "0.15.4" +source =3D "registry+https://github.com/rust-lang/crates.io-index" +checksum =3D "5971ac85611da7067dbfcabef3c70ebb5606018acd9e2a3903a0da507521= e0d5" + +[[package]] +name =3D "indexmap" +version =3D "2.10.0" +source =3D "registry+https://github.com/rust-lang/crates.io-index" +checksum =3D "fe4cd85333e22411419a0bcae1297d25e58c9443848b11dc6a86fefe8c78= a661" +dependencies =3D [ + "arbitrary", + "equivalent", + "hashbrown", + "serde", +] + +[[package]] +name =3D "itoa" +version =3D "1.0.15" +source =3D "registry+https://github.com/rust-lang/crates.io-index" +checksum =3D "4a5f13b858c8d314ee3e8f639011f7ccefe71f97f96e50151fb991f26792= 8e2c" + +[[package]] +name =3D "proc-macro2" +version =3D "1.0.95" +source =3D "registry+https://github.com/rust-lang/crates.io-index" +checksum =3D "02b3e5e68a3a1a02aad3ec490a98007cbc13c37cbe84a3cd7b8e406d76e7= f778" +dependencies =3D [ + "unicode-ident", +] + +[[package]] +name =3D "quote" +version =3D "1.0.40" +source =3D "registry+https://github.com/rust-lang/crates.io-index" +checksum =3D "1885c039570dc00dcb4ff087a89e185fd56bae234ddc7f056a945bf36467= 248d" +dependencies =3D [ + "proc-macro2", +] + +[[package]] +name =3D "ryu" +version =3D "1.0.20" +source =3D "registry+https://github.com/rust-lang/crates.io-index" +checksum =3D "28d3b2b1366ec20994f1fd18c3c594f05c5dd4bc44d8bb0c1c632c8d6829= 481f" + +[[package]] +name =3D "serde" +version =3D "1.0.219" +source =3D "registry+https://github.com/rust-lang/crates.io-index" +checksum =3D "5f0e2c6ed6606019b4e29e69dbaba95b11854410e5347d525002456dbbb7= 86b6" +dependencies =3D [ + "serde_derive", +] + +[[package]] +name =3D "serde_derive" +version =3D "1.0.219" +source =3D "registry+https://github.com/rust-lang/crates.io-index" +checksum =3D "5b0276cf7f2c73365f7157c8123c21cd9a50fbbd844757af28ca1f5925fc= 2a00" +dependencies =3D [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name =3D "serde_yaml" +version =3D "0.9.34+deprecated" +source =3D "registry+https://github.com/rust-lang/crates.io-index" +checksum =3D "6a8b1a1a2ebf674015cc02edccce75287f1a0130d394307b36743c2f5d50= 4b47" +dependencies =3D [ + "indexmap", + "itoa", + "ryu", + "serde", + "unsafe-libyaml", +] + +[[package]] +name =3D "syn" +version =3D "2.0.104" +source =3D "registry+https://github.com/rust-lang/crates.io-index" +checksum =3D "17b6f705963418cdb9927482fa304bc562ece2fdd4f616084c50b7023b43= 5a40" +dependencies =3D [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name =3D "unicode-ident" +version =3D "1.0.18" +source =3D "registry+https://github.com/rust-lang/crates.io-index" +checksum =3D "5a5f39404a5da50712a4c1eecf25e90dd62b613502b7e925fd4e4d19b5c9= 6512" + +[[package]] +name =3D "unsafe-libyaml" +version =3D "0.2.11" +source =3D "registry+https://github.com/rust-lang/crates.io-index" +checksum =3D "673aac59facbab8a9007c7f6108d11f63b603f7cabff99fabf650fea5c32= b861" diff --git a/xen/tools/abi-tool/Cargo.toml b/xen/tools/abi-tool/Cargo.toml new file mode 100644 index 0000000000..eee8ad18a9 --- /dev/null +++ b/xen/tools/abi-tool/Cargo.toml @@ -0,0 +1,11 @@ +[package] +name =3D "abi-tool" +version =3D "0.1.0" +edition =3D "2024" + +[dependencies] +anyhow =3D "1.0.98" +bimap =3D { version =3D "0.6.3", features =3D ["serde"] } +indexmap =3D { version =3D "2.10.0", features =3D ["arbitrary", "serde"] } +serde =3D { version =3D "1.0.219", features =3D ["derive"] } +serde_yaml =3D "0.9.34" diff --git a/xen/tools/abi-tool/src/abi.rs b/xen/tools/abi-tool/src/abi.rs new file mode 100644 index 0000000000..9ca427e821 --- /dev/null +++ b/xen/tools/abi-tool/src/abi.rs @@ -0,0 +1,23 @@ +pub trait XenABI { + fn get_register_name(id: u8) -> &'static str; +} + +pub struct Amd64ABI; + +impl XenABI for Amd64ABI { + fn get_register_name(id: u8) -> &'static str { + match id { + 0 =3D> "rax", + 1 =3D> "rdi", + 2 =3D> "rsi", + 3 =3D> "r8", + 4 =3D> "r9", + 5 =3D> "r10", + 6 =3D> "r11", + 7 =3D> "r12", + 8 =3D> "r13", + + _ =3D> panic!("Unexpected register id: {id}"), + } + } +} diff --git a/xen/tools/abi-tool/src/c_lang.rs b/xen/tools/abi-tool/src/c_la= ng.rs new file mode 100644 index 0000000000..20389d305d --- /dev/null +++ b/xen/tools/abi-tool/src/c_lang.rs @@ -0,0 +1,173 @@ +use std::{collections::HashMap, fmt::Write}; + +use crate::{ + abi::{Amd64ABI, XenABI}, + spec::{AbiSpec, CType, HypercallOp}, +}; + +fn emit_register_variable( + w: &mut impl Write, + id: u8, + value: Option<&str>, +) -> anyhow::Result<()> { + write!( + w, + " register {ctype} reg{id} __asm__(\"{reg}\")", + ctype =3D if id =3D=3D 0 { "long" } else { "uint64_t" }, + reg =3D ABI::get_register_name(id) + )?; + if let Some(value) =3D value { + write!(w, " =3D {value}")?; + } + writeln!(w, ";")?; + + Ok(()) +} + +fn emit_hypercall( + w: &mut impl Write, + op: &HypercallOp, + ident: usize, + instruction: &str, +) -> anyhow::Result<()> { + let start =3D format!("{:ident$}__asm__ volatile (\"{instruction}\" ",= ""); + let pad =3D start.len(); + + /* All the exclusive inputs. */ + let reg_input =3D op + .input + .right_values() + .filter(|&input| !op.output.contains_right(input)) + .map(|input| format!("\"r\"(reg{input})")) + .collect::>() + .join(", "); + + /* Outputs that are also inputs are transformed into +r, the rest is = =3Dr */ + let reg_output =3D op + .output + .right_values() + .chain(&[0]) /* 0 is always a input/output */ + .map(|output| { + if *output =3D=3D 0 || op.input.contains_right(output) { + format!("\"+r\"(reg{output})") + } else { + format!("\"=3Dr\"(reg{output})") + } + }) + .collect::>() + .join(", "); + + writeln!(w, "{:ident$}{start}: {reg_output}", "")?; + writeln!(w, "{:ident$}{:pad$}: {reg_input}", "", "")?; + writeln!(w, "{:ident$}{:pad$}: \"memory\");", "", "")?; + + Ok(()) +} + +fn generate_hypercall_function( + w: &mut impl Write, + hypercall_name: &str, + op: &HypercallOp, + function_name: &str, + subop_index: Option, +) -> anyhow::Result<()> { + writeln!(w, "static inline")?; + + eprintln!("Processing {hypercall_name}.{function_name}"); + let annotations =3D op.c_lang.clone().unwrap_or_default(); + + assert!( + annotations.cstruct.is_some() || op.output.is_empty(), + "struct-less wrappers doesn't allow outputs, please use a C struct= ure" + ); + + // Match each input register with its C value. + let input_map: HashMap =3D op + .input + .iter() + .map(|(name, &id)| { + if annotations.params.contains_key(name) { + (id, name.clone()) + } else { + // Struct may have a custom mapping + let field =3D annotations.mapping.get(name).unwrap_or(name= ); + + (id, format!("param->{field}")) + } + }) + .collect(); + + write!(w, "long {function_name}(enum xen_hypercall_vendor vendor")?; + let pad =3D 6 + function_name.len(); + + if let Some(cstruct) =3D &annotations.cstruct { + write!(w, ",\n{:pad$}struct {cstruct} *param", "",)?; + } + + for (name, CType(ctype)) in &annotations.params { + write!(w, ",\n{:pad$}{ctype} {name}", "",)?; + } + + writeln!(w, ")")?; + + writeln!(w, "{{")?; + + for id in op.used_registers() { + // If it is a input, we need to set it here. + let value =3D match (id, subop_index) { + /* Hypercall index */ + (0, _) =3D> Some(format!( + "__HYPERVISOR_FASTABI_MASK | __HYPERVISOR_{hypercall_name}= _op" + )), + /* Sub-operation index */ + (1, Some(subop_index)) =3D> Some(format!("{subop_index}")), + /* Other input parameter */ + (id, _) =3D> input_map.get(&id).cloned(), + }; + + emit_register_variable::(w, id, value.as_deref())?; + } + writeln!(w)?; + + writeln!(w, " if ( vendor =3D=3D Intel )")?; + emit_hypercall::(w, op, 4, "vmcall")?; + writeln!(w, " else")?; + emit_hypercall::(w, op, 4, "vmmcall")?; + + writeln!(w, "")?; + + for (field, output) in &op.output { + let field =3D annotations.mapping.get(field).unwrap_or(field); + + writeln!(w, " param->{field} =3D reg{output};")?; + } + + writeln!(w, " return reg0;")?; + + writeln!(w, "}}")?; + + Ok(()) +} + +pub fn generate_code(w: &mut impl Write, spec: AbiSpec) -> anyhow::Result<= ()> { + writeln!(w, "/* SPDX-License-Identifier: MIT */")?; + writeln!(w, "/* AUTOGENERATED. DO NOT MODIFY */")?; + writeln!(w)?; + + if let Some(op) =3D spec.direct { + let function_name =3D ["xen_hypercall", &spec.name].join("_"); + + generate_hypercall_function(w, &spec.name, &op, &function_name, No= ne)?; + writeln!(w)?; + } + + for (name, mut subop) in spec.subops { + let function_name =3D ["xen_hypercall", &spec.name, &name].join("_= "); + subop.op.input.insert("subop_index".to_string(), 1); + + generate_hypercall_function(w, &spec.name, &subop.op, &function_na= me, Some(subop.index))?; + writeln!(w)?; + } + + Ok(()) +} diff --git a/xen/tools/abi-tool/src/main.rs b/xen/tools/abi-tool/src/main.rs new file mode 100644 index 0000000000..dda85c24d5 --- /dev/null +++ b/xen/tools/abi-tool/src/main.rs @@ -0,0 +1,17 @@ +use std::io::{Read, stdin}; + +pub mod abi; +pub mod c_lang; +pub mod spec; + +fn main() { + let mut buffer =3D String::new(); + stdin().read_to_string(&mut buffer).unwrap(); + + let abi_spec: spec::AbiSpec =3D serde_yaml::from_str(&buffer).unwrap(); + + let mut buffer =3D String::new(); + + c_lang::generate_code(&mut buffer, abi_spec).unwrap(); + print!("{buffer}"); +} diff --git a/xen/tools/abi-tool/src/spec.rs b/xen/tools/abi-tool/src/spec.rs new file mode 100644 index 0000000000..e5fb2c85d2 --- /dev/null +++ b/xen/tools/abi-tool/src/spec.rs @@ -0,0 +1,61 @@ +use std::collections::{BTreeSet, HashMap}; + +use bimap::BiBTreeMap; +use indexmap::IndexMap; /* use indexmap to keep consistent ordering */ +use serde::Deserialize; + +fn default_ctype() -> String { + "uint64_t".into() +} + +#[derive(Clone, Debug, Deserialize, PartialEq, Eq, Hash)] +pub struct CType(#[serde(default =3D "default_ctype")] pub String); + +#[derive(Clone, Debug, Default, Deserialize)] +pub struct CAnnotations { + #[serde(rename =3D "struct")] + pub cstruct: Option, + #[serde(default)] + pub mapping: HashMap, + #[serde(default)] + pub params: HashMap, +} + +#[derive(Debug, Deserialize)] +pub struct HypercallOp { + #[serde(default)] + pub input: BiBTreeMap, + #[serde(default)] + pub output: BiBTreeMap, + + pub c_lang: Option, +} + +impl HypercallOp { + pub fn used_registers(&self) -> BTreeSet { + self.input + .right_values() + .chain(self.output.right_values()) + .chain(&[0]) + .cloned() + .collect() + } +} + +#[derive(Debug, Deserialize)] +pub struct HypercallSubOp { + pub index: u32, + #[serde(flatten)] + pub op: HypercallOp, +} + +#[derive(Debug, Deserialize)] +pub struct AbiSpec { + pub hypercall_index: u32, + pub name: String, + + pub direct: Option, + + #[serde(default)] + pub subops: IndexMap, +} --=20 2.50.1 Teddy Astie | Vates XCP-ng Developer XCP-ng & Xen Orchestra - Vates solutions web: https://vates.tech