Received: by 2002:a05:6a10:a852:0:0:0:0 with SMTP id d18csp2893232pxy; Mon, 3 May 2021 10:19:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwPhtfjx2X65SnKb6Q2KxKIOYHmBuQlBFHKe5a6i2Hrxd8MIgabCsvL8P133zPQzNn+7n75 X-Received: by 2002:a63:5c19:: with SMTP id q25mr19778643pgb.402.1620062353923; Mon, 03 May 2021 10:19:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620062353; cv=none; d=google.com; s=arc-20160816; b=tfoW4dGs8/mS25T4knjYeExLmIW1a7aVakXmSJGbuDlQZy+9m60mNO7Uu6Wl5cNRGT Vg/dJ0jlYVPYNMaurlAVW1XQB25/Sxwo6cWzI07Zn3HH3RtS/qGTuQpOKVO+KcOWLtKx yZ5eoGUtQr1nihmdzyz0GqV+u5fh0UFlpstt9xxP3LaOC8fqbXq7OPwKB2xZqcP0ePl5 2WO7ccY87eY/hoxaF+ReJG3AkpkxIrKcwGwP4NFx49cjv6tbudG4lvf6QZS6n/HgoN4g zpRXUG71A6gkRhv5/5nIgjDvWDWWqZ8uTRsdD2hORA/8f7vcZ0BJdDLNxHJxpkXLe45M FuIA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:subject:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:dkim-signature; bh=SAQ4S+jSIpU03o924OYwfD9SEbxJ72ZyqTFfTksfdhA=; b=FsuOfSPs7ySwMSACkB8bVE5tgKjebyMlUZQpcpIoGrGEm2JeVqdrv99fG5xLSnZf/d Y5hyNyXt8TaioRxrbh8q3y/PdCiEUGgJdgUV9VCzAsBSGDs/3CrpxAB5ZWnC1rRt7d3/ RBFHp0lTn/7FMAo2tkCGhi3jTs06YwqFhtqUcTzsuZp1pdqvOluAKOq7H2Z52hcpieSY SpPTS6n1vsgH0gwfH7JrUdsiPUniYHxzn/gGF0dNfCy8UIPJamSxIKHb052DO8Fdq6j3 4pZBSSlvwqxjt0yh3ryEDlMjOi3VTWxl/FxKdIY0Nm90I44Zj+X5f2Z3QUl0sctKO/oH pgWA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@deltatee.com header.s=20200525 header.b=aHvkXNhJ; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m4si318049pga.257.2021.05.03.10.18.59; Mon, 03 May 2021 10:19:13 -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=@deltatee.com header.s=20200525 header.b=aHvkXNhJ; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231443AbhECRTB (ORCPT + 99 others); Mon, 3 May 2021 13:19:01 -0400 Received: from ale.deltatee.com ([204.191.154.188]:58914 "EHLO ale.deltatee.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231388AbhECRS7 (ORCPT ); Mon, 3 May 2021 13:18:59 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=deltatee.com; s=20200525; h=Subject:In-Reply-To:MIME-Version:Date: Message-ID:From:References:Cc:To:content-disposition; bh=SAQ4S+jSIpU03o924OYwfD9SEbxJ72ZyqTFfTksfdhA=; b=aHvkXNhJC0Th2xBJKUmBj+YFHL UzUUk1ISTbtYsp83553YSXXGRA++kbSiJtSN05jEXVqt9VEX+wniOJS1RplCEqtuDD5dEX6odZ4Kq cu222eZYaQudBjSH8A2rSJDXWW+51r3qeRWafwKoGAm6AVx0/RQ21Pp4Domc5hgQYrYZGJC3acctI oDyhQ6cbTWTz+4TBfHuPIS5Ncok4vJKWmc5qIIjxy5BONLC07sANEe9vDy3pqahAl0m4DRp8PkoaL 1+iVIZ7RcwI7jzxYjW8Dkp9JZw0qq1u+WTSwK8ErzNEhrqQw5/H+bDo+O6nCitRx5LdA8d9D7PVCk nOiYSZ1A==; Received: from guinness.priv.deltatee.com ([172.16.1.162]) by ale.deltatee.com with esmtp (Exim 4.92) (envelope-from ) id 1ldcCd-0005A2-F7; Mon, 03 May 2021 11:17:52 -0600 To: John Hubbard , linux-kernel@vger.kernel.org, linux-nvme@lists.infradead.org, linux-block@vger.kernel.org, linux-pci@vger.kernel.org, linux-mm@kvack.org, iommu@lists.linux-foundation.org Cc: Stephen Bates , Christoph Hellwig , Dan Williams , Jason Gunthorpe , =?UTF-8?Q?Christian_K=c3=b6nig?= , Don Dutile , Matthew Wilcox , Daniel Vetter , Jakowski Andrzej , Minturn Dave B , Jason Ekstrand , Dave Hansen , Xiong Jianxin , Bjorn Helgaas , Ira Weiny , Robin Murphy References: <20210408170123.8788-1-logang@deltatee.com> <20210408170123.8788-13-logang@deltatee.com> From: Logan Gunthorpe Message-ID: Date: Mon, 3 May 2021 11:17:50 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.9.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-CA Content-Transfer-Encoding: 7bit X-SA-Exim-Connect-IP: 172.16.1.162 X-SA-Exim-Rcpt-To: robin.murphy@arm.com, ira.weiny@intel.com, helgaas@kernel.org, jianxin.xiong@intel.com, dave.hansen@linux.intel.com, jason@jlekstrand.net, dave.b.minturn@intel.com, andrzej.jakowski@intel.com, daniel.vetter@ffwll.ch, willy@infradead.org, ddutile@redhat.com, christian.koenig@amd.com, jgg@ziepe.ca, dan.j.williams@intel.com, hch@lst.de, sbates@raithlin.com, iommu@lists.linux-foundation.org, linux-mm@kvack.org, linux-pci@vger.kernel.org, linux-block@vger.kernel.org, linux-nvme@lists.infradead.org, linux-kernel@vger.kernel.org, jhubbard@nvidia.com X-SA-Exim-Mail-From: logang@deltatee.com X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on ale.deltatee.com X-Spam-Level: X-Spam-Status: No, score=-8.9 required=5.0 tests=ALL_TRUSTED,BAYES_00, GREYLIST_ISWHITE,NICE_REPLY_A autolearn=ham autolearn_force=no version=3.4.2 Subject: Re: [PATCH 12/16] nvme-pci: Check DMA ops when indicating support for PCI P2PDMA X-SA-Exim-Version: 4.2.1 (built Wed, 08 May 2019 21:11:16 +0000) X-SA-Exim-Scanned: Yes (on ale.deltatee.com) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2021-05-02 7:29 p.m., John Hubbard wrote: > On 4/8/21 10:01 AM, Logan Gunthorpe wrote: >> Introduce a supports_pci_p2pdma() operation in nvme_ctrl_ops to >> replace the fixed NVME_F_PCI_P2PDMA flag such that the dma_map_ops >> flags can be checked for PCI P2PDMA support. >> >> Signed-off-by: Logan Gunthorpe >> --- >> drivers/nvme/host/core.c | 3 ++- >> drivers/nvme/host/nvme.h | 2 +- >> drivers/nvme/host/pci.c | 11 +++++++++-- >> 3 files changed, 12 insertions(+), 4 deletions(-) >> >> diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c >> index 0896e21642be..223419454516 100644 >> --- a/drivers/nvme/host/core.c >> +++ b/drivers/nvme/host/core.c >> @@ -3907,7 +3907,8 @@ static void nvme_alloc_ns(struct nvme_ctrl *ctrl, unsigned nsid, >> blk_queue_flag_set(QUEUE_FLAG_STABLE_WRITES, ns->queue); >> >> blk_queue_flag_set(QUEUE_FLAG_NONROT, ns->queue); >> - if (ctrl->ops->flags & NVME_F_PCI_P2PDMA) >> + if (ctrl->ops->supports_pci_p2pdma && >> + ctrl->ops->supports_pci_p2pdma(ctrl)) > > This is a little excessive, as I suspected. How about providing a > default .supports_pci_p2pdma routine that returns false, so that > the op is always available (non-null)? By "default", maybe that > means either requiring an init_the_ops_struct() routine to be > used, and/or checking all the users of struct nvme_ctrl_ops. Honestly that sounds much more messy to me than simply checking if it's NULL before using it (which is a common, accepted pattern for ops). > Another idea: maybe you don't really need a bool .supports_pci_p2pdma() > routine at all, because the existing .flags really is about right. > You just need the flags to be filled in dynamically. So, do that > during nvme_pci setup/init time: that's when this module would call > dma_pci_p2pdma_supported(). If the flag is filled in dynamically, then the ops struct would have to be non-constant. Ops structs should be constant for security reasons. Logan