From patchwork Fri Jan 29 01:48:39 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleksandr Tyshchenko X-Patchwork-Id: 12054963 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5905EC433DB for ; Fri, 29 Jan 2021 01:59:17 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id E2DC764DF1 for ; Fri, 29 Jan 2021 01:59:16 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E2DC764DF1 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from list by lists.xenproject.org with outflank-mailman.77627.140752 (Exim 4.92) (envelope-from ) id 1l5J41-0006zJ-Kr; Fri, 29 Jan 2021 01:59:09 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 77627.140752; Fri, 29 Jan 2021 01:59:09 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1l5J41-0006yt-Gk; Fri, 29 Jan 2021 01:59:09 +0000 Received: by outflank-mailman (input) for mailman id 77627; Fri, 29 Jan 2021 01:59: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 1l5Iv7-0004da-Ky for xen-devel@lists.xenproject.org; Fri, 29 Jan 2021 01:49:57 +0000 Received: from mail-lf1-x12b.google.com (unknown [2a00:1450:4864:20::12b]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 6959da08-c442-4655-bd02-cac1cadc4785; Fri, 29 Jan 2021 01:49:18 +0000 (UTC) Received: by mail-lf1-x12b.google.com with SMTP id i187so10306523lfd.4 for ; Thu, 28 Jan 2021 17:49:18 -0800 (PST) Received: from otyshchenko.www.tendawifi.com ([212.22.223.21]) by smtp.gmail.com with ESMTPSA id z128sm1840238lfa.72.2021.01.28.17.49.16 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 28 Jan 2021 17:49:16 -0800 (PST) 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: 6959da08-c442-4655-bd02-cac1cadc4785 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=wO92iTlgb3DNVOezolo/XVlMnVKwV7Y/rHIBCUd9Cu8=; b=SY9UcgHzjsclm7gI+VSLSdbMx7Y+JLur1TDQbTOD8jLvHId5WwCm5B9hFwbmCHPxfg W+j+LRzOFGjbWtPrgvlV+bWRC9aFV/rFqLFGumSp0rtwXUsjl87scUDJ5w/uP15UyPgN sNosYkbC4YWVwbBx202bVI42SidEY8tPHvm/OCS/o8jXV2k2GQfqxPyAJXY9QJXd6ILi wnuIv+zPBqmN1+GJ+zlErH8Z8DJ+Bv+x1530nTrDIdGYo8vQugHDzO9t7smnxYf10nYS zUDXhdGU8KfdKZbO6Ya1zRFHqvlUq4EPWb8rXY3ft6zxFECybFHRpvaHnan2jPEe17rx db/A== 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=wO92iTlgb3DNVOezolo/XVlMnVKwV7Y/rHIBCUd9Cu8=; b=JC2ZHD8xpfUnZ3w6yZfEMqsgBz2sOaX+FKFb1Kit9+3ZMSqUCSnSAJKFw7hXlMsUmt pt5uu8nqr4w8Cs+GZ0+Ulu0gTg/AGfB4oYgSwN2oCo5jLN//qGVvmSO9+3OIT2tM5HVb 1XDxcGsAq5hZCANLAXDjPcqbJx2yTXN2Zw4mHX8UppNyaS8f1hEu7ozp7rU4iviNmp/q Qx3WlIt0uosL5pDkVvHHvKp5Dz4JMwem3B0PQ0cbyjSJ8rpb7gJOBsLgxBlhCEcV02MS x7ssmVOqx21A+njVQiPayAfYoHktWjkkAFbQgQu6Uutm479iUhhS1QCdLNbrs1E8MQ85 OcQg== X-Gm-Message-State: AOAM531LNV5ziTaiMbfQX94S05YNcHugztcXFJ/atQmrmJh4hxeKrmZD iphsCGmO24q6Ato/h3VIEr/11SZxHoMBTg== X-Google-Smtp-Source: ABdhPJzPm/FEOVU7qPNjQYoLRgww8CaY20+14YvdxhpQqKI3lLPXxYbZWQ6BDet5953TClQxpDebsA== X-Received: by 2002:a19:c356:: with SMTP id t83mr875368lff.484.1611884957102; Thu, 28 Jan 2021 17:49:17 -0800 (PST) From: Oleksandr Tyshchenko To: xen-devel@lists.xenproject.org Cc: Julien Grall , Jan Beulich , Andrew Cooper , =?utf-8?q?Roger_Pau_Monn=C3=A9?= , Wei Liu , George Dunlap , Ian Jackson , Julien Grall , Stefano Stabellini , Oleksandr Tyshchenko Subject: [PATCH V6 11/24] xen/mm: Make x86's XENMEM_resource_ioreq_server handling common Date: Fri, 29 Jan 2021 03:48:39 +0200 Message-Id: <1611884932-1851-12-git-send-email-olekstysh@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1611884932-1851-1-git-send-email-olekstysh@gmail.com> References: <1611884932-1851-1-git-send-email-olekstysh@gmail.com> From: Julien Grall 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 (and the corresponding option) as unneeded. Also re-order #include-s alphabetically. 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 Reviewed-by: Jan Beulich Reviewed-by: Paul Durrant [On Arm only] Tested-by: Wei Chen --- 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 Changes V1 -> V2: - update the author of a patch Changes V2 -> V3: - don't wrap #include - limit the number of #ifdef-s - re-order #include-s alphabetically Changes V3 -> V4: - rebase - Add Jan's R-b Changes V4 -> V5: - add Paul's R-b - update patch description - remove ARCH_ACQUIRE_RESOURCE option, etc Changes V5 -> V6: - no changes --- --- xen/arch/x86/Kconfig | 1 - xen/arch/x86/mm.c | 44 --------------------------------- xen/common/Kconfig | 3 --- xen/common/memory.c | 63 +++++++++++++++++++++++++++++++++++++++--------- xen/include/asm-x86/mm.h | 4 --- xen/include/xen/mm.h | 9 ------- 6 files changed, 51 insertions(+), 73 deletions(-) diff --git a/xen/arch/x86/Kconfig b/xen/arch/x86/Kconfig index ea9a9ea..abe0fce 100644 --- a/xen/arch/x86/Kconfig +++ b/xen/arch/x86/Kconfig @@ -6,7 +6,6 @@ config X86 select ACPI select ACPI_LEGACY_TABLES_LOOKUP select ARCH_SUPPORTS_INT128 - select ARCH_ACQUIRE_RESOURCE select COMPAT select CORE_PARKING select HAS_ALTERNATIVE diff --git a/xen/arch/x86/mm.c b/xen/arch/x86/mm.c index 59eb5c8..4366ea3 100644 --- a/xen/arch/x86/mm.c +++ b/xen/arch/x86/mm.c @@ -4587,50 +4587,6 @@ static int handle_iomem_range(unsigned long s, unsigned long e, void *p) return err || s > e ? err : _handle_iomem_range(s, e, p); } -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 = id; - unsigned int i; - - rc = -EINVAL; - if ( !is_hvm_domain(d) ) - break; - - if ( id != (unsigned int)ioservid ) - break; - - rc = 0; - for ( i = 0; i < nr_frames; i++ ) - { - mfn_t mfn; - - rc = hvm_get_ioreq_server_frame(d, id, frame + i, &mfn); - if ( rc ) - break; - - mfn_list[i] = mfn_x(mfn); - } - break; - } -#endif - - default: - rc = -EOPNOTSUPP; - break; - } - - return rc; -} - long arch_memory_op(unsigned long cmd, XEN_GUEST_HANDLE_PARAM(void) arg) { int rc; diff --git a/xen/common/Kconfig b/xen/common/Kconfig index cf32a07..fa049a6 100644 --- a/xen/common/Kconfig +++ b/xen/common/Kconfig @@ -22,9 +22,6 @@ config GRANT_TABLE If unsure, say Y. -config ARCH_ACQUIRE_RESOURCE - bool - config HAS_ALTERNATIVE bool diff --git a/xen/common/memory.c b/xen/common/memory.c index ccb4d49..2f274a6 100644 --- a/xen/common/memory.c +++ b/xen/common/memory.c @@ -8,22 +8,23 @@ */ #include -#include +#include +#include +#include +#include +#include +#include +#include #include +#include #include +#include +#include #include #include #include -#include -#include -#include -#include -#include -#include -#include -#include #include -#include +#include #include #include #include @@ -1091,6 +1092,40 @@ static int acquire_grant_table(struct domain *d, unsigned int id, return 0; } +static int acquire_ioreq_server(struct domain *d, + unsigned int id, + unsigned long frame, + unsigned int nr_frames, + xen_pfn_t mfn_list[]) +{ +#ifdef CONFIG_IOREQ_SERVER + ioservid_t ioservid = id; + unsigned int i; + int rc; + + if ( !is_hvm_domain(d) ) + return -EINVAL; + + if ( id != (unsigned int)ioservid ) + return -EINVAL; + + for ( i = 0; i < nr_frames; i++ ) + { + mfn_t mfn; + + rc = hvm_get_ioreq_server_frame(d, id, frame + i, &mfn); + if ( rc ) + return rc; + + mfn_list[i] = mfn_x(mfn); + } + + return 0; +#else + return -EOPNOTSUPP; +#endif +} + static int acquire_resource( XEN_GUEST_HANDLE_PARAM(xen_mem_acquire_resource_t) arg) { @@ -1149,9 +1184,13 @@ static int acquire_resource( mfn_list); break; + case XENMEM_resource_ioreq_server: + rc = acquire_ioreq_server(d, xmar.id, xmar.frame, xmar.nr_frames, + mfn_list); + break; + default: - rc = arch_acquire_resource(d, xmar.type, xmar.id, xmar.frame, - xmar.nr_frames, mfn_list); + rc = -EOPNOTSUPP; break; } diff --git a/xen/include/asm-x86/mm.h b/xen/include/asm-x86/mm.h index 1fdb4eb..041c158 100644 --- a/xen/include/asm-x86/mm.h +++ b/xen/include/asm-x86/mm.h @@ -640,8 +640,4 @@ static inline bool arch_mfn_in_directmap(unsigned long mfn) return mfn <= (virt_to_mfn(eva - 1) + 1); } -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__ */ diff --git a/xen/include/xen/mm.h b/xen/include/xen/mm.h index 636a125..667f9da 100644 --- a/xen/include/xen/mm.h +++ b/xen/include/xen/mm.h @@ -612,13 +612,4 @@ static inline void put_page_alloc_ref(struct page_info *page) } } -#ifndef CONFIG_ARCH_ACQUIRE_RESOURCE -static inline 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[]) -{ - return -EOPNOTSUPP; -} -#endif /* !CONFIG_ARCH_ACQUIRE_RESOURCE */ - #endif /* __XEN_MM_H__ */