From nobody Sun May 5 05:57:25 2024 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1564511636; cv=none; d=zoho.com; s=zohoarc; b=Wbw38JNZeDYHKEZ2Wu+PDpan5bzSe110YSyhvGZ9vHxJJnXuZQF8Q36GBTL4vC07WSXzl4xU8/4p36wKa/GTzqgAb/VYqqubdEufszCgsFB5LcSrT1vDphTGMYQ25MyLv2Jbm/uQ8sQXqt9oQnvYAmRdC54ZsUvdEqJQE8AP0RI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1564511636; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To:ARC-Authentication-Results; bh=oH9+2mA1U+l7Mli4sj6rRP64yH7ZI4u9ykGgwTgJFnA=; b=oGA2JUpASYRPnAGLqFp0hb74HkjEGuMcrhQyu6SPeZfsFqEHH3K8la5AVyorvs5YYAwfaJjqWBtnESWGrx5cGYtHenneArMCD9tMuKWvhbILAVN70T9LzCKVdCcr6uweLF5AKg8a6qqdQuSNiGliFE1NwexHqYnoaZF15dM4MC4= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1564511636772871.6654722735143; Tue, 30 Jul 2019 11:33:56 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hsWvb-00053N-Tx; Tue, 30 Jul 2019 18:32:51 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hsWva-00053I-Ok for xen-devel@lists.xenproject.org; Tue, 30 Jul 2019 18:32:50 +0000 Received: from mail-pg1-x544.google.com (unknown [2607:f8b0:4864:20::544]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id 6ebb428b-b2f8-11e9-8980-bc764e045a96; Tue, 30 Jul 2019 18:32:49 +0000 (UTC) Received: by mail-pg1-x544.google.com with SMTP id i70so19758623pgd.4 for ; Tue, 30 Jul 2019 11:32:49 -0700 (PDT) Received: from jordon-HP-15-Notebook-PC.domain.name ([106.51.16.0]) by smtp.gmail.com with ESMTPSA id j5sm57328671pgp.59.2019.07.30.11.32.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 30 Jul 2019 11:32:47 -0700 (PDT) X-Inumbo-ID: 6ebb428b-b2f8-11e9-8980-bc764e045a96 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=6fCIBt83Qg0xm9/csFeyeLFWARKqAMvTELcBmphTpo0=; b=JUA9FbUPr0F6xNgBd5J9MHwHtCHrMpBJuNDTvZBzKBZeCmNsbohHado2HBbGTi0It9 yThD+OL5Bkf6Da9wJnEKF7n1ZuYfE+RCaAChBqmkI/jmB2QhloDai+ucTPidoKT2u6UQ 29UC6QoAyrEf4tN2GNQniwXjZkr83rJH4ak6SFrbJFSb15jmyMBIWZiHh1EgvVH6j48q cZKmuIlqPfwxsnRzt4ye0SXQ2NpyGAmqO03R0RsRzNRYkzGXP/3U1W6hIGXqsFMnjHXR g7Xo3I2gA+uPgrVqyPZw3rp948eNJFIjP60aR0GcG/CsRV9BR7dafhIdCpB5PUi2sogn ixHw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=6fCIBt83Qg0xm9/csFeyeLFWARKqAMvTELcBmphTpo0=; b=aza+YUpQeZ0J/kE1BHMi0XkVKFD2GccFNHk1VfR1/k8pUvYR1NisYnzwGXprk1jZjB o/0ccjHOsNNxC3yuXFyjk0E/+ReO53B+Vh2g3mpBc+4oDB06PlzVWIBzU0o+JgXmrKSi YioNI019PsKypVju0du2I3qJdv+KMvgwD9QK51O01QEvn4J5vlkK+68Sxx53d45fkcF7 jwIRnQRJbl/c4jO4sL+xTJS4sYfbecTKKopXKybCeYqv1xBhQTsAK7P/QcDkUuTXY94t xLm8yk3RKpg2sUQATe8GvHCcQ/viMfWnABr2mie15YP2PzvYxVbi5pjTX1TTrZzYLkUA ZBiw== X-Gm-Message-State: APjAAAVNM4kMXjUt6KmI96LSkBsDHhbMP+pmmT+DqWH2iRaCa628Qkix zUnF7hj/oHG9FyWaveJB8ZE= X-Google-Smtp-Source: APXvYqz3TKO5CR8bm9L/zAhw0K/5mmOOXYnkeug29AHRYcKaRz4UPuCN4Qa7WYzWXEa+PlUkZGXEBw== X-Received: by 2002:a62:754d:: with SMTP id q74mr42050335pfc.211.1564511568653; Tue, 30 Jul 2019 11:32:48 -0700 (PDT) From: Souptick Joarder To: boris.ostrovsky@oracle.com, jgross@suse.com, sstabellini@kernel.org, marmarek@invisiblethingslab.com Date: Wed, 31 Jul 2019 00:04:56 +0530 Message-Id: <1564511696-4044-1-git-send-email-jrdr.linux@gmail.com> X-Mailer: git-send-email 1.9.1 MIME-Version: 1.0 Subject: [Xen-devel] [PATCH] xen/gntdev.c: Replace vm_map_pages() with vm_map_pages_zero() X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: gregkh@linuxfoundation.org, linux-kernel@vger.kernel.org, willy@infradead.org, linux@armlinux.org.uk, linux-mm@kvack.org, stable@vger.kernel.org, xen-devel@lists.xenproject.org, akpm@linux-foundation.org, Souptick Joarder Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) 'commit df9bde015a72 ("xen/gntdev.c: convert to use vm_map_pages()")' breaks gntdev driver. If vma->vm_pgoff > 0, vm_map_pages() will: - use map->pages starting at vma->vm_pgoff instead of 0 - verify map->count against vma_pages()+vma->vm_pgoff instead of just vma_pages(). In practice, this breaks using a single gntdev FD for mapping multiple grants. relevant strace output: [pid 857] ioctl(7, IOCTL_GNTDEV_MAP_GRANT_REF, 0x7ffd3407b6d0) =3D 0 [pid 857] mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_SHARED, 7, 0) =3D 0x777f1211b000 [pid 857] ioctl(7, IOCTL_GNTDEV_SET_UNMAP_NOTIFY, 0x7ffd3407b710) =3D 0 [pid 857] ioctl(7, IOCTL_GNTDEV_MAP_GRANT_REF, 0x7ffd3407b6d0) =3D 0 [pid 857] mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_SHARED, 7, 0x1000) =3D -1 ENXIO (No such device or address) details here: https://github.com/QubesOS/qubes-issues/issues/5199 The reason is -> ( copying Marek's word from discussion) vma->vm_pgoff is used as index passed to gntdev_find_map_index. It's basically using this parameter for "which grant reference to map". map struct returned by gntdev_find_map_index() describes just the pages to be mapped. Specifically map->pages[0] should be mapped at vma->vm_start, not vma->vm_start+vma->vm_pgoff*PAGE_SIZE. When trying to map grant with index (aka vma->vm_pgoff) > 1, __vm_map_pages() will refuse to map it because it will expect map->count to be at least vma_pages(vma)+vma->vm_pgoff, while it is exactly vma_pages(vma). Converting vm_map_pages() to use vm_map_pages_zero() will fix the problem. Marek has tested and confirmed the same. Reported-by: Marek Marczykowski-G=C3=B3recki Signed-off-by: Souptick Joarder Tested-by: Marek Marczykowski-G=C3=B3recki Reviewed-by: Boris Ostrovsky --- drivers/xen/gntdev.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/xen/gntdev.c b/drivers/xen/gntdev.c index 4c339c7..a446a72 100644 --- a/drivers/xen/gntdev.c +++ b/drivers/xen/gntdev.c @@ -1143,7 +1143,7 @@ static int gntdev_mmap(struct file *flip, struct vm_a= rea_struct *vma) goto out_put_map; =20 if (!use_ptemod) { - err =3D vm_map_pages(vma, map->pages, map->count); + err =3D vm_map_pages_zero(vma, map->pages, map->count); if (err) goto out_put_map; } else { --=20 1.9.1 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel