From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by sourceware.org (Postfix) with ESMTP id 8B2E5385BF9E for ; Tue, 23 Mar 2021 20:25:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 8B2E5385BF9E Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-25-aSVmP-PiM--5v1gZatu8jg-1; Tue, 23 Mar 2021 16:25:28 -0400 X-MC-Unique: aSVmP-PiM--5v1gZatu8jg-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 2D0AE107ACCA; Tue, 23 Mar 2021 20:25:27 +0000 (UTC) Received: from rhel8.vm.delorie.com (ovpn-112-40.rdu2.redhat.com [10.10.112.40]) by smtp.corp.redhat.com (Postfix) with ESMTPS id EFEBF18A5C; Tue, 23 Mar 2021 20:25:26 +0000 (UTC) Received: from rhel8.vm.redhat.com (localhost [127.0.0.1]) by rhel8.vm.delorie.com (8.15.2/8.15.2) with ESMTP id 12NKPPBB047764; Tue, 23 Mar 2021 16:25:25 -0400 From: DJ Delorie To: Szabolcs Nagy Cc: libc-alpha@sourceware.org Subject: Re: [PATCH 3/6] malloc: Use chunk2rawmem throughout In-Reply-To: (message from Szabolcs Nagy on Fri, 19 Mar 2021 13:26:49 +0000) Date: Tue, 23 Mar 2021 16:25:25 -0400 Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain X-Spam-Status: No, score=-6.3 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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-List-Received-Date: Tue, 23 Mar 2021 20:25:35 -0000 Szabolcs Nagy writes: > The difference between chunk2mem and chunk2rawmem is that the latter > does not get the memory tag for the returned pointer. It turns out > chunk2rawmem almost always works: Given that these two macros are identical on non-aarch64 systems, I'm going to gloss over the "is it tagged correctly" question since you folks can just test it, and other targets won't care ;-) LGTM Reviewed-by: DJ Delorie > sysmalloc: Returns untagged memory. > _int_malloc: Returns untagged memory. > _int_free: Takes untagged memory. > _int_memalign: Returns untagged memory. > _int_realloc: Takes and returns tagged memory. We should probably put this information in comments at each function implementation too, but at least it's in the source files :-) > - newmem = chunk2mem (newp); > + newmem = tag_at (chunk2rawmem (newp)); Ok. > headers have distinct tags. Converting fully from one to the other > involves extracting the tag at the other address and creating a > suitable pointer using it. That can be quite expensive. There are > - many occasions, though when the pointer will not be dereferenced > - (for example, because we only want to assert that the pointer is > - correctly aligned). In these cases it is more efficient not > - to extract the tag, since the answer will be the same either way. > - chunk2rawmem() can be used in these cases. > - */ > + cases when the pointers are not dereferenced (for example only used > + for alignment check) so the tags are not relevant, and there are > + cases when user data is not tagged distinctly from malloc headers > + (user data is untagged because tagging is done late in malloc and > + early in free). User memory tagging across internal interfaces: > + > + sysmalloc: Returns untagged memory. > + _int_malloc: Returns untagged memory. > + _int_free: Takes untagged memory. > + _int_memalign: Returns untagged memory. > + _int_memalign: Returns untagged memory. > + _mid_memalign: Returns tagged memory. > + _int_realloc: Takes and returns tagged memory. > +*/ Ok. > -/* Convert a user mem pointer to a chunk address without correcting > +/* Convert a chunk address to a user mem pointer without correcting > the tag. */ > #define chunk2rawmem(p) ((void*)((char*)(p) + CHUNK_HDR_SZ)) Heh. Ok. > #define misaligned_chunk(p) \ > - ((uintptr_t)(MALLOC_ALIGNMENT == CHUNK_HDR_SZ ? (p) : chunk2mem (p)) \ > + ((uintptr_t)(MALLOC_ALIGNMENT == CHUNK_HDR_SZ ? (p) : chunk2rawmem (p)) \ > & MALLOC_ALIGN_MASK) Ok. > - return chunk2mem (p); > + return chunk2rawmem (p); Ok. > - return chunk2mem (p); > + return chunk2rawmem (p); Ok. > - uintptr_t mem = (uintptr_t) chunk2mem(p); > + uintptr_t mem = (uintptr_t) chunk2rawmem(p); Ok. > - tcache_entry *e = (tcache_entry *) chunk2mem (chunk); > + tcache_entry *e = (tcache_entry *) chunk2rawmem (chunk); Ok. > - void *newmem = chunk2mem (newp); > + void *newmem = tag_at (chunk2rawmem (newp)); Ok. > - void *p = chunk2mem (victim); > + void *p = chunk2rawmem (victim); Ok. > - void *p = chunk2mem (victim); > + void *p = chunk2rawmem (victim); Ok. > - void *p = chunk2mem (victim); > + void *p = chunk2rawmem (victim); Ok. > - void *p = chunk2mem (victim); > + void *p = chunk2rawmem (victim); Ok. > - void *p = chunk2mem (victim); > + void *p = chunk2rawmem (victim); Ok. > - void *p = chunk2mem (victim); > + void *p = chunk2rawmem (victim); Ok. > - void *p = chunk2mem (victim); > + void *p = chunk2rawmem (victim); Ok. > - tcache_entry *e = (tcache_entry *) chunk2mem (p); > + tcache_entry *e = (tcache_entry *) chunk2rawmem (p); Ok. > - free_perturb (chunk2mem(p), size - CHUNK_HDR_SZ); > + free_perturb (chunk2rawmem(p), size - CHUNK_HDR_SZ); Ok. > - free_perturb (chunk2mem(p), size - CHUNK_HDR_SZ); > + free_perturb (chunk2rawmem(p), size - CHUNK_HDR_SZ); Ok. > - return chunk2mem (newp); > + return chunk2rawmem (newp); Ok. > - return chunk2mem (p); > + return chunk2rawmem (p); Ok.