qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Philippe Mathieu-Daudé" <philmd@linaro.org>
To: Yunpeng Yang <yunpeng.yang@nutanix.com>,
	"minyard@acm.org" <minyard@acm.org>
Cc: "farosas@suse.de" <farosas@suse.de>,
	"lvivier@redhat.com" <lvivier@redhat.com>,
	"pbonzini@redhat.com" <pbonzini@redhat.com>,
	"qemu-devel@nongnu.org" <qemu-devel@nongnu.org>,
	Mark Cave-Ayland <mark.caveayland@nutanix.com>,
	"corey@minyard.net" <corey@minyard.net>,
	Jonathan Davies <jond@nutanix.com>,
	"cornelia.huck@de.ibm.com" <cornelia.huck@de.ibm.com>
Subject: Re: [PATCH 1/2] hw/ipmi/ipmi_bmc_sim: Support getting fake LAN channel config
Date: Mon, 1 Dec 2025 21:18:08 +0100	[thread overview]
Message-ID: <a5803130-031a-441d-b15e-c8ea31ff82e3@linaro.org> (raw)
In-Reply-To: <20251028180115.1098433-2-yunpeng.yang@nutanix.com>

Hi Yunpeng,

On 28/10/25 19:01, Yunpeng Yang wrote:
> The following IPMI commands are added or modified to support getting
> fake LAN channel configurations from the `ipmi_bmc_sim` device:
> * Get Channel Access;
> * Get Channel Info Command;
> * Get LAN Configuration Parameters.
> 
> The fake LAN channel configurations can be specified from QEMU
> commandline options for device `ipmi_bmc_sim`. Inside the guest OS, the
> configurations can be retrieved from the device using some IPMI tools,
> e.g., `ipmitool lan print`.
> Note, there is not a real LAN channel. The fake LAN channel is suitable
> for testing purposes.
> 
> Signed-off-by: Yunpeng Yang <yunpeng.yang@nutanix.com>
> ---
>   hw/ipmi/ipmi_bmc_sim.c      | 297 ++++++++++++++++++++++++++++++++++--
>   include/hw/ipmi/ipmi.h      |   1 +
>   qemu-options.hx             |  26 ++++
>   tests/qtest/ipmi-kcs-test.c |  60 ++++++++
>   4 files changed, 374 insertions(+), 10 deletions(-)


>   /* Same as a timespec struct. */
>   struct ipmi_time {
> @@ -170,6 +177,23 @@ typedef struct IPMISensor {
>   #define MAX_SENSORS 20
>   #define IPMI_WATCHDOG_SENSOR 0
>   
> +#define NBYTES_IP  4
> +#define NBYTES_MAC 6
> +
> +typedef struct IPMILan {
> +    uint8_t channel;
> +    uint8_t ipaddr[NBYTES_IP];
> +    uint8_t ipsrc;
> +    MACAddr macaddr;
> +    uint8_t netmask[NBYTES_IP];
> +    uint8_t defgw_ipaddr[NBYTES_IP];
> +    MACAddr defgw_macaddr;
> +
> +    char *arg_ipaddr;
> +    char *arg_netmask;
> +    char *arg_defgw_ipaddr;
> +} IPMILan;
> +
>   #define MAX_NETFNS 64
>   
>   typedef struct IPMIRcvBufEntry {
> @@ -215,6 +239,7 @@ struct IPMIBmcSim {
>       IPMIFru fru;
>       IPMISensor sensors[MAX_SENSORS];
>       char *sdr_filename;
> +    IPMILan lan;
>   

[...]

> +static inline bool is_valid_netmask(const uint8_t *netmask)
> +{
> +    uint32_t mask = netmask[3];
> +    uint32_t inverted;
> +
> +    mask |= (uint32_t) netmask[2] << 8;
> +    mask |= (uint32_t) netmask[1] << 16;
> +    mask |= (uint32_t) netmask[0] << 24;

Why manually byteswap?

I'd expect such helper already available in include/net/ somewhere,
otherwise what about:

   static bool is_ipv4_netmask_valid(const void *buf)
   {
       uint32_t netmask = ldl_be_p(buf);

       return clo32(netmask) + ctz32(netmask) == 32;
   }

> +    inverted = ~mask;
> +    return mask != 0 && (inverted & (inverted + 1)) == 0;
> +}


> @@ -2176,7 +2395,7 @@ static void ipmi_sdr_init(IPMIBmcSim *ibs)
>   
>   static const VMStateDescription vmstate_ipmi_sim = {
>       .name = TYPE_IPMI_BMC_SIMULATOR,
> -    .version_id = 1,
> +    .version_id = 2,
>       .minimum_version_id = 1,
>       .fields = (const VMStateField[]) {
>           VMSTATE_UINT8(bmc_global_enables, IPMIBmcSim),
> @@ -2198,6 +2417,13 @@ static const VMStateDescription vmstate_ipmi_sim = {
>           VMSTATE_UINT16(sensors[IPMI_WATCHDOG_SENSOR].deassert_states,
>                          IPMIBmcSim),
>           VMSTATE_UINT16(sensors[IPMI_WATCHDOG_SENSOR].assert_enable, IPMIBmcSim),
> +        VMSTATE_UINT8_V(lan.channel, IPMIBmcSim, 2),
> +        VMSTATE_UINT8_ARRAY_V(lan.ipaddr, IPMIBmcSim, NBYTES_IP, 2),
> +        VMSTATE_UINT8_V(lan.ipsrc, IPMIBmcSim, 2),
> +        VMSTATE_UINT8_ARRAY_V(lan.macaddr.a, IPMIBmcSim, NBYTES_MAC, 2),
> +        VMSTATE_UINT8_ARRAY_V(lan.netmask, IPMIBmcSim, NBYTES_IP, 2),
> +        VMSTATE_UINT8_ARRAY_V(lan.defgw_ipaddr, IPMIBmcSim, NBYTES_IP, 2),
> +        VMSTATE_UINT8_ARRAY_V(lan.defgw_macaddr.a, IPMIBmcSim, NBYTES_MAC, 2),

Safer would be to add a VMStateDescription for the new IPMILan
structure and link it as subsections, so other code using could just
link as subsection, not duplicating the VMSTATE_FOO() macros.

>           VMSTATE_END_OF_LIST()
>       }
>   };

Regards,

Phil.


  reply	other threads:[~2025-12-01 20:18 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-28 18:01 [PATCH 0/2] hw/ipmi/ipmi_bmc_sim: Get/set fake LAN config Yunpeng Yang
2025-10-28 18:01 ` [PATCH 1/2] hw/ipmi/ipmi_bmc_sim: Support getting fake LAN channel config Yunpeng Yang
2025-12-01 20:18   ` Philippe Mathieu-Daudé [this message]
2025-10-28 18:01 ` [PATCH 2/2] hw/ipmi/ipmi_bmc_sim: Support setting " Yunpeng Yang
2025-11-24 20:54 ` [PATCH 0/2] hw/ipmi/ipmi_bmc_sim: Get/set fake LAN config Corey Minyard
2025-11-26 18:04   ` Yunpeng Yang
2025-11-27 17:28     ` Yunpeng Yang

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=a5803130-031a-441d-b15e-c8ea31ff82e3@linaro.org \
    --to=philmd@linaro.org \
    --cc=corey@minyard.net \
    --cc=cornelia.huck@de.ibm.com \
    --cc=farosas@suse.de \
    --cc=jond@nutanix.com \
    --cc=lvivier@redhat.com \
    --cc=mark.caveayland@nutanix.com \
    --cc=minyard@acm.org \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=yunpeng.yang@nutanix.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).