174fe6c29SRuslan Bukin /*
2*85f87cf4SRuslan Bukin * Copyright (c) 2014-2019, Intel Corporation
374fe6c29SRuslan Bukin *
474fe6c29SRuslan Bukin * Redistribution and use in source and binary forms, with or without
574fe6c29SRuslan Bukin * modification, are permitted provided that the following conditions are met:
674fe6c29SRuslan Bukin *
774fe6c29SRuslan Bukin * * Redistributions of source code must retain the above copyright notice,
874fe6c29SRuslan Bukin * this list of conditions and the following disclaimer.
974fe6c29SRuslan Bukin * * Redistributions in binary form must reproduce the above copyright notice,
1074fe6c29SRuslan Bukin * this list of conditions and the following disclaimer in the documentation
1174fe6c29SRuslan Bukin * and/or other materials provided with the distribution.
1274fe6c29SRuslan Bukin * * Neither the name of Intel Corporation nor the names of its contributors
1374fe6c29SRuslan Bukin * may be used to endorse or promote products derived from this software
1474fe6c29SRuslan Bukin * without specific prior written permission.
1574fe6c29SRuslan Bukin *
1674fe6c29SRuslan Bukin * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
1774fe6c29SRuslan Bukin * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1874fe6c29SRuslan Bukin * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1974fe6c29SRuslan Bukin * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
2074fe6c29SRuslan Bukin * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2174fe6c29SRuslan Bukin * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2274fe6c29SRuslan Bukin * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2374fe6c29SRuslan Bukin * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2474fe6c29SRuslan Bukin * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2574fe6c29SRuslan Bukin * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2674fe6c29SRuslan Bukin * POSSIBILITY OF SUCH DAMAGE.
2774fe6c29SRuslan Bukin */
2874fe6c29SRuslan Bukin
2974fe6c29SRuslan Bukin #include "ptunit.h"
3074fe6c29SRuslan Bukin
3174fe6c29SRuslan Bukin #include "pt_asid.h"
3274fe6c29SRuslan Bukin
3374fe6c29SRuslan Bukin #include "intel-pt.h"
3474fe6c29SRuslan Bukin
3574fe6c29SRuslan Bukin #include <stddef.h>
3674fe6c29SRuslan Bukin
3774fe6c29SRuslan Bukin
from_user_null(void)3874fe6c29SRuslan Bukin static struct ptunit_result from_user_null(void)
3974fe6c29SRuslan Bukin {
4074fe6c29SRuslan Bukin struct pt_asid user;
4174fe6c29SRuslan Bukin int errcode;
4274fe6c29SRuslan Bukin
4374fe6c29SRuslan Bukin pt_asid_init(&user);
4474fe6c29SRuslan Bukin
4574fe6c29SRuslan Bukin errcode = pt_asid_from_user(NULL, NULL);
4674fe6c29SRuslan Bukin ptu_int_eq(errcode, -pte_internal);
4774fe6c29SRuslan Bukin
4874fe6c29SRuslan Bukin errcode = pt_asid_from_user(NULL, &user);
4974fe6c29SRuslan Bukin ptu_int_eq(errcode, -pte_internal);
5074fe6c29SRuslan Bukin
5174fe6c29SRuslan Bukin return ptu_passed();
5274fe6c29SRuslan Bukin }
5374fe6c29SRuslan Bukin
from_user_default(void)5474fe6c29SRuslan Bukin static struct ptunit_result from_user_default(void)
5574fe6c29SRuslan Bukin {
5674fe6c29SRuslan Bukin struct pt_asid asid;
5774fe6c29SRuslan Bukin int errcode;
5874fe6c29SRuslan Bukin
5974fe6c29SRuslan Bukin errcode = pt_asid_from_user(&asid, NULL);
6074fe6c29SRuslan Bukin ptu_int_eq(errcode, 0);
6174fe6c29SRuslan Bukin ptu_uint_eq(asid.size, sizeof(asid));
6274fe6c29SRuslan Bukin ptu_uint_eq(asid.cr3, pt_asid_no_cr3);
6374fe6c29SRuslan Bukin ptu_uint_eq(asid.vmcs, pt_asid_no_vmcs);
6474fe6c29SRuslan Bukin
6574fe6c29SRuslan Bukin return ptu_passed();
6674fe6c29SRuslan Bukin }
6774fe6c29SRuslan Bukin
from_user_small(void)6874fe6c29SRuslan Bukin static struct ptunit_result from_user_small(void)
6974fe6c29SRuslan Bukin {
7074fe6c29SRuslan Bukin struct pt_asid asid, user;
7174fe6c29SRuslan Bukin int errcode;
7274fe6c29SRuslan Bukin
7374fe6c29SRuslan Bukin user.size = sizeof(user.size);
7474fe6c29SRuslan Bukin
7574fe6c29SRuslan Bukin errcode = pt_asid_from_user(&asid, &user);
7674fe6c29SRuslan Bukin ptu_int_eq(errcode, 0);
7774fe6c29SRuslan Bukin ptu_uint_eq(asid.size, sizeof(asid));
7874fe6c29SRuslan Bukin ptu_uint_eq(asid.cr3, pt_asid_no_cr3);
7974fe6c29SRuslan Bukin ptu_uint_eq(asid.vmcs, pt_asid_no_vmcs);
8074fe6c29SRuslan Bukin
8174fe6c29SRuslan Bukin return ptu_passed();
8274fe6c29SRuslan Bukin }
8374fe6c29SRuslan Bukin
from_user_big(void)8474fe6c29SRuslan Bukin static struct ptunit_result from_user_big(void)
8574fe6c29SRuslan Bukin {
8674fe6c29SRuslan Bukin struct pt_asid asid, user;
8774fe6c29SRuslan Bukin int errcode;
8874fe6c29SRuslan Bukin
8974fe6c29SRuslan Bukin user.size = sizeof(user) + 4;
9074fe6c29SRuslan Bukin user.cr3 = 0x4200ull;
9174fe6c29SRuslan Bukin user.vmcs = 0x23000ull;
9274fe6c29SRuslan Bukin
9374fe6c29SRuslan Bukin errcode = pt_asid_from_user(&asid, &user);
9474fe6c29SRuslan Bukin ptu_int_eq(errcode, 0);
9574fe6c29SRuslan Bukin ptu_uint_eq(asid.size, sizeof(asid));
9674fe6c29SRuslan Bukin ptu_uint_eq(asid.cr3, 0x4200ull);
9774fe6c29SRuslan Bukin ptu_uint_eq(asid.vmcs, 0x23000ull);
9874fe6c29SRuslan Bukin
9974fe6c29SRuslan Bukin return ptu_passed();
10074fe6c29SRuslan Bukin }
10174fe6c29SRuslan Bukin
from_user(void)10274fe6c29SRuslan Bukin static struct ptunit_result from_user(void)
10374fe6c29SRuslan Bukin {
10474fe6c29SRuslan Bukin struct pt_asid asid, user;
10574fe6c29SRuslan Bukin int errcode;
10674fe6c29SRuslan Bukin
10774fe6c29SRuslan Bukin user.size = sizeof(user);
10874fe6c29SRuslan Bukin user.cr3 = 0x4200ull;
10974fe6c29SRuslan Bukin user.vmcs = 0x23000ull;
11074fe6c29SRuslan Bukin
11174fe6c29SRuslan Bukin errcode = pt_asid_from_user(&asid, &user);
11274fe6c29SRuslan Bukin ptu_int_eq(errcode, 0);
11374fe6c29SRuslan Bukin ptu_uint_eq(asid.size, sizeof(asid));
11474fe6c29SRuslan Bukin ptu_uint_eq(asid.cr3, 0x4200ull);
11574fe6c29SRuslan Bukin ptu_uint_eq(asid.vmcs, 0x23000ull);
11674fe6c29SRuslan Bukin
11774fe6c29SRuslan Bukin return ptu_passed();
11874fe6c29SRuslan Bukin }
11974fe6c29SRuslan Bukin
from_user_cr3(void)12074fe6c29SRuslan Bukin static struct ptunit_result from_user_cr3(void)
12174fe6c29SRuslan Bukin {
12274fe6c29SRuslan Bukin struct pt_asid asid, user;
12374fe6c29SRuslan Bukin int errcode;
12474fe6c29SRuslan Bukin
12574fe6c29SRuslan Bukin user.size = offsetof(struct pt_asid, vmcs);
12674fe6c29SRuslan Bukin user.cr3 = 0x4200ull;
12774fe6c29SRuslan Bukin user.vmcs = 0x23000ull;
12874fe6c29SRuslan Bukin
12974fe6c29SRuslan Bukin errcode = pt_asid_from_user(&asid, &user);
13074fe6c29SRuslan Bukin ptu_int_eq(errcode, 0);
13174fe6c29SRuslan Bukin ptu_uint_eq(asid.size, sizeof(asid));
13274fe6c29SRuslan Bukin ptu_uint_eq(asid.cr3, 0x4200ull);
13374fe6c29SRuslan Bukin ptu_uint_eq(asid.vmcs, pt_asid_no_vmcs);
13474fe6c29SRuslan Bukin
13574fe6c29SRuslan Bukin return ptu_passed();
13674fe6c29SRuslan Bukin }
13774fe6c29SRuslan Bukin
to_user_null(void)13874fe6c29SRuslan Bukin static struct ptunit_result to_user_null(void)
13974fe6c29SRuslan Bukin {
14074fe6c29SRuslan Bukin struct pt_asid asid;
14174fe6c29SRuslan Bukin int errcode;
14274fe6c29SRuslan Bukin
14374fe6c29SRuslan Bukin pt_asid_init(&asid);
14474fe6c29SRuslan Bukin
14574fe6c29SRuslan Bukin errcode = pt_asid_to_user(NULL, NULL, sizeof(asid));
14674fe6c29SRuslan Bukin ptu_int_eq(errcode, -pte_internal);
14774fe6c29SRuslan Bukin
14874fe6c29SRuslan Bukin errcode = pt_asid_to_user(NULL, &asid, sizeof(asid));
14974fe6c29SRuslan Bukin ptu_int_eq(errcode, -pte_internal);
15074fe6c29SRuslan Bukin
15174fe6c29SRuslan Bukin return ptu_passed();
15274fe6c29SRuslan Bukin }
15374fe6c29SRuslan Bukin
to_user_too_small(void)15474fe6c29SRuslan Bukin static struct ptunit_result to_user_too_small(void)
15574fe6c29SRuslan Bukin {
15674fe6c29SRuslan Bukin struct pt_asid asid, user;
15774fe6c29SRuslan Bukin int errcode;
15874fe6c29SRuslan Bukin
15974fe6c29SRuslan Bukin pt_asid_init(&asid);
16074fe6c29SRuslan Bukin
16174fe6c29SRuslan Bukin errcode = pt_asid_to_user(&user, &asid, 0);
16274fe6c29SRuslan Bukin ptu_int_eq(errcode, -pte_invalid);
16374fe6c29SRuslan Bukin
16474fe6c29SRuslan Bukin errcode = pt_asid_to_user(&user, &asid, sizeof(user.size) - 1);
16574fe6c29SRuslan Bukin ptu_int_eq(errcode, -pte_invalid);
16674fe6c29SRuslan Bukin
16774fe6c29SRuslan Bukin return ptu_passed();
16874fe6c29SRuslan Bukin }
16974fe6c29SRuslan Bukin
to_user_small(void)17074fe6c29SRuslan Bukin static struct ptunit_result to_user_small(void)
17174fe6c29SRuslan Bukin {
17274fe6c29SRuslan Bukin struct pt_asid asid, user;
17374fe6c29SRuslan Bukin int errcode;
17474fe6c29SRuslan Bukin
17574fe6c29SRuslan Bukin memset(&user, 0xcc, sizeof(user));
17674fe6c29SRuslan Bukin pt_asid_init(&asid);
17774fe6c29SRuslan Bukin
17874fe6c29SRuslan Bukin errcode = pt_asid_to_user(&user, &asid, sizeof(user.size));
17974fe6c29SRuslan Bukin ptu_int_eq(errcode, 0);
18074fe6c29SRuslan Bukin ptu_uint_eq(user.size, sizeof(user.size));
18174fe6c29SRuslan Bukin ptu_uint_eq(user.cr3, 0xccccccccccccccccull);
18274fe6c29SRuslan Bukin ptu_uint_eq(user.vmcs, 0xccccccccccccccccull);
18374fe6c29SRuslan Bukin
18474fe6c29SRuslan Bukin return ptu_passed();
18574fe6c29SRuslan Bukin }
18674fe6c29SRuslan Bukin
to_user_big(void)18774fe6c29SRuslan Bukin static struct ptunit_result to_user_big(void)
18874fe6c29SRuslan Bukin {
18974fe6c29SRuslan Bukin struct pt_asid asid, user;
19074fe6c29SRuslan Bukin int errcode;
19174fe6c29SRuslan Bukin
19274fe6c29SRuslan Bukin memset(&user, 0xcc, sizeof(user));
19374fe6c29SRuslan Bukin pt_asid_init(&asid);
19474fe6c29SRuslan Bukin asid.cr3 = 0x4200ull;
19574fe6c29SRuslan Bukin asid.vmcs = 0x23000ull;
19674fe6c29SRuslan Bukin
19774fe6c29SRuslan Bukin errcode = pt_asid_to_user(&user, &asid, sizeof(user) + 8);
19874fe6c29SRuslan Bukin ptu_int_eq(errcode, 0);
19974fe6c29SRuslan Bukin ptu_uint_eq(user.size, sizeof(asid));
20074fe6c29SRuslan Bukin ptu_uint_eq(user.cr3, 0x4200ull);
20174fe6c29SRuslan Bukin ptu_uint_eq(user.vmcs, 0x23000ull);
20274fe6c29SRuslan Bukin
20374fe6c29SRuslan Bukin return ptu_passed();
20474fe6c29SRuslan Bukin }
20574fe6c29SRuslan Bukin
to_user(void)20674fe6c29SRuslan Bukin static struct ptunit_result to_user(void)
20774fe6c29SRuslan Bukin {
20874fe6c29SRuslan Bukin struct pt_asid asid, user;
20974fe6c29SRuslan Bukin int errcode;
21074fe6c29SRuslan Bukin
21174fe6c29SRuslan Bukin memset(&user, 0xcc, sizeof(user));
21274fe6c29SRuslan Bukin pt_asid_init(&asid);
21374fe6c29SRuslan Bukin asid.cr3 = 0x4200ull;
21474fe6c29SRuslan Bukin asid.vmcs = 0x23000ull;
21574fe6c29SRuslan Bukin
21674fe6c29SRuslan Bukin errcode = pt_asid_to_user(&user, &asid, sizeof(user));
21774fe6c29SRuslan Bukin ptu_int_eq(errcode, 0);
21874fe6c29SRuslan Bukin ptu_uint_eq(user.size, sizeof(asid));
21974fe6c29SRuslan Bukin ptu_uint_eq(user.cr3, 0x4200ull);
22074fe6c29SRuslan Bukin ptu_uint_eq(user.vmcs, 0x23000ull);
22174fe6c29SRuslan Bukin
22274fe6c29SRuslan Bukin return ptu_passed();
22374fe6c29SRuslan Bukin }
22474fe6c29SRuslan Bukin
to_user_cr3(void)22574fe6c29SRuslan Bukin static struct ptunit_result to_user_cr3(void)
22674fe6c29SRuslan Bukin {
22774fe6c29SRuslan Bukin struct pt_asid asid, user;
22874fe6c29SRuslan Bukin int errcode;
22974fe6c29SRuslan Bukin
23074fe6c29SRuslan Bukin memset(&user, 0xcc, sizeof(user));
23174fe6c29SRuslan Bukin pt_asid_init(&asid);
23274fe6c29SRuslan Bukin asid.cr3 = 0x4200ull;
23374fe6c29SRuslan Bukin
23474fe6c29SRuslan Bukin errcode = pt_asid_to_user(&user, &asid, offsetof(struct pt_asid, vmcs));
23574fe6c29SRuslan Bukin ptu_int_eq(errcode, 0);
23674fe6c29SRuslan Bukin ptu_uint_eq(user.size, offsetof(struct pt_asid, vmcs));
23774fe6c29SRuslan Bukin ptu_uint_eq(user.cr3, 0x4200ull);
23874fe6c29SRuslan Bukin ptu_uint_eq(user.vmcs, 0xccccccccccccccccull);
23974fe6c29SRuslan Bukin
24074fe6c29SRuslan Bukin return ptu_passed();
24174fe6c29SRuslan Bukin }
24274fe6c29SRuslan Bukin
match_null(void)24374fe6c29SRuslan Bukin static struct ptunit_result match_null(void)
24474fe6c29SRuslan Bukin {
24574fe6c29SRuslan Bukin struct pt_asid asid;
24674fe6c29SRuslan Bukin int errcode;
24774fe6c29SRuslan Bukin
24874fe6c29SRuslan Bukin pt_asid_init(&asid);
24974fe6c29SRuslan Bukin
25074fe6c29SRuslan Bukin errcode = pt_asid_match(NULL, NULL);
25174fe6c29SRuslan Bukin ptu_int_eq(errcode, -pte_internal);
25274fe6c29SRuslan Bukin
25374fe6c29SRuslan Bukin errcode = pt_asid_match(NULL, &asid);
25474fe6c29SRuslan Bukin ptu_int_eq(errcode, -pte_internal);
25574fe6c29SRuslan Bukin
25674fe6c29SRuslan Bukin errcode = pt_asid_match(&asid, NULL);
25774fe6c29SRuslan Bukin ptu_int_eq(errcode, -pte_internal);
25874fe6c29SRuslan Bukin
25974fe6c29SRuslan Bukin return ptu_passed();
26074fe6c29SRuslan Bukin }
26174fe6c29SRuslan Bukin
match_default(void)26274fe6c29SRuslan Bukin static struct ptunit_result match_default(void)
26374fe6c29SRuslan Bukin {
26474fe6c29SRuslan Bukin struct pt_asid lhs, rhs;
26574fe6c29SRuslan Bukin int errcode;
26674fe6c29SRuslan Bukin
26774fe6c29SRuslan Bukin pt_asid_init(&lhs);
26874fe6c29SRuslan Bukin pt_asid_init(&rhs);
26974fe6c29SRuslan Bukin
27074fe6c29SRuslan Bukin errcode = pt_asid_match(&lhs, &rhs);
27174fe6c29SRuslan Bukin ptu_int_eq(errcode, 1);
27274fe6c29SRuslan Bukin
27374fe6c29SRuslan Bukin lhs.cr3 = 0x2300ull;
27474fe6c29SRuslan Bukin lhs.vmcs = 0x42000ull;
27574fe6c29SRuslan Bukin
27674fe6c29SRuslan Bukin errcode = pt_asid_match(&lhs, &rhs);
27774fe6c29SRuslan Bukin ptu_int_eq(errcode, 1);
27874fe6c29SRuslan Bukin
27974fe6c29SRuslan Bukin errcode = pt_asid_match(&rhs, &lhs);
28074fe6c29SRuslan Bukin ptu_int_eq(errcode, 1);
28174fe6c29SRuslan Bukin
28274fe6c29SRuslan Bukin return ptu_passed();
28374fe6c29SRuslan Bukin }
28474fe6c29SRuslan Bukin
match_default_mixed(void)28574fe6c29SRuslan Bukin static struct ptunit_result match_default_mixed(void)
28674fe6c29SRuslan Bukin {
28774fe6c29SRuslan Bukin struct pt_asid lhs, rhs;
28874fe6c29SRuslan Bukin int errcode;
28974fe6c29SRuslan Bukin
29074fe6c29SRuslan Bukin pt_asid_init(&lhs);
29174fe6c29SRuslan Bukin pt_asid_init(&rhs);
29274fe6c29SRuslan Bukin
29374fe6c29SRuslan Bukin errcode = pt_asid_match(&lhs, &rhs);
29474fe6c29SRuslan Bukin ptu_int_eq(errcode, 1);
29574fe6c29SRuslan Bukin
29674fe6c29SRuslan Bukin lhs.cr3 = 0x2300ull;
29774fe6c29SRuslan Bukin rhs.vmcs = 0x42000ull;
29874fe6c29SRuslan Bukin
29974fe6c29SRuslan Bukin errcode = pt_asid_match(&lhs, &rhs);
30074fe6c29SRuslan Bukin ptu_int_eq(errcode, 1);
30174fe6c29SRuslan Bukin
30274fe6c29SRuslan Bukin errcode = pt_asid_match(&rhs, &lhs);
30374fe6c29SRuslan Bukin ptu_int_eq(errcode, 1);
30474fe6c29SRuslan Bukin
30574fe6c29SRuslan Bukin return ptu_passed();
30674fe6c29SRuslan Bukin }
30774fe6c29SRuslan Bukin
match_cr3(void)30874fe6c29SRuslan Bukin static struct ptunit_result match_cr3(void)
30974fe6c29SRuslan Bukin {
31074fe6c29SRuslan Bukin struct pt_asid lhs, rhs;
31174fe6c29SRuslan Bukin int errcode;
31274fe6c29SRuslan Bukin
31374fe6c29SRuslan Bukin pt_asid_init(&lhs);
31474fe6c29SRuslan Bukin pt_asid_init(&rhs);
31574fe6c29SRuslan Bukin
31674fe6c29SRuslan Bukin lhs.cr3 = 0x2300ull;
31774fe6c29SRuslan Bukin rhs.cr3 = 0x2300ull;
31874fe6c29SRuslan Bukin
31974fe6c29SRuslan Bukin errcode = pt_asid_match(&lhs, &rhs);
32074fe6c29SRuslan Bukin ptu_int_eq(errcode, 1);
32174fe6c29SRuslan Bukin
32274fe6c29SRuslan Bukin return ptu_passed();
32374fe6c29SRuslan Bukin }
32474fe6c29SRuslan Bukin
match_vmcs(void)32574fe6c29SRuslan Bukin static struct ptunit_result match_vmcs(void)
32674fe6c29SRuslan Bukin {
32774fe6c29SRuslan Bukin struct pt_asid lhs, rhs;
32874fe6c29SRuslan Bukin int errcode;
32974fe6c29SRuslan Bukin
33074fe6c29SRuslan Bukin pt_asid_init(&lhs);
33174fe6c29SRuslan Bukin pt_asid_init(&rhs);
33274fe6c29SRuslan Bukin
33374fe6c29SRuslan Bukin lhs.vmcs = 0x23000ull;
33474fe6c29SRuslan Bukin rhs.vmcs = 0x23000ull;
33574fe6c29SRuslan Bukin
33674fe6c29SRuslan Bukin errcode = pt_asid_match(&lhs, &rhs);
33774fe6c29SRuslan Bukin ptu_int_eq(errcode, 1);
33874fe6c29SRuslan Bukin
33974fe6c29SRuslan Bukin return ptu_passed();
34074fe6c29SRuslan Bukin }
34174fe6c29SRuslan Bukin
match(void)34274fe6c29SRuslan Bukin static struct ptunit_result match(void)
34374fe6c29SRuslan Bukin {
34474fe6c29SRuslan Bukin struct pt_asid lhs, rhs;
34574fe6c29SRuslan Bukin int errcode;
34674fe6c29SRuslan Bukin
34774fe6c29SRuslan Bukin pt_asid_init(&lhs);
34874fe6c29SRuslan Bukin pt_asid_init(&rhs);
34974fe6c29SRuslan Bukin
35074fe6c29SRuslan Bukin lhs.cr3 = 0x2300ull;
35174fe6c29SRuslan Bukin rhs.cr3 = 0x2300ull;
35274fe6c29SRuslan Bukin lhs.vmcs = 0x23000ull;
35374fe6c29SRuslan Bukin rhs.vmcs = 0x23000ull;
35474fe6c29SRuslan Bukin
35574fe6c29SRuslan Bukin errcode = pt_asid_match(&lhs, &rhs);
35674fe6c29SRuslan Bukin ptu_int_eq(errcode, 1);
35774fe6c29SRuslan Bukin
35874fe6c29SRuslan Bukin return ptu_passed();
35974fe6c29SRuslan Bukin }
36074fe6c29SRuslan Bukin
match_cr3_false(void)36174fe6c29SRuslan Bukin static struct ptunit_result match_cr3_false(void)
36274fe6c29SRuslan Bukin {
36374fe6c29SRuslan Bukin struct pt_asid lhs, rhs;
36474fe6c29SRuslan Bukin int errcode;
36574fe6c29SRuslan Bukin
36674fe6c29SRuslan Bukin pt_asid_init(&lhs);
36774fe6c29SRuslan Bukin pt_asid_init(&rhs);
36874fe6c29SRuslan Bukin
36974fe6c29SRuslan Bukin lhs.cr3 = 0x4200ull;
37074fe6c29SRuslan Bukin rhs.cr3 = 0x2300ull;
37174fe6c29SRuslan Bukin
37274fe6c29SRuslan Bukin errcode = pt_asid_match(&lhs, &rhs);
37374fe6c29SRuslan Bukin ptu_int_eq(errcode, 0);
37474fe6c29SRuslan Bukin
37574fe6c29SRuslan Bukin return ptu_passed();
37674fe6c29SRuslan Bukin }
37774fe6c29SRuslan Bukin
match_vmcs_false(void)37874fe6c29SRuslan Bukin static struct ptunit_result match_vmcs_false(void)
37974fe6c29SRuslan Bukin {
38074fe6c29SRuslan Bukin struct pt_asid lhs, rhs;
38174fe6c29SRuslan Bukin int errcode;
38274fe6c29SRuslan Bukin
38374fe6c29SRuslan Bukin pt_asid_init(&lhs);
38474fe6c29SRuslan Bukin pt_asid_init(&rhs);
38574fe6c29SRuslan Bukin
38674fe6c29SRuslan Bukin lhs.vmcs = 0x42000ull;
38774fe6c29SRuslan Bukin rhs.vmcs = 0x23000ull;
38874fe6c29SRuslan Bukin
38974fe6c29SRuslan Bukin errcode = pt_asid_match(&lhs, &rhs);
39074fe6c29SRuslan Bukin ptu_int_eq(errcode, 0);
39174fe6c29SRuslan Bukin
39274fe6c29SRuslan Bukin return ptu_passed();
39374fe6c29SRuslan Bukin }
39474fe6c29SRuslan Bukin
main(int argc,char ** argv)39574fe6c29SRuslan Bukin int main(int argc, char **argv)
39674fe6c29SRuslan Bukin {
39774fe6c29SRuslan Bukin struct ptunit_suite suite;
39874fe6c29SRuslan Bukin
39974fe6c29SRuslan Bukin suite = ptunit_mk_suite(argc, argv);
40074fe6c29SRuslan Bukin
40174fe6c29SRuslan Bukin ptu_run(suite, from_user_null);
40274fe6c29SRuslan Bukin ptu_run(suite, from_user_default);
40374fe6c29SRuslan Bukin ptu_run(suite, from_user_small);
40474fe6c29SRuslan Bukin ptu_run(suite, from_user_big);
40574fe6c29SRuslan Bukin ptu_run(suite, from_user);
40674fe6c29SRuslan Bukin ptu_run(suite, from_user_cr3);
40774fe6c29SRuslan Bukin
40874fe6c29SRuslan Bukin ptu_run(suite, to_user_null);
40974fe6c29SRuslan Bukin ptu_run(suite, to_user_too_small);
41074fe6c29SRuslan Bukin ptu_run(suite, to_user_small);
41174fe6c29SRuslan Bukin ptu_run(suite, to_user_big);
41274fe6c29SRuslan Bukin ptu_run(suite, to_user);
41374fe6c29SRuslan Bukin ptu_run(suite, to_user_cr3);
41474fe6c29SRuslan Bukin
41574fe6c29SRuslan Bukin ptu_run(suite, match_null);
41674fe6c29SRuslan Bukin ptu_run(suite, match_default);
41774fe6c29SRuslan Bukin ptu_run(suite, match_default_mixed);
41874fe6c29SRuslan Bukin ptu_run(suite, match_cr3);
41974fe6c29SRuslan Bukin ptu_run(suite, match_vmcs);
42074fe6c29SRuslan Bukin ptu_run(suite, match);
42174fe6c29SRuslan Bukin ptu_run(suite, match_cr3_false);
42274fe6c29SRuslan Bukin ptu_run(suite, match_vmcs_false);
42374fe6c29SRuslan Bukin
42474fe6c29SRuslan Bukin return ptunit_report(&suite);
42574fe6c29SRuslan Bukin }
426