Skip to contentSkip to conversation

let set_phys_to_machine return the old entry

PATCH In review Stefan Berger 2 participants 3 messages Apr 20, 2006 – Apr 21, 2006

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 let set_phys_to_machine return the old entry

The attached patch makes set_phys_to_machine(pfn,mfn) return the old entry in the array, such that the old entry can be restored again using the same call. If the feature XENFEAT_auto_translate_physmap is not enabled, then these two calls will end up in no-op relative to changes to the phys_to_machine_mapping array.

There's currently only one occurrence where remembering the entry from the array is necessary and this is in the vTPM backend driver.

This patch builds on top of the previously posted TPM backend patch.

xen-unstable.hg/linux-2.6-xen-sparse/drivers/xen/tpmback/tpmback.c +1 -2
Index: xen/xen-unstable.hg/linux-2.6-xen-sparse/drivers/xen/tpmback/tpmback.c
===================================================================
@@ -297,9 +297,8 @@ int _packet_write(struct packet *pak,
 
 		pfn = __pa(MMAP_VADDR(tpmif, i)) >> PAGE_SHIFT;
 		mfn = FOREIGN_FRAME(map_op.dev_bus_addr >> PAGE_SHIFT);
-		mfn_orig = phys_to_machine_mapping[pfn];
 
-		set_phys_to_machine(pfn, mfn);
+		mfn_orig = set_phys_to_machine(pfn, mfn);
 
 		tocopy = MIN(size - offset, PAGE_SIZE);
 
xen-unstable.hg/linux-2.6-xen-sparse/include/asm-i386/mach-xen/asm/page.h +6 -2
Index: xen/xen-unstable.hg/linux-2.6-xen-sparse/include/asm-i386/mach-xen/asm/page.h
===================================================================
@@ -137,13 +137,17 @@ static inline unsigned long mfn_to_local
 	return pfn;
 }
 
-static inline void set_phys_to_machine(unsigned long pfn, unsigned long mfn)
+static inline
+unsigned long set_phys_to_machine(unsigned long pfn, unsigned long mfn)
 {
+	unsigned long mfn_orig;
 	if (xen_feature(XENFEAT_auto_translated_physmap)) {
 		BUG_ON(pfn != mfn && mfn != INVALID_P2M_ENTRY);
-		return;
+		return phys_to_machine_mapping[pfn];
 	}
+	mfn_orig = phys_to_machine_mapping[pfn];
 	phys_to_machine_mapping[pfn] = mfn;
+	return mfn_orig;
 }
 
 /* Definitions for machine and pseudophysical addresses. */

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

#1 lore raw
Quoted 10 lines · Stefan Berger

The attached patch makes set_phys_to_machine(pfn,mfn) return the old entry in the array, such that the old entry can be restored again using the same call. If the feature XENFEAT_auto_translate_physmap is not enabled, then these two calls will end up in no-op relative to changes to the phys_to_machine_mapping array.

There's currently only one occurrence where remembering the entry from the array is necessary and this is in the vTPM backend driver.

This patch builds on top of the previously posted TPM backend patch.

Why do you need to mess with the phys_to_machine table at all? You install the mapping only for a very short time, to do a memcpy or copy_from_user: neither of which will use that p2m entry. Even if you really do want to set the p2m entry properly you know that its old value must be INVALID_P2M_ENTRY because you obtained that kernel virtual address via balloon_alloc_empty_page_range().

You should probably just delete the p2m code from that copy routine.

-- Keir

#2 lore raw

[email protected] wrote on 04/20/2006 03:08:08 PM:

Quoted 5 lines · Stefan Berger
Quoted 3 lines

The attached patch makes set_phys_to_machine(pfn,mfn) return the old entry in the array, such that the old entry can be restored again

using

Quoted 9 lines
Quoted 8 lines

the same call. If the feature XENFEAT_auto_translate_physmap is not enabled, then these two calls will end up in no-op relative to changes to the phys_to_machine_mapping array.

There's currently only one occurrence where remembering the entry from the array is necessary and this is in the vTPM backend driver.

This patch builds on top of the previously posted TPM backend patch.

Quoted 8 lines

Why do you need to mess with the phys_to_machine table at all? You install the mapping only for a very short time, to do a memcpy or
copy_from_user: neither of which will use that p2m entry. Even if you really do want to set the p2m entry properly you know that its old value must be INVALID_P2M_ENTRY because you obtained that kernel virtual address via balloon_alloc_empty_page_range().

You should probably just delete the p2m code from that copy routine.

Going to do that and will repost.

Stefan

Quoted 8 lines

-- Keir

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel