From: Pranith Kumar <bobby.prani@gmail.com>
To: Eric Blake <eblake@redhat.com>
Cc: "Emilio G. Cota" <cota@braap.org>,
Paolo Bonzini <pbonzini@redhat.com>,
Richard Henderson <rth@twiddle.net>,
"open list:Overall" <qemu-devel@nongnu.org>,
Peter Crosthwaite <crosthwaite.peter@gmail.com>
Subject: Re: [Qemu-devel] [PATCH 2/2] translate-all: Use proper type
Date: Tue, 18 Oct 2016 15:14:42 -0400 [thread overview]
Message-ID: <87twc9cvvh.fsf@gmail.com> (raw)
In-Reply-To: <a49a5a08-40b4-7e35-20d6-7f17586ccafa@redhat.com>
Eric Blake writes:
> On 10/18/2016 01:34 PM, Emilio G. Cota wrote:
>> +++ b/translate-all.c
>> @@ -405,23 +405,23 @@ static void page_init(void)
>> static PageDesc *page_find_alloc(tb_page_addr_t index, int alloc)
>> {
>> PageDesc *pd;
>> void **lp;
>> int i;
>>
>> /* Level 1. Always allocated. */
>> lp = l1_map + ((index >> V_L1_SHIFT) & (V_L1_SIZE - 1));
>>
>> /* Level 2..N-1. */
>> for (i = V_L1_SHIFT / V_L2_BITS - 1; i > 0; i--) {
>> - void **p = atomic_rcu_read(lp);
>> + void *p = atomic_rcu_read(lp);
>>
>> if (p == NULL) {
>> if (!alloc) {
>> return NULL;
>> }
>> p = g_new0(void *, V_L2_SIZE);
>> atomic_rcu_set(lp, p);
>> }
>>
>> lp = p + ((index >> (i * V_L2_BITS)) & (V_L2_SIZE - 1));
>
> Pointer addition of 'void *' plus an offset is undefined (gcc, and
> presumably clang, have an extension that treats it the same as computing
> an offset to a 'char *'; but some compilers choke); this is because
> sizeof(void) is unknown, so you don't know what stride to make for each
> offset. Or put another way, 'p + offset' is the same as
> '&((*p)[offset])', but (*p)[offset] is ill-defined when p is the opaque
> type void.
>
> Pointer addition of 'void **' plus an offset is well-defined, because
> sizeof(void*) is well-defined and therefore the stride (4 or 8) makes
> sense. Or in array notation, computing '&((*p)[offset]) means we are
> skipping to the offset array entry where p is the start of the array of
> void* pointers.
>
Indeed. I missed that crucial detail. I would prefer explicitly casting to
'void **' for p, since that is not the type of what is being returned by
atomic_rcu_read().
The joys of void pointer arithmetic, TIL.
--
Pranith
next prev parent reply other threads:[~2016-10-18 19:14 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-10-18 14:56 [Qemu-devel] [PATCH 1/2] docs/rcu: Distinguish rcu_dereference and atomic_rcu_read Pranith Kumar
2016-10-18 14:56 ` [Qemu-devel] [PATCH 2/2] translate-all: Use proper type Pranith Kumar
2016-10-18 18:34 ` Emilio G. Cota
2016-10-18 18:43 ` Eric Blake
2016-10-18 19:14 ` Pranith Kumar [this message]
2016-10-18 21:55 ` Paolo Bonzini
2016-10-18 21:50 ` [Qemu-devel] [PATCH 1/2] docs/rcu: Distinguish rcu_dereference and atomic_rcu_read Paolo Bonzini
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=87twc9cvvh.fsf@gmail.com \
--to=bobby.prani@gmail.com \
--cc=cota@braap.org \
--cc=crosthwaite.peter@gmail.com \
--cc=eblake@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=rth@twiddle.net \
/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).