Skip to content

Commit 07be038

Browse files
author
Martin Schwidefsky
committed
s390/hypfs: add interface for diagnose 0x304
To provide access to the set-partition-resource-parameter interface to user space add a new attribute to hypfs/debugfs: * s390_hypsfs/diag_304 The data for the query-partition-resource-parameters command can be access by a read on the attribute. All other diagnose 0x304 requests need to be submitted via ioctl with CAP_SYS_ADMIN rights. Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>
1 parent fded432 commit 07be038

9 files changed

Lines changed: 208 additions & 5 deletions

File tree

‎Documentation/ioctl/ioctl-number.txt‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ Code Seq#(hex) Include File Comments
7373
0x09 all linux/raid/md_u.h
7474
0x10 00-0F drivers/char/s390/vmcp.h
7575
0x10 10-1F arch/s390/include/uapi/sclp_ctl.h
76+
0x10 20-2F arch/s390/include/uapi/asm/hypfs.h
7677
0x12 all linux/fs.h
7778
linux/blkpg.h
7879
0x1b all InfiniBand Subsystem <http://infiniband.sourceforge.net/>

‎arch/s390/hypfs/Makefile‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44

55
obj-$(CONFIG_S390_HYPFS_FS) += s390_hypfs.o
66

7-
s390_hypfs-objs := inode.o hypfs_diag.o hypfs_vm.o hypfs_dbfs.o
7+
s390_hypfs-objs := inode.o hypfs_diag.o hypfs_vm.o hypfs_dbfs.o hypfs_sprp.o

‎arch/s390/hypfs/hypfs.h‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <linux/debugfs.h>
1414
#include <linux/workqueue.h>
1515
#include <linux/kref.h>
16+
#include <asm/hypfs.h>
1617

1718
#define REG_FILE_MODE 0440
1819
#define UPDATE_FILE_MODE 0220
@@ -36,6 +37,10 @@ extern int hypfs_vm_init(void);
3637
extern void hypfs_vm_exit(void);
3738
extern int hypfs_vm_create_files(struct dentry *root);
3839

40+
/* Set Partition-Resource Parameter */
41+
int hypfs_sprp_init(void);
42+
void hypfs_sprp_exit(void);
43+
3944
/* debugfs interface */
4045
struct hypfs_dbfs_file;
4146

@@ -52,6 +57,8 @@ struct hypfs_dbfs_file {
5257
int (*data_create)(void **data, void **data_free_ptr,
5358
size_t *size);
5459
void (*data_free)(const void *buf_free_ptr);
60+
long (*unlocked_ioctl) (struct file *, unsigned int,
61+
unsigned long);
5562

5663
/* Private data for hypfs_dbfs.c */
5764
struct hypfs_dbfs_data *data;

‎arch/s390/hypfs/hypfs_dbfs.c‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,25 @@ static ssize_t dbfs_read(struct file *file, char __user *buf,
8181
return rc;
8282
}
8383

84+
static long dbfs_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
85+
{
86+
struct hypfs_dbfs_file *df;
87+
long rc;
88+
89+
df = file->f_path.dentry->d_inode->i_private;
90+
mutex_lock(&df->lock);
91+
if (df->unlocked_ioctl)
92+
rc = df->unlocked_ioctl(file, cmd, arg);
93+
else
94+
rc = -ENOTTY;
95+
mutex_unlock(&df->lock);
96+
return rc;
97+
}
98+
8499
static const struct file_operations dbfs_ops = {
85100
.read = dbfs_read,
86101
.llseek = no_llseek,
102+
.unlocked_ioctl = dbfs_ioctl,
87103
};
88104

89105
int hypfs_dbfs_create_file(struct hypfs_dbfs_file *df)

‎arch/s390/hypfs/hypfs_sprp.c‎

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
/*
2+
* Hypervisor filesystem for Linux on s390.
3+
* Set Partition-Resource Parameter interface.
4+
*
5+
* Copyright IBM Corp. 2013
6+
* Author(s): Martin Schwidefsky <schwidefsky@de.ibm.com>
7+
*/
8+
9+
#include <linux/compat.h>
10+
#include <linux/errno.h>
11+
#include <linux/gfp.h>
12+
#include <linux/string.h>
13+
#include <linux/types.h>
14+
#include <linux/uaccess.h>
15+
#include <asm/compat.h>
16+
#include <asm/sclp.h>
17+
#include "hypfs.h"
18+
19+
#define DIAG304_SET_WEIGHTS 0
20+
#define DIAG304_QUERY_PRP 1
21+
#define DIAG304_SET_CAPPING 2
22+
23+
#define DIAG304_CMD_MAX 2
24+
25+
static unsigned long hypfs_sprp_diag304(void *data, unsigned long cmd)
26+
{
27+
register unsigned long _data asm("2") = (unsigned long) data;
28+
register unsigned long _rc asm("3");
29+
register unsigned long _cmd asm("4") = cmd;
30+
31+
asm volatile("diag %1,%2,0x304\n"
32+
: "=d" (_rc) : "d" (_data), "d" (_cmd) : "memory");
33+
34+
return _rc;
35+
}
36+
37+
static void hypfs_sprp_free(const void *data)
38+
{
39+
free_page((unsigned long) data);
40+
}
41+
42+
static int hypfs_sprp_create(void **data_ptr, void **free_ptr, size_t *size)
43+
{
44+
unsigned long rc;
45+
void *data;
46+
47+
data = (void *) get_zeroed_page(GFP_KERNEL);
48+
if (!data)
49+
return -ENOMEM;
50+
rc = hypfs_sprp_diag304(data, DIAG304_QUERY_PRP);
51+
if (rc != 1) {
52+
*data_ptr = *free_ptr = NULL;
53+
*size = 0;
54+
free_page((unsigned long) data);
55+
return -EIO;
56+
}
57+
*data_ptr = *free_ptr = data;
58+
*size = PAGE_SIZE;
59+
return 0;
60+
}
61+
62+
static int __hypfs_sprp_ioctl(void __user *user_area)
63+
{
64+
struct hypfs_diag304 diag304;
65+
unsigned long cmd;
66+
void __user *udata;
67+
void *data;
68+
int rc;
69+
70+
if (copy_from_user(&diag304, user_area, sizeof(diag304)))
71+
return -EFAULT;
72+
if ((diag304.args[0] >> 8) != 0 || diag304.args[1] > DIAG304_CMD_MAX)
73+
return -EINVAL;
74+
75+
data = (void *) get_zeroed_page(GFP_KERNEL | GFP_DMA);
76+
if (!data)
77+
return -ENOMEM;
78+
79+
udata = (void __user *)(unsigned long) diag304.data;
80+
if (diag304.args[1] == DIAG304_SET_WEIGHTS ||
81+
diag304.args[1] == DIAG304_SET_CAPPING)
82+
if (copy_from_user(data, udata, PAGE_SIZE)) {
83+
rc = -EFAULT;
84+
goto out;
85+
}
86+
87+
cmd = *(unsigned long *) &diag304.args[0];
88+
diag304.rc = hypfs_sprp_diag304(data, cmd);
89+
90+
if (diag304.args[1] == DIAG304_QUERY_PRP)
91+
if (copy_to_user(udata, data, PAGE_SIZE)) {
92+
rc = -EFAULT;
93+
goto out;
94+
}
95+
96+
rc = copy_to_user(user_area, &diag304, sizeof(diag304)) ? -EFAULT : 0;
97+
out:
98+
free_page((unsigned long) data);
99+
return rc;
100+
}
101+
102+
static long hypfs_sprp_ioctl(struct file *file, unsigned int cmd,
103+
unsigned long arg)
104+
{
105+
void __user *argp;
106+
107+
if (!capable(CAP_SYS_ADMIN))
108+
return -EACCES;
109+
if (is_compat_task())
110+
argp = compat_ptr(arg);
111+
else
112+
argp = (void __user *) arg;
113+
switch (cmd) {
114+
case HYPFS_DIAG304:
115+
return __hypfs_sprp_ioctl(argp);
116+
default: /* unknown ioctl number */
117+
return -ENOTTY;
118+
}
119+
return 0;
120+
}
121+
122+
static struct hypfs_dbfs_file hypfs_sprp_file = {
123+
.name = "diag_304",
124+
.data_create = hypfs_sprp_create,
125+
.data_free = hypfs_sprp_free,
126+
.unlocked_ioctl = hypfs_sprp_ioctl,
127+
};
128+
129+
int hypfs_sprp_init(void)
130+
{
131+
if (!sclp_has_sprp())
132+
return 0;
133+
return hypfs_dbfs_create_file(&hypfs_sprp_file);
134+
}
135+
136+
void hypfs_sprp_exit(void)
137+
{
138+
if (!sclp_has_sprp())
139+
return;
140+
hypfs_dbfs_remove_file(&hypfs_sprp_file);
141+
}

‎arch/s390/hypfs/inode.c‎

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -478,10 +478,14 @@ static int __init hypfs_init(void)
478478
rc = -ENODATA;
479479
goto fail_hypfs_diag_exit;
480480
}
481+
if (hypfs_sprp_init()) {
482+
rc = -ENODATA;
483+
goto fail_hypfs_vm_exit;
484+
}
481485
s390_kobj = kobject_create_and_add("s390", hypervisor_kobj);
482486
if (!s390_kobj) {
483487
rc = -ENOMEM;
484-
goto fail_hypfs_vm_exit;
488+
goto fail_hypfs_sprp_exit;
485489
}
486490
rc = register_filesystem(&hypfs_type);
487491
if (rc)
@@ -490,6 +494,8 @@ static int __init hypfs_init(void)
490494

491495
fail_filesystem:
492496
kobject_put(s390_kobj);
497+
fail_hypfs_sprp_exit:
498+
hypfs_sprp_exit();
493499
fail_hypfs_vm_exit:
494500
hypfs_vm_exit();
495501
fail_hypfs_diag_exit:
@@ -502,11 +508,12 @@ static int __init hypfs_init(void)
502508

503509
static void __exit hypfs_exit(void)
504510
{
505-
hypfs_diag_exit();
506-
hypfs_vm_exit();
507-
hypfs_dbfs_exit();
508511
unregister_filesystem(&hypfs_type);
509512
kobject_put(s390_kobj);
513+
hypfs_sprp_exit();
514+
hypfs_vm_exit();
515+
hypfs_diag_exit();
516+
hypfs_dbfs_exit();
510517
}
511518

512519
module_init(hypfs_init)

‎arch/s390/include/asm/sclp.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ int sclp_chp_read_info(struct sclp_chp_info *info);
5454
void sclp_get_ipl_info(struct sclp_ipl_info *info);
5555
bool __init sclp_has_linemode(void);
5656
bool __init sclp_has_vt220(void);
57+
bool sclp_has_sprp(void);
5758
int sclp_pci_configure(u32 fid);
5859
int sclp_pci_deconfigure(u32 fid);
5960
int memcpy_hsa(void *dest, unsigned long src, size_t count, int mode);

‎arch/s390/include/uapi/asm/hypfs.h‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
* IOCTL interface for hypfs
3+
*
4+
* Copyright IBM Corp. 2013
5+
*
6+
* Author: Martin Schwidefsky <schwidefsky@de.ibm.com>
7+
*/
8+
9+
#ifndef _ASM_HYPFS_CTL_H
10+
#define _ASM_HYPFS_CTL_H
11+
12+
#include <linux/types.h>
13+
14+
struct hypfs_diag304 {
15+
__u32 args[2];
16+
__u64 data;
17+
__u64 rc;
18+
} __attribute__((packed));
19+
20+
#define HYPFS_IOCTL_MAGIC 0x10
21+
22+
#define HYPFS_DIAG304 \
23+
_IOWR(HYPFS_IOCTL_MAGIC, 0x20, struct hypfs_diag304)
24+
25+
#endif

‎drivers/s390/char/sclp_cmd.c‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -700,3 +700,8 @@ int sclp_chp_read_info(struct sclp_chp_info *info)
700700
free_page((unsigned long) sccb);
701701
return rc;
702702
}
703+
704+
bool sclp_has_sprp(void)
705+
{
706+
return !!(sclp_fac84 & 0x2);
707+
}

0 commit comments

Comments
 (0)