From: Paolo Bonzini <pbonzini@redhat.com>
To: Andrew Jeffery <andrew@aj.id.au>, qemu-devel@nongnu.org
Cc: qemu-arm@nongnu.org, joel@jms.id.au, clg@kaod.org, f4bug@amsat.org
Subject: Re: [Qemu-devel] [RFC PATCH 1/1] memory: Support unaligned accesses on aligned-only models
Date: Thu, 13 Jul 2017 14:05:33 +0200 [thread overview]
Message-ID: <cd1aba90-176f-9ec6-3e2b-d1135156a96d@redhat.com> (raw)
In-Reply-To: <20170630030058.28943-1-andrew@aj.id.au>
On 30/06/2017 05:00, Andrew Jeffery wrote:
> This RFC patch stems from a discussion on a patch for an ADC model[1] where it
> was pointed out that I should be able to use the .impl member of
> MemoryRegionOps to constrain how my read() and write() callbacks where invoked.
>
> I tried Phil's suggested approach and found I got reads of size 4, but with an
> address that was not 4-byte aligned.
>
> Looking at the source for access_with_adjusted_size() lead to the comment
>
> /* FIXME: support unaligned access? */
>
> which at least suggests that the implementation isn't complete.
>
> So, this patch is a quick and incomplete attempt at resolving the issue to see
> whether I'm on the right track or way off in the weeds.
>
> I've lightly tested it with the ADC model mentioned above, and it appears to do
> the right thing (I changed the values generated by the ADC to distinguish
> between the lower and upper 16 bits).
I think the idea is okay.
> + access_addr[0] = align_down(addr, access_size);
> + access_addr[1] = align_up(addr + size, access_size);
> +
> + for (cur = access_addr[0]; cur < access_addr[1]; cur += access_size) {
> + uint64_t mask_bounds[2];
> + mask_bounds[0] = MAX(addr, cur) - cur;
> + mask_bounds[1] =
> + MIN(addr + size, align_up(cur + 1, access_size)) - cur;
> +
> + access_mask = (-1ULL << mask_bounds[0] * 8) &
> + (-1ULL >> (64 - mask_bounds[1] * 8));
Please use MAKE_64BIT_MASK.
> + r |= access(mr, cur, &access_value, access_size,
> + (MAX(addr, cur) - addr), access_mask, attrs);
> +
> + /* XXX: Can't do this hack for writes */
> + access_value >>= mask_bounds[0] * 8;
> + }
Can you subtract access_addr[0] from mask_bounds[0] and mask_bounds[1]
(instead of cur) to remove the need for this right shift?
Thanks,
Paolo
next prev parent reply other threads:[~2017-07-13 12:05 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-06-30 3:00 [Qemu-devel] [RFC PATCH 1/1] memory: Support unaligned accesses on aligned-only models Andrew Jeffery
2017-07-13 12:05 ` Paolo Bonzini [this message]
2017-07-14 6:20 ` Andrew Jeffery
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=cd1aba90-176f-9ec6-3e2b-d1135156a96d@redhat.com \
--to=pbonzini@redhat.com \
--cc=andrew@aj.id.au \
--cc=clg@kaod.org \
--cc=f4bug@amsat.org \
--cc=joel@jms.id.au \
--cc=qemu-arm@nongnu.org \
--cc=qemu-devel@nongnu.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).