From nobody Mon Feb 9 07:56:37 2026 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; 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=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1599769404; cv=none; d=zohomail.com; s=zohoarc; b=WReTwEcfHu0d4pkXjBuPG6mHuOlQmJrePVlDOiteQxYyecnnmzk74HYyqMxV7Un95sB35exsuMFcrk2eP9HaUruTbcOUNYiIxYjAZv10QxkY0YPDkKTUPAjGgiQo+aJ9Jr9fD39VDfm0CK1dD1O71OpPqvhSsXfLUIicSpqsg94= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1599769404; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=x2TvnkSHZ6vsjE4G3HR67k0zN5hdZf0KT4MdD6dTRn4=; b=hCaCVvHohifM2bBJsYezWqvugCmm326Ia0BwLIKQdwRfOiGxRU0RMNB5c3dyK+AcVo1hiq7i1jrQwF2xcYNsDW4o3Xg6x9C9eN89xQt+CIC2vCIH6xAM534GxR2wjpARlhqwhLC+zpRVFpCmHcYakjifwtb8n8bfXKgbxn06uyM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=none dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1599769404439247.0996423178675; Thu, 10 Sep 2020 13:23:24 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kGT64-0004ai-AW; Thu, 10 Sep 2020 20:23:08 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kGT63-0004JK-TS for xen-devel@lists.xenproject.org; Thu, 10 Sep 2020 20:23:07 +0000 Received: from mail-lj1-x244.google.com (unknown [2a00:1450:4864:20::244]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 665f8bca-6a63-4b95-9739-3d38d92b83c7; Thu, 10 Sep 2020 20:22:39 +0000 (UTC) Received: by mail-lj1-x244.google.com with SMTP id a22so9836931ljp.13 for ; Thu, 10 Sep 2020 13:22:38 -0700 (PDT) Received: from otyshchenko.www.tendawifi.com ([212.22.223.21]) by smtp.gmail.com with ESMTPSA id u5sm1584375lfq.17.2020.09.10.13.22.35 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 10 Sep 2020 13:22:36 -0700 (PDT) X-Inumbo-ID: 665f8bca-6a63-4b95-9739-3d38d92b83c7 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=x2TvnkSHZ6vsjE4G3HR67k0zN5hdZf0KT4MdD6dTRn4=; b=d7c0+ECti+KZNjYH5yLtCpMrSFmsaQQcmQwqcNjPTjCVB7SbdeLBJKfwJUiSdnV7Px cKN6utAnZDobb9G703G6qNUG7fc/uZL77NtV8TRMz6ybhQlWZcWYZphDChDuJ/Nbuw/w FhiQSVf79omn+imxS8xbs+01yAYUgm5Xg5wCWDGuDLa46TaSxDtsiMjznBYi8u5wBE4Y RJAln6b9uSNfXft7q1oQJ3vm+VK5Y5aMO7Bpj6C4lKA3ewV1+Hp6CWqXFVj3IT4S+7jx Fy/9Lhv/LvDhyMLB+ly7w5Eu3vGi14AmTzW/6tAeUVlqk/sdE+cvHBaRwpiVxSYJWCOA fzBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=x2TvnkSHZ6vsjE4G3HR67k0zN5hdZf0KT4MdD6dTRn4=; b=mDEbSbdjkJXF2uun43SxuO2LIeG/nfrl0kQEiTeBlgclf2y/+0dL0F7BJBvBLvEMJn l529453TtUMS6K0OyUPNICm1UBFiB60+oSKJ3VB/FZh6EGzcUcoMeuXL4U/8noO+7ws5 yLgYvSAYTnqNrTn8vpKxtJS8pmvxlGfO8n35DT8209q1YTFaK7TjEdwZ5ZlAHY7I+Bt8 45Ua9Mhhxpech0FIrwTklyrcrI31P3TgppSpVRBCMnIfG9FM5RUKxsM3U/yejbwGKL9+ yt8J9ItoM+RkJxHQf3m+ZXy0eZCo//rEd9rMMxxNUoJ5f6tmx2ZeHIQtGa0snrzSnYFA nYbQ== X-Gm-Message-State: AOAM530ZwNUSI1L3P7RzWeRjjaUvCtAiVCNdiDgrn8ly8cMXUk57wfPf f2OezEyJ3hkQ3hj//Uo17XC1rug16Z5Fiw== X-Google-Smtp-Source: ABdhPJxiCtwpmQ8E6CVwNVMH8pPcmbXi82Q8uLR+4j6pmLOijaXJM9EpcRxnzEtvWOkBTSIjNHIJCQ== X-Received: by 2002:a2e:8182:: with SMTP id e2mr5356957ljg.142.1599769357523; Thu, 10 Sep 2020 13:22:37 -0700 (PDT) From: Oleksandr Tyshchenko To: xen-devel@lists.xenproject.org Cc: Oleksandr Tyshchenko , Jan Beulich , Andrew Cooper , Wei Liu , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , George Dunlap , Ian Jackson , Julien Grall , Stefano Stabellini , Volodymyr Babchuk , Julien Grall Subject: [PATCH V1 08/16] xen/mm: Make x86's XENMEM_resource_ioreq_server handling common Date: Thu, 10 Sep 2020 23:22:02 +0300 Message-Id: <1599769330-17656-9-git-send-email-olekstysh@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1599769330-17656-1-git-send-email-olekstysh@gmail.com> References: <1599769330-17656-1-git-send-email-olekstysh@gmail.com> X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-ZohoMail-DKIM: pass (identity @gmail.com) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Oleksandr Tyshchenko As x86 implementation of XENMEM_resource_ioreq_server can be re-used on Arm later on, this patch makes it common and removes arch_acquire_resource as unneeded. This support is going to be used on Arm to be able run device emulator outside of Xen hypervisor. Signed-off-by: Julien Grall Signed-off-by: Oleksandr Tyshchenko --- Please note, this is a split/cleanup/hardening of Julien's PoC: "Add support for Guest IO forwarding to a device emulator" Changes RFC -> V1: - no changes --- --- xen/arch/x86/mm.c | 44 -------------------------------------------- xen/common/memory.c | 45 +++++++++++++++++++++++++++++++++++++++++++-- xen/include/asm-arm/mm.h | 8 -------- xen/include/asm-x86/mm.h | 4 ---- 4 files changed, 43 insertions(+), 58 deletions(-) diff --git a/xen/arch/x86/mm.c b/xen/arch/x86/mm.c index 776d2b6..a5f6f12 100644 --- a/xen/arch/x86/mm.c +++ b/xen/arch/x86/mm.c @@ -4594,50 +4594,6 @@ int xenmem_add_to_physmap_one( return rc; } =20 -int arch_acquire_resource(struct domain *d, unsigned int type, - unsigned int id, unsigned long frame, - unsigned int nr_frames, xen_pfn_t mfn_list[]) -{ - int rc; - - switch ( type ) - { -#ifdef CONFIG_HVM - case XENMEM_resource_ioreq_server: - { - ioservid_t ioservid =3D id; - unsigned int i; - - rc =3D -EINVAL; - if ( !is_hvm_domain(d) ) - break; - - if ( id !=3D (unsigned int)ioservid ) - break; - - rc =3D 0; - for ( i =3D 0; i < nr_frames; i++ ) - { - mfn_t mfn; - - rc =3D hvm_get_ioreq_server_frame(d, id, frame + i, &mfn); - if ( rc ) - break; - - mfn_list[i] =3D mfn_x(mfn); - } - break; - } -#endif - - default: - rc =3D -EOPNOTSUPP; - break; - } - - return rc; -} - long arch_memory_op(unsigned long cmd, XEN_GUEST_HANDLE_PARAM(void) arg) { int rc; diff --git a/xen/common/memory.c b/xen/common/memory.c index 714077c..e551fa6 100644 --- a/xen/common/memory.c +++ b/xen/common/memory.c @@ -30,6 +30,10 @@ #include #include =20 +#ifdef CONFIG_IOREQ_SERVER +#include +#endif + #ifdef CONFIG_X86 #include #endif @@ -1045,6 +1049,38 @@ static int acquire_grant_table(struct domain *d, uns= igned int id, return 0; } =20 +#ifdef CONFIG_IOREQ_SERVER +static int acquire_ioreq_server(struct domain *d, + unsigned int id, + unsigned long frame, + unsigned int nr_frames, + xen_pfn_t mfn_list[]) +{ + ioservid_t ioservid =3D id; + unsigned int i; + int rc; + + if ( !is_hvm_domain(d) ) + return -EINVAL; + + if ( id !=3D (unsigned int)ioservid ) + return -EINVAL; + + for ( i =3D 0; i < nr_frames; i++ ) + { + mfn_t mfn; + + rc =3D hvm_get_ioreq_server_frame(d, id, frame + i, &mfn); + if ( rc ) + return rc; + + mfn_list[i] =3D mfn_x(mfn); + } + + return 0; +} +#endif + static int acquire_resource( XEN_GUEST_HANDLE_PARAM(xen_mem_acquire_resource_t) arg) { @@ -1095,9 +1131,14 @@ static int acquire_resource( mfn_list); break; =20 +#ifdef CONFIG_IOREQ_SERVER + case XENMEM_resource_ioreq_server: + rc =3D acquire_ioreq_server(d, xmar.id, xmar.frame, xmar.nr_frames, + mfn_list); + break; +#endif default: - rc =3D arch_acquire_resource(d, xmar.type, xmar.id, xmar.frame, - xmar.nr_frames, mfn_list); + rc =3D -EOPNOTSUPP; break; } =20 diff --git a/xen/include/asm-arm/mm.h b/xen/include/asm-arm/mm.h index f8ba49b..0b7de31 100644 --- a/xen/include/asm-arm/mm.h +++ b/xen/include/asm-arm/mm.h @@ -358,14 +358,6 @@ static inline void put_page_and_type(struct page_info = *page) =20 void clear_and_clean_page(struct page_info *page); =20 -static inline -int arch_acquire_resource(struct domain *d, unsigned int type, unsigned in= t id, - unsigned long frame, unsigned int nr_frames, - xen_pfn_t mfn_list[]) -{ - return -EOPNOTSUPP; -} - unsigned int arch_get_dma_bitsize(void); =20 #endif /* __ARCH_ARM_MM__ */ diff --git a/xen/include/asm-x86/mm.h b/xen/include/asm-x86/mm.h index 7e74996..2e111ad 100644 --- a/xen/include/asm-x86/mm.h +++ b/xen/include/asm-x86/mm.h @@ -649,8 +649,4 @@ static inline bool arch_mfn_in_directmap(unsigned long = mfn) return mfn <=3D (virt_to_mfn(eva - 1) + 1); } =20 -int arch_acquire_resource(struct domain *d, unsigned int type, - unsigned int id, unsigned long frame, - unsigned int nr_frames, xen_pfn_t mfn_list[]); - #endif /* __ASM_X86_MM_H__ */ --=20 2.7.4