Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp5112501imu; Tue, 29 Jan 2019 13:02:26 -0800 (PST) X-Google-Smtp-Source: ALg8bN41WYQGqa2/GrJNV/b0pndOfwT0gVOoyq9GUWitrzVOkxFPQho0NuQA/ZbkSc57e+VyLkb/ X-Received: by 2002:a63:374e:: with SMTP id g14mr25682765pgn.59.1548795746013; Tue, 29 Jan 2019 13:02:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548795745; cv=none; d=google.com; s=arc-20160816; b=bgIb8I+m51bjVegjPHf2zVJaZKNqRcTPSaO1DTWDD4FY/8hCuz0dBhUi1ZXqsBr28M jGqPC/Urcwv+onH9X+icbGest5DlKT57CeAzouIYnUS6c6Xxa9nZW5XCkne4b2JfjYZs XE/WBL0QM7OqQIuHYrjeJG+wEx6NxcAKDx4ib7CZPNdX/rFQI1FrEynpVDg5qGU3iGx0 D1XfvaSmKGbSTCJIqsIGBbh6JzGiuVWgStCHG0b98PEeBu74MdXqiM9W0ykO8KB3jCLU 9q8wk5GhpuHRv2PJn81va4cQ/DTwG3ZQefeKgLIaabOtmuvjiwOpy/4YA6wn/nL1cuoX tp+g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-transfer-encoding:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=/1gIi7T1dRTUHKPk97ncy1O0U6azH8+Kof8HoJbyGiI=; b=XBWaBtKs7YgmztrG+K0tIHQzF3c61k1bwYgg0e8GteqbB96x7ELggMtUKioiVENtrT lyhwiT53CRngHrGLia8KFhPaDRjm9phAStRmhuA/KjTFYHLhq3esnlP6k4DSE6gBsanj YMU0X3xPEHKYkaNelSWN3MkNfnybgZjRPeJ12SUdG5wNaRbAozUxee4kWFSn3fAQyfYV cGr86Ldbz/gmzyqn7bwfArDoe+MdtRtmuef0+nWbuAvjRwAmoEGxo6i4TkTZCZCpJFLX m1ZDcp5B2zEhgO556nQg0yqpH2KFDbgtp5lgYBbF5huQUI0nsP9RdTx6fI0KOQvyLKJp Z0Fw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n5si7343577pgh.422.2019.01.29.13.02.10; Tue, 29 Jan 2019 13:02:25 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729578AbfA2VAO (ORCPT + 99 others); Tue, 29 Jan 2019 16:00:14 -0500 Received: from mx1.redhat.com ([209.132.183.28]:38812 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727570AbfA2VAN (ORCPT ); Tue, 29 Jan 2019 16:00:13 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6751D58E22; Tue, 29 Jan 2019 21:00:13 +0000 (UTC) Received: from redhat.com (ovpn-122-2.rdu2.redhat.com [10.10.122.2]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3147460C6E; Tue, 29 Jan 2019 21:00:10 +0000 (UTC) Date: Tue, 29 Jan 2019 16:00:08 -0500 From: Jerome Glisse To: Logan Gunthorpe Cc: Greg Kroah-Hartman , linux-mm@kvack.org, linux-kernel@vger.kernel.org, "Rafael J . Wysocki" , Bjorn Helgaas , Christian Koenig , Felix Kuehling , Jason Gunthorpe , linux-pci@vger.kernel.org, dri-devel@lists.freedesktop.org, Christoph Hellwig , Marek Szyprowski , Robin Murphy , Joerg Roedel , iommu@lists.linux-foundation.org Subject: Re: [RFC PATCH 1/5] pci/p2p: add a function to test peer to peer capability Message-ID: <20190129210007.GO3176@redhat.com> References: <20190129174728.6430-1-jglisse@redhat.com> <20190129174728.6430-2-jglisse@redhat.com> <20190129194426.GB32069@kroah.com> <8b4e0157-4eaf-c79a-28d0-7a266abe2207@deltatee.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <8b4e0157-4eaf-c79a-28d0-7a266abe2207@deltatee.com> User-Agent: Mutt/1.10.1 (2018-07-13) X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Tue, 29 Jan 2019 21:00:13 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jan 29, 2019 at 01:44:09PM -0700, Logan Gunthorpe wrote: > > > On 2019-01-29 12:44 p.m., Greg Kroah-Hartman wrote: > > On Tue, Jan 29, 2019 at 11:24:09AM -0700, Logan Gunthorpe wrote: > >> > >> > >> On 2019-01-29 10:47 a.m., jglisse@redhat.com wrote: > >>> +bool pci_test_p2p(struct device *devA, struct device *devB) > >>> +{ > >>> + struct pci_dev *pciA, *pciB; > >>> + bool ret; > >>> + int tmp; > >>> + > >>> + /* > >>> + * For now we only support PCIE peer to peer but other inter-connect > >>> + * can be added. > >>> + */ > >>> + pciA = find_parent_pci_dev(devA); > >>> + pciB = find_parent_pci_dev(devB); > >>> + if (pciA == NULL || pciB == NULL) { > >>> + ret = false; > >>> + goto out; > >>> + } > >>> + > >>> + tmp = upstream_bridge_distance(pciA, pciB, NULL); > >>> + ret = tmp < 0 ? false : true; > >>> + > >>> +out: > >>> + pci_dev_put(pciB); > >>> + pci_dev_put(pciA); > >>> + return false; > >>> +} > >>> +EXPORT_SYMBOL_GPL(pci_test_p2p); > >> > >> This function only ever returns false.... > > > > I guess it was nevr actually tested :( > > > > I feel really worried about passing random 'struct device' pointers into > > the PCI layer. Are we _sure_ it can handle this properly? > > Yes, there are a couple of pci_p2pdma functions that take struct devices > directly simply because it's way more convenient for the caller. That's > what find_parent_pci_dev() takes care of (it returns false if the device > is not a PCI device). Whether that's appropriate here is hard to say > seeing we haven't seen any caller code. Caller code as a reference (i already given that link in other part of thread but just so that people don't have to follow all branches). https://cgit.freedesktop.org/~glisse/linux/commit/?h=hmm-p2p&id=401a567696eafb1d4faf7054ab0d7c3a16a5ef06 Cheers, J?r?me