[PATCH v1] hyperv: reduce size of ms_hyperv_info

2023-09-18 Thread Olaf Hering
Use the hole prior shared_gpa_boundary to store the result of get_vtl.
This reduces the size by 8 bytes.

Signed-off-by: Olaf Hering 
---
 include/asm-generic/mshyperv.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/asm-generic/mshyperv.h b/include/asm-generic/mshyperv.h
index cecd2b7bd033..bdee5fbaaf40 100644
--- a/include/asm-generic/mshyperv.h
+++ b/include/asm-generic/mshyperv.h
@@ -53,8 +53,8 @@ struct ms_hyperv_info {
u32 reserved_b2 : 20;
};
};
-   u64 shared_gpa_boundary;
u8 vtl;
+   u64 shared_gpa_boundary;
 };
 extern struct ms_hyperv_info ms_hyperv;
 extern bool hv_nested;



Re: [PATCH v1] hyperv: reduce size of ms_hyperv_info

2023-09-19 Thread Olaf Hering
Tue, 19 Sep 2023 06:18:53 + Dexuan Cui :

> How about moving the 'vtl' field to an even earlier place:

I have not tried it, but I think this would just move the hole up.
The end result will likely be the same, pahole -E vmlinux will show it.


Olaf


pgpDmiOmWAMyl.pgp
Description: Digitale Signatur von OpenPGP


[PATCH v2] hyperv: reduce size of ms_hyperv_info

2023-09-22 Thread Olaf Hering
Use the hole prior shared_gpa_boundary to store the result of get_vtl.
This reduces the size by 8 bytes.

Signed-off-by: Olaf Hering 
---
v2: move vtl up, as suggested by Dexuan Cui

 include/asm-generic/mshyperv.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/asm-generic/mshyperv.h b/include/asm-generic/mshyperv.h
index cecd2b7bd033..430f0ae0dde2 100644
--- a/include/asm-generic/mshyperv.h
+++ b/include/asm-generic/mshyperv.h
@@ -36,6 +36,7 @@ struct ms_hyperv_info {
u32 nested_features;
u32 max_vp_index;
u32 max_lp_index;
+   u8 vtl;
union {
u32 isolation_config_a;
struct {
@@ -54,7 +55,6 @@ struct ms_hyperv_info {
};
};
u64 shared_gpa_boundary;
-   u8 vtl;
 };
 extern struct ms_hyperv_info ms_hyperv;
 extern bool hv_nested;



[PATCH v1] tools: hv: change permissions of NetworkManager configuration file

2024-10-16 Thread Olaf Hering
Align permissions of the resulting .nmconnection file, instead of
the input file from hv_kvp_daemon. To avoid the tiny time frame
where the output file is world-readable, use umask instead of chmod.

Fixes: 42999c90 ("Support for keyfile based connection profile")

Signed-off-by: Olaf Hering 
---
 tools/hv/hv_set_ifconfig.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/hv/hv_set_ifconfig.sh b/tools/hv/hv_set_ifconfig.sh
index 440a91b35823..2f8baed2b8f7 100755
--- a/tools/hv/hv_set_ifconfig.sh
+++ b/tools/hv/hv_set_ifconfig.sh
@@ -81,7 +81,7 @@ echo "ONBOOT=yes" >> $1
 
 cp $1 /etc/sysconfig/network-scripts/
 
-chmod 600 $2
+umask 0177
 interface=$(echo $2 | awk -F - '{ print $2 }')
 filename="${2##*/}"
 



[PATCH v2] tools/hv: terminate fcopy daemon if read from uio fails

2024-11-05 Thread Olaf Hering
Terminate endless loop in reading fails, to avoid flooding syslog.

This happens if the state of "Guest services" integration service
is changed from "enabled" to "disabled" at runtime in the VM
settings. In this case pread returns EIO.

Also handle an interrupted system call, and continue in this case.

Signed-off-by: Olaf Hering 
---
v2: update commit message

A more complete fix is to handle this properly in the kernel,
by making the file descriptor unavailable for further operations.

 tools/hv/hv_fcopy_uio_daemon.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/tools/hv/hv_fcopy_uio_daemon.c b/tools/hv/hv_fcopy_uio_daemon.c
index 7a00f3066a98..281fd95dc0d8 100644
--- a/tools/hv/hv_fcopy_uio_daemon.c
+++ b/tools/hv/hv_fcopy_uio_daemon.c
@@ -468,8 +468,10 @@ int main(int argc, char *argv[])
 */
ret = pread(fcopy_fd, &tmp, sizeof(int), 0);
if (ret < 0) {
+   if (errno == EINTR || errno == EAGAIN)
+   continue;
syslog(LOG_ERR, "pread failed: %s", strerror(errno));
-   continue;
+   goto close;
}
 
len = HV_RING_SIZE;



[PATCH v1] tools/hv: terminate fcopy daemon if read from uio fails

2024-10-25 Thread Olaf Hering
Terminate endless loop in reading fails, to avoid flooding syslog.

This happens if the "Guest services" integration service is
disabled at runtime in the VM settings.

Also handle an interrupted system call, and continue in this case.

Signed-off-by: Olaf Hering 
---

A more complete fix is to handle this properly in the kernel,
by making the file descriptor unavailable for further operations.

 tools/hv/hv_fcopy_uio_daemon.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/tools/hv/hv_fcopy_uio_daemon.c b/tools/hv/hv_fcopy_uio_daemon.c
index 7a00f3066a98..281fd95dc0d8 100644
--- a/tools/hv/hv_fcopy_uio_daemon.c
+++ b/tools/hv/hv_fcopy_uio_daemon.c
@@ -468,8 +468,10 @@ int main(int argc, char *argv[])
 */
ret = pread(fcopy_fd, &tmp, sizeof(int), 0);
if (ret < 0) {
+   if (errno == EINTR || errno == EAGAIN)
+   continue;
syslog(LOG_ERR, "pread failed: %s", strerror(errno));
-   continue;
+   goto close;
}
 
len = HV_RING_SIZE;



Re: [PATCH v1] tools/hv: terminate fcopy daemon if read from uio fails

2024-10-28 Thread Olaf Hering
Mon, 28 Oct 2024 02:06:20 -0700 Saurabh Singh Sengar 
:

> Thanks for the patch. Changes look good to me, I will suggest to improve this
> log message incase the error type is EIO by suggesting that users verify if
> 'Guest Services' is enabled.

No error happens if the state of "Guest services" remains unchanged during
the life time of the VM (either "enabled" or "disabled"). Also no error happens
if "Guest services" changes from "disabled" to "enabled". But the error happens
if "Guest services" changes from "enabled" to "disabled". I think the actual
error "EIO" is not relevant for the commit message. Maybe you mean the second
paragraph should read like this?

This happens if the state of "Guest services" integration service is changed
from "enabled" to "disabled" at runtime in the VM settings.



I'm probably not telling news if I say that this behavior is a regression 
compared
to the hv_utils based variant of fcopy. In the past one could flip the state of
"Guest services", it would always come back if state changed to "enabled" again,
because the "hv_fcopy" device node came back. With UIO the device node does not
come back AFAICS. Not a big deal to reboot the VM in this case.


Olaf


pgploo1Ti5fxU.pgp
Description: Digitale Signatur von OpenPGP


[PATCH v1] tools/hv: reduce resouce usage in hv_kvp_daemon

2024-12-02 Thread Olaf Hering
hv_kvp_daemon uses popen(3) and system(3) as convinience helper to
launch external helpers. These helpers are invoked via a
temporary shell process. There is no need to keep this temporary
process around while the helper runs. Replace this temporary shell
with the actual helper process via 'exec'.

Signed-off-by: Olaf Hering 
---
 tools/hv/hv_kvp_daemon.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/tools/hv/hv_kvp_daemon.c b/tools/hv/hv_kvp_daemon.c
index ae57bf69ad4a..91b50cadfc52 100644
--- a/tools/hv/hv_kvp_daemon.c
+++ b/tools/hv/hv_kvp_daemon.c
@@ -725,7 +725,7 @@ static void kvp_get_ipconfig_info(char *if_name,
 * .
 */
 
-   sprintf(cmd, KVP_SCRIPTS_PATH "%s",  "hv_get_dns_info");
+   sprintf(cmd, "exec %s", KVP_SCRIPTS_PATH "hv_get_dns_info");
 
/*
 * Execute the command to gather DNS info.
@@ -742,7 +742,7 @@ static void kvp_get_ipconfig_info(char *if_name,
 * Enabled: DHCP enabled.
 */
 
-   sprintf(cmd, KVP_SCRIPTS_PATH "%s %s", "hv_get_dhcp_info", if_name);
+   sprintf(cmd, "exec %s %s", KVP_SCRIPTS_PATH "hv_get_dhcp_info", 
if_name);
 
file = popen(cmd, "r");
if (file == NULL)
@@ -1606,7 +1606,7 @@ static int kvp_set_ip_info(char *if_name, struct 
hv_kvp_ipaddr_value *new_val)
 * invoke the external script to do its magic.
 */
 
-   str_len = snprintf(cmd, sizeof(cmd), KVP_SCRIPTS_PATH "%s %s %s",
+   str_len = snprintf(cmd, sizeof(cmd), "exec %s %s %s", KVP_SCRIPTS_PATH
   "hv_set_ifconfig", if_filename, nm_filename);
/*
 * This is a little overcautious, but it's necessary to suppress some



[PATCH v1] tools/hv: reduce resouce usage in hv_get_dns_info helper

2024-12-02 Thread Olaf Hering
Remove the usage of cat. Replace the shell process with awk with 'exec'.
Also use a generic shell because no bash specific features will be used.

Signed-off-by: Olaf Hering 
---
 tools/hv/hv_get_dns_info.sh | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/tools/hv/hv_get_dns_info.sh b/tools/hv/hv_get_dns_info.sh
index 058c17b46ffc..268521234d4b 100755
--- a/tools/hv/hv_get_dns_info.sh
+++ b/tools/hv/hv_get_dns_info.sh
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/bin/sh
 
 # This example script parses /etc/resolv.conf to retrive DNS information.
 # In the interest of keeping the KVP daemon code free of distro specific
@@ -10,4 +10,4 @@
 # this script can be based on the Network Manager APIs for retrieving DNS
 # entries.
 
-cat /etc/resolv.conf 2>/dev/null | awk '/^nameserver/ { print $2 }'
+exec awk '/^nameserver/ { print $2 }' /etc/resolv.conf 2>/dev/null



[PATCH v1] tools/hv: add a .gitignore file

2024-12-02 Thread Olaf Hering
Remove generated files from 'git status' output after 'make -C tools/hv'.

Signed-off-by: Olaf Hering 
---
 tools/hv/.gitignore | 3 +++
 1 file changed, 3 insertions(+)
 create mode 100644 tools/hv/.gitignore

diff --git a/tools/hv/.gitignore b/tools/hv/.gitignore
new file mode 100644
index ..0c5bc15d602f
--- /dev/null
+++ b/tools/hv/.gitignore
@@ -0,0 +1,3 @@
+hv_fcopy_uio_daemon
+hv_kvp_daemon
+hv_vss_daemon



[PATCH v1] tools/hv: update route parsing in kvp daemon

2024-12-02 Thread Olaf Hering
After recent changes in the VM network stack, the host fails to
display the IP addresses of the VM. As a result the "IP Addresses"
column in the "Networking" tab in the Windows Hyper-V Manager is
empty. This is caused by a change in the expected output of the
"ip route show" command. Previously the gateway address was shown
in the third row. Now the gateway addresses might be split into
several lines of output. As a result, the string "ra" instead of
an IP address is sent to the host.

To me more specific, a VM with the wellknown wicked network
managing tool still shows the expected output in recent openSUSE
Tumbleweed snapshots:

ip a show dev uplink;ip -4 route show;ip -6 route show
2: uplink:  mtu 1500 qdisc mq state ...
link/ether 00:15:5d:d0:93:08 brd ff:ff:ff:ff:ff:ff
inet 1.2.3.4/22 brd 1.2.3.255 scope global uplink
   valid_lft forever preferred_lft forever
inet6 fe80::215:5dff:fed0:9308/64 scope link proto kernel_ll
   valid_lft forever preferred_lft forever
default via 1.2.3.254 dev uplink proto dhcp
1.2.3.0/22 dev uplink proto kernel scope link src 1.2.3.4
fe80::/64 dev uplink proto kernel metric 256 pref medium
default via fe80::26fc:4e00:3b:74 dev uplink proto ra metric 1024 exp...
default via fe80::6a22:8e00:fb:14f8 dev uplink proto ra metric 1024 e...

A similar VM, but with NetworkManager as network managing tool:

ip a show dev eth0;ip -4 route show;ip -6 route show
2: eth0:  mtu 1500 qdisc mq state UP...
link/ether 00:15:5d:d0:93:0b brd ff:ff:ff:ff:ff:ff
inet 1.2.3.8/22 brd 1.2.3.255 scope global dynamic noprefixroute ...
   valid_lft 1022sec preferred_lft 1022sec
inet6 fe80::215:5dff:fed0:930b/64 scope link noprefixroute
   valid_lft forever preferred_lft forever
default via 1.2.3.254 dev eth0 proto dhcp src 1.2.3.8 metric 100
1.2.3.0/22 dev eth0 proto kernel scope link src 1.2.3.8 metric 100
fe80::/64 dev eth0 proto kernel metric 1024 pref medium
default proto ra metric 20100 pref medium
nexthop via fe80::6a22:8e00:fb:14f8 dev eth0 weight 1
nexthop via fe80::26fc:4e00:3b:74 dev eth0 weight 1

Adjust the route parsing to use a single line for each line of
output. Also use a single shell invocation to retrieve both IPv4
and IPv6 information. The actual IP addresses are expected after
the "via" keyword.

Signed-off-by: Olaf Hering 
---
 tools/hv/hv_kvp_daemon.c | 108 ++-
 1 file changed, 84 insertions(+), 24 deletions(-)

diff --git a/tools/hv/hv_kvp_daemon.c b/tools/hv/hv_kvp_daemon.c
index ae57bf69ad4a..63b44b191320 100644
--- a/tools/hv/hv_kvp_daemon.c
+++ b/tools/hv/hv_kvp_daemon.c
@@ -24,6 +24,7 @@
 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -677,6 +678,88 @@ static void kvp_process_ipconfig_file(char *cmd,
pclose(file);
 }
 
+static bool kvp_verify_ip_address(const void *address_string)
+{
+   char verify_buf[sizeof(struct in6_addr)];
+
+   if (inet_pton(AF_INET, address_string, verify_buf) == 1)
+   return true;
+   if (inet_pton(AF_INET6, address_string, verify_buf) == 1)
+   return true;
+   return false;
+}
+
+static void kvp_extract_routes(const char *line, void **output, size_t 
*remaining)
+{
+   static const char needle[] = "via ";
+   const char *match, *haystack = line;
+
+   while ((match = strstr(haystack, needle))) {
+   const char *address, *next_char;
+
+   /* Address starts after needle. */
+   address = match + strlen(needle);
+
+   /* The char following address is a space or end of line. */
+   next_char = strpbrk(address, " \t\\");
+   if (!next_char)
+   next_char = address + strlen(address) + 1;
+
+   /* Enough room for address and semicolon. */
+   if (*remaining >= (next_char - address) + 1) {
+   memcpy(*output, address, next_char - address);
+   /* Terminate string for verification. */
+   memcpy(*output + (next_char - address), "", 1);
+   if (kvp_verify_ip_address(*output)) {
+   /* Advance output buffer. */
+   *output += next_char - address;
+   *remaining -= next_char - address;
+
+   /* Each address needs a trailing semicolon. */
+   memcpy(*output, ";", 1);
+   *output += 1;
+   *remaining -= 1;
+   }
+   }
+   haystack = next_char;
+   }
+}
+
+static void kvp_get_gateway(void *buffer, size_t buffer_len)
+{
+   static const char needle[] = "default ";
+   FILE *f;
+   void *output = buffer;
+   char *line = NULL;
+ 

Re: [PATCH v1] tools/hv: reduce resouce usage in hv_kvp_daemon

2024-12-08 Thread Olaf Hering
Sun, 8 Dec 2024 23:52:54 + Wei Liu :

> There's one conflict caused by an earlier patch by Vitaly. I've resolved
> the conflict and applied the patch to hyperv-fixes. Please check the
> final result.

Commit b8ea8cd0fbd358feee3e9172c5ef8afd671e0d11 looks good, thanks.


Olaf


pgp7RZdDSAY7I.pgp
Description: Digitale Signatur von OpenPGP