diff mbox

exec: fix address_space_get_iotlb_entry page mask

Message ID 1496029936-6381-1-git-send-email-peterx@redhat.com
State New
Headers show

Commit Message

Peter Xu May 29, 2017, 3:52 a.m. UTC
The IOTLB that it returned didn't guarantee that page_mask is indeed a
so-called page mask. That won't affect current usage since now only
vhost is using it (vhost API allows arbitary IOTLB range). However we
have IOTLB scemantic and we should best follow it. This patch fixes this
issue to make sure the page_mask is always a valid page mask.

Fixes: a764040 ("exec: abstract address_space_do_translate()")
Signed-off-by: Peter Xu <peterx@redhat.com>
---
 exec.c | 20 +++++++++-----------
 1 file changed, 9 insertions(+), 11 deletions(-)

Comments

no-reply@patchew.org May 29, 2017, 3:56 a.m. UTC | #1
Hi,

This series seems to have some coding style problems. See output below for
more information:

Type: series
Subject: [Qemu-devel] [PATCH] exec: fix address_space_get_iotlb_entry page mask
Message-id: 1496029936-6381-1-git-send-email-peterx@redhat.com

=== TEST SCRIPT BEGIN ===
#!/bin/bash

BASE=base
n=1
total=$(git log --oneline $BASE.. | wc -l)
failed=0

git config --local diff.renamelimit 0
git config --local diff.renames True

commits="$(git log --format=%H --reverse $BASE..)"
for c in $commits; do
    echo "Checking PATCH $n/$total: $(git log -n 1 --format=%s $c)..."
    if ! git show $c --format=email | ./scripts/checkpatch.pl --mailback -; then
        failed=1
        echo
    fi
    n=$((n+1))
done

exit $failed
=== TEST SCRIPT END ===

Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384
From https://github.com/patchew-project/qemu
 * [new tag]         patchew/1496029936-6381-1-git-send-email-peterx@redhat.com -> patchew/1496029936-6381-1-git-send-email-peterx@redhat.com
Switched to a new branch 'test'
8778a42 exec: fix address_space_get_iotlb_entry page mask

=== OUTPUT BEGIN ===
Checking PATCH 1/1: exec: fix address_space_get_iotlb_entry page mask...
ERROR: spaces required around that '-' (ctx:VxV)
#24: FILE: exec.c:522:
+    if (plen == (hwaddr)-1) {
                         ^

total: 1 errors, 0 warnings, 32 lines checked

Your patch has style problems, please review.  If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.

=== OUTPUT END ===

Test command exited with code: 1


---
Email generated automatically by Patchew [http://patchew.org/].
Please send your feedback to patchew-devel@freelists.org
diff mbox

Patch

diff --git a/exec.c b/exec.c
index ff16f04..7026c21 100644
--- a/exec.c
+++ b/exec.c
@@ -519,6 +519,15 @@  IOMMUTLBEntry address_space_get_iotlb_entry(AddressSpace *as, hwaddr addr,
     section = address_space_do_translate(as, addr, &xlat, &plen,
                                          is_write, false);
 
+    if (plen == (hwaddr)-1) {
+        /* If not specified during translation, use default mask */
+        plen = TARGET_PAGE_MASK;
+    } else {
+        /* Make it a valid page mask */
+        assert(plen);
+        plen = (1ULL << (63 - clz64(plen))) - 1;
+    }
+
     /* Illegal translation */
     if (section.mr == &io_mem_unassigned) {
         goto iotlb_fail;
@@ -528,17 +537,6 @@  IOMMUTLBEntry address_space_get_iotlb_entry(AddressSpace *as, hwaddr addr,
     xlat += section.offset_within_address_space -
         section.offset_within_region;
 
-    if (plen == (hwaddr)-1) {
-        /*
-         * We use default page size here. Logically it only happens
-         * for identity mappings.
-         */
-        plen = TARGET_PAGE_SIZE;
-    }
-
-    /* Convert to address mask */
-    plen -= 1;
-
     return (IOMMUTLBEntry) {
         .target_as = section.address_space,
         .iova = addr & ~plen,