Skip to content

Commit 275d05c

Browse files
Claudio ImbrendaVasily Gorbik
authored andcommitted
s390/kvm: Move bitfields for dat tables
Move and improve the struct definitions for DAT tables from gaccess.c to a new header. Once in a separate header, the structs become available everywhere. One possible usecase is to merge them in the s390 pte_t and p?d_t definitions, which is left as an exercise for the reader. Signed-off-by: Claudio Imbrenda <[email protected]> Reviewed-by: Nico Boehr <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Heiko Carstens <[email protected]> Signed-off-by: Vasily Gorbik <[email protected]>
1 parent 723ac2d commit 275d05c

File tree

2 files changed

+173
-160
lines changed

2 files changed

+173
-160
lines changed

arch/s390/include/asm/dat-bits.h

Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
/* SPDX-License-Identifier: GPL-2.0 */
2+
/*
3+
* DAT table and related structures
4+
*
5+
* Copyright IBM Corp. 2024
6+
*
7+
*/
8+
9+
#ifndef _S390_DAT_BITS_H
10+
#define _S390_DAT_BITS_H
11+
12+
union asce {
13+
unsigned long val;
14+
struct {
15+
unsigned long rsto: 52;/* Region- or Segment-Table Origin */
16+
unsigned long : 2;
17+
unsigned long g : 1; /* Subspace Group control */
18+
unsigned long p : 1; /* Private Space control */
19+
unsigned long s : 1; /* Storage-Alteration-Event control */
20+
unsigned long x : 1; /* Space-Switch-Event control */
21+
unsigned long r : 1; /* Real-Space control */
22+
unsigned long : 1;
23+
unsigned long dt : 2; /* Designation-Type control */
24+
unsigned long tl : 2; /* Region- or Segment-Table Length */
25+
};
26+
};
27+
28+
enum {
29+
ASCE_TYPE_SEGMENT = 0,
30+
ASCE_TYPE_REGION3 = 1,
31+
ASCE_TYPE_REGION2 = 2,
32+
ASCE_TYPE_REGION1 = 3
33+
};
34+
35+
union region1_table_entry {
36+
unsigned long val;
37+
struct {
38+
unsigned long rto: 52;/* Region-Table Origin */
39+
unsigned long : 2;
40+
unsigned long p : 1; /* DAT-Protection Bit */
41+
unsigned long : 1;
42+
unsigned long tf : 2; /* Region-Second-Table Offset */
43+
unsigned long i : 1; /* Region-Invalid Bit */
44+
unsigned long : 1;
45+
unsigned long tt : 2; /* Table-Type Bits */
46+
unsigned long tl : 2; /* Region-Second-Table Length */
47+
};
48+
};
49+
50+
union region2_table_entry {
51+
unsigned long val;
52+
struct {
53+
unsigned long rto: 52;/* Region-Table Origin */
54+
unsigned long : 2;
55+
unsigned long p : 1; /* DAT-Protection Bit */
56+
unsigned long : 1;
57+
unsigned long tf : 2; /* Region-Third-Table Offset */
58+
unsigned long i : 1; /* Region-Invalid Bit */
59+
unsigned long : 1;
60+
unsigned long tt : 2; /* Table-Type Bits */
61+
unsigned long tl : 2; /* Region-Third-Table Length */
62+
};
63+
};
64+
65+
struct region3_table_entry_fc0 {
66+
unsigned long sto: 52;/* Segment-Table Origin */
67+
unsigned long : 1;
68+
unsigned long fc : 1; /* Format-Control */
69+
unsigned long p : 1; /* DAT-Protection Bit */
70+
unsigned long : 1;
71+
unsigned long tf : 2; /* Segment-Table Offset */
72+
unsigned long i : 1; /* Region-Invalid Bit */
73+
unsigned long cr : 1; /* Common-Region Bit */
74+
unsigned long tt : 2; /* Table-Type Bits */
75+
unsigned long tl : 2; /* Segment-Table Length */
76+
};
77+
78+
struct region3_table_entry_fc1 {
79+
unsigned long rfaa: 33;/* Region-Frame Absolute Address */
80+
unsigned long : 14;
81+
unsigned long av : 1; /* ACCF-Validity Control */
82+
unsigned long acc : 4; /* Access-Control Bits */
83+
unsigned long f : 1; /* Fetch-Protection Bit */
84+
unsigned long fc : 1; /* Format-Control */
85+
unsigned long p : 1; /* DAT-Protection Bit */
86+
unsigned long iep : 1; /* Instruction-Execution-Protection */
87+
unsigned long : 2;
88+
unsigned long i : 1; /* Region-Invalid Bit */
89+
unsigned long cr : 1; /* Common-Region Bit */
90+
unsigned long tt : 2; /* Table-Type Bits */
91+
unsigned long : 2;
92+
};
93+
94+
union region3_table_entry {
95+
unsigned long val;
96+
struct region3_table_entry_fc0 fc0;
97+
struct region3_table_entry_fc1 fc1;
98+
struct {
99+
unsigned long : 53;
100+
unsigned long fc: 1; /* Format-Control */
101+
unsigned long : 4;
102+
unsigned long i : 1; /* Region-Invalid Bit */
103+
unsigned long cr: 1; /* Common-Region Bit */
104+
unsigned long tt: 2; /* Table-Type Bits */
105+
unsigned long : 2;
106+
};
107+
};
108+
109+
struct segment_table_entry_fc0 {
110+
unsigned long pto: 53;/* Page-Table Origin */
111+
unsigned long fc : 1; /* Format-Control */
112+
unsigned long p : 1; /* DAT-Protection Bit */
113+
unsigned long : 3;
114+
unsigned long i : 1; /* Segment-Invalid Bit */
115+
unsigned long cs : 1; /* Common-Segment Bit */
116+
unsigned long tt : 2; /* Table-Type Bits */
117+
unsigned long : 2;
118+
};
119+
120+
struct segment_table_entry_fc1 {
121+
unsigned long sfaa: 44;/* Segment-Frame Absolute Address */
122+
unsigned long : 3;
123+
unsigned long av : 1; /* ACCF-Validity Control */
124+
unsigned long acc : 4; /* Access-Control Bits */
125+
unsigned long f : 1; /* Fetch-Protection Bit */
126+
unsigned long fc : 1; /* Format-Control */
127+
unsigned long p : 1; /* DAT-Protection Bit */
128+
unsigned long iep : 1; /* Instruction-Execution-Protection */
129+
unsigned long : 2;
130+
unsigned long i : 1; /* Segment-Invalid Bit */
131+
unsigned long cs : 1; /* Common-Segment Bit */
132+
unsigned long tt : 2; /* Table-Type Bits */
133+
unsigned long : 2;
134+
};
135+
136+
union segment_table_entry {
137+
unsigned long val;
138+
struct segment_table_entry_fc0 fc0;
139+
struct segment_table_entry_fc1 fc1;
140+
struct {
141+
unsigned long : 53;
142+
unsigned long fc: 1; /* Format-Control */
143+
unsigned long : 4;
144+
unsigned long i : 1; /* Segment-Invalid Bit */
145+
unsigned long cs: 1; /* Common-Segment Bit */
146+
unsigned long tt: 2; /* Table-Type Bits */
147+
unsigned long : 2;
148+
};
149+
};
150+
151+
union page_table_entry {
152+
unsigned long val;
153+
struct {
154+
unsigned long pfra: 52;/* Page-Frame Real Address */
155+
unsigned long z : 1; /* Zero Bit */
156+
unsigned long i : 1; /* Page-Invalid Bit */
157+
unsigned long p : 1; /* DAT-Protection Bit */
158+
unsigned long iep : 1; /* Instruction-Execution-Protection */
159+
unsigned long : 8;
160+
};
161+
};
162+
163+
enum {
164+
TABLE_TYPE_SEGMENT = 0,
165+
TABLE_TYPE_REGION3 = 1,
166+
TABLE_TYPE_REGION2 = 2,
167+
TABLE_TYPE_REGION1 = 3
168+
};
169+
170+
#endif /* _S390_DAT_BITS_H */

