From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F14AE241CB7 for ; Fri, 21 Nov 2025 20:58:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763758710; cv=none; b=ebQFlawzG7y3Sb5TU/uQXOEw7sI/IXrYlaq4sUhxmyoBmvEpN4j//2E37nof3LDmp3pIdE70XRKg7462EQyo9xLoqxczZYzo2kPI3EQwOKbksp+OGSIABG2Vqhi4Kwfg05179V7YYqZ1oUnNuKmxm2icPozUHDvBhTBFxJD9OUM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763758710; c=relaxed/simple; bh=06oXEfhjprUqiQB5deP8QG66ZL/M1lhD7+55HTheX04=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=KhE/Tw11cYiH309eYfwDlvyxwLQ1ZYRqNYUg2DT3N8xkQEqJwPfYm/16oh6oAV4dIlCCOcg342Ygiyqw1NHE6qFg6dz/zypBcJqk7oYSTI/OO7Hgzyi+S+7QSfZpTdKM0yiaDcrvtEpm9Es4Layzf3cBoOO2DV8smi/nRMtU/F8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=DkTWV8JB; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=Tr/8dx4Z; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="DkTWV8JB"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="Tr/8dx4Z" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1763758707; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=e88HhueZj89DvDALxZLu6Aq2WQkVf8WGiqxl2400ceE=; b=DkTWV8JBnunVkryKFBISTdTGJ/HE9oLW0d1vN7owmns+oI3sv/SpVc9AmmqrP3f+eZ8MxF ZNy2aBr1bi1PJI9xOMfkNjL34D8MQ7A3yMLu8g4+nGdebAM4JpfQ6a2yMjr35bhLwKbW9G ejzqycTqiPw1kFYYr3EI6DnSERcTH2k= Received: from mail-qk1-f197.google.com (mail-qk1-f197.google.com [209.85.222.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-221-TOYD4d7JMDW6x2WNQ2v7cw-1; Fri, 21 Nov 2025 15:58:25 -0500 X-MC-Unique: TOYD4d7JMDW6x2WNQ2v7cw-1 X-Mimecast-MFC-AGG-ID: TOYD4d7JMDW6x2WNQ2v7cw_1763758705 Received: by mail-qk1-f197.google.com with SMTP id af79cd13be357-8b1d8f56e24so712886185a.2 for ; Fri, 21 Nov 2025 12:58:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1763758705; x=1764363505; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=e88HhueZj89DvDALxZLu6Aq2WQkVf8WGiqxl2400ceE=; b=Tr/8dx4ZEx4i7rTR7eOLeBbWhE4h3do7z0Fy4zAkg2xuO4tyNPBSo7GB1gjiOzDsPD u64oahVPBwvbLDh3qtjVKKK5LUr/+P99nXuaodGhfdIJe/8PrQJ32+HVOPJgX6tTCWSs sBYMZ7pbvFMUcRwe7PwoHlkrd8dCQUDfvUK5gOZdFEgXGvko0WyHaHsc0gTdLobjf5rc AOUGYFeIFq2ogvdC+nw+g5QkMf3JTzeJmYN4ArwBplX1c1jauOYVeURy9ekiBZvl5SBp n+CY/vZSTWX5WqCCmsbCQxBadSUGBGNq3+4/+w7HPDSQzaQ2QZZ9PTRoH5BDkgKXDUDA rZYA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1763758705; x=1764363505; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=e88HhueZj89DvDALxZLu6Aq2WQkVf8WGiqxl2400ceE=; b=Vl/rDWP3qhN3JDGV1umek2xf3r7pyuplYMjElQsQgUxIJS20coMZ1Ynao0cw21wDpP eggJn9vqeCmqWpT9AHB3VGx1Nke+nsoRoyMef5H9pM83f4r1Cs0j3VXOnDArTSkDd6V8 46KMJ+xGsB+cKd5ZxMYS/MHuFvwZLQszZI+24w+Lif355oMDMsZQcJ2lm1eIH1llWv7i kadW5/8ZEJI3jbNGRpD9ZxTvg1DAvUIzQ/kOQ4fw0/zth4FsH9ISKV7HRsAmQxBC0APB IrJcWW/03FiNIsTrnt2W37QGeUm6b3C4SZDOuQW4f3Vw2b3KQ0EK+BAZ4EYx9sVC3N1n hSew== X-Forwarded-Encrypted: i=1; AJvYcCVbG8THTQS3n/C77vQ2b9MY1mcHR9KCIYteyXdc1GVtoWggjM1A6Y6E1o7/smDgdl3bVjNptMA9GFl2oUo=@vger.kernel.org X-Gm-Message-State: AOJu0Yyvu0F2xcTX+xbe4QjFl8az871Q5frreGwNS545uwDvfhr8dNP3 TMuTOwe1QuzBayMMTwu0FEUKMrIqk4pzrL/u7JMzhp6QJVBXTCQqOrrD69dYOyVEPps4A7oAY7Q xJeOcxNeJerKCMnPkU8xpDHuifN2AIImbbutsWjHilhM+yalq1uhrwFboEzddNElsHw== X-Gm-Gg: ASbGncuJEaHe5vDO2NDaIzQ+so8snPD43pS1QMFifi1UZm+52XDa8UUZP3MykPYu0qU OVeneAkveqNmrhOV18RQHTX+gJFyKH9eIzVWMGHCV85SXIDnwkvBg4EzJW3liTTCxBtFIAlJ1vi laKLy8tG42d0/0M5u4ief7hJI0q74982pBx1GMVPFCdbEDRMWwwRd3Xc+8x6RqC0S3FyLxxaiSF EE2+qnmMA6mxrD3wLYq9lpOv+MLLxwIoxYwFo17n3S9iSe2c99w+PvU+DzXp2wIqxFSGMxaHJcX jCpYusePyiaVk3YJfrmEfHZ3HOtTskjQwYNoxGh32VAzE5/7NWezz/cBXWTUSt1k+jvyfTWLcC+ JtXaxFXGImw== X-Received: by 2002:a05:620a:414b:b0:8a3:9bb4:9e4f with SMTP id af79cd13be357-8b33d1fe5e1mr463784185a.30.1763758704698; Fri, 21 Nov 2025 12:58:24 -0800 (PST) X-Google-Smtp-Source: AGHT+IGhfkyzY52YJ2bXpl0xvrpFvW8lduyG4EKof39hTidPOL/dpJFOpP6aOif1GUzrwgXScGO24A== X-Received: by 2002:a05:620a:414b:b0:8a3:9bb4:9e4f with SMTP id af79cd13be357-8b33d1fe5e1mr463780785a.30.1763758704275; Fri, 21 Nov 2025 12:58:24 -0800 (PST) Received: from [192.168.40.164] ([70.105.235.240]) by smtp.gmail.com with ESMTPSA id af79cd13be357-8b3295e4b96sm437647485a.45.2025.11.21.12.58.21 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 21 Nov 2025 12:58:23 -0800 (PST) Message-ID: <9b25494c-0271-4469-a7f4-71876eadd4e3@redhat.com> Date: Fri, 21 Nov 2025 15:58:19 -0500 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v3 5/7] vfio: move barmap to a separate function and export To: Alex Williamson , ankita@nvidia.com Cc: jgg@ziepe.ca, yishaih@nvidia.com, skolothumtho@nvidia.com, kevin.tian@intel.com, aniketa@nvidia.com, vsethi@nvidia.com, mochs@nvidia.com, Yunxiang.Li@amd.com, yi.l.liu@intel.com, zhangdongdong@eswincomputing.com, avihaih@nvidia.com, bhelgaas@google.com, peterx@redhat.com, pstanner@redhat.com, apopple@nvidia.com, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, cjia@nvidia.com, kwankhede@nvidia.com, targupta@nvidia.com, zhiw@nvidia.com, danw@nvidia.com, dnigam@nvidia.com, kjaju@nvidia.com References: <20251121141141.3175-1-ankita@nvidia.com> <20251121141141.3175-6-ankita@nvidia.com> <20251121093949.54f647a6.alex@shazbot.org> Content-Language: en-US From: Donald Dutile In-Reply-To: <20251121093949.54f647a6.alex@shazbot.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 11/21/25 11:39 AM, Alex Williamson wrote: > On Fri, 21 Nov 2025 14:11:39 +0000 > wrote: > >> From: Ankit Agrawal >> >> Move the code to map the BAR to a separate function. >> >> This would be reused by the nvgrace-gpu module. >> >> Signed-off-by: Ankit Agrawal >> --- >> drivers/vfio/pci/vfio_pci_core.c | 38 ++++++++++++++++++++++---------- >> include/linux/vfio_pci_core.h | 1 + >> 2 files changed, 27 insertions(+), 12 deletions(-) >> >> diff --git a/drivers/vfio/pci/vfio_pci_core.c b/drivers/vfio/pci/vfio_pci_core.c >> index 29dcf78905a6..d1ff1c0aa727 100644 >> --- a/drivers/vfio/pci/vfio_pci_core.c >> +++ b/drivers/vfio/pci/vfio_pci_core.c >> @@ -1717,6 +1717,29 @@ static const struct vm_operations_struct vfio_pci_mmap_ops = { >> #endif >> }; >> >> +int vfio_pci_core_barmap(struct vfio_pci_core_device *vdev, unsigned int index) >> +{ >> + struct pci_dev *pdev = vdev->pdev; >> + int ret; >> + >> + if (vdev->barmap[index]) >> + return 0; >> + >> + ret = pci_request_selected_regions(pdev, >> + 1 << index, "vfio-pci"); >> + if (ret) >> + return ret; >> + >> + vdev->barmap[index] = pci_iomap(pdev, index, 0); >> + if (!vdev->barmap[index]) { >> + pci_release_selected_regions(pdev, 1 << index); >> + return -ENOMEM; >> + } >> + >> + return 0; >> +} >> +EXPORT_SYMBOL_GPL(vfio_pci_core_barmap); > > Looks a lot like vfio_pci_core_setup_barmap() ;) > > Thanks, > Alex > +1 ... and below ... > >> + >> int vfio_pci_core_mmap(struct vfio_device *core_vdev, struct vm_area_struct *vma) >> { >> struct vfio_pci_core_device *vdev = >> @@ -1761,18 +1784,9 @@ int vfio_pci_core_mmap(struct vfio_device *core_vdev, struct vm_area_struct *vma >> * Even though we don't make use of the barmap for the mmap, >> * we need to request the region and the barmap tracks that. >> */ >> - if (!vdev->barmap[index]) { >> - ret = pci_request_selected_regions(pdev, >> - 1 << index, "vfio-pci"); >> - if (ret) >> - return ret; >> - >> - vdev->barmap[index] = pci_iomap(pdev, index, 0); >> - if (!vdev->barmap[index]) { >> - pci_release_selected_regions(pdev, 1 << index); >> - return -ENOMEM; >> - } >> - } >> + ret = vfio_pci_core_barmap(vdev, index); >> + if (ret) >> + return ret; >> so, vfio_pci_core_mmap() should be calling vfio_pci_core_setup_barmap() vs. what it does above currently? --Don >> vma->vm_private_data = vdev; >> vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot); >> diff --git a/include/linux/vfio_pci_core.h b/include/linux/vfio_pci_core.h >> index a097a66485b4..75f04d613e0c 100644 >> --- a/include/linux/vfio_pci_core.h >> +++ b/include/linux/vfio_pci_core.h >> @@ -121,6 +121,7 @@ ssize_t vfio_pci_core_write(struct vfio_device *core_vdev, const char __user *bu >> size_t count, loff_t *ppos); >> vm_fault_t vfio_pci_map_pfn(struct vm_fault *vmf, unsigned long pfn, >> unsigned int order); >> +int vfio_pci_core_barmap(struct vfio_pci_core_device *vdev, unsigned int index); >> int vfio_pci_core_mmap(struct vfio_device *core_vdev, struct vm_area_struct *vma); >> void vfio_pci_core_request(struct vfio_device *core_vdev, unsigned int count); >> int vfio_pci_core_match(struct vfio_device *core_vdev, char *buf); > >