From patchwork Sat Jan 30 15:22:10 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 12057245 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=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,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 9F945C433E0 for ; Sat, 30 Jan 2021 15:22:41 +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 47F9260C3D for ; Sat, 30 Jan 2021 15:22:41 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 47F9260C3D Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=xen.org 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.78926.143673 (Exim 4.92) (envelope-from ) id 1l5s4n-00068T-K0; Sat, 30 Jan 2021 15:22:17 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 78926.143673; Sat, 30 Jan 2021 15:22:17 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1l5s4n-00068M-Eg; Sat, 30 Jan 2021 15:22:17 +0000 Received: by outflank-mailman (input) for mailman id 78926; Sat, 30 Jan 2021 15:22:15 +0000 Received: from mail.xenproject.org ([104.130.215.37]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1l5s4l-00068H-QN for xen-devel@lists.xenproject.org; Sat, 30 Jan 2021 15:22:15 +0000 Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1l5s4k-0001PM-4Y; Sat, 30 Jan 2021 15:22:14 +0000 Received: from 54-240-197-235.amazon.com ([54.240.197.235] helo=ufe34d9ed68d054.ant.amazon.com) by xenbits.xenproject.org with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1l5s4j-00030l-Oc; Sat, 30 Jan 2021 15:22:13 +0000 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" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org; s=20200302mail; h=Message-Id:Date:Subject:Cc:To:From; bh=qOiXMDevhm0RwhWScyWMR1qp3ZEzs7jvG4bra0f+F5U=; b=KGZxHa+0vhdA5t1dbUcS453QU3 PIMUpECWtLnCmdTZV7uRuOxUXNue0cza96861OZQ/uwh1Z5H1juxruv6EiLmxhTVtVVEiBt16WQIY ptJz5G8n3hvHRBWETCyAESS+N9+sFxkXvE3SKhQkE7DBpFyWopDwmE/wdDWqFLb2jzYs=; From: Julien Grall To: xen-devel@lists.xenproject.org Cc: julien@xen.org, Julien Grall , Andrew Cooper , George Dunlap , Ian Jackson , Jan Beulich , Stefano Stabellini , Wei Liu , Oleksandr Tyshchenko Subject: [PATCH for-4.15] xen/mm: Fix build when CONFIG_HVM=n and CONFIG_COVERAGE=y Date: Sat, 30 Jan 2021 15:22:10 +0000 Message-Id: <20210130152210.17503-1-julien@xen.org> X-Mailer: git-send-email 2.17.1 From: Julien Grall Xen is heavily relying on the DCE stage to remove unused code so the linker doesn't throw an error because a function is not implemented yet we defined a prototype for it. On some GCC version (such as 9.4 provided by Debian sid), the compiler will DCE stage will not managed to figure that out for xenmem_add_to_physmap_batch(): ld: ld: prelink.o: in function `xenmem_add_to_physmap_batch': /xen/xen/common/memory.c:942: undefined reference to `xenmem_add_to_physmap_one' /xen/xen/common/memory.c:942:(.text+0x22145): relocation truncated to fit: R_X86_64_PLT32 against undefined symbol `xenmem_add_to_physmap_one' prelink-efi.o: in function `xenmem_add_to_physmap_batch': /xen/xen/common/memory.c:942: undefined reference to `xenmem_add_to_physmap_one' make[2]: *** [Makefile:215: /root/xen/xen/xen.efi] Error 1 make[2]: *** Waiting for unfinished jobs.... ld: /xen/xen/.xen-syms.0: hidden symbol `xenmem_add_to_physmap_one' isn't defined ld: final link failed: bad value It is not entirely clear why the compiler DCE is not detecting the unused code. However, moving the permission check from do_memory_op() to xenmem_add_to_physmap_batch() does the trick. Note that this required to move the implementation of xapt_permision_check() earlier on so it can be called in xemem_add_to_physmap_batch(). No functional change intended. Fixes: d4f699a0df6c ("x86/mm: p2m_add_foreign() is HVM-only") Reported-by: Oleksandr Tyshchenko Signed-off-by: Julien Grall --- This also resolves a randconfig issue on the gitlab CI. The gitlab CI is used to provide basic testing on a per-series basis. So I would like to request this patch to be merged in Xen 4.15 in order to reduce the number of failure not related to the series tested. Note that there are a few more randconfig issues that needs to be addressed. --- xen/common/memory.c | 44 +++++++++++++++++++++----------------------- 1 file changed, 21 insertions(+), 23 deletions(-) diff --git a/xen/common/memory.c b/xen/common/memory.c index 01cab7e4930e..b047a93a703a 100644 --- a/xen/common/memory.c +++ b/xen/common/memory.c @@ -898,11 +898,32 @@ int xenmem_add_to_physmap(struct domain *d, struct xen_add_to_physmap *xatp, return rc; } +static long xatp_permission_check(struct domain *d, unsigned int space) +{ + if ( !paging_mode_translate(d) ) + return -EACCES; + + /* + * XENMAPSPACE_dev_mmio mapping is only supported for hardware Domain + * to map this kind of space to itself. + */ + if ( (space == XENMAPSPACE_dev_mmio) && + (!is_hardware_domain(d) || (d != current->domain)) ) + return -EACCES; + + return xsm_add_to_physmap(XSM_TARGET, current->domain, d); +} + static int xenmem_add_to_physmap_batch(struct domain *d, struct xen_add_to_physmap_batch *xatpb, unsigned int extent) { union add_to_physmap_extra extra = {}; + int rc; + + rc = xatp_permission_check(d, xatpb->space); + if ( rc ) + return rc; if ( unlikely(xatpb->size < extent) ) return -EILSEQ; @@ -1038,22 +1059,6 @@ static int get_reserved_device_memory(xen_pfn_t start, xen_ulong_t nr, } #endif -static long xatp_permission_check(struct domain *d, unsigned int space) -{ - if ( !paging_mode_translate(d) ) - return -EACCES; - - /* - * XENMAPSPACE_dev_mmio mapping is only supported for hardware Domain - * to map this kind of space to itself. - */ - if ( (space == XENMAPSPACE_dev_mmio) && - (!is_hardware_domain(d) || (d != current->domain)) ) - return -EACCES; - - return xsm_add_to_physmap(XSM_TARGET, current->domain, d); -} - unsigned int ioreq_server_max_frames(const struct domain *d) { unsigned int nr = 0; @@ -1442,13 +1447,6 @@ long do_memory_op(unsigned long cmd, XEN_GUEST_HANDLE_PARAM(void) arg) if ( d == NULL ) return -ESRCH; - rc = xatp_permission_check(d, xatpb.space); - if ( rc ) - { - rcu_unlock_domain(d); - return rc; - } - rc = xenmem_add_to_physmap_batch(d, &xatpb, start_extent); rcu_unlock_domain(d);