All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Jürgen Groß" <jgross@suse.com>
To: Jan Beulich <jbeulich@suse.com>
Cc: "Kevin Tian" <kevin.tian@intel.com>,
	"Stefano Stabellini" <sstabellini@kernel.org>,
	"Julien Grall" <julien@xen.org>, "Wei Liu" <wl@xen.org>,
	"Konrad Rzeszutek Wilk" <konrad.wilk@oracle.com>,
	"Andrew Cooper" <andrew.cooper3@citrix.com>,
	"Ian Jackson" <ian.jackson@eu.citrix.com>,
	"George Dunlap" <george.dunlap@citrix.com>,
	"Jun Nakajima" <jun.nakajima@intel.com>,
	xen-devel@lists.xenproject.org,
	"Volodymyr Babchuk" <Volodymyr_Babchuk@epam.com>,
	"Roger Pau Monné" <roger.pau@citrix.com>
Subject: Re: [Xen-devel] [PATCH v6 09/12] xen: add runtime parameter access support to hypfs
Date: Wed, 4 Mar 2020 16:07:31 +0100	[thread overview]
Message-ID: <1a6e1c6c-7e88-3396-885b-62371bb24db4@suse.com> (raw)
In-Reply-To: <61640156-0e35-6808-829a-2eb8accbfb94@suse.com>

On 04.03.20 12:32, Jan Beulich wrote:
> On 26.02.2020 13:47, Juergen Gross wrote:
>> --- a/xen/arch/x86/hvm/vmx/vmcs.c
>> +++ b/xen/arch/x86/hvm/vmx/vmcs.c
>> @@ -70,6 +70,30 @@ integer_param("ple_window", ple_window);
>>   static bool __read_mostly opt_ept_pml = true;
>>   static s8 __read_mostly opt_ept_ad = -1;
>>   int8_t __read_mostly opt_ept_exec_sp = -1;
>> +static char opt_ept_setting[16];
> 
> I don't think this is quite big enough.

Yes, you are right.

> 
>> +static void update_ept_param_append(const char *str, int val)
>> +{
>> +    char *pos = opt_ept_setting + strlen(opt_ept_setting);
>> +
>> +    snprintf(pos, sizeof(opt_ept_setting) - (pos - opt_ept_setting),
>> +             ",%s=%d", str, val);
>> +}
>> +
>> +static void update_ept_param(void)
>> +{
>> +    snprintf(opt_ept_setting, sizeof(opt_ept_setting), "pml=%d", opt_ept_pml);
>> +    if ( opt_ept_ad >= 0 )
>> +        update_ept_param_append("ad", opt_ept_ad);
> 
> This won't correctly reflect reality: If you look at
> vmx_init_vmcs_config(), even a negative value means "true" here,
> unless on a specific Atom model. I think init_ept_param() wants
> to have that erratum workaround logic moved there, such that
> you can then assme the value to be non-negative here.

But isn't not mentioning it in the -1 case correct? -1 means: do the
correct thing on the current hardware.

In case we want to report an explicit value for "ad" we should add a
node for that purpose.

>> +    if ( opt_ept_exec_sp >= 0 )
>> +        update_ept_param_append("exec-sp", opt_ept_exec_sp);
> 
> I agree for this one - if the value is still -1, it has neither
> been set nor is its value of any interest.
> 
>> +static void __init init_ept_param(struct param_hypfs *par)
>> +{
>> +    custom_runtime_set_var(par, opt_ept_setting);
>> +    update_ept_param();
>> +}
>>   
>>   static int __init parse_ept_param(const char *s)
>>   {
>> @@ -93,6 +117,8 @@ static int __init parse_ept_param(const char *s)
>>           s = ss + 1;
>>       } while ( *ss );
>>   
>> +    update_ept_param();
> 
> Isn't this redundant with the use in init_ept_param() (or the
> other way around - there should be clear ordering between the
> command line parsing functions and the param-init ones, I would
> suppose)?

You are right. I can drop this call, as the param-init call will
come later.

