kvm: s390: Changes for 6.5
Janosch Frank
maintainerDear Paolo,
here are the patches for 6.5 (or later):
~80% of the code is a new CMM selftest by Nico.
~19% of the code is Steffen's additions to the uvdevice introducing the UV secret API. The rest are a couple of fixes that we picked up along the way.
I plan to remove the ifdefs and the PROTECTED_VIRTUALIZATION_GUEST config in the (near) future so we won't run into the linking problems that plagued the uvdevice patches anymore.
Please pull:
The following changes since commit f1fcbaa18b28dec10281551dfe6ed3a3ed80e3d6:
Linux 6.4-rc2 (2023-05-14 12:51:40 -0700)
are available in the Git repository at:
https://git.kernel.org/pub/scm/linux/kernel/git/kvms390/linux.git tags/kvm-s390-next-6.5-1
for you to fetch changes up to db54dfc9f71cd2df7afd1e88535ef6099cb0333e:
s390/uv: Update query for secret-UVCs (2023-06-16 11:08:09 +0200)
----------------------------------------------------------------
* New uvdevice secret API
* New CMM selftest
* cmm fix
* diag 9c racy access of target cpu fix
* VSIE AP control block fix
----------------------------------------------------------------
Christian Borntraeger (1):
KVM: s390/diag: fix racy access of physical cpu number in diag 9c
handler
Nico Boehr (2):
KVM: s390: fix KVM_S390_GET_CMMA_BITS for GFNs in memslot holes
KVM: s390: selftests: add selftest for CMMA migration
Pierre Morel (1):
KVM: s390: vsie: fix the length of APCB bitmap
Steffen Eiden (7):
s390/uv: Always export uv_info
s390/uvdevice: Add info IOCTL
s390/uvdevice: Add 'Add Secret' UVC
s390/uvdevice: Add 'List Secrets' UVC
s390/uvdevice: Add 'Lock Secret Store' UVC
s390/uv: replace scnprintf with sysfs_emit
s390/uv: Update query for secret-UVCs
arch/s390/boot/uv.c | 4 + arch/s390/include/asm/uv.h | 32 +- arch/s390/include/uapi/asm/uvdevice.h | 53 +- arch/s390/kernel/uv.c | 108 ++- arch/s390/kvm/diag.c | 8 +- arch/s390/kvm/kvm-s390.c | 4 + arch/s390/kvm/vsie.c | 6 +- drivers/s390/char/Kconfig | 2 +- drivers/s390/char/uvdevice.c | 231 +++++- tools/testing/selftests/kvm/Makefile | 1 + tools/testing/selftests/kvm/s390x/cmma_test.c | 700 ++++++++++++++++++ 11 files changed, 1100 insertions(+), 49 deletions(-) create mode 100644 tools/testing/selftests/kvm/s390x/cmma_test.c
Signature · 1 line
2.41.0
Janosch Frank
maintainer[GIT PULL 04/11] KVM: s390/diag: fix racy access of physical cpu number in diag 9c handler
From: Christian Borntraeger <[email protected]>
We do check for target CPU == -1, but this might change at the time we are going to use it. Hold the physical target CPU in a local variable to avoid out-of-bound accesses to the cpu arrays.
--- arch/s390/kvm/diag.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
arch/s390/kvm/diag.c +5 -3
@@ -166,6 +166,7 @@ static int diag9c_forwarding_overrun(void)static int __diag_time_slice_end_directed (struct kvm_vcpu *vcpu) {struct kvm_vcpu *tcpu; +int tcpu_cpu;int tid; tid = vcpu->run->s.regs.gprs[(vcpu->arch.sie_block->ipa &0xf0 ) >>4 ];
@@ -181,14 +182,15 @@ static int __diag_time_slice_end_directed(struct kvm_vcpu *vcpu) goto no_yield;/* target guest VCPU already running */ -if (READ_ONCE (tcpu->cpu) >=0 ) { + tcpu_cpu =READ_ONCE (tcpu->cpu); +if (tcpu_cpu >=0 ) {if (!diag9c_forwarding_hz ||diag9c_forwarding_overrun ()) goto no_yield;/* target host CPU already running */ -if (!vcpu_is_preempted (tcpu->cpu)) +if (!vcpu_is_preempted (tcpu_cpu)) goto no_yield; -smp_yield_cpu (tcpu->cpu); +smp_yield_cpu (tcpu_cpu);VCPU_EVENT (vcpu,5 ,"diag time slice end directed to %d: yield forwarded" , tid);
Signature · 1 line
2.41.0
Janosch Frank
maintainer[GIT PULL 01/11] KVM: s390: fix KVM_S390_GET_CMMA_BITS for GFNs in memslot holes
In reply to Janosch FrankFrom: Nico Boehr <[email protected]>
The KVM_S390_GET_CMMA_BITS ioctl may return incorrect values when userspace specifies a start_gfn outside of memslots.
This can occur when a VM has multiple memslots with a hole in between:
+-----+----------+--------+--------+
| ... | Slot N-1 | <hole> | Slot N |
+-----+----------+--------+--------+
^ ^ ^ ^
| | | |
GFN A A+B | |
A+B+C |
A+B+C+DWhen userspace specifies a GFN in [A+B, A+B+C), it would expect to get the CMMA values of the first dirty page in Slot N. However, userspace may get a start_gfn of A+B+C+D with a count of 0, hence completely skipping over any dirty pages in slot N.
The error is in kvm_s390_next_dirty_cmma(), which assumes gfn_to_memslot_approx() will return the memslot _below_ the specified GFN when the specified GFN lies outside a memslot. In reality it may return either the memslot below or above the specified GFN.
When a memslot above the specified GFN is returned this happens:
- ofs is calculated, but since the memslot's base_gfn is larger than the specified cur_gfn, ofs will underflow to a huge number.
- ofs is passed to find_next_bit(). Since ofs will exceed the memslot's number of pages, the number of pages in the memslot is returned, completely skipping over all bits in the memslot userspace would be interested in.
Fix this by resetting ofs to zero when a memslot _above_ cur_gfn is returned (cur_gfn < ms->base_gfn).
Message-Id: <[email protected]>
--- arch/s390/kvm/kvm-s390.c | 4 ++++ 1 file changed, 4 insertions(+)
arch/s390/kvm/kvm-s390.c +4 -0
@@ -2156,6 +2156,10 @@ static unsigned long kvm_s390_next_dirty_cmma(struct kvm_memslots *slots, ms = container_of(mnode, struct kvm_memory_slot, gfn_node[slots->node_idx]); ofs =0 ; } + +if (cur_gfn < ms->base_gfn) + ofs =0 ; + ofs =find_next_bit (kvm_second_dirty_bitmap (ms), ms->npages, ofs);while (ofs >= ms->npages && (mnode =rb_next (mnode))) { ms = container_of(mnode, struct kvm_memory_slot, gfn_node[slots->node_idx]);
Signature · 1 line
2.41.0
Janosch Frank
maintainer[GIT PULL 03/11] KVM: s390: vsie: fix the length of APCB bitmap
In reply to Janosch FrankFrom: Pierre Morel <[email protected]>
bit_and() uses the count of bits as the woking length. Fix the previous implementation and effectively use the right bitmap size.
--- arch/s390/kvm/vsie.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
arch/s390/kvm/vsie.c +4 -2
@@ -177,7 +177,8 @@ static int setup_apcb00(struct kvm_vcpu *vcpu, unsigned long *apcb_s, sizeof(struct kvm_s390_apcb0)))return -EFAULT ; -bitmap_and (apcb_s, apcb_s, apcb_h,sizeof (struct kvm_s390_apcb0 )); +bitmap_and (apcb_s, apcb_s, apcb_h, +BITS_PER_BYTE *sizeof (struct kvm_s390_apcb0 ));return 0 ; }
@@ -203,7 +204,8 @@ static int setup_apcb11(struct kvm_vcpu *vcpu, unsigned long *apcb_s, sizeof(struct kvm_s390_apcb1)))return -EFAULT ; -bitmap_and (apcb_s, apcb_s, apcb_h,sizeof (struct kvm_s390_apcb1 )); +bitmap_and (apcb_s, apcb_s, apcb_h, +BITS_PER_BYTE *sizeof (struct kvm_s390_apcb1 ));return 0 ; }
Signature · 1 line
2.41.0
Janosch Frank
maintainer[GIT PULL 08/11] s390/uvdevice: Add 'List Secrets' UVC
In reply to Janosch FrankFrom: Steffen Eiden <[email protected]>
Userspace can call the List Secrets Ultravisor Call using IOCTLs on the uvdevice. The List Secrets UV call lists the identifier of the secrets in the UV secret store.
The uvdevice is merely transporting the request from userspace to Ultravisor. It's neither checking nor manipulating the request or response data.
Message-Id: <[email protected]>
--- arch/s390/include/asm/uv.h | 3 ++ arch/s390/include/uapi/asm/uvdevice.h | 4 +++ drivers/s390/char/uvdevice.c | 52 +++++++++++++++++++++++++++ 3 files changed, 59 insertions(+)
arch/s390/include/asm/uv.h +3 -0
@@ -59,6 +59,7 @@#define UVC_CMD_REMOVE_SHARED_ACCESS 0x1001#define UVC_CMD_RETR_ATTEST 0x1020#define UVC_CMD_ADD_SECRET 0x1031 +#define UVC_CMD_LIST_SECRETS 0x1033/* Bits in installed uv calls */ enum uv_cmds_inst {
@@ -90,6 +91,7 @@ enum uv_cmds_inst {BIT_UVC_CMD_DUMP_COMPLETE =27 ,BIT_UVC_CMD_RETR_ATTEST =28 ,BIT_UVC_CMD_ADD_SECRET =29 , + BIT_UVC_CMD_LIST_SECRETS = 30, }; enum uv_feat_ind {
@@ -298,6 +300,7 @@ struct uv_cb_dump_complete {* A common UV call struct for pv guests that contains a single address * Examples: * Add Secret +* List Secrets */ struct uv_cb_guest_addr {struct uv_cb_header header;
arch/s390/include/uapi/asm/uvdevice.h +4 -0
@@ -70,6 +70,7 @@ struct uvio_uvdev_info {#define UVIO_ATT_MEASUREMENT_MAX_LEN 0x8000#define UVIO_ATT_ADDITIONAL_MAX_LEN 0x8000#define UVIO_ADD_SECRET_MAX_LEN 0x100000 +#define UVIO_LIST_SECRETS_LEN 0x1000#define UVIO_DEVICE_NAME "uv"#define UVIO_TYPE_UVC 'u'
@@ -78,6 +79,7 @@ enum UVIO_IOCTL_NR {UVIO_IOCTL_UVDEV_INFO_NR =0x00 ,UVIO_IOCTL_ATT_NR ,UVIO_IOCTL_ADD_SECRET_NR , +UVIO_IOCTL_LIST_SECRETS_NR ,/* must be the last entry */ UVIO_IOCTL_NUM_IOCTLS };
@@ -86,10 +88,12 @@ enum UVIO_IOCTL_NR {#define UVIO_IOCTL_UVDEV_INFO UVIO_IOCTL(UVIO_IOCTL_UVDEV_INFO_NR)#define UVIO_IOCTL_ATT UVIO_IOCTL(UVIO_IOCTL_ATT_NR)#define UVIO_IOCTL_ADD_SECRET UVIO_IOCTL(UVIO_IOCTL_ADD_SECRET_NR) +#define UVIO_IOCTL_LIST_SECRETS UVIO_IOCTL(UVIO_IOCTL_LIST_SECRETS_NR)#define UVIO_SUPP_CALL (nr) (1ULL << (nr))#define UVIO_SUPP_UDEV_INFO UVIO_SUPP_CALL(UVIO_IOCTL_UDEV_INFO_NR)#define UVIO_SUPP_ATT UVIO_SUPP_CALL(UVIO_IOCTL_ATT_NR)#define UVIO_SUPP_ADD_SECRET UVIO_SUPP_CALL(UVIO_IOCTL_ADD_SECRET_NR) +#define UVIO_SUPP_LIST_SECRETS UVIO_SUPP_CALL(UVIO_IOCTL_LIST_SECRETS_NR)#endif /* __S390_ASM_UVDEVICE_H */
drivers/s390/char/uvdevice.c +52 -0
70 lines not on this page · raw message
Signature · 1 line
2.41.0
Janosch Frank
maintainer[GIT PULL 11/11] s390/uv: Update query for secret-UVCs
In reply to Janosch FrankFrom: Steffen Eiden <[email protected]>
Update the query struct such that secret-UVC related information can be parsed.
Add sysfs files for these new values.
'supp_add_secret_req_ver' notes the supported versions for the Add Secret UVC. Bit 0 indicates that version 0x100 is supported, bit 1 indicates 0x200, and so on.
'supp_add_secret_pcf' notes the supported plaintext flags for the Add Secret UVC.
'supp_secret_types' notes the supported types of secrets. Bit 0 indicates secret type 1, bit 1 indicates type 2, and so on.
'max_secrets' notes the maximum amount of secrets the secret store can store per pv guest.
Message-Id: <[email protected]>
--- arch/s390/boot/uv.c | 4 ++++ arch/s390/include/asm/uv.h | 13 +++++++++++-- arch/s390/kernel/uv.c | 40 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 55 insertions(+), 2 deletions(-)
arch/s390/boot/uv.c +4 -0
@@ -47,6 +47,10 @@ void uv_query_info(void) uv_info.conf_dump_finalize_len = uvcb.conf_dump_finalize_len; uv_info.supp_att_req_hdr_ver = uvcb.supp_att_req_hdr_ver; uv_info.supp_att_pflags = uvcb.supp_att_pflags; + uv_info.supp_add_secret_req_ver = uvcb.supp_add_secret_req_ver; + uv_info.supp_add_secret_pcf = uvcb.supp_add_secret_pcf; + uv_info.supp_secret_types = uvcb.supp_secret_types; + uv_info.max_secrets = uvcb.max_secrets; }#ifdef CONFIG_PROTECTED_VIRTUALIZATION_GUEST
arch/s390/include/asm/uv.h +11 -2
@@ -123,7 +123,7 @@ struct uv_cb_qui {u32 reserved70[3 ];/* 0x0070 */ u32 max_num_sec_conf;/* 0x007c */ u64 max_guest_stor_addr;/* 0x0080 */ -u8 reserved88[158 -136 ];/* 0x0088 */ +u8 reserved88[0x9e -0x88 ];/* 0x0088 */ u16 max_guest_cpu_id;/* 0x009e */ u64 uv_feature_indications;/* 0x00a0 */ u64 reserveda8;/* 0x00a8 */
@@ -135,7 +135,12 @@ struct uv_cb_qui {u64 reservedd8;/* 0x00d8 */ u64 supp_att_req_hdr_ver;/* 0x00e0 */ u64 supp_att_pflags;/* 0x00e8 */ -u8 reservedf0[256 -240 ];/* 0x00f0 */ +u64 reservedf0;/* 0x00f0 */ +u64 supp_add_secret_req_ver;/* 0x00f8 */ +u64 supp_add_secret_pcf;/* 0x0100 */ +u64 supp_secret_types;/* 0x0180 */ +u16 max_secrets;/* 0x0110 */ +u8 reserved112[0x120 -0x112 ];/* 0x0112 */ } __packed__aligned(8) ;/* Initialize Ultravisor */
@@ -384,6 +389,10 @@ struct uv_info {unsigned long conf_dump_finalize_len;unsigned long supp_att_req_hdr_ver;unsigned long supp_att_pflags; +unsigned long supp_add_secret_req_ver; +unsigned long supp_add_secret_pcf; +unsigned long supp_secret_types; +unsigned short max_secrets; };extern struct uv_info uv_info;
arch/s390/kernel/uv.c +40 -0
@@ -579,6 +579,42 @@ static ssize_t uv_query_supp_att_pflags(struct kobject *kobj,static struct kobj_attribute uv_query_supp_att_pflags_attr =__ATTR (supp_att_pflags,0444 , uv_query_supp_att_pflags,NULL ); +static ssize_t uv_query_supp_add_secret_req_ver (struct kobject *kobj, +struct kobj_attribute *attr,char *buf) +{ +return sysfs_emit (buf,"%lx\n" , uv_info.supp_add_secret_req_ver); +} + +static struct kobj_attribute uv_query_supp_add_secret_req_ver_attr = +__ATTR (supp_add_secret_req_ver,0444 , uv_query_supp_add_secret_req_ver,NULL ); + +static ssize_t uv_query_supp_add_secret_pcf (struct kobject *kobj, +struct kobj_attribute *attr,char *buf) +{ +return sysfs_emit (buf,"%lx\n" , uv_info.supp_add_secret_pcf); +} + +static struct kobj_attribute uv_query_supp_add_secret_pcf_attr = +__ATTR (supp_add_secret_pcf,0444 , uv_query_supp_add_secret_pcf,NULL ); + +static ssize_t uv_query_supp_secret_types (struct kobject *kobj, +struct kobj_attribute *attr,char *buf) +{ +return sysfs_emit (buf,"%lx\n" , uv_info.supp_secret_types); +} + +static struct kobj_attribute uv_query_supp_secret_types_attr = +__ATTR (supp_secret_types,0444 , uv_query_supp_secret_types,NULL ); + +static ssize_t uv_query_max_secrets (struct kobject *kobj, +struct kobj_attribute *attr,char *buf) +{ +return sysfs_emit (buf,"%d\n" , uv_info.max_secrets); +} + +static struct kobj_attribute uv_query_max_secrets_attr = +__ATTR (max_secrets,0444 , uv_query_max_secrets,NULL ); +static struct attribute *uv_query_attrs[] = { &uv_query_facilities_attr.attr, &uv_query_feature_indications_attr.attr,
@@ -592,6 +628,10 @@ static struct attribute *uv_query_attrs[] = { &uv_query_dump_cpu_len_attr.attr, &uv_query_supp_att_req_hdr_ver_attr.attr, &uv_query_supp_att_pflags_attr.attr, + &uv_query_supp_add_secret_req_ver_attr.attr, + &uv_query_supp_add_secret_pcf_attr.attr, + &uv_query_supp_secret_types_attr.attr, + &uv_query_max_secrets_attr.attr, NULL, };
Signature · 1 line
2.41.0
Janosch Frank
maintainer[GIT PULL 02/11] KVM: s390: selftests: add selftest for CMMA migration
In reply to Janosch FrankFrom: Nico Boehr <[email protected]>
Add a selftest for CMMA migration on s390.
The tests cover:
- interaction of dirty tracking and migration mode, see my recent patch "KVM: s390: disable migration mode when dirty tracking is disabled" [1],
- several invalid calls of KVM_S390_GET_CMMA_BITS, for example: invalid flags, CMMA support off, with/without peeking
- ensure KVM_S390_GET_CMMA_BITS initally reports all pages as dirty,
- ensure KVM_S390_GET_CMMA_BITS properly skips over holes in memslots, but also non-dirty pages
Note that without the patch at [1] and the small fix in this series, the selftests will fail.
[1] https://lore.kernel.org/all/[email protected]/
Message-Id: <[email protected]>
[[email protected]: squashed [email protected] / "KVM: s390: selftests:
CMMA: don't run if CMMA not supported"]
--- tools/testing/selftests/kvm/Makefile | 1 + tools/testing/selftests/kvm/s390x/cmma_test.c | 700 ++++++++++++++++++ 2 files changed, 701 insertions(+) create mode 100644 tools/testing/selftests/kvm/s390x/cmma_test.c
tools/testing/selftests/kvm/Makefile +1 -0
@@ -163,6 +163,7 @@ TEST_GEN_PROGS_s390x = s390x/memop TEST_GEN_PROGS_s390x += s390x/resets TEST_GEN_PROGS_s390x += s390x/sync_regs_test TEST_GEN_PROGS_s390x += s390x/tprot +TEST_GEN_PROGS_s390x += s390x/cmma_test TEST_GEN_PROGS_s390x += demand_paging_test TEST_GEN_PROGS_s390x += dirty_log_test TEST_GEN_PROGS_s390x += kvm_create_max_vcpus
tools/testing/selftests/kvm/s390x/cmma_test.c new file +700 -0
700 lines not on this page · raw message
Signature · 1 line
2.41.0
Janosch Frank
maintainer[GIT PULL 10/11] s390/uv: replace scnprintf with sysfs_emit
In reply to Janosch FrankFrom: Steffen Eiden <[email protected]>
Replace scnprintf(page, PAGE_SIZE, ...) with the page size aware sysfs_emit(buf, ...) which adds some sanity checks.
Message-Id: <[email protected]>
--- arch/s390/kernel/uv.c | 58 +++++++++++++++++++------------------------ 1 file changed, 26 insertions(+), 32 deletions(-)
arch/s390/kernel/uv.c +26 -32
@@ -468,13 +468,13 @@ EXPORT_SYMBOL_GPL(arch_make_page_accessible);#if defined(CONFIG_PROTECTED_VIRTUALIZATION_GUEST ) ||IS_ENABLED (CONFIG_KVM )static ssize_t uv_query_facilities (struct kobject *kobj, -struct kobj_attribute *attr,char *page) +struct kobj_attribute *attr,char *buf) { -return scnprintf (page,PAGE_SIZE ,"%lx\n%lx\n%lx\n%lx\n" , - uv_info.inst_calls_list[0 ], - uv_info.inst_calls_list[1 ], - uv_info.inst_calls_list[2 ], - uv_info.inst_calls_list[3 ]); +return sysfs_emit (buf,"%lx\n%lx\n%lx\n%lx\n" , + uv_info.inst_calls_list[0 ], + uv_info.inst_calls_list[1 ], + uv_info.inst_calls_list[2 ], + uv_info.inst_calls_list[3 ]); } static struct kobj_attribute uv_query_facilities_attr =
@@ -499,30 +499,27 @@ static struct kobj_attribute uv_query_supp_se_hdr_pcf_attr =__ATTR (supp_se_hdr_pcf,0444 , uv_query_supp_se_hdr_pcf,NULL );static ssize_t uv_query_dump_cpu_len (struct kobject *kobj, -struct kobj_attribute *attr,char *page) +struct kobj_attribute *attr,char *buf) { -return scnprintf (page,PAGE_SIZE ,"%lx\n" , - uv_info.guest_cpu_stor_len); +return sysfs_emit (buf,"%lx\n" , uv_info.guest_cpu_stor_len); }static struct kobj_attribute uv_query_dump_cpu_len_attr =__ATTR (uv_query_dump_cpu_len,0444 , uv_query_dump_cpu_len,NULL );static ssize_t uv_query_dump_storage_state_len (struct kobject *kobj, -struct kobj_attribute *attr,char *page) +struct kobj_attribute *attr,char *buf) { -return scnprintf (page,PAGE_SIZE ,"%lx\n" , - uv_info.conf_dump_storage_state_len); +return sysfs_emit (buf,"%lx\n" , uv_info.conf_dump_storage_state_len); }static struct kobj_attribute uv_query_dump_storage_state_len_attr =__ATTR (dump_storage_state_len,0444 , uv_query_dump_storage_state_len,NULL );static ssize_t uv_query_dump_finalize_len (struct kobject *kobj, -struct kobj_attribute *attr,char *page) +struct kobj_attribute *attr,char *buf) { -return scnprintf (page,PAGE_SIZE ,"%lx\n" , - uv_info.conf_dump_finalize_len); +return sysfs_emit (buf,"%lx\n" , uv_info.conf_dump_finalize_len); } static struct kobj_attribute uv_query_dump_finalize_len_attr =
@@ -538,48 +535,45 @@ static struct kobj_attribute uv_query_feature_indications_attr =__ATTR (feature_indications,0444 , uv_query_feature_indications,NULL );static ssize_t uv_query_max_guest_cpus (struct kobject *kobj, -struct kobj_attribute *attr,char *page) +struct kobj_attribute *attr,char *buf) { -return scnprintf (page,PAGE_SIZE ,"%d\n" , - uv_info.max_guest_cpu_id +1 ); +return sysfs_emit (buf,"%d\n" , uv_info.max_guest_cpu_id +1 ); }static struct kobj_attribute uv_query_max_guest_cpus_attr =__ATTR (max_cpus,0444 , uv_query_max_guest_cpus,NULL );static ssize_t uv_query_max_guest_vms (struct kobject *kobj, -struct kobj_attribute *attr,char *page) +struct kobj_attribute *attr,char *buf) { -return scnprintf (page,PAGE_SIZE ,"%d\n" , - uv_info.max_num_sec_conf); +return sysfs_emit (buf,"%d\n" , uv_info.max_num_sec_conf); }static struct kobj_attribute uv_query_max_guest_vms_attr =__ATTR (max_guests,0444 , uv_query_max_guest_vms,NULL );static ssize_t uv_query_max_guest_addr (struct kobject *kobj, -struct kobj_attribute *attr,char *page) +struct kobj_attribute *attr,char *buf) { -return scnprintf (page,PAGE_SIZE ,"%lx\n" , - uv_info.max_sec_stor_addr); +return sysfs_emit (buf,"%lx\n" , uv_info.max_sec_stor_addr); }static struct kobj_attribute uv_query_max_guest_addr_attr =__ATTR (max_address,0444 , uv_query_max_guest_addr,NULL );static ssize_t uv_query_supp_att_req_hdr_ver (struct kobject *kobj, -struct kobj_attribute *attr,char *page) +struct kobj_attribute *attr,char *buf) { -return scnprintf (page,PAGE_SIZE ,"%lx\n" , uv_info.supp_att_req_hdr_ver); +return sysfs_emit (buf,"%lx\n" , uv_info.supp_att_req_hdr_ver); }static struct kobj_attribute uv_query_supp_att_req_hdr_ver_attr =__ATTR (supp_att_req_hdr_ver,0444 , uv_query_supp_att_req_hdr_ver,NULL );static ssize_t uv_query_supp_att_pflags (struct kobject *kobj, -struct kobj_attribute *attr,char *page) +struct kobj_attribute *attr,char *buf) { -return scnprintf (page,PAGE_SIZE ,"%lx\n" , uv_info.supp_att_pflags); +return sysfs_emit (buf,"%lx\n" , uv_info.supp_att_pflags); } static struct kobj_attribute uv_query_supp_att_pflags_attr =
@@ -606,18 +600,18 @@ static struct attribute_group uv_query_attr_group = { };static ssize_t uv_is_prot_virt_guest (struct kobject *kobj, -struct kobj_attribute *attr,char *page) +struct kobj_attribute *attr,char *buf) {int val =0 ;#ifdef CONFIG_PROTECTED_VIRTUALIZATION_GUEST val = prot_virt_guest;#endif -return scnprintf (page,PAGE_SIZE ,"%d\n" , val); +return sysfs_emit (buf,"%d\n" , val); }static ssize_t uv_is_prot_virt_host (struct kobject *kobj, -struct kobj_attribute *attr,char *page) +struct kobj_attribute *attr,char *buf) {int val =0 ;
@@ -625,7 +619,7 @@ static ssize_t uv_is_prot_virt_host(struct kobject *kobj, val = prot_virt_host;#endif -return scnprintf (page,PAGE_SIZE ,"%d\n" , val); +return sysfs_emit (buf,"%d\n" , val); } static struct kobj_attribute uv_prot_virt_guest =
Signature · 1 line
2.41.0
Janosch Frank
maintainer[GIT PULL 07/11] s390/uvdevice: Add 'Add Secret' UVC
In reply to Janosch FrankFrom: Steffen Eiden <[email protected]>
Userspace can call the Add Secret Ultravisor Call using IOCTLs on the uvdevice. The Add Secret UV call sends an encrypted and cryptographically verified request to the Ultravisor. The request inserts a protected guest's secret into the Ultravisor for later use.
The uvdevice is merely transporting the request from userspace to the Ultravisor. It's neither checking nor manipulating the request data.
Message-Id: <[email protected]>
--- arch/s390/include/asm/uv.h | 14 ++++++ arch/s390/include/uapi/asm/uvdevice.h | 4 ++ drivers/s390/char/uvdevice.c | 63 +++++++++++++++++++++++++++ 3 files changed, 81 insertions(+)
arch/s390/include/asm/uv.h +14 -0
@@ -58,6 +58,7 @@#define UVC_CMD_SET_SHARED_ACCESS 0x1000#define UVC_CMD_REMOVE_SHARED_ACCESS 0x1001#define UVC_CMD_RETR_ATTEST 0x1020 +#define UVC_CMD_ADD_SECRET 0x1031/* Bits in installed uv calls */ enum uv_cmds_inst {
@@ -88,6 +89,7 @@ enum uv_cmds_inst {BIT_UVC_CMD_DUMP_CPU =26 ,BIT_UVC_CMD_DUMP_COMPLETE =27 ,BIT_UVC_CMD_RETR_ATTEST =28 , + BIT_UVC_CMD_ADD_SECRET = 29, }; enum uv_feat_ind {
@@ -292,6 +294,18 @@ struct uv_cb_dump_complete {u64 reserved30[5 ]; } __packed__aligned(8) ; +/* +* A common UV call struct for pv guests that contains a single address +* Examples: +* Add Secret +*/ +struct uv_cb_guest_addr { +struct uv_cb_header header; +u64 reserved08[3 ]; +u64 addr; +u64 reserved28[4 ]; +} __packed__aligned(8) ; +static inline int __uv_call (unsigned long r1,unsigned long r2) {int cc;
arch/s390/include/uapi/asm/uvdevice.h +4 -0
@@ -69,6 +69,7 @@ struct uvio_uvdev_info {#define UVIO_ATT_ARCB_MAX_LEN 0x100000#define UVIO_ATT_MEASUREMENT_MAX_LEN 0x8000#define UVIO_ATT_ADDITIONAL_MAX_LEN 0x8000 +#define UVIO_ADD_SECRET_MAX_LEN 0x100000#define UVIO_DEVICE_NAME "uv"#define UVIO_TYPE_UVC 'u'
@@ -76,6 +77,7 @@ struct uvio_uvdev_info {enum UVIO_IOCTL_NR {UVIO_IOCTL_UVDEV_INFO_NR =0x00 ,UVIO_IOCTL_ATT_NR , +UVIO_IOCTL_ADD_SECRET_NR ,/* must be the last entry */ UVIO_IOCTL_NUM_IOCTLS };
@@ -83,9 +85,11 @@ enum UVIO_IOCTL_NR {#define UVIO_IOCTL (nr) _IOWR(UVIO_TYPE_UVC, nr, struct uvio_ioctl_cb)#define UVIO_IOCTL_UVDEV_INFO UVIO_IOCTL(UVIO_IOCTL_UVDEV_INFO_NR)#define UVIO_IOCTL_ATT UVIO_IOCTL(UVIO_IOCTL_ATT_NR) +#define UVIO_IOCTL_ADD_SECRET UVIO_IOCTL(UVIO_IOCTL_ADD_SECRET_NR)#define UVIO_SUPP_CALL (nr) (1ULL << (nr))#define UVIO_SUPP_UDEV_INFO UVIO_SUPP_CALL(UVIO_IOCTL_UDEV_INFO_NR)#define UVIO_SUPP_ATT UVIO_SUPP_CALL(UVIO_IOCTL_ATT_NR) +#define UVIO_SUPP_ADD_SECRET UVIO_SUPP_CALL(UVIO_IOCTL_ADD_SECRET_NR)#endif /* __S390_ASM_UVDEVICE_H */
drivers/s390/char/uvdevice.c +63 -0
81 lines not on this page · raw message
Signature · 1 line
2.41.0
Janosch Frank
maintainer[GIT PULL 06/11] s390/uvdevice: Add info IOCTL
In reply to Janosch FrankFrom: Steffen Eiden <[email protected]>
Add an IOCTL that allows userspace to find out which IOCTLs the uvdevice supports without trial and error.
Explicitly expose the IOCTL nr for the request types.
Message-Id: <[email protected]>
--- arch/s390/include/uapi/asm/uvdevice.h | 42 ++++++++++++++- drivers/s390/char/Kconfig | 2 +- drivers/s390/char/uvdevice.c | 77 ++++++++++++++++++++++++--- 3 files changed, 112 insertions(+), 9 deletions(-)
arch/s390/include/uapi/asm/uvdevice.h +41 -1
@@ -32,6 +32,33 @@ struct uvio_attest {__u16 reserved136;/* 0x0136 */ }; +/** +* uvio_uvdev_info - Information of supported functions +* @supp_uvio_cmds - supported IOCTLs by this device +* @supp_uv_cmds - supported UVCs corresponding to the IOCTL +* +* UVIO request to get information about supported request types by this +* uvdevice and the Ultravisor. Everything is output. Bits are in LSB0 +* ordering. If the bit is set in both, @supp_uvio_cmds and @supp_uv_cmds, the +* uvdevice and the Ultravisor support that call. +* +* Note that bit 0 (UVIO_IOCTL_UVDEV_INFO_NR) is always zero for `supp_uv_cmds` +* as there is no corresponding UV-call. +*/ +struct uvio_uvdev_info { +/* +* If bit `n` is set, this device supports the IOCTL with nr `n`. +*/ +__u64 supp_uvio_cmds; +/* +* If bit `n` is set, the Ultravisor(UV) supports the UV-call +* corresponding to the IOCTL with nr `n` in the calling contextx (host +* or guest). The value is only valid if the corresponding bit in +* @supp_uvio_cmds is set as well. +*/ +__u64 supp_uv_cmds; +}; +/* * The following max values define an upper length for the IOCTL in/out buffers. * However, they do not represent the maximum the Ultravisor allows which is
@@ -46,6 +73,19 @@ struct uvio_attest {#define UVIO_DEVICE_NAME "uv"#define UVIO_TYPE_UVC 'u' -#define UVIO_IOCTL_ATT _IOWR(UVIO_TYPE_UVC, 0x01, struct uvio_ioctl_cb) +enum UVIO_IOCTL_NR { +UVIO_IOCTL_UVDEV_INFO_NR =0x00 , +UVIO_IOCTL_ATT_NR , +/* must be the last entry */ +UVIO_IOCTL_NUM_IOCTLS +}; + +#define UVIO_IOCTL (nr) _IOWR(UVIO_TYPE_UVC, nr, struct uvio_ioctl_cb) +#define UVIO_IOCTL_UVDEV_INFO UVIO_IOCTL(UVIO_IOCTL_UVDEV_INFO_NR) +#define UVIO_IOCTL_ATT UVIO_IOCTL(UVIO_IOCTL_ATT_NR) + +#define UVIO_SUPP_CALL (nr) (1ULL << (nr)) +#define UVIO_SUPP_UDEV_INFO UVIO_SUPP_CALL(UVIO_IOCTL_UDEV_INFO_NR) +#define UVIO_SUPP_ATT UVIO_SUPP_CALL(UVIO_IOCTL_ATT_NR)#endif /* __S390_ASM_UVDEVICE_H */
drivers/s390/char/Kconfig +1 -1
@@ -96,7 +96,7 @@ config SCLP_OFB config S390_UV_UAPI def_tristate m prompt "Ultravisor userspace API" - depends on S390 + depends on S390 && (KVM || PROTECTED_VIRTUALIZATION_GUEST) help Selecting exposes parts of the UV interface to userspace by providing a misc character device at /dev/uv.
drivers/s390/char/uvdevice.c +70 -7
109 lines not on this page · raw message
Signature · 1 line
2.41.0
Janosch Frank
maintainer[GIT PULL 05/11] s390/uv: Always export uv_info
In reply to Janosch FrankFrom: Steffen Eiden <[email protected]>
KVM needs the struct's values to be able to provide PV support.
The uvdevice is currently guest only and will need the struct's values for call support checking and potential future expansions.
As uv.c is only compiled with CONFIG_PGSTE or CONFIG_PROTECTED_VIRTUALIZATION_GUEST we don't need a second check in the code. Users of uv_info will need to fence for these two config options for the time being.
Message-Id: <[email protected]>
--- arch/s390/kernel/uv.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)
arch/s390/kernel/uv.c +9 -1
@@ -23,12 +23,20 @@int __bootdata_preserved (prot_virt_guest );#endif +/* +* uv_info contains both host and guest information but it's currently only +* expected to be used within modules if it's the KVM module or for +* any PV guest module. +* +* The kernel itself will write these values once in uv_query_info() +* and then make some of them readable via a sysfs interface. +*/ struct uv_info __bootdata_preserved (uv_info ); +EXPORT_SYMBOL (uv_info);#if IS_ENABLED (CONFIG_KVM )int __bootdata_preserved (prot_virt_host );EXPORT_SYMBOL (prot_virt_host); -EXPORT_SYMBOL (uv_info);static int __init uv_init (phys_addr_t stor_base,unsigned long stor_len) {
Signature · 1 line
2.41.0
Janosch Frank
maintainer[GIT PULL 09/11] s390/uvdevice: Add 'Lock Secret Store' UVC
In reply to Janosch FrankFrom: Steffen Eiden <[email protected]>
Userspace can call the Lock Secret Store Ultravisor Call using IOCTLs on the uvdevice. The Lock Secret Store UV call disables all additions of secrets for the future.
The uvdevice is merely transporting the request from userspace to the Ultravisor.
Message-Id: <[email protected]>
--- arch/s390/include/asm/uv.h | 2 ++ arch/s390/include/uapi/asm/uvdevice.h | 3 +++ drivers/s390/char/uvdevice.c | 39 +++++++++++++++++++++++++++ 3 files changed, 44 insertions(+)
arch/s390/include/asm/uv.h +2 -0
@@ -60,6 +60,7 @@#define UVC_CMD_RETR_ATTEST 0x1020#define UVC_CMD_ADD_SECRET 0x1031#define UVC_CMD_LIST_SECRETS 0x1033 +#define UVC_CMD_LOCK_SECRETS 0x1034/* Bits in installed uv calls */ enum uv_cmds_inst {
@@ -92,6 +93,7 @@ enum uv_cmds_inst {BIT_UVC_CMD_RETR_ATTEST =28 ,BIT_UVC_CMD_ADD_SECRET =29 ,BIT_UVC_CMD_LIST_SECRETS =30 , + BIT_UVC_CMD_LOCK_SECRETS = 31, }; enum uv_feat_ind {
arch/s390/include/uapi/asm/uvdevice.h +3 -0
@@ -80,6 +80,7 @@ enum UVIO_IOCTL_NR {UVIO_IOCTL_ATT_NR ,UVIO_IOCTL_ADD_SECRET_NR ,UVIO_IOCTL_LIST_SECRETS_NR , +UVIO_IOCTL_LOCK_SECRETS_NR ,/* must be the last entry */ UVIO_IOCTL_NUM_IOCTLS };
@@ -89,11 +90,13 @@ enum UVIO_IOCTL_NR {#define UVIO_IOCTL_ATT UVIO_IOCTL(UVIO_IOCTL_ATT_NR)#define UVIO_IOCTL_ADD_SECRET UVIO_IOCTL(UVIO_IOCTL_ADD_SECRET_NR)#define UVIO_IOCTL_LIST_SECRETS UVIO_IOCTL(UVIO_IOCTL_LIST_SECRETS_NR) +#define UVIO_IOCTL_LOCK_SECRETS UVIO_IOCTL(UVIO_IOCTL_LOCK_SECRETS_NR)#define UVIO_SUPP_CALL (nr) (1ULL << (nr))#define UVIO_SUPP_UDEV_INFO UVIO_SUPP_CALL(UVIO_IOCTL_UDEV_INFO_NR)#define UVIO_SUPP_ATT UVIO_SUPP_CALL(UVIO_IOCTL_ATT_NR)#define UVIO_SUPP_ADD_SECRET UVIO_SUPP_CALL(UVIO_IOCTL_ADD_SECRET_NR)#define UVIO_SUPP_LIST_SECRETS UVIO_SUPP_CALL(UVIO_IOCTL_LIST_SECRETS_NR) +#define UVIO_SUPP_LOCK_SECRETS UVIO_SUPP_CALL(UVIO_IOCTL_LOCK_SECRETS_NR)#endif /* __S390_ASM_UVDEVICE_H */
drivers/s390/char/uvdevice.c +39 -0
@@ -39,6 +39,7 @@ static const u32 ioctl_nr_to_uvc_bit[] __initconst = { [UVIO_IOCTL_ATT_NR] = BIT_UVC_CMD_RETR_ATTEST, [UVIO_IOCTL_ADD_SECRET_NR] = BIT_UVC_CMD_ADD_SECRET, [UVIO_IOCTL_LIST_SECRETS_NR] = BIT_UVC_CMD_LIST_SECRETS, + [UVIO_IOCTL_LOCK_SECRETS_NR ] =BIT_UVC_CMD_LOCK_SECRETS , };static_assert (ARRAY_SIZE (ioctl_nr_to_uvc_bit) ==UVIO_IOCTL_NUM_IOCTLS );
@@ -340,6 +341,41 @@ static int uvio_list_secrets(struct uvio_ioctl_cb *uv_ioctl)return ret; } +/** uvio_lock_secrets() - perform a Lock Secret Store UVC +* @uv_ioctl: ioctl control block +* +* uvio_lock_secrets() performs the Lock Secret Store Ultravisor Call. It +* performs the UV-call and copies the return codes to the ioctl control block. +* After this call was dispatched successfully every following Add Secret UVC +* and Lock Secrets UVC will fail with return code 0x102. +* +* The argument address and size must be 0. +* +* If the Lock Secrets UV facility is not present, UV will return invalid +* command rc. This won't be fenced in the driver and does not result in a +* negative return value. +* +* Context: might sleep +* +* Return: 0 on success or a negative error code on error. +*/ +static int uvio_lock_secrets (struct uvio_ioctl_cb *ioctl) +{ +struct uv_cb_nodata uvcb = { + .header.len =sizeof (uvcb), + .header.cmd =UVC_CMD_LOCK_SECRETS , + }; + +if (ioctl->argument_addr || ioctl->argument_len) +return -EINVAL ; + +uv_call (0 , (u64)&uvcb); + ioctl->uv_rc = uvcb.header.rc; + ioctl->uv_rrc = uvcb.header.rrc; + +return 0 ; +} +static int uvio_copy_and_check_ioctl (struct uvio_ioctl_cb *ioctl,void __user *argp,unsigned long cmd) {
@@ -390,6 +426,9 @@ static long uvio_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)case UVIO_IOCTL_LIST_SECRETS_NR : ret =uvio_list_secrets (&uv_ioctl);break ; +case UVIO_IOCTL_LOCK_SECRETS_NR : + ret =uvio_lock_secrets (&uv_ioctl); +break ;default : ret = -ENOIOCTLCMD ;break ;
Signature · 1 line
2.41.0
Paolo Bonzini
maintainerQuoted 18 lines · Janosch Frank
Dear Paolo,
here are the patches for 6.5 (or later):
~80% of the code is a new CMM selftest by Nico.
~19% of the code is Steffen's additions to the uvdevice introducing the UV secret API. The rest are a couple of fixes that we picked up along the way.I plan to remove the ifdefs and the
PROTECTED_VIRTUALIZATION_GUESTconfig in the (near) future so we won't run into the linking problems that plagued the uvdevice patches anymore.Please pull:
The following changes since commitf1fcbaa18b28dec10281551dfe6ed3a3ed80e3d6:Linux 6.4-rc2 (2023-05-14 12:51:40 -0700)
Quoted 7 lines
are available in the Git repository at:
https://git.kernel.org/pub/scm/linux/kernel/git/kvms390/linux.git tags/kvm-s390-next-6.5-1
for you to fetch changes up to
db54dfc9f71cd2df7afd1e88535ef6099cb0333e:s390/uv: Update query for secret-UVCs (2023-06-16 11:08:09 +0200)
Done, thanks.
Paolo
Quoted 46 lines
----------------------------------------------------------------
* New uvdevice secret API
* New CMM selftest
* cmm fix
* diag 9c racy access of target cpu fix
* VSIE AP control block fix
----------------------------------------------------------------Christian Borntraeger (1):
KVM: s390/diag: fix racy access of physical cpu number in diag 9c
handlerNico Boehr (2):
KVM: s390: fixKVM_S390_GET_CMMA_BITSfor GFNs in memslot holes
KVM: s390: selftests: add selftest for CMMA migrationPierre Morel (1):
KVM: s390: vsie: fix the length of APCB bitmapSteffen Eiden (7):
s390/uv: Always exportuv_info
s390/uvdevice: Add info IOCTL
s390/uvdevice: Add 'Add Secret' UVC
s390/uvdevice: Add 'List Secrets' UVC
s390/uvdevice: Add 'Lock Secret Store' UVC
s390/uv: replace scnprintf withsysfs_emit
s390/uv: Update query for secret-UVCsarch/s390/boot/uv.c | 4 + arch/s390/include/asm/uv.h | 32 +- arch/s390/include/uapi/asm/uvdevice.h | 53 +- arch/s390/kernel/uv.c | 108 ++- arch/s390/kvm/diag.c | 8 +- arch/s390/kvm/kvm-s390.c | 4 + arch/s390/kvm/vsie.c | 6 +- drivers/s390/char/Kconfig | 2 +- drivers/s390/char/uvdevice.c | 231 +++++- tools/testing/selftests/kvm/Makefile | 1 + tools/testing/selftests/kvm/s390x/cmma_test.c | 700 ++++++++++++++++++ 11 files changed, 1100 insertions(+), 49 deletions(-) create mode 100644 tools/testing/selftests/kvm/s390x/cmma_test.c--
2.41.0