From nobody Mon Feb 9 05:59:54 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.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 CF8B52DBF78 for ; Thu, 4 Dec 2025 15:10:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764861017; cv=none; b=GM3I0pLts/+5i2NDpGw1O39HTW0gcSgT8a5lfmn/bqrAoN633DWsqrCzgWvGnOuMt6TscG+AsF+GmJtsGkWyZCIkEXD3AdWmrdIMselDEDRFEWihKknCQKrBOCvhazx0FO0Zo/UfsssbuX/3SGhd/EBs8/y0EzsBGCCXHhhK44c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764861017; c=relaxed/simple; bh=lJveRauWUx7y5IzCU8bQ8COo3Mcg7RepbtONX9mf16o=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=sQU7oiiCRBSVapjpgLCKqsNJRIxN5NNxAzy25Sqy9c7EtVBHCTppFa9Qk1Z+IKDAR7V93R2eRaojdbuX4AVtTmfdEb5zmkKdBF4zXmxSVrYB6E+TgqqGsf/4F88qS4jiMoxTPDYStqAtPlPSMQCAOkTydGVyFslJnKgkg1Fx5oc= 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=BoTx9/7o; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=jxdvfIo7; arc=none smtp.client-ip=170.10.133.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="BoTx9/7o"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="jxdvfIo7" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1764861014; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=i3kfS3mg3HiGefUEuetCpDNaxRxqIsOmdjOWI6Qvpxo=; b=BoTx9/7oaFjSrdq+g6+PCK5eALbTZmjV/OEd1iOMR+QYYaeOz+sdj4CBV6mxpQpuacGNOT 1PogDpP66fEM/Ur7p2oLYTqUb9jU8/Kn2pz8jzpHCH+c1AfC1VzYFPI/U36JjBcRyPeyQz vkeYGYkcUtOLOBvQwGR4LXM7ekL+YqU= Received: from mail-qk1-f199.google.com (mail-qk1-f199.google.com [209.85.222.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-628-O4SyUZ71M4uB9KgooQljDA-1; Thu, 04 Dec 2025 10:10:13 -0500 X-MC-Unique: O4SyUZ71M4uB9KgooQljDA-1 X-Mimecast-MFC-AGG-ID: O4SyUZ71M4uB9KgooQljDA_1764861013 Received: by mail-qk1-f199.google.com with SMTP id af79cd13be357-8b245c49d0cso220313285a.3 for ; Thu, 04 Dec 2025 07:10:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1764861013; x=1765465813; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=i3kfS3mg3HiGefUEuetCpDNaxRxqIsOmdjOWI6Qvpxo=; b=jxdvfIo7LhB54e4GmojuV+AGhWHdrNXhp6kTm2cpx++qND90Vf2sOhly5tgQxla10P qtdOV5S0bTpoavddaiD3SObJj4orWmDuAlCGP6jCtGbgWLmLT5WJ8cJ1MJDSuon/rYjo GHQq88bfTCaeDEj4yRKQTbUq9ZbLRXRpK396dIhmvL9QObX5eDoZaC3FdH1xDRFlQ75W ggzJWhlcFuFz5+O6lnSQBgnMn6lG+QO3Y8BGnVInup8X2TvKK6T9r+q/yWQgm5zNfoID JfHwP0z7owYnuJfue5MsrRZl0GQF/DqU04UohKhV9X4tTHwucBwWVBP3iIFHAyX/Nqu6 1bkQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1764861013; x=1765465813; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=i3kfS3mg3HiGefUEuetCpDNaxRxqIsOmdjOWI6Qvpxo=; b=sVv3vc++89kDGFFVuuhoKYaF+kGMBbsndQun/A1bqaON8m5LcAtKmn1rTvpsfjloSS dtKBttqYK+CmXeVlbMepw/yjyGxYOBHJHDtYFDdqCveFcM5yUdojZCXzLQuYvBnV/pqz bsszl+mBn12aogiq2/hyo9q3W2pQZLhhCmNI/ke8L6nO5j9UOjwQa5FVdlK1gP5gTfGc N94GGvsPONPSm4IVlTt4g7eilp9VbUhSg9FlK2nhrko/ar8tDIMghY8eDf1aWXFNMZwc i2FFn9GLI5paxIBSpUGBFoji2dctURzy01kbb8lAvr/IJvPqVrQ8MpbaM/9BKVvoP99R Sfpw== X-Forwarded-Encrypted: i=1; AJvYcCUzYpJE58R10GjOsynvnesLKqx3F0IQUAkBjU8R3gEaKD4MtnUJr66xyWUXqrz0H+ney03v2hpJBy7UCYw=@vger.kernel.org X-Gm-Message-State: AOJu0YxmgPYNUmdo1+krSJPSMEXpZ9yFrnggE4GrWeDmOFrPzTos/pty cpVrn52wXPHHLJ7vae4BKHJWtaWjyNmxEu8cGpUWP5iVJEH19NDXNUDalCQFCcif6pqaqU5he9r HYFdlPgPczqAZmTjIQbKvQqbW/zhMllyceZQ0IxKS4FygfG/TfNrPStO3A0qdWAxlnQ== X-Gm-Gg: ASbGnctvdoRq4S9ulL95NA3uAfekKY3ivbyXhAU2T449gC6OD69eZQ1JYZvG6YcLvEx E5jgHkZV51jxv5tdvGfseV2Sm6tDloe7j/nq/yUQtnrkKaIndm1Lp4OtmC3B2TcTMSzpwT41NEH ZKd4EFcFr9jUfpawGXGMUelRkYxPIiVSxkS7RcaUaIElMZv6Xi8L72WYunyhmGY5dOlhy4dX0qa UGPbi2KcAukTnHcC6/f3ird27rdSJwPfABEYlrDx6SpUOukaL6jsYF1fgi7yfY3PPm255mhhua5 skM9yuRsU2q6wXd9lfHc80Ri1FgO6HApBZPSX2ExJTky0+m+sOOnYZZiNNHu16M1uqN31SWqt5v y X-Received: by 2002:a05:620a:4095:b0:8b1:c48f:105d with SMTP id af79cd13be357-8b5e773519fmr795855385a.87.1764861012802; Thu, 04 Dec 2025 07:10:12 -0800 (PST) X-Google-Smtp-Source: AGHT+IHBkxqpioh6ZUgFWGNITjXJGV2mFH098xBMOQL61kY3xJnsMn9OK+8WpatADqnDH4w9UHn6yQ== X-Received: by 2002:a05:620a:4095:b0:8b1:c48f:105d with SMTP id af79cd13be357-8b5e773519fmr795845685a.87.1764861012060; Thu, 04 Dec 2025 07:10:12 -0800 (PST) Received: from x1.com ([142.188.210.156]) by smtp.gmail.com with ESMTPSA id af79cd13be357-8b627a9fd23sm154263285a.46.2025.12.04.07.10.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Dec 2025 07:10:10 -0800 (PST) From: Peter Xu To: kvm@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Jason Gunthorpe , Nico Pache , Zi Yan , Alex Mastro , David Hildenbrand , Alex Williamson , Zhi Wang , David Laight , Yi Liu , Ankit Agrawal , peterx@redhat.com, Kevin Tian , Andrew Morton Subject: [PATCH v2 3/4] vfio: Introduce vfio_device_ops.get_mapping_order hook Date: Thu, 4 Dec 2025 10:10:02 -0500 Message-ID: <20251204151003.171039-4-peterx@redhat.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20251204151003.171039-1-peterx@redhat.com> References: <20251204151003.171039-1-peterx@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add a hook to vfio_device_ops to allow sub-modules provide mapping order hint for an mmap() request. When not available, use the default value (0). Note that this patch will change the code path for vfio on mmap() when allocating the virtual address range to be mapped, however it should not change the result of the VA allocated, because the default value (0) should be the old behavior. Signed-off-by: Peter Xu --- drivers/vfio/vfio_main.c | 14 ++++++++++++++ include/linux/vfio.h | 5 +++++ 2 files changed, 19 insertions(+) diff --git a/drivers/vfio/vfio_main.c b/drivers/vfio/vfio_main.c index 38c8e9350a60e..3f2107ff93e5d 100644 --- a/drivers/vfio/vfio_main.c +++ b/drivers/vfio/vfio_main.c @@ -1372,6 +1372,19 @@ static void vfio_device_show_fdinfo(struct seq_file = *m, struct file *filep) } #endif =20 +static int vfio_device_get_mapping_order(struct file *file, + unsigned long pgoff, + size_t len) +{ + struct vfio_device_file *df =3D file->private_data; + struct vfio_device *device =3D df->device; + + if (device->ops->get_mapping_order) + return device->ops->get_mapping_order(device, pgoff, len); + + return 0; +} + const struct file_operations vfio_device_fops =3D { .owner =3D THIS_MODULE, .open =3D vfio_device_fops_cdev_open, @@ -1384,6 +1397,7 @@ const struct file_operations vfio_device_fops =3D { #ifdef CONFIG_PROC_FS .show_fdinfo =3D vfio_device_show_fdinfo, #endif + .get_mapping_order =3D vfio_device_get_mapping_order, }; =20 static struct vfio_device *vfio_device_from_file(struct file *file) diff --git a/include/linux/vfio.h b/include/linux/vfio.h index eb563f538dee5..46a4d85fc4953 100644 --- a/include/linux/vfio.h +++ b/include/linux/vfio.h @@ -111,6 +111,8 @@ struct vfio_device { * @dma_unmap: Called when userspace unmaps IOVA from the container * this device is attached to. * @device_feature: Optional, fill in the VFIO_DEVICE_FEATURE ioctl + * @get_mapping_order: Optional, provide mapping order hints for mmap(). + * When unavailable, use the default order (zero). */ struct vfio_device_ops { char *name; @@ -139,6 +141,9 @@ struct vfio_device_ops { void (*dma_unmap)(struct vfio_device *vdev, u64 iova, u64 length); int (*device_feature)(struct vfio_device *device, u32 flags, void __user *arg, size_t argsz); + int (*get_mapping_order)(struct vfio_device *device, + unsigned long pgoff, + size_t len); }; =20 #if IS_ENABLED(CONFIG_IOMMUFD) --=20 2.50.1