From: Thomas Huth <thuth@redhat.com>
To: Cornelia Huck <cohuck@redhat.com>, David Hildenbrand <david@redhat.com>
Cc: qemu-devel@nongnu.org,
Christian Borntraeger <borntraeger@de.ibm.com>,
Alexander Graf <agraf@suse.de>,
Richard Henderson <richard.henderson@linaro.org>,
qemu-s390x@nongnu.org
Subject: Re: [Qemu-devel] [PATCH RFC 2/3] s390x/tcg: low-address protection support
Date: Thu, 12 Oct 2017 10:41:33 +0200 [thread overview]
Message-ID: <469b7729-0e9a-1c20-6a68-b3b8e55bafb4@redhat.com> (raw)
In-Reply-To: <20170929132717.23ecf350.cohuck@redhat.com>
On 29.09.2017 13:27, Cornelia Huck wrote:
> On Thu, 28 Sep 2017 15:08:11 +0200
> David Hildenbrand <david@redhat.com> wrote:
>
>> On 28.09.2017 06:50, Thomas Huth wrote:
>>> On 27.09.2017 19:00, David Hildenbrand wrote:
>>>> This is a neat way to implement low address protection, whereby
>>>> only the first 512 bytes of the first two pages (each 4096 bytes) of
>>>> every address space are protected.
>>>>
>>>> Store a tec of 0 for the access exception, this is what is defined by
>>>> Enhanced Suppression on Protection in case of a low address protection
>>>> (Bit 61 set to 0, rest undefined).
>>>>
>>>> We have to make sure to to pass the access address, not the masked page
>>>> address into mmu_translate*().
>>>>
>>>> Drop the check from testblock. So we can properly test this via
>>>> kvm-unit-tests.
>>>>
>>>> This will check every access going through one of the MMUs.
>>>>
>>>> Signed-off-by: David Hildenbrand <david@redhat.com>
>>>> ---
>>>> target/s390x/excp_helper.c | 3 +-
>>>> target/s390x/mem_helper.c | 8 ----
>>>> target/s390x/mmu_helper.c | 96 +++++++++++++++++++++++++++++-----------------
>>>> 3 files changed, 62 insertions(+), 45 deletions(-)
>>> [...]
>>>> diff --git a/target/s390x/mmu_helper.c b/target/s390x/mmu_helper.c
>>>> index 9daa0fd8e2..44a15449d2 100644
>>>> --- a/target/s390x/mmu_helper.c
>>>> +++ b/target/s390x/mmu_helper.c
>>>> @@ -106,6 +106,37 @@ static void trigger_page_fault(CPUS390XState *env, target_ulong vaddr,
>>>> trigger_access_exception(env, type, ilen, tec);
>>>> }
>>>>
>>>> +/* check whether the address would be proteted by Low-Address Protection */
>>>> +static bool is_low_address(uint64_t addr)
>>>> +{
>>>> + return addr < 512 || (addr >= 4096 && addr < 4607);
>>>> +}
>>>
>>> I like the check from the kernel sources better:
>>>
>>> static inline int is_low_address(unsigned long ga)
>>> {
>>> /* Check for address ranges 0..511 and 4096..4607 */
>>> return (ga & ~0x11fful) == 0;
>>> }
>>>
>>> ... that might result in slightly faster code (depending on the
>>> compiler, of course).
>>
>> I think that lim (readability) -> 0. Without that comment you're at
>> first sight really clueless what this is about.
>>
>> My check exactly corresponds to the wording in the PoP (and smart
>> compilers should be able to optimize).
>>
>> But I don't have a strong opinion on this micro optimization.
>
> FWIW, I'd be happy with both, but has anyone actually looked at the
> generated code?
This is what I get for David's original code:
80000510: c4 18 00 00 0d a4 lgrl %r1,80002058 <x1>
80000516: a7 29 01 ff lghi %r2,511
8000051a: ec 12 00 4f c0 65 clgrjnh %r1,%r2,800005b8 <main+0xd8>
80000520: a7 1b f0 00 aghi %r1,-4096
80000524: c2 1e 00 00 01 fe clgfi %r1,510
8000052a: a7 18 00 00 lhi %r1,0
8000052e: b9 99 00 11 slbr %r1,%r1
80000532: 13 11 lcr %r1,%r1
80000534: c4 1f 00 00 0d 96 strl %r1,80002060 <b1>
And this is the optimized kernel version:
8000054a: c4 18 00 00 0d 7f lgrl %r1,80002048 <x2>
80000550: a5 17 ee 00 nill %r1,60928
80000554: b9 00 00 11 lpgr %r1,%r1
80000558: a7 1b ff ff aghi %r1,-1
8000055c: eb 11 00 3f 00 0c srlg %r1,%r1,63
80000562: c4 1f 00 00 0d 77 strl %r1,80002050 <b2>
So that's indeed a little bit better :-)
(I was using GCC 4.8.5 from RHEL7, with -O2)
By the way, I think there's a bug in David's code: It should either be
"addr <= 4607" or "addr < 4608" instead of "addr < 4607".
With that bug fixed, David's version get's optimized even more:
80000510: c4 18 00 00 0d a4 lgrl %r1,80002058 <x1>
80000516: a5 17 ef ff nill %r1,61439
8000051a: c2 1e 00 00 01 ff clgfi %r1,511
80000520: a7 18 00 00 lhi %r1,0
80000524: b9 99 00 11 slbr %r1,%r1
80000528: 13 11 lcr %r1,%r1
8000052a: c4 1f 00 00 0d 9b strl %r1,80002060 <b1>
... so the difference is really very minimal in that case --> We could
really use the more readable version, I think.
Thomas
next prev parent reply other threads:[~2017-10-12 8:41 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-09-27 17:00 [Qemu-devel] [PATCH RFC 0/3] s390x/tcg: LAP support using immediate TLB invalidation David Hildenbrand
2017-09-27 17:00 ` [Qemu-devel] [PATCH RFC 1/3] accel/tcg: allow to invalidate a write TLB entry immediately David Hildenbrand
2017-09-27 17:48 ` Richard Henderson
2017-09-27 18:50 ` David Hildenbrand
2017-10-16 7:24 ` David Hildenbrand
2017-10-16 18:06 ` Richard Henderson
2017-09-27 17:00 ` [Qemu-devel] [PATCH RFC 2/3] s390x/tcg: low-address protection support David Hildenbrand
2017-09-27 17:51 ` Richard Henderson
2017-09-28 4:50 ` Thomas Huth
2017-09-28 13:08 ` David Hildenbrand
2017-09-29 11:27 ` Cornelia Huck
2017-10-12 8:41 ` Thomas Huth [this message]
2017-10-16 7:20 ` David Hildenbrand
2017-09-27 17:00 ` [Qemu-devel] [PATCH RFC 3/3] s390x/tcg: make STFL store into the lowcore David Hildenbrand
2017-09-27 17:52 ` Richard Henderson
2017-09-27 18:46 ` David Hildenbrand
2017-09-28 4:23 ` Thomas Huth
2017-09-29 12:43 ` Cornelia Huck
2017-09-29 11:49 ` [Qemu-devel] [PATCH RFC 0/3] s390x/tcg: LAP support using immediate TLB invalidation Cornelia Huck
2017-09-29 12:09 ` David Hildenbrand
2017-09-29 12:13 ` Cornelia Huck
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=469b7729-0e9a-1c20-6a68-b3b8e55bafb4@redhat.com \
--to=thuth@redhat.com \
--cc=agraf@suse.de \
--cc=borntraeger@de.ibm.com \
--cc=cohuck@redhat.com \
--cc=david@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=qemu-s390x@nongnu.org \
--cc=richard.henderson@linaro.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).