Skip to contentSkip to conversation

exec: fix address_space_get_iotlb_entry page mask

PATCH Superseded Peter Xu 2 participants 2 messages May 29, 2017

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Peter Xu

author
#0 lore raw

PATCH 1/1 exec: fix address_space_get_iotlb_entry page mask

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()")
---
 exec.c | 20 +++++++++-----------
 1 file changed, 9 insertions(+), 11 deletions(-)
exec.c +9 -11
index ff16f04..7026c21 100644
@@ -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,
Signature · 1 line
2.7.4
#1 lore raw
This series seems to have some coding style problems. See output below for more information:

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: [email protected]

=== 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/[email protected] -> patchew/[email protected]
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 [email protected]