Пример #1
0
    def test_Class_configure_more_free_buddies_and_mmap(self):
        pageflags = kpageflags.FlagsDataSource(kpageflags.KPageFlags,
                                               "/proc/kpageflags")

        requests = []
        free_buddies = find_free_buddy_pfns(pageflags, 0x100)
        for pfn in free_buddies:
            requests.append(
                physmem.Phys_mem_frame_request(pfn, self.allowed_sources))

        config = self.util_Class_configure(requests)

        claimed = 0

        for request, answer in zip(requests, config):
            # Test, if the request has been properly copied over to the configuration
            self.assertEqual(
                request.requested_pfn, answer.request.requested_pfn,
                "request.requested_pfn differs from the request read from the device"
            )
            self.assertEqual(
                request.allowed_sources, answer.request.allowed_sources,
                "request.allowed_sources differs from the request read from the device"
            )

            # print(answer)
            if (answer.is_claimed()):
                claimed += 1

        print("Claimed: %d of %d" % (claimed, len(requests)))
        with self.device.mmap(claimed * 4096) as map:
            pass
Пример #2
0
    def test_Class_configure_no_buddy_allocs_from_hwpoison(self):
        pageflags = kpageflags.FlagsDataSource(kpageflags.KPageFlags,
                                               "/proc/kpageflags")

        allowed_sources = physmem.SOURCE_HW_POISON_ANON | physmem.SOURCE_HW_POISON_PAGE_CACHE

        requests = []
        free_buddies = find_free_buddy_pfns(pageflags, 0x100)
        for pfn in free_buddies:
            requests.append(
                physmem.Phys_mem_frame_request(pfn, allowed_sources))

        config = self.util_Class_configure(requests)

        claimed = 0

        for request, answer in zip(requests, config):
            # Test, if the request has been properly copied over to the configuration
            self.assertEqual(
                request.requested_pfn, answer.request.requested_pfn,
                "request.requested_pfn differs from the request read from the device"
            )
            self.assertEqual(
                request.allowed_sources, answer.request.allowed_sources,
                "request.allowed_sources differs from the request read from the device"
            )

            # print(answer)
            if (answer.is_claimed()):
                claimed += 1

        self.assertEqual(
            0, claimed,
            "Claimed: %d of %d, although no buddy pages should be claimed by the hw-poison claimer"
            % (claimed, len(requests)))
Пример #3
0
    def test_Class_configure_more_elements(self):
        requests = []
        for pfn in xrange(0x40000, 0x40100):
            requests.append(
                physmem.Phys_mem_frame_request(pfn, self.allowed_sources))

        config = self.util_Class_configure(requests)

        claimed = 0

        for request, answer in zip(requests, config):
            # Test, if the request has been properly copied over to the configuration
            self.assertEqual(
                request.requested_pfn, answer.request.requested_pfn,
                "request.requested_pfn differs from the request read from the device"
            )
            self.assertEqual(
                request.allowed_sources, answer.request.allowed_sources,
                "request.allowed_sources differs from the request read from the device"
            )

            # print(answer)
            if (answer.is_claimed()):
                claimed += 1

        print("Claimed: %d of %d" % (claimed, len(requests)))
Пример #4
0
    def testIOCTL_no_element_but_data(self):
        with open(self.device_name, "rb") as f:
            # IOCTL:
            protocol_version = 1
            num_requests = 0

            pfn_request = physmem.Phys_mem_frame_request(1, 1)
            preq = pointer(pfn_request)

            arg = physmem.Phys_mem_request(protocol_version, num_requests,
                                           preq)
            rv = fcntl.ioctl(f, self.IOCTL_CONFIGURE, arg)
Пример #5
0
 def _claim_pfns(self, pfns,allowed_sources):
     requests = []
     for pfn in pfns:
         requests.append(physmem.Phys_mem_frame_request(pfn, allowed_sources))
      
     self.physmem_device.configure(requests)
     config = self.physmem_device.read_configuration()
     
     if not ( len(requests) ==  len(config) ) :
         # Error
         raise RuntimeError("The result read from the physmem-device contains %d elements, but I expected %d elements! " %  (len(config),len(requests)))
     
     return config
Пример #6
0
    def test_Class_configure_one_element(self):
        requests = [
            physmem.Phys_mem_frame_request(10000, self.allowed_sources)
        ]

        config = self.util_Class_configure(requests)

        for request, answer in zip(requests, config):
            # Test, if the request has been properly copied over to the configuration
            self.assertEqual(
                request.requested_pfn, answer.request.requested_pfn,
                "request.requested_pfn differs from the request read from the device"
            )
            self.assertEqual(
                request.allowed_sources, answer.request.allowed_sources,
                "request.allowed_sources differs from the request read from the device"
            )

            print(answer)
            if (answer.is_claimed()):
                print("Claimed!")
Пример #7
0
    def configure_mmap_and_test(self, pfns, allowed_sources=None):
        """  Claim and test the pageframes named by the list of PFNs by using the allowed_sources.
                  The tests include mapping and a basic memory test
            """

        if None == allowed_sources: allowed_sources = self.allowed_sources

        pageflags = kpageflags.FlagsDataSource('flags', "/proc/kpageflags")

        pagecount = kpagecount.CountDataSource('count', "/proc/kpagecount")

        requests = []
        for pfn in pfns:
            requests.append(
                physmem.Phys_mem_frame_request(pfn, allowed_sources))

        config = self.util_Class_configure(requests)

        claimed = 0

        with pageflags.open() as pf:
            with pagecount.open() as pc:
                for request, answer in zip(requests, config):
                    # Test, if the request has been properly copied over to the configuration
                    self.assertEqual(
                        request.requested_pfn, answer.request.requested_pfn,
                        "request.requested_pfn differs from the request read from the device"
                    )
                    self.assertEqual(
                        request.allowed_sources,
                        answer.request.allowed_sources,
                        "request.allowed_sources differs from the request read from the device"
                    )

                    # print(answer)
                    if (answer.is_claimed()):
                        claimed += 1
                        pfn = answer.pfn

                        self.assertEqual(request.requested_pfn, answer.pfn,
                                         "requested and aquired pfn differ")

                        flags = pf[pfn]
                        count = pc[pfn]

                        self.failIfEqual(
                            None, flags,
                            "Could not read flags for pfn %d" % (pfn, ))
                        self.failIfEqual(
                            None, count,
                            "Could not read count for pfn %d" % (pfn, ))

                        # self.assertFalse(flags.all_set_in(kpageflags.BUDDY),"The page should no longer be a free buddy page. The flags are %s" %(flags,)  )
                        #self.failIfEqual(0, flags.flags,"No  flags set for pfn %d" % (pfn,))

                        # We did not map the page yet, so expect 0 mapcount
                        # http://fixunix.com/kernel/488903-patch-2-5-pagemap-change-kpagecount-return-map-count-not-reference-count-page.html
                        self.assertTrue(
                            count == 0,
                            "Pagecount should be 0, but is %d" % (count, ))

                print("Claimed: %d of %d" % (claimed, len(requests)))

                self.assertTrue(
                    claimed > 0, "No pages claimed using method(s) 0x%x " %
                    (allowed_sources, ))

                size = claimed * 4096
                with self.device.mmap(size) as map:
                    self.failIfEqual(None, map, "No map returned")
                    self.assertEquals(
                        0, map.tell(),
                        "Pointer into mapping should start at 0")

                    # test mapcont
                    for answer in config:
                        if (answer.is_claimed()):
                            pfn = answer.pfn

                            flags = pf[pfn]
                            count = pc[pfn]

                            self.failIfEqual(
                                None, flags,
                                "Could not read flags for pfn %d" % (pfn, ))
                            self.failIfEqual(
                                None, count,
                                "Could not read count for pfn %d" % (pfn, ))

                            # We did  map the page yet, so expect 1 mapcount
                            # http://fixunix.com/kernel/488903-patch-2-5-pagemap-change-kpagecount-return-map-count-not-reference-count-page.html
                            self.assertTrue(
                                count == 1,
                                "Pagecount should be 1 becuase we did map the page, but is %d"
                                % (count, ))

                    for i in xrange(0, size):
                        map.write_byte(chr(i % 0xff))

                    self.assertEqual(size, map.tell(),
                                     "Did not reach end of file")
                    map.seek(0)
                    self.assertEquals(
                        0, map.tell(),
                        "After seek(0): Pointer into mapping should be at 0")

                    for i in xrange(0, size):
                        expected = i % 0xff
                        found = ord(map.read_byte())
                        self.assertEqual(
                            expected, found,
                            "Expected value %x at %d, not %x" %
                            (expected, i, found))