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 [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id D4B0D3858C52 for ; Tue, 4 Apr 2023 17:54:47 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D4B0D3858C52 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1680630887; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=7n8LEYeNZWJDkt8HREFN9UTsQpRN4zg6E5CCKJei6JU=; b=XQGRXwTBNvSOBX2dcQ2Az6WHrDHOwq+JkHM9C/I0CSEdgiSeiM6WRSwLvM4xhOFdsurpNE J2+mvu4cMwA0mUWFGrJJaNc4WxMeVH3+Zv/X8CJjrFqOqb4xbpCncWhQNNlScTXUErKT/m YEXcRVAFzRFJbZVfTdnopGIjTmGxySI= Received: from mail-yw1-f198.google.com (mail-yw1-f198.google.com [209.85.128.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-593-nGUJGXtTNcGX0t1QEnWyzw-1; Tue, 04 Apr 2023 13:54:46 -0400 X-MC-Unique: nGUJGXtTNcGX0t1QEnWyzw-1 Received: by mail-yw1-f198.google.com with SMTP id 00721157ae682-545dd1a1e31so280654257b3.22 for ; Tue, 04 Apr 2023 10:54:46 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680630885; h=content-transfer-encoding:in-reply-to:organization:from:references :to:content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=7n8LEYeNZWJDkt8HREFN9UTsQpRN4zg6E5CCKJei6JU=; b=VNBsCxOSd+ICphPtkvzvZyY4hGyQPpHFyEMUZ6PG2tkq8vcRhAHOm6RySTh3lzKbpc jPQZH18NOEnGi9Ynzdvx2J2TgH+YmRmAEsQqeY18I0PsWOrG2bmLpyczEOoEKcB54ITv VLvM+9AH8lBWeGD8iiCaTyA8ljKNzMIThn7fEIEp5Xw0i9fCpeDTDxgqAOx5zwkYgJlk oOBKUfD91W+XV9hodGV83SovPaj2shnHp+IN2meKaORZ4pwN4s9kVI819TuKyqJR02IF KdtiPCi4luO4f1unvmdEEZhIvubza/aHPlKLRRc/kse9mbcqzNbXqX1/OQs8HxgBSIJW PhRQ== X-Gm-Message-State: AAQBX9d3NtzFpNwZzdGcVV4G2ndSP6cKYGk9gLBonOmlYCpsJnyzL77/ DAMhdjTBV2+3xNYWTfN2RH53Q9NedExEmj2j7jQk1dzID52D6IA5TCt3BAoHFPKDGazPCNw6liH oRKGT09GxKYKDJr42S4c1Wzln2qpN X-Received: by 2002:a81:dd07:0:b0:535:aff2:d264 with SMTP id e7-20020a81dd07000000b00535aff2d264mr3246095ywn.1.1680630885508; Tue, 04 Apr 2023 10:54:45 -0700 (PDT) X-Google-Smtp-Source: AKy350abwjw+1vkfW6q+TpWoRFRoPwmCogdb5WQJVF51FxxtpoHHagtUaC2pLWXJcfm0aB4xyvX0NA== X-Received: by 2002:a81:dd07:0:b0:535:aff2:d264 with SMTP id e7-20020a81dd07000000b00535aff2d264mr3246086ywn.1.1680630885283; Tue, 04 Apr 2023 10:54:45 -0700 (PDT) Received: from [192.168.0.241] ([198.48.244.52]) by smtp.gmail.com with ESMTPSA id a23-20020a811a17000000b00545a081849fsm3367931ywa.47.2023.04.04.10.54.44 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 04 Apr 2023 10:54:44 -0700 (PDT) Message-ID: <5c5304a6-f614-f0e5-306c-41a922f9a03c@redhat.com> Date: Tue, 4 Apr 2023 13:54:44 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.9.0 Subject: Re: [patch v1] malloc: set NON_MAIN_ARENA flag for reclaimed memalign chunk (BZ #30101) To: DJ Delorie , libc-alpha@sourceware.org References: From: Carlos O'Donell Organization: Red Hat In-Reply-To: X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-13.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,NICE_REPLY_A,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On 4/3/23 18:12, DJ Delorie via Libc-alpha wrote: > > From 61bd502ecac4d63f04c74bfc491ca675660d26b7 Mon Sep 17 00:00:00 2001 > From: DJ Delorie > Date: Mon, 3 Apr 2023 17:33:03 -0400 > Subject: malloc: set NON_MAIN_ARENA flag for reclaimed memalign chunk (BZ #30101) > > Based on these comments in malloc.c: > > size field is or'ed with NON_MAIN_ARENA if the chunk was obtained > from a non-main arena. This is only set immediately before handing > the chunk to the user, if necessary. > > The NON_MAIN_ARENA flag is never set for unsorted chunks, so it > does not have to be taken into account in size comparisons. > > When we pull a chunk off the unsorted list (or any list) we need to > make sure that flag is set properly before returning the chunk. > > diff --git a/malloc/malloc.c b/malloc/malloc.c > index 0315ac5d16..66e7ca57dd 100644 > --- a/malloc/malloc.c > +++ b/malloc/malloc.c > @@ -5147,6 +5147,8 @@ _int_memalign (mstate av, size_t alignment, size_t bytes) > p = victim; > m = chunk2mem (p); > set_inuse (p); > + if (av != &main_arena) > + set_non_main_arena (p); My preference is to: (a) Fix both cases where this happens. The other is here: 5199 /* Also give back spare room at the end */ 5200 if (!chunk_is_mmapped (p)) 5201 { 5202 size = chunksize (p); 5203 if ((unsigned long) (size) > (unsigned long) (nb + MINSIZE)) 5204 { 5205 remainder_size = size - nb; 5206 remainder = chunk_at_offset (p, nb); 5207 set_head (remainder, remainder_size | PREV_INUSE | 5208 (av != &main_arena ? NON_MAIN_ARENA : 0)); 5209 set_head_size (p, nb); 5210 _int_free (av, remainder, 1); 5211 } 5212 } (b) Remove the comment that says NON_MAIN_ARENA flag is never set, and adjust the comment to say it's always set. I want a *strong* invariant here that the chunks have their flags set correctly when placed into any of the lists, to do otherwise is incredibly confusing and is the root cause of the assertion triggering (very good of you to add it in the first place). > } > else > { > -- Cheers, Carlos.