KVM Archive on lore.kernel.org
 help / color / Atom feed
From: Janosch Frank <frankja@linux.ibm.com>
To: kvm@vger.kernel.org
Cc: linux-s390@vger.kernel.org, thuth@redhat.com, david@redhat.com,
	imbrenda@linux.ibm.com
Subject: [kvm-unit-tests PATCH 4/6] s390x: Test for share/unshare call support before using them
Date: Tue, 16 Mar 2021 09:16:52 +0000
Message-ID: <20210316091654.1646-5-frankja@linux.ibm.com> (raw)
In-Reply-To: <20210316091654.1646-1-frankja@linux.ibm.com>

Testing for facility only means the UV Call facility is available.
The UV will only indicate the share/unshare calls for a protected
guest 2, so let's also check that.

Signed-off-by: Janosch Frank <frankja@linux.ibm.com>
---
 lib/s390x/malloc_io.c | 5 +++--
 s390x/uv-guest.c      | 6 ++++++
 2 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/lib/s390x/malloc_io.c b/lib/s390x/malloc_io.c
index 1dcf1691..78582eac 100644
--- a/lib/s390x/malloc_io.c
+++ b/lib/s390x/malloc_io.c
@@ -19,6 +19,7 @@
 #include <alloc_page.h>
 #include <asm/facility.h>
 #include <bitops.h>
+#include <uv.h>
 
 static int share_pages(void *p, int count)
 {
@@ -47,7 +48,7 @@ void *alloc_io_mem(int size, int flags)
 	assert(size);
 
 	p = alloc_pages_flags(order, AREA_DMA31 | flags);
-	if (!p || !test_facility(158))
+	if (!p || !uv_os_is_guest())
 		return p;
 
 	n = share_pages(p, 1 << order);
@@ -65,7 +66,7 @@ void free_io_mem(void *p, int size)
 
 	assert(IS_ALIGNED((uintptr_t)p, PAGE_SIZE));
 
-	if (test_facility(158))
+	if (uv_os_is_guest())
 		unshare_pages(p, 1 << order);
 	free_pages(p);
 }
diff --git a/s390x/uv-guest.c b/s390x/uv-guest.c
index 95a968c5..8915b2f1 100644
--- a/s390x/uv-guest.c
+++ b/s390x/uv-guest.c
@@ -16,6 +16,7 @@
 #include <asm/facility.h>
 #include <asm/uv.h>
 #include <sclp.h>
+#include <uv.h>
 
 static unsigned long page;
 
@@ -141,6 +142,11 @@ int main(void)
 		goto done;
 	}
 
+	if (!uv_os_is_guest()) {
+		report_skip("Not a protected guest");
+		goto done;
+	}
+
 	page = (unsigned long)alloc_page();
 	test_priv();
 	test_invalid();
-- 
2.27.0


  parent reply index

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-16  9:16 [kvm-unit-tests PATCH 0/6] s390x: uv: Extend guest test and add host test Janosch Frank
2021-03-16  9:16 ` [kvm-unit-tests PATCH 1/6] s390x: uv-guest: Add invalid share location test Janosch Frank
2021-04-19 11:24   ` Thomas Huth
2021-04-19 11:45     ` Janosch Frank
2021-04-20  8:48       ` Thomas Huth
2021-04-20 13:40   ` Claudio Imbrenda
2021-04-21 11:04   ` Cornelia Huck
2021-03-16  9:16 ` [kvm-unit-tests PATCH 2/6] s390x: Add more Ultravisor command structure definitions Janosch Frank
2021-04-20 14:09   ` Claudio Imbrenda
2021-04-21 11:13   ` Cornelia Huck
2021-04-26 14:33     ` Janosch Frank
2021-03-16  9:16 ` [kvm-unit-tests PATCH 3/6] s390x: uv: Add UV lib Janosch Frank
2021-04-20 14:15   ` Claudio Imbrenda
2021-04-26 14:20     ` Janosch Frank
2021-03-16  9:16 ` Janosch Frank [this message]
2021-04-20 14:18   ` [kvm-unit-tests PATCH 4/6] s390x: Test for share/unshare call support before using them Claudio Imbrenda
2021-03-16  9:16 ` [kvm-unit-tests PATCH 5/6] s390x: uv-guest: Test invalid commands Janosch Frank
2021-04-20 14:26   ` Claudio Imbrenda
2021-04-26 13:40     ` Janosch Frank
2021-03-16  9:16 ` [kvm-unit-tests PATCH 6/6] s390x: Add UV host test Janosch Frank
2021-04-20 15:47   ` Claudio Imbrenda
2021-04-26 14:31     ` Janosch Frank
2021-04-19  7:24 ` [kvm-unit-tests PATCH 0/6] s390x: uv: Extend guest test and add " Janosch Frank

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=20210316091654.1646-5-frankja@linux.ibm.com \
    --to=frankja@linux.ibm.com \
    --cc=david@redhat.com \
    --cc=imbrenda@linux.ibm.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-s390@vger.kernel.org \
    --cc=thuth@redhat.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

KVM Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/kvm/0 kvm/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 kvm kvm/ https://lore.kernel.org/kvm \
		kvm@vger.kernel.org
	public-inbox-index kvm

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.kvm


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git