From patchwork Wed Dec 2 11:03:07 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 1409648 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=LvxsX3Qw; dkim-atps=neutral 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 ozlabs.org (Postfix) with ESMTPS id 4CmGY34qtkz9sSf for ; Wed, 2 Dec 2020 22:13:11 +1100 (AEDT) Received: from localhost ([::1]:40914 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kkQ4L-0002fA-LP for incoming@patchwork.ozlabs.org; Wed, 02 Dec 2020 06:13:09 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:37298) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kkPup-0002jW-4G for qemu-devel@nongnu.org; Wed, 02 Dec 2020 06:03:19 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:25540) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kkPuk-0002nw-8R for qemu-devel@nongnu.org; Wed, 02 Dec 2020 06:03:18 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1606906993; 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: in-reply-to:in-reply-to:references:references; bh=T1SVHdVGU4Xx3+1TvaSIiSga1fTtl00R2aC0nHg/hx0=; b=LvxsX3QwLEAO1Y1LEWJA5qFWFP9f8nmxvz7Zq+gPPz64G1QLv1u7jieL0olHdVdviK4H8X RIZvDuk9NhcioX7N3Uagd30Ekjilt0LPd4AduIVyxU97LKcGhPYoWhUNysSt5BLEESLhYw sM/IrCcJsB+LcBvB9EMlEMmQduL40GM= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-370-jjPLdasmMC2PFHJ65n6Ibw-1; Wed, 02 Dec 2020 06:03:11 -0500 X-MC-Unique: jjPLdasmMC2PFHJ65n6Ibw-1 Received: by mail-wm1-f69.google.com with SMTP id l5so3182787wmi.4 for ; Wed, 02 Dec 2020 03:03:11 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=T1SVHdVGU4Xx3+1TvaSIiSga1fTtl00R2aC0nHg/hx0=; b=SPoy+WbXWeNaKcfa8UEnQq/6qqcgRNjBfPU3Qa1jR606/SeYsXlqrOX5TBzCIC4lD2 ruhswf0xPfdWeSPBinh6xZILMqFQ2GhEP74n9xNGILbNA+Ll05Ktx3dr3vdwYA29BwjL OdX9iSusmkf3wdRR9jtlxco/WS+cInGmIlI1RJsYXl4kyCsUoB64wRRQlESwpJ8epAs6 XPzL9wJ5OlIcY5SU6Pf1T1pzHEVpcNhAApDAatv2mac1c88mzX3SGMesLBElwq7lTPqS +WHFx+fM1wN8bjwc+4GxJ6vqcmO95onbcXMFy1O5qengpuSCmcAMBkUX5IzZ1dP4v8UH 0n0w== X-Gm-Message-State: AOAM532rSZ1Bly0tZKtv+XqNzJCbhN9rV0LkQ6tzSowKZfiNINLaYUpV K2jPrbFYZUTalznPHamOdelL1UWITmGhEDNSxxniMUUt8bvRfcNkLQuPLSp7WyqtNHLmN5P/L8n zzVsJF6YsXx2T/52kiSz/K6BN8eGH61il/YdNGlS2c1ef//PBWzlmPE2o/W9y X-Received: by 2002:a5d:400a:: with SMTP id n10mr2740287wrp.362.1606906989974; Wed, 02 Dec 2020 03:03:09 -0800 (PST) X-Google-Smtp-Source: ABdhPJwM1z1dgh+dLJXeEZ3uAJzJ7f1uLIJ6jwlmKCcwtvRy3KunnXnDdNHHcVL81frRvtIHDcNuyA== X-Received: by 2002:a5d:400a:: with SMTP id n10mr2740259wrp.362.1606906989746; Wed, 02 Dec 2020 03:03:09 -0800 (PST) Received: from redhat.com (bzq-79-176-44-197.red.bezeqint.net. [79.176.44.197]) by smtp.gmail.com with ESMTPSA id c1sm1554105wml.8.2020.12.02.03.03.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Dec 2020 03:03:09 -0800 (PST) Date: Wed, 2 Dec 2020 06:03:07 -0500 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Subject: [PULL 1/6] vhost-user-scsi: Fix memleaks in vus_proc_req() Message-ID: <20201202101655.122214-2-mst@redhat.com> References: <20201202101655.122214-1-mst@redhat.com> MIME-Version: 1.0 In-Reply-To: <20201202101655.122214-1-mst@redhat.com> X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=mst@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline Received-SPF: pass client-ip=63.128.21.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -35 X-Spam_score: -3.6 X-Spam_bar: --- X-Spam_report: (-3.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.497, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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: Alex Chen , Peter Maydell , Raphael Norwitz , Euler Robot Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Alex Chen The 'elem' is allocated memory in vu_queue_pop(), and its memory should be freed in all error branches after vu_queue_pop(). In addition, in order to free the 'elem' memory outside of while(1) loop, move the definition of 'elem' to the beginning of vus_proc_req(). Reported-by: Euler Robot Signed-off-by: Alex Chen Reviewed-by: Raphael Norwitz Message-Id: <20201125013055.34147-1-alex.chen@huawei.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- contrib/vhost-user-scsi/vhost-user-scsi.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/contrib/vhost-user-scsi/vhost-user-scsi.c b/contrib/vhost-user-scsi/vhost-user-scsi.c index 0f9ba4b2a2..4639440a70 100644 --- a/contrib/vhost-user-scsi/vhost-user-scsi.c +++ b/contrib/vhost-user-scsi/vhost-user-scsi.c @@ -232,6 +232,7 @@ static void vus_proc_req(VuDev *vu_dev, int idx) VugDev *gdev; VusDev *vdev_scsi; VuVirtq *vq; + VuVirtqElement *elem = NULL; assert(vu_dev); @@ -248,7 +249,6 @@ static void vus_proc_req(VuDev *vu_dev, int idx) g_debug("Got kicked on vq[%d]@%p", idx, vq); while (1) { - VuVirtqElement *elem; VirtIOSCSICmdReq *req; VirtIOSCSICmdResp *rsp; @@ -288,6 +288,7 @@ static void vus_proc_req(VuDev *vu_dev, int idx) free(elem); } + free(elem); } static void vus_queue_set_started(VuDev *vu_dev, int idx, bool started) From patchwork Wed Dec 2 11:03:10 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 1409651 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=QgGVqSj9; dkim-atps=neutral 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 ozlabs.org (Postfix) with ESMTPS id 4CmGbp40nQz9sTL for ; Wed, 2 Dec 2020 22:15:34 +1100 (AEDT) Received: from localhost ([::1]:47326 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kkQ6d-0005wU-QO for incoming@patchwork.ozlabs.org; Wed, 02 Dec 2020 06:15:31 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:37308) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kkPuq-0002lI-KV for qemu-devel@nongnu.org; Wed, 02 Dec 2020 06:03:20 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:37356) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kkPun-0002pd-GS for qemu-devel@nongnu.org; Wed, 02 Dec 2020 06:03:20 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1606906996; 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=kU8LLfrD++DTckVdz92f3StgJjIwiPAzY3tPlKdDYNE=; b=QgGVqSj9/vY/ScIXZHkFg4nZ9FcUjBaACW3UWckIw63R6YVdpeSZVGykWVEhhnGSOIeuFv fLLh/2HSZSbzWoMur+6oF0y8FYfbQfsQGy5IJLvbFKHZ01czicaqRDM+M1OKfBCVFU+/ME w2CM/bIMZ5Fgbj47B8VsOLoZi9gqKlw= Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-582-T2oOe9cqM9a4gWcPu2XnPQ-1; Wed, 02 Dec 2020 06:03:15 -0500 X-MC-Unique: T2oOe9cqM9a4gWcPu2XnPQ-1 Received: by mail-wr1-f71.google.com with SMTP id x16so3359200wrm.20 for ; Wed, 02 Dec 2020 03:03:15 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to; bh=kU8LLfrD++DTckVdz92f3StgJjIwiPAzY3tPlKdDYNE=; b=ukN9dIwPecAa3KRylm/rTYELrZVk/kRXM0/HmANaiBXsjyOcZeVzsbDslqAtHYunhG kW/9uGLfud46TwVD2pDc7rYasvgmQmHVEPCwT8J6aGKa5AJVjnELG0MUaZe6q+eo8xlA Rok4hyIkLv7UwZTdfombF6ECSkjd/zSTCemboo8pV4TSkhlZbPRERX2n63R1GpGsWOsf oi3w7Tnl0bUMpJuXoiRPma4KIaxCbQZP+A1fxqwEcsy4CAPeUMB8h6g/Di0RkWTS7mdx XIiue/l6n2Q4hBQr6NxXrONAoj9UeO6KBYN/6vpEdbBNeR8s6bHsQDxe4iC3ZPGdOYLh qF1w== X-Gm-Message-State: AOAM532vizXShYpWWif9EtHJjJWIVPK43QM5JMM+UayIGv6a4JQr8lMe 8XFWoyTYV8vAFnuWtd+11YTAKucZnzchVF3C8ClGWbNyng3o9hkdEj7ECkjRzFfugsag4NfXFMH JCx7DXSNzfpCh7CflSUrHJ4igRn697ZlAUqXLtAWw5BpcqjsoxR0gzsKH8Qj0 X-Received: by 2002:adf:dd52:: with SMTP id u18mr2655924wrm.44.1606906993426; Wed, 02 Dec 2020 03:03:13 -0800 (PST) X-Google-Smtp-Source: ABdhPJxLXfbjaUo36hYtWvriXUWkOg2QNha+37bTIwj/wt+9KuyVS7IqSZJqGxDFM8IQe79vodgwpA== X-Received: by 2002:adf:dd52:: with SMTP id u18mr2655877wrm.44.1606906993068; Wed, 02 Dec 2020 03:03:13 -0800 (PST) Received: from redhat.com (bzq-79-176-44-197.red.bezeqint.net. [79.176.44.197]) by smtp.gmail.com with ESMTPSA id k6sm1496829wmf.25.2020.12.02.03.03.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Dec 2020 03:03:12 -0800 (PST) Date: Wed, 2 Dec 2020 06:03:10 -0500 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Subject: [PULL 2/6] memory: Rename memory_region_notify_one to memory_region_notify_iommu_one Message-ID: <20201202101655.122214-3-mst@redhat.com> References: <20201202101655.122214-1-mst@redhat.com> MIME-Version: 1.0 In-Reply-To: <20201202101655.122214-1-mst@redhat.com> X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=mst@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline Received-SPF: pass client-ip=63.128.21.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -35 X-Spam_score: -3.6 X-Spam_bar: --- X-Spam_report: (-3.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.497, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable 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: Peter Maydell , Eduardo Habkost , Juan Quintela , Jason Wang , Richard Henderson , Peter Xu , Eric Auger , qemu-arm@nongnu.org, Paolo Bonzini , Eugenio =?utf-8?b?UMOpcmV6?= , David Gibson Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Eugenio Pérez Previous name didn't reflect the iommu operation. Signed-off-by: Eugenio Pérez Reviewed-by: Peter Xu Reviewed-by: David Gibson Reviewed-by: Juan Quintela Reviewed-by: Eric Auger Acked-by: Jason Wang Message-Id: <20201116165506.31315-2-eperezma@redhat.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- include/exec/memory.h | 6 +++--- hw/arm/smmu-common.c | 2 +- hw/arm/smmuv3.c | 2 +- hw/i386/intel_iommu.c | 4 ++-- softmmu/memory.c | 6 +++--- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/include/exec/memory.h b/include/exec/memory.h index 0f3e6bcd5e..d8456ccf52 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -236,7 +236,7 @@ enum IOMMUMemoryRegionAttr { * The IOMMU implementation must use the IOMMU notifier infrastructure * to report whenever mappings are changed, by calling * memory_region_notify_iommu() (or, if necessary, by calling - * memory_region_notify_one() for each registered notifier). + * memory_region_notify_iommu_one() for each registered notifier). * * Conceptually an IOMMU provides a mapping from input address * to an output TLB entry. If the IOMMU is aware of memory transaction @@ -1346,7 +1346,7 @@ void memory_region_notify_iommu(IOMMUMemoryRegion *iommu_mr, IOMMUTLBEntry entry); /** - * memory_region_notify_one: notify a change in an IOMMU translation + * memory_region_notify_iommu_one: notify a change in an IOMMU translation * entry to a single notifier * * This works just like memory_region_notify_iommu(), but it only @@ -1357,7 +1357,7 @@ void memory_region_notify_iommu(IOMMUMemoryRegion *iommu_mr, * replaces all old entries for the same virtual I/O address range. * Deleted entries have .@perm == 0. */ -void memory_region_notify_one(IOMMUNotifier *notifier, +void memory_region_notify_iommu_one(IOMMUNotifier *notifier, IOMMUTLBEntry *entry); /** diff --git a/hw/arm/smmu-common.c b/hw/arm/smmu-common.c index 3838db1395..88d2c454f0 100644 --- a/hw/arm/smmu-common.c +++ b/hw/arm/smmu-common.c @@ -472,7 +472,7 @@ static void smmu_unmap_notifier_range(IOMMUNotifier *n) entry.perm = IOMMU_NONE; entry.addr_mask = n->end - n->start; - memory_region_notify_one(n, &entry); + memory_region_notify_iommu_one(n, &entry); } /* Unmap all notifiers attached to @mr */ diff --git a/hw/arm/smmuv3.c b/hw/arm/smmuv3.c index 22607c3784..273f5f7dce 100644 --- a/hw/arm/smmuv3.c +++ b/hw/arm/smmuv3.c @@ -828,7 +828,7 @@ static void smmuv3_notify_iova(IOMMUMemoryRegion *mr, entry.addr_mask = num_pages * (1 << granule) - 1; entry.perm = IOMMU_NONE; - memory_region_notify_one(n, &entry); + memory_region_notify_iommu_one(n, &entry); } /* invalidate an asid/iova range tuple in all mr's */ diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c index 70ac837733..067593b9e4 100644 --- a/hw/i386/intel_iommu.c +++ b/hw/i386/intel_iommu.c @@ -3497,7 +3497,7 @@ static void vtd_address_space_unmap(VTDAddressSpace *as, IOMMUNotifier *n) /* This field is meaningless for unmap */ entry.translated_addr = 0; - memory_region_notify_one(n, &entry); + memory_region_notify_iommu_one(n, &entry); start += mask; remain -= mask; @@ -3535,7 +3535,7 @@ static void vtd_address_space_refresh_all(IntelIOMMUState *s) static int vtd_replay_hook(IOMMUTLBEntry *entry, void *private) { - memory_region_notify_one((IOMMUNotifier *)private, entry); + memory_region_notify_iommu_one((IOMMUNotifier *)private, entry); return 0; } diff --git a/softmmu/memory.c b/softmmu/memory.c index 11ca94d037..44de610c72 100644 --- a/softmmu/memory.c +++ b/softmmu/memory.c @@ -1942,8 +1942,8 @@ void memory_region_unregister_iommu_notifier(MemoryRegion *mr, memory_region_update_iommu_notify_flags(iommu_mr, NULL); } -void memory_region_notify_one(IOMMUNotifier *notifier, - IOMMUTLBEntry *entry) +void memory_region_notify_iommu_one(IOMMUNotifier *notifier, + IOMMUTLBEntry *entry) { IOMMUNotifierFlag request_flags; hwaddr entry_end = entry->iova + entry->addr_mask; @@ -1979,7 +1979,7 @@ void memory_region_notify_iommu(IOMMUMemoryRegion *iommu_mr, IOMMU_NOTIFIER_FOREACH(iommu_notifier, iommu_mr) { if (iommu_notifier->iommu_idx == iommu_idx) { - memory_region_notify_one(iommu_notifier, &entry); + memory_region_notify_iommu_one(iommu_notifier, &entry); } } } From patchwork Wed Dec 2 11:03:13 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 1409663 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=geORiVi9; dkim-atps=neutral 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 ozlabs.org (Postfix) with ESMTPS id 4CmHBR46cCz9s1l for ; Wed, 2 Dec 2020 22:42:06 +1100 (AEDT) Received: from localhost ([::1]:40062 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kkQWI-0003Px-NP for incoming@patchwork.ozlabs.org; Wed, 02 Dec 2020 06:42:02 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:37388) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kkPuu-0002pf-Tk for qemu-devel@nongnu.org; Wed, 02 Dec 2020 06:03:24 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:36928) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kkPur-0002rs-Mc for qemu-devel@nongnu.org; Wed, 02 Dec 2020 06:03:24 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1606907000; 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=hCZCKCuFOJBCydymGeiwWLBXi/oP0lMJNiHZPbP0zJw=; b=geORiVi9V7xc4fCFcHCzGXfSs26nS3Mqs+Lpd80j6NKDNDk8He/aB1vRubppL+FLm99/p6 FjbJEmdUcLWVF7WDsu480BdBmPF4zcLOIov0hgAVkDJgd3nF4yycR/4FNWjUz8HQzBlZJF fjiHgVNMBgYddWSnyHh2CRxNJ1mE/h4= Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-275-7pBY1RS0Pi21Q1BPBpoUdQ-1; Wed, 02 Dec 2020 06:03:19 -0500 X-MC-Unique: 7pBY1RS0Pi21Q1BPBpoUdQ-1 Received: by mail-wr1-f70.google.com with SMTP id n1so3305551wro.22 for ; Wed, 02 Dec 2020 03:03:18 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to; bh=hCZCKCuFOJBCydymGeiwWLBXi/oP0lMJNiHZPbP0zJw=; b=ILmbAlMkh7zliOS5Ytd7JwrDpncF7QiH66HI7dgev8753LI/rR2+l0yagCarbj1b9K 88+W8UbChwy5vqm0/M/GLzZq4gpZW9zwRMLkUClHy032kNivu60uBHsYku4EwB/zf22t BaACGKrCbzuEMdA+pawFH+8Y3wWAIxvYCfsBMJ/0OVcRSur02sAVQ9FDWHRC3Dw51+r9 gXF1+r6yuiuXvi4gM2vhkjnBApF10qarcHHyo/4ctNaUfnkxVqWdSX15ZHlHwtzFalTf xyJ1QX3h0NV8q8kIbfvQifwL/md7iaDblCAnFk1syRkSVqSe9pSkh0C37fLmrKasOrML /zJQ== X-Gm-Message-State: AOAM530k2WLgtdLVlJOd8WUea6gARJi/Y2eTC0WTX/1lSVsDdlUZg14O AlVzZNr71MGC7q0qNLrkPC/AbCoKF6iUOL6jLX/qXI1zO/9jC/+CepDxjGy/bQsOMhFk7TEDKzv 0cB6esc4T4+iytLKsi1/G80/ZLE+CwMREkgr9B87lOTUdRawo10YX2jd0cR3w X-Received: by 2002:a1c:a402:: with SMTP id n2mr2582563wme.185.1606906997171; Wed, 02 Dec 2020 03:03:17 -0800 (PST) X-Google-Smtp-Source: ABdhPJw9bWnKvC5j42PERY34pSEQ/IsLi+CSESyQ55iZ4EfslYU27s+O6YhteYMgvl6Yijidvze1Eg== X-Received: by 2002:a1c:a402:: with SMTP id n2mr2582502wme.185.1606906996743; Wed, 02 Dec 2020 03:03:16 -0800 (PST) Received: from redhat.com (bzq-79-176-44-197.red.bezeqint.net. [79.176.44.197]) by smtp.gmail.com with ESMTPSA id a9sm1711967wrp.21.2020.12.02.03.03.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Dec 2020 03:03:15 -0800 (PST) Date: Wed, 2 Dec 2020 06:03:13 -0500 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Subject: [PULL 3/6] memory: Add IOMMUTLBEvent Message-ID: <20201202101655.122214-4-mst@redhat.com> References: <20201202101655.122214-1-mst@redhat.com> MIME-Version: 1.0 In-Reply-To: <20201202101655.122214-1-mst@redhat.com> X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=mst@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline Received-SPF: pass client-ip=216.205.24.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -35 X-Spam_score: -3.6 X-Spam_bar: --- X-Spam_report: (-3.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.497, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable 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: Peter Maydell , Thomas Huth , Eduardo Habkost , Matthew Rosato , Juan Quintela , Jason Wang , Cornelia Huck , Richard Henderson , Peter Xu , Halil Pasic , Eugenio =?utf-8?b?UMOpcmV6?= , qemu-s390x@nongnu.org, qemu-arm@nongnu.org, qemu-ppc@nongnu.org, Eric Auger , Paolo Bonzini , David Hildenbrand , Christian Borntraeger , David Gibson Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Eugenio Pérez This way we can tell between regular IOMMUTLBEntry (entry of IOMMU hardware) and notifications. In the notifications, we set explicitly if it is a MAPs or an UNMAP, instead of trusting in entry permissions to differentiate them. Signed-off-by: Eugenio Pérez Reviewed-by: Peter Xu Reviewed-by: Juan Quintela Acked-by: Jason Wang Message-Id: <20201116165506.31315-3-eperezma@redhat.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin Reviewed-by: Matthew Rosato Acked-by: David Gibson --- include/exec/memory.h | 27 ++++++------ hw/arm/smmu-common.c | 13 +++--- hw/arm/smmuv3.c | 13 +++--- hw/i386/intel_iommu.c | 88 ++++++++++++++++++++++------------------ hw/misc/tz-mpc.c | 32 ++++++++------- hw/ppc/spapr_iommu.c | 15 +++---- hw/s390x/s390-pci-inst.c | 27 +++++++----- hw/virtio/virtio-iommu.c | 30 +++++++------- softmmu/memory.c | 20 ++++----- 9 files changed, 143 insertions(+), 122 deletions(-) diff --git a/include/exec/memory.h b/include/exec/memory.h index d8456ccf52..e86b5e92da 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -116,6 +116,11 @@ struct IOMMUNotifier { }; typedef struct IOMMUNotifier IOMMUNotifier; +typedef struct IOMMUTLBEvent { + IOMMUNotifierFlag type; + IOMMUTLBEntry entry; +} IOMMUTLBEvent; + /* RAM is pre-allocated and passed into qemu_ram_alloc_from_ptr */ #define RAM_PREALLOC (1 << 0) @@ -1326,24 +1331,18 @@ uint64_t memory_region_iommu_get_min_page_size(IOMMUMemoryRegion *iommu_mr); /** * memory_region_notify_iommu: notify a change in an IOMMU translation entry. * - * The notification type will be decided by entry.perm bits: - * - * - For UNMAP (cache invalidation) notifies: set entry.perm to IOMMU_NONE. - * - For MAP (newly added entry) notifies: set entry.perm to the - * permission of the page (which is definitely !IOMMU_NONE). - * * Note: for any IOMMU implementation, an in-place mapping change * should be notified with an UNMAP followed by a MAP. * * @iommu_mr: the memory region that was changed * @iommu_idx: the IOMMU index for the translation table which has changed - * @entry: the new entry in the IOMMU translation table. The entry - * replaces all old entries for the same virtual I/O address range. - * Deleted entries have .@perm == 0. + * @event: TLB event with the new entry in the IOMMU translation table. + * The entry replaces all old entries for the same virtual I/O address + * range. */ void memory_region_notify_iommu(IOMMUMemoryRegion *iommu_mr, int iommu_idx, - IOMMUTLBEntry entry); + IOMMUTLBEvent event); /** * memory_region_notify_iommu_one: notify a change in an IOMMU translation @@ -1353,12 +1352,12 @@ void memory_region_notify_iommu(IOMMUMemoryRegion *iommu_mr, * notifies a specific notifier, not all of them. * * @notifier: the notifier to be notified - * @entry: the new entry in the IOMMU translation table. The entry - * replaces all old entries for the same virtual I/O address range. - * Deleted entries have .@perm == 0. + * @event: TLB event with the new entry in the IOMMU translation table. + * The entry replaces all old entries for the same virtual I/O address + * range. */ void memory_region_notify_iommu_one(IOMMUNotifier *notifier, - IOMMUTLBEntry *entry); + IOMMUTLBEvent *event); /** * memory_region_register_iommu_notifier: register a notifier for changes to diff --git a/hw/arm/smmu-common.c b/hw/arm/smmu-common.c index 88d2c454f0..405d5c5325 100644 --- a/hw/arm/smmu-common.c +++ b/hw/arm/smmu-common.c @@ -465,14 +465,15 @@ IOMMUMemoryRegion *smmu_iommu_mr(SMMUState *s, uint32_t sid) /* Unmap the whole notifier's range */ static void smmu_unmap_notifier_range(IOMMUNotifier *n) { - IOMMUTLBEntry entry; + IOMMUTLBEvent event; - entry.target_as = &address_space_memory; - entry.iova = n->start; - entry.perm = IOMMU_NONE; - entry.addr_mask = n->end - n->start; + event.type = IOMMU_NOTIFIER_UNMAP; + event.entry.target_as = &address_space_memory; + event.entry.iova = n->start; + event.entry.perm = IOMMU_NONE; + event.entry.addr_mask = n->end - n->start; - memory_region_notify_iommu_one(n, &entry); + memory_region_notify_iommu_one(n, &event); } /* Unmap all notifiers attached to @mr */ diff --git a/hw/arm/smmuv3.c b/hw/arm/smmuv3.c index 273f5f7dce..bbca0e9f20 100644 --- a/hw/arm/smmuv3.c +++ b/hw/arm/smmuv3.c @@ -800,7 +800,7 @@ static void smmuv3_notify_iova(IOMMUMemoryRegion *mr, uint8_t tg, uint64_t num_pages) { SMMUDevice *sdev = container_of(mr, SMMUDevice, iommu); - IOMMUTLBEntry entry; + IOMMUTLBEvent event; uint8_t granule = tg; if (!tg) { @@ -823,12 +823,13 @@ static void smmuv3_notify_iova(IOMMUMemoryRegion *mr, granule = tt->granule_sz; } - entry.target_as = &address_space_memory; - entry.iova = iova; - entry.addr_mask = num_pages * (1 << granule) - 1; - entry.perm = IOMMU_NONE; + event.type = IOMMU_NOTIFIER_UNMAP; + event.entry.target_as = &address_space_memory; + event.entry.iova = iova; + event.entry.addr_mask = num_pages * (1 << granule) - 1; + event.entry.perm = IOMMU_NONE; - memory_region_notify_iommu_one(n, &entry); + memory_region_notify_iommu_one(n, &event); } /* invalidate an asid/iova range tuple in all mr's */ diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c index 067593b9e4..56180b1c43 100644 --- a/hw/i386/intel_iommu.c +++ b/hw/i386/intel_iommu.c @@ -1073,7 +1073,7 @@ static int vtd_iova_to_slpte(IntelIOMMUState *s, VTDContextEntry *ce, } } -typedef int (*vtd_page_walk_hook)(IOMMUTLBEntry *entry, void *private); +typedef int (*vtd_page_walk_hook)(IOMMUTLBEvent *event, void *private); /** * Constant information used during page walking @@ -1094,11 +1094,12 @@ typedef struct { uint16_t domain_id; } vtd_page_walk_info; -static int vtd_page_walk_one(IOMMUTLBEntry *entry, vtd_page_walk_info *info) +static int vtd_page_walk_one(IOMMUTLBEvent *event, vtd_page_walk_info *info) { VTDAddressSpace *as = info->as; vtd_page_walk_hook hook_fn = info->hook_fn; void *private = info->private; + IOMMUTLBEntry *entry = &event->entry; DMAMap target = { .iova = entry->iova, .size = entry->addr_mask, @@ -1107,7 +1108,7 @@ static int vtd_page_walk_one(IOMMUTLBEntry *entry, vtd_page_walk_info *info) }; DMAMap *mapped = iova_tree_find(as->iova_tree, &target); - if (entry->perm == IOMMU_NONE && !info->notify_unmap) { + if (event->type == IOMMU_NOTIFIER_UNMAP && !info->notify_unmap) { trace_vtd_page_walk_one_skip_unmap(entry->iova, entry->addr_mask); return 0; } @@ -1115,7 +1116,7 @@ static int vtd_page_walk_one(IOMMUTLBEntry *entry, vtd_page_walk_info *info) assert(hook_fn); /* Update local IOVA mapped ranges */ - if (entry->perm) { + if (event->type == IOMMU_NOTIFIER_MAP) { if (mapped) { /* If it's exactly the same translation, skip */ if (!memcmp(mapped, &target, sizeof(target))) { @@ -1141,19 +1142,21 @@ static int vtd_page_walk_one(IOMMUTLBEntry *entry, vtd_page_walk_info *info) int ret; /* Emulate an UNMAP */ + event->type = IOMMU_NOTIFIER_UNMAP; entry->perm = IOMMU_NONE; trace_vtd_page_walk_one(info->domain_id, entry->iova, entry->translated_addr, entry->addr_mask, entry->perm); - ret = hook_fn(entry, private); + ret = hook_fn(event, private); if (ret) { return ret; } /* Drop any existing mapping */ iova_tree_remove(as->iova_tree, &target); - /* Recover the correct permission */ + /* Recover the correct type */ + event->type = IOMMU_NOTIFIER_MAP; entry->perm = cache_perm; } } @@ -1170,7 +1173,7 @@ static int vtd_page_walk_one(IOMMUTLBEntry *entry, vtd_page_walk_info *info) trace_vtd_page_walk_one(info->domain_id, entry->iova, entry->translated_addr, entry->addr_mask, entry->perm); - return hook_fn(entry, private); + return hook_fn(event, private); } /** @@ -1191,7 +1194,7 @@ static int vtd_page_walk_level(dma_addr_t addr, uint64_t start, uint32_t offset; uint64_t slpte; uint64_t subpage_size, subpage_mask; - IOMMUTLBEntry entry; + IOMMUTLBEvent event; uint64_t iova = start; uint64_t iova_next; int ret = 0; @@ -1245,13 +1248,15 @@ static int vtd_page_walk_level(dma_addr_t addr, uint64_t start, * * In either case, we send an IOTLB notification down. */ - entry.target_as = &address_space_memory; - entry.iova = iova & subpage_mask; - entry.perm = IOMMU_ACCESS_FLAG(read_cur, write_cur); - entry.addr_mask = ~subpage_mask; + event.entry.target_as = &address_space_memory; + event.entry.iova = iova & subpage_mask; + event.entry.perm = IOMMU_ACCESS_FLAG(read_cur, write_cur); + event.entry.addr_mask = ~subpage_mask; /* NOTE: this is only meaningful if entry_valid == true */ - entry.translated_addr = vtd_get_slpte_addr(slpte, info->aw); - ret = vtd_page_walk_one(&entry, info); + event.entry.translated_addr = vtd_get_slpte_addr(slpte, info->aw); + event.type = event.entry.perm ? IOMMU_NOTIFIER_MAP : + IOMMU_NOTIFIER_UNMAP; + ret = vtd_page_walk_one(&event, info); } if (ret < 0) { @@ -1430,10 +1435,10 @@ static int vtd_dev_to_context_entry(IntelIOMMUState *s, uint8_t bus_num, return 0; } -static int vtd_sync_shadow_page_hook(IOMMUTLBEntry *entry, +static int vtd_sync_shadow_page_hook(IOMMUTLBEvent *event, void *private) { - memory_region_notify_iommu((IOMMUMemoryRegion *)private, 0, *entry); + memory_region_notify_iommu(private, 0, *event); return 0; } @@ -1993,14 +1998,17 @@ static void vtd_iotlb_page_invalidate_notify(IntelIOMMUState *s, * page tables. We just deliver the PSI down to * invalidate caches. */ - IOMMUTLBEntry entry = { - .target_as = &address_space_memory, - .iova = addr, - .translated_addr = 0, - .addr_mask = size - 1, - .perm = IOMMU_NONE, + IOMMUTLBEvent event = { + .type = IOMMU_NOTIFIER_UNMAP, + .entry = { + .target_as = &address_space_memory, + .iova = addr, + .translated_addr = 0, + .addr_mask = size - 1, + .perm = IOMMU_NONE, + }, }; - memory_region_notify_iommu(&vtd_as->iommu, 0, entry); + memory_region_notify_iommu(&vtd_as->iommu, 0, event); } } } @@ -2412,7 +2420,7 @@ static bool vtd_process_device_iotlb_desc(IntelIOMMUState *s, VTDInvDesc *inv_desc) { VTDAddressSpace *vtd_dev_as; - IOMMUTLBEntry entry; + IOMMUTLBEvent event; struct VTDBus *vtd_bus; hwaddr addr; uint64_t sz; @@ -2460,12 +2468,13 @@ static bool vtd_process_device_iotlb_desc(IntelIOMMUState *s, sz = VTD_PAGE_SIZE; } - entry.target_as = &vtd_dev_as->as; - entry.addr_mask = sz - 1; - entry.iova = addr; - entry.perm = IOMMU_NONE; - entry.translated_addr = 0; - memory_region_notify_iommu(&vtd_dev_as->iommu, 0, entry); + event.type = IOMMU_NOTIFIER_UNMAP; + event.entry.target_as = &vtd_dev_as->as; + event.entry.addr_mask = sz - 1; + event.entry.iova = addr; + event.entry.perm = IOMMU_NONE; + event.entry.translated_addr = 0; + memory_region_notify_iommu(&vtd_dev_as->iommu, 0, event); done: return true; @@ -3485,19 +3494,20 @@ static void vtd_address_space_unmap(VTDAddressSpace *as, IOMMUNotifier *n) size = remain = end - start + 1; while (remain >= VTD_PAGE_SIZE) { - IOMMUTLBEntry entry; + IOMMUTLBEvent event; uint64_t mask = get_naturally_aligned_size(start, remain, s->aw_bits); assert(mask); - entry.iova = start; - entry.addr_mask = mask - 1; - entry.target_as = &address_space_memory; - entry.perm = IOMMU_NONE; + event.type = IOMMU_NOTIFIER_UNMAP; + event.entry.iova = start; + event.entry.addr_mask = mask - 1; + event.entry.target_as = &address_space_memory; + event.entry.perm = IOMMU_NONE; /* This field is meaningless for unmap */ - entry.translated_addr = 0; + event.entry.translated_addr = 0; - memory_region_notify_iommu_one(n, &entry); + memory_region_notify_iommu_one(n, &event); start += mask; remain -= mask; @@ -3533,9 +3543,9 @@ static void vtd_address_space_refresh_all(IntelIOMMUState *s) vtd_switch_address_space_all(s); } -static int vtd_replay_hook(IOMMUTLBEntry *entry, void *private) +static int vtd_replay_hook(IOMMUTLBEvent *event, void *private) { - memory_region_notify_iommu_one((IOMMUNotifier *)private, entry); + memory_region_notify_iommu_one(private, event); return 0; } diff --git a/hw/misc/tz-mpc.c b/hw/misc/tz-mpc.c index 98f151237f..30481e1c90 100644 --- a/hw/misc/tz-mpc.c +++ b/hw/misc/tz-mpc.c @@ -82,8 +82,10 @@ static void tz_mpc_iommu_notify(TZMPC *s, uint32_t lutidx, /* Called when the LUT word at lutidx has changed from oldlut to newlut; * must call the IOMMU notifiers for the changed blocks. */ - IOMMUTLBEntry entry = { - .addr_mask = s->blocksize - 1, + IOMMUTLBEvent event = { + .entry = { + .addr_mask = s->blocksize - 1, + } }; hwaddr addr = lutidx * s->blocksize * 32; int i; @@ -100,26 +102,28 @@ static void tz_mpc_iommu_notify(TZMPC *s, uint32_t lutidx, block_is_ns = newlut & (1 << i); trace_tz_mpc_iommu_notify(addr); - entry.iova = addr; - entry.translated_addr = addr; + event.entry.iova = addr; + event.entry.translated_addr = addr; - entry.perm = IOMMU_NONE; - memory_region_notify_iommu(&s->upstream, IOMMU_IDX_S, entry); - memory_region_notify_iommu(&s->upstream, IOMMU_IDX_NS, entry); + event.type = IOMMU_NOTIFIER_UNMAP; + event.entry.perm = IOMMU_NONE; + memory_region_notify_iommu(&s->upstream, IOMMU_IDX_S, event); + memory_region_notify_iommu(&s->upstream, IOMMU_IDX_NS, event); - entry.perm = IOMMU_RW; + event.type = IOMMU_NOTIFIER_MAP; + event.entry.perm = IOMMU_RW; if (block_is_ns) { - entry.target_as = &s->blocked_io_as; + event.entry.target_as = &s->blocked_io_as; } else { - entry.target_as = &s->downstream_as; + event.entry.target_as = &s->downstream_as; } - memory_region_notify_iommu(&s->upstream, IOMMU_IDX_S, entry); + memory_region_notify_iommu(&s->upstream, IOMMU_IDX_S, event); if (block_is_ns) { - entry.target_as = &s->downstream_as; + event.entry.target_as = &s->downstream_as; } else { - entry.target_as = &s->blocked_io_as; + event.entry.target_as = &s->blocked_io_as; } - memory_region_notify_iommu(&s->upstream, IOMMU_IDX_NS, entry); + memory_region_notify_iommu(&s->upstream, IOMMU_IDX_NS, event); } } diff --git a/hw/ppc/spapr_iommu.c b/hw/ppc/spapr_iommu.c index 0790239ba5..30352df00e 100644 --- a/hw/ppc/spapr_iommu.c +++ b/hw/ppc/spapr_iommu.c @@ -445,7 +445,7 @@ static void spapr_tce_reset(DeviceState *dev) static target_ulong put_tce_emu(SpaprTceTable *tcet, target_ulong ioba, target_ulong tce) { - IOMMUTLBEntry entry; + IOMMUTLBEvent event; hwaddr page_mask = IOMMU_PAGE_MASK(tcet->page_shift); unsigned long index = (ioba - tcet->bus_offset) >> tcet->page_shift; @@ -457,12 +457,13 @@ static target_ulong put_tce_emu(SpaprTceTable *tcet, target_ulong ioba, tcet->table[index] = tce; - entry.target_as = &address_space_memory, - entry.iova = (ioba - tcet->bus_offset) & page_mask; - entry.translated_addr = tce & page_mask; - entry.addr_mask = ~page_mask; - entry.perm = spapr_tce_iommu_access_flags(tce); - memory_region_notify_iommu(&tcet->iommu, 0, entry); + event.entry.target_as = &address_space_memory, + event.entry.iova = (ioba - tcet->bus_offset) & page_mask; + event.entry.translated_addr = tce & page_mask; + event.entry.addr_mask = ~page_mask; + event.entry.perm = spapr_tce_iommu_access_flags(tce); + event.type = event.entry.perm ? IOMMU_NOTIFIER_MAP : IOMMU_NOTIFIER_UNMAP; + memory_region_notify_iommu(&tcet->iommu, 0, event); return H_SUCCESS; } diff --git a/hw/s390x/s390-pci-inst.c b/hw/s390x/s390-pci-inst.c index 70bfd91bf7..d9e1e29f1e 100644 --- a/hw/s390x/s390-pci-inst.c +++ b/hw/s390x/s390-pci-inst.c @@ -602,15 +602,18 @@ static uint32_t s390_pci_update_iotlb(S390PCIIOMMU *iommu, S390IOTLBEntry *entry) { S390IOTLBEntry *cache = g_hash_table_lookup(iommu->iotlb, &entry->iova); - IOMMUTLBEntry notify = { - .target_as = &address_space_memory, - .iova = entry->iova, - .translated_addr = entry->translated_addr, - .perm = entry->perm, - .addr_mask = ~PAGE_MASK, + IOMMUTLBEvent event = { + .type = entry->perm ? IOMMU_NOTIFIER_MAP : IOMMU_NOTIFIER_UNMAP, + .entry = { + .target_as = &address_space_memory, + .iova = entry->iova, + .translated_addr = entry->translated_addr, + .perm = entry->perm, + .addr_mask = ~PAGE_MASK, + }, }; - if (entry->perm == IOMMU_NONE) { + if (event.type == IOMMU_NOTIFIER_UNMAP) { if (!cache) { goto out; } @@ -623,9 +626,11 @@ static uint32_t s390_pci_update_iotlb(S390PCIIOMMU *iommu, goto out; } - notify.perm = IOMMU_NONE; - memory_region_notify_iommu(&iommu->iommu_mr, 0, notify); - notify.perm = entry->perm; + event.type = IOMMU_NOTIFIER_UNMAP; + event.entry.perm = IOMMU_NONE; + memory_region_notify_iommu(&iommu->iommu_mr, 0, event); + event.type = IOMMU_NOTIFIER_MAP; + event.entry.perm = entry->perm; } cache = g_new(S390IOTLBEntry, 1); @@ -637,7 +642,7 @@ static uint32_t s390_pci_update_iotlb(S390PCIIOMMU *iommu, dec_dma_avail(iommu); } - memory_region_notify_iommu(&iommu->iommu_mr, 0, notify); + memory_region_notify_iommu(&iommu->iommu_mr, 0, event); out: return iommu->dma_limit ? iommu->dma_limit->avail : 1; diff --git a/hw/virtio/virtio-iommu.c b/hw/virtio/virtio-iommu.c index fc5c75d693..cea8811295 100644 --- a/hw/virtio/virtio-iommu.c +++ b/hw/virtio/virtio-iommu.c @@ -129,7 +129,7 @@ static void virtio_iommu_notify_map(IOMMUMemoryRegion *mr, hwaddr virt_start, hwaddr virt_end, hwaddr paddr, uint32_t flags) { - IOMMUTLBEntry entry; + IOMMUTLBEvent event; IOMMUAccessFlags perm = IOMMU_ACCESS_FLAG(flags & VIRTIO_IOMMU_MAP_F_READ, flags & VIRTIO_IOMMU_MAP_F_WRITE); @@ -141,19 +141,20 @@ static void virtio_iommu_notify_map(IOMMUMemoryRegion *mr, hwaddr virt_start, trace_virtio_iommu_notify_map(mr->parent_obj.name, virt_start, virt_end, paddr, perm); - entry.target_as = &address_space_memory; - entry.addr_mask = virt_end - virt_start; - entry.iova = virt_start; - entry.perm = perm; - entry.translated_addr = paddr; + event.type = IOMMU_NOTIFIER_MAP; + event.entry.target_as = &address_space_memory; + event.entry.addr_mask = virt_end - virt_start; + event.entry.iova = virt_start; + event.entry.perm = perm; + event.entry.translated_addr = paddr; - memory_region_notify_iommu(mr, 0, entry); + memory_region_notify_iommu(mr, 0, event); } static void virtio_iommu_notify_unmap(IOMMUMemoryRegion *mr, hwaddr virt_start, hwaddr virt_end) { - IOMMUTLBEntry entry; + IOMMUTLBEvent event; if (!(mr->iommu_notify_flags & IOMMU_NOTIFIER_UNMAP)) { return; @@ -161,13 +162,14 @@ static void virtio_iommu_notify_unmap(IOMMUMemoryRegion *mr, hwaddr virt_start, trace_virtio_iommu_notify_unmap(mr->parent_obj.name, virt_start, virt_end); - entry.target_as = &address_space_memory; - entry.addr_mask = virt_end - virt_start; - entry.iova = virt_start; - entry.perm = IOMMU_NONE; - entry.translated_addr = 0; + event.type = IOMMU_NOTIFIER_UNMAP; + event.entry.target_as = &address_space_memory; + event.entry.addr_mask = virt_end - virt_start; + event.entry.iova = virt_start; + event.entry.perm = IOMMU_NONE; + event.entry.translated_addr = 0; - memory_region_notify_iommu(mr, 0, entry); + memory_region_notify_iommu(mr, 0, event); } static gboolean virtio_iommu_notify_unmap_cb(gpointer key, gpointer value, diff --git a/softmmu/memory.c b/softmmu/memory.c index 44de610c72..6ca87e8d73 100644 --- a/softmmu/memory.c +++ b/softmmu/memory.c @@ -1943,11 +1943,15 @@ void memory_region_unregister_iommu_notifier(MemoryRegion *mr, } void memory_region_notify_iommu_one(IOMMUNotifier *notifier, - IOMMUTLBEntry *entry) + IOMMUTLBEvent *event) { - IOMMUNotifierFlag request_flags; + IOMMUTLBEntry *entry = &event->entry; hwaddr entry_end = entry->iova + entry->addr_mask; + if (event->type == IOMMU_NOTIFIER_UNMAP) { + assert(entry->perm == IOMMU_NONE); + } + /* * Skip the notification if the notification does not overlap * with registered range. @@ -1958,20 +1962,14 @@ void memory_region_notify_iommu_one(IOMMUNotifier *notifier, assert(entry->iova >= notifier->start && entry_end <= notifier->end); - if (entry->perm & IOMMU_RW) { - request_flags = IOMMU_NOTIFIER_MAP; - } else { - request_flags = IOMMU_NOTIFIER_UNMAP; - } - - if (notifier->notifier_flags & request_flags) { + if (event->type & notifier->notifier_flags) { notifier->notify(notifier, entry); } } void memory_region_notify_iommu(IOMMUMemoryRegion *iommu_mr, int iommu_idx, - IOMMUTLBEntry entry) + IOMMUTLBEvent event) { IOMMUNotifier *iommu_notifier; @@ -1979,7 +1977,7 @@ void memory_region_notify_iommu(IOMMUMemoryRegion *iommu_mr, IOMMU_NOTIFIER_FOREACH(iommu_notifier, iommu_mr) { if (iommu_notifier->iommu_idx == iommu_idx) { - memory_region_notify_iommu_one(iommu_notifier, &entry); + memory_region_notify_iommu_one(iommu_notifier, &event); } } } From patchwork Wed Dec 2 11:03:16 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 1409646 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=F7V14atI; dkim-atps=neutral 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 ozlabs.org (Postfix) with ESMTPS id 4CmGR00ZzPz9sTL for ; Wed, 2 Dec 2020 22:07:56 +1100 (AEDT) Received: from localhost ([::1]:57560 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kkPzG-0005hr-1Y for incoming@patchwork.ozlabs.org; Wed, 02 Dec 2020 06:07:54 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:37398) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kkPuv-0002rj-Th for qemu-devel@nongnu.org; Wed, 02 Dec 2020 06:03:25 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:55404) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kkPut-0002sj-Iy for qemu-devel@nongnu.org; Wed, 02 Dec 2020 06:03:25 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1606907002; 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=DDpDvWnDXn0+AbenIHpi5XjLObz83cMo1H8va2rlpRI=; b=F7V14atITgh3bRASO5841cvLjXnVximhYwvdyDY7yk80nsbKTfzOn9cDH5yPbEcYJO2Ll0 5hriPv8jBpd9wtBFH4diWAdL9XKVFja2HWjgcdAD0wLxXQdNA2uXR65YpZ4FDS4DwitFdn PFNU0/roUM8lby8V67CMXYXmO6y2P3g= Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-19-JEbTa4ITODC1D-dVv69jgw-1; Wed, 02 Dec 2020 06:03:21 -0500 X-MC-Unique: JEbTa4ITODC1D-dVv69jgw-1 Received: by mail-wr1-f71.google.com with SMTP id b5so3359950wrp.3 for ; Wed, 02 Dec 2020 03:03:20 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to; bh=DDpDvWnDXn0+AbenIHpi5XjLObz83cMo1H8va2rlpRI=; b=jFSADVEw+NGp2Dm9HcvdYGC6kEgBAS9t2+1hz0NI1L0IWIds3nfBTI9oRxWCmdEOFg uPzhXUsvuVjKC/lUmqizELccleHhccoTfEm49FbGzy1pHLpIZy+40pKWjQrMFdz+nSVQ AamHXox9+e2crQvBhd24L3kxSZspA2C8v+kssADrHRfBHi6P2GGMSpRP5IcSuRtb2nrF lLQghK5h1vUqqo3MvWl5SzhZHIvhaanmSw1oNdArQziAWyv05QrQGl10u48wABUVe6pw uUk2LnrYYnYsdsgQ6YKlCxp16U+DE0USxb/Jj86AAjCVaSuKloOD6Adu2x1Q1xtlmQgA 9pNA== X-Gm-Message-State: AOAM5333wK8ZjAZiQ3LYY1dwIqdoCLiId2+O/wauNTHhxoZOEDYv9+NY +z2Z5GQ6yyyU8JoeDU9KWrcrUu/53p5VeUul9Ef9eZ0u/osJt2PsXu4O2f67XQJF0wf2DYVx+3N 2gzjYaYBUaURYoklZTeAm/jwf4AP7YqyD+Rvez0mLZ958wqnH2GX6MqrdgYp5 X-Received: by 2002:a5d:4a84:: with SMTP id o4mr2732243wrq.57.1606906999537; Wed, 02 Dec 2020 03:03:19 -0800 (PST) X-Google-Smtp-Source: ABdhPJwOY8XQ6Mv+l68v/d5uYNgN/5+/W2qBz+beV9kR70g+pVMQA8oe3rYmuwXrl4R3LFY+qInoAA== X-Received: by 2002:a5d:4a84:: with SMTP id o4mr2732204wrq.57.1606906999238; Wed, 02 Dec 2020 03:03:19 -0800 (PST) Received: from redhat.com (bzq-79-176-44-197.red.bezeqint.net. [79.176.44.197]) by smtp.gmail.com with ESMTPSA id g18sm1838702wrp.63.2020.12.02.03.03.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Dec 2020 03:03:18 -0800 (PST) Date: Wed, 2 Dec 2020 06:03:16 -0500 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Subject: [PULL 4/6] memory: Add IOMMU_NOTIFIER_DEVIOTLB_UNMAP IOMMUTLBNotificationType Message-ID: <20201202101655.122214-5-mst@redhat.com> References: <20201202101655.122214-1-mst@redhat.com> MIME-Version: 1.0 In-Reply-To: <20201202101655.122214-1-mst@redhat.com> X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=mst@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline Received-SPF: pass client-ip=216.205.24.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -35 X-Spam_score: -3.6 X-Spam_bar: --- X-Spam_report: (-3.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.497, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=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: Peter Maydell , Eduardo Habkost , Juan Quintela , Jason Wang , Richard Henderson , Peter Xu , Eugenio =?utf-8?b?UMOpcmV6?= , Paolo Bonzini Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Eugenio Pérez This allows us to differentiate between regular IOMMU map/unmap events and DEVIOTLB unmap. Doing so, notifiers that only need device IOTLB invalidations will not receive regular IOMMU unmappings. Adapt intel and vhost to use it. Signed-off-by: Eugenio Pérez Reviewed-by: Peter Xu Reviewed-by: Juan Quintela Acked-by: Jason Wang Message-Id: <20201116165506.31315-4-eperezma@redhat.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- include/exec/memory.h | 7 ++++++- hw/i386/intel_iommu.c | 2 +- hw/virtio/vhost.c | 2 +- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/include/exec/memory.h b/include/exec/memory.h index e86b5e92da..521d9901d7 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -97,9 +97,14 @@ typedef enum { IOMMU_NOTIFIER_UNMAP = 0x1, /* Notify entry changes (newly created entries) */ IOMMU_NOTIFIER_MAP = 0x2, + /* Notify changes on device IOTLB entries */ + IOMMU_NOTIFIER_DEVIOTLB_UNMAP = 0x04, } IOMMUNotifierFlag; -#define IOMMU_NOTIFIER_ALL (IOMMU_NOTIFIER_MAP | IOMMU_NOTIFIER_UNMAP) +#define IOMMU_NOTIFIER_IOTLB_EVENTS (IOMMU_NOTIFIER_MAP | IOMMU_NOTIFIER_UNMAP) +#define IOMMU_NOTIFIER_DEVIOTLB_EVENTS IOMMU_NOTIFIER_DEVIOTLB_UNMAP +#define IOMMU_NOTIFIER_ALL (IOMMU_NOTIFIER_IOTLB_EVENTS | \ + IOMMU_NOTIFIER_DEVIOTLB_EVENTS) struct IOMMUNotifier; typedef void (*IOMMUNotify)(struct IOMMUNotifier *notifier, diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c index 56180b1c43..edc3090f91 100644 --- a/hw/i386/intel_iommu.c +++ b/hw/i386/intel_iommu.c @@ -2468,7 +2468,7 @@ static bool vtd_process_device_iotlb_desc(IntelIOMMUState *s, sz = VTD_PAGE_SIZE; } - event.type = IOMMU_NOTIFIER_UNMAP; + event.type = IOMMU_NOTIFIER_DEVIOTLB_UNMAP; event.entry.target_as = &vtd_dev_as->as; event.entry.addr_mask = sz - 1; event.entry.iova = addr; diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c index 614ccc2bcb..28c7d78172 100644 --- a/hw/virtio/vhost.c +++ b/hw/virtio/vhost.c @@ -718,7 +718,7 @@ static void vhost_iommu_region_add(MemoryListener *listener, iommu_idx = memory_region_iommu_attrs_to_index(iommu_mr, MEMTXATTRS_UNSPECIFIED); iommu_notifier_init(&iommu->n, vhost_iommu_unmap_notify, - IOMMU_NOTIFIER_UNMAP, + IOMMU_NOTIFIER_DEVIOTLB_UNMAP, section->offset_within_region, int128_get64(end), iommu_idx); From patchwork Wed Dec 2 11:03:19 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 1409653 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=itmuQvke; dkim-atps=neutral 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 ozlabs.org (Postfix) with ESMTPS id 4CmGjH4Sd7z9sVw for ; Wed, 2 Dec 2020 22:20:19 +1100 (AEDT) Received: from localhost ([::1]:59626 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kkQBF-0002rI-J3 for incoming@patchwork.ozlabs.org; Wed, 02 Dec 2020 06:20:17 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:39040) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kkPzT-0006lW-0p for qemu-devel@nongnu.org; Wed, 02 Dec 2020 06:08:07 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:38724) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kkPzQ-0004Yc-Kd for qemu-devel@nongnu.org; Wed, 02 Dec 2020 06:08:06 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1606907283; 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=LOFadtS8P+HipB+dMXVoHfndgHAL2KBXN7L2k6t4OKo=; b=itmuQvkehMAaUGVUrepB0jtpU4MWfm9JKC3cr4xXITdBBRjyED3nO/OY71LqmC6GVmnXw5 p2Q1/W1sOdBmhdyZaf5+twSPpWs9saTsA92IvZO2xkyyCvVHyC8dSMLU5a1khvyLtSmRWn udnzLx7vVfKs96EbGbcUIXtv97UYXuA= Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-584-emRIhzgXNkOPA0fxQES1Nw-1; Wed, 02 Dec 2020 06:03:24 -0500 X-MC-Unique: emRIhzgXNkOPA0fxQES1Nw-1 Received: by mail-wr1-f69.google.com with SMTP id w17so3327780wrl.8 for ; Wed, 02 Dec 2020 03:03:24 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to; bh=LOFadtS8P+HipB+dMXVoHfndgHAL2KBXN7L2k6t4OKo=; b=h7Ayg+tFqzAIJfMkcufzqoskD/vVd9pjtO3Qi18DBxR6SHjiiAPwKLhDvGloM4kQp/ Kmm1jP5nuzxINU07dOhWqSZ5Pmy0F15GxF8voeyVoi1lnKmJlXbPJ1ewZMe7Ix0G7l5T k69Yg06O5Tl3p/nUDqd11xS4N4tLcFzIVydYe4kwHUvbFh3rWz+wPBza8X29LV+DhNA7 M1PGFRTBZ41n/Kdzf0B713i4n7TiQfx7gilbInuxt2KF2rbCyvf7N8323cehhJpPh6x1 GXRcewBpsdKSwZ3rmux+Col39qqT2W8o+aXdP4y+Kde7OUmlpQXHO8Gzw2wo5p9zvSBE 2RYw== X-Gm-Message-State: AOAM531meN9NuuuFv5oNUuRmIZg+jBzVK9EtNWmmB/Sv1afjC1vYFwmo htGw+r6+zXDNoNwTT0XYRrkENXFwoV34flDRyISdvMNQFXfzsY4UCbb4Nqin4JmZvucSVVcrcvk 46+lhTMdVfPESZLRuxA35Tm/b+Ooz3c1AzoVGLfcW2TnXmGBIl7odLoHYCB6Z X-Received: by 2002:adf:dd09:: with SMTP id a9mr2736169wrm.128.1606907002926; Wed, 02 Dec 2020 03:03:22 -0800 (PST) X-Google-Smtp-Source: ABdhPJyZEcw9h18148/+x9Vx8uxRpofgzQNaSfwww6H0KZDfXX4pDEhfZuivS7KGY9UdXBTNKu0C1g== X-Received: by 2002:adf:dd09:: with SMTP id a9mr2736043wrm.128.1606907001659; Wed, 02 Dec 2020 03:03:21 -0800 (PST) Received: from redhat.com (bzq-79-176-44-197.red.bezeqint.net. [79.176.44.197]) by smtp.gmail.com with ESMTPSA id i16sm1667455wru.92.2020.12.02.03.03.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Dec 2020 03:03:21 -0800 (PST) Date: Wed, 2 Dec 2020 06:03:19 -0500 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Subject: [PULL 5/6] intel_iommu: Skip page walking on device iotlb invalidations Message-ID: <20201202101655.122214-6-mst@redhat.com> References: <20201202101655.122214-1-mst@redhat.com> MIME-Version: 1.0 In-Reply-To: <20201202101655.122214-1-mst@redhat.com> X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=mst@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline Received-SPF: pass client-ip=63.128.21.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -35 X-Spam_score: -3.6 X-Spam_bar: --- X-Spam_report: (-3.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.497, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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: Peter Maydell , Eduardo Habkost , Jason Wang , Richard Henderson , Peter Xu , Eugenio =?utf-8?b?UMOpcmV6?= , Paolo Bonzini Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Eugenio Pérez Although they didn't reach the notifier because of the filtering in memory_region_notify_iommu_one, the vt-d was still splitting huge memory invalidations in chunks. Skipping it. This improves performance in case of netperf with vhost-net: * TCP_STREAM: From 1923.6Mbit/s to 2175.13Mbit/s (13%) * TCP_RR: From 8464.73 trans/s to 8932.703333 trans/s (5.5%) * UDP_RR: From 8562.08 trans/s to 9005.62/s (5.1%) * UDP_STREAM: No change observed (insignificant 0.1% improvement) Signed-off-by: Eugenio Pérez Acked-by: Jason Wang Message-Id: <20201116165506.31315-5-eperezma@redhat.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- hw/i386/intel_iommu.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c index edc3090f91..0cc71e4057 100644 --- a/hw/i386/intel_iommu.c +++ b/hw/i386/intel_iommu.c @@ -1478,6 +1478,10 @@ static int vtd_sync_shadow_page_table(VTDAddressSpace *vtd_as) VTDContextEntry ce; IOMMUNotifier *n; + if (!(vtd_as->iommu.iommu_notify_flags & IOMMU_NOTIFIER_IOTLB_EVENTS)) { + return 0; + } + ret = vtd_dev_to_context_entry(vtd_as->iommu_state, pci_bus_num(vtd_as->bus), vtd_as->devfn, &ce); From patchwork Wed Dec 2 11:03:23 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 1409652 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=MCo9EFna; dkim-atps=neutral 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 ozlabs.org (Postfix) with ESMTPS id 4CmGgQ36qHz9sVw for ; Wed, 2 Dec 2020 22:18:40 +1100 (AEDT) Received: from localhost ([::1]:54144 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kkQ9d-0000Yj-Kt for incoming@patchwork.ozlabs.org; Wed, 02 Dec 2020 06:18:37 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:37428) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kkPv0-00031l-Kh for qemu-devel@nongnu.org; Wed, 02 Dec 2020 06:03:30 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:41334) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kkPuz-0002ut-0o for qemu-devel@nongnu.org; Wed, 02 Dec 2020 06:03:30 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1606907008; 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=zxJ3f9AkcimEoHVGFWIULEfxtXcI3G+nN2yyJC0qTJU=; b=MCo9EFnaA2c/zW23cLHn+J4S/HWZo/dlo3WiEwUHAxSGBi3EERcOHetKzd+w5KfKeOxr3h OkNpCc+s0ShxrPufpAT3dDgERSX6JT9r3VHlRymZv/rOV+/R6gb4A4gSQMe2AAoHV6diTF lDrDTyx72SpT5VmzhaDUxJrFlDeXTrY= Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-27-g5CwY4g0Ni63cTCCNpolhg-1; Wed, 02 Dec 2020 06:03:26 -0500 X-MC-Unique: g5CwY4g0Ni63cTCCNpolhg-1 Received: by mail-wr1-f69.google.com with SMTP id b12so3304590wru.15 for ; Wed, 02 Dec 2020 03:03:26 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to; bh=zxJ3f9AkcimEoHVGFWIULEfxtXcI3G+nN2yyJC0qTJU=; b=RlXaaX8R2jmcb0bov/YA/POrTRfeorFy6a7kQUpdddaK3xd9+DsKT8pZW21zRN3hMc bTFd4sFNGEWHjckJURlKU8bX1vtBSk8Oocwypwtb4HnrdHuLzrXt4mU3jOKEyBi5r3/S I4v0LFqN03HjNMFLAQxpHLn8KVSdPbBZiWJ82DmzpV7cqDgLzyQ4EWFxvS/D/ayndzYI rqbK+4ykM11Efyx6uGzzNg5Le/DuiBLqt1JCWXsQHfHj6s1BrEXs/Xy1YMMbH5ukwYMr I3TiVLHNjxmVhPq3sWK4GILN3fPouYJqgSZiy6HCviLfWfeQbnWLZasbXs4JKPqDoKJQ DO7g== X-Gm-Message-State: AOAM533HYYb1ytfjT4WltckveD2N+BLAUioAveRik0Z2mB+QkDajCpk1 f27p2Ejtzg3btevs1pbDb+13oNVSXe7scMWMchaTn0JJrFMrsqP9weko7/vNSULFFnyfuc5sRl8 1I9fQtL1g6I6l3grHVyofq4im6dJMdSZS+Vp0OCCOWhvXVdviw+70xcxwkIXJ X-Received: by 2002:adf:a549:: with SMTP id j9mr2716547wrb.199.1606907005498; Wed, 02 Dec 2020 03:03:25 -0800 (PST) X-Google-Smtp-Source: ABdhPJwRZGmsqZ80Aj5NqXQhVY1vaZpvY1Pnn5jQ4J/5DSm7RX2LtlT1AB2jArH32E4pWvLTpG9H4Q== X-Received: by 2002:adf:a549:: with SMTP id j9mr2716514wrb.199.1606907005247; Wed, 02 Dec 2020 03:03:25 -0800 (PST) Received: from redhat.com (bzq-79-176-44-197.red.bezeqint.net. [79.176.44.197]) by smtp.gmail.com with ESMTPSA id u26sm1665480wmm.24.2020.12.02.03.03.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Dec 2020 03:03:24 -0800 (PST) Date: Wed, 2 Dec 2020 06:03:23 -0500 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Subject: [PULL 6/6] memory: Skip bad range assertion if notifier is DEVIOTLB_UNMAP type Message-ID: <20201202101655.122214-7-mst@redhat.com> References: <20201202101655.122214-1-mst@redhat.com> MIME-Version: 1.0 In-Reply-To: <20201202101655.122214-1-mst@redhat.com> X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=mst@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline Received-SPF: pass client-ip=216.205.24.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -35 X-Spam_score: -3.6 X-Spam_bar: --- X-Spam_report: (-3.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.497, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=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: Peter Maydell , Juan Quintela , Jason Wang , Peter Xu , Eugenio =?utf-8?b?UMOpcmV6?= , Paolo Bonzini Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Eugenio Pérez Device IOTLB invalidations can unmap arbitrary ranges, eiter outside of the memory region or even [0, ~0ULL] for all the space. The assertion could be hit by a guest, and rhel7 guest effectively hit it. Signed-off-by: Eugenio Pérez Reviewed-by: Peter Xu Reviewed-by: Juan Quintela Acked-by: Jason Wang Message-Id: <20201116165506.31315-6-eperezma@redhat.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- softmmu/memory.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/softmmu/memory.c b/softmmu/memory.c index 6ca87e8d73..22bacbbc78 100644 --- a/softmmu/memory.c +++ b/softmmu/memory.c @@ -1947,6 +1947,7 @@ void memory_region_notify_iommu_one(IOMMUNotifier *notifier, { IOMMUTLBEntry *entry = &event->entry; hwaddr entry_end = entry->iova + entry->addr_mask; + IOMMUTLBEntry tmp = *entry; if (event->type == IOMMU_NOTIFIER_UNMAP) { assert(entry->perm == IOMMU_NONE); @@ -1960,10 +1961,16 @@ void memory_region_notify_iommu_one(IOMMUNotifier *notifier, return; } - assert(entry->iova >= notifier->start && entry_end <= notifier->end); + if (notifier->notifier_flags & IOMMU_NOTIFIER_DEVIOTLB_UNMAP) { + /* Crop (iova, addr_mask) to range */ + tmp.iova = MAX(tmp.iova, notifier->start); + tmp.addr_mask = MIN(entry_end, notifier->end) - tmp.iova; + } else { + assert(entry->iova >= notifier->start && entry_end <= notifier->end); + } if (event->type & notifier->notifier_flags) { - notifier->notify(notifier, entry); + notifier->notify(notifier, &tmp); } }