From: Oleksandr <olekstysh@gmail.com>
To: Paul Durrant <Paul.Durrant@citrix.com>,
"xen-devel@lists.xenproject.org" <xen-devel@lists.xenproject.org>
Cc: "sstabellini@kernel.org" <sstabellini@kernel.org>,
Wei Liu <wl@xen.org>,
Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>,
Andrew Cooper <Andrew.Cooper3@citrix.com>,
"Tim \(Xen.org\)" <tim@xen.org>,
George Dunlap <George.Dunlap@citrix.com>,
Oleksandr Tyshchenko <oleksandr_tyshchenko@epam.com>,
"julien.grall@arm.com" <julien.grall@arm.com>,
Jan Beulich <jbeulich@suse.com>,
Ian Jackson <Ian.Jackson@citrix.com>,
"Volodymyr_Babchuk@epam.com" <Volodymyr_Babchuk@epam.com>
Subject: Re: [Xen-devel] [PATCH V3 3/8] xen/common: Introduce _xrealloc function
Date: Wed, 21 Aug 2019 20:04:08 +0300 [thread overview]
Message-ID: <0759e91a-a695-565f-de70-7701fb562e3e@gmail.com> (raw)
In-Reply-To: <51167370fc2d4853bd0d34df1b4dfb24@AMSPEX02CL03.citrite.net>
On 21.08.19 18:47, Paul Durrant wrote:
Hi
>>
>> You should also check whether the new requested alignment is compatible with the existing block
>> alignment
>>
>>
>> I am wondering:
>>
>> In case when we use only type-safe construction for the basic allocation
>> (xmalloc) and type-safe construction for the re-allocation
>> (xrealloc_flex_struct) over the same pointer of the correct type, will
>> we get a possible alignment incompatibility?
> You shouldn't but you're trusting that no-one will want to call the function directly with a higher alignment.
Yes, it is best to be on the safe side.
>
>>
>> This is how I see it:
>>
>> diff --git a/xen/common/xmalloc_tlsf.c b/xen/common/xmalloc_tlsf.c
>> index eecae2e..f90f453 100644
>> --- a/xen/common/xmalloc_tlsf.c
>> +++ b/xen/common/xmalloc_tlsf.c
>> @@ -616,8 +616,15 @@ void *_xrealloc(void *ptr, unsigned long size,
>> unsigned long align)
>> curr_size = PFN_ORDER(virt_to_page(ptr)) << PAGE_SHIFT;
>> else
>> {
>> - struct bhdr *b;
>> - b = (struct bhdr *)((char *)ptr - BHDR_OVERHEAD);
>> + struct bhdr *b = (struct bhdr *)((char *)ptr - BHDR_OVERHEAD);
>> +
>> + if ( b->size & FREE_BLOCK )
>> + {
>> + p = (char *)ptr - (b->size & ~FREE_BLOCK);
>> + b = (struct bhdr *)((char *)p - BHDR_OVERHEAD);
>> + ASSERT(!(b->size & FREE_BLOCK));
>> + }
>> +
>> curr_size = b->size & BLOCK_SIZE_MASK;
> Yes, that looks ok for getting the size right...
>
>> }
>>
>> @@ -630,8 +637,8 @@ void *_xrealloc(void *ptr, unsigned long size,
>> unsigned long align)
>> tmp_size = ( tmp_size < MIN_BLOCK_SIZE ) ? MIN_BLOCK_SIZE :
>> ROUNDUP_SIZE(tmp_size);
>>
>> - if ( tmp_size <= curr_size ) /* fits in current block */
>> - return ptr;
>> + if ( tmp_size <= curr_size && ((unsigned long)ptr & (align - 1)) == 0 )
>> + return ptr; /* fits in current block */
> ...and that should deal with the alignment too (although you may want to mention the alignment part in the comment too)
>
>> p = _xmalloc(size, align);
>> if ( p )
>>
>> (END)
>>
>>
>> Did I get your point correct?
>>
> Yes, with those changes I think it will look ok.
Thank you.
--
Regards,
Oleksandr Tyshchenko
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel
next prev parent reply other threads:[~2019-08-21 17:04 UTC|newest]
Thread overview: 41+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-08-20 18:09 [Xen-devel] [PATCH V3 0/8] iommu/arm: Add Renesas IPMMU-VMSA support + Linux's iommu_fwspec Oleksandr Tyshchenko
2019-08-20 18:09 ` [Xen-devel] [PATCH V3 1/8] iommu/arm: Add iommu_helpers.c file to keep common for IOMMUs stuff Oleksandr Tyshchenko
2019-09-09 11:45 ` Julien Grall
2019-09-09 14:12 ` Oleksandr
2019-08-20 18:09 ` [Xen-devel] [PATCH V3 2/8] iommu/arm: Add ability to handle deferred probing request Oleksandr Tyshchenko
2019-09-09 12:24 ` Julien Grall
2019-09-09 14:19 ` Oleksandr
2019-08-20 18:09 ` [Xen-devel] [PATCH V3 3/8] xen/common: Introduce _xrealloc function Oleksandr Tyshchenko
2019-08-21 8:09 ` Paul Durrant
2019-08-21 14:36 ` Oleksandr
2019-08-21 15:47 ` Paul Durrant
2019-08-21 17:04 ` Oleksandr [this message]
2019-08-20 18:09 ` [Xen-devel] [PATCH V3 4/8] xen/common: Introduce xrealloc_flex_struct() helper macros Oleksandr Tyshchenko
2019-08-27 13:28 ` Jan Beulich
2019-08-28 18:23 ` Oleksandr
2019-08-29 7:21 ` Jan Beulich
2019-08-29 19:04 ` Oleksandr
2019-08-20 18:09 ` [Xen-devel] [PATCH V3 5/8] iommu/arm: Add lightweight iommu_fwspec support Oleksandr Tyshchenko
2019-09-09 14:36 ` Julien Grall
2019-09-09 14:41 ` Oleksandr
2019-08-20 18:09 ` [Xen-devel] [PATCH V3 6/8] iommu: Add of_xlate callback Oleksandr Tyshchenko
2019-08-27 13:30 ` Jan Beulich
2019-08-27 14:59 ` Oleksandr
2019-08-27 15:11 ` Jan Beulich
2019-09-09 12:37 ` Julien Grall
2019-09-09 14:28 ` Oleksandr
2019-08-20 18:09 ` [Xen-devel] [PATCH V3 7/8] iommu/arm: Introduce iommu_add_dt_device API Oleksandr Tyshchenko
2019-09-09 15:04 ` Julien Grall
2019-09-09 15:48 ` Oleksandr
2019-09-10 13:34 ` Oleksandr
2019-09-10 14:30 ` Julien Grall
2019-08-20 18:09 ` [Xen-devel] [PATCH V3 8/8] iommu/arm: Add Renesas IPMMU-VMSA support Oleksandr Tyshchenko
2019-08-29 8:37 ` Yoshihiro Shimoda
2019-08-29 10:56 ` Oleksandr
2019-09-02 7:04 ` Yoshihiro Shimoda
2019-09-09 14:33 ` Oleksandr
2019-08-29 11:19 ` Oleksandr
2019-09-09 21:24 ` Julien Grall
2019-09-10 11:04 ` Oleksandr
2019-09-10 14:31 ` Julien Grall
2019-09-11 15:29 ` 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=0759e91a-a695-565f-de70-7701fb562e3e@gmail.com \
--to=olekstysh@gmail.com \
--cc=Andrew.Cooper3@citrix.com \
--cc=George.Dunlap@citrix.com \
--cc=Ian.Jackson@citrix.com \
--cc=Paul.Durrant@citrix.com \
--cc=Volodymyr_Babchuk@epam.com \
--cc=jbeulich@suse.com \
--cc=julien.grall@arm.com \
--cc=konrad.wilk@oracle.com \
--cc=oleksandr_tyshchenko@epam.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).