From patchwork Sun Apr 23 21:55:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Bugaev X-Patchwork-Id: 1772496 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=oxokTANT; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Q4MX65jrTz23hs for ; Mon, 24 Apr 2023 07:55:50 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id BF01A3857357 for ; Sun, 23 Apr 2023 21:55:48 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BF01A3857357 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1682286948; bh=/yfNzVVfOruWe50R+UZPHrSzw7GSYQOsOpkZLkBE4sc=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=oxokTANTZntJ8r4S6hlp3433k1VOpoaJQ8+WZv2xZr8Oxz/nhjQnaUg9G1lTxL/ER BaqJU4cwy87nNxsayHfqJhCthf5XsmFz4cBahIfzewlLq/vLI4vsZQN1NeQMHuA8G2 7Slu5Mg/o/HXU/bRSk0x2nae7q1vyDPHurHJstFw= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-lj1-x230.google.com (mail-lj1-x230.google.com [IPv6:2a00:1450:4864:20::230]) by sourceware.org (Postfix) with ESMTPS id AC1C83858C83 for ; Sun, 23 Apr 2023 21:55:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org AC1C83858C83 Received: by mail-lj1-x230.google.com with SMTP id 38308e7fff4ca-2a7b02615f1so35821091fa.0 for ; Sun, 23 Apr 2023 14:55:30 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682286929; x=1684878929; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=/yfNzVVfOruWe50R+UZPHrSzw7GSYQOsOpkZLkBE4sc=; b=AfKL+RshCnfa5tdBxNLKjgedjYwRYbGQ81QusaZoiSvYEv7pPXP2ztwgsnjpM0fA9q qw8gXrbrFx8MZK+PCj+OX8XQvW/UQJd9dWehO41Qt51+wC4qzcrWuIeE7BNwlPTPFX+Q 4DICaqa79MSAwV5ObMZClqOu1GcXntZ/u/PhITFnkTcwzx9ypcImdCWinVnbi285Odl6 DnB3/nUTHo3z+Qnjm9+AuazW+yfMB9mG91mKzNUc9Q9eTcHi63TCQzWNQ/3sO4QBR2QT zOodKzQpfluw78awn28aztx1zoDQdAe53HHosJbuTbuNT1WRugtJTq9USPjnEvepJZdw opdw== X-Gm-Message-State: AAQBX9edyzPx2e8otFzYUqAL7o8k+QpNUdRLuyKoREV4u7MbG61HoUYl VEyHGzeX/5EzhuFCT5Oj4t+MgMl2Mz4aRA== X-Google-Smtp-Source: AKy350ZTewtIZ5f/t8TqjZ4xhSK76YxNYu2bWX4BqNXR25mOqD0Pnsv9AVNAAXV/KXJ9J4nR99ggCA== X-Received: by 2002:ac2:4243:0:b0:4e8:3f38:7d21 with SMTP id m3-20020ac24243000000b004e83f387d21mr2797654lfl.28.1682286928506; Sun, 23 Apr 2023 14:55:28 -0700 (PDT) Received: from surface-pro-6.. ([2a00:1370:818c:4a57:e26d:6595:78ee:6d64]) by smtp.gmail.com with ESMTPSA id q8-20020ac25a08000000b004ecb06acbb3sm1393905lfn.281.2023.04.23.14.55.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 23 Apr 2023 14:55:28 -0700 (PDT) To: libc-alpha@sourceware.org Cc: bug-hurd@gnu.org, Samuel Thibault Subject: [PATCH 1/4] hurd: Implement MAP_32BIT Date: Mon, 24 Apr 2023 00:55:23 +0300 Message-Id: <20230423215526.346009-1-bugaevc@gmail.com> X-Mailer: git-send-email 2.40.0 MIME-Version: 1.0 X-Spam-Status: No, score=-11.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Sergey Bugaev via Libc-alpha From: Sergey Bugaev Reply-To: Sergey Bugaev Errors-To: libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org Sender: "Libc-alpha" This is a flag that can be passed to mmap () to request that the mapping being established should be located in the lower 2 GB area of the address space, so only the lower 31 (not 32) bits can be set in its address, and the address can be represented as a 32-bit integer without truncating it. This flag is intended to be compatible with Linux, FreeBSD, and Darwin flags of the same name. Out of those systems, it appears Linux and FreeBSD take MAP_32BIT to mean "map 31 bit", whereas Darwin allows the 32nd bit to be set in the address as well. The Hurd follows Linux and FreeBSD behavior. Unlike on those systems, on the Hurd MAP_32BIT is defined on all supported architectures (which currently are only i386 and x86_64). Signed-off-by: Sergey Bugaev --- sysdeps/mach/hurd/bits/mman_ext.h | 1 + sysdeps/mach/hurd/dl-sysdep.c | 8 +++++--- sysdeps/mach/hurd/mmap.c | 10 ++++++---- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/sysdeps/mach/hurd/bits/mman_ext.h b/sysdeps/mach/hurd/bits/mman_ext.h index f022826e..bbb94743 100644 --- a/sysdeps/mach/hurd/bits/mman_ext.h +++ b/sysdeps/mach/hurd/bits/mman_ext.h @@ -22,4 +22,5 @@ #ifdef __USE_GNU # define SHM_ANON ((const char *) 1) +# define MAP_32BIT 0x1000 #endif /* __USE_GNU */ diff --git a/sysdeps/mach/hurd/dl-sysdep.c b/sysdeps/mach/hurd/dl-sysdep.c index 6e167e12..d7b309e0 100644 --- a/sysdeps/mach/hurd/dl-sysdep.c +++ b/sysdeps/mach/hurd/dl-sysdep.c @@ -451,7 +451,7 @@ __mmap (void *addr, size_t len, int prot, int flags, int fd, off_t offset) { error_t err; vm_prot_t vmprot; - vm_address_t mapaddr; + vm_address_t mapaddr, mask; mach_port_t memobj_rd, memobj_wr; vmprot = VM_PROT_NONE; @@ -462,6 +462,8 @@ __mmap (void *addr, size_t len, int prot, int flags, int fd, off_t offset) if (prot & PROT_EXEC) vmprot |= VM_PROT_EXECUTE; + mask = (flags & MAP_32BIT) ? ~(vm_address_t) 0x7FFFFFFF : 0; + if (flags & MAP_ANON) memobj_rd = MACH_PORT_NULL; else @@ -476,7 +478,7 @@ __mmap (void *addr, size_t len, int prot, int flags, int fd, off_t offset) mapaddr = (vm_address_t) addr; err = __vm_map (__mach_task_self (), - &mapaddr, (vm_size_t) len, 0, + &mapaddr, (vm_size_t) len, mask, !(flags & MAP_FIXED), memobj_rd, (vm_offset_t) offset, @@ -491,7 +493,7 @@ __mmap (void *addr, size_t len, int prot, int flags, int fd, off_t offset) if (! err) err = __vm_map (__mach_task_self (), &mapaddr, (vm_size_t) len, - 0, + mask, !(flags & MAP_FIXED), memobj_rd, (vm_offset_t) offset, flags & (MAP_COPY|MAP_PRIVATE), diff --git a/sysdeps/mach/hurd/mmap.c b/sysdeps/mach/hurd/mmap.c index 20a41e36..c3cc1856 100644 --- a/sysdeps/mach/hurd/mmap.c +++ b/sysdeps/mach/hurd/mmap.c @@ -36,7 +36,7 @@ __mmap (void *addr, size_t len, int prot, int flags, int fd, off_t offset) error_t err; vm_prot_t vmprot, max_vmprot; memory_object_t memobj; - vm_address_t mapaddr; + vm_address_t mapaddr, mask; boolean_t copy; mapaddr = (vm_address_t) addr; @@ -55,6 +55,8 @@ __mmap (void *addr, size_t len, int prot, int flags, int fd, off_t offset) copy = ! (flags & MAP_SHARED); + mask = (flags & MAP_32BIT) ? ~(vm_address_t) 0x7FFFFFFF : 0; + switch (flags & MAP_TYPE) { default: @@ -134,7 +136,7 @@ __mmap (void *addr, size_t len, int prot, int flags, int fd, off_t offset) max_vmprot = VM_PROT_ALL; err = __vm_map (__mach_task_self (), - &mapaddr, (vm_size_t) len, (vm_address_t) 0, + &mapaddr, (vm_size_t) len, mask, mapaddr == 0, memobj, (vm_offset_t) offset, copy, vmprot, max_vmprot, @@ -149,7 +151,7 @@ __mmap (void *addr, size_t len, int prot, int flags, int fd, off_t offset) err = __vm_deallocate (__mach_task_self (), mapaddr, len); if (! err) err = __vm_map (__mach_task_self (), - &mapaddr, (vm_size_t) len, (vm_address_t) 0, + &mapaddr, (vm_size_t) len, mask, 0, memobj, (vm_offset_t) offset, copy, vmprot, max_vmprot, copy ? VM_INHERIT_COPY : VM_INHERIT_SHARE); @@ -159,7 +161,7 @@ __mmap (void *addr, size_t len, int prot, int flags, int fd, off_t offset) { if (mapaddr != 0 && (err == KERN_NO_SPACE || err == KERN_INVALID_ADDRESS)) err = __vm_map (__mach_task_self (), - &mapaddr, (vm_size_t) len, (vm_address_t) 0, + &mapaddr, (vm_size_t) len, mask, 1, memobj, (vm_offset_t) offset, copy, vmprot, max_vmprot, copy ? VM_INHERIT_COPY : VM_INHERIT_SHARE); From patchwork Sun Apr 23 21:55:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Bugaev X-Patchwork-Id: 1772495 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=ivComQXU; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Q4MX44wPBz23hs for ; Mon, 24 Apr 2023 07:55:48 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 9DDC1385770E for ; Sun, 23 Apr 2023 21:55:46 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9DDC1385770E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1682286946; bh=L7oeWsZL9dZlsjAqHQOHiPrLSGr+/RfmGfPLeQUTNUY=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=ivComQXUmEz5JeBWqVbI78y+57bBrOf0AYedIBRR8BghsZLkOKwyVDStwEx6pfDGG bBJyTQDHaaRsle3M/avqKBn0ynk838BymJdjCaxkWkTKrHmor4dx4PI3+3rbglPaYx PJzitnn6ytmvuH1rr+E3JjWJfpDMXTUOhS3wiBOg= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-lf1-x132.google.com (mail-lf1-x132.google.com [IPv6:2a00:1450:4864:20::132]) by sourceware.org (Postfix) with ESMTPS id 2F7713858C50 for ; Sun, 23 Apr 2023 21:55:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2F7713858C50 Received: by mail-lf1-x132.google.com with SMTP id 2adb3069b0e04-4efe8b3f3f7so1430837e87.2 for ; Sun, 23 Apr 2023 14:55:31 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682286929; x=1684878929; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=L7oeWsZL9dZlsjAqHQOHiPrLSGr+/RfmGfPLeQUTNUY=; b=Fdy0zpquX+o14XOE7LbjJlUbi966NLhsQRRUjnfKx2jzWsOILjrONKfh0LBK72DLG3 5qE/7v+/L0i5Olos3/PK+a7QBtNNY4BvaSqR6of6gRgnTz996lOHf6pDZQwyAEyugAqm +Gs2BjoljTHnN+IK7u6KApWBuUrzXJf9ZIDHlV1IQGd8PUZn3InfD2az/7UVJmbMm3K6 Z8socwM9+SOOc2epAufgpZEScp4QujoZ7bA9rQM5LGIWbXmvWyXDkKHkmPHRh8mn6Rwg FvDCPi/V/yuZQvtMEmDPmGh08CmXWCgtyk0m6UDjVaj5c+OP2nu2ybXHMfDrBfO0TeFc OqIg== X-Gm-Message-State: AAQBX9dB2Fr006R0VCSuABctnUbuN2Qd0g1lvFMtPOECr/APQUEE5u3e jDScxiGml0KaVOifCFhbAnZ2OwNTFeyXkw== X-Google-Smtp-Source: AKy350aQ/eyNkY2dqI/2FxOLwL1YTX3piFa+qalqZkJwc3VTCkypeJrnK0MxtgmoHb6Z5HquCSsyVA== X-Received: by 2002:ac2:5dfb:0:b0:4e8:5392:492c with SMTP id z27-20020ac25dfb000000b004e85392492cmr2256326lfq.43.1682286929351; Sun, 23 Apr 2023 14:55:29 -0700 (PDT) Received: from surface-pro-6.. ([2a00:1370:818c:4a57:e26d:6595:78ee:6d64]) by smtp.gmail.com with ESMTPSA id q8-20020ac25a08000000b004ecb06acbb3sm1393905lfn.281.2023.04.23.14.55.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 23 Apr 2023 14:55:28 -0700 (PDT) To: libc-alpha@sourceware.org Cc: bug-hurd@gnu.org, Samuel Thibault Subject: [PATCH 2/4] hurd: Don't attempt to deallocate MACH_PORT_DEAD Date: Mon, 24 Apr 2023 00:55:24 +0300 Message-Id: <20230423215526.346009-2-bugaevc@gmail.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230423215526.346009-1-bugaevc@gmail.com> References: <20230423215526.346009-1-bugaevc@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-11.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Sergey Bugaev via Libc-alpha From: Sergey Bugaev Reply-To: Sergey Bugaev Errors-To: libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org Sender: "Libc-alpha" ...in some more places. Signed-off-by: Sergey Bugaev --- sysdeps/mach/hurd/dl-sysdep.c | 2 +- sysdeps/mach/hurd/mmap.c | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/sysdeps/mach/hurd/dl-sysdep.c b/sysdeps/mach/hurd/dl-sysdep.c index d7b309e0..25a12774 100644 --- a/sysdeps/mach/hurd/dl-sysdep.c +++ b/sysdeps/mach/hurd/dl-sysdep.c @@ -472,7 +472,7 @@ __mmap (void *addr, size_t len, int prot, int flags, int fd, off_t offset) err = __io_map ((mach_port_t) fd, &memobj_rd, &memobj_wr); if (err) return __hurd_fail (err), MAP_FAILED; - if (memobj_wr != MACH_PORT_NULL) + if (MACH_PORT_VALID (memobj_wr)) __mach_port_deallocate (__mach_task_self (), memobj_wr); } diff --git a/sysdeps/mach/hurd/mmap.c b/sysdeps/mach/hurd/mmap.c index c3cc1856..790eb238 100644 --- a/sysdeps/mach/hurd/mmap.c +++ b/sysdeps/mach/hurd/mmap.c @@ -91,7 +91,7 @@ __mmap (void *addr, size_t len, int prot, int flags, int fd, off_t offset) if (wobj == robj) max_vmprot |= VM_PROT_WRITE; memobj = robj; - if (wobj != MACH_PORT_NULL) + if (MACH_PORT_VALID (wobj)) __mach_port_deallocate (__mach_task_self (), wobj); break; case PROT_WRITE: @@ -99,7 +99,7 @@ __mmap (void *addr, size_t len, int prot, int flags, int fd, off_t offset) if (robj == wobj) max_vmprot |= VM_PROT_READ|VM_PROT_EXECUTE; memobj = wobj; - if (robj != MACH_PORT_NULL) + if (MACH_PORT_VALID (robj)) __mach_port_deallocate (__mach_task_self (), robj); break; case PROT_READ|PROT_WRITE: @@ -167,7 +167,7 @@ __mmap (void *addr, size_t len, int prot, int flags, int fd, off_t offset) copy ? VM_INHERIT_COPY : VM_INHERIT_SHARE); } - if (memobj != MACH_PORT_NULL) + if (MACH_PORT_VALID (memobj)) __mach_port_deallocate (__mach_task_self (), memobj); if (err == KERN_PROTECTION_FAILURE) From patchwork Sun Apr 23 21:55:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Bugaev X-Patchwork-Id: 1772497 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=vVIvK/hl; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Q4MXt305wz23hs for ; Mon, 24 Apr 2023 07:56:30 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 6DFCC385771D for ; Sun, 23 Apr 2023 21:56:28 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6DFCC385771D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1682286988; bh=qBeAdZi81iccaLmE7yPrSBBu/BngQeSeDsQzDPS4YDc=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=vVIvK/hlvZYnAdZf0irlr+D4RKkSawI3hogElFHDKP9uEthmIASg48Ls3lj3xVPm3 FLV/1RThyAz3UV6UXdtpJ7ePA9wgR+HTYtxV4WJB/Fxp5s11m4XTnBKgKzmdeOODLt WlsQJXA40g/5YdPCguuZunDTZSz6xBxeGtAwLLrY= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-lf1-x129.google.com (mail-lf1-x129.google.com [IPv6:2a00:1450:4864:20::129]) by sourceware.org (Postfix) with ESMTPS id 236003858C53 for ; Sun, 23 Apr 2023 21:55:32 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 236003858C53 Received: by mail-lf1-x129.google.com with SMTP id 2adb3069b0e04-4eff1f7f34bso193177e87.0 for ; Sun, 23 Apr 2023 14:55:32 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682286930; x=1684878930; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=qBeAdZi81iccaLmE7yPrSBBu/BngQeSeDsQzDPS4YDc=; b=SwFvISGaEYWX3/LaIWDJW3dQNKmjHp9O24gzrPqlHLpnWg9cjqSogQUg+iqt15UzbJ BocJ4uEdykpI9QfLeQvsml1mwmwdbeqrVtO5DdTBosl8imWVdNxiQ64DXG9+oinsYAQX hhjg2u7Z0SghivOuwQmAxHCD8YRX3liSa8cbxBgDQ6Nl2RpVyllu0VvC9Dj2O0A4uF5G reqN9p2fOm+goVXdu65zrAK7JttehZCwnV6FXajwmd6Cz5mwVNYYbX3MSwNg2KKdLVUq nkfrqZyvuFhDMpbj8H3+QWg+jnI5CDxw9QoCb/bhiHVVWxeh25iOJXfxlZCrko9nXpQw o2jw== X-Gm-Message-State: AAQBX9eu4RhNXBfGxzOtMbYHfPw3JnEU/tCdKjQfNuW7cEDePSNCCRLD z4Aal8qQRixP3+Dstyw3TMg2gvU9ExVYKQ== X-Google-Smtp-Source: AKy350ZqJeQ1b4yIk3ghSE8J9kCwnowEIE5SBNfFNqNvJpURxdfdEsY2AhxwuSXYGjbm4iduKyo6eg== X-Received: by 2002:a05:6512:243:b0:4e0:ff8e:bbfe with SMTP id b3-20020a056512024300b004e0ff8ebbfemr2881460lfo.12.1682286930206; Sun, 23 Apr 2023 14:55:30 -0700 (PDT) Received: from surface-pro-6.. ([2a00:1370:818c:4a57:e26d:6595:78ee:6d64]) by smtp.gmail.com with ESMTPSA id q8-20020ac25a08000000b004ecb06acbb3sm1393905lfn.281.2023.04.23.14.55.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 23 Apr 2023 14:55:29 -0700 (PDT) To: libc-alpha@sourceware.org Cc: bug-hurd@gnu.org, Samuel Thibault Subject: [PATCH 3/4] hurd: Microoptimize mmap () Date: Mon, 24 Apr 2023 00:55:25 +0300 Message-Id: <20230423215526.346009-3-bugaevc@gmail.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230423215526.346009-1-bugaevc@gmail.com> References: <20230423215526.346009-1-bugaevc@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-11.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Sergey Bugaev via Libc-alpha From: Sergey Bugaev Reply-To: Sergey Bugaev Errors-To: libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org Sender: "Libc-alpha" Signed-off-by: Sergey Bugaev --- sysdeps/mach/hurd/mmap.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/sysdeps/mach/hurd/mmap.c b/sysdeps/mach/hurd/mmap.c index 790eb238..d570be24 100644 --- a/sysdeps/mach/hurd/mmap.c +++ b/sysdeps/mach/hurd/mmap.c @@ -42,7 +42,8 @@ __mmap (void *addr, size_t len, int prot, int flags, int fd, off_t offset) mapaddr = (vm_address_t) addr; /* ADDR and OFFSET must be page-aligned. */ - if ((mapaddr & (__vm_page_size - 1)) || (offset & (__vm_page_size - 1))) + if (__glibc_unlikely ((mapaddr & (__vm_page_size - 1)) + || (offset & (__vm_page_size - 1)))) return (void *) (long int) __hurd_fail (EINVAL); vmprot = VM_PROT_NONE; @@ -73,7 +74,8 @@ __mmap (void *addr, size_t len, int prot, int flags, int fd, off_t offset) mach_port_t robj, wobj; if (err = HURD_DPORT_USE (fd, __io_map (port, &robj, &wobj))) { - if (err == MIG_BAD_ID || err == EOPNOTSUPP || err == ENOSYS) + if (__glibc_unlikely (err == MIG_BAD_ID || err == EOPNOTSUPP + || err == ENOSYS)) err = ENODEV; /* File descriptor doesn't support mmap. */ return (void *) (long int) __hurd_dfail (fd, err); } @@ -173,7 +175,7 @@ __mmap (void *addr, size_t len, int prot, int flags, int fd, off_t offset) if (err == KERN_PROTECTION_FAILURE) err = EACCES; - if (err) + if (__glibc_unlikely (err)) return (void *) (long int) __hurd_fail (err); return (void *) mapaddr; From patchwork Sun Apr 23 21:55:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Bugaev X-Patchwork-Id: 1772498 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=LO+gbpbw; dkim-atps=neutral Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Q4MXw6WQFz23hs for ; Mon, 24 Apr 2023 07:56:32 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D6B963858422 for ; Sun, 23 Apr 2023 21:56:30 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D6B963858422 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1682286990; bh=BlTnaLZGSmx9pN/0u3YRfEIzFq2rPbcTmlnlwZV4rzg=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=LO+gbpbwhHwR3QeTwpryxJKkPDf185GmApkYClDeQ5jq7E8yJi3gMmqdwVbBhan4U LPrZWZNZUTxeAuu45Oqy6+5pi+VCIa3ycOwP0dnHfrpukdlrDVOejUpImf0VD66Zf+ sWOuFlu0f9rO/4/XVvgS0aAIhN5IgZKLGMU1sB0Q= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-lf1-x134.google.com (mail-lf1-x134.google.com [IPv6:2a00:1450:4864:20::134]) by sourceware.org (Postfix) with ESMTPS id 291333858C5E for ; Sun, 23 Apr 2023 21:55:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 291333858C5E Received: by mail-lf1-x134.google.com with SMTP id 2adb3069b0e04-4efe8b3f3f7so1430849e87.2 for ; Sun, 23 Apr 2023 14:55:33 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682286931; x=1684878931; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=BlTnaLZGSmx9pN/0u3YRfEIzFq2rPbcTmlnlwZV4rzg=; b=c0Pu8rAxagekcm/cJ4WBNq14eyB3RseOesL028nOyqUU7rs3wY/sxp739wHpccdrnM t4OTfYyQiSHoyrAichOqpiYMG5N9IBrGJSCczY2T1GGwzbky8JpBS19O+dFmvcMk4Mxy k/gr3ZhRoakZdormmQKLU/d8KJj0cwFIlHdPdAfhto27OOrHwJj2BhMgfL7I3+sa10mi dhcFQAf7D/3ubLnWKioD+Bi1gVT0LqOaai3+fdXR3LvGk5ia2965BBjLT7sqhbWGh2Cx TTm0C6h8Nq8nonZiTTwJ/W+udcETHCfPJY7SiRbuAz9qbK+jOs5555/x1W7saRADQTTV 19aA== X-Gm-Message-State: AAQBX9d/uBVAp7MKp5QJQUZ6DhXg04TmmUy29IdoemUM/lFk8Y3A297L k7N6tIv/uObzRFYnlmy4Libn5/TA5MZgcQ== X-Google-Smtp-Source: AKy350aTIo/CCRFxZH9V2Wes1j3HdSbiXdwVlZOTJY1sV0FbPjXI4H19JEJI8fG/5aGOAlP5lDiHrw== X-Received: by 2002:a05:6512:15e:b0:4ec:62ad:918c with SMTP id m30-20020a056512015e00b004ec62ad918cmr2757480lfo.30.1682286931223; Sun, 23 Apr 2023 14:55:31 -0700 (PDT) Received: from surface-pro-6.. ([2a00:1370:818c:4a57:e26d:6595:78ee:6d64]) by smtp.gmail.com with ESMTPSA id q8-20020ac25a08000000b004ecb06acbb3sm1393905lfn.281.2023.04.23.14.55.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 23 Apr 2023 14:55:30 -0700 (PDT) To: libc-alpha@sourceware.org Cc: bug-hurd@gnu.org, Samuel Thibault , "H . J . Lu" Subject: [RFC PATCH 4/4] hurd: Implement prefer_map_32bit_exec tunable Date: Mon, 24 Apr 2023 00:55:26 +0300 Message-Id: <20230423215526.346009-4-bugaevc@gmail.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230423215526.346009-1-bugaevc@gmail.com> References: <20230423215526.346009-1-bugaevc@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-11.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Sergey Bugaev via Libc-alpha From: Sergey Bugaev Reply-To: Sergey Bugaev Errors-To: libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org Sender: "Libc-alpha" This makes the prefer_map_32bit_exec tunable no longer Linux-specific. Signed-off-by: Sergey Bugaev --- sysdeps/mach/hurd/dl-sysdep.c | 5 ++++ sysdeps/mach/hurd/mmap.c | 6 +++++ sysdeps/unix/sysv/linux/x86_64/64/Makefile | 23 ------------------- sysdeps/x86_64/64/Makefile | 22 ++++++++++++++++++ .../linux => }/x86_64/64/dl-tunables.list | 0 .../linux => }/x86_64/64/tst-map-32bit-1a.c | 0 .../linux => }/x86_64/64/tst-map-32bit-1b.c | 0 .../linux => }/x86_64/64/tst-map-32bit-mod.c | 0 8 files changed, 33 insertions(+), 23 deletions(-) create mode 100644 sysdeps/x86_64/64/Makefile rename sysdeps/{unix/sysv/linux => }/x86_64/64/dl-tunables.list (100%) rename sysdeps/{unix/sysv/linux => }/x86_64/64/tst-map-32bit-1a.c (100%) rename sysdeps/{unix/sysv/linux => }/x86_64/64/tst-map-32bit-1b.c (100%) rename sysdeps/{unix/sysv/linux => }/x86_64/64/tst-map-32bit-mod.c (100%) diff --git a/sysdeps/mach/hurd/dl-sysdep.c b/sysdeps/mach/hurd/dl-sysdep.c index 25a12774..79ebb0ce 100644 --- a/sysdeps/mach/hurd/dl-sysdep.c +++ b/sysdeps/mach/hurd/dl-sysdep.c @@ -462,6 +462,11 @@ __mmap (void *addr, size_t len, int prot, int flags, int fd, off_t offset) if (prot & PROT_EXEC) vmprot |= VM_PROT_EXECUTE; +#ifdef __LP64__ + if ((addr == NULL) && (prot & PROT_EXEC) + && HAS_ARCH_FEATURE (Prefer_MAP_32BIT_EXEC)) + flags |= MAP_32BIT; +#endif mask = (flags & MAP_32BIT) ? ~(vm_address_t) 0x7FFFFFFF : 0; if (flags & MAP_ANON) diff --git a/sysdeps/mach/hurd/mmap.c b/sysdeps/mach/hurd/mmap.c index d570be24..c4ffbba3 100644 --- a/sysdeps/mach/hurd/mmap.c +++ b/sysdeps/mach/hurd/mmap.c @@ -18,6 +18,7 @@ #include #include #include +#include #include #include @@ -56,6 +57,11 @@ __mmap (void *addr, size_t len, int prot, int flags, int fd, off_t offset) copy = ! (flags & MAP_SHARED); +#ifdef __LP64__ + if ((addr == NULL) && (prot & PROT_EXEC) + && HAS_ARCH_FEATURE (Prefer_MAP_32BIT_EXEC)) + flags |= MAP_32BIT; +#endif mask = (flags & MAP_32BIT) ? ~(vm_address_t) 0x7FFFFFFF : 0; switch (flags & MAP_TYPE) diff --git a/sysdeps/unix/sysv/linux/x86_64/64/Makefile b/sysdeps/unix/sysv/linux/x86_64/64/Makefile index 1bf7d528..a7b6dc5a 100644 --- a/sysdeps/unix/sysv/linux/x86_64/64/Makefile +++ b/sysdeps/unix/sysv/linux/x86_64/64/Makefile @@ -1,25 +1,2 @@ # The default ABI is 64. default-abi := 64 - -ifeq ($(subdir),elf) - -tests-map-32bit = \ - tst-map-32bit-1a \ - tst-map-32bit-1b \ -# tests-map-32bit -tst-map-32bit-1a-no-pie = yes -tst-map-32bit-1b-no-pie = yes -tests += $(tests-map-32bit) - -modules-map-32bit = \ - tst-map-32bit-mod \ -# modules-map-32bit -modules-names += $(modules-map-32bit) - -$(objpfx)tst-map-32bit-mod.so: $(libsupport) -tst-map-32bit-1a-ENV = LD_PREFER_MAP_32BIT_EXEC=1 -$(objpfx)tst-map-32bit-1a: $(objpfx)tst-map-32bit-mod.so -tst-map-32bit-1b-ENV = GLIBC_TUNABLES=glibc.cpu.prefer_map_32bit_exec=1 -$(objpfx)tst-map-32bit-1b: $(objpfx)tst-map-32bit-mod.so - -endif diff --git a/sysdeps/x86_64/64/Makefile b/sysdeps/x86_64/64/Makefile new file mode 100644 index 00000000..73fcfe0b --- /dev/null +++ b/sysdeps/x86_64/64/Makefile @@ -0,0 +1,22 @@ +ifeq ($(subdir),elf) + +tests-map-32bit = \ + tst-map-32bit-1a \ + tst-map-32bit-1b \ +# tests-map-32bit +tst-map-32bit-1a-no-pie = yes +tst-map-32bit-1b-no-pie = yes +tests += $(tests-map-32bit) + +modules-map-32bit = \ + tst-map-32bit-mod \ +# modules-map-32bit +modules-names += $(modules-map-32bit) + +$(objpfx)tst-map-32bit-mod.so: $(libsupport) +tst-map-32bit-1a-ENV = LD_PREFER_MAP_32BIT_EXEC=1 +$(objpfx)tst-map-32bit-1a: $(objpfx)tst-map-32bit-mod.so +tst-map-32bit-1b-ENV = GLIBC_TUNABLES=glibc.cpu.prefer_map_32bit_exec=1 +$(objpfx)tst-map-32bit-1b: $(objpfx)tst-map-32bit-mod.so + +endif diff --git a/sysdeps/unix/sysv/linux/x86_64/64/dl-tunables.list b/sysdeps/x86_64/64/dl-tunables.list similarity index 100% rename from sysdeps/unix/sysv/linux/x86_64/64/dl-tunables.list rename to sysdeps/x86_64/64/dl-tunables.list diff --git a/sysdeps/unix/sysv/linux/x86_64/64/tst-map-32bit-1a.c b/sysdeps/x86_64/64/tst-map-32bit-1a.c similarity index 100% rename from sysdeps/unix/sysv/linux/x86_64/64/tst-map-32bit-1a.c rename to sysdeps/x86_64/64/tst-map-32bit-1a.c diff --git a/sysdeps/unix/sysv/linux/x86_64/64/tst-map-32bit-1b.c b/sysdeps/x86_64/64/tst-map-32bit-1b.c similarity index 100% rename from sysdeps/unix/sysv/linux/x86_64/64/tst-map-32bit-1b.c rename to sysdeps/x86_64/64/tst-map-32bit-1b.c diff --git a/sysdeps/unix/sysv/linux/x86_64/64/tst-map-32bit-mod.c b/sysdeps/x86_64/64/tst-map-32bit-mod.c similarity index 100% rename from sysdeps/unix/sysv/linux/x86_64/64/tst-map-32bit-mod.c rename to sysdeps/x86_64/64/tst-map-32bit-mod.c