From nobody Tue Apr 30 09:44:02 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; 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=1623155763; cv=none; d=zohomail.com; s=zohoarc; b=NpBbBDrNHNmeRGUwTyDjUjW6mDXKy726xmdKisr85fS3DwAExg4KSCaLs9L26fyuq48zzU/r/r7l78AG1Lqf9tghVRrF2LMGPgSDAKr1nCFF8q3iSZazO21R4BmkcHnDcCxaPfQwcevSyvvXoxJCsmrd0fy9fkx4NX73RESXB3o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1623155763; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=dDG01WTq3Q553bKgDVfLibZqNjM0BBqm3NV7NtaSPIU=; b=kIUq9Y0Qn4o7nLqSCZqJqj8RfGVYdojfPihiX01f+nAB5X2kiDh+2ZkaQxJG/reW6jBVhRZcpsdc1VLnFNPpJIK1FSqQtGv0dPe2u3IX1V6LJriud0l1Mq+WzChKwLU5nYiFL2ZBji3IMxR69HCJxcdJzzolInMzV7nXze04yY8= ARC-Authentication-Results: i=1; mx.zohomail.com; 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 1623155763313345.65213097977244; Tue, 8 Jun 2021 05:36:03 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.138453.256282 (Exim 4.92) (envelope-from ) id 1lqaxM-0007P3-E5; Tue, 08 Jun 2021 12:35:44 +0000 Received: by outflank-mailman (output) from mailman id 138453.256282; Tue, 08 Jun 2021 12:35:44 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lqaxM-0007Ow-B6; Tue, 08 Jun 2021 12:35:44 +0000 Received: by outflank-mailman (input) for mailman id 138453; Tue, 08 Jun 2021 12:35:43 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lqaxL-0007Ok-Cf for xen-devel@lists.xenproject.org; Tue, 08 Jun 2021 12:35:43 +0000 Received: from mx.upb.ro (unknown [141.85.13.201]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 922b3d25-9387-4a10-bfbd-97bc20a93b20; Tue, 08 Jun 2021 12:35:42 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by mx.upb.ro (Postfix) with ESMTP id 1F056B560197; Tue, 8 Jun 2021 15:35:41 +0300 (EEST) Received: from mx.upb.ro ([127.0.0.1]) by localhost (mx.upb.ro [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id HBWGNFF5zl2C; Tue, 8 Jun 2021 15:35:38 +0300 (EEST) Received: from localhost (localhost [127.0.0.1]) by mx.upb.ro (Postfix) with ESMTP id 559ACB56018F; Tue, 8 Jun 2021 15:35:38 +0300 (EEST) Received: from mx.upb.ro ([127.0.0.1]) by localhost (mx.upb.ro [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id An2SduKIoHOu; Tue, 8 Jun 2021 15:35:38 +0300 (EEST) Received: from localhost.localdomain (unknown [188.25.174.245]) by mx.upb.ro (Postfix) with ESMTPSA id EB1D7B560197; Tue, 8 Jun 2021 15:35:37 +0300 (EEST) 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: 922b3d25-9387-4a10-bfbd-97bc20a93b20 X-Virus-Scanned: amavisd-new at upb.ro From: Costin Lupu To: xen-devel@lists.xenproject.org Cc: Tim Deegan , Ian Jackson , Wei Liu Subject: [PATCH v4 1/5] tools/debugger: Fix PAGE_SIZE redefinition error Date: Tue, 8 Jun 2021 15:35:25 +0300 Message-Id: <603eac57f53a2263baceb5ec5cd8e14aa46c213f.1623155575.git.costin.lupu@cs.pub.ro> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" If PAGE_SIZE is already defined in the system (e.g. in /usr/include/limits.h header) then gcc will trigger a redefinition error because of -Werror. This patch replaces usage of PAGE_* macros with KDD_PAGE_* macros in order to av= oid confusion between control domain page granularity (PAGE_* definitions) and guest domain page granularity (which is what we are dealing with here). We chose to define the KDD_PAGE_* macros instead of using XC_PAGE_* macros because (1) the code in kdd.c should not include any Xen headers and (2) to= add consistency for code in both kdd.c and kdd-xen.c. Signed-off-by: Costin Lupu Reviewed-by: Tim Deegan Acked-by: Christian Lindig > --- tools/debugger/kdd/kdd-xen.c | 15 ++++++--------- tools/debugger/kdd/kdd.c | 19 ++++++++----------- tools/debugger/kdd/kdd.h | 7 +++++++ 3 files changed, 21 insertions(+), 20 deletions(-) diff --git a/tools/debugger/kdd/kdd-xen.c b/tools/debugger/kdd/kdd-xen.c index f3f9529f9f..e78c9311c4 100644 --- a/tools/debugger/kdd/kdd-xen.c +++ b/tools/debugger/kdd/kdd-xen.c @@ -48,9 +48,6 @@ =20 #define MAPSIZE 4093 /* Prime */ =20 -#define PAGE_SHIFT 12 -#define PAGE_SIZE (1U << PAGE_SHIFT) - struct kdd_guest { struct xentoollog_logger xc_log; /* Must be first for xc log callbacks= */ xc_interface *xc_handle; @@ -72,7 +69,7 @@ static void flush_maps(kdd_guest *g) int i; for (i =3D 0; i < MAPSIZE; i++) { if (g->maps[i] !=3D NULL) - munmap(g->maps[i], PAGE_SIZE); + munmap(g->maps[i], KDD_PAGE_SIZE); g->maps[i] =3D NULL; } } @@ -490,13 +487,13 @@ static uint32_t kdd_access_physical_page(kdd_guest *g= , uint64_t addr, uint32_t map_pfn, map_offset; uint8_t *map; =20 - map_pfn =3D (addr >> PAGE_SHIFT); - map_offset =3D addr & (PAGE_SIZE - 1); + map_pfn =3D (addr >> KDD_PAGE_SHIFT); + map_offset =3D addr & (KDD_PAGE_SIZE - 1); =20 /* Evict any mapping of the wrong frame from our slot */=20 if (g->pfns[map_pfn % MAPSIZE] !=3D map_pfn && g->maps[map_pfn % MAPSIZE] !=3D NULL) { - munmap(g->maps[map_pfn % MAPSIZE], PAGE_SIZE); + munmap(g->maps[map_pfn % MAPSIZE], KDD_PAGE_SIZE); g->maps[map_pfn % MAPSIZE] =3D NULL; } g->pfns[map_pfn % MAPSIZE] =3D map_pfn; @@ -507,7 +504,7 @@ static uint32_t kdd_access_physical_page(kdd_guest *g, = uint64_t addr, else { map =3D xc_map_foreign_range(g->xc_handle, g->domid, - PAGE_SIZE, + KDD_PAGE_SIZE, PROT_READ|PROT_WRITE, map_pfn); =20 @@ -533,7 +530,7 @@ uint32_t kdd_access_physical(kdd_guest *g, uint64_t add= r, { uint32_t chunk, rv, done =3D 0; while (len > 0) { - chunk =3D PAGE_SIZE - (addr & (PAGE_SIZE - 1)); + chunk =3D KDD_PAGE_SIZE - (addr & (KDD_PAGE_SIZE - 1)); if (chunk > len)=20 chunk =3D len; rv =3D kdd_access_physical_page(g, addr, chunk, buf, write); diff --git a/tools/debugger/kdd/kdd.c b/tools/debugger/kdd/kdd.c index 17513c2650..320c623eda 100644 --- a/tools/debugger/kdd/kdd.c +++ b/tools/debugger/kdd/kdd.c @@ -288,9 +288,6 @@ static void kdd_log_pkt(kdd_state *s, const char *name,= kdd_pkt *p) * Memory access: virtual addresses and syntactic sugar. */ =20 -#define PAGE_SHIFT (12) -#define PAGE_SIZE (1ULL << PAGE_SHIFT)=20 - static uint32_t kdd_read_physical(kdd_state *s, uint64_t addr,=20 uint32_t len, void *buf) { @@ -352,7 +349,7 @@ static uint64_t v2p(kdd_state *s, int cpuid, uint64_t v= a) =20 /* Walk the appropriate number of levels */ for (i =3D levels; i > 0; i--) { - shift =3D PAGE_SHIFT + bits * (i-1); + shift =3D KDD_PAGE_SHIFT + bits * (i-1); mask =3D ((1ULL << bits) - 1) << shift; offset =3D ((va & mask) >> shift) * width; KDD_DEBUG(s, "level %i: mask 0x%16.16"PRIx64" pa 0x%16.16"PRIx64 @@ -364,12 +361,12 @@ static uint64_t v2p(kdd_state *s, int cpuid, uint64_t= va) return -1ULL; // Not present pa =3D entry & 0x000ffffffffff000ULL; if (pse && (i =3D=3D 2) && (entry & 0x80)) { // Superpage - mask =3D ((1ULL << (PAGE_SHIFT + bits)) - 1); + mask =3D ((1ULL << (KDD_PAGE_SHIFT + bits)) - 1); return (pa & ~mask) + (va & mask); } } =20 - return pa + (va & (PAGE_SIZE - 1)); + return pa + (va & (KDD_PAGE_SIZE - 1)); } =20 static uint32_t kdd_access_virtual(kdd_state *s, int cpuid, uint64_t addr, @@ -380,7 +377,7 @@ static uint32_t kdd_access_virtual(kdd_state *s, int cp= uid, uint64_t addr, =20 /* Process one page at a time */ while (len > 0) { - chunk =3D PAGE_SIZE - (addr & (PAGE_SIZE - 1)); + chunk =3D KDD_PAGE_SIZE - (addr & (KDD_PAGE_SIZE - 1)); if (chunk > len)=20 chunk =3D len; pa =3D v2p(s, cpuid, addr); @@ -591,7 +588,7 @@ static void get_os_info_64(kdd_state *s) uint64_t dbgkd_addr; DBGKD_GET_VERSION64 dbgkd_get_version64; /* Maybe 1GB is too big for the limit to search? */ - uint32_t search_limit =3D (1024 * 1024 * 1024) / PAGE_SIZE; /*1GB/Page= Size*/ + uint32_t search_limit =3D (1024 * 1024 * 1024) / KDD_PAGE_SIZE; /*1GB/= PageSize*/ uint64_t efer; =20 /* if we are not in 64-bit mode, fail */ @@ -620,7 +617,7 @@ static void get_os_info_64(kdd_state *s) * in 1GB range above the current page base address */ =20 - base =3D idt0_addr & ~(PAGE_SIZE - 1); + base =3D idt0_addr & ~(KDD_PAGE_SIZE - 1); =20 while (search_limit) { uint16_t val; @@ -633,7 +630,7 @@ static void get_os_info_64(kdd_state *s) if (val =3D=3D MZ_HEADER) // MZ break; =20 - base -=3D PAGE_SIZE; + base -=3D KDD_PAGE_SIZE; search_limit -=3D 1; } =20 @@ -720,7 +717,7 @@ static void find_os(kdd_state *s) /* Try each page in the potential range of kernel load addresses */ for (limit =3D s->os.base + s->os.range; s->os.base <=3D limit; - s->os.base +=3D PAGE_SIZE) + s->os.base +=3D KDD_PAGE_SIZE) if (check_os(s)) return; } diff --git a/tools/debugger/kdd/kdd.h b/tools/debugger/kdd/kdd.h index b9a17440df..b476a76d93 100644 --- a/tools/debugger/kdd/kdd.h +++ b/tools/debugger/kdd/kdd.h @@ -39,6 +39,13 @@ =20 #define PACKED __attribute__((packed)) =20 +/* We define our page related constants here in order to specifically + * avoid using the Xen page macros (this is a restriction for the code + * in kdd.c which should not include any Xen headers) and to add + * consistency for code in both kdd.c and kdd-xen.c. */ +#define KDD_PAGE_SHIFT 12 +#define KDD_PAGE_SIZE (1U << KDD_PAGE_SHIFT) + /*************************************************************************= **** * Serial line protocol: Sender sends a 16-byte header with an optional * payload following it. Receiver responds to each packet with an --=20 2.20.1 From nobody Tue Apr 30 09:44:02 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; 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=1623155763; cv=none; d=zohomail.com; s=zohoarc; b=O+yCq59/261AjhoOQ2XIC/y/u1jjpdI/FnxhyjIcCesBCg3PM415iOIu9J06Vwydko/z5LEskxLucc5b+qNyvRLEJs1y/D6RrWujyIxfaqtkZRfmaBimj+YEP31OrZlIcHm1MDrGZEx9s7Baoz50JQCN0HC6PuhfOyb/XfDw0KE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1623155763; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=fHygASjvSRjFIB1H7AgjibCXITuuztQiig++c1gz138=; b=CSMlUGXTi5lJe/OnBGVldKjIeH71Ql7zqv2yI2FXzy/qzjsCIulcsCY9E/AOpPit1Qw0x/cX52OId0ApYle2N1TBFZc5VJt8mb/6KzzZWRdi0IZCzRlXeWC5t+9pc0J0BO+gliGCXqXfAZRef8q8QXtyKKx13Rsd9eD+ZDvs/4M= ARC-Authentication-Results: i=1; mx.zohomail.com; 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 1623155763487870.5170108853091; Tue, 8 Jun 2021 05:36:03 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.138455.256307 (Exim 4.92) (envelope-from ) id 1lqaxR-0007yY-UO; Tue, 08 Jun 2021 12:35:49 +0000 Received: by outflank-mailman (output) from mailman id 138455.256307; Tue, 08 Jun 2021 12:35:49 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lqaxR-0007yN-QN; Tue, 08 Jun 2021 12:35:49 +0000 Received: by outflank-mailman (input) for mailman id 138455; Tue, 08 Jun 2021 12:35:48 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lqaxQ-0007Ok-8S for xen-devel@lists.xenproject.org; Tue, 08 Jun 2021 12:35:48 +0000 Received: from mx.upb.ro (unknown [141.85.13.211]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 543521e3-c839-4bef-96ec-530f55d95727; Tue, 08 Jun 2021 12:35:42 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by mx.upb.ro (Postfix) with ESMTP id C0F95B560196; Tue, 8 Jun 2021 15:35:40 +0300 (EEST) Received: from mx.upb.ro ([127.0.0.1]) by localhost (mx.upb.ro [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id Pe8Jzz6oRYRU; Tue, 8 Jun 2021 15:35:38 +0300 (EEST) Received: from localhost (localhost [127.0.0.1]) by mx.upb.ro (Postfix) with ESMTP id BE197B560197; Tue, 8 Jun 2021 15:35:38 +0300 (EEST) Received: from mx.upb.ro ([127.0.0.1]) by localhost (mx.upb.ro [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id E4KKFI4Bk5Xd; Tue, 8 Jun 2021 15:35:38 +0300 (EEST) Received: from localhost.localdomain (unknown [188.25.174.245]) by mx.upb.ro (Postfix) with ESMTPSA id 5A94EB560198; Tue, 8 Jun 2021 15:35:38 +0300 (EEST) 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: 543521e3-c839-4bef-96ec-530f55d95727 X-Virus-Scanned: amavisd-new at upb.ro From: Costin Lupu To: xen-devel@lists.xenproject.org Cc: Ian Jackson , Wei Liu , Julien Grall Subject: [PATCH v4 2/5] tools/libfsimage: Fix PATH_MAX redefinition error Date: Tue, 8 Jun 2021 15:35:26 +0300 Message-Id: <0a80da2cefbef0349177b26facbdc8067e75371f.1623155575.git.costin.lupu@cs.pub.ro> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" If PATH_MAX is already defined in the system (e.g. in /usr/include/limits.h header) then gcc will trigger a redefinition error because of -Werror. Signed-off-by: Costin Lupu Reviewed-by: Julien Grall Acked-by: Christian Lindig > --- tools/libfsimage/ext2fs/fsys_ext2fs.c | 2 ++ tools/libfsimage/reiserfs/fsys_reiserfs.c | 2 ++ 2 files changed, 4 insertions(+) diff --git a/tools/libfsimage/ext2fs/fsys_ext2fs.c b/tools/libfsimage/ext2f= s/fsys_ext2fs.c index a4ed10419c..5ed8fce90e 100644 --- a/tools/libfsimage/ext2fs/fsys_ext2fs.c +++ b/tools/libfsimage/ext2fs/fsys_ext2fs.c @@ -278,7 +278,9 @@ struct ext4_extent_header { =20 #define EXT2_SUPER_MAGIC 0xEF53 /* include/linux/ext2_fs.h */ #define EXT2_ROOT_INO 2 /* include/linux/ext2_fs.h */ +#ifndef PATH_MAX #define PATH_MAX 1024 /* include/linux/limits.h */ +#endif #define MAX_LINK_COUNT 5 /* number of symbolic links to follow= */ =20 /* made up, these are pointers into FSYS_BUF */ diff --git a/tools/libfsimage/reiserfs/fsys_reiserfs.c b/tools/libfsimage/r= eiserfs/fsys_reiserfs.c index 916eb15292..10ca657476 100644 --- a/tools/libfsimage/reiserfs/fsys_reiserfs.c +++ b/tools/libfsimage/reiserfs/fsys_reiserfs.c @@ -284,7 +284,9 @@ struct reiserfs_de_head #define S_ISDIR(mode) (((mode) & 0170000) =3D=3D 0040000) #define S_ISLNK(mode) (((mode) & 0170000) =3D=3D 0120000) =20 +#ifndef PATH_MAX #define PATH_MAX 1024 /* include/linux/limits.h */ +#endif #define MAX_LINK_COUNT 5 /* number of symbolic links to follow */ =20 /* The size of the node cache */ --=20 2.20.1 From nobody Tue Apr 30 09:44:02 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; 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=1623155766; cv=none; d=zohomail.com; s=zohoarc; b=EDUZYyWGlGvyKE8YR+MqqRE3SaZh16LwdNmUjxPMngtA7WE62Mhbry7WbWYxQWLWtUzc2uv2jiV+j8yX77S9AkWK6zZeLBqK1iSSn/fpNzpUxjrDmMFo2cEe5lbtTOkDEZ016/d/h43toTGVzlrH4cCae0SWqsl5jRK+0yuF1XE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1623155766; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=DM1MO/jXMyiKDVjhb06eBB+MaUWak32F6DfHvZImvRw=; b=LtooEmEPf46aj//nx4z+UihYI+OlvP5dPXqqj3Gqgb3CcDRw+qxBv9MKXNr4FOVglk+U5Qg/f9FvXThhIe3wmTwNzbhjOP8cUWlaiolk/sxTZlXDiWjS1zguH3OamdN43fo1HGlTumC7OAML2itpj1mxy4IuunDgjL36+B4wYmk= ARC-Authentication-Results: i=1; mx.zohomail.com; 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 1623155766796316.854107488006; Tue, 8 Jun 2021 05:36:06 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.138456.256319 (Exim 4.92) (envelope-from ) id 1lqaxX-0008Lq-81; Tue, 08 Jun 2021 12:35:55 +0000 Received: by outflank-mailman (output) from mailman id 138456.256319; Tue, 08 Jun 2021 12:35: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 1lqaxX-0008Lf-4I; Tue, 08 Jun 2021 12:35:55 +0000 Received: by outflank-mailman (input) for mailman id 138456; Tue, 08 Jun 2021 12:35:53 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lqaxV-0007Ok-8Z for xen-devel@lists.xenproject.org; Tue, 08 Jun 2021 12:35:53 +0000 Received: from mx.upb.ro (unknown [141.85.13.221]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id d09f5da0-5a51-4942-b1c4-47e530ba074d; Tue, 08 Jun 2021 12:35:43 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by mx.upb.ro (Postfix) with ESMTP id 6BABEB56018F; Tue, 8 Jun 2021 15:35:42 +0300 (EEST) Received: from mx.upb.ro ([127.0.0.1]) by localhost (mx.upb.ro [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id QlRxf5MRgZX5; Tue, 8 Jun 2021 15:35:39 +0300 (EEST) Received: from localhost (localhost [127.0.0.1]) by mx.upb.ro (Postfix) with ESMTP id 19DA1B560198; Tue, 8 Jun 2021 15:35:39 +0300 (EEST) Received: from mx.upb.ro ([127.0.0.1]) by localhost (mx.upb.ro [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id Vp6o898uIw3W; Tue, 8 Jun 2021 15:35:39 +0300 (EEST) Received: from localhost.localdomain (unknown [188.25.174.245]) by mx.upb.ro (Postfix) with ESMTPSA id C5104B560199; Tue, 8 Jun 2021 15:35:38 +0300 (EEST) 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: d09f5da0-5a51-4942-b1c4-47e530ba074d X-Virus-Scanned: amavisd-new at upb.ro From: Costin Lupu To: xen-devel@lists.xenproject.org Cc: Ian Jackson , Wei Liu Subject: [PATCH v4 3/5] tools/libs/foreignmemory: Fix PAGE_SIZE redefinition error Date: Tue, 8 Jun 2021 15:35:27 +0300 Message-Id: <83beb95e3633b1aca7801fd8592406e2057f9bdc.1623155575.git.costin.lupu@cs.pub.ro> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" If PAGE_SIZE is already defined in the system (e.g. in /usr/include/limits.h header) then gcc will trigger a redefinition error because of -Werror. This patch replaces usage of PAGE_* macros with XC_PAGE_* macros in order to avo= id confusion between control domain page granularity (PAGE_* definitions) and guest domain page granularity. The exception is in osdep_xenforeignmemory_map() where we need the system p= age size to check whether the PFN array should be allocated with mmap() or with dynamic allocation. Signed-off-by: Costin Lupu Acked-by: Christian Lindig > Reviewed-by: Julien Grall --- tools/libs/foreignmemory/core.c | 2 +- tools/libs/foreignmemory/freebsd.c | 10 +++++----- tools/libs/foreignmemory/linux.c | 23 ++++++++++++----------- tools/libs/foreignmemory/minios.c | 2 +- tools/libs/foreignmemory/netbsd.c | 10 +++++----- tools/libs/foreignmemory/private.h | 9 +-------- 6 files changed, 25 insertions(+), 31 deletions(-) diff --git a/tools/libs/foreignmemory/core.c b/tools/libs/foreignmemory/cor= e.c index 28ec311af1..7edc6f0dbf 100644 --- a/tools/libs/foreignmemory/core.c +++ b/tools/libs/foreignmemory/core.c @@ -202,7 +202,7 @@ int xenforeignmemory_resource_size( if ( rc ) return rc; =20 - *size =3D fres.nr_frames << PAGE_SHIFT; + *size =3D fres.nr_frames << XC_PAGE_SHIFT; return 0; } =20 diff --git a/tools/libs/foreignmemory/freebsd.c b/tools/libs/foreignmemory/= freebsd.c index d94ea07862..2cf0fa1c38 100644 --- a/tools/libs/foreignmemory/freebsd.c +++ b/tools/libs/foreignmemory/freebsd.c @@ -63,7 +63,7 @@ void *osdep_xenforeignmemory_map(xenforeignmemory_handle = *fmem, privcmd_mmapbatch_t ioctlx; int rc; =20 - addr =3D mmap(addr, num << PAGE_SHIFT, prot, flags | MAP_SHARED, fd, 0= ); + addr =3D mmap(addr, num << XC_PAGE_SHIFT, prot, flags | MAP_SHARED, fd= , 0); if ( addr =3D=3D MAP_FAILED ) return NULL; =20 @@ -78,7 +78,7 @@ void *osdep_xenforeignmemory_map(xenforeignmemory_handle = *fmem, { int saved_errno =3D errno; =20 - (void)munmap(addr, num << PAGE_SHIFT); + (void)munmap(addr, num << XC_PAGE_SHIFT); errno =3D saved_errno; return NULL; } @@ -89,7 +89,7 @@ void *osdep_xenforeignmemory_map(xenforeignmemory_handle = *fmem, int osdep_xenforeignmemory_unmap(xenforeignmemory_handle *fmem, void *addr, size_t num) { - return munmap(addr, num << PAGE_SHIFT); + return munmap(addr, num << XC_PAGE_SHIFT); } =20 int osdep_xenforeignmemory_restrict(xenforeignmemory_handle *fmem, @@ -101,7 +101,7 @@ int osdep_xenforeignmemory_restrict(xenforeignmemory_ha= ndle *fmem, int osdep_xenforeignmemory_unmap_resource(xenforeignmemory_handle *fmem, xenforeignmemory_resource_handle *= fres) { - return fres ? munmap(fres->addr, fres->nr_frames << PAGE_SHIFT) : 0; + return fres ? munmap(fres->addr, fres->nr_frames << XC_PAGE_SHIFT) : 0; } =20 int osdep_xenforeignmemory_map_resource(xenforeignmemory_handle *fmem, @@ -120,7 +120,7 @@ int osdep_xenforeignmemory_map_resource(xenforeignmemor= y_handle *fmem, /* Request for resource size. Skip mmap(). */ goto skip_mmap; =20 - fres->addr =3D mmap(fres->addr, fres->nr_frames << PAGE_SHIFT, + fres->addr =3D mmap(fres->addr, fres->nr_frames << XC_PAGE_SHIFT, fres->prot, fres->flags | MAP_SHARED, fmem->fd, 0); if ( fres->addr =3D=3D MAP_FAILED ) return -1; diff --git a/tools/libs/foreignmemory/linux.c b/tools/libs/foreignmemory/li= nux.c index c1f35e2db7..9062117407 100644 --- a/tools/libs/foreignmemory/linux.c +++ b/tools/libs/foreignmemory/linux.c @@ -134,7 +134,7 @@ static int retry_paged(int fd, uint32_t dom, void *addr, /* At least one gfn is still in paging state */ ioctlx.num =3D 1; ioctlx.dom =3D dom; - ioctlx.addr =3D (unsigned long)addr + (i< PAGE_SIZE ) + if ( pfn_arr_size > os_page_size ) munmap(pfn, pfn_arr_size); =20 if ( rc =3D=3D -ENOENT && i =3D=3D num ) @@ -270,7 +271,7 @@ void *osdep_xenforeignmemory_map(xenforeignmemory_handl= e *fmem, { int saved_errno =3D errno; =20 - (void)munmap(addr, num << PAGE_SHIFT); + (void)munmap(addr, num << XC_PAGE_SHIFT); errno =3D saved_errno; return NULL; } @@ -281,7 +282,7 @@ void *osdep_xenforeignmemory_map(xenforeignmemory_handl= e *fmem, int osdep_xenforeignmemory_unmap(xenforeignmemory_handle *fmem, void *addr, size_t num) { - return munmap(addr, num << PAGE_SHIFT); + return munmap(addr, num << XC_PAGE_SHIFT); } =20 int osdep_xenforeignmemory_restrict(xenforeignmemory_handle *fmem, @@ -293,7 +294,7 @@ int osdep_xenforeignmemory_restrict(xenforeignmemory_ha= ndle *fmem, int osdep_xenforeignmemory_unmap_resource( xenforeignmemory_handle *fmem, xenforeignmemory_resource_handle *fres) { - return fres ? munmap(fres->addr, fres->nr_frames << PAGE_SHIFT) : 0; + return fres ? munmap(fres->addr, fres->nr_frames << XC_PAGE_SHIFT) : 0; } =20 int osdep_xenforeignmemory_map_resource( @@ -312,7 +313,7 @@ int osdep_xenforeignmemory_map_resource( /* Request for resource size. Skip mmap(). */ goto skip_mmap; =20 - fres->addr =3D mmap(fres->addr, fres->nr_frames << PAGE_SHIFT, + fres->addr =3D mmap(fres->addr, fres->nr_frames << XC_PAGE_SHIFT, fres->prot, fres->flags | MAP_SHARED, fmem->fd, 0); if ( fres->addr =3D=3D MAP_FAILED ) return -1; diff --git a/tools/libs/foreignmemory/minios.c b/tools/libs/foreignmemory/m= inios.c index 43341ca301..c5453736d5 100644 --- a/tools/libs/foreignmemory/minios.c +++ b/tools/libs/foreignmemory/minios.c @@ -55,7 +55,7 @@ void *osdep_xenforeignmemory_map(xenforeignmemory_handle = *fmem, int osdep_xenforeignmemory_unmap(xenforeignmemory_handle *fmem, void *addr, size_t num) { - return munmap(addr, num << PAGE_SHIFT); + return munmap(addr, num << XC_PAGE_SHIFT); } =20 /* diff --git a/tools/libs/foreignmemory/netbsd.c b/tools/libs/foreignmemory/n= etbsd.c index c0b1b8f79d..597db775d7 100644 --- a/tools/libs/foreignmemory/netbsd.c +++ b/tools/libs/foreignmemory/netbsd.c @@ -76,7 +76,7 @@ void *osdep_xenforeignmemory_map(xenforeignmemory_handle = *fmem, { int fd =3D fmem->fd; privcmd_mmapbatch_v2_t ioctlx; - addr =3D mmap(addr, num * PAGE_SIZE, prot, + addr =3D mmap(addr, num * XC_PAGE_SIZE, prot, flags | MAP_ANON | MAP_SHARED, -1, 0); if ( addr =3D=3D MAP_FAILED ) { PERROR("osdep_xenforeignmemory_map: mmap failed"); @@ -93,7 +93,7 @@ void *osdep_xenforeignmemory_map(xenforeignmemory_handle = *fmem, { int saved_errno =3D errno; PERROR("osdep_xenforeignmemory_map: ioctl failed"); - munmap(addr, num * PAGE_SIZE); + munmap(addr, num * XC_PAGE_SIZE); errno =3D saved_errno; return NULL; } @@ -104,7 +104,7 @@ void *osdep_xenforeignmemory_map(xenforeignmemory_handl= e *fmem, int osdep_xenforeignmemory_unmap(xenforeignmemory_handle *fmem, void *addr, size_t num) { - return munmap(addr, num * PAGE_SIZE); + return munmap(addr, num * XC_PAGE_SIZE); } =20 int osdep_xenforeignmemory_restrict(xenforeignmemory_handle *fmem, @@ -117,7 +117,7 @@ int osdep_xenforeignmemory_restrict(xenforeignmemory_ha= ndle *fmem, int osdep_xenforeignmemory_unmap_resource( xenforeignmemory_handle *fmem, xenforeignmemory_resource_handle *fres) { - return fres ? munmap(fres->addr, fres->nr_frames << PAGE_SHIFT) : 0; + return fres ? munmap(fres->addr, fres->nr_frames << XC_PAGE_SHIFT) : 0; } =20 int osdep_xenforeignmemory_map_resource( @@ -136,7 +136,7 @@ int osdep_xenforeignmemory_map_resource( /* Request for resource size. Skip mmap(). */ goto skip_mmap; =20 - fres->addr =3D mmap(fres->addr, fres->nr_frames << PAGE_SHIFT, + fres->addr =3D mmap(fres->addr, fres->nr_frames << XC_PAGE_SHIFT, fres->prot, fres->flags | MAP_ANON | MAP_SHARED, -1,= 0); if ( fres->addr =3D=3D MAP_FAILED ) return -1; diff --git a/tools/libs/foreignmemory/private.h b/tools/libs/foreignmemory/= private.h index 1ee3626dd2..65fe77aa5b 100644 --- a/tools/libs/foreignmemory/private.h +++ b/tools/libs/foreignmemory/private.h @@ -1,6 +1,7 @@ #ifndef XENFOREIGNMEMORY_PRIVATE_H #define XENFOREIGNMEMORY_PRIVATE_H =20 +#include #include =20 #include @@ -10,14 +11,6 @@ #include #include =20 -#ifndef PAGE_SHIFT /* Mini-os, Yukk */ -#define PAGE_SHIFT 12 -#endif -#ifndef __MINIOS__ /* Yukk */ -#define PAGE_SIZE (1UL << PAGE_SHIFT) -#define PAGE_MASK (~(PAGE_SIZE-1)) -#endif - struct xenforeignmemory_handle { xentoollog_logger *logger, *logger_tofree; unsigned flags; --=20 2.20.1 From nobody Tue Apr 30 09:44:02 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; 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=1623155772; cv=none; d=zohomail.com; s=zohoarc; b=KlVjPSrkN+E2sSYHg3zPnM+dMDFwJZ57X+UJgXhCYRaFi4JboE+ZosFX1+TIvIyikPklsfZXk+QGSyeocwxC53P5FRUoVH1Qb5M4CjgwC5UQ5L9/bE6o5iWSFM1A7mWFPv9AYICcqraT9OhAPCa/w8OsSXNyli28saIo3tz24PM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1623155772; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Qnx/SNFLNA1deEJUJwilfGPY5lyCKRPNsFOrV0G6E+U=; b=PRtOth2lVQZmT9R9BXA6v4mWuOQG6jYCReEPiZOQRHf9s4BiQQoEGmh1+23fxAxkBSFY+rPTKeYSbv5QKckm48OZhKvTbRLryaz0e/t8WootLk2A6x5VZIcgMcK4LwFMBuaIQy6K7Vf8JAWUyUVHL+kF6dCmmUYueT6TAp+H94I= ARC-Authentication-Results: i=1; mx.zohomail.com; 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 1623155772867758.3554187282951; Tue, 8 Jun 2021 05:36:12 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.138458.256331 (Exim 4.92) (envelope-from ) id 1lqaxb-0000MV-RV; Tue, 08 Jun 2021 12:35:59 +0000 Received: by outflank-mailman (output) from mailman id 138458.256331; Tue, 08 Jun 2021 12:35:59 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lqaxb-0000MK-MN; Tue, 08 Jun 2021 12:35:59 +0000 Received: by outflank-mailman (input) for mailman id 138458; Tue, 08 Jun 2021 12:35:58 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lqaxa-0007Ok-8j for xen-devel@lists.xenproject.org; Tue, 08 Jun 2021 12:35:58 +0000 Received: from mx.upb.ro (unknown [141.85.13.231]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 2fc4d4b7-96d5-4a35-8117-8c13f80885ce; Tue, 08 Jun 2021 12:35:43 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by mx.upb.ro (Postfix) with ESMTP id E9E40B560198; Tue, 8 Jun 2021 15:35:42 +0300 (EEST) Received: from mx.upb.ro ([127.0.0.1]) by localhost (mx.upb.ro [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id BwKakGLi3CjN; Tue, 8 Jun 2021 15:35:39 +0300 (EEST) Received: from localhost (localhost [127.0.0.1]) by mx.upb.ro (Postfix) with ESMTP id 81FB0B56019C; Tue, 8 Jun 2021 15:35:39 +0300 (EEST) Received: from mx.upb.ro ([127.0.0.1]) by localhost (mx.upb.ro [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id h32ba2wsXpzQ; Tue, 8 Jun 2021 15:35:39 +0300 (EEST) Received: from localhost.localdomain (unknown [188.25.174.245]) by mx.upb.ro (Postfix) with ESMTPSA id 1F3A5B56019A; Tue, 8 Jun 2021 15:35:39 +0300 (EEST) 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: 2fc4d4b7-96d5-4a35-8117-8c13f80885ce X-Virus-Scanned: amavisd-new at upb.ro From: Costin Lupu To: xen-devel@lists.xenproject.org Cc: Ian Jackson , Wei Liu Subject: [PATCH v4 4/5] tools/libs/gnttab: Fix PAGE_SIZE redefinition error Date: Tue, 8 Jun 2021 15:35:28 +0300 Message-Id: <84d03c4595428e4ff857dcacc72f6b9c04476849.1623155575.git.costin.lupu@cs.pub.ro> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" If PAGE_SIZE is already defined in the system (e.g. in /usr/include/limits.h header) then gcc will trigger a redefinition error because of -Werror. This patch replaces usage of PAGE_* macros with XC_PAGE_* macros in order to avo= id confusion between control domain page granularity (PAGE_* definitions) and guest domain page granularity. The exception is in osdep_xenforeignmemory_map() where we need the system p= age size to check whether the PFN array should be allocated with mmap() or with dynamic allocation. Signed-off-by: Costin Lupu Acked-by: Christian Lindig > Reviewed-by: Julien Grall --- tools/libs/gnttab/freebsd.c | 28 +++++++++++++--------------- tools/libs/gnttab/linux.c | 28 +++++++++++++--------------- tools/libs/gnttab/netbsd.c | 23 ++++++++++------------- 3 files changed, 36 insertions(+), 43 deletions(-) diff --git a/tools/libs/gnttab/freebsd.c b/tools/libs/gnttab/freebsd.c index 768af701c6..e42ac3fbf3 100644 --- a/tools/libs/gnttab/freebsd.c +++ b/tools/libs/gnttab/freebsd.c @@ -30,14 +30,11 @@ =20 #include =20 +#include #include =20 #include "private.h" =20 -#define PAGE_SHIFT 12 -#define PAGE_SIZE (1UL << PAGE_SHIFT) -#define PAGE_MASK (~(PAGE_SIZE-1)) - #define DEVXEN "/dev/xen/gntdev" =20 int osdep_gnttab_open(xengnttab_handle *xgt) @@ -77,10 +74,11 @@ void *osdep_gnttab_grant_map(xengnttab_handle *xgt, int domids_stride; unsigned int refs_size =3D ROUNDUP(count * sizeof(struct ioctl_gntdev_grant_ref), - PAGE_SHIFT); + XC_PAGE_SHIFT); + int os_page_size =3D getpagesize(); =20 domids_stride =3D (flags & XENGNTTAB_GRANT_MAP_SINGLE_DOMAIN) ? 0 : 1; - if ( refs_size <=3D PAGE_SIZE ) + if ( refs_size <=3D os_page_size ) map.refs =3D malloc(refs_size); else { @@ -107,7 +105,7 @@ void *osdep_gnttab_grant_map(xengnttab_handle *xgt, goto out; } =20 - addr =3D mmap(NULL, PAGE_SIZE * count, prot, MAP_SHARED, fd, + addr =3D mmap(NULL, XC_PAGE_SIZE * count, prot, MAP_SHARED, fd, map.index); if ( addr !=3D MAP_FAILED ) { @@ -116,7 +114,7 @@ void *osdep_gnttab_grant_map(xengnttab_handle *xgt, =20 notify.index =3D map.index; notify.action =3D 0; - if ( notify_offset < PAGE_SIZE * count ) + if ( notify_offset < XC_PAGE_SIZE * count ) { notify.index +=3D notify_offset; notify.action |=3D UNMAP_NOTIFY_CLEAR_BYTE; @@ -131,7 +129,7 @@ void *osdep_gnttab_grant_map(xengnttab_handle *xgt, if ( rv ) { GTERROR(xgt->logger, "ioctl SET_UNMAP_NOTIFY failed"); - munmap(addr, count * PAGE_SIZE); + munmap(addr, count * XC_PAGE_SIZE); addr =3D MAP_FAILED; } } @@ -150,7 +148,7 @@ void *osdep_gnttab_grant_map(xengnttab_handle *xgt, } =20 out: - if ( refs_size > PAGE_SIZE ) + if ( refs_size > os_page_size ) munmap(map.refs, refs_size); else free(map.refs); @@ -189,7 +187,7 @@ int osdep_gnttab_unmap(xengnttab_handle *xgt, } =20 /* Next, unmap the memory. */ - if ( (rc =3D munmap(start_address, count * PAGE_SIZE)) ) + if ( (rc =3D munmap(start_address, count * XC_PAGE_SIZE)) ) return rc; =20 /* Finally, unmap the driver slots used to store the grant information= . */ @@ -256,7 +254,7 @@ void *osdep_gntshr_share_pages(xengntshr_handle *xgs, goto out; } =20 - area =3D mmap(NULL, count * PAGE_SIZE, PROT_READ | PROT_WRITE, MAP_SHA= RED, + area =3D mmap(NULL, count * XC_PAGE_SIZE, PROT_READ | PROT_WRITE, MAP_= SHARED, fd, gref_info.index); =20 if ( area =3D=3D MAP_FAILED ) @@ -268,7 +266,7 @@ void *osdep_gntshr_share_pages(xengntshr_handle *xgs, =20 notify.index =3D gref_info.index; notify.action =3D 0; - if ( notify_offset < PAGE_SIZE * count ) + if ( notify_offset < XC_PAGE_SIZE * count ) { notify.index +=3D notify_offset; notify.action |=3D UNMAP_NOTIFY_CLEAR_BYTE; @@ -283,7 +281,7 @@ void *osdep_gntshr_share_pages(xengntshr_handle *xgs, if ( err ) { GSERROR(xgs->logger, "ioctl SET_UNMAP_NOTIFY failed"); - munmap(area, count * PAGE_SIZE); + munmap(area, count * XC_PAGE_SIZE); area =3D NULL; } =20 @@ -306,7 +304,7 @@ void *osdep_gntshr_share_pages(xengntshr_handle *xgs, int osdep_gntshr_unshare(xengntshr_handle *xgs, void *start_address, uint32_t count) { - return munmap(start_address, count * PAGE_SIZE); + return munmap(start_address, count * XC_PAGE_SIZE); } =20 /* diff --git a/tools/libs/gnttab/linux.c b/tools/libs/gnttab/linux.c index 74331a4c7b..5628fd5719 100644 --- a/tools/libs/gnttab/linux.c +++ b/tools/libs/gnttab/linux.c @@ -32,14 +32,11 @@ #include #include =20 +#include #include =20 #include "private.h" =20 -#define PAGE_SHIFT 12 -#define PAGE_SIZE (1UL << PAGE_SHIFT) -#define PAGE_MASK (~(PAGE_SIZE-1)) - #define DEVXEN "/dev/xen/" =20 #ifndef O_CLOEXEC @@ -92,6 +89,7 @@ void *osdep_gnttab_grant_map(xengnttab_handle *xgt, int fd =3D xgt->fd; struct ioctl_gntdev_map_grant_ref *map; unsigned int map_size =3D sizeof(*map) + (count - 1) * sizeof(map->ref= s[0]); + int os_page_size =3D sysconf(_SC_PAGESIZE); void *addr =3D NULL; int domids_stride =3D 1; int i; @@ -99,11 +97,11 @@ void *osdep_gnttab_grant_map(xengnttab_handle *xgt, if (flags & XENGNTTAB_GRANT_MAP_SINGLE_DOMAIN) domids_stride =3D 0; =20 - if ( map_size <=3D PAGE_SIZE ) + if ( map_size <=3D os_page_size ) map =3D alloca(map_size); else { - map_size =3D ROUNDUP(map_size, PAGE_SHIFT); + map_size =3D ROUNDUP(map_size, XC_PAGE_SHIFT); map =3D mmap(NULL, map_size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON | MAP_POPULATE, -1, 0); if ( map =3D=3D MAP_FAILED ) @@ -127,7 +125,7 @@ void *osdep_gnttab_grant_map(xengnttab_handle *xgt, } =20 retry: - addr =3D mmap(NULL, PAGE_SIZE * count, prot, MAP_SHARED, fd, + addr =3D mmap(NULL, XC_PAGE_SIZE * count, prot, MAP_SHARED, fd, map->index); =20 if (addr =3D=3D MAP_FAILED && errno =3D=3D EAGAIN) @@ -152,7 +150,7 @@ void *osdep_gnttab_grant_map(xengnttab_handle *xgt, struct ioctl_gntdev_unmap_notify notify; notify.index =3D map->index; notify.action =3D 0; - if (notify_offset < PAGE_SIZE * count) { + if (notify_offset < XC_PAGE_SIZE * count) { notify.index +=3D notify_offset; notify.action |=3D UNMAP_NOTIFY_CLEAR_BYTE; } @@ -164,7 +162,7 @@ void *osdep_gnttab_grant_map(xengnttab_handle *xgt, rv =3D ioctl(fd, IOCTL_GNTDEV_SET_UNMAP_NOTIFY, ¬ify); if (rv) { GTERROR(xgt->logger, "ioctl SET_UNMAP_NOTIFY failed"); - munmap(addr, count * PAGE_SIZE); + munmap(addr, count * XC_PAGE_SIZE); addr =3D MAP_FAILED; } } @@ -184,7 +182,7 @@ void *osdep_gnttab_grant_map(xengnttab_handle *xgt, } =20 out: - if ( map_size > PAGE_SIZE ) + if ( map_size > os_page_size ) munmap(map, map_size); =20 return addr; @@ -220,7 +218,7 @@ int osdep_gnttab_unmap(xengnttab_handle *xgt, } =20 /* Next, unmap the memory. */ - if ( (rc =3D munmap(start_address, count * PAGE_SIZE)) ) + if ( (rc =3D munmap(start_address, count * XC_PAGE_SIZE)) ) return rc; =20 /* Finally, unmap the driver slots used to store the grant information= . */ @@ -466,7 +464,7 @@ void *osdep_gntshr_share_pages(xengntshr_handle *xgs, goto out; } =20 - area =3D mmap(NULL, count * PAGE_SIZE, PROT_READ | PROT_WRITE, + area =3D mmap(NULL, count * XC_PAGE_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd, gref_info->index); =20 if (area =3D=3D MAP_FAILED) { @@ -477,7 +475,7 @@ void *osdep_gntshr_share_pages(xengntshr_handle *xgs, =20 notify.index =3D gref_info->index; notify.action =3D 0; - if (notify_offset < PAGE_SIZE * count) { + if (notify_offset < XC_PAGE_SIZE * count) { notify.index +=3D notify_offset; notify.action |=3D UNMAP_NOTIFY_CLEAR_BYTE; } @@ -489,7 +487,7 @@ void *osdep_gntshr_share_pages(xengntshr_handle *xgs, err =3D ioctl(fd, IOCTL_GNTALLOC_SET_UNMAP_NOTIFY, ¬ify); if (err) { GSERROR(xgs->logger, "ioctl SET_UNMAP_NOTIFY failed"); - munmap(area, count * PAGE_SIZE); + munmap(area, count * XC_PAGE_SIZE); area =3D NULL; } =20 @@ -510,7 +508,7 @@ void *osdep_gntshr_share_pages(xengntshr_handle *xgs, int osdep_gntshr_unshare(xengntshr_handle *xgs, void *start_address, uint32_t count) { - return munmap(start_address, count * PAGE_SIZE); + return munmap(start_address, count * XC_PAGE_SIZE); } =20 /* diff --git a/tools/libs/gnttab/netbsd.c b/tools/libs/gnttab/netbsd.c index f8d7c356eb..a4ad624b54 100644 --- a/tools/libs/gnttab/netbsd.c +++ b/tools/libs/gnttab/netbsd.c @@ -28,15 +28,12 @@ #include #include =20 +#include #include #include =20 #include "private.h" =20 -#define PAGE_SHIFT 12 -#define PAGE_SIZE (1UL << PAGE_SHIFT) -#define PAGE_MASK (~(PAGE_SIZE-1)) - #define DEVXEN "/kern/xen/privcmd" =20 int osdep_gnttab_open(xengnttab_handle *xgt) @@ -87,19 +84,19 @@ void *osdep_gnttab_grant_map(xengnttab_handle *xgt, } =20 map.count =3D count; - addr =3D mmap(NULL, count * PAGE_SIZE, + addr =3D mmap(NULL, count * XC_PAGE_SIZE, prot, flags | MAP_ANON | MAP_SHARED, -1, 0); if ( map.va =3D=3D MAP_FAILED ) { GTERROR(xgt->logger, "osdep_gnttab_grant_map: mmap failed"); - munmap((void *)map.va, count * PAGE_SIZE); + munmap((void *)map.va, count * XC_PAGE_SIZE); addr =3D MAP_FAILED; } map.va =3D addr; =20 map.notify.offset =3D 0; map.notify.action =3D 0; - if ( notify_offset < PAGE_SIZE * count ) + if ( notify_offset < XC_PAGE_SIZE * count ) { map.notify.offset =3D notify_offset; map.notify.action |=3D UNMAP_NOTIFY_CLEAR_BYTE; @@ -115,7 +112,7 @@ void *osdep_gnttab_grant_map(xengnttab_handle *xgt, { GTERROR(xgt->logger, "ioctl IOCTL_GNTDEV_MMAP_GRANT_REF failed: %d", rv); - munmap(addr, count * PAGE_SIZE); + munmap(addr, count * XC_PAGE_SIZE); addr =3D MAP_FAILED; } =20 @@ -136,7 +133,7 @@ int osdep_gnttab_unmap(xengnttab_handle *xgt, } =20 /* Next, unmap the memory. */ - rc =3D munmap(start_address, count * PAGE_SIZE); + rc =3D munmap(start_address, count * XC_PAGE_SIZE); =20 return rc; } @@ -187,7 +184,7 @@ void *osdep_gntshr_share_pages(xengntshr_handle *xgs, alloc.domid =3D domid; alloc.flags =3D writable ? GNTDEV_ALLOC_FLAG_WRITABLE : 0; alloc.count =3D count; - area =3D mmap(NULL, count * PAGE_SIZE, + area =3D mmap(NULL, count * XC_PAGE_SIZE, PROT_READ | PROT_WRITE, MAP_ANON | MAP_SHARED, -1, 0); =20 if ( area =3D=3D MAP_FAILED ) @@ -200,7 +197,7 @@ void *osdep_gntshr_share_pages(xengntshr_handle *xgs, =20 alloc.notify.offset =3D 0; alloc.notify.action =3D 0; - if ( notify_offset < PAGE_SIZE * count ) + if ( notify_offset < XC_PAGE_SIZE * count ) { alloc.notify.offset =3D notify_offset; alloc.notify.action |=3D UNMAP_NOTIFY_CLEAR_BYTE; @@ -215,7 +212,7 @@ void *osdep_gntshr_share_pages(xengntshr_handle *xgs, if ( err ) { GSERROR(xgs->logger, "IOCTL_GNTDEV_ALLOC_GRANT_REF failed"); - munmap(area, count * PAGE_SIZE); + munmap(area, count * XC_PAGE_SIZE); area =3D MAP_FAILED; goto out; } @@ -230,7 +227,7 @@ void *osdep_gntshr_share_pages(xengntshr_handle *xgs, int osdep_gntshr_unshare(xengntshr_handle *xgs, void *start_address, uint32_t count) { - return munmap(start_address, count * PAGE_SIZE); + return munmap(start_address, count * XC_PAGE_SIZE); } =20 /* --=20 2.20.1 From nobody Tue Apr 30 09:44:02 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; 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=1623155777; cv=none; d=zohomail.com; s=zohoarc; b=USBZyU9Y3I2UaxgQ6sM4Okwz2O6sUBKMqb9VO9419HkHGS7HcX7UHsfIl97Bhn5bxZGjLjRJe2X8mtv4XrVITg5BldvN0t4lsjAugxmuqOrkTJVmSYLW1btTAMNiljA2kZmPgoj+bpDXknseJ03NoCJAUAJpr9gtv0g5BsQZ7+w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1623155777; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=d+aT00SixwfN6y3TbETKjs2Mm4cbtsEqdyAtNOgVz9Q=; b=SCZjBDeyHLQA0uSJ7Y3z3cA88lQGFXtJ3rZJu7ZzGpobnLl9fG2W44YChVS0SMrCsMlXFIOud8PlFmaHF2nRJnxZX9Q76KSyR6IfDUaSF/jXP5yJK0+WNNm5SnJZTeCJurNprZLsjbMULElHrsvYB2rlk++RjMbCKHaza1/ln/Y= ARC-Authentication-Results: i=1; mx.zohomail.com; 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 1623155777193612.1314469797973; Tue, 8 Jun 2021 05:36:17 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.138462.256343 (Exim 4.92) (envelope-from ) id 1lqaxh-00010L-4R; Tue, 08 Jun 2021 12:36:05 +0000 Received: by outflank-mailman (output) from mailman id 138462.256343; Tue, 08 Jun 2021 12:36:05 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lqaxh-00010A-0N; Tue, 08 Jun 2021 12:36:05 +0000 Received: by outflank-mailman (input) for mailman id 138462; Tue, 08 Jun 2021 12:36:03 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lqaxf-0007Ok-8w for xen-devel@lists.xenproject.org; Tue, 08 Jun 2021 12:36:03 +0000 Received: from mx.upb.ro (unknown [141.85.13.201]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id ec443ab5-320a-4712-918f-847d522ef42d; Tue, 08 Jun 2021 12:35:44 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by mx.upb.ro (Postfix) with ESMTP id 144CDB56019A; Tue, 8 Jun 2021 15:35:43 +0300 (EEST) Received: from mx.upb.ro ([127.0.0.1]) by localhost (mx.upb.ro [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id C8chw8VKlSZH; Tue, 8 Jun 2021 15:35:40 +0300 (EEST) Received: from localhost (localhost [127.0.0.1]) by mx.upb.ro (Postfix) with ESMTP id 56AC1B560192; Tue, 8 Jun 2021 15:35:40 +0300 (EEST) Received: from mx.upb.ro ([127.0.0.1]) by localhost (mx.upb.ro [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id hIA9l4veBTRc; Tue, 8 Jun 2021 15:35:40 +0300 (EEST) Received: from localhost.localdomain (unknown [188.25.174.245]) by mx.upb.ro (Postfix) with ESMTPSA id 819B0B56019B; Tue, 8 Jun 2021 15:35:39 +0300 (EEST) 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: ec443ab5-320a-4712-918f-847d522ef42d X-Virus-Scanned: amavisd-new at upb.ro From: Costin Lupu To: xen-devel@lists.xenproject.org Cc: Christian Lindig , David Scott , Ian Jackson , Wei Liu , Julien Grall , Dario Faggioli Subject: [PATCH v4 5/5] tools/ocaml: Fix redefinition errors Date: Tue, 8 Jun 2021 15:35:29 +0300 Message-Id: X-Mailer: git-send-email 2.20.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" If PAGE_SIZE is already defined in the system (e.g. in /usr/include/limits.h header) then gcc will trigger a redefinition error because of -Werror. This patch replaces usage of PAGE_* macros with XC_PAGE_* macros in order to avo= id confusion between control domain page granularity (PAGE_* definitions) and guest domain page granularity (which is what we are dealing with here). Same issue applies for redefinitions of Val_none and Some_val macros which can be already define in the OCaml system headers (e.g. /usr/lib/ocaml/caml/mlvalues.h). Signed-off-by: Costin Lupu Reviewed-by: Julien Grall Tested-by: Dario Faggioli Acked-by: Christian Lindig > --- tools/ocaml/libs/xc/xenctrl_stubs.c | 10 ++++------ tools/ocaml/libs/xentoollog/xentoollog_stubs.c | 4 ++++ tools/ocaml/libs/xl/xenlight_stubs.c | 4 ++++ 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/tools/ocaml/libs/xc/xenctrl_stubs.c b/tools/ocaml/libs/xc/xenc= trl_stubs.c index d05d7bb30e..f9e33e599a 100644 --- a/tools/ocaml/libs/xc/xenctrl_stubs.c +++ b/tools/ocaml/libs/xc/xenctrl_stubs.c @@ -36,14 +36,12 @@ =20 #include "mmap_stubs.h" =20 -#define PAGE_SHIFT 12 -#define PAGE_SIZE (1UL << PAGE_SHIFT) -#define PAGE_MASK (~(PAGE_SIZE-1)) - #define _H(__h) ((xc_interface *)(__h)) #define _D(__d) ((uint32_t)Int_val(__d)) =20 +#ifndef Val_none #define Val_none (Val_int(0)) +#endif =20 #define string_of_option_array(array, index) \ ((Field(array, index) =3D=3D Val_none) ? NULL : String_val(Field(Field(ar= ray, index), 0))) @@ -818,7 +816,7 @@ CAMLprim value stub_xc_domain_memory_increase_reservati= on(value xch, CAMLparam3(xch, domid, mem_kb); int retval; =20 - unsigned long nr_extents =3D ((unsigned long)(Int64_val(mem_kb))) >> (PAG= E_SHIFT - 10); + unsigned long nr_extents =3D ((unsigned long)(Int64_val(mem_kb))) >> (XC_= PAGE_SHIFT - 10); =20 uint32_t c_domid =3D _D(domid); caml_enter_blocking_section(); @@ -924,7 +922,7 @@ CAMLprim value stub_pages_to_kib(value pages) { CAMLparam1(pages); =20 - CAMLreturn(caml_copy_int64(Int64_val(pages) << (PAGE_SHIFT - 10))); + CAMLreturn(caml_copy_int64(Int64_val(pages) << (XC_PAGE_SHIFT - 10))); } =20 =20 diff --git a/tools/ocaml/libs/xentoollog/xentoollog_stubs.c b/tools/ocaml/l= ibs/xentoollog/xentoollog_stubs.c index bf64b211c2..e4306a0c2f 100644 --- a/tools/ocaml/libs/xentoollog/xentoollog_stubs.c +++ b/tools/ocaml/libs/xentoollog/xentoollog_stubs.c @@ -53,8 +53,12 @@ static char * dup_String_val(value s) #include "_xtl_levels.inc" =20 /* Option type support as per http://www.linux-nantes.org/~fmonnier/ocaml/= ocaml-wrapping-c.php */ +#ifndef Val_none #define Val_none Val_int(0) +#endif +#ifndef Some_val #define Some_val(v) Field(v,0) +#endif =20 static value Val_some(value v) { diff --git a/tools/ocaml/libs/xl/xenlight_stubs.c b/tools/ocaml/libs/xl/xen= light_stubs.c index 352a00134d..45b8af61c7 100644 --- a/tools/ocaml/libs/xl/xenlight_stubs.c +++ b/tools/ocaml/libs/xl/xenlight_stubs.c @@ -227,8 +227,12 @@ static value Val_string_list(libxl_string_list *c_val) } =20 /* Option type support as per http://www.linux-nantes.org/~fmonnier/ocaml/= ocaml-wrapping-c.php */ +#ifndef Val_none #define Val_none Val_int(0) +#endif +#ifndef Some_val #define Some_val(v) Field(v,0) +#endif =20 static value Val_some(value v) { --=20 2.20.1