> 
>> --- a/xen/arch/x86/pv/domain.c
>> +++ b/xen/arch/x86/pv/domain.c
>> @@ -20,8 +20,27 @@ static __read_mostly enum {
>>       PCID_OFF,
>>       PCID_ALL,
>>       PCID_XPTI,
>> -    PCID_NOXPTI
>> +    PCID_NOXPTI,
>> +    PCID_END
>>   } opt_pcid = PCID_XPTI;
>> +static const char *opt_pcid_2_string[PCID_END] = {
> 
> You either want another const here, or (more space efficient) you
> want to use const char[PCID_END][7].

Ah, right, good idea.

> 
>> +    [PCID_OFF] = "off",
>> +    [PCID_ALL] = "on",
>> +    [PCID_XPTI] = "xpti",
>> +    [PCID_NOXPTI] = "noxpti"
>> +};
>> +static char opt_pcid_val[7];
>> +
>> +static void update_opt_pcid(void)
>> +{
>> +    strlcpy(opt_pcid_val, opt_pcid_2_string[opt_pcid], sizeof(opt_pcid_val));
> 
> Instead of copying, couldn't you make the hypfs entry point
> into the array above, by using custom_runtime_set_var() here?

Hmm, probably yes.

> 
>> @@ -55,9 +74,12 @@ static int parse_pcid(const char *s)
>>           break;
>>       }
>>   
>> +    if ( !rc )
>> +        update_opt_pcid();
> 
> Personally I'd avoid the if() here - there's no harm updating
> the hypfs entry anyway.

Okay.

> 
>> --- a/xen/common/grant_table.c
>> +++ b/xen/common/grant_table.c
>> @@ -85,8 +85,10 @@ struct grant_table {
>>       struct grant_table_arch arch;
>>   };
>>   
>> -static int parse_gnttab_limit(const char *param, const char *arg,
>> -                              unsigned int *valp)
>> +#define GRANT_CUSTOM_VAL_SZ  12
>> +
>> +static int parse_gnttab_limit(const char *arg, unsigned int *valp,
>> +                              char *parval)
>>   {
>>       const char *e;
>>       unsigned long val;
>> @@ -99,28 +101,47 @@ static int parse_gnttab_limit(const char *param, const char *arg,
>>           return -ERANGE;
>>   
>>       *valp = val;
>> +    snprintf(parval, GRANT_CUSTOM_VAL_SZ, "%lu", val);
>>   
>>       return 0;
>>   }
>>   
>>   unsigned int __read_mostly opt_max_grant_frames = 64;
>> +static char __read_mostly opt_max_grant_frames_val[GRANT_CUSTOM_VAL_SZ];
>> +
>> +static void __init gnttab_max_frames_init(struct param_hypfs *par)
>> +{
>> +    custom_runtime_set_var(par, opt_max_grant_frames_val);
> 
> You still use a custom string buffer here. Can this "set-var"
> operation record that the variable (for presentation purposes)
> is simply of UINT type, handing a pointer to the actual
> variable?

No, this would result in the need to set a custom parameter via a
binary value passed in from user land. So I'd need to convert this
binary into a string to be parseable by the custom function.

> 
>> --- a/xen/common/hypfs.c
>> +++ b/xen/common/hypfs.c
>> @@ -10,6 +10,7 @@
>>   #include <xen/hypercall.h>
>>   #include <xen/hypfs.h>
>>   #include <xen/lib.h>
>> +#include <xen/param.h>
>>   #include <xen/rwlock.h>
>>   #include <public/hypfs.h>
>>   
>> @@ -281,6 +282,33 @@ int hypfs_write_bool(struct hypfs_entry_leaf *leaf,
>>       return 0;
>>   }
>>   
>> +int hypfs_write_custom(struct hypfs_entry_leaf *leaf,
>> +                       XEN_GUEST_HANDLE_PARAM(void) uaddr, unsigned long ulen)
>> +{
>> +    struct param_hypfs *p;
>> +    char *buf;
>> +    int ret;
>> +
>> +    buf = xzalloc_array(char, ulen);
>> +    if ( !buf )
>> +        return -ENOMEM;
>> +
>> +    ret = -EFAULT;
>> +    if ( copy_from_guest(buf, uaddr, ulen) )
>> +        goto out;
>> +
>> +    ret = -EDOM;
>> +    if ( !memchr(buf, 0, ulen) )
> 
> Once again " != buf + ulen - 1"? (EDOM also looks like an odd
> error code to use in this case, but I guess there's no really
> good one.)

" != buf + ulen - 1" is a logical choice with the change of patch 4.

> 
>> --- a/xen/drivers/char/console.c
>> +++ b/xen/drivers/char/console.c
>> @@ -75,12 +75,36 @@ enum con_timestamp_mode
>>       TSM_DATE_MS,       /* [YYYY-MM-DD HH:MM:SS.mmm] */
>>       TSM_BOOT,          /* [SSSSSS.uuuuuu] */
>>       TSM_RAW,           /* [XXXXXXXXXXXXXXXX] */
>> +    TSM_END
>> +};
>> +
>> +static const char *con_timestamp_mode_2_string[TSM_END] = {
>> +    [TSM_NONE] = "none",
>> +    [TSM_DATE] = "date",
>> +    [TSM_DATE_MS] = "datems",
>> +    [TSM_BOOT] = "boot",
>> +    [TSM_RAW] = "raw"
>>   };
>>   
>>   static enum con_timestamp_mode __read_mostly opt_con_timestamp_mode = TSM_NONE;
>> +static char con_timestamp_mode_val[7];
>> +
>> +static void update_con_timestamp_mode(void)
>> +{
>> +    strlcpy(con_timestamp_mode_val,
>> +            con_timestamp_mode_2_string[opt_con_timestamp_mode],
>> +            sizeof(con_timestamp_mode_val));
>> +}
>> +
>> +static void __init con_timestamp_mode_init(struct param_hypfs *par)
>> +{
>> +    custom_runtime_set_var(par, con_timestamp_mode_val);
>> +    update_con_timestamp_mode();
>> +}
>>   
>>   static int parse_console_timestamps(const char *s);
>> -custom_runtime_param("console_timestamps", parse_console_timestamps);
>> +custom_runtime_param("console_timestamps", parse_console_timestamps,
>> +                     con_timestamp_mode_init);
> 
> Same remark as for the PCID option, and then also for the log level
> ones further down. My main concern with how things are currently is
> that the amount of logic needed for custom params seems overly
> large.
> 
>> @@ -79,41 +88,94 @@ extern const struct kernel_param __param_start[], __param_end[];
>>             .type = OPT_IGNORE }
>>   
>>   #define __rtparam         __param(__dataparam)
>> +#define __paramfs         static __paramhypfs \
>> +    __attribute__((__aligned__(sizeof(void *)))) struct param_hypfs
>>   
>> -#define custom_runtime_only_param(_name, _var) \
>> +#define custom_runtime_set_var(parfs, var) \
>> +    { \
>> +        (parfs)->hypfs.write_ptr = &(var); \
>> +        (parfs)->hypfs.e.size = sizeof(var); \
> 
> All users of this use char[]. Why sizeof() rather than strlen(),

That is the maximum string length. Otherwise I wouldn't know I am
allowed to replace e.g. "on" by "noxpti".

> and why taking the address instead of enforcing this to be of
> (at least) array (potentially also "of char") type? Do you
> envision this to be needed for anything where the value isn't
> in string form, but still needs dynamically calculating? (As per
> above there may already be cases where non-string variables may
> want passing into here.)

Ah, this is a leftover from the failed experiment to allow other
types than strings. I'll change it accordingly.


Juergen

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

  reply	other threads:[~2020-03-04 15:07 UTC|newest]

Thread overview: 50+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-26 12:46 [Xen-devel] [PATCH v6 00/12] Add hypervisor sysfs-like support Juergen Gross
2020-02-26 12:46 ` [Xen-devel] [PATCH v6 01/12] xen: allow only sizeof(bool) variables for boolean_param() Juergen Gross
2020-03-03 16:40   ` Jan Beulich
2020-03-09 11:43   ` Julien Grall
2020-03-09 11:55     ` Jan Beulich
2020-03-09 13:01       ` Jürgen Groß
2020-03-09 13:06         ` Jan Beulich
2020-03-09 14:06           ` Jürgen Groß
2020-02-26 12:46 ` [Xen-devel] [PATCH v6 02/12] xen: add a generic way to include binary files as variables Juergen Gross
2020-02-26 12:46 ` [Xen-devel] [PATCH v6 03/12] docs: add feature document for Xen hypervisor sysfs-like support Juergen Gross
2020-03-09 11:48   ` Julien Grall
2020-03-25 14:05     ` Jürgen Groß
2020-02-26 12:46 ` [Xen-devel] [PATCH v6 04/12] xen: add basic hypervisor filesystem support Juergen Gross
2020-03-03 16:59   ` Jan Beulich
2020-03-04 12:00     ` Jürgen Groß
2020-03-04 13:03       ` Jan Beulich
2020-03-04 14:39         ` Jürgen Groß
2020-03-04 15:07           ` Jan Beulich
2020-03-04 15:14             ` Jürgen Groß
2020-03-04 15:21               ` Jan Beulich
2020-03-06  6:06                 ` Jürgen Groß
2020-03-06  8:19                   ` Jan Beulich
2020-02-26 12:46 ` [Xen-devel] [PATCH v6 05/12] libs: add libxenhypfs Juergen Gross
2020-02-26 12:46 ` [Xen-devel] [PATCH v6 06/12] tools: add xenfs tool Juergen Gross
2020-02-26 12:47 ` [Xen-devel] [PATCH v6 07/12] xen: provide version information in hypfs Juergen Gross
2020-02-26 12:47 ` [Xen-devel] [PATCH v6 08/12] xen: add /buildinfo/config entry to hypervisor filesystem Juergen Gross
2020-03-04 10:49   ` Jan Beulich
2020-03-04 12:06     ` Jürgen Groß
2020-03-04 13:04       ` Jan Beulich
2020-02-26 12:47 ` [Xen-devel] [PATCH v6 09/12] xen: add runtime parameter access support to hypfs Juergen Gross
2020-03-04 11:32   ` Jan Beulich
2020-03-04 15:07     ` Jürgen Groß [this message]
2020-03-04 15:19       ` Jan Beulich
2020-03-04 16:31         ` Jürgen Groß
2020-03-04 16:56           ` Jan Beulich
2020-03-05  6:01             ` Jürgen Groß
2020-03-05  8:26               ` Jan Beulich
2020-03-06  6:42                 ` Jürgen Groß
2020-03-06  8:20                   ` Jan Beulich
2020-03-06  8:47                     ` Jürgen Groß
2020-03-06  9:04                       ` Jan Beulich
2020-03-06  9:20                         ` Jürgen Groß
2020-03-06  9:22                           ` Jan Beulich
2020-03-06  9:27                             ` Jürgen Groß
2020-03-23 10:38   ` Julien Grall
2020-02-26 12:47 ` [Xen-devel] [PATCH v6 10/12] tools/libxl: use libxenhypfs for setting xen runtime parameters Juergen Gross
2020-02-26 12:47 ` [Xen-devel] [PATCH v6 11/12] tools/libxc: remove xc_set_parameters() Juergen Gross
2020-02-26 12:47 ` [Xen-devel] [PATCH v6 12/12] xen: remove XEN_SYSCTL_set_parameter support Juergen Gross
2020-03-04 11:45   ` Jan Beulich
2020-03-04 14:40     ` Jürgen Groß

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1a6e1c6c-7e88-3396-885b-62371bb24db4@suse.com \
    --to=jgross@suse.com \
    --cc=Volodymyr_Babchuk@epam.com \
    --cc=andrew.cooper3@citrix.com \
    --cc=george.dunlap@citrix.com \
    --cc=ian.jackson@eu.citrix.com \
    --cc=jbeulich@suse.com \
    --cc=julien@xen.org \
    --cc=jun.nakajima@intel.com \
    --cc=kevin.tian@intel.com \
    --cc=konrad.wilk@oracle.com \
    --cc=roger.pau@citrix.com \
    --cc=sstabellini@kernel.org \
    --cc=wl@xen.org \
    --cc=xen-devel@lists.xenproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.