cachepc-qemu

Fork of AMDESE/qemu with changes for cachepc side-channel attack
git clone https://git.sinitax.com/sinitax/cachepc-qemu
Log | Files | Refs | Submodules | LICENSE | sfeed.txt

270 (2810B)


      1#!/usr/bin/env bash
      2# group: rw backing quick
      3#
      4# Test large write to a qcow2 image
      5#
      6# Copyright (C) 2019 Red Hat, Inc.
      7#
      8# This program is free software; you can redistribute it and/or modify
      9# it under the terms of the GNU General Public License as published by
     10# the Free Software Foundation; either version 2 of the License, or
     11# (at your option) any later version.
     12#
     13# This program is distributed in the hope that it will be useful,
     14# but WITHOUT ANY WARRANTY; without even the implied warranty of
     15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     16# GNU General Public License for more details.
     17#
     18# You should have received a copy of the GNU General Public License
     19# along with this program.  If not, see <http://www.gnu.org/licenses/>.
     20#
     21
     22seq=$(basename "$0")
     23echo "QA output created by $seq"
     24
     25status=1	# failure is the default!
     26
     27_cleanup()
     28{
     29    _cleanup_test_img
     30}
     31trap "_cleanup; exit \$status" 0 1 2 3 15
     32
     33# get standard environment, filters and checks
     34. ./common.rc
     35. ./common.filter
     36
     37# This is a qcow2 regression test
     38_supported_fmt qcow2
     39_supported_proto file
     40_supported_os Linux
     41
     42# We use our own external data file and our own cluster size, and we
     43# require v3 images
     44_unsupported_imgopts data_file cluster_size 'compat=0.10'
     45
     46
     47# We need a backing file so that handle_alloc_space() will not do
     48# anything.  (If it were to do anything, it would simply fail its
     49# write-zeroes request because the request range is too large.)
     50TEST_IMG="$TEST_IMG.base" _make_test_img 4G
     51$QEMU_IO -c 'write 0 512' "$TEST_IMG.base" | _filter_qemu_io
     52
     53# (Use .orig because _cleanup_test_img will remove that file)
     54# We need a large cluster size, see below for why (above the $QEMU_IO
     55# invocation)
     56_make_test_img -o cluster_size=2M,data_file="$TEST_IMG.orig" \
     57    -b "$TEST_IMG.base" -F $IMGFMT 4G
     58
     59# We want a null-co as the data file, because it allows us to quickly
     60# "write" 2G of data without using any space.
     61# (qemu-img create does not like it, though, because null-co does not
     62# support image creation.)
     63$QEMU_IMG amend -o data_file="json:{'driver':'null-co',,'size':'4294967296'}" \
     64    "$TEST_IMG"
     65
     66# This gives us a range of:
     67#   2^31 - 512 + 768 - 1 = 2^31 + 255 > 2^31
     68# until the beginning of the end COW block.  (The total allocation
     69# size depends on the cluster size, but all that is important is that
     70# it exceeds INT_MAX.)
     71#
     72# 2^31 - 512 is the maximum request size.  We want this to result in a
     73# single allocation, and because the qcow2 driver splits allocations
     74# on L2 boundaries, we need large L2 tables; hence the cluster size of
     75# 2 MB.  (Anything from 256 kB should work, though, because then one L2
     76# table covers 8 GB.)
     77$QEMU_IO -c "write 768 $((2 ** 31 - 512))" "$TEST_IMG" | _filter_qemu_io
     78
     79_check_test_img
     80
     81# success, all done
     82echo "*** done"
     83rm -f $seq.full
     84status=0