From patchwork Fri Dec 17 14:37:48 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Alexander Bulekov X-Patchwork-Id: 12684823 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 10FC1C433F5 for ; Fri, 17 Dec 2021 14:40:42 +0000 (UTC) Received: from localhost ([::1]:55138 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1myEPZ-0007PA-0Q for qemu-devel@archiver.kernel.org; Fri, 17 Dec 2021 09:40:41 -0500 Received: from eggs.gnu.org ([209.51.188.92]:40100) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1myENB-00053A-J8 for qemu-devel@nongnu.org; Fri, 17 Dec 2021 09:38:13 -0500 Received: from mail-bn8nam12on2102.outbound.protection.outlook.com ([40.107.237.102]:4416 helo=NAM12-BN8-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1myEN4-00070Q-IW for qemu-devel@nongnu.org; Fri, 17 Dec 2021 09:38:13 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=hqN8iSlqHx0WgTmLWYwQg4fv/mrusesh+sgp2He/gTkar98WacxXn2ITMPW/PLM40QuPu7NpH1Sd1ODC/BpZNBiycA8PnIzjfu1ROFNZip5FPZQ/sK58tRuEk9GZg96sc6MizddbzcbP14F5zZ1vca3fuB9GlMRP1bvFMwbwpOnFvyM6H/4huTW6g9s5oxdVAAlP5soyQFFjRH+glKBFoQiIghL7BoBawQNOMv4afJG6SC6I4JSyXdrK3slqBCVmduhhnzayfLqqck2b4U/K78tPIZPOBxg7qdHfGrQIz9AVEMkn0amAnjNIpe/MiuQYNbW0Zc9WZeACZoJeL2oCqg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=f07iEKfczjv5EqP+wNDlpd5IkuiiNkcyYVPQ3JdwVXs=; b=jmgt+Qh8Akd22mxsajkxWG0IOh1XQDdIlxMonPY+hLsdOXpBvnQukXDt1SgrXG8L0og/t2mUfEbP3aqkCxC2N2iAXEaTPpobmJcQXQVl/bhu//L+lJuMSy5iNmI4oPb/OHm9QdVHUYnlAXx/d4Ozr5IFEgbIV7Q1rarqYxGYZeAivIFFA39jHhWw4e9R2ZO3CYKsYRHKSFfR89Mmy3T0hztMMBLU19ubIq7vOaeBUDMGzTsCQvlcr11InCWZsxMtURENA1A6ycO6sOI3/gM0UMV6wapjdGoDpcoxUngLOXSZEM1fuUeUhbyXrLa8ycNoe7bl5JNs/sxucN1v9wA1dA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=bu.edu; dmarc=pass action=none header.from=bu.edu; dkim=pass header.d=bu.edu; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bu.edu; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=f07iEKfczjv5EqP+wNDlpd5IkuiiNkcyYVPQ3JdwVXs=; b=nUPZMMR6j7UP0RR/JvRtpCaKiOOF1UXwFQbrUSEwgUeTvyg8dbCO+HIdGYFumPzN9t67NN5LY2Ym27qDPhwPLIaDxSRtV6aylrvUCQzCRMSoHiXuf6apMXle5arAXr3Fq/FGUzUv3SndfSV0c9JI/MXrD9iBUQCl+C8yRGKy2K+hGzaGUYP2PKDg3ePWQfOHlfIjvsIgHleE1cnayPD5dvtC8xj0MBhkYSOERVON6iM/oqcKDudBFGOKdmJDX3zFPIRkztF3C5Ruw5+j8xXNuWAg53MiKqvLUZjc1cdfB64MYM+ur34Qel+I8lIBAL8u3ITt5c8dIHpjwxzXsDYtKg== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=bu.edu; Received: from SN6PR03MB3871.namprd03.prod.outlook.com (2603:10b6:805:6d::32) by SA2PR03MB5724.namprd03.prod.outlook.com (2603:10b6:806:113::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4801.17; Fri, 17 Dec 2021 14:38:03 +0000 Received: from SN6PR03MB3871.namprd03.prod.outlook.com ([fe80::6cf1:fa6a:fb65:131]) by SN6PR03MB3871.namprd03.prod.outlook.com ([fe80::6cf1:fa6a:fb65:131%3]) with mapi id 15.20.4778.019; Fri, 17 Dec 2021 14:38:03 +0000 From: Alexander Bulekov To: qemu-devel@nongnu.org Subject: [RFC PATCH v2 0/2] Attempt to fix DMA reentrancy issues Date: Fri, 17 Dec 2021 09:37:48 -0500 Message-Id: <20211217143750.50641-1-alxndr@bu.edu> X-Mailer: git-send-email 2.33.0 X-ClientProxiedBy: BL1PR13CA0305.namprd13.prod.outlook.com (2603:10b6:208:2c1::10) To SN6PR03MB3871.namprd03.prod.outlook.com (2603:10b6:805:6d::32) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 5a8703c0-ca31-40bc-5121-08d9c16ad4ae X-MS-TrafficTypeDiagnostic: SA2PR03MB5724:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:8882; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 5X5P2IS8gmVbokid7LLwzTPDTMz00W0XWUqbK6TIsF0jhHG/YTN807sjebOK92srh7bPbSXOndv/eTSg0COaqBLBynxVWEW8Hrm7ah79sfu+C/wngVlLredvMs50VGPB42VaDnzaWeh0cALBlfsI1eYqi/rPnj6XwegQDlEw2T2vYZM1UGNHkUPA/MNG2SDPmybPsriOOEVu11wBfY7C2UxzwIVS0l79zGUtNkUVcFL7OFvlquZ8QNFSXXN9CfDJiD6NMl0PugWjb8OsUE/9VM61Em3Tg5n+78/kX6HVPq7XPuS7leOf/ou5vYRD3tqzwLSsZD+wj+rBuJDPNK62gFkjDPuIkZdGwc+qblNqRyswBuAAOSkN6SIsowUgXJLCZANIhAOGkX74nfihz6/Bf9qEXq9gJn2jtx3ZYlRoOgSoxoNe/PvxW421cz1Chrvz5aJ//L+5fP5iQre1o2N73lO3yOElwMuUFD10hbl2XtdrPGEQBoOX6NffwouS3XI+T1jd2E2yt3bj3zb9XAjYfTp91yMIaYnsuxDNMknZrKD93/IfurTr6lIZD56+aYinobPdF4UNVW3QetGsBILUOWNEv+CJ5a1+gj7lps7gjPM/WZmCaFZfTVWP+Jb1IaMXumgGl/FLImzmAK+I0X48TUZrKf7Jbfjq9S0luENoLqyMINb3b21jG06ZgwgpqV92 X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:SN6PR03MB3871.namprd03.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(366004)(6666004)(66476007)(1076003)(4326008)(316002)(6512007)(36756003)(786003)(7416002)(54906003)(66556008)(26005)(5660300002)(66946007)(75432002)(83380400001)(8936002)(508600001)(38350700002)(45080400002)(38100700002)(86362001)(52116002)(186003)(6916009)(6486002)(2616005)(6506007)(8676002)(2906002); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8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Pa885gBP6bgzfRgWUGeYx6RHH8Bl?= =?utf-8?q?dlQKZ26KimXUBcaGoeC6h1pON6FHBEubFK06bV7ylOidO6vva9xGxYcwUsIHBFdJm?= =?utf-8?q?EpB7wAZzzUsru3AgUuxCSIuFaxwBdByq6jKGy7WFEa2D+kWIXhdd+r+L60Km8z1dI?= =?utf-8?q?4VEKlGCxBGaa4MBjIK3OxenZp9AEevmqPey9uwkYIaRACz3uQm4JPBJy+Gw3v/cVm?= =?utf-8?q?0gO+I2thCcirGAPI8OFv6vC54BSkgNLkS0Ay2x+mn0hZs8t2EmyuU1JAc7c5Jajob?= =?utf-8?q?+Mx4x6EFijtQ3sV9Gm9M8sDha9lBSe9hI43ponFso1IVsrgRdNndGGrQ4fiD8kFmF?= =?utf-8?q?d9e57AumdNVzoRhDcGAYBfArm3mj/87851GpJpQB65Tzn506PCK5zB1+3wd5BxNZ0?= =?utf-8?q?+URVT/lyUY6YXA0Li6NCnv6j9ILpdwMaiKefdgwsmC3nFOzuY2rpkpOkotJ/UuWnB?= =?utf-8?q?r1G9H5Gt8M1u9uUs099C5+6bfNNyei9bObddCIAubCABv7inIKa1F6epiefrkeEZB?= =?utf-8?q?vSEvdjCaqLHzt7h/LQ6GJ1EHNR+Sqg1n6CLvG1QYsuClzEyzl1jnDvtMM/A5dTMLv?= =?utf-8?q?jD/Enaz5aWX3DHP3dtwJkv7BmKEsevq1Xgw=3D=3D?= X-OriginatorOrg: bu.edu X-MS-Exchange-CrossTenant-Network-Message-Id: 5a8703c0-ca31-40bc-5121-08d9c16ad4ae X-MS-Exchange-CrossTenant-AuthSource: SN6PR03MB3871.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Dec 2021 14:38:03.3500 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: d57d32cc-c121-488f-b07b-dfe705680c71 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 9dcK7T56Uz1Mr7tlGRfAzwUP011sbIapZmI9TpJI4b3WXhEhOAECzxb9wwYqGUcC X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA2PR03MB5724 Received-SPF: pass client-ip=40.107.237.102; envelope-from=alxndr@bu.edu; helo=NAM12-BN8-obe.outbound.protection.outlook.com X-Spam_score_int: 0 X-Spam_score: -0.1 X-Spam_bar: / X-Spam_report: (-0.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, HK_RANDOM_ENVFROM=0.998, HK_RANDOM_FROM=0.998, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Laurent Vivier , Peter Maydell , Mauro Matteo Cascella , Darren Kenny , David Hildenbrand , Jason Wang , Bin Meng , Li Qiang , Qiuhao Li , Peter Xu , Alexander Bulekov , Bandan Das , Gerd Hoffmann , Stefan Hajnoczi , Paolo Bonzini , Thomas Huth , "Edgar E . Iglesias" , =?utf-8?q?Philippe_Mathieu?= =?utf-8?q?-Daud=C3=A9?= Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Here's my shot at fixing dma-reentracy issues. This patch adds a flag to the DeviceState, which is set/checked when we call an accessor associated with the device's IO MRs. The problem, in short, as I understand it: For the vast majority of cases, we want to prevent a device from accessing it's own PIO/MMIO regions over DMA. V2: Try to fix reentrancies initiated by DMA accesses in BHs Cc: Philippe Mathieu-Daudé Cc: Mauro Matteo Cascella Cc: Qiuhao Li Cc: Peter Xu Cc: Jason Wang Cc: David Hildenbrand Cc: Gerd Hoffmann Cc: Peter Maydell Cc: Li Qiang Cc: Thomas Huth Cc: Laurent Vivier Cc: Bandan Das Cc: Edgar E. Iglesias Cc: Darren Kenny Cc: Bin Meng Cc: Paolo Bonzini Cc: Stefan Hajnoczi Alexander Bulekov (2): memory: fix dma-reentrancy issues at the MMIO level memory: set engaged_in_io when a device calls DMA APIs include/hw/pci/pci.h | 6 +++++- include/hw/qdev-core.h | 1 + softmmu/dma-helpers.c | 2 ++ softmmu/memory.c | 15 +++++++++++++++ softmmu/trace-events | 1 + 5 files changed, 24 insertions(+), 1 deletion(-)