Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

powerpc/pseries/vas: Implement getting capabilities from hypervisor

The hypervisor provides VAS capabilities for GZIP default and QoS
features. These capabilities gives information for the specific
features such as total number of credits available in LPAR,
maximum credits allowed per window, maximum credits allowed in
LPAR, whether usermode copy/paste is supported, and etc.

This patch adds the following:
- Retrieve all features that are provided by hypervisor using
H_QUERY_VAS_CAPABILITIES hcall with 0 as feature type.
- Retrieve capabilities for the specific feature using the same
hcall and the feature type (1 for QoS and 2 for default type).

Signed-off-by: Haren Myneni <haren@linux.ibm.com>
Reviewed-by: Nicholas Piggin <npiggin@gmail.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://lore.kernel.org/r/177c88608cb88f7b87d1c546103f18cec6c056b4.camel@linux.ibm.com

authored by

Haren Myneni and committed by
Michael Ellerman
ca77d488 f33ecfde

+122
+122
arch/powerpc/platforms/pseries/vas.c
··· 10 10 #include <linux/export.h> 11 11 #include <linux/types.h> 12 12 #include <linux/delay.h> 13 + #include <asm/machdep.h> 13 14 #include <asm/hvcall.h> 14 15 #include <asm/plpar_wrappers.h> 15 16 #include <asm/vas.h> ··· 20 19 #define VAS_DEFAULT_DOMAIN_ID 0xFFFFFFFFFFFFFFFFul 21 20 /* The hypervisor allows one credit per window right now */ 22 21 #define DEF_WIN_CREDS 1 22 + 23 + static struct vas_all_caps caps_all; 24 + static bool copypaste_feat; 25 + 26 + static struct vas_caps vascaps[VAS_MAX_FEAT_TYPE]; 23 27 24 28 static long hcall_return_busy_check(long rc) 25 29 { ··· 151 145 hcall, rc, query_type, result); 152 146 return -EIO; 153 147 } 148 + 149 + /* 150 + * Get the specific capabilities based on the feature type. 151 + * Right now supports GZIP default and GZIP QoS capabilities. 152 + */ 153 + static int get_vas_capabilities(u8 feat, enum vas_cop_feat_type type, 154 + struct hv_vas_cop_feat_caps *hv_caps) 155 + { 156 + struct vas_cop_feat_caps *caps; 157 + struct vas_caps *vcaps; 158 + int rc = 0; 159 + 160 + vcaps = &vascaps[type]; 161 + memset(vcaps, 0, sizeof(*vcaps)); 162 + INIT_LIST_HEAD(&vcaps->list); 163 + 164 + caps = &vcaps->caps; 165 + 166 + rc = h_query_vas_capabilities(H_QUERY_VAS_CAPABILITIES, feat, 167 + (u64)virt_to_phys(hv_caps)); 168 + if (rc) 169 + return rc; 170 + 171 + caps->user_mode = hv_caps->user_mode; 172 + if (!(caps->user_mode & VAS_COPY_PASTE_USER_MODE)) { 173 + pr_err("User space COPY/PASTE is not supported\n"); 174 + return -ENOTSUPP; 175 + } 176 + 177 + caps->descriptor = be64_to_cpu(hv_caps->descriptor); 178 + caps->win_type = hv_caps->win_type; 179 + if (caps->win_type >= VAS_MAX_FEAT_TYPE) { 180 + pr_err("Unsupported window type %u\n", caps->win_type); 181 + return -EINVAL; 182 + } 183 + caps->max_lpar_creds = be16_to_cpu(hv_caps->max_lpar_creds); 184 + caps->max_win_creds = be16_to_cpu(hv_caps->max_win_creds); 185 + atomic_set(&caps->target_lpar_creds, 186 + be16_to_cpu(hv_caps->target_lpar_creds)); 187 + if (feat == VAS_GZIP_DEF_FEAT) { 188 + caps->def_lpar_creds = be16_to_cpu(hv_caps->def_lpar_creds); 189 + 190 + if (caps->max_win_creds < DEF_WIN_CREDS) { 191 + pr_err("Window creds(%u) > max allowed window creds(%u)\n", 192 + DEF_WIN_CREDS, caps->max_win_creds); 193 + return -EINVAL; 194 + } 195 + } 196 + 197 + copypaste_feat = true; 198 + 199 + return 0; 200 + } 201 + 202 + static int __init pseries_vas_init(void) 203 + { 204 + struct hv_vas_cop_feat_caps *hv_cop_caps; 205 + struct hv_vas_all_caps *hv_caps; 206 + int rc; 207 + 208 + /* 209 + * Linux supports user space COPY/PASTE only with Radix 210 + */ 211 + if (!radix_enabled()) { 212 + pr_err("API is supported only with radix page tables\n"); 213 + return -ENOTSUPP; 214 + } 215 + 216 + hv_caps = kmalloc(sizeof(*hv_caps), GFP_KERNEL); 217 + if (!hv_caps) 218 + return -ENOMEM; 219 + /* 220 + * Get VAS overall capabilities by passing 0 to feature type. 221 + */ 222 + rc = h_query_vas_capabilities(H_QUERY_VAS_CAPABILITIES, 0, 223 + (u64)virt_to_phys(hv_caps)); 224 + if (rc) 225 + goto out; 226 + 227 + caps_all.descriptor = be64_to_cpu(hv_caps->descriptor); 228 + caps_all.feat_type = be64_to_cpu(hv_caps->feat_type); 229 + 230 + hv_cop_caps = kmalloc(sizeof(*hv_cop_caps), GFP_KERNEL); 231 + if (!hv_cop_caps) { 232 + rc = -ENOMEM; 233 + goto out; 234 + } 235 + /* 236 + * QOS capabilities available 237 + */ 238 + if (caps_all.feat_type & VAS_GZIP_QOS_FEAT_BIT) { 239 + rc = get_vas_capabilities(VAS_GZIP_QOS_FEAT, 240 + VAS_GZIP_QOS_FEAT_TYPE, hv_cop_caps); 241 + 242 + if (rc) 243 + goto out_cop; 244 + } 245 + /* 246 + * Default capabilities available 247 + */ 248 + if (caps_all.feat_type & VAS_GZIP_DEF_FEAT_BIT) { 249 + rc = get_vas_capabilities(VAS_GZIP_DEF_FEAT, 250 + VAS_GZIP_DEF_FEAT_TYPE, hv_cop_caps); 251 + if (rc) 252 + goto out_cop; 253 + } 254 + 255 + pr_info("GZIP feature is available\n"); 256 + 257 + out_cop: 258 + kfree(hv_cop_caps); 259 + out: 260 + kfree(hv_caps); 261 + return rc; 262 + } 263 + machine_device_initcall(pseries, pseries_vas_init);