arch/s390/kvm/gaccess.c

Lines changed: 3 additions & 160 deletions
Original file line numberDiff line numberDiff line change
@@ -14,167 +14,10 @@
1414
#include <asm/access-regs.h>
1515
#include <asm/fault.h>
1616
#include <asm/gmap.h>
17+
#include <asm/dat-bits.h>
1718
#include "kvm-s390.h"
1819
#include "gaccess.h"
1920

20-
union asce {
21-
unsigned long val;
22-
struct {
23-
unsigned long origin : 52; /* Region- or Segment-Table Origin */
24-
unsigned long : 2;
25-
unsigned long g : 1; /* Subspace Group Control */
26-
unsigned long p : 1; /* Private Space Control */
27-
unsigned long s : 1; /* Storage-Alteration-Event Control */
28-
unsigned long x : 1; /* Space-Switch-Event Control */
29-
unsigned long r : 1; /* Real-Space Control */
30-
unsigned long : 1;
31-
unsigned long dt : 2; /* Designation-Type Control */
32-
unsigned long tl : 2; /* Region- or Segment-Table Length */
33-
};
34-
};
35-
36-
enum {
37-
ASCE_TYPE_SEGMENT = 0,
38-
ASCE_TYPE_REGION3 = 1,
39-
ASCE_TYPE_REGION2 = 2,
40-
ASCE_TYPE_REGION1 = 3
41-
};
42-
43-
union region1_table_entry {
44-
unsigned long val;
45-
struct {
46-
unsigned long rto: 52;/* Region-Table Origin */
47-
unsigned long : 2;
48-
unsigned long p : 1; /* DAT-Protection Bit */
49-
unsigned long : 1;
50-
unsigned long tf : 2; /* Region-Second-Table Offset */
51-
unsigned long i : 1; /* Region-Invalid Bit */
52-
unsigned long : 1;
53-
unsigned long tt : 2; /* Table-Type Bits */
54-
unsigned long tl : 2; /* Region-Second-Table Length */
55-
};
56-
};
57-
58-
union region2_table_entry {
59-
unsigned long val;
60-
struct {
61-
unsigned long rto: 52;/* Region-Table Origin */
62-
unsigned long : 2;
63-
unsigned long p : 1; /* DAT-Protection Bit */
64-
unsigned long : 1;
65-
unsigned long tf : 2; /* Region-Third-Table Offset */
66-
unsigned long i : 1; /* Region-Invalid Bit */
67-
unsigned long : 1;
68-
unsigned long tt : 2; /* Table-Type Bits */
69-
unsigned long tl : 2; /* Region-Third-Table Length */
70-
};
71-
};
72-
73-
struct region3_table_entry_fc0 {
74-
unsigned long sto: 52;/* Segment-Table Origin */
75-
unsigned long : 1;
76-
unsigned long fc : 1; /* Format-Control */
77-
unsigned long p : 1; /* DAT-Protection Bit */
78-
unsigned long : 1;
79-
unsigned long tf : 2; /* Segment-Table Offset */
80-
unsigned long i : 1; /* Region-Invalid Bit */
81-
unsigned long cr : 1; /* Common-Region Bit */
82-
unsigned long tt : 2; /* Table-Type Bits */
83-
unsigned long tl : 2; /* Segment-Table Length */
84-
};
85-
86-
struct region3_table_entry_fc1 {
87-
unsigned long rfaa : 33; /* Region-Frame Absolute Address */
88-
unsigned long : 14;
89-
unsigned long av : 1; /* ACCF-Validity Control */
90-
unsigned long acc: 4; /* Access-Control Bits */
91-
unsigned long f : 1; /* Fetch-Protection Bit */
92-
unsigned long fc : 1; /* Format-Control */
93-
unsigned long p : 1; /* DAT-Protection Bit */
94-
unsigned long iep: 1; /* Instruction-Execution-Protection */
95-
unsigned long : 2;
96-
unsigned long i : 1; /* Region-Invalid Bit */
97-
unsigned long cr : 1; /* Common-Region Bit */
98-
unsigned long tt : 2; /* Table-Type Bits */
99-
unsigned long : 2;
100-
};
101-
102-
union region3_table_entry {
103-
unsigned long val;
104-
struct region3_table_entry_fc0 fc0;
105-
struct region3_table_entry_fc1 fc1;
106-
struct {
107-
unsigned long : 53;
108-
unsigned long fc : 1; /* Format-Control */
109-
unsigned long : 4;
110-
unsigned long i : 1; /* Region-Invalid Bit */
111-
unsigned long cr : 1; /* Common-Region Bit */
112-
unsigned long tt : 2; /* Table-Type Bits */
113-
unsigned long : 2;
114-
};
115-
};
116-
117-
struct segment_entry_fc0 {
118-
unsigned long pto: 53;/* Page-Table Origin */
119-
unsigned long fc : 1; /* Format-Control */
120-
unsigned long p : 1; /* DAT-Protection Bit */
121-
unsigned long : 3;
122-
unsigned long i : 1; /* Segment-Invalid Bit */
123-
unsigned long cs : 1; /* Common-Segment Bit */
124-
unsigned long tt : 2; /* Table-Type Bits */
125-
unsigned long : 2;
126-
};
127-
128-
struct segment_entry_fc1 {
129-
unsigned long sfaa : 44; /* Segment-Frame Absolute Address */
130-
unsigned long : 3;
131-
unsigned long av : 1; /* ACCF-Validity Control */
132-
unsigned long acc: 4; /* Access-Control Bits */
133-
unsigned long f : 1; /* Fetch-Protection Bit */
134-
unsigned long fc : 1; /* Format-Control */
135-
unsigned long p : 1; /* DAT-Protection Bit */
136-
unsigned long iep: 1; /* Instruction-Execution-Protection */
137-
unsigned long : 2;
138-
unsigned long i : 1; /* Segment-Invalid Bit */
139-
unsigned long cs : 1; /* Common-Segment Bit */
140-
unsigned long tt : 2; /* Table-Type Bits */
141-
unsigned long : 2;
142-
};
143-
144-
union segment_table_entry {
145-
unsigned long val;
146-
struct segment_entry_fc0 fc0;
147-
struct segment_entry_fc1 fc1;
148-
struct {
149-
unsigned long : 53;
150-
unsigned long fc : 1; /* Format-Control */
151-
unsigned long : 4;
152-
unsigned long i : 1; /* Segment-Invalid Bit */
153-
unsigned long cs : 1; /* Common-Segment Bit */
154-
unsigned long tt : 2; /* Table-Type Bits */
155-
unsigned long : 2;
156-
};
157-
};
158-
159-
enum {
160-
TABLE_TYPE_SEGMENT = 0,
161-
TABLE_TYPE_REGION3 = 1,
162-
TABLE_TYPE_REGION2 = 2,
163-
TABLE_TYPE_REGION1 = 3
164-
};
165-
166-
union page_table_entry {
167-
unsigned long val;
168-
struct {
169-
unsigned long pfra : 52; /* Page-Frame Real Address */
170-
unsigned long z : 1; /* Zero Bit */
171-
unsigned long i : 1; /* Page-Invalid Bit */
172-
unsigned long p : 1; /* DAT-Protection Bit */
173-
unsigned long iep: 1; /* Instruction-Execution-Protection */
174-
unsigned long : 8;
175-
};
176-
};
177-
17821
/*
17922
* vaddress union in order to easily decode a virtual address into its
18023
* region first index, region second index etc. parts.
@@ -632,7 +475,7 @@ static unsigned long guest_translate(struct kvm_vcpu *vcpu, unsigned long gva,
632475
iep = ctlreg0.iep && test_kvm_facility(vcpu->kvm, 130);
633476
if (asce.r)
634477
goto real_address;
635-
ptr = asce.origin * PAGE_SIZE;
478+
ptr = asce.rsto * PAGE_SIZE;
636479
switch (asce.dt) {
637480
case ASCE_TYPE_REGION1:
638481
if (vaddr.rfx01 > asce.tl)
@@ -1379,7 +1222,7 @@ static int kvm_s390_shadow_tables(struct gmap *sg, unsigned long saddr,
13791222
parent = sg->parent;
13801223
vaddr.addr = saddr;
13811224
asce.val = sg->orig_asce;
1382-
ptr = asce.origin * PAGE_SIZE;
1225+
ptr = asce.rsto * PAGE_SIZE;
13831226
if (asce.r) {
13841227
*fake = 1;
13851228
ptr = 0;

0 commit comments

Comments
 (0)