From nobody Thu Apr 18 20:43:59 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1570548007; cv=none; d=zoho.com; s=zohoarc; b=QI4Se2aJ1c9fEIFPhYqo08rYgK5IgvBzNd7vUNVo6Ac3FrL+KJK3E9A7dpRjAr86o+UmjcaIgLzQJDpBDXc+slCpe0iINZouFYD7Vyy7zSgmfaq6K422ntuYrq/YQpwJf0A3ArcBoH0vf6o0FtSFVCixB2Qaao+hlmSpvCl42kY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1570548007; h=Content-Type:Content-Transfer-Encoding:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=qH2NdemFcehs0dsi6rIm+ZLWq2uA31nyciFkuhQjkDY=; b=TkFZ+odDSx19Afl9na6lujsMQD5+rXJ/u+yzWkAf9tLxFu+GOSipAaK8y1uN5RnytHjEZgRpw5Lh03bUvVjdqRI1ZJ+oUJKMjdO3MZsX3aRsmS/ECUebNJ4rLv7xgzUSXvvxHGe60EVwOBKYJn3XWy2ZMvLbxT+I+5E2KWPMMss= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1570548007704841.9823022308418; Tue, 8 Oct 2019 08:20:07 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E70C5307C820; Tue, 8 Oct 2019 15:20:04 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3C963600CE; Tue, 8 Oct 2019 15:20:04 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 3525724F30; Tue, 8 Oct 2019 15:20:03 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x98FK1bY004301 for ; Tue, 8 Oct 2019 11:20:01 -0400 Received: by smtp.corp.redhat.com (Postfix) id C3D715EE1D; Tue, 8 Oct 2019 15:20:01 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-112-66.ams2.redhat.com [10.36.112.66]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1E6645D71C; Tue, 8 Oct 2019 15:19:55 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Tue, 8 Oct 2019 16:19:54 +0100 Message-Id: <20191008151954.15173-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH] tests: delete objectlocking test code X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Tue, 08 Oct 2019 15:20:05 +0000 (UTC) The object locking test code is not run by any CI tests and has bitrotted to the point where it isn't worth the effort to try to fix it. Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Michal Privoznik --- .gitignore | 3 - configure.ac | 12 - tests/Makefile.am | 29 +- tests/objectlocking.ml | 819 ----------------------------------------- 4 files changed, 1 insertion(+), 862 deletions(-) delete mode 100644 tests/objectlocking.ml diff --git a/.gitignore b/.gitignore index 82495e8692..6b4b2096cc 100644 --- a/.gitignore +++ b/.gitignore @@ -231,9 +231,6 @@ !/tests/virsh-self-test !/tests/virt-aa-helper-test !/tests/virt-admin-self-test -/tests/objectlocking -/tests/objectlocking-files.txt -/tests/objectlocking.cm[ix] /tests/reconnect /tests/ssh /tests/test_file_access.txt diff --git a/configure.ac b/configure.ac index 40e93e251e..74d3aea10c 100644 --- a/configure.ac +++ b/configure.ac @@ -770,18 +770,6 @@ if test "$enable_test_coverage" =3D yes; then WARN_CFLAGS=3D$save_WARN_CFLAGS fi =20 -LIBVIRT_ARG_ENABLE([TEST_LOCKING], [thread locking tests using CIL], [no]) -case "$enable_test_locking" in - yes|no) ;; - *) AC_MSG_ERROR([bad value ${enable_test_locking} for test-locking optio= n]) ;; -esac - -if test "$enable_test_locking" =3D "yes"; then - LOCK_CHECKING_CFLAGS=3D"-save-temps" - AC_SUBST([LOCK_CHECKING_CFLAGS]) -fi -AM_CONDITIONAL([WITH_CIL],[test "$enable_test_locking" =3D "yes"]) - dnl Cygwin, MinGW and MSVC checks LIBVIRT_WIN_CHECK_COMMON LIBVIRT_WIN_CHECK_CYGWIN diff --git a/tests/Makefile.am b/tests/Makefile.am index d88ad7f686..10e1a5d78d 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -332,10 +332,6 @@ test_programs +=3D bhyvexml2argvtest bhyvexml2xmltest = bhyveargv2xmltest test_libraries +=3D libbhyvexml2argvmock.la libbhyveargv2xmlmock.la endif WITH_BHYVE =20 -if WITH_CIL -test_programs +=3D objectlocking -endif WITH_CIL - if WITH_YAJL test_programs +=3D virjsontest endif WITH_YAJL @@ -1547,27 +1543,4 @@ else ! WITH_LINUX EXTRA_DIST +=3D virscsitest.c endif ! WITH_LINUX =20 -if WITH_CIL -CILOPTFLAGS =3D -CILOPTINCS =3D -CILOPTPACKAGES =3D -package unix,str,cil -CILOPTLIBS =3D -linkpkg - -objectlocking_SOURCES =3D objectlocking.ml - -%.cmx: %.ml - ocamlfind ocamlopt $(CILOPTFLAGS) $(CILOPTINCS) $(CILOPTPACKAGES) -c $< - -objectlocking: objectlocking.cmx objectlocking-files.txt - ocamlfind ocamlopt $(CILOPTFLAGS) $(CILOPTINCS) $(CILOPTPACKAGES) \ - $(CILOPTLIBS) $< -o $@ - -objectlocking-files.txt: - find $(top_builddir)/src/ -name '*.i' > $@ - -else ! WITH_CIL -EXTRA_DIST +=3D objectlocking.ml -endif ! WITH_CIL - -CLEANFILES =3D *.cov *.gcov .libs/*.gcda .libs/*.gcno *.gcno *.gcda *.cmi = *.cmx \ - objectlocking-files.txt +CLEANFILES =3D *.cov *.gcov .libs/*.gcda .libs/*.gcno *.gcno *.gcda diff --git a/tests/objectlocking.ml b/tests/objectlocking.ml deleted file mode 100644 index 6726d29e73..0000000000 --- a/tests/objectlocking.ml +++ /dev/null @@ -1,819 +0,0 @@ -(* - * Analyse libvirt driver API methods for mutex locking mistakes - * - * Copyright (C) 2008-2010, 2012, 2014 Red Hat, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library. If not, see - * . - *) - -open Pretty -open Cil - -(* - * Convenient routine to load the contents of a file into - * a list of strings - *) -let input_file filename =3D - let chan =3D open_in filename in - let lines =3D ref [] in - try while true; do lines :=3D input_line chan :: !lines done; [] - with - End_of_file -> close_in chan; List.rev !lines - -module DF =3D Dataflow -module UD =3D Usedef -module IH =3D Inthash -module E =3D Errormsg -module VS =3D UD.VS - -let debug =3D ref false - - -let driverTables =3D [ - "virDriver"; - "virNetworkDriver"; - "virStorageDriver"; - "virNodeDeviceDriver"; -(* "virStateDriver"; Disable for now, since shutdown/startup have weird l= ocking rules *) -] - -(* - * This is the list of all libvirt methods which return - * pointers to locked objects - *) -let lockedObjMethods =3D [ - "virDomainFindByID"; - "virDomainFindByUUID"; - "virDomainFindByName"; - "virDomainAssignDef"; - - "virNetworkObjFindByUUID"; - "virNetworkObjFindByName"; - "virNetworkAssignDef"; - - "virNodeDeviceFindByName"; - "virNodeDeviceAssignDef"; - - "virStoragePoolObjFindByUUID"; - "virStoragePoolObjFindByName"; - "virStoragePoolObjAssignDef" -] - - -(* - * This is the list of all libvirt methods which - * can release an object lock. Technically we - * ought to pair them up correctly with previous - * ones, but the compiler can already complain - * about passing a virNetworkObjPtr to a virDomainObjUnlock - * method so lets be lazy - *) -let objectLockMethods =3D [ - "virDomainObjLock"; - "virStoragePoolObjLock"; - "virNodeDevObjLock" -] - -(* - * This is the list of all libvirt methods which - * can release an object lock. Technically we - * ought to pair them up correctly with previous - * ones, but the compiler can already complain - * about passing a virNetworkObjPtr to a virDomainObjUnlock - * method so lets be lazy - *) -let objectUnlockMethods =3D [ - "virDomainObjUnlock"; - "virStoragePoolObjUnlock"; - "virNodeDevObjUnlock" -] - -(* - * The data types that the previous two sets of - * methods operate on - *) -let lockableObjects =3D [ - "virDomainObjPtr"; - "virNetworkObjPtr"; - "virStoragePoolObjPtr"; - "virNodeDevObjPtr" -] - - - -(* - * The methods which globally lock an entire driver - *) -let driverLockMethods =3D [ - "qemuDriverLock"; - "openvzDriverLock"; - "testDriverLock"; - "lxcDriverLock"; - "nodedevDriverLock"; - "networkDriverLock"; - "storageDriverLock"; - "oneDriverLock" -] - -(* - * The methods which globally unlock an entire driver - *) -let driverUnlockMethods =3D [ - "qemuDriverUnlock"; - "openvzDriverUnlock"; - "testDriverUnlock"; - "lxcDriverUnlock"; - "nodedevDriverUnlock"; - "networkDriverUnlock"; - "storageDriverUnlock"; - "oneDriverUnlock" -] - -(* - * The data types that the previous two sets of - * methods operate on. These may be structs or - * typedefs, we don't care - *) -let lockableDrivers =3D [ - "qemud_driver"; - "openvz_driver"; - "testConnPtr"; - "lxc_driver_t"; - "virStorageDriverStatePtr"; - "network_driver"; - "virNodeDeviceState"; - "one_driver_t"; -] - - -let isFuncCallLval lval methodList =3D - match lval with - Var vi, o -> - List.mem vi.vname methodList - | _ -> false - -let isFuncCallExp exp methodList =3D - match exp with - Lval lval -> - isFuncCallLval lval methodList - | _ -> false - -let isFuncCallInstr instr methodList =3D - match instr with - Call (retval,exp,explist,srcloc) -> - isFuncCallExp exp methodList - | _ -> false - - - -let findDriverFunc init =3D - match init with - SingleInit (exp) -> ( - match exp with - AddrOf (lval) -> ( - match lval with - Var vi, o -> - true - | _ -> false - ) - | _ -> false - ) - | _ ->false - -let findDriverFuncs init =3D - match init with - CompoundInit (typ, list) -> - List.filter ( - fun l -> - match l with - (offset, init) -> - findDriverFunc init - - ) list; - | _ -> ([]) - - -let getDriverFuncs initinfo =3D - match initinfo.init with - Some (i) -> - let ls =3D findDriverFuncs i in - ls - | _ -> [] - -let getDriverFuncName init =3D - match init with - SingleInit (exp) -> ( - match exp with - AddrOf (lval) -> ( - match lval with - Var vi, o -> - - vi.vname - | _ -> "unknown" - ) - | _ -> "unknown" - ) - | _ -> "unknown" - - -let getDriverFuncNames initinfo =3D - List.map ( - fun l -> - match l with - (offset, init) -> - getDriverFuncName init - ) (getDriverFuncs initinfo) - - -(* - * Convenience methods which take a Cil.Instr object - * and ask whether its associated with one of the - * method sets defined earlier - *) -let isObjectFetchCall instr =3D - isFuncCallInstr instr lockedObjMethods - -let isObjectLockCall instr =3D - isFuncCallInstr instr objectLockMethods - -let isObjectUnlockCall instr =3D - isFuncCallInstr instr objectUnlockMethods - -let isDriverLockCall instr =3D - isFuncCallInstr instr driverLockMethods - -let isDriverUnlockCall instr =3D - isFuncCallInstr instr driverUnlockMethods - - -let isWantedType typ typeList =3D - match typ with - TNamed (tinfo, attrs) -> - List.mem tinfo.tname typeList - | TPtr (ptrtyp, attrs) -> - let f =3D match ptrtyp with - TNamed (tinfo2, attrs) -> - List.mem tinfo2.tname typeList - | TComp (cinfo, attrs) -> - List.mem cinfo.cname typeList - | _ -> - false in - f - | _ -> false - -(* - * Convenience methods which take a Cil.Varinfo object - * and ask whether it matches a variable datatype that - * we're interested in tracking for locking purposes - *) -let isLockableObjectVar varinfo =3D - isWantedType varinfo.vtype lockableObjects - -let isLockableDriverVar varinfo =3D - isWantedType varinfo.vtype lockableDrivers - -let isDriverTable varinfo =3D - isWantedType varinfo.vtype driverTables - - -(* - * Take a Cil.Exp object (ie an expression) and see whether - * the expression corresponds to a check for NULL against - * one of our interesting objects - * eg - * - * if (!vm) ... - * - * For a variable 'virDomainObjPtr vm' - *) -let isLockableThingNull exp funcheck =3D - match exp with - | UnOp (op,exp,typ) -> ( - match op with - LNot -> ( - match exp with - Lval (lhost, off) -> ( - match lhost with - Var vi -> - funcheck vi - | _ -> false - ) - | _ -> false - ) - | _ -> false - ) - | _ -> - false - -let isLockableObjectNull exp =3D - isLockableThingNull exp isLockableObjectVar - -let isLockableDriverNull exp =3D - isLockableThingNull exp isLockableDriverVar - - -(* - * Prior to validating a function, initialize these - * to VS.empty - * - * They contain the list of driver and object variables - * objects declared as local variables - * - *) -let lockableObjs: VS.t ref =3D ref VS.empty -let lockableDriver: VS.t ref =3D ref VS.empty - -(* - * Given a Cil.Instr object (ie a single instruction), get - * the list of all used & defined variables associated with - * it. Then caculate intersection with the driver and object - * variables we're interested in tracking and return four sets - * - * List of used driver variables - * List of defined driver variables - * List of used object variables - * List of defined object variables - *) -let computeUseDefState i =3D - let u, d =3D UD.computeUseDefInstr i in - let useo =3D VS.inter u !lockableObjs in - let defo =3D VS.inter d !lockableObjs in - let used =3D VS.inter u !lockableDriver in - let defd =3D VS.inter d !lockableDriver in - (used, defd, useo, defo) - - -(* Some crude helpers for debugging this horrible code *) -let printVI vi =3D - ignore(printf " | %a %s\n" d_type vi.vtype vi.vname) - -let printVS vs =3D - VS.iter printVI vs - - -let prettyprint2 stmdat () (_, ld, ud, lo, ui, uud, uuo, loud, ldlo, dead)= =3D - text "" - - -type ilist =3D Cil.instr list - -(* - * This module implements the Cil.DataFlow.ForwardsTransfer - * interface. This is what 'does the interesting stuff' - * when walking over a function's code paths - *) -module Locking =3D struct - let name =3D "Locking" - let debug =3D debug - - (* - * Our state currently consists of - * - * The set of driver variables that are locked - * The set of driver variables that are unlocked - * The set of object variables that are locked - * The set of object variables that are unlocked - * - * Lists of Cil.Instr for: - * - * Instrs using an unlocked driver variable - * Instrs using an unlocked object variable - * Instrs locking a object variable while not holding a locked driver = variable - * Instrs locking a driver variable while holding a locked object vari= able - * Instrs causing deadlock by fetching a lock object, while an object = is already locked - * - *) - type t =3D (unit * VS.t * VS.t * VS.t * VS.t * ilist * ilist * ilist * i= list * ilist) - - (* This holds an instance of our state data, per statement *) - let stmtStartData =3D IH.create 32 - - let pretty =3D - prettyprint2 stmtStartData - - let copy (_, ld, ud, lo, uo, uud, uuo, loud, ldlo, dead) =3D - ((), ld, ud, lo, uo, uud, uuo, loud, ldlo, dead) - - let computeFirstPredecessor stm (_, ld, ud, lo, uo, uud, uuo, loud, ldlo= , dead) =3D - ((), ld, ud, lo, uo, uud, uuo, loud, ldlo, dead) - - - (* - * Merge existing state for a statement, with new state - * - * If new and old state is the same, this returns None, - * If they are different, then returns the union. - *) - let combinePredecessors (stm:stmt) ~(old:t) ((_, ldn, udn, lon, uon, uud= n, uuon, loudn, ldlon, deadn):t) =3D - match old with (_, ldo, udo, loo,uoo, uudo, uuoo, loudo, ldloo, deado= )-> begin - let lde=3D (VS.equal ldo ldn) || ((VS.is_empty ldo) && (VS.is_empty l= dn)) in - let ude=3D VS.equal udo udn || ((VS.is_empty udo) && (VS.is_empty udn= )) in - let loe=3D VS.equal loo lon || ((VS.is_empty loo) && (VS.is_empty lon= )) in - let uoe=3D VS.equal uoo uon || ((VS.is_empty uoo) && (VS.is_empty uon= )) in - - if lde && ude && loe && uoe then - None - else ( - let ldret =3D VS.union ldo ldn in - let udret =3D VS.union udo udn in - let loret =3D VS.union loo lon in - let uoret =3D VS.union uoo uon in - Some ((), ldret, udret, loret, uoret, uudn, uuon, loudn, ldlon, d= eadn) - ) - end - - - (* - * This handles a Cil.Instr object. This is sortof a C level statement. - *) - let doInstr i (_, ld, ud, lo, uo, uud, uuo, loud, ldlo, dead) =3D - let transform (_, ld, ud, lo, uo, uud, uuo, loud, ldlo, dead) =3D - let used, defd, useo, defo =3D computeUseDefState i in - - - if isDriverLockCall i then ( - (* - * A driver was locked, so add to the list of locked - * driver variables, and remove from the unlocked list - *) - let retld =3D VS.union ld used in - let retud =3D VS.diff ud used in - - (* - * Report if any objects are locked already since - * thats a deadlock risk - *) - if VS.is_empty lo then - ((), retld, retud, lo, uo, uud, uuo, loud, ldlo, dead) - else - ((), retld, retud, lo, uo, uud, uuo, loud, List.append ldlo= [i], dead) - ) else if isDriverUnlockCall i then ( - (* - * A driver was unlocked, so add to the list of unlocked - * driver variables, and remove from the locked list - *) - let retld =3D VS.diff ld used in - let retud =3D VS.union ud used in - - ((), retld, retud, lo, uo, uud, uuo, loud, ldlo, dead); - ) else if isObjectFetchCall i then ( - (* - * A object was fetched & locked, so add to the list of - * locked driver variables. Nothing to remove from unlocked - * list here. - * - * XXX, not entirely true. We should check if they're - * blowing away an existing non-NULL value in the lval - * really. - *) - let retlo =3D VS.union lo defo in - - (* - * Report if driver is not locked, since that's a safety - * risk - *) - if VS.is_empty ld then ( - if VS.is_empty lo then ( - ((), ld, ud, retlo, uo, uud, uuo, List.append loud [i], l= dlo, dead) - ) else ( - ((), ld, ud, retlo, uo, uud, uuo, List.append loud [i], l= dlo, List.append dead [i]) - ) - ) else ( - if VS.is_empty lo then ( - ((), ld, ud, retlo, uo, uud, uuo, loud, ldlo, dead) - ) else ( - ((), ld, ud, retlo, uo, uud, uuo, loud, ldlo, List.append= dead [i]) - ) - ) - ) else if isObjectLockCall i then ( - (* - * A driver was locked, so add to the list of locked - * driver variables, and remove from the unlocked list - *) - let retlo =3D VS.union lo useo in - let retuo =3D VS.diff uo useo in - - (* - * Report if driver is not locked, since that's a safety - * risk - *) - if VS.is_empty ld then - ((), ld, ud, retlo, retuo, uud, uuo, List.append loud [i], = ldlo, dead) - else - ((), ld, ud, retlo, retuo, uud, uuo, loud, ldlo, dead) - ) else if isObjectUnlockCall i then ( - (* - * A object was unlocked, so add to the list of unlocked - * driver variables, and remove from the locked list - *) - let retlo =3D VS.diff lo useo in - let retuo =3D VS.union uo useo in - ((), ld, ud, retlo, retuo, uud, uuo, loud, ldlo, dead); - ) else ( - (* - * Nothing special happened, at best an assignment. - * So add any defined variables to the list of unlocked - * object or driver variables. - * XXX same edge case as isObjectFetchCall about possible - * overwriting - *) - let retud =3D VS.union ud defd in - let retuo =3D VS.union uo defo in - - (* - * Report is a driver is used while unlocked - *) - let retuud =3D - if not (VS.is_empty used) && (VS.is_empty ld) then - List.append uud [i] - else - uud in - (* - * Report is a object is used while unlocked - *) - let retuuo =3D - if not (VS.is_empty useo) && (VS.is_empty lo) then - List.append uuo [i] - else - uuo in - - ((), ld, retud, lo, retuo, retuud, retuuo, loud, ldlo, dead) - ); - in - - DF.Post transform - - (* - * This handles a Cil.Stmt object. This is sortof a C code block - *) - let doStmt stm (_, ld, ud, lo, uo, uud, uuo, loud, ldlo, dead) =3D - DF.SUse ((), ld, ud, lo, uo, [], [], [], [], []) - - - (* - * This handles decision making for a conditional statement, - * ie an if (foo). It is called twice for each conditional - * ie, once per possible choice. - *) - let doGuard exp (_, ld, ud, lo, uo, uud, uuo, loud, ldlo, dead) =3D - (* - * If we're going down a branch where our object variable - * is set to NULL, then we must remove it from the - * list of locked objects. This handles the case of... - * - * vm =3D virDomainFindByUUID(..) - * if (!vm) { - * .... this code branch .... - * } else { - * .... leaves default handling for this branch ... - * } - *) - let lonull =3D UD.computeUseExp exp in - - let loret =3D - if isLockableObjectNull exp then - VS.diff lo lonull - else - lo in - let uoret =3D - if isLockableObjectNull exp then - VS.union uo lonull - else - uo in - let ldret =3D - if isLockableDriverNull exp then - VS.diff ld lonull - else - ld in - let udret =3D - if isLockableDriverNull exp then - VS.union ud lonull - else - ud in - - DF.GUse ((), ldret, udret, loret, uoret, uud, uuo, loud, ldlo, dead) - - (* - * We're not filtering out any statements - *) - let filterStmt stm =3D true - -end - -module L =3D DF.ForwardsDataFlow(Locking) - -let () =3D - (* Read the list of files from "libvirt-files". *) - let files =3D input_file "objectlocking-files.txt" in - - (* Load & parse each input file. *) - let files =3D - List.map ( - fun filename -> - (* Why does parse return a continuation? *) - let f =3D Frontc.parse filename in - f () - ) files in - - (* Merge them. *) - let file =3D Mergecil.merge files "test" in - - (* Do control-flow-graph analysis. *) - Cfg.computeFileCFG file; - - print_endline ""; - - let driverVars =3D List.filter ( - function - | GVar (varinfo, initinfo, loc) -> (* global variable *) - if isDriverTable varinfo then - true - else - false - | _ -> false - ) file.globals in - - let driverVarFuncs =3D List.map ( - function - | GVar (varinfo, initinfo, loc) -> (* global variable *) - if isDriverTable varinfo then - getDriverFuncNames initinfo - else - [] - | _ -> [] - ) driverVars in - - let driverFuncsAll =3D List.flatten driverVarFuncs in - let driverFuncsSkip =3D [ - "testClose"; - "openvzClose"; - ] in - let driverFuncs =3D List.filter ( - fun st -> - if List.mem st driverFuncsSkip then - false - else - true - ) driverFuncsAll in - - (* - * Now comes our fun.... iterate over every global symbol - * definition Cfg found..... but... - *) - List.iter ( - function - (* ....only care about functions *) - | GFun (fundec, loc) -> (* function definition *) - let name =3D fundec.svar.vname in - - if List.mem name driverFuncs then ( - (* Initialize list of driver & object variables to be empty *) - ignore (lockableDriver =3D ref VS.empty); - ignore (lockableObjs =3D ref VS.empty); - - (* - * Query all local variables, and figure out which correspond - * to interesting driver & object variables we track - *) - List.iter ( - fun var -> - if isLockableDriverVar var then - lockableDriver :=3D VS.add var !lockableDriver - else if isLockableObjectVar var then - lockableObjs :=3D VS.add var !lockableObjs; - ) fundec.slocals; - - List.iter ( - fun gl -> - match gl with - GVar (vi, ii, loc) -> - if isLockableDriverVar vi then - lockableDriver :=3D VS.add vi !lockableDriver - | _ -> () - ) file.globals; - - (* - * Initialize the state for each statement (ie C code block) - * to be empty - *) - List.iter ( - fun st -> - IH.add Locking.stmtStartData st.sid ((), - VS.empty, VS.empty, VS.empty, VS.empty, - [], [], [], [], []) - ) fundec.sallstmts; - - (* - * This walks all the code paths in the function building - * up the state for each statement (ie C code block) - * ie, this is invoking the "Locking" module we created - * earlier - *) - L.compute fundec.sallstmts; - - (* - * Find all statements (ie C code blocks) which have no - * successor statements. This means they are exit points - * in the function - *) - let exitPoints =3D List.filter ( - fun st -> - List.length st.succs =3D 0 - ) fundec.sallstmts in - - (* - * For each of the exit points, check to see if there are - * any with locked driver or object variables & grab them - *) - let leaks =3D List.filter ( - fun st -> - let (_, ld, ud, lo, uo, uud, uuo, loud, ldlo, dead) =3D - IH.find Locking.stmtStartData st.sid in - let leakDrivers =3D not (VS.is_empty ld) in - let leakObjects =3D not (VS.is_empty lo) in - leakDrivers || leakObjects - ) exitPoints in - - let mistakes =3D List.filter ( - fun st -> - let (_, ld, ud, lo, uo, uud, uuo, loud, ldlo, dead) =3D - IH.find Locking.stmtStartData st.sid in - let lockDriverOrdering =3D (List.length ldlo) >= 0 in - let lockObjectOrdering =3D (List.length loud) >= 0 in - - let useDriverUnlocked =3D (List.length uud) > 0= in - let useObjectUnlocked =3D (List.length uuo) > 0= in - - let deadLocked =3D (List.length dead) > 0 in - - lockDriverOrdering || lockObjectOrdering || useDriverUnlocked || use= ObjectUnlocked || deadLocked - ) fundec.sallstmts in - - if (List.length leaks) > 0 || (List.length mistakes) > 0 then ( - print_endline "=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D"; - ignore (printf "Function: %s\n" name); - print_endline "---------------------------------------------------------= -------"; - ignore (printf " - Total exit points with locked vars: %d\n" (List.leng= th leaks)); - - (* - * Finally tell the user which exit points had locked varaibles - * And show them the line number and code snippet for easy fixing - *) - List.iter ( - fun st -> - ignore (Pretty.printf " - At exit on %a\n^^^^^^^^^\n" d_stmt st); - let (_, ld, ud, lo, uo, uud, uuo, loud, ldlo, dead) =3D - IH.find Locking.stmtStartData st.sid in - print_endline " variables still locked are"; - printVS ld; - printVS lo - ) leaks; - - - ignore (printf " - Total blocks with lock ordering mistakes: %d\n" (Lis= t.length mistakes)); - List.iter ( - fun st -> - let (_, ld, ud, lo, uo, uud, uuo, loud, ldlo, dead) =3D - IH.find Locking.stmtStartData st.sid in - List.iter ( - fun i -> - ignore (Pretty.printf " - Driver locked while object is locked on= %a\n" d_instr i); - ) ldlo; - List.iter ( - fun i -> - ignore (Pretty.printf " - Object locked while driver is unlocked = on %a\n" d_instr i); - ) loud; - List.iter ( - fun i -> - ignore (Pretty.printf " - Driver used while unlocked on %a\n" d_i= nstr i); - ) uud; - List.iter ( - fun i -> - ignore (Pretty.printf " - Object used while unlocked on %a\n" d_i= nstr i); - ) uuo; - List.iter ( - fun i -> - ignore (Pretty.printf " - Object fetched while locked objects exi= st %a\n" d_instr i); - ) dead; - ) mistakes; - print_endline "=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D"; - print_endline ""; - print_endline ""; - ); - - () - ) - | _ -> () - ) file.globals; --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list