From patchwork Tue Jul 30 18:34:56 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Souptick Joarder X-Patchwork-Id: 11066491 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id AF4561395 for ; Tue, 30 Jul 2019 18:34:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A41C8285E0 for ; Tue, 30 Jul 2019 18:34:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 955C628832; Tue, 30 Jul 2019 18:34:12 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.0 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 3403A285E0 for ; Tue, 30 Jul 2019 18:34:12 +0000 (UTC) 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 X-Inumbo-ID: 6ebb428b-b2f8-11e9-8980-bc764e045a96 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) 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) 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) 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 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP '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) = 0 [pid 857] mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_SHARED, 7, 0) = 0x777f1211b000 [pid 857] ioctl(7, IOCTL_GNTDEV_SET_UNMAP_NOTIFY, 0x7ffd3407b710) = 0 [pid 857] ioctl(7, IOCTL_GNTDEV_MAP_GRANT_REF, 0x7ffd3407b6d0) = 0 [pid 857] mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_SHARED, 7, 0x1000) = -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órecki Signed-off-by: Souptick Joarder Tested-by: Marek Marczykowski-Górecki 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_area_struct *vma) goto out_put_map; if (!use_ptemod) { - err = vm_map_pages(vma, map->pages, map->count); + err = vm_map_pages_zero(vma, map->pages, map->count); if (err) goto out_put_map; } else {