Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932840AbcKPRB5 (ORCPT ); Wed, 16 Nov 2016 12:01:57 -0500 Received: from aserp1040.oracle.com ([141.146.126.69]:28947 "EHLO aserp1040.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932629AbcKPRBv (ORCPT ); Wed, 16 Nov 2016 12:01:51 -0500 From: Boris Ostrovsky To: david.vrabel@citrix.com, jgross@suse.com Cc: xen-devel@lists.xenproject.org, linux-kernel@vger.kernel.org, olaf@aepfle.de, Boris Ostrovsky Subject: [PATCH] xen/gntdev: Use mempolicy instead of VM_IO flag to avoid NUMA balancing Date: Wed, 16 Nov 2016 12:02:42 -0500 Message-Id: <1479315762-32060-1-git-send-email-boris.ostrovsky@oracle.com> X-Mailer: git-send-email 2.7.4 X-Source-IP: aserv0021.oracle.com [141.146.126.233] Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2008 Lines: 73 Commit 9c17d96500f7 ("xen/gntdev: Grant maps should not be subject to NUMA balancing") set VM_IO flag to prevent grant maps from being subjected to NUMA balancing. It was discovered recently this this flag may cause page allocation failures with the following stack: check_vma_flags __get_user_pages __get_user_pages_locked __get_user_pages_unlocked get_user_pages_fast iov_iter_get_pages dio_refill_pages do_direct_IO do_blockdev_direct_IO do_blockdev_direct_IO ext4_direct_IO_read generic_file_read_iter aio_run_iocb (which can happen if guest's vdisk has direct-io-safe option). To avoid this, instead of setting VM_IO use mempolicy that prohibits page migration (i.e. clear policy's MPOL_F_MOF|MPOL_F_MORON) Reported-by: Olaf Hering Signed-off-by: Boris Ostrovsky --- Unfortunately I haven't been able to trigger NUMA balancing so while I tested this in general I am not sure I actually exercised the code path. drivers/xen/gntdev.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/drivers/xen/gntdev.c b/drivers/xen/gntdev.c index bb95212..743e6f0 100644 --- a/drivers/xen/gntdev.c +++ b/drivers/xen/gntdev.c @@ -35,6 +35,7 @@ #include #include #include +#include #include #include @@ -1007,8 +1008,20 @@ static int gntdev_mmap(struct file *flip, struct vm_area_struct *vma) vma->vm_ops = &gntdev_vmops; - vma->vm_flags |= VM_DONTEXPAND | VM_DONTDUMP | VM_IO; + vma->vm_flags |= VM_DONTEXPAND | VM_DONTDUMP; +#ifdef CONFIG_NUMA + /* Prevent NUMA balancing */ + if (vma->vm_policy) + vma->vm_policy->flags &= ~(MPOL_F_MOF | MPOL_F_MORON); + else { + struct mempolicy *pol = get_task_policy(current); + + vma->vm_policy = mpol_dup(pol); + if (vma->vm_policy) + vma->vm_policy->flags &= ~(MPOL_F_MOF | MPOL_F_MORON); + } +#endif if (use_ptemod) vma->vm_flags |= VM_DONTCOPY; -- 2.5.5