tools/testing/selftests/kvm/s390/keyop.c

Source file repositories/reference/linux-study-clean/tools/testing/selftests/kvm/s390/keyop.c

File Facts

System
Linux kernel
Corpus path
tools/testing/selftests/kvm/s390/keyop.c
Extension
.c
Size
7692 bytes
Lines
300
Domain
Support Tooling And Documentation
Bucket
tools
Inferred role
Support Tooling And Documentation: implementation source
Status
source implementation candidate

Why This File Exists

Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.

Dependency Surface

Detected Declarations

Annotated Snippet

if (expected[i] != what[i]) {
			dump_sk(expected, "Expected");
			dump_sk(what, "Got");
		}
		TEST_ASSERT(expected[i] == what[i],
			    "%s! fault-in location %d, page %d, expected %#x, got %#x",
			    descr, fault_in_loc, i, expected[i], what[i]);
	}
}

static inline void clear_all(void)
{
	memset(tmp, 0, BUF_PAGES);
	memset(old, 0, BUF_PAGES);
	memset(expected, 0, BUF_PAGES);
}

static void test_init(struct kvm_vcpu *vcpu, int fault_in)
{
	/* Set all storage keys to zero */
	fault_in_buffer(vcpu, fault_in, 1);
	set_skeys(vcpu, expected);

	fault_in_buffer(vcpu, fault_in, 2);
	get_skeys(vcpu, tmp);
	compare(tmp, expected, "Setting keys not zero", fault_in);

	/* Set storage keys to a sequential pattern */
	fault_in_buffer(vcpu, fault_in, 3);
	set_pattern(expected);
	set_skeys(vcpu, expected);

	fault_in_buffer(vcpu, fault_in, 4);
	get_skeys(vcpu, tmp);
	compare(tmp, expected, "Setting storage keys failed", fault_in);
}

static void test_rrbe(struct kvm_vcpu *vcpu, int fault_in)
{
	unsigned char k;
	int i;

	/* Set storage keys to a sequential pattern */
	fault_in_buffer(vcpu, fault_in, 1);
	set_pattern(expected);
	set_skeys(vcpu, expected);

	/* Call the RRBE KEYOP ioctl on each page and verify the result */
	fault_in_buffer(vcpu, fault_in, 2);
	for (i = 0; i < BUF_PAGES; i++) {
		k = do_keyop(vcpu, KVM_S390_KEYOP_RRBE, i, 0xff);
		TEST_ASSERT((expected[i] & KEY_BITS_RC) == k,
			    "Old R or C value mismatch! expected: %#x, got %#x",
			    expected[i] & KEY_BITS_RC, k);
		if (i == BUF_PAGES / 2)
			fault_in_buffer(vcpu, fault_in, 3);
	}

	for (i = 0; i < BUF_PAGES; i++)
		expected[i] &= ~KEY_BIT_R;

	/* Verify that only the R bit has been cleared */
	fault_in_buffer(vcpu, fault_in, 4);
	get_skeys(vcpu, tmp);
	compare(tmp, expected, "New value mismatch", fault_in);
}

static void test_iske(struct kvm_vcpu *vcpu, int fault_in)
{
	int i;

	/* Set storage keys to a sequential pattern */
	fault_in_buffer(vcpu, fault_in, 1);
	set_pattern(expected);
	set_skeys(vcpu, expected);

	/* Call the ISKE KEYOP ioctl on each page and verify the result */
	fault_in_buffer(vcpu, fault_in, 2);
	for (i = 0; i < BUF_PAGES; i++) {
		tmp[i] = do_keyop(vcpu, KVM_S390_KEYOP_ISKE, i, 0xff);
		if (i == BUF_PAGES / 2)
			fault_in_buffer(vcpu, fault_in, 3);
	}
	compare(tmp, expected, "Old value mismatch", fault_in);

	/* Check storage keys have not changed */
	fault_in_buffer(vcpu, fault_in, 4);
	get_skeys(vcpu, tmp);
	compare(tmp, expected, "Storage keys values changed", fault_in);
}

Annotation

Implementation Notes