From patchwork Fri Jun 7 19:38:39 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcelo Henrique Cerri X-Patchwork-Id: 1112220 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=canonical.com Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 45LCX40xXFz9s4Y; Sat, 8 Jun 2019 05:39:16 +1000 (AEST) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1hZKhj-00077w-2p; Fri, 07 Jun 2019 19:39:11 +0000 Received: from youngberry.canonical.com ([91.189.89.112]) by huckleberry.canonical.com with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:128) (Exim 4.86_2) (envelope-from ) id 1hZKhg-00075y-0y for kernel-team@lists.ubuntu.com; Fri, 07 Jun 2019 19:39:08 +0000 Received: from mail-qk1-f198.google.com ([209.85.222.198]) by youngberry.canonical.com with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.76) (envelope-from ) id 1hZKhf-000719-FO for kernel-team@lists.ubuntu.com; Fri, 07 Jun 2019 19:39:07 +0000 Received: by mail-qk1-f198.google.com with SMTP id n190so2488217qkd.5 for ; Fri, 07 Jun 2019 12:39:07 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=yX0xWL1xLNjytVGbiBbdU/u8sYRrgKMUeaIWU3Q3cSM=; b=az+XB++Ekx9BxMkP68fHdOikpJI3/HdWLDGoVsO0ovH9iEj3FClR8hT00q4YT/QI9e 4pwHTh2oXy4RwgBmcog9JQisi67fTkxWosuqmPa+QowR88FV0QxbOIAf18aAHNuUxuDk RemyPZuqKOujkpCPkKK81NVAI8mMOIB6cCwL80cVMxHT55IBwLOijCfdsePdP8KSHenv x6073tfvnApOp1VbLC5T7jhV4v275zlC8BOitC31NVaUcVLrfmzEFn7wvxnJGEIeCpPL foT0+r80szAcekin1UjFKWJ1b+luvhSgizT1Zs7DXqqCQdFdHYsFBT+uVdGw7kT7EKC6 fBcA== X-Gm-Message-State: APjAAAVSN+tB2exK4zxk8rBPJybtD6SBbMmIkAbUlS+i1c9sgSbbtVDj Wm+/rjaWSfxBmkMlMNR6TxddLuXQ1SvSeU8pl/DY5bpAAhWY+8e3rRpRyeUFEgbXcz1UIyOW/86 tEZ3DVI0mbhbhHukdKSm3DAQnJFmBy0tJWSIvMkoY X-Received: by 2002:a0c:fd64:: with SMTP id k4mr22231236qvs.143.1559936345355; Fri, 07 Jun 2019 12:39:05 -0700 (PDT) X-Google-Smtp-Source: APXvYqxR0a9aVX2Hsx9H8Na31I4qJ5ToSBVV352QdP3EKBlcaAXsKNPAFjPMZlyf4wdIaeVA9MbNWA== X-Received: by 2002:a0c:fd64:: with SMTP id k4mr22231211qvs.143.1559936345076; Fri, 07 Jun 2019 12:39:05 -0700 (PDT) Received: from gallifrey.lan ([2804:14c:4e3:4a76:b1ae:211f:e30b:4e05]) by smtp.gmail.com with ESMTPSA id r2sm1318875qtp.8.2019.06.07.12.39.03 for (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Fri, 07 Jun 2019 12:39:04 -0700 (PDT) From: Marcelo Henrique Cerri To: kernel-team@lists.ubuntu.com Subject: [x/azure][PATCH 05/17] uio_hv_generic: fix subchannel ring mmap Date: Fri, 7 Jun 2019 16:38:39 -0300 Message-Id: <20190607193851.21914-6-marcelo.cerri@canonical.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190607193851.21914-1-marcelo.cerri@canonical.com> References: <20190607193851.21914-1-marcelo.cerri@canonical.com> MIME-Version: 1.0 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Stephen Hemminger BugLink: http://bugs.launchpad.net/bugs/1812123 The fault method of handling subchannel ring, did not work correctly (it only worked for the first page). Since ring buffer is physically contiguous, using the vm helper function is simpler and handles more cases. Fixes: 37b96a4931db ("uio_hv_generic: support sub-channels") Signed-off-by: Stephen Hemminger Signed-off-by: Greg Kroah-Hartman (cherry picked from commit ce3d1536acabbdcdc3c945c3c078dd4ed1b8edfa) Signed-off-by: Marcelo Henrique Cerri --- drivers/uio/uio_hv_generic.c | 49 +++++++----------------------------- 1 file changed, 9 insertions(+), 40 deletions(-) diff --git a/drivers/uio/uio_hv_generic.c b/drivers/uio/uio_hv_generic.c index 95c1f8260450..0e4e54e95b23 100644 --- a/drivers/uio/uio_hv_generic.c +++ b/drivers/uio/uio_hv_generic.c @@ -17,7 +17,7 @@ * # echo -n vmbus-ed963694-e847-4b2a-85af-bc9cfc11d6f3 \ * > /sys/bus/vmbus/drivers/uio_hv_generic/bind */ - +#define DEBUG 1 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt #include @@ -137,54 +137,23 @@ static void hv_uio_rescind(struct vmbus_channel *channel) uio_event_notify(&pdata->info); } -/* - * Handle fault when looking for sub channel ring buffer - * Subchannel ring buffer is same as resource 0 which is main ring buffer - * This is derived from uio_vma_fault +/* Sysfs API to allow mmap of the ring buffers + * The ring buffer is allocated as contiguous memory by vmbus_open */ -static int hv_uio_vma_fault(struct vm_fault *vmf) -{ - struct vm_area_struct *vma = vmf->vma; - void *ring_buffer = vma->vm_private_data; - struct page *page; - void *addr; - - addr = ring_buffer + (vmf->pgoff << PAGE_SHIFT); - page = virt_to_page(addr); - get_page(page); - vmf->page = page; - return 0; -} - -static const struct vm_operations_struct hv_uio_vm_ops = { - .fault = hv_uio_vma_fault, -}; - -/* Sysfs API to allow mmap of the ring buffers */ static int hv_uio_ring_mmap(struct file *filp, struct kobject *kobj, struct bin_attribute *attr, struct vm_area_struct *vma) { struct vmbus_channel *channel = container_of(kobj, struct vmbus_channel, kobj); - unsigned long requested_pages, actual_pages; - - if (vma->vm_end < vma->vm_start) - return -EINVAL; + struct hv_device *dev = channel->primary_channel->device_obj; + u16 q_idx = channel->offermsg.offer.sub_channel_index; - /* only allow 0 for now */ - if (vma->vm_pgoff > 0) - return -EINVAL; + dev_dbg(&dev->device, "mmap channel %u pages %#lx at %#lx\n", + q_idx, vma_pages(vma), vma->vm_pgoff); - requested_pages = vma_pages(vma); - actual_pages = 2 * HV_RING_SIZE; - if (requested_pages > actual_pages) - return -EINVAL; - - vma->vm_private_data = channel->ringbuffer_pages; - vma->vm_flags |= VM_DONTEXPAND | VM_DONTDUMP; - vma->vm_ops = &hv_uio_vm_ops; - return 0; + return vm_iomap_memory(vma, virt_to_phys(channel->ringbuffer_pages), + channel->ringbuffer_pagecount << PAGE_SHIFT); } static struct bin_attribute ring_buffer_bin_attr __ro_after_init = {