All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jan Beulich <jbeulich@suse.com>
To: Oleksandr <olekstysh@gmail.com>
Cc: sstabellini@kernel.org, Wei Liu <wl@xen.org>,
	Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>,
	George Dunlap <George.Dunlap@eu.citrix.com>,
	Andrew Cooper <andrew.cooper3@citrix.com>,
	Ian Jackson <ian.jackson@eu.citrix.com>, Tim Deegan <tim@xen.org>,
	Oleksandr Tyshchenko <oleksandr_tyshchenko@epam.com>,
	julien.grall@arm.com, Paul Durrant <paul.durrant@citrix.com>,
	xen-devel@lists.xenproject.org, Volodymyr_Babchuk@epam.com
Subject: Re: [Xen-devel] [PATCH V4 4/8] xen/common: Introduce _xrealloc function
Date: Mon, 16 Sep 2019 17:24:51 +0200	[thread overview]
Message-ID: <93811967-b49d-7a86-6d19-647cd0e8d1dd@suse.com> (raw)
In-Reply-To: <0021c5ab-457e-7cbf-a5c7-7d8676503116@gmail.com>

On 16.09.2019 17:03, Oleksandr wrote:
> On 16.09.19 13:13, Jan Beulich wrote:
>> On 13.09.2019 17:35, Oleksandr Tyshchenko wrote:
>>> --- a/xen/common/xmalloc_tlsf.c
>>> +++ b/xen/common/xmalloc_tlsf.c
>>> @@ -598,6 +598,58 @@ void *_xzalloc(unsigned long size, unsigned long align)
>>>       return p ? memset(p, 0, size) : p;
>>>   }
>>>   
>>> +void *_xrealloc(void *ptr, unsigned long size, unsigned long align)
>>> +{
>>> +    unsigned long curr_size, tmp_size;
>>> +    void *p;
>>> +
>>> +    if ( !size )
>>> +    {
>>> +        xfree(ptr);
>>> +        return ZERO_BLOCK_PTR;
>>> +    }
>>> +
>>> +    if ( ptr == NULL || ptr == ZERO_BLOCK_PTR )
>>> +        return _xmalloc(size, align);
>>> +
>>> +    if ( !((unsigned long)ptr & (PAGE_SIZE - 1)) )
>>> +        curr_size = PFN_ORDER(virt_to_page(ptr)) << PAGE_SHIFT;
>> While the present MAX_ORDER setting will prevent allocations of
>> 4GiB or above from succeeding, may I ask that you don't introduce
>> latent issues in case MAX_ORDER would ever need bumping?
> Sure (I assume, you are talking about possible truncation):
> 
> if ( !((unsigned long)ptr & (PAGE_SIZE - 1)) )
>      curr_size = (unsigned long)PFN_ORDER(virt_to_page(ptr)) << PAGE_SHIFT;

Yes.

>>> +            ROUNDUP_SIZE(tmp_size);
>>> +
>>> +    if ( tmp_size <= curr_size && ((unsigned long)ptr & (align - 1)) == 0 )
>>> +        return ptr; /* the size and alignment fit in already allocated space */
>> You also don't seem to ever update ptr in case you want to use the
>> (head) padding, i.e. you'd hand back a pointer to a block which the
>> caller would assume extends past its actual end. I think you want
>> to calculate the new tentative pointer (taking the requested
>> alignment into account), and only from that calculate curr_size
>> (which perhaps would better be named "usable" or "space" or some
>> such). Obviously the (head) padding block may need updating, too.
> 
> I am afraid I don't completely understand your point here. And sorry for 
> the maybe naive question, but what is the "(head) padding" here?

The very padding talked about earlier. I did add "(head)" to clarify
it's that specific case - after all tail padding is far more common.

Jan

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

  reply	other threads:[~2019-09-16 15:26 UTC|newest]

Thread overview: 45+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-13 15:35 [Xen-devel] [PATCH V4 0/8] iommu/arm: Add Renesas IPMMU-VMSA support + Linux's iommu_fwspec Oleksandr Tyshchenko
2019-09-13 15:35 ` [Xen-devel] [PATCH V4 1/8] iommu/arm: Add iommu_helpers.c file to keep common for IOMMUs stuff Oleksandr Tyshchenko
2019-09-13 15:35 ` [Xen-devel] [PATCH V4 2/8] iommu/arm: Add ability to handle deferred probing request Oleksandr Tyshchenko
2019-09-19  9:44   ` Julien Grall
2019-09-19  9:57     ` Oleksandr
2019-09-13 15:35 ` [Xen-devel] [PATCH V4 3/8] iommu/arm: Order the headers alphabetically in iommu.c Oleksandr Tyshchenko
2019-09-19  9:48   ` Julien Grall
2019-09-13 15:35 ` [Xen-devel] [PATCH V4 4/8] xen/common: Introduce _xrealloc function Oleksandr Tyshchenko
2019-09-16 10:13   ` Jan Beulich
2019-09-16 15:03     ` Oleksandr
2019-09-16 15:24       ` Jan Beulich [this message]
2019-09-23 12:50         ` Oleksandr
2019-09-23 13:31           ` Jan Beulich
2019-09-23 13:41             ` Oleksandr
2019-09-13 15:35 ` [Xen-devel] [PATCH V4 5/8] xen/common: Introduce xrealloc_flex_struct() helper macros Oleksandr Tyshchenko
2019-09-16 10:37   ` Jan Beulich
2019-09-16 18:11     ` Oleksandr
2019-09-20  9:51       ` Oleksandr
2019-09-20 10:25         ` Jan Beulich
2019-09-13 15:35 ` [Xen-devel] [PATCH V4 6/8] iommu/arm: Add lightweight iommu_fwspec support Oleksandr Tyshchenko
2019-09-16 10:40   ` Jan Beulich
2019-09-16 18:08     ` Oleksandr
2019-09-17  6:12       ` Jan Beulich
2019-09-17 18:18         ` Oleksandr
2019-09-19 10:12           ` Julien Grall
2019-09-19 10:15             ` Jan Beulich
2019-09-19 10:57               ` Oleksandr
2019-09-19 11:36                 ` Julien Grall
2019-09-19 12:07                   ` Oleksandr
2019-09-13 15:35 ` [Xen-devel] [PATCH V4 7/8] iommu/arm: Introduce iommu_add_dt_device API Oleksandr Tyshchenko
2019-09-16  9:53   ` Jan Beulich
2019-09-16 11:07     ` Oleksandr
2019-09-19 11:35   ` Julien Grall
2019-09-19 12:25     ` Oleksandr
2019-09-19 12:29       ` Julien Grall
2019-09-19 13:26         ` Oleksandr
2019-09-20 13:18           ` Julien Grall
2019-09-20 13:24             ` Oleksandr
2019-09-13 15:35 ` [Xen-devel] [PATCH V4 8/8] iommu/arm: Add Renesas IPMMU-VMSA support Oleksandr Tyshchenko
2019-09-19 11:45   ` Julien Grall
2019-09-19 11:58     ` Oleksandr
2019-09-19 12:05       ` Julien Grall
2019-09-19 12:08         ` Oleksandr
2019-09-20  0:25   ` Yoshihiro Shimoda
2019-09-20 12:57     ` Oleksandr

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=93811967-b49d-7a86-6d19-647cd0e8d1dd@suse.com \
    --to=jbeulich@suse.com \
    --cc=George.Dunlap@eu.citrix.com \
    --cc=Volodymyr_Babchuk@epam.com \
    --cc=andrew.cooper3@citrix.com \
    --cc=ian.jackson@eu.citrix.com \
    --cc=julien.grall@arm.com \
    --cc=konrad.wilk@oracle.com \
    --cc=oleksandr_tyshchenko@epam.com \
    --cc=olekstysh@gmail.com \
    --cc=paul.durrant@citrix.com \
    --cc=sstabellini@kernel.org \
    --cc=tim@xen.org \
    --cc=wl@xen.org \
    --cc=xen-devel@lists.xenproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.