Skip to contentSkip to conversation

examine: detect IOMMU availability and add it as a hostflag

PATCH Superseded Roger Pau Monne 2 participants 7 messages Mar 10, 2020 – Mar 11, 2020

v2 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/2 examine: detect IOMMU availability and add it as a hostflag

Introduce a new test to check for iommu availability and add it as a hostflag if found.

---
 Osstest/HostDB/Executive.pm | 19 +++++++++++++++++++
 Osstest/HostDB/Static.pm    |  6 ++++++
 Osstest/TestSupport.pm      | 16 ++++++++++++++--
 sg-run-job                  |  1 +
 ts-examine-hostprops-save   | 23 ++++++++++++++---------
 ts-examine-iommu            | 31 +++++++++++++++++++++++++++++++
 6 files changed, 85 insertions(+), 11 deletions(-)
 create mode 100755 ts-examine-iommu
Osstest/HostDB/Executive.pm +19 -0
index 7ffca6c4..8bedbdff 100644
@@ -90,6 +90,25 @@ END
     return $flags;
 }
 
+sub set_flag($$$) {
+    my ($hd, $ho, $flag) = @_;
+    my $rmq = $dbh_tests->prepare(<<END);
+        DELETE FROM hostflags WHERE hostname=? AND hostflag=?
+END
+    my $addq = $dbh_tests->prepare(<<END);
+        INSERT INTO hostflags (hostname,hostflag) VALUES (?,?)
+END
+    my $blessing = intended_blessing();
+
+    die "Attempting to modify host flags with intended blessing $blessing != real"
+        if $blessing ne "real";
+
+    db_retry($dbh_tests, [qw(resources)], sub {
+        $rmq->execute($ho->{Name}, $flag);
+        $addq->execute($ho->{Name}, $flag);
+    });
+}
+
 sub get_arch_platforms ($$$) {
     my ($hd, $blessing, $arch, $suite) = @_;
 
Osstest/HostDB/Static.pm +6 -0
index 0c6be3ee..8ac39cf5 100644
@@ -72,6 +72,12 @@ sub get_flags ($$) { #method
     return $flags;
 }
 
+sub set_property($$$) {
+    my ($hd, $ho, $flag) = @_;
+
+    die "Cannot set flags in standalone mode for $ho->{Name} $flag\n";
+}
+
 sub get_arch_platforms ($$$) {
     my ($hd, $blessing, $arch, $suite) = @_;
 
Osstest/TestSupport.pm +14 -2
index f49ed529..0291dbd8 100644
@@ -84,9 +84,9 @@ BEGIN {
                       get_target_property get_host_native_linux_console
                       hostnamepath hostnamepath_list set_runtime_hostflag
                       power_state power_cycle power_reboot_attempts
-                      serial_fetch_logs set_host_property
+                      serial_fetch_logs set_host_property set_host_flag
                       propname_massage propname_check
-                      hostprop_putative_record
+                      hostprop_putative_record hostflag_putative_record
          
                       get_stashed open_unique_stashfile compress_stashed
                       dir_identify_vcs
@@ -1411,6 +1411,18 @@ sub hostprop_putative_record ($$$) {
     store_runvar("hostprop/$ho->{Ident}/$prop", $val);
 }
 
+sub set_host_flag ($$) {
+    my ($ho,$flag) = @_;
+
+    $mhostdb->set_flag($ho, $flag);
+}
+
+sub hostflag_putative_record ($$) {
+    my ($ho, $prop) = @_;
+
+    store_runvar("hostflag/$ho->{Ident}/$prop", "");
+}
+
 sub get_target_property ($$;$);
 sub get_target_property ($$;$) {
     my ($ho, $prop, $defval) = @_;
sg-run-job +1 -0
index 7c58d4ba..f6bfdfd5 100755
@@ -679,6 +679,7 @@ proc examine-host-examine {install} {
     if {$ok} {
 	run-ts -.  =           ts-examine-serial-post + host
 	run-ts .   =           ts-examine-logs-save   + host
+	run-ts .   =           ts-examine-iommu       + host
 	run-ts .   =           ts-examine-hostprops-save
     }
 }
ts-examine-hostprops-save +14 -9
index 55d23392..502c2db2 100755
@@ -27,20 +27,25 @@ tsreadconfig();
 
 our $blessing = intended_blessing();
 
-logm("setting host properties");
+logm("setting host properties and flags");
 
 # NB: in order to aid debug only attempt to save the host props on flights
 # with intended real blessing, for the rest just do a dry run.
 our $dry_run = $blessing ne "real";
-logm("not saving host props with intended blessing $blessing != real")
+logm("not saving host props/flags with intended blessing $blessing != real")
     if $dry_run;
 
 foreach my $k (sort keys %r) {
-    next unless $k =~ m/^hostprop\/([^\/]*)\/([^\/]*)$/;
-    my $ho = selecthost($1);
-    my $prop = $2;
-
-    logm("recording for $ho->{Name} $prop=$r{$k}");
-
-    set_host_property($ho, $prop, $r{$k}) if !$dry_run;
+    next unless $k =~ m/^host(prop|flag)\/([^\/]*)\/([^\/]*)$/;
+    my $type = $1;
+    my $ho = selecthost($2);
+    my $prop = $3;
+
+    if ($type == "flag") {
+        logm("recording flag $prop for $ho->{Name}");
+        set_host_flag($ho, $prop) if !$dry_run;
+    } else {
+        logm("recording prop for $ho->{Name} $prop=$r{$k}");
+        set_host_property($ho, $prop, $r{$k}) if !$dry_run;
+    }
 }
ts-examine-iommu new file +31 -0
new file mode 100755
index 00000000..ae91d4d2
@@ -0,0 +1,31 @@
+#!/usr/bin/perl -w
+# This is part of "osstest", an automated testing framework for Xen.
+# Copyright (C) 2009-2020 Citrix Inc.
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+use strict qw(vars);
+BEGIN { unshift @INC, qw(.); }
+use Osstest;
+use Osstest::TestSupport;
+
+tsreadconfig();
+
+our ($whhost) = @ARGV;
+$whhost ||= 'host';
+our $ho= selecthost($whhost);
+
+our $has_iommu = !target_cmd_root_status($ho, 'xl info|grep directio', 10);
+logm("$ho->{Ident} iommu: $has_iommu");
+hostflag_putative_record($ho, "iommu") if $has_iommu;
Signature · 7 lines
2.25.0


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#1 lore raw

PATCH v2 2/2 make-flight: add dom0 PVH test

Add a dom0 PVH test, the test to be run is launching a PV guest (test-debian). Note the PVH dom0 tests are only enabled for Xen >= 4.13.

The runvar difference is:

+test-amd64-amd64-dom0pvh-xl-amd all_host_di_version 2020-02-10
+test-amd64-amd64-dom0pvh-xl-intel all_host_di_version 2020-02-10

+test-amd64-amd64-dom0pvh-xl-amd   all_host_suite      stretch
+test-amd64-amd64-dom0pvh-xl-intel all_host_suite      stretch
+test-amd64-amd64-dom0pvh-xl-amd   all_hostflags       arch-amd64,arch-xen-amd64,suite-stretch,purpose-test,hvm-amd
+test-amd64-amd64-dom0pvh-xl-intel all_hostflags       arch-amd64,arch-xen-amd64,suite-stretch,purpose-test,hvm-intel
+test-amd64-amd64-dom0pvh-xl-amd   arch                amd64
+test-amd64-amd64-dom0pvh-xl-intel arch                amd64
+test-amd64-amd64-dom0pvh-xl-amd   buildjob            build-amd64
+test-amd64-amd64-dom0pvh-xl-intel buildjob            build-amd64
+test-amd64-amd64-dom0pvh-xl-amd   debian_arch         amd64
+test-amd64-amd64-dom0pvh-xl-intel debian_arch         amd64
+test-amd64-amd64-dom0pvh-xl-amd   debian_kernkind     pvops
+test-amd64-amd64-dom0pvh-xl-intel debian_kernkind     pvops
+test-amd64-amd64-dom0pvh-xl-amd   debian_suite        stretch
+test-amd64-amd64-dom0pvh-xl-intel debian_suite        stretch
+test-amd64-amd64-dom0pvh-xl-amd   kernbuildjob        build-amd64-pvops
+test-amd64-amd64-dom0pvh-xl-intel kernbuildjob        build-amd64-pvops
+test-amd64-amd64-dom0pvh-xl-amd   kernkind            pvops
+test-amd64-amd64-dom0pvh-xl-intel kernkind            pvops
+test-amd64-amd64-dom0pvh-xl-amd   toolstack           xl
+test-amd64-amd64-dom0pvh-xl-intel toolstack           xl
+test-amd64-amd64-dom0pvh-xl-amd   xen_boot_append     dom0=pvh,verbose
+test-amd64-amd64-dom0pvh-xl-intel xen_boot_append     dom0=pvh,verbose
---
 make-flight | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)
make-flight +24 -0
index b08431dc..48f164cc 100755
@@ -753,6 +753,16 @@ test_matrix_do_one () {
   *)                test_shim=y ;;
   esac
 
+  # PVH dom0 tests for versions >= 4.13 only
+  case "$xenbranch" in
+  xen-3.*-testing)  test_dom0pvh=n ;;
+  xen-4.?-testing)  test_dom0pvh=n ;;
+  xen-4.10-testing) test_dom0pvh=n ;;
+  xen-4.11-testing) test_dom0pvh=n ;;
+  xen-4.12-testing) test_dom0pvh=n ;;
+  *)                test_dom0pvh=y ;;
+  esac
+
   # xend PV guest test on x86 only
   if [ x$test_xend = xy -a \( $dom0arch = "i386" -o $dom0arch = "amd64" \) ]; then
     job_create_test test-$xenarch$kern-$dom0arch-pv test-debian xend \
