[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] x86/p2m-pt: fix p2m_flags_to_access()

  • To: "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Jan Beulich <jbeulich@xxxxxxxx>
  • Date: Thu, 2 Sep 2021 09:01:41 +0200
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=suse.com; dmarc=pass action=none header.from=suse.com; dkim=pass header.d=suse.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=27WMxhXQJYDK8zBJxq3wqZWYbPIQe9ZgUpLtLbNSdZo=; b=k+vYz7XkeCgxv0UA8VqD72xKzK2oYkw5izLtTAyYeAuEf4SMSrSOfTL0ZngxdzFOtnw6Ftbi6n8K8i/20YgUJqqBWmhGRSE837k+MMvrZc1P32elvt67ptuyaOoUyYhCAVsv2o7eaq8BGJudYL6BkIEXOUdq0JGi/jyyE4GQ01iSr9qyJyLyj1oFVjl1F+Ah8+hmYYVZ4mFTmdcBqyocW7+jaOXnQSSdQIqxz/V7PcbweZf78dSp9yApQxwBC7TwvOiB4z8/cTATGZHeU8dasTRmS259JsMZ5pmFWL89RFs8BhwKVMZBZYPrvv01SlcRaT0+qFjXvcP4pmTeRcSzoA==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=nHEnISrcHdZrmeEhjciMwCW7JIRW3f0n2KvAxSRbtZII+QfpNvzbT/1mnXRYPve6+raQpdkpr5DsdYF79HjCGSs5U0d9Y8/gcSBquK8t+m5VJEy26R3Aoguh1M+zF8rP+CmQQXWev6sv2CH02F+YsXc7Y7Z5KTxgt8EzGJm3wdp5Qaz5KcPbwfnXu7VuaBfzf1onlo3A20NuhzJEusn/H1nVz87uksPG9YD4oefzeP2MMAp7vb0YJFLk+KIfENJNdbTgijsDYN/FVBh6/cC5LYRQHGOSXYDilO8Y1dNFKipObTrFYvvqarIUGWrvqAf9Z5TvpScN/RxxFQhO1oE6PA==
  • Authentication-results: citrix.com; dkim=none (message not signed) header.d=none;citrix.com; dmarc=none action=none header.from=suse.com;
  • Cc: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Wei Liu <wl@xxxxxxx>, Roger Pau Monné <roger.pau@xxxxxxxxxx>, George Dunlap <george.dunlap@xxxxxxxxxx>
  • Delivery-date: Thu, 02 Sep 2021 07:01:56 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

The initial if() was inverted, invalidating all output from this
function. Which in turn means the mirroring of P2M mappings into the
IOMMU didn't always work as intended: Mappings may have got updated when
there was no need to. There would not have been too few (un)mappings;
what saves us is that alongside the flags comparison MFNs also get
compared, with non-present entries always having an MFN of 0 or
INVALID_MFN while present entries always have MFNs different from these
two (0 in the table also meant to cover INVALID_MFN):

OLD                                     NEW
P W     access  MFN                     P W     access  MFN
0 0     r       0                       0 0     n       0
0 1     rw      0                       0 1     n       0
1 0     n       non-0                   1 0     r       non-0
1 1     n       non-0                   1 1     rw      non-0

present <-> non-present transitions are fine because the MFNs differ.
present -> present transitions as well as non-present -> non-present
ones are potentially causing too many map/unmap operations, but never
too few, because in that case old (bogus) and new access differ.

Fixes: d1bb6c97c31e ("IOMMU: also pass p2m_access_t to p2m_get_iommu_flags())
Signed-off-by: Jan Beulich <jbeulich@xxxxxxxx>

--- a/xen/arch/x86/mm/p2m-pt.c
+++ b/xen/arch/x86/mm/p2m-pt.c
@@ -548,7 +548,7 @@ int p2m_pt_handle_deferred_changes(uint6
 /* Reconstruct a fake p2m_access_t from stored PTE flags. */
 static p2m_access_t p2m_flags_to_access(unsigned int flags)
-    if ( flags & _PAGE_PRESENT )
+    if ( !(flags & _PAGE_PRESENT) )
         return p2m_access_n;
     /* No need to look at _PAGE_NX for now. */



Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.