From patchwork Wed Nov 4 18:41:54 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: 320561 Delivered-To: patch@linaro.org Received: by 2002:a92:7b12:0:0:0:0:0 with SMTP id w18csp5665830ilc; Wed, 4 Nov 2020 10:46:40 -0800 (PST) X-Google-Smtp-Source: ABdhPJy/PIIg3aTL8kdgKVOnjjZo2Aqdlv9vRuSiAv7D1Cweyuy14rd2izH/vdxd+LA21Ne7G5rC X-Received: by 2002:a25:4085:: with SMTP id n127mr37000001yba.342.1604515600635; Wed, 04 Nov 2020 10:46:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604515600; cv=none; d=google.com; s=arc-20160816; b=qTtD/a7UrGovgfe5Yrt6/xhW/4z63Mt4O7vQYaXHz6rFUCZa8CgR2y0exJ02S/M2fw 8FrtNwxLdkJHVkmVM19Jnf70hrWhy69jdYk2CGUNssquzFFNAvZb8/xN8dyPHmG/3aCo cbNt5hkml5vNp3GivVW/5CBmnrMo2Lhk7fZeR1jYlTPto2N+GrQNHP5aAzgZdUoj068F m0+R7L9WQOlrsF32K77mhV92M78VKnkPb86F/vTYZOqg0FhiCoXSqTucc35N4A+OSSIt 6CtT+wJE+1mOI5/gFMwRL8B62Dq6zvGUQIR/ehSBd7lrtKzARdtk3La/iyZAJJCcShBS DCeQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-disposition:in-reply-to :mime-version:references:message-id:subject:to:from:date :dkim-signature; bh=yb0+hTu/cI4h7Se3wHsf9S5j6pZCfXhlBpQERrIdWig=; b=Ajfv+4vIJOfk98urhIAoRu/12dnpoTSCl5dKCVEhFPh2rcuuMPmNpcDg8KS9Vq7y0V tvxoThvXrXQJlr78kqniBg44mqA//hTuQxewZoEedbIO2TORUcmI7H1BvHKvf6G4pSmV F712yIWtuuLWlLnHQJ/UgnlCHWp0ORt59Uu8pvTXcE0oHVOgKcMNw6BmIUlZLJcp+Sc/ IZRBgby8rmPgJt/91OZ8LVqikpweD/7APMqnKNDJDkF3WmzN42tsLO1vXJ27ecirq43p pmbpg0Wk666qdW0pV5CGUCfNYyFDcvqOMKlsaHTkB2ihbe2hC7HyAvoSsP/H7vlRB2B3 TZEA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@redhat.com header.s=mimecast20190719 header.b=MRbU3cYV; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id u63si526735ybb.61.2020.11.04.10.46.40 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 04 Nov 2020 10:46:40 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@redhat.com header.s=mimecast20190719 header.b=MRbU3cYV; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from localhost ([::1]:60754 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kaNns-00076K-48 for patch@linaro.org; Wed, 04 Nov 2020 13:46:40 -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 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= 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 X-MC-Unique: IyBkSYblOSmNp14Ouqg0Pw-1 Received: by mail-wr1-f72.google.com with SMTP id h8so9633835wrt.9 for ; Wed, 04 Nov 2020 10:41:58 -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=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-Received: by 2002:adf:a551:: with SMTP id j17mr35913491wrb.217.1604515316845; Wed, 04 Nov 2020 10:41:56 -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) 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 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+patch=linaro.org@nongnu.org Sender: "Qemu-devel" 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(-) -- MST 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 = PCI_BUS_NUM(sid); iommu_pci_bus = iommu_find_iommu_pcibus(s, bus_n); if (iommu_pci_bus) { - devfn = sid & PCI_DEVFN_MAX; + devfn = sid & (PCI_DEVFN_MAX - 1); dev = iommu_pci_bus->pbdev[devfn]; if (dev) { return &dev->iommu_mr;