From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.4 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C0DD5C43461 for ; Fri, 7 May 2021 15:43:44 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 3886761106 for ; Fri, 7 May 2021 15:43:44 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3886761106 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:49358 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lf2dj-0000rZ-4z for qemu-devel@archiver.kernel.org; Fri, 07 May 2021 11:43:43 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:52282) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lf2cI-0000LF-Fs for qemu-devel@nongnu.org; Fri, 07 May 2021 11:42:14 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:46918) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lf2cD-0003h9-Po for qemu-devel@nongnu.org; Fri, 07 May 2021 11:42:14 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1620402129; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=LFljFZbrZ+d/UWCXFCOrc8jwPFQoRBUcCXfBtEcz6Sk=; b=ADGvwVhZIQnGJrYFNf9iowmbgCNIaAqWxkUqxXWbqw9uHtLqnSNDYsDQ+ll9DyY1wAUDm8 o5hXrxmLszPwmuKyqkJmwUdEjwwB74pscY+65y9EYimNwuZtU8XKtLxFcdXrvFSFjAoOiS GwrsjHXHDKbEf8/7eV5ovuAsiJwPH0o= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-324-pxmLVF9YNqOmPvTnSuLXOg-1; Fri, 07 May 2021 11:42:07 -0400 X-MC-Unique: pxmLVF9YNqOmPvTnSuLXOg-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 4272E10066E6; Fri, 7 May 2021 15:42:06 +0000 (UTC) Received: from redhat.com (ovpn-113-225.phx2.redhat.com [10.3.113.225]) by smtp.corp.redhat.com (Postfix) with ESMTP id E5BFF5D9CC; Fri, 7 May 2021 15:42:05 +0000 (UTC) Date: Fri, 7 May 2021 09:42:05 -0600 From: Alex Williamson To: Thanos Makatos Subject: Re: question regarding QEMU adding overlapping memory regions to VFIO Message-ID: <20210507094205.43adae95@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=alex.williamson@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Received-SPF: pass client-ip=170.10.133.124; envelope-from=alex.williamson@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.699, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "qemu-devel@nongnu.org" , Raphael Norwitz Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" On Fri, 7 May 2021 13:51:52 +0000 Thanos Makatos wrote: > I've noticed that QEMU adds overlapping memory regions to VFIO, e.g.: > > vfio_listener_region_add_ram region_add [ram] 0xc0000 - 0xc0fff [0x7f6702c00000] > vfio_listener_region_del region_del 0xc4000 - 0xdffff > vfio_listener_region_add_ram region_add [ram] 0xc1000 - 0xc3fff [0x7f66406c1000] > vfio_listener_region_del region_del 0xe0000 - 0xfffff > vfio_listener_region_add_ram region_add [ram] 0xc4000 - 0xdffff [0x7f6702c04000] > vfio_listener_region_add_ram region_add [ram] 0xc0000 - 0xc0fff [0x7f66406c0000] > 2021-05-05T09:38:16.158864Z qemu-system-x86_64: vfio_dma_map(0x557b8fd281b0, 0xc0000, 0x1000, 0x7f66406c0000) = -22 (Resource temporarily unavailable) > > Region 0xc0000 - 0xc0fff is added first and then region 0xc0000 - > 0xc0fff is added again? Is this legitimate? What is the implication > of this? Is the previous region replaced by the more recent one? This might be where the hack we have in hw/vfio/common.c:vfio_dma_map() comes from: /* * Try the mapping, if it fails with EBUSY, unmap the region and try * again. This shouldn't be necessary, but we sometimes see it in * the VGA ROM space. */ if (ioctl(container->fd, VFIO_IOMMU_MAP_DMA, &map) == 0 || (errno == EBUSY && vfio_dma_unmap(container, iova, size, NULL) == 0 && ioctl(container->fd, VFIO_IOMMU_MAP_DMA, &map) == 0)) { return 0; } Clearly that's only triggered with -EBUSY and you're getting -EINVAL, did we unintentionally change the errno for this? What's the host kernel version? It's my expectation that this really shouldn't happen, the above is a lazy workaround, but a listener being told to map two different things at the same address range without an unmap in between seems like it should violate the MemoryListener protocol. Thanks, Alex