Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp4381030pxa; Mon, 10 Aug 2020 07:52:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwC2ggLUtZcM8PoxK2ln0RpEOi6pI3jdS370fRrul01K1MhDAMRgAj1TF5GMZSFUjl5sdCB X-Received: by 2002:a17:906:95d4:: with SMTP id n20mr23374187ejy.485.1597071127447; Mon, 10 Aug 2020 07:52:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597071127; cv=none; d=google.com; s=arc-20160816; b=rkQuZH3HpCYZkFT52lrnDobBk4hyTqrk/7Xvo1qKTwZTEv3PPzqisUQjVOp/gtor9j QTxV7gemNfoV8JSOUqBCig6CXTIDNbV5ACZv6QvrPA6AtIdCYEc+gtKiLm09fZDuSDGp Kp63BsQDEfr5Zc0mN0QXNC3Z+XwNUFwZZRhr9rFARaDvOuyitM0LTq0SfeHbva+x5gaI AIFmnJdO5Uke3Vadv1h4f1ChmHDIiZZWM8bU4B4MFX7ciGQlzbLMMQLxQboqHM+/1G+D BrgPIDD4CrOJPsAifpR2u+HyshR69bG//xnJ5fnUecsHLtdJ+aOXYXroTZJKENfgdTkO 9TVg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=CmPgr4Q4WAZKNKGFTE7tvM8ImvK/kVdmqG/HrVAHjUk=; b=QBYcNfFETzPVSaQYCOK0q6QV2eFnaqJGNkOjgF4wtHLJUy7MRogHibgfLIg/oYDpV/ ys3kSb+0HFCavEnUCDlcFp2yZ33VtSMTD5Q10speEr1f3ilmMisDcq/6jpO1Vu7xoL78 E7SPA5u8WoDsWTyVCwCuZ+OcoxS3Tt+RxBkIDPyfQFwAC/6YvTyCq4hrebDFfgEXP3j2 gmGpbnJSoAk2TWg5upmUH3LfS/G0ZfSa5KoCogT48b8QXXoL0z97l+gsi5wJAeZnuiFK Fgn+ZKjQxDUROYY22ifDV3sMhN4nsBOfts5XVzFR2HEfcRsL1C7wIVIUViAYk7RUPQGO pgHg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=hi3Hw404; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g22si10866299ejw.97.2020.08.10.07.51.44; Mon, 10 Aug 2020 07:52:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=hi3Hw404; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727109AbgHJOuh (ORCPT + 99 others); Mon, 10 Aug 2020 10:50:37 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:47430 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726946AbgHJOuf (ORCPT ); Mon, 10 Aug 2020 10:50:35 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1597071034; 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=CmPgr4Q4WAZKNKGFTE7tvM8ImvK/kVdmqG/HrVAHjUk=; b=hi3Hw404FaxaD9QaKNWFb+v3JeiVoRk+t5CCVh6LbHNCIgOtLP3TZk512rVz4n1TTABr3+ fOFNKYY1s13KMy2qKhtjcu8INH1umM/1AsIODCfe0FwG5Wqu/0vM7Spxv4S6p2fwj6RdTT 61UDNFVOeHfW4PlK59+MYetIA0MVsdg= 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-496-nDAT6UYOOhuk0ykGpsGy3g-1; Mon, 10 Aug 2020 10:50:30 -0400 X-MC-Unique: nDAT6UYOOhuk0ykGpsGy3g-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 5C9AE80BCA6; Mon, 10 Aug 2020 14:50:29 +0000 (UTC) Received: from horse.redhat.com (unknown [10.10.115.251]) by smtp.corp.redhat.com (Postfix) with ESMTP id B1B7310016E8; Mon, 10 Aug 2020 14:50:19 +0000 (UTC) Received: by horse.redhat.com (Postfix, from userid 10451) id 41C7722036A; Mon, 10 Aug 2020 10:50:19 -0400 (EDT) Date: Mon, 10 Aug 2020 10:50:19 -0400 From: Vivek Goyal To: "Michael S. Tsirkin" Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, virtio-fs@redhat.com, miklos@szeredi.hu, stefanha@redhat.com, dgilbert@redhat.com, Sebastien Boeuf , kbuild test robot , kvm@vger.kernel.org Subject: Re: [PATCH v2 04/20] virtio: Implement get_shm_region for PCI transport Message-ID: <20200810145019.GB455528@redhat.com> References: <20200807195526.426056-1-vgoyal@redhat.com> <20200807195526.426056-5-vgoyal@redhat.com> <20200810100327-mutt-send-email-mst@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200810100327-mutt-send-email-mst@kernel.org> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Aug 10, 2020 at 10:05:17AM -0400, Michael S. Tsirkin wrote: > On Fri, Aug 07, 2020 at 03:55:10PM -0400, Vivek Goyal wrote: > > From: Sebastien Boeuf > > > > On PCI the shm regions are found using capability entries; > > find a region by searching for the capability. > > > > Signed-off-by: Sebastien Boeuf > > Signed-off-by: Dr. David Alan Gilbert > > Signed-off-by: kbuild test robot > > Cc: kvm@vger.kernel.org > > Cc: "Michael S. Tsirkin" > > Acked-by: Michael S. Tsirkin > [..] > > +static bool vp_get_shm_region(struct virtio_device *vdev, > > + struct virtio_shm_region *region, u8 id) > > +{ > > + struct virtio_pci_device *vp_dev = to_vp_device(vdev); > > + struct pci_dev *pci_dev = vp_dev->pci_dev; > > + u8 bar; > > + u64 offset, len; > > + phys_addr_t phys_addr; > > + size_t bar_len; > > + > > + if (!virtio_pci_find_shm_cap(pci_dev, id, &bar, &offset, &len)) { > > + return false; > > + } > > + > > + phys_addr = pci_resource_start(pci_dev, bar); > > + bar_len = pci_resource_len(pci_dev, bar); > > + > > + if ((offset + len) < offset) { > > + dev_err(&pci_dev->dev, "%s: cap offset+len overflow detected\n", > > + __func__); > > + return false; > > + } > > + > > + if (offset + len > bar_len) { > > + dev_err(&pci_dev->dev, "%s: bar shorter than cap offset+len\n", > > + __func__); > > + return false; > > + } > > Maybe move this to a common header so the checks can be reused by > other transports? Can be a patch on top. Will do as patch on top once these patches get merged. Thanks Vivek