@@ -861,6 +871,20 @@ test_matrix_do_one () {
 
   fi
 
+  if [ x$test_dom0pvh = xy -a $xenarch = amd64 -a $dom0arch = amd64 ]; then
+
+    for cpuvendor in amd intel; do
+
+      job_create_test test-$xenarch$kern-$dom0arch-dom0pvh-xl-$cpuvendor \
+                test-debian xl $xenarch $dom0arch $debian_runvars \
+                all_hostflags=$most_hostflags,hvm-$cpuvendor,iommu \
+                xen_boot_append='dom0=pvh,verbose'
+
+    done
+
+  fi
+
+
   if [ x$test_shim = xy -a $xenarch = amd64 ]; then
 
     job_create_test test-$xenarch$kern-$dom0arch-xl-pvshim \
Signature · 7 lines
2.25.0


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#2 lore raw

Re: [Xen-devel] [PATCH OSSTEST v2 2/2] make-flight: add dom0 PVH test

Roger Pau Monne writes ("[PATCH OSSTEST v2 2/2] make-flight: add dom0 PVH test"):

Quoted 5 lines

Add a dom0 PVH test, the test to be run is launching a PV guest (test-debian). Note the PVH dom0 tests are only enabled for Xen >= 4.13.

The runvar difference is:

Are you sure this is still true ? It doesn't mention the iommu host flag which

make-flight test_matrix_do_one () { · line 881

Quoted 4 lines
make-flight +4 -0
+      job_create_test test-$xenarch$kern-$dom0arch-dom0pvh-xl-$cpuvendor \
+                test-debian xl $xenarch $dom0arch $debian_runvars \
+                all_hostflags=$most_hostflags,hvm-$cpuvendor,iommu \
+                xen_boot_append='dom0=pvh,verbose'

appears here. So please regenerate this.

I gave your previous version a Reviewed-by. Is this the only thing you changed ?

Ian.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#3 lore raw

Re: [Xen-devel] [PATCH OSSTEST v2 2/2] make-flight: add dom0 PVH test

Quoted 9 lines · Ian Jackson

Roger Pau Monne writes ("[PATCH OSSTEST v2 2/2] make-flight: add dom0 PVH test"):

Quoted 5 lines

Add a dom0 PVH test, the test to be run is launching a PV guest (test-debian). Note the PVH dom0 tests are only enabled for Xen >= 4.13.

The runvar difference is:

Are you sure this is still true ? It doesn't mention the iommu host flag which

Updated it on v3.

Quoted 9 lines

make-flight test_matrix_do_one () { · line 881

Quoted 4 lines
make-flight +4 -0
+      job_create_test test-$xenarch$kern-$dom0arch-dom0pvh-xl-$cpuvendor \
+                test-debian xl $xenarch $dom0arch $debian_runvars \
+                all_hostflags=$most_hostflags,hvm-$cpuvendor,iommu \
+                xen_boot_append='dom0=pvh,verbose'

appears here. So please regenerate this.

I gave your previous version a Reviewed-by. Is this the only thing you changed ?

Yes.

Thanks, Roger.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#4 lore raw
In reply to Roger Pau Monne

Roger Pau Monne writes ("[PATCH OSSTEST v2 1/2] examine: detect IOMMU availability and add it as a hostflag"):

Quoted 2 lines

Introduce a new test to check for iommu availability and add it as a hostflag if found.

Thanks.

Quoted 1 line

+sub set_flag($$$) {

Firstly, can you break this new code out into its own patch ?

Quoted 1 line

+ my ($hd, $ho, $flag) = @_;

Secondly, this doesn't take a booleanish for yes/no. I think it should. Ie, it should be capable of both setting and clearing. I think leaving that functionality out now is too close to Extreme Programming for my taste, even for osstest :-).

Osstest/HostDB/Executive.pm END · line 104

Quoted 10 lines
Osstest/HostDB/Executive.pm +10 -0
+    my $rmq = $dbh_tests->prepare(<<END);
+        DELETE FROM hostflags WHERE hostname=? AND hostflag=?
+END
+    my $addq = $dbh_tests->prepare(<<END);
+        INSERT INTO hostflags (hostname,hostflag) VALUES (?,?)
+END
+    my $blessing = intended_blessing();
+
+    die "Attempting to modify host flags with intended blessing $blessing != real"
+        if $blessing ne "real";

Much of this code is identical to that in set_property. I think maybe you could introduce

   sub modify_host ($$$) {
       my ($hd, $ho, $fn) = @_;

which contains the call to intended_blessing and passes its $fn argument to db_retry ?

Quoted 1 line

+++ b/Osstest/HostDB/Static.pm

...

Osstest/HostDB/Static.pm sub get_flags ($$) { #method · line 79

Quoted 5 lines
Osstest/HostDB/Static.pm +5 -0
+sub set_property($$$) {
+    my ($hd, $ho, $flag) = @_;
+
+    die "Cannot set flags in standalone mode for $ho->{Name} $flag\n";
+}

I considered whether this meant that modify_host ought to be part of some base class but $rmq etc. would need setting up and plumbing through so that seems both too annoying and to make things too abstract. But if you think you can and would like to, please do...

Quoted 7 lines
ts-examine-iommu new file +1 -0
new file mode 100755
index 00000000..ae91d4d2
@@ -0,0 +1,31 @@
+#!/usr/bin/perl -w

...

Quoted 1 line

+our $has_iommu = !target_cmd_root_status($ho, 'xl info|grep directio', 10);

Please fetch the output of xl info and do the grepping in perl.

The way you do it here will miss a situation where xl info fails completely, which ought to be fatal, not treated as "no iommu".

Apart from these things, the code all LGTM.

Thanks,
Ian.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#5 lore raw
Quoted 9 lines · Ian Jackson

Roger Pau Monne writes ("[PATCH OSSTEST v2 1/2] examine: detect IOMMU availability and add it as a hostflag"):

Quoted 2 lines

Introduce a new test to check for iommu availability and add it as a hostflag if found.

Thanks.

Quoted 1 line

+sub set_flag($$$) {

Firstly, can you break this new code out into its own patch ?

Can do, but then there will be no user of the introduced code which I tend to avoid.

Quoted 21 lines
Quoted 1 line

+ my ($hd, $ho, $flag) = @_;

Secondly, this doesn't take a booleanish for yes/no. I think it should. Ie, it should be capable of both setting and clearing. I think leaving that functionality out now is too close to Extreme Programming for my taste, even for osstest :-).

Osstest/HostDB/Executive.pm END · line 104

Quoted 10 lines
Osstest/HostDB/Executive.pm +10 -0
+    my $rmq = $dbh_tests->prepare(<<END);
+        DELETE FROM hostflags WHERE hostname=? AND hostflag=?
+END
+    my $addq = $dbh_tests->prepare(<<END);
+        INSERT INTO hostflags (hostname,hostflag) VALUES (?,?)
+END
+    my $blessing = intended_blessing();
+
+    die "Attempting to modify host flags with intended blessing $blessing != real"
+        if $blessing ne "real";

Much of this code is identical to that in set_property. I think maybe you could introduce

Quoted 5 lines
   sub modify_host ($$$) {
       my ($hd, $ho, $fn) = @_;

which contains the call to intended_blessing and passes its $fn argument to db_retry ?

Ack.

Quoted 22 lines
Quoted 2 lines

+++ b/Osstest/HostDB/Static.pm

...

Osstest/HostDB/Static.pm sub get_flags ($$) { #method · line 79

Quoted 5 lines
Osstest/HostDB/Static.pm +5 -0
+sub set_property($$$) {
+    my ($hd, $ho, $flag) = @_;
+
+    die "Cannot set flags in standalone mode for $ho->{Name} $flag\n";
+}

I considered whether this meant that modify_host ought to be part of some base class but $rmq etc. would need setting up and plumbing through so that seems both too annoying and to make things too abstract. But if you think you can and would like to, please do...

Quoted 7 lines
ts-examine-iommu new file +1 -0
new file mode 100755
index 00000000..ae91d4d2
@@ -0,0 +1,31 @@
+#!/usr/bin/perl -w

...

Quoted 6 lines
Quoted 1 line

+our $has_iommu = !target_cmd_root_status($ho, 'xl info|grep directio', 10);

Please fetch the output of xl info and do the grepping in perl.

The way you do it here will miss a situation where xl info fails completely, which ought to be fatal, not treated as "no iommu".

Sure.

Quoted 1 line

Apart from these things, the code all LGTM.

Thanks, Roger.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#6 lore raw

Roger Pau Monne writes ("Re: [PATCH OSSTEST v2 1/2] examine: detect IOMMU availability and add it as a hostflag"):

Quoted 5 lines · Ian Jackson
Quoted 1 line

Firstly, can you break this new code out into its own patch ?

Can do, but then there will be no user of the introduced code which I tend to avoid.

I prefer that to the alternative of mixing it up.

Quoted 1 line

[rest snipped]

OK, good.

Thanks,
Ian.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel