Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /*
0003  * Copyright 2016, Michael Ellerman, IBM Corp.
0004  */
0005 
0006 #include <stdio.h>
0007 #include <stdlib.h>
0008 #include <string.h>
0009 #include <sys/mman.h>
0010 #include <unistd.h>
0011 
0012 #include <asm/cputable.h>
0013 
0014 #include "utils.h"
0015 
0016 #define SIZE (64 * 1024)
0017 
0018 int test_prot_sao(void)
0019 {
0020     char *p;
0021 
0022     /*
0023      * SAO was introduced in 2.06 and removed in 3.1. It's disabled in
0024      * guests/LPARs by default, so also skip if we are running in a guest.
0025      */
0026     SKIP_IF(!have_hwcap(PPC_FEATURE_ARCH_2_06) ||
0027         have_hwcap2(PPC_FEATURE2_ARCH_3_1) ||
0028         access("/proc/device-tree/rtas/ibm,hypertas-functions", F_OK) == 0);
0029 
0030     /*
0031      * Ensure we can ask for PROT_SAO.
0032      * We can't really verify that it does the right thing, but at least we
0033      * confirm the kernel will accept it.
0034      */
0035     p = mmap(NULL, SIZE, PROT_READ | PROT_WRITE | PROT_SAO,
0036          MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
0037     FAIL_IF(p == MAP_FAILED);
0038 
0039     /* Write to the mapping, to at least cause a fault */
0040     memset(p, 0xaa, SIZE);
0041 
0042     return 0;
0043 }
0044 
0045 int main(void)
0046 {
0047     return test_harness(test_prot_sao, "prot-sao");
0048 }