powerpc/pseries: read the lpar name from the firmware
PATCH v2 1/1 powerpc/pseries: read the lpar name from the firmware
The LPAR name may be changed after the LPAR has been started in the HMC. In that case lparstat command is not reporting the updated value because it reads it from the device tree which is read at boot time.
However this value could be read from RTAS.
Adding this value in the /proc/powerpc/lparcfg output allows to read the updated value.
---
v2:
address Nathan's comments.
change title to partition_name aligning with existing partition_id
--- arch/powerpc/platforms/pseries/lparcfg.c | 53 ++++++++++++++++++++++++ 1 file changed, 53 insertions(+)
arch/powerpc/platforms/pseries/lparcfg.c +53 -0
@@ -311,6 +311,58 @@ static void parse_mpp_x_data(struct seq_file *m)seq_printf (m,"coalesce_pool_spurr=%ld\n" , mpp_x_data.pool_spurr_cycles); } +/* +* PAPR defines no maximum for the LPAR name, and defines that the maximum +* length of the get-system-parameter's output buffer is 4000 plus 2 bytes for +* the length. Limit LPAR's name size to 1024 +*/ +#define SPLPAR_LPAR_NAME_MAXLEN 1026 +#define SPLPAR_LPAR_NAME_TOKEN 55 +static void parse_lpar_name (struct seq_file *m) +{ +int rc, len, token; +unsigned char *local_buffer; + + token =rtas_token ("ibm,get-system-parameter" ); +if (token ==RTAS_UNKNOWN_SERVICE ) +return ; + + local_buffer =kmalloc (SPLPAR_LPAR_NAME_MAXLEN ,GFP_KERNEL ); +if (!local_buffer) +return ; + +do { +spin_lock (&rtas_data_buf_lock); + +memset (rtas_data_buf,0 ,RTAS_DATA_BUF_SIZE ); + rc =rtas_call (token,3 ,1 ,NULL ,SPLPAR_LPAR_NAME_TOKEN , +__pa (rtas_data_buf),RTAS_DATA_BUF_SIZE ); +memcpy (local_buffer, rtas_data_buf,SPLPAR_LPAR_NAME_MAXLEN ); + +spin_unlock (&rtas_data_buf_lock); + }while (rtas_busy_delay (rc)); + +if (rc !=0 ) { +pr_err_once ( +"%s %s Error calling get-system-parameter (0x%x)\n" , + __FILE__, __func__, rc); + }else { + local_buffer[SPLPAR_LPAR_NAME_MAXLEN -1 ] ='\0' ; + len = local_buffer[0 ] *256 + local_buffer[1 ]; + +/* +* Forces an empty string in the weird case fw reports no data. +*/ +if (!len) + local_buffer[2 ] ='\0' ; + +seq_printf (m,"partition_name=%s\n" , local_buffer +2 ); + } + +kfree (local_buffer); +} + +#define SPLPAR_CHARACTERISTICS_TOKEN 20#define SPLPAR_MAXLENGTH 1026*(sizeof(char))
@@ -496,6 +548,7 @@ static int pseries_lparcfg_data(struct seq_file *m, void *v)if (firmware_has_feature (FW_FEATURE_SPLPAR )) {/* this call handles the ibm,get-system-parameter contents */ +parse_lpar_name (m);parse_system_parameter_string (m);parse_ppp_data (m);parse_mpp_data (m);
Signature · 1 line
2.34.1
Hi Laurent,
Just a few minor comments below ...
Quoted 24 lines · Laurent Dufour
The LPAR name may be changed after the LPAR has been started in the HMC. In that case lparstat command is not reporting the updated value because it reads it from the device tree which is read at boot time.
However this value could be read from RTAS.
Adding this value in the
/proc/powerpc/lparcfgoutput allows to read the updated value.Cc Nathan Lynch <[email protected]>Signed-off-by Laurent Dufour <[email protected]>---
v2:
address Nathan's comments.
change title topartition_namealigning with existingpartition_id--- arch/powerpc/platforms/pseries/lparcfg.c | 53 ++++++++++++++++++++++++ 1 file changed, 53 insertions(+)arch/powerpc/platforms/pseries/lparcfg.c +0
-0
arch/powerpc/platforms/pseries/lparcfg.c static void parse_mpp_x_data(struct seq_file *m) · line 319
Quoted 9 lines
arch/powerpc/platforms/pseries/lparcfg.c +6
-0@@ -311,6 +311,58 @@ static void parse_mpp_x_data(struct seq_file *m)seq_printf (m,"coalesce_pool_spurr=%ld\n" , mpp_x_data.pool_spurr_cycles); } +/* +* PAPR defines no maximum for the LPAR name, and defines that the maximum +* length of the get-system-parameter's output buffer is 4000 plus 2 bytes for +* the length. Limit LPAR's name size to 1024 +*/ +#define SPLPAR_LPAR_NAME_MAXLEN 1026
Why not just allocate the full 4000? That's not much memory in the scheme of things, and allocating less risks us needing to update this in future. I realise that's a ridiculously long LPAR name, but still.
arch/powerpc/platforms/pseries/lparcfg.c static void parse_mpp_x_data(struct seq_file *m) · line 320
Quoted 1 line
arch/powerpc/platforms/pseries/lparcfg.c +1
-0+#define SPLPAR_LPAR_NAME_TOKEN 55
Can you add a comment saying where that value is defined, PAPR?
arch/powerpc/platforms/pseries/lparcfg.c static void parse_mpp_x_data(struct seq_file *m) · line 321
Quoted 1 line
arch/powerpc/platforms/pseries/lparcfg.c +1
-0+static void parse_lpar_name (struct seq_file *m)
Nitpick, but we're not really parsing it, we're just reading it from firmware.
Quoted 9 lines
arch/powerpc/platforms/pseries/lparcfg.c +9
-0+{ +int rc, len, token; +unsigned char *local_buffer; + + token =rtas_token ("ibm,get-system-parameter" ); +if (token ==RTAS_UNKNOWN_SERVICE ) +return ; + + local_buffer =kmalloc (SPLPAR_LPAR_NAME_MAXLEN ,GFP_KERNEL );
arch/powerpc/platforms/pseries/lparcfg.c static void parse_mpp_x_data(struct seq_file *m) · line 340
Quoted 10 lines
arch/powerpc/platforms/pseries/lparcfg.c +10
-0+if (!local_buffer) +return ; + + do { + spin_lock(&rtas_data_buf_lock); + + memset(rtas_data_buf, 0, RTAS_DATA_BUF_SIZE); + rc = rtas_call(token, 3, 1, NULL, SPLPAR_LPAR_NAME_TOKEN, + __pa(rtas_data_buf), RTAS_DATA_BUF_SIZE); + memcpy(local_buffer, rtas_data_buf, SPLPAR_LPAR_NAME_MAXLEN);
Would be nice to skip the memcpy() if rc is non-zero.
arch/powerpc/platforms/pseries/lparcfg.c static void parse_mpp_x_data(struct seq_file *m) · line 351
Quoted 10 lines
arch/powerpc/platforms/pseries/lparcfg.c +10
-0+spin_unlock (&rtas_data_buf_lock); + }while (rtas_busy_delay (rc)); + +if (rc !=0 ) { +pr_err_once ( +"%s %s Error calling get-system-parameter (0x%x)\n" , + __FILE__, __func__, rc); + }else { + local_buffer[SPLPAR_LPAR_NAME_MAXLEN -1 ] ='\0' ; + len = local_buffer[0 ] *256 + local_buffer[1 ];
This is kind of a hand rolled be16_to_cpu().
And we also have the + 2 to skip the length in several places.
I feel like the code would be cleaner if we had a type for the result buffer, eg something like:
union {
char raw_buffer[1026];
struct {
__be16 len;
char data[1024];
};
};arch/powerpc/platforms/pseries/lparcfg.c static void parse_mpp_x_data(struct seq_file *m) · line 359
Quoted 7 lines
arch/powerpc/platforms/pseries/lparcfg.c +7
-0+/* +* Forces an empty string in the weird case fw reports no data. +*/ +if (!len) + local_buffer[2 ] ='\0' ; + +seq_printf (m,"partition_name=%s\n" , local_buffer +2 );
Then above you could use the data field rather than having to add the "2" in both places.
Quoted 19 lines
arch/powerpc/platforms/pseries/lparcfg.c +7
-0+ } + +kfree (local_buffer); +} + +#define SPLPAR_CHARACTERISTICS_TOKEN 20#define SPLPAR_MAXLENGTH 1026*(sizeof(char))@@ -496,6 +548,7 @@ static int pseries_lparcfg_data(struct seq_file *m, void *v)if (firmware_has_feature (FW_FEATURE_SPLPAR )) {/* this call handles the ibm,get-system-parameter contents */ +parse_lpar_name (m);parse_system_parameter_string (m);parse_ppp_data (m);parse_mpp_data (m);Signature · 1 line
2.34.1
cheers
Quoted 3 lines · Michael Ellerman
Hi Laurent,
Just a few minor comments below ...
Thanks, Michael, for your _major_ comments.
I'll send a version 3 soon.
Laurent.
Quoted 130 lines
Quoted 24 lines · Laurent Dufour
The LPAR name may be changed after the LPAR has been started in the HMC. In that case lparstat command is not reporting the updated value because it reads it from the device tree which is read at boot time.
However this value could be read from RTAS.
Adding this value in the
/proc/powerpc/lparcfgoutput allows to read the updated value.Cc Nathan Lynch <[email protected]>Signed-off-by Laurent Dufour <[email protected]>---
v2:
address Nathan's comments.
change title topartition_namealigning with existingpartition_id--- arch/powerpc/platforms/pseries/lparcfg.c | 53 ++++++++++++++++++++++++ 1 file changed, 53 insertions(+)arch/powerpc/platforms/pseries/lparcfg.c +0
-0arch/powerpc/platforms/pseries/lparcfg.c static void parse_mpp_x_data(struct seq_file *m) · line 319
Quoted 9 lines
arch/powerpc/platforms/pseries/lparcfg.c +6
-0@@ -311,6 +311,58 @@ static void parse_mpp_x_data(struct seq_file *m)seq_printf (m,"coalesce_pool_spurr=%ld\n" , mpp_x_data.pool_spurr_cycles); } +/* +* PAPR defines no maximum for the LPAR name, and defines that the maximum +* length of the get-system-parameter's output buffer is 4000 plus 2 bytes for +* the length. Limit LPAR's name size to 1024 +*/ +#define SPLPAR_LPAR_NAME_MAXLEN 1026Why not just allocate the full 4000? That's not much memory in the scheme of things, and allocating less risks us needing to update this in future. I realise that's a ridiculously long LPAR name, but still.
arch/powerpc/platforms/pseries/lparcfg.c static void parse_mpp_x_data(struct seq_file *m) · line 320
Quoted 1 line
arch/powerpc/platforms/pseries/lparcfg.c +1
-0+#define SPLPAR_LPAR_NAME_TOKEN 55Can you add a comment saying where that value is defined, PAPR?
arch/powerpc/platforms/pseries/lparcfg.c static void parse_mpp_x_data(struct seq_file *m) · line 321
Quoted 1 line
arch/powerpc/platforms/pseries/lparcfg.c +1
-0+static void parse_lpar_name (struct seq_file *m)Nitpick, but we're not really parsing it, we're just reading it from firmware.
Quoted 9 lines
arch/powerpc/platforms/pseries/lparcfg.c +9
-0+{ +int rc, len, token; +unsigned char *local_buffer; + + token =rtas_token ("ibm,get-system-parameter" ); +if (token ==RTAS_UNKNOWN_SERVICE ) +return ; + + local_buffer =kmalloc (SPLPAR_LPAR_NAME_MAXLEN ,GFP_KERNEL );arch/powerpc/platforms/pseries/lparcfg.c static void parse_mpp_x_data(struct seq_file *m) · line 340
Quoted 10 lines
arch/powerpc/platforms/pseries/lparcfg.c +10
-0+if (!local_buffer) +return ; + + do { + spin_lock(&rtas_data_buf_lock); + + memset(rtas_data_buf, 0, RTAS_DATA_BUF_SIZE); + rc = rtas_call(token, 3, 1, NULL, SPLPAR_LPAR_NAME_TOKEN, + __pa(rtas_data_buf), RTAS_DATA_BUF_SIZE); + memcpy(local_buffer, rtas_data_buf, SPLPAR_LPAR_NAME_MAXLEN);Would be nice to skip the
memcpy()if rc is non-zero.arch/powerpc/platforms/pseries/lparcfg.c static void parse_mpp_x_data(struct seq_file *m) · line 351
Quoted 10 lines
arch/powerpc/platforms/pseries/lparcfg.c +10
-0+spin_unlock (&rtas_data_buf_lock); + }while (rtas_busy_delay (rc)); + +if (rc !=0 ) { +pr_err_once ( +"%s %s Error calling get-system-parameter (0x%x)\n" , + __FILE__, __func__, rc); + }else { + local_buffer[SPLPAR_LPAR_NAME_MAXLEN -1 ] ='\0' ; + len = local_buffer[0 ] *256 + local_buffer[1 ];This is kind of a hand rolled
be16_to_cpu().And we also have the + 2 to skip the length in several places.
I feel like the code would be cleaner if we had a type for the result buffer, eg something like:
union { char raw_buffer[1026]; struct { __be16 len; char data[1024]; }; };arch/powerpc/platforms/pseries/lparcfg.c static void parse_mpp_x_data(struct seq_file *m) · line 359
Quoted 7 lines
arch/powerpc/platforms/pseries/lparcfg.c +7
-0+/* +* Forces an empty string in the weird case fw reports no data. +*/ +if (!len) + local_buffer[2 ] ='\0' ; + +seq_printf (m,"partition_name=%s\n" , local_buffer +2 );Then above you could use the data field rather than having to add the "2" in both places.
Quoted 19 lines
arch/powerpc/platforms/pseries/lparcfg.c +7
-0+ } + +kfree (local_buffer); +} + +#define SPLPAR_CHARACTERISTICS_TOKEN 20#define SPLPAR_MAXLENGTH 1026*(sizeof(char))@@ -496,6 +548,7 @@ static int pseries_lparcfg_data(struct seq_file *m, void *v)if (firmware_has_feature (FW_FEATURE_SPLPAR )) {/* this call handles the ibm,get-system-parameter contents */ +parse_lpar_name (m);parse_system_parameter_string (m);parse_ppp_data (m);parse_mpp_data (m);Signature · 1 line
2.34.1cheers