Skip to contentSkip to conversation

pseries/drmem: update LMBs after LPM

PATCH Superseded Laurent Dufour 2 participants 3 messages May 4, 2021 – May 5, 2021 PowerPC

v4 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

PATCH v4 1/1 pseries/drmem: update LMBs after LPM

After a LPM, the device tree node ibm,dynamic-reconfiguration-memory may be updated by the hypervisor in the case the NUMA topology of the LPAR's memory is updated.

This is caught by the kernel, but the memory's node is updated because there is no way to move a memory block between nodes.

If later a memory block is added or removed, drmem_update_dt() is called and it is overwriting the DT node to match the added or removed LMB. But the LMB's associativity node has not been updated after the DT node update and thus the node is overwritten by the Linux's topology instead of the hypervisor one.

Introduce a hook called when the ibm,dynamic-reconfiguration-memory node is updated to force an update of the LMB's associativity. However, ignore the call to that hook when the update has been triggered by drmem_update_dt(). Because, in that case, the LMB tree has been used to set the DT property and thus it doesn't need to be updated back. Since drmem_update_dt() is called under the protection of the device_hotplug_lock and the hook is called in the same context, use a simple boolean variable to detect that call.

Cc Aneesh Kumar K.V <[email protected]>
Cc Tyrel Datwyler <[email protected]>

---

V4:
- Prevent the LMB to be updated back in the case the request came from the LMB tree's update.
V3:
- Check rd->dn->name instead of rd->dn->full_name
V2:
- Take Tyrel's idea to rely on OF_RECONFIG_UPDATE_PROPERTY instead of introducing a new hook mechanism.

---
 arch/powerpc/include/asm/drmem.h              |  1 +
 arch/powerpc/mm/drmem.c                       | 46 +++++++++++++++++++
 .../platforms/pseries/hotplug-memory.c        |  4 ++
 3 files changed, 51 insertions(+)
arch/powerpc/include/asm/drmem.h +1 -0
index bf2402fed3e0..4265d5e95c2c 100644
@@ -111,6 +111,7 @@ int drmem_update_dt(void);
 int __init
 walk_drmem_lmbs_early(unsigned long node, void *data,
 		      int (*func)(struct drmem_lmb *, const __be32 **, void *));
+void drmem_update_lmbs(struct property *prop);
 #endif
 
 static inline void invalidate_lmb_associativity_index(struct drmem_lmb *lmb)
arch/powerpc/mm/drmem.c +46 -0

70 lines not on this page · raw message

arch/powerpc/platforms/pseries/hotplug-memory.c +4 -0
index 8377f1f7c78e..672ffbee2e78 100644
@@ -949,6 +949,10 @@ static int pseries_memory_notifier(struct notifier_block *nb,
 	case OF_RECONFIG_DETACH_NODE:
 		err = pseries_remove_mem_node(rd->dn);
 		break;
+	case OF_RECONFIG_UPDATE_PROPERTY:
+		if (!strcmp(rd->dn->name,
+			    "ibm,dynamic-reconfiguration-memory"))
+			drmem_update_lmbs(rd->prop);
 	}
 	return notifier_from_errno(err);
 }
Signature · 1 line
2.31.1
#1 lore raw

Hi Laurent,

Bear with me while I work through the commit message:

Quoted 3 lines · Laurent Dufour

After a LPM, the device tree node ibm,dynamic-reconfiguration-memory may be updated by the hypervisor in the case the NUMA topology of the LPAR's memory is updated.

Yes, the RTAS functions ibm,update-nodes and ibm,update-properties, which the OS invokes after resuming, may bring in updated properties under the ibm,dynamic-reconfiguration-memory node, including the ibm,associativity-lookup-arrays property.

Quoted 1 line

This is caught by the kernel,

"Caught" makes me think this is an error condition, as in catching an exception. I guess "handled" better conveys your meaning?

Quoted 2 lines

but the memory's node is updated because there is no way to move a memory block between nodes.

"The memory's node" refers the ibm,dynamic-reconfiguration-memory DT node, yes? Or is it referring to Linux's NUMA nodes? ("move a memory block between nodes" in your statement here refers to Linux's NUMA nodes, that much is clear to me.)

I am failing to follow the cause->effect relationship stated. True, changing a block's node assignment while it's in use isn't safe. I don't see why that implies that "the memory's node is updated"? In fact this seems contradictory.

This statement makes more sense to me if I change it to "the memory's node is _not_ updated" -- is this what you intended?

Quoted 2 lines

If later a memory block is added or removed, drmem_update_dt() is called and it is overwriting the DT node to match the added or removed LMB.

I understand this, but I will expand on it.

dlpar_memory()
-> dlpar_memory_add_by_count()

    -> dlpar_add_lmb()
      -> update_lmb_associativity_index()
        ... lmb->aa_index = <value>

-> drmem_update_dt()

update_lmb_associativity_index() retrieves the firmware description of the new block, and sets the aa_index of the matching entry in the drmem_info array to the value matching the firmware description.

Then, drmem_update_dt() walks the drmem_info array and synthesizes a new /ibm,dynamic-reconfiguration-memory/ibm,dynamic-memory-v2 property based on the recently updated information in that array.

Quoted 3 lines

But the LMB's associativity node has not been updated after the DT node update and thus the node is overwritten by the Linux's topology instead of the hypervisor one.

So, an example of the problem is:

1. VM migrates. On resume, ibm,associativity-lookup-arrays is changed via ibm,update-properties. Entries in the drmem_info array remain unchanged, with aa_index values that correspond to the source system's ibm,associativity-lookup-arrays property, now inaccessible.

2. A memory block is added. We look up the new block's entry in the drmem_info array, and set the aa_index to the value matching the current ibm,associativity-lookup-arrays.

3. Then, the ibm,associativity-lookup-arrays property is completely regenerated from the drmem_info array, which reflects a mixture of information from the source and destination systems.

Do I understand correctly?

Quoted 8 lines

Introduce a hook called when the ibm,dynamic-reconfiguration-memory node is updated to force an update of the LMB's associativity. However, ignore the call to that hook when the update has been triggered by drmem_update_dt(). Because, in that case, the LMB tree has been used to set the DT property and thus it doesn't need to be updated back. Since drmem_update_dt() is called under the protection of the device_hotplug_lock and the hook is called in the same context, use a simple boolean variable to detect that call.

This strikes me as almost a revert of e978a3ccaa71 ("powerpc/pseries:
remove obsolete memory hotplug DT notifier code").

I'd rather avoid smuggling through global state information that ought to be passed in function parameters, if it should be passed around at all. Despite having (IMO) relatively simple responsibilities, this code is difficult to change and review; adding this property makes it worse. If the structure of the code is pushing us toward this kind of compromise, then the code probably needs more fundamental changes.

I'm probably forgetting something -- can anyone remind me why we need an array of these:

struct drmem_lmb {
	u64     base_addr;
	u32     drc_index;
	u32     aa_index;
	u32     flags;
};

which is just a less efficient representation of what's already in the device tree? If we got rid of it, would this problem disappear?

#2 lore raw

Le 05/05/2021 à 00:30, Nathan Lynch a écrit :

Quoted 1 line

Hi Laurent,

Hi Nathan,

Thanks for your review.

Quoted 12 lines

Bear with me while I work through the commit message:

Quoted 3 lines · Laurent Dufour

After a LPM, the device tree node ibm,dynamic-reconfiguration-memory may be updated by the hypervisor in the case the NUMA topology of the LPAR's memory is updated.

Yes, the RTAS functions ibm,update-nodes and ibm,update-properties, which the OS invokes after resuming, may bring in updated properties under the ibm,dynamic-reconfiguration-memory node, including the ibm,associativity-lookup-arrays property.

Quoted 4 lines
Quoted 1 line

This is caught by the kernel,

"Caught" makes me think this is an error condition, as in catching an exception. I guess "handled" better conveys your meaning?

ok

Quoted 9 lines
Quoted 3 lines

but the memory's node is updated because there is no way to move a memory block between nodes.

"The memory's node" refers the ibm,dynamic-reconfiguration-memory DT node, yes? Or is it referring to Linux's NUMA nodes? ("move a memory block between nodes" in your statement here refers to Linux's NUMA nodes, that much is clear to me.)

Quoted 7 lines

I am failing to follow the cause->effect relationship stated. True, changing a block's node assignment while it's in use isn't safe. I don't see why that implies that "the memory's node is updated"? In fact this seems contradictory.

This statement makes more sense to me if I change it to "the memory's node is _not_ updated" -- is this what you intended?

Correct, I dropped the 'not' word here ;)

Quoted 13 lines
Quoted 3 lines

If later a memory block is added or removed, drmem_update_dt() is called and it is overwriting the DT node to match the added or removed LMB.

I understand this, but I will expand on it.

dlpar_memory()
-> dlpar_memory_add_by_count()

     -> dlpar_add_lmb()
       -> update_lmb_associativity_index()
         ... lmb->aa_index = <value>

-> drmem_update_dt()

Quoted 7 lines

update_lmb_associativity_index() retrieves the firmware description of the new block, and sets the aa_index of the matching entry in the drmem_info array to the value matching the firmware description.

Then, drmem_update_dt() walks the drmem_info array and synthesizes a new /ibm,dynamic-reconfiguration-memory/ibm,dynamic-memory-v2 property based on the recently updated information in that array.

Yes

Quoted 16 lines
Quoted 4 lines

But the LMB's associativity node has not been updated after the DT node update and thus the node is overwritten by the Linux's topology instead of the hypervisor one.

So, an example of the problem is:

1. VM migrates. On resume, ibm,associativity-lookup-arrays is changed via ibm,update-properties. Entries in the drmem_info array remain unchanged, with aa_index values that correspond to the source system's ibm,associativity-lookup-arrays property, now inaccessible.

2. A memory block is added. We look up the new block's entry in the drmem_info array, and set the aa_index to the value matching the current ibm,associativity-lookup-arrays.

Quoted 5 lines

3. Then, the ibm,associativity-lookup-arrays property is completely regenerated from the drmem_info array, which reflects a mixture of information from the source and destination systems.

Do I understand correctly?

Yes

Quoted 11 lines
Quoted 10 lines

Introduce a hook called when the ibm,dynamic-reconfiguration-memory node is updated to force an update of the LMB's associativity. However, ignore the call to that hook when the update has been triggered by drmem_update_dt(). Because, in that case, the LMB tree has been used to set the DT property and thus it doesn't need to be updated back. Since drmem_update_dt() is called under the protection of the device_hotplug_lock and the hook is called in the same context, use a simple boolean variable to detect that call.

Quoted 2 lines

This strikes me as almost a revert of e978a3ccaa71 ("powerpc/pseries:
remove obsolete memory hotplug DT notifier code").

Not really identical to reverting e978a3ccaa71, here only the aa_index of the LMB is updated, everything else is kept in place. I don't try to apply the memory layout's changes, just updating the in use LMB's aa_index field.

The only matching point with the code reverted by the commit you mentioned would be the use of a global variable in_drmem_update instead of the previous rtas_hp_event to prevent the LMB tree to be updated again during memory hot plug event.

Quoted 17 lines

I'd rather avoid smuggling through global state information that ought to be passed in function parameters, if it should be passed around at all. Despite having (IMO) relatively simple responsibilities, this code is difficult to change and review; adding this property makes it worse. If the structure of the code is pushing us toward this kind of compromise, then the code probably needs more fundamental changes.

I'm probably forgetting something -- can anyone remind me why we need an array of these:

struct drmem_lmb {
	u64     base_addr;
	u32     drc_index;
	u32     aa_index;
	u32     flags;
};
Quoted 2 lines

which is just a less efficient representation of what's already in the device tree? If we got rid of it, would this problem disappear?

I don't think this is right for the moment, at first, we should robustify the DLPAR and LPM operations.