Commit b7f64368 authored by Martin Schwidefsky's avatar Martin Schwidefsky Committed by Linus Torvalds

[PATCH] s390: dcss segments

From: Carsten Otte <cotte@de.ibm.com>

dcss segment interface changes:
 - Add check when loading segments to avoid out of range mappings.
 - Add code to check for segment_load returning -ERANGE.
 - Rename segment_info to segment_type.
 - Restore previous segment state if reload fails.
 - Add segment_modify_shared() to change shared attributes of a dcss
   segment and use it in the dcss block device driver.
 - Add support for contiguous EW/EN multipart segments.
Signed-off-by: default avatarMartin Schwidefsky <schwidefsky@de.ibm.com>
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent 4e4eef31
...@@ -40,14 +40,19 @@ ...@@ -40,14 +40,19 @@
#define DCSS_FINDSEG 0x0c #define DCSS_FINDSEG 0x0c
#define DCSS_LOADNOLY 0x10 #define DCSS_LOADNOLY 0x10
#define DCSS_SEGEXT 0x18 #define DCSS_SEGEXT 0x18
#define DCSS_QACTV 0x0c #define DCSS_FINDSEGA 0x0c
struct qrange {
unsigned int start; // 3byte start address, 1 byte type
unsigned int end; // 3byte end address, 1 byte reserved
};
struct qout64 { struct qout64 {
int segstart; int segstart;
int segend; int segend;
int segcnt; int segcnt;
int segrcnt; int segrcnt;
char segout[8][6]; struct qrange range[6];
}; };
struct qin64 { struct qin64 {
...@@ -67,12 +72,15 @@ struct dcss_segment { ...@@ -67,12 +72,15 @@ struct dcss_segment {
unsigned long end; unsigned long end;
atomic_t ref_count; atomic_t ref_count;
int do_nonshared; int do_nonshared;
int vm_segtype; unsigned int vm_segtype;
struct qrange range[6];
int segcnt;
}; };
static spinlock_t dcss_lock = SPIN_LOCK_UNLOCKED; static spinlock_t dcss_lock = SPIN_LOCK_UNLOCKED;
static struct list_head dcss_list = LIST_HEAD_INIT(dcss_list); static struct list_head dcss_list = LIST_HEAD_INIT(dcss_list);
static char *segtype_string[7] = { "SW", "EW", "SR", "ER", "SN", "EN", "SC" }; static char *segtype_string[] = { "SW", "EW", "SR", "ER", "SN", "EN", "SC",
"EW/EN-MIXED" };
extern struct { extern struct {
unsigned long addr, size, type; unsigned long addr, size, type;
...@@ -162,12 +170,12 @@ dcss_diag_translate_rc (int vm_rc) { ...@@ -162,12 +170,12 @@ dcss_diag_translate_rc (int vm_rc) {
* fills start_address, end and vm_segtype fields * fills start_address, end and vm_segtype fields
*/ */
static int static int
query_segment_info (struct dcss_segment *seg) query_segment_type (struct dcss_segment *seg)
{ {
struct qin64 *qin = kmalloc (sizeof(struct qin64), GFP_DMA); struct qin64 *qin = kmalloc (sizeof(struct qin64), GFP_DMA);
struct qout64 *qout = kmalloc (sizeof(struct qout64), GFP_DMA); struct qout64 *qout = kmalloc (sizeof(struct qout64), GFP_DMA);
int diag_cc, rc; int diag_cc, rc, i;
unsigned long dummy, vmrc; unsigned long dummy, vmrc;
if ((qin == NULL) || (qout == NULL)) { if ((qin == NULL) || (qout == NULL)) {
...@@ -176,7 +184,7 @@ query_segment_info (struct dcss_segment *seg) ...@@ -176,7 +184,7 @@ query_segment_info (struct dcss_segment *seg)
} }
/* initialize diag input parameters */ /* initialize diag input parameters */
qin->qopcode = DCSS_QACTV; qin->qopcode = DCSS_FINDSEGA;
qin->qoutptr = (unsigned long) qout; qin->qoutptr = (unsigned long) qout;
qin->qoutlen = sizeof(struct qout64); qin->qoutlen = sizeof(struct qout64);
memcpy (qin->qname, seg->dcss_name, 8); memcpy (qin->qname, seg->dcss_name, 8);
...@@ -188,16 +196,40 @@ query_segment_info (struct dcss_segment *seg) ...@@ -188,16 +196,40 @@ query_segment_info (struct dcss_segment *seg)
goto out_free; goto out_free;
} }
if (qout->segcnt > 1) { if (qout->segcnt > 6) {
rc = -ENOTSUPP; rc = -ENOTSUPP;
goto out_free; goto out_free;
} }
if (qout->segcnt == 1) {
seg->vm_segtype = qout->range[0].start & 0xff;
} else {
/* multi-part segment. only one type supported here:
- all parts are contiguous
- all parts are either EW or EN type
- maximum 6 parts allowed */
unsigned long start = qout->segstart >> PAGE_SHIFT;
for (i=0; i<qout->segcnt; i++) {
if (((qout->range[i].start & 0xff) != SEG_TYPE_EW) &&
((qout->range[i].start & 0xff) != SEG_TYPE_EN)) {
rc = -ENOTSUPP;
goto out_free;
}
if (start != qout->range[i].start >> PAGE_SHIFT) {
rc = -ENOTSUPP;
goto out_free;
}
start = (qout->range[i].end >> PAGE_SHIFT) + 1;
}
seg->vm_segtype = SEG_TYPE_EWEN;
}
/* analyze diag output and update seg */ /* analyze diag output and update seg */
seg->start_addr = qout->segstart; seg->start_addr = qout->segstart;
seg->end = qout->segend; seg->end = qout->segend;
seg->vm_segtype = qout->segout[0][3]; memcpy (seg->range, qout->range, 6*sizeof(struct qrange));
seg->segcnt = qout->segcnt;
rc = 0; rc = 0;
...@@ -253,6 +285,19 @@ segment_overlaps_others (struct dcss_segment *seg) ...@@ -253,6 +285,19 @@ segment_overlaps_others (struct dcss_segment *seg)
return 0; return 0;
} }
/*
* check if segment exceeds the kernel mapping range (detected or set via mem=)
* returns 1 if this is the case, 0 if segment fits into the range
*/
static inline int
segment_exceeds_range (struct dcss_segment *seg)
{
int seg_last_pfn = (seg->end) >> PAGE_SHIFT;
if (seg_last_pfn > max_pfn)
return 1;
return 0;
}
/* /*
* get info about a segment * get info about a segment
* possible return values: * possible return values:
...@@ -265,7 +310,7 @@ segment_overlaps_others (struct dcss_segment *seg) ...@@ -265,7 +310,7 @@ segment_overlaps_others (struct dcss_segment *seg)
* 0 .. 6 : type of segment as defined in include/asm-s390/extmem.h * 0 .. 6 : type of segment as defined in include/asm-s390/extmem.h
*/ */
int int
segment_info (char* name) segment_type (char* name)
{ {
int rc; int rc;
struct dcss_segment seg; struct dcss_segment seg;
...@@ -274,7 +319,7 @@ segment_info (char* name) ...@@ -274,7 +319,7 @@ segment_info (char* name)
return -ENOSYS; return -ENOSYS;
dcss_mkname(name, seg.dcss_name); dcss_mkname(name, seg.dcss_name);
rc = query_segment_info (&seg); rc = query_segment_type (&seg);
if (rc < 0) if (rc < 0)
return rc; return rc;
return seg.vm_segtype; return seg.vm_segtype;
...@@ -295,9 +340,15 @@ __segment_load (char *name, int do_nonshared, unsigned long *addr, unsigned long ...@@ -295,9 +340,15 @@ __segment_load (char *name, int do_nonshared, unsigned long *addr, unsigned long
goto out; goto out;
} }
dcss_mkname (name, seg->dcss_name); dcss_mkname (name, seg->dcss_name);
rc = query_segment_info (seg); rc = query_segment_type (seg);
if (rc < 0) if (rc < 0)
goto out_free; goto out_free;
if (segment_exceeds_range(seg)) {
PRINT_WARN ("segment_load: not loading segment %s - exceeds"
" kernel mapping range\n",name);
rc = -ERANGE;
goto out_free;
}
if (segment_overlaps_storage(seg)) { if (segment_overlaps_storage(seg)) {
PRINT_WARN ("segment_load: not loading segment %s - overlaps" PRINT_WARN ("segment_load: not loading segment %s - overlaps"
" storage\n",name); " storage\n",name);
...@@ -362,6 +413,7 @@ __segment_load (char *name, int do_nonshared, unsigned long *addr, unsigned long ...@@ -362,6 +413,7 @@ __segment_load (char *name, int do_nonshared, unsigned long *addr, unsigned long
* -ENOTSUPP: multi-part segment cannot be used with linux * -ENOTSUPP: multi-part segment cannot be used with linux
* -ENOSPC : segment cannot be used (overlaps with storage) * -ENOSPC : segment cannot be used (overlaps with storage)
* -EBUSY : segment can temporarily not be used (overlaps with dcss) * -EBUSY : segment can temporarily not be used (overlaps with dcss)
* -ERANGE : segment cannot be used (exceeds kernel mapping range)
* -EPERM : segment is currently loaded with incompatible permissions * -EPERM : segment is currently loaded with incompatible permissions
* -ENOMEM : out of memory * -ENOMEM : out of memory
* 0 .. 6 : type of segment as defined in include/asm-s390/extmem.h * 0 .. 6 : type of segment as defined in include/asm-s390/extmem.h
...@@ -395,6 +447,70 @@ segment_load (char *name, int do_nonshared, unsigned long *addr, ...@@ -395,6 +447,70 @@ segment_load (char *name, int do_nonshared, unsigned long *addr,
return rc; return rc;
} }
/*
* this function modifies the shared state of a DCSS segment. note that
* name : name of the DCSS
* do_nonshared : 0 indicates that the dcss should be shared with other linux images
* 1 indicates that the dcss should be exclusive for this linux image
* return values:
* -EIO : could not perform load diagnose (segment gone!)
* -ENOENT : no such segment (segment gone!)
* -EAGAIN : segment is in use by other exploiters, try later
* -EINVAL : no segment with the given name is currently loaded - name invalid
* 0 : operation succeeded
*/
int
segment_modify_shared (char *name, int do_nonshared)
{
struct dcss_segment *seg;
unsigned long dummy;
int dcss_command, rc, diag_cc;
spin_lock (&dcss_lock);
seg = segment_by_name (name);
if (seg == NULL) {
rc = -EINVAL;
goto out_unlock;
}
if (do_nonshared == seg->do_nonshared) {
PRINT_INFO ("segment_modify_shared: not reloading segment %s"
" - already in requested mode\n",name);
rc = 0;
goto out_unlock;
}
if (atomic_read (&seg->ref_count) != 1) {
PRINT_WARN ("segment_modify_shared: not reloading segment %s - "
"segment is in use by other driver(s)\n",name);
rc = -EAGAIN;
goto out_unlock;
}
dcss_diag(DCSS_PURGESEG, seg->dcss_name,
&dummy, &dummy);
if (do_nonshared)
dcss_command = DCSS_LOADNSR;
else
dcss_command = DCSS_LOADNOLY;
diag_cc = dcss_diag(dcss_command, seg->dcss_name,
&seg->start_addr, &seg->end);
if (diag_cc > 1) {
PRINT_WARN ("segment_modify_shared: could not reload segment %s"
" - diag returned error (%ld)\n",name,seg->end);
rc = dcss_diag_translate_rc (seg->end);
goto out_del;
}
seg->do_nonshared = do_nonshared;
rc = 0;
goto out_unlock;
out_del:
list_del(&seg->list);
dcss_diag(DCSS_PURGESEG, seg->dcss_name,
&dummy, &dummy);
kfree (seg);
out_unlock:
spin_unlock(&dcss_lock);
return rc;
}
/* /*
* Decrease the use count of a DCSS segment and remove * Decrease the use count of a DCSS segment and remove
* it from the address space if nobody is using it * it from the address space if nobody is using it
...@@ -434,8 +550,9 @@ void segment_save(char *name) ...@@ -434,8 +550,9 @@ void segment_save(char *name)
struct dcss_segment *seg; struct dcss_segment *seg;
int startpfn = 0; int startpfn = 0;
int endpfn = 0; int endpfn = 0;
char cmd1[80]; char cmd1[160];
char cmd2[80]; char cmd2[80];
int i;
if (!MACHINE_IS_VM) if (!MACHINE_IS_VM)
return; return;
...@@ -448,10 +565,15 @@ void segment_save(char *name) ...@@ -448,10 +565,15 @@ void segment_save(char *name)
return; return;
} }
startpfn = seg->start_addr >> 12; startpfn = seg->start_addr >> PAGE_SHIFT;
endpfn = (seg->end) >> 12; endpfn = (seg->end) >> PAGE_SHIFT;
sprintf(cmd1, "DEFSEG %s %X-%X %s", name, startpfn, endpfn, sprintf(cmd1, "DEFSEG %s", name);
segtype_string[seg->vm_segtype]); for (i=0; i<seg->segcnt; i++) {
sprintf(cmd1+strlen(cmd1), " %X-%X %s",
seg->range[i].start >> PAGE_SHIFT,
seg->range[i].end >> PAGE_SHIFT,
segtype_string[seg->range[i].start & 0xff]);
}
sprintf(cmd2, "SAVESEG %s", name); sprintf(cmd2, "SAVESEG %s", name);
cpcmd(cmd1, NULL, 80); cpcmd(cmd1, NULL, 80);
cpcmd(cmd2, NULL, 80); cpcmd(cmd2, NULL, 80);
...@@ -461,4 +583,5 @@ void segment_save(char *name) ...@@ -461,4 +583,5 @@ void segment_save(char *name)
EXPORT_SYMBOL(segment_load); EXPORT_SYMBOL(segment_load);
EXPORT_SYMBOL(segment_unload); EXPORT_SYMBOL(segment_unload);
EXPORT_SYMBOL(segment_save); EXPORT_SYMBOL(segment_save);
EXPORT_SYMBOL(segment_info); EXPORT_SYMBOL(segment_type);
EXPORT_SYMBOL(segment_modify_shared);
...@@ -140,7 +140,7 @@ dcssblk_get_device_by_name(char *name) ...@@ -140,7 +140,7 @@ dcssblk_get_device_by_name(char *name)
} }
/* /*
* print appropriate error message for segment_load()/segment_info() * print appropriate error message for segment_load()/segment_type()
* return code * return code
*/ */
static void static void
...@@ -179,6 +179,10 @@ dcssblk_segment_warn(int rc, char* seg_name) ...@@ -179,6 +179,10 @@ dcssblk_segment_warn(int rc, char* seg_name)
PRINT_WARN("cannot load/query segment %s, out of memory\n", PRINT_WARN("cannot load/query segment %s, out of memory\n",
seg_name); seg_name);
break; break;
case -ERANGE:
PRINT_WARN("cannot load/query segment %s, exceeds kernel "
"mapping range\n", seg_name);
break;
default: default:
PRINT_WARN("cannot load/query segment %s, return value %i\n", PRINT_WARN("cannot load/query segment %s, return value %i\n",
seg_name, rc); seg_name, rc);
...@@ -214,57 +218,50 @@ dcssblk_shared_store(struct device *dev, const char *inbuf, size_t count) ...@@ -214,57 +218,50 @@ dcssblk_shared_store(struct device *dev, const char *inbuf, size_t count)
if (atomic_read(&dev_info->use_count)) { if (atomic_read(&dev_info->use_count)) {
PRINT_ERR("share: segment %s is busy!\n", PRINT_ERR("share: segment %s is busy!\n",
dev_info->segment_name); dev_info->segment_name);
up_write(&dcssblk_devices_sem); rc = -EBUSY;
return -EBUSY; goto out;
}
if ((inbuf[0] == '1') && (dev_info->is_shared == 1)) {
PRINT_WARN("Segment %s already loaded in shared mode!\n",
dev_info->segment_name);
up_write(&dcssblk_devices_sem);
return count;
}
if ((inbuf[0] == '0') && (dev_info->is_shared == 0)) {
PRINT_WARN("Segment %s already loaded in exclusive mode!\n",
dev_info->segment_name);
up_write(&dcssblk_devices_sem);
return count;
} }
if (inbuf[0] == '1') { if (inbuf[0] == '1') {
// reload segment in shared mode // reload segment in shared mode
segment_unload(dev_info->segment_name); rc = segment_modify_shared(dev_info->segment_name,
rc = segment_load(dev_info->segment_name, SEGMENT_SHARED, SEGMENT_SHARED);
&dev_info->start, &dev_info->end);
if (rc < 0) { if (rc < 0) {
dcssblk_segment_warn(rc, dev_info->segment_name); BUG_ON(rc == -EINVAL);
goto removeseg; if (rc == -EIO || rc == -ENOENT)
goto removeseg;
} else {
dev_info->is_shared = 1;
switch (dev_info->segment_type) {
case SEG_TYPE_SR:
case SEG_TYPE_ER:
case SEG_TYPE_SC:
set_disk_ro(dev_info->gd,1);
}
} }
dev_info->is_shared = 1;
if (rc == SEG_TYPE_SR || rc == SEG_TYPE_ER || rc == SEG_TYPE_SC)
set_disk_ro(dev_info->gd, 1);
} else if (inbuf[0] == '0') { } else if (inbuf[0] == '0') {
// reload segment in exclusive mode // reload segment in exclusive mode
if (dev_info->segment_type == SEG_TYPE_SC) { if (dev_info->segment_type == SEG_TYPE_SC) {
PRINT_ERR("Segment type SC (%s) cannot be loaded in " PRINT_ERR("Segment type SC (%s) cannot be loaded in "
"non-shared mode\n", dev_info->segment_name); "non-shared mode\n", dev_info->segment_name);
up_write(&dcssblk_devices_sem); rc = -EINVAL;
return -EINVAL; goto out;
} }
segment_unload(dev_info->segment_name); rc = segment_modify_shared(dev_info->segment_name,
rc = segment_load(dev_info->segment_name, SEGMENT_EXCLUSIVE, SEGMENT_EXCLUSIVE);
&dev_info->start, &dev_info->end);
if (rc < 0) { if (rc < 0) {
dcssblk_segment_warn(rc, dev_info->segment_name); BUG_ON(rc == -EINVAL);
goto removeseg; if (rc == -EIO || rc == -ENOENT)
goto removeseg;
} else {
dev_info->is_shared = 0;
set_disk_ro(dev_info->gd, 0);
} }
dev_info->is_shared = 0;
set_disk_ro(dev_info->gd, 0);
} else { } else {
up_write(&dcssblk_devices_sem);
PRINT_WARN("Invalid value, must be 0 or 1\n"); PRINT_WARN("Invalid value, must be 0 or 1\n");
return -EINVAL; rc = -EINVAL;
goto out;
} }
rc = count; rc = count;
up_write(&dcssblk_devices_sem);
goto out; goto out;
removeseg: removeseg:
...@@ -278,8 +275,8 @@ dcssblk_shared_store(struct device *dev, const char *inbuf, size_t count) ...@@ -278,8 +275,8 @@ dcssblk_shared_store(struct device *dev, const char *inbuf, size_t count)
put_disk(dev_info->gd); put_disk(dev_info->gd);
device_unregister(dev); device_unregister(dev);
put_device(dev); put_device(dev);
up_write(&dcssblk_devices_sem);
out: out:
up_write(&dcssblk_devices_sem);
return rc; return rc;
} }
......
...@@ -116,7 +116,7 @@ dcss_mkname(char *ascii_name, char *ebcdic_name) ...@@ -116,7 +116,7 @@ dcss_mkname(char *ascii_name, char *ebcdic_name)
} }
/* /*
* print appropriate error message for segment_load()/segment_info() * print appropriate error message for segment_load()/segment_type()
* return code * return code
*/ */
static void static void
...@@ -155,6 +155,10 @@ mon_segment_warn(int rc, char* seg_name) ...@@ -155,6 +155,10 @@ mon_segment_warn(int rc, char* seg_name)
P_WARNING("cannot load/query segment %s, out of memory\n", P_WARNING("cannot load/query segment %s, out of memory\n",
seg_name); seg_name);
break; break;
case -ERANGE:
P_WARNING("cannot load/query segment %s, exceeds kernel "
"mapping range\n", seg_name);
break;
default: default:
P_WARNING("cannot load/query segment %s, return value %i\n", P_WARNING("cannot load/query segment %s, return value %i\n",
seg_name, rc); seg_name, rc);
...@@ -581,7 +585,7 @@ mon_init(void) ...@@ -581,7 +585,7 @@ mon_init(void)
return -ENODEV; return -ENODEV;
} }
rc = segment_info(mon_dcss_name); rc = segment_type(mon_dcss_name);
if (rc < 0) { if (rc < 0) {
mon_segment_warn(rc, mon_dcss_name); mon_segment_warn(rc, mon_dcss_name);
return rc; return rc;
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#define SEG_TYPE_SN 4 #define SEG_TYPE_SN 4
#define SEG_TYPE_EN 5 #define SEG_TYPE_EN 5
#define SEG_TYPE_SC 6 #define SEG_TYPE_SC 6
#define SEG_TYPE_EWEN 7
#define SEGMENT_SHARED 0 #define SEGMENT_SHARED 0
#define SEGMENT_EXCLUSIVE 1 #define SEGMENT_EXCLUSIVE 1
...@@ -24,7 +25,8 @@ ...@@ -24,7 +25,8 @@
extern int segment_load (char *name,int segtype,unsigned long *addr,unsigned long *length); extern int segment_load (char *name,int segtype,unsigned long *addr,unsigned long *length);
extern void segment_unload(char *name); extern void segment_unload(char *name);
extern void segment_save(char *name); extern void segment_save(char *name);
extern int segment_info (char* name); extern int segment_type (char* name);
extern int segment_modify_shared (char *name, int do_nonshared);
#endif #endif
#endif #endif
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment