From nobody Mon Feb 9 08:57:22 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1604515640; cv=none; d=zohomail.com; s=zohoarc; b=PwQNb+WOghupcoBi9fSTzS7O0r5Gev0XeOVE/mhCjzzqRaG/XsJ1cYbAATXTdzW8j50cXoDmDm6gBhXcSrKdRbLPWIE3Q6kYSWJeUsSYyjbnlgkTw947e6Ux4IwgiwTe357untaT3vohWddlRg7z4hzr4svUpJIQjHZ1yUm7gnU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1604515640; h=Content-Type:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=yb0+hTu/cI4h7Se3wHsf9S5j6pZCfXhlBpQERrIdWig=; b=CGP8NpavyQq9zWW0dEGhoqD0oz8Rjs4G33pdDG8ptDA16seWucB/TEWcM4fgM6tgfUaG4fTp2bxyuhoB2rUHaqGUg/b/QdnU3Eal/N0YORtG2+iOC3uT6/OggH+rEMRCNCdhO4wBsJ5840fKun/xV6OuyDEMuUM1reJuqOAq038= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1604515640510336.79591178379326; Wed, 4 Nov 2020 10:47:20 -0800 (PST) Received: from localhost ([::1]:36572 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kaNoV-0000Jq-6A for importer@patchew.org; Wed, 04 Nov 2020 13:47:19 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:52394) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kaNjQ-00013X-3O for qemu-devel@nongnu.org; Wed, 04 Nov 2020 13:42:04 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:51785) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kaNjN-00021Y-JY for qemu-devel@nongnu.org; Wed, 04 Nov 2020 13:42:03 -0500 Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-225-IyBkSYblOSmNp14Ouqg0Pw-1; Wed, 04 Nov 2020 13:41:58 -0500 Received: by mail-wr1-f72.google.com with SMTP id h8so9633835wrt.9 for ; Wed, 04 Nov 2020 10:41:58 -0800 (PST) Received: from redhat.com (bzq-79-176-118-93.red.bezeqint.net. [79.176.118.93]) by smtp.gmail.com with ESMTPSA id u23sm3158102wmc.22.2020.11.04.10.41.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Nov 2020 10:41:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1604515320; 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=yb0+hTu/cI4h7Se3wHsf9S5j6pZCfXhlBpQERrIdWig=; b=MRbU3cYVzV0jXCS9m2CfwP8f7C5/Cy1I6OKsGO1zcsL690eKhcqAsf4iKsnt5SKsF2DVJ2 4kZ+pRTIE+MHKQ5cWWI5DjBae4dyQNudkCEWFEpcpdqHB3JtxDMsfEypqaOVq2KPwPsI2K Ke2hLCSM6G/iyN3cwdx/x4ZkaqFseII= X-MC-Unique: IyBkSYblOSmNp14Ouqg0Pw-1 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=yb0+hTu/cI4h7Se3wHsf9S5j6pZCfXhlBpQERrIdWig=; b=ltzwDKvMtSb7uLM0yDVKE4d0yhlI150eW7WG9a1gBCysDISR8qYFjHpiHC6Kkghzku fFBQHaFfaGvXMzLpzhKPXHU2L8K0x2rpcGcV/DUZnYverjHx1amLL3JgjRzfUqH3xMi4 lVZgIHhFWMKXmMvs8IidqzPIhT+gmEYwexcxqOAh0L8SFqFxgASGcYrEQgxefmVw2j8M QmsOCQqhIN8e6dzn0bBpYkKJO7Ev8CAV9GNvuV/E75COu/6CN4RhsObhsoYX3ZmZ3Tl5 yizTpiezPd5G81ZtWErd/u2CjwEqKMZJEPUIgFUNT79bHzSem4s3wgWNcRQZ2yzWCGXl nwmw== X-Gm-Message-State: AOAM53184gSD2fZyjy35paVJIA1NIo/i14WV3wbnusGDNrpuH+tEnfHW BJUjrK3vYBJ8o81zR9AZ1M11zWuJXntjNHl5pzAzfNbXWGNCvDM4mkqwADORI6WZ7lJ4W+dxEaj uFuViuf7Tsi96In0= X-Received: by 2002:adf:a551:: with SMTP id j17mr35913506wrb.217.1604515317026; Wed, 04 Nov 2020 10:41:57 -0800 (PST) X-Google-Smtp-Source: ABdhPJzif6kJPWWIqQLRE+Xsa2+DT3ne1XbRCcaIZd1ix1xiw40hXDzwFtXdHoeDtaRpMOPjzlHYdA== X-Received: by 2002:adf:a551:: with SMTP id j17mr35913491wrb.217.1604515316845; Wed, 04 Nov 2020 10:41:56 -0800 (PST) Date: Wed, 4 Nov 2020 13:41:54 -0500 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Subject: [PULL v3 13/31] virtio-iommu: Fix virtio_iommu_mr() Message-ID: <20201104184040.285057-14-mst@redhat.com> References: <20201104184040.285057-1-mst@redhat.com> MIME-Version: 1.0 In-Reply-To: <20201104184040.285057-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 (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/03 00:03:41 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, 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 , Peter Xu , QEMU Stable , Eric Auger , Jean-Philippe Brucker Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Jean-Philippe Brucker Due to an invalid mask, virtio_iommu_mr() may return the wrong memory region. It hasn't been too problematic so far because the function was only used to test existence of an endpoint, but that is about to change. Fixes: cfb42188b24d ("virtio-iommu: Implement attach/detach command") Cc: QEMU Stable Acked-by: Eric Auger Reviewed-by: Peter Xu Signed-off-by: Jean-Philippe Brucker Message-Id: <20201030180510.747225-2-jean-philippe@linaro.org> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- hw/virtio/virtio-iommu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hw/virtio/virtio-iommu.c b/hw/virtio/virtio-iommu.c index 21ec63b108..4c8f3909b7 100644 --- a/hw/virtio/virtio-iommu.c +++ b/hw/virtio/virtio-iommu.c @@ -101,7 +101,7 @@ static IOMMUMemoryRegion *virtio_iommu_mr(VirtIOIOMMU *= s, uint32_t sid) bus_n =3D PCI_BUS_NUM(sid); iommu_pci_bus =3D iommu_find_iommu_pcibus(s, bus_n); if (iommu_pci_bus) { - devfn =3D sid & PCI_DEVFN_MAX; + devfn =3D sid & (PCI_DEVFN_MAX - 1); dev =3D iommu_pci_bus->pbdev[devfn]; if (dev) { return &dev->iommu_mr; --=20 MST