From nobody Thu May 2 21:42:23 2024 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 ARC-Seal: i=1; a=rsa-sha256; t=1612020169; cv=none; d=zohomail.com; s=zohoarc; b=P3LcBz2EBiaVFTT8qd5UpTl9349Lwp3GsrHlRFTgj7Ofe9PaW0nAw2DcoQgjfp9Edy0VHnnjvGvP8BIt9+0YRS7g6bZQzDl9QOhRy0WcZJh8zKWlKmU1FjeIacdAwdMdHOs1j+oyjKflyKQUzVutDQqJMwIAzGPUDOHeaDI7vHM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612020169; h=Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:Message-ID:Sender:Subject:To; bh=qOiXMDevhm0RwhWScyWMR1qp3ZEzs7jvG4bra0f+F5U=; b=Isy2aMlN+fq2SzO599dZsNRBvOnQVHH9Xtsm3dhFCQR5nD69GZ+USqssxkeK1d8qR90Vn12cDM1Mz+eq/0DP5t/7jck2lcv3407TwOnwsvhzwdycdZBtWN7WtqfG0K3k53XwUMzZO8P58GzE4M3I5YtEsITRW8Zk77i42OqxIdE= 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 Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1612020169081372.4622698504436; Sat, 30 Jan 2021 07:22:49 -0800 (PST) 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 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-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" 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 X-ZohoMail-DKIM: pass (identity @xen.org) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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 d= efined 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 xe= n_add_to_physmap *xatp, return rc; } =20 +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 =3D=3D XENMAPSPACE_dev_mmio) && + (!is_hardware_domain(d) || (d !=3D 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 *xa= tpb, unsigned int extent) { union add_to_physmap_extra extra =3D {}; + int rc; + + rc =3D xatp_permission_check(d, xatpb->space); + if ( rc ) + return rc; =20 if ( unlikely(xatpb->size < extent) ) return -EILSEQ; @@ -1038,22 +1059,6 @@ static int get_reserved_device_memory(xen_pfn_t star= t, xen_ulong_t nr, } #endif =20 -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 =3D=3D XENMAPSPACE_dev_mmio) && - (!is_hardware_domain(d) || (d !=3D 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 =3D 0; @@ -1442,13 +1447,6 @@ long do_memory_op(unsigned long cmd, XEN_GUEST_HANDL= E_PARAM(void) arg) if ( d =3D=3D NULL ) return -ESRCH; =20 - rc =3D xatp_permission_check(d, xatpb.space); - if ( rc ) - { - rcu_unlock_domain(d); - return rc; - } - rc =3D xenmem_add_to_physmap_batch(d, &xatpb, start_extent); =20 rcu_unlock_domain(d); --=20 2.17.1