From patchwork Fri Jun 7 19:38:35 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: 1112215 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 45LCWs5dFpz9sCJ; Sat, 8 Jun 2019 05:39:05 +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 1hZKhY-00071Y-Sd; Fri, 07 Jun 2019 19:39:00 +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 1hZKhX-00071N-Dv for kernel-team@lists.ubuntu.com; Fri, 07 Jun 2019 19:38:59 +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 1hZKhW-0006zp-Pa for kernel-team@lists.ubuntu.com; Fri, 07 Jun 2019 19:38:58 +0000 Received: by mail-qk1-f198.google.com with SMTP id v2so2476004qkd.11 for ; Fri, 07 Jun 2019 12:38:58 -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=N05TffFmOvQ7QIxwhYokjIgjvQ0r+DtNCEtvJ6uVmaE=; b=LfXfzvoFv96GuQppT5gIodq4i56ZChSkILoD/L3wPKNe3MMMMyIleDZ9clJvw2U1Tt I3IqRDhZq8qCVkol/k5L6AW4SjFR5m4X8fHClVMgR/i0FkTkqcztRK4R/QpqE4YOKNJU h5JNIdCdku1buyG8H9sfHjqnQu2lq699MKVBrh6fC1aZ5/IkGn4whBBeFWdiz9zCK7oR GX4+RrotCxzK+QLGEZrza9hl5LqMM7QwtlYyMEhde6NIqdUE5lHgaHl6q22aLkPCZBDS u7oX2GpR6iLbIGZS1pvvhcgiFQeyLweZjbQCE3cn971KciEcIzdY2J4otqRMKmcx6kXy BUlA== X-Gm-Message-State: APjAAAU/DaqMs60bkXa34yO5uV97y4y6vIy+GRpH0iBOuqJmmfEDVVy6 2RSlID32r6CkLpAz5LDMBFY0E/riM6zWe7bGlN3nRf209rtpgrGHUPB0Ouuw10lP6Du3hAwYxzr Ln7t6kRTZ8HFj2DS1HM/RGnZI6v15pvQ+KHTCs/hN X-Received: by 2002:a0c:b997:: with SMTP id v23mr44989373qvf.128.1559936337571; Fri, 07 Jun 2019 12:38:57 -0700 (PDT) X-Google-Smtp-Source: APXvYqxrY2tQ4irghS8/DPWTp1VjI7ouFomcEaHjcM/5FuHQywr17hVlfvNZ0h35kV6p7vxN2FIwVw== X-Received: by 2002:a0c:b997:: with SMTP id v23mr44989354qvf.128.1559936337340; Fri, 07 Jun 2019 12:38:57 -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.38.55 for (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Fri, 07 Jun 2019 12:38:56 -0700 (PDT) From: Marcelo Henrique Cerri To: kernel-team@lists.ubuntu.com Subject: [x/azure][PATCH 01/17] uio: document uio_hv_generic regions Date: Fri, 7 Jun 2019 16:38:35 -0300 Message-Id: <20190607193851.21914-2-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 Describe the regions present with uio_hv_generic in documentation for driver API. Signed-off-by: Stephen Hemminger Signed-off-by: Greg Kroah-Hartman (cherry picked from commit c5702d1b31085ccda7f46e514a51c6c8db54cdc4) Signed-off-by: Marcelo Henrique Cerri --- Documentation/driver-api/uio-howto.rst | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Documentation/driver-api/uio-howto.rst b/Documentation/driver-api/uio-howto.rst index f73d660b2956..733672ff702d 100644 --- a/Documentation/driver-api/uio-howto.rst +++ b/Documentation/driver-api/uio-howto.rst @@ -697,6 +697,11 @@ prevents the device from generating further interrupts until the bit is cleared. The userspace driver should clear this bit before blocking and waiting for more interrupts. +The vmbus device regions are mapped into uio device resources: + 0) Channel ring buffers: guest to host and host to guest + 1) Guest to host interrupt signalling pages + 2) Guest to host monitor page + Further information =================== From patchwork Fri Jun 7 19:38:36 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: 1112216 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 45LCWv1lYfz9sN4; Sat, 8 Jun 2019 05:39:07 +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 1hZKhb-00072o-4L; Fri, 07 Jun 2019 19:39:03 +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 1hZKhZ-00071k-87 for kernel-team@lists.ubuntu.com; Fri, 07 Jun 2019 19:39:01 +0000 Received: from mail-qk1-f197.google.com ([209.85.222.197]) by youngberry.canonical.com with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.76) (envelope-from ) id 1hZKhY-00070E-Pi for kernel-team@lists.ubuntu.com; Fri, 07 Jun 2019 19:39:00 +0000 Received: by mail-qk1-f197.google.com with SMTP id n5so2484966qkf.7 for ; Fri, 07 Jun 2019 12:39:00 -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=dWzrHTtWIjneBeBiX0m5O7sxKVRxbb6XscmfpIA8cpo=; b=S+ikhSjwI9E+z+G+if7624NKUAA2BBDm65X5SjJ3LivS0DqP5EmWYaR2rRGSmxsWY2 KjTXBM8xl+fR2boEfNNyx0NK014xLVjEhq7UNyGlZD0jNRJlg8R3LS6iuVo0YzHE8l6W yT68Odpicx9VAGyD8NhBA9unH4NRLcDwCR+p1XQirUr47eB3aMPWhiiTbqYDx6y9rsJq bO0DJSYtnT1LoUuww4894ykeDKawLgJGL6+G5TTJa/9WdkHbq5/0GJIy5ya1Wgf+yTVw G2jODcFVeYQOx6WGK4o9QwIxUisjFTfCZbEC612DkBrQa1/c/ZtmzOysO6yvJLw9peKb CVfA== X-Gm-Message-State: APjAAAUfaE57to4nezoj/t8HLNkq6fOCesJR+ra5Se3McMRvytNG1/6H +y0m/9mRVaO9e8lT+ildiA3Yu+oWmitP503xm8R35XK7cqmThLWoQCeOkOWMrr6Eb92oSrNDLSO RaghFXC6Og0/8wXYCPqrJWl5xn/CYmHusRXedBYkw X-Received: by 2002:ac8:28bc:: with SMTP id i57mr16588517qti.288.1559936339551; Fri, 07 Jun 2019 12:38:59 -0700 (PDT) X-Google-Smtp-Source: APXvYqy4ahow2TgRnGwF8CuFXyZ4qiv6i5cgdqVdBeD9i5TKQceeKVkkeW9Yx9wDq8r7d8qAJk1bkA== X-Received: by 2002:ac8:28bc:: with SMTP id i57mr16588496qti.288.1559936339252; Fri, 07 Jun 2019 12:38:59 -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.38.57 for (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Fri, 07 Jun 2019 12:38:58 -0700 (PDT) From: Marcelo Henrique Cerri To: kernel-team@lists.ubuntu.com Subject: [x/azure][PATCH 02/17] uio_hv_generic: create send and receive buffers Date: Fri, 7 Jun 2019 16:38:36 -0300 Message-Id: <20190607193851.21914-3-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 Map in receive and send buffers for networking in UIO device. These buffers are special and need to be setup by kernel API's; userspace can not do it. Signed-off-by: Stephen Hemminger Signed-off-by: Greg Kroah-Hartman (cherry picked from commit e7d214642a19b8e0e7ecda39184c2ab98ba4801f) Signed-off-by: Marcelo Henrique Cerri --- Documentation/driver-api/uio-howto.rst | 2 + drivers/uio/uio_hv_generic.c | 71 +++++++++++++++++++++++++- 2 files changed, 71 insertions(+), 2 deletions(-) diff --git a/Documentation/driver-api/uio-howto.rst b/Documentation/driver-api/uio-howto.rst index 733672ff702d..3d582634d1f5 100644 --- a/Documentation/driver-api/uio-howto.rst +++ b/Documentation/driver-api/uio-howto.rst @@ -701,6 +701,8 @@ The vmbus device regions are mapped into uio device resources: 0) Channel ring buffers: guest to host and host to guest 1) Guest to host interrupt signalling pages 2) Guest to host monitor page + 3) Network receive buffer region + 4) Network send buffer region Further information =================== diff --git a/drivers/uio/uio_hv_generic.c b/drivers/uio/uio_hv_generic.c index fe5cdda80b2c..dee96330bd53 100644 --- a/drivers/uio/uio_hv_generic.c +++ b/drivers/uio/uio_hv_generic.c @@ -37,6 +37,10 @@ #define DRIVER_AUTHOR "Stephen Hemminger " #define DRIVER_DESC "Generic UIO driver for VMBus devices" +#define HV_RING_SIZE 512 /* pages */ +#define SEND_BUFFER_SIZE (15 * 1024 * 1024) +#define RECV_BUFFER_SIZE (15 * 1024 * 1024) + /* * List of resources to be mapped to user space * can be extended up to MAX_UIO_MAPS(5) items @@ -45,13 +49,21 @@ enum hv_uio_map { TXRX_RING_MAP = 0, INT_PAGE_MAP, MON_PAGE_MAP, + RECV_BUF_MAP, + SEND_BUF_MAP }; -#define HV_RING_SIZE 512 - struct hv_uio_private_data { struct uio_info info; struct hv_device *device; + + void *recv_buf; + u32 recv_gpadl; + char recv_name[32]; /* "recv_4294967295" */ + + void *send_buf; + u32 send_gpadl; + char send_name[32]; }; static int @@ -107,6 +119,19 @@ static void hv_uio_channel_cb(void *context) uio_event_notify(&pdata->info); } + +static void +hv_uio_cleanup(struct hv_device *dev, struct hv_uio_private_data *pdata) +{ + if (pdata->send_gpadl) + vmbus_teardown_gpadl(dev->channel, pdata->send_gpadl); + vfree(pdata->send_buf); + + if (pdata->recv_gpadl) + vmbus_teardown_gpadl(dev->channel, pdata->recv_gpadl); + vfree(pdata->recv_buf); +} + static int hv_uio_probe(struct hv_device *dev, const struct hv_vmbus_device_id *dev_id) @@ -161,6 +186,46 @@ hv_uio_probe(struct hv_device *dev, pdata->info.mem[MON_PAGE_MAP].size = PAGE_SIZE; pdata->info.mem[MON_PAGE_MAP].memtype = UIO_MEM_LOGICAL; + pdata->recv_buf = vzalloc(RECV_BUFFER_SIZE); + if (pdata->recv_buf == NULL) { + ret = -ENOMEM; + goto fail_close; + } + + ret = vmbus_establish_gpadl(dev->channel, pdata->recv_buf, + RECV_BUFFER_SIZE, &pdata->recv_gpadl); + if (ret) + goto fail_close; + + /* put Global Physical Address Label in name */ + snprintf(pdata->recv_name, sizeof(pdata->recv_name), + "recv:%u", pdata->recv_gpadl); + pdata->info.mem[RECV_BUF_MAP].name = pdata->recv_name; + pdata->info.mem[RECV_BUF_MAP].addr + = (phys_addr_t)pdata->recv_buf; + pdata->info.mem[RECV_BUF_MAP].size = RECV_BUFFER_SIZE; + pdata->info.mem[RECV_BUF_MAP].memtype = UIO_MEM_VIRTUAL; + + + pdata->send_buf = vzalloc(SEND_BUFFER_SIZE); + if (pdata->send_buf == NULL) { + ret = -ENOMEM; + goto fail_close; + } + + ret = vmbus_establish_gpadl(dev->channel, pdata->send_buf, + SEND_BUFFER_SIZE, &pdata->send_gpadl); + if (ret) + goto fail_close; + + snprintf(pdata->send_name, sizeof(pdata->send_name), + "send:%u", pdata->send_gpadl); + pdata->info.mem[SEND_BUF_MAP].name = pdata->send_name; + pdata->info.mem[SEND_BUF_MAP].addr + = (phys_addr_t)pdata->send_buf; + pdata->info.mem[SEND_BUF_MAP].size = SEND_BUFFER_SIZE; + pdata->info.mem[SEND_BUF_MAP].memtype = UIO_MEM_VIRTUAL; + pdata->info.priv = pdata; pdata->device = dev; @@ -175,6 +240,7 @@ hv_uio_probe(struct hv_device *dev, return 0; fail_close: + hv_uio_cleanup(dev, pdata); vmbus_close(dev->channel); fail: kfree(pdata); @@ -191,6 +257,7 @@ hv_uio_remove(struct hv_device *dev) return 0; uio_unregister_device(&pdata->info); + hv_uio_cleanup(dev, pdata); hv_set_drvdata(dev, NULL); vmbus_close(dev->channel); kfree(pdata); From patchwork Fri Jun 7 19:38:37 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: 1112217 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 45LCWx6dYXz9sDB; Sat, 8 Jun 2019 05:39:09 +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 1hZKhd-00074P-K8; Fri, 07 Jun 2019 19:39:05 +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 1hZKhb-00072l-6L for kernel-team@lists.ubuntu.com; Fri, 07 Jun 2019 19:39:03 +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 1hZKha-00070p-O5 for kernel-team@lists.ubuntu.com; Fri, 07 Jun 2019 19:39:02 +0000 Received: by mail-qk1-f198.google.com with SMTP id n126so2458587qkc.18 for ; Fri, 07 Jun 2019 12:39:02 -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=ie5HXhsuSvpKA5/cGTHuBkxXV1Nz6LmkIAGq1Dr+1vY=; b=gMZKClNxjeFR01WpzHy9lCFrzamPAnk5YdumfQtPLx3RIFPZRL86O5X89QqK/sI2p9 OqvqrIiDo1k73PsVoxKda5iLJiR+dZSjxmdLQA/jiILmAz1Tmm/8nAOxzsStWzvMjGi0 oTgH1yrKR2ZWZGSZmRZYv1Z4TXePFHpxk547RO3z2gIjC6USRbsYFOvnGXIbR8NNhkRa iX+fbNhQ9k+sG5l3n0bxrjGg96/eg8oNtBPc/I2bWd2+kp8QYXtub2HckDYrIpqvqGqT oc8kVyLz65Y0Vv9Pn9hE2Jhxs/niBrgXaWKpBVy4HFQexatndqu02e4Aw3G2pF2c2v/O VfNg== X-Gm-Message-State: APjAAAXcKqPanfFp7kz+nraaJSwBeHnPcp3yRDhV9gdAWHyC7Tl71vl4 B41YAst3qiRdG2i66rFajnfnxnZLwLD4pkN+UWYJL0gAd1mkqS8gqTAy+rlOxrWNY/2kIJZTmpL oLE2P5KjSPg4eY1QziwtrBbB8hGMBE+5pjt3vSwOt X-Received: by 2002:a0c:d003:: with SMTP id u3mr32767066qvg.112.1559936341502; Fri, 07 Jun 2019 12:39:01 -0700 (PDT) X-Google-Smtp-Source: APXvYqwb6kJma9koHHCFre16DKB4itLLj2hEYcjNcZb+nqJu2EMkZVcrXqFq4hKSkfB6KXHB9HlO/Q== X-Received: by 2002:a0c:d003:: with SMTP id u3mr32767047qvg.112.1559936341201; Fri, 07 Jun 2019 12:39:01 -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.38.59 for (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Fri, 07 Jun 2019 12:39:00 -0700 (PDT) From: Marcelo Henrique Cerri To: kernel-team@lists.ubuntu.com Subject: [x/azure][PATCH 03/17] uio_hv_generic: add rescind support Date: Fri, 7 Jun 2019 16:38:37 -0300 Message-Id: <20190607193851.21914-4-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 When host rescinds the device, the UIO driver will clear the interrupt state and notify application. The read (or write) on the interrupt FD will then fail with -EIO. This is simpler than adding lots extra uevent stuff inside UIO. Signed-off-by: Stephen Hemminger Signed-off-by: Greg Kroah-Hartman (cherry picked from commit ca3cda6fcf1e922213a0cc58e708ffb999151db3) Signed-off-by: Marcelo Henrique Cerri --- Documentation/driver-api/uio-howto.rst | 4 ++++ drivers/uio/uio_hv_generic.c | 19 +++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/Documentation/driver-api/uio-howto.rst b/Documentation/driver-api/uio-howto.rst index 3d582634d1f5..bfab29cf86c6 100644 --- a/Documentation/driver-api/uio-howto.rst +++ b/Documentation/driver-api/uio-howto.rst @@ -697,6 +697,10 @@ prevents the device from generating further interrupts until the bit is cleared. The userspace driver should clear this bit before blocking and waiting for more interrupts. +When host rescinds a device, the interrupt file descriptor is marked down +and any reads of the interrupt file descriptor will return -EIO. Similar +to a closed socket or disconnected serial device. + The vmbus device regions are mapped into uio device resources: 0) Channel ring buffers: guest to host and host to guest 1) Guest to host interrupt signalling pages diff --git a/drivers/uio/uio_hv_generic.c b/drivers/uio/uio_hv_generic.c index dee96330bd53..fbe7e956de60 100644 --- a/drivers/uio/uio_hv_generic.c +++ b/drivers/uio/uio_hv_generic.c @@ -119,6 +119,23 @@ static void hv_uio_channel_cb(void *context) uio_event_notify(&pdata->info); } +/* + * Callback from vmbus_event when channel is rescinded. + */ +static void hv_uio_rescind(struct vmbus_channel *channel) +{ + struct hv_device *hv_dev = channel->primary_channel->device_obj; + struct hv_uio_private_data *pdata = hv_get_drvdata(hv_dev); + + /* + * Turn off the interrupt file handle + * Next read for event will return -EIO + */ + pdata->info.irq = 0; + + /* Wake up reader */ + uio_event_notify(&pdata->info); +} static void hv_uio_cleanup(struct hv_device *dev, struct hv_uio_private_data *pdata) @@ -235,6 +252,8 @@ hv_uio_probe(struct hv_device *dev, goto fail_close; } + vmbus_set_chn_rescind_callback(dev->channel, hv_uio_rescind); + hv_set_drvdata(dev, pdata); return 0; From patchwork Fri Jun 7 19:38:38 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: 1112218 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 45LCX20f0Jz9s6w; Sat, 8 Jun 2019 05:39:14 +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 1hZKhh-00076n-GZ; Fri, 07 Jun 2019 19:39:09 +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 1hZKhd-000749-4h for kernel-team@lists.ubuntu.com; Fri, 07 Jun 2019 19:39:05 +0000 Received: from mail-qt1-f198.google.com ([209.85.160.198]) by youngberry.canonical.com with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.76) (envelope-from ) id 1hZKhc-00070v-LY for kernel-team@lists.ubuntu.com; Fri, 07 Jun 2019 19:39:04 +0000 Received: by mail-qt1-f198.google.com with SMTP id w41so2727271qth.20 for ; Fri, 07 Jun 2019 12:39:04 -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=uCWmZ0JmhpxkywO+cZ6scS36T68+Wr3TzZcbXUFw2MU=; b=FezeHS8O8+NlQgo83vsv4815gFMKMQ/XOBKGdF62EnObci1nvuajswAWo3pM2/1kLn igJC0rUsH76pkmO/nvQwUYUQ6oJe1LLARg1T6L4AL69gcVAymU79B4hIjsUcI6WjTdNu VJeffdMfI/A+P37w+5pte0nxe2BiszQjDIuh8ZqkaMlNzmKi2eYQBFITrMZcUiBFJiKL hn438LbuSVi4rVrIOLAEbv8clcSjxIfNhxUlSvr/RRgCkAkBcfavfpt0G1ar4dZ1m7c7 gwd8HsUddmviIyxHb/53tp/NIMfVIBGNjQoxzO8IsxnQtpDR7pdL5IOxlTR1mae9cxsd W77A== X-Gm-Message-State: APjAAAWhI9iIq5KbAFz71ROFEBKSxp7oSph3q5iexNYdsU3dNYE+TKU+ MAsF0ZOdjuqKByot0XBJub092sTZEDR+JeA4xH7oT5VRw0MeSvP2QrE/7HryLJL6mZZkmh/IgCy nntFj2nMfM5gs0RGZ8YUPfFEJcDGkNki4IsvohPYt X-Received: by 2002:ac8:197a:: with SMTP id g55mr13139995qtk.320.1559936343406; Fri, 07 Jun 2019 12:39:03 -0700 (PDT) X-Google-Smtp-Source: APXvYqx8OpHIgGpYaJcPbLg7N7EAPm5WUy9koo6lZQCvXtXnFNUAWd2smTcYi8bUbbTPCChxkNBn0w== X-Received: by 2002:ac8:197a:: with SMTP id g55mr13139974qtk.320.1559936343090; Fri, 07 Jun 2019 12:39:03 -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.01 for (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Fri, 07 Jun 2019 12:39:02 -0700 (PDT) From: Marcelo Henrique Cerri To: kernel-team@lists.ubuntu.com Subject: [x/azure][PATCH 04/17] uio_hv_generic: support sub-channels Date: Fri, 7 Jun 2019 16:38:38 -0300 Message-Id: <20190607193851.21914-5-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 Use sysfs to allow supporting sub-channels. The userspace application makes request to host to create sub-channels and the UIO kernel driver populates the sysfs per-channel directory with a binary attribute file that can be used to read/write ring. Signed-off-by: Stephen Hemminger Signed-off-by: Greg Kroah-Hartman (backported from commit 37b96a4931dba07cebbf07092e55d1562155412b) [marcelo.cerri@canonical.com: fixed context in Documentation/ABI/stable/sysfs-bus-vmbus] Signed-off-by: Marcelo Henrique Cerri --- Documentation/ABI/stable/sysfs-bus-vmbus | 7 ++ Documentation/driver-api/uio-howto.rst | 5 ++ drivers/uio/uio_hv_generic.c | 89 ++++++++++++++++++++++++ 3 files changed, 101 insertions(+) diff --git a/Documentation/ABI/stable/sysfs-bus-vmbus b/Documentation/ABI/stable/sysfs-bus-vmbus index d4077cc60d55..e47777a300d3 100644 --- a/Documentation/ABI/stable/sysfs-bus-vmbus +++ b/Documentation/ABI/stable/sysfs-bus-vmbus @@ -111,3 +111,10 @@ KernelVersion: 4.14 Contact: Stephen Hemminger Description: Number of times we have taken an interrupt (incoming) Users: Debugging tools + +What: /sys/bus/vmbus/devices/vmbus_*/channels/NN/ring +Date: January. 2018 +KernelVersion: 4.16 +Contact: Stephen Hemminger +Description: Binary file created by uio_hv_generic for ring buffer +Users: Userspace drivers diff --git a/Documentation/driver-api/uio-howto.rst b/Documentation/driver-api/uio-howto.rst index bfab29cf86c6..2663984ced86 100644 --- a/Documentation/driver-api/uio-howto.rst +++ b/Documentation/driver-api/uio-howto.rst @@ -708,6 +708,11 @@ The vmbus device regions are mapped into uio device resources: 3) Network receive buffer region 4) Network send buffer region +If a subchannel is created by a request to host, then the uio_hv_generic +device driver will create a sysfs binary file for the per-channel ring buffer. +For example: + /sys/bus/vmbus/devices/3811fe4d-0fa0-4b62-981a-74fc1084c757/channels/21/ring + Further information =================== diff --git a/drivers/uio/uio_hv_generic.c b/drivers/uio/uio_hv_generic.c index fbe7e956de60..95c1f8260450 100644 --- a/drivers/uio/uio_hv_generic.c +++ b/drivers/uio/uio_hv_generic.c @@ -137,6 +137,94 @@ 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 + */ +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; + + /* only allow 0 for now */ + if (vma->vm_pgoff > 0) + return -EINVAL; + + 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; +} + +static struct bin_attribute ring_buffer_bin_attr __ro_after_init = { + .attr = { + .name = "ring", + .mode = 0600, + /* size is set at init time */ + }, + .mmap = hv_uio_ring_mmap, +}; + +/* Callback from VMBUS subystem when new channel created. */ +static void +hv_uio_new_channel(struct vmbus_channel *new_sc) +{ + struct hv_device *hv_dev = new_sc->primary_channel->device_obj; + struct device *device = &hv_dev->device; + struct hv_uio_private_data *pdata = hv_get_drvdata(hv_dev); + const size_t ring_bytes = HV_RING_SIZE * PAGE_SIZE; + int ret; + + /* Create host communication ring */ + ret = vmbus_open(new_sc, ring_bytes, ring_bytes, NULL, 0, + hv_uio_channel_cb, pdata); + if (ret) { + dev_err(device, "vmbus_open subchannel failed: %d\n", ret); + return; + } + + /* Disable interrupts on sub channel */ + new_sc->inbound.ring_buffer->interrupt_mask = 1; + set_channel_read_mode(new_sc, HV_CALL_ISR); + + ret = sysfs_create_bin_file(&new_sc->kobj, &ring_buffer_bin_attr); + if (ret) { + dev_err(device, "sysfs create ring bin file failed; %d\n", ret); + vmbus_close(new_sc); + } +} + static void hv_uio_cleanup(struct hv_device *dev, struct hv_uio_private_data *pdata) { @@ -253,6 +341,7 @@ hv_uio_probe(struct hv_device *dev, } vmbus_set_chn_rescind_callback(dev->channel, hv_uio_rescind); + vmbus_set_sc_create_callback(dev->channel, hv_uio_new_channel); hv_set_drvdata(dev, pdata); 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 = { From patchwork Fri Jun 7 19:38:40 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: 1112221 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 45LCX61ZHPz9s4Y; Sat, 8 Jun 2019 05:39:18 +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 1hZKhl-00079U-FP; Fri, 07 Jun 2019 19:39:13 +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-00076T-VC for kernel-team@lists.ubuntu.com; Fri, 07 Jun 2019 19:39:08 +0000 Received: from mail-qk1-f199.google.com ([209.85.222.199]) by youngberry.canonical.com with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.76) (envelope-from ) id 1hZKhg-00071E-ED for kernel-team@lists.ubuntu.com; Fri, 07 Jun 2019 19:39:08 +0000 Received: by mail-qk1-f199.google.com with SMTP id c4so2470269qkd.16 for ; Fri, 07 Jun 2019 12:39:08 -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=7kHorqL0KG9en5cCkYRa8cTAdC9Ixtc5uisN5Ad4QYA=; b=MbQnWsDBxZ8fExXOtyespnyWjCOqJf7QyVrmpQGrEG2zgfbr3h4Sl/JEKXHdNeuoz1 df6T40NdUqhE0yWtFhTiklyuGC6KdrEmYVz8rx7v79Tzd5Jf48aZbUu4VvqNuTvrR8p1 aZqTRwaj7OFnJ72NGhAV8YkNQ7N3OayCvHgZL1uhHaWaerOu14NR2P2Z59xtw++PUMbf 7oF5NazDhlhYbDxXQYoMKzy100WKJHDdml4jOs8ZZCd0zLXIyehHudaU8G/ppIFHslwq 57q3Uqq1+BkxvbMtzxWoEIHzB4RxQuyw9DjB+iN5QlCGx9ZKj4VKjqFMhq6ijTFBQRL+ CGAg== X-Gm-Message-State: APjAAAWrUVXeKjVtBRQX/LdzfAvcxuVPVGITLECN14fsVzM5SppEhQtN tbS9k4gBRadp3dgMVKJ+4f29YFt6J23pwamYeke0vLHBDntSiw8U8vhea3q9FJpdqdtrJW6KfnQ ODuuuTQDB6UuIU5gHvVTcxyFGkBZJhGj2qPcR573D X-Received: by 2002:ac8:3f32:: with SMTP id c47mr47522021qtk.342.1559936347191; Fri, 07 Jun 2019 12:39:07 -0700 (PDT) X-Google-Smtp-Source: APXvYqzVXlVDGeSXYtWYayznplwborlCK8qMOuQb9twFAEgD/7sfZleCspvYY5iPc6joJsJzKaEGoQ== X-Received: by 2002:ac8:3f32:: with SMTP id c47mr47522001qtk.342.1559936346902; Fri, 07 Jun 2019 12:39:06 -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.05 for (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Fri, 07 Jun 2019 12:39:06 -0700 (PDT) From: Marcelo Henrique Cerri To: kernel-team@lists.ubuntu.com Subject: [x/azure][PATCH 06/17] uio_hv_generic: use standard mmap for resources Date: Fri, 7 Jun 2019 16:38:40 -0300 Message-Id: <20190607193851.21914-7-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 generic UIO mmap should work for us. Signed-off-by: Stephen Hemminger Signed-off-by: Greg Kroah-Hartman (cherry picked from commit 9c40546c012c8d98e88be38c650e66203cb2f1a8) Signed-off-by: Marcelo Henrique Cerri --- drivers/uio/uio_hv_generic.c | 33 +++++++-------------------------- 1 file changed, 7 insertions(+), 26 deletions(-) diff --git a/drivers/uio/uio_hv_generic.c b/drivers/uio/uio_hv_generic.c index 0e4e54e95b23..75094605dd02 100644 --- a/drivers/uio/uio_hv_generic.c +++ b/drivers/uio/uio_hv_generic.c @@ -66,24 +66,6 @@ struct hv_uio_private_data { char send_name[32]; }; -static int -hv_uio_mmap(struct uio_info *info, struct vm_area_struct *vma) -{ - int mi; - - if (vma->vm_pgoff >= MAX_UIO_MAPS) - return -EINVAL; - - if (info->mem[vma->vm_pgoff].size == 0) - return -EINVAL; - - mi = (int)vma->vm_pgoff; - - return remap_pfn_range(vma, vma->vm_start, - info->mem[mi].addr >> PAGE_SHIFT, - vma->vm_end - vma->vm_start, vma->vm_page_prot); -} - /* * This is the irqcontrol callback to be registered to uio_info. * It can be used to disable/enable interrupt from user space processes. @@ -237,26 +219,25 @@ hv_uio_probe(struct hv_device *dev, pdata->info.name = "uio_hv_generic"; pdata->info.version = DRIVER_VERSION; pdata->info.irqcontrol = hv_uio_irqcontrol; - pdata->info.mmap = hv_uio_mmap; pdata->info.irq = UIO_IRQ_CUSTOM; /* mem resources */ pdata->info.mem[TXRX_RING_MAP].name = "txrx_rings"; pdata->info.mem[TXRX_RING_MAP].addr - = virt_to_phys(dev->channel->ringbuffer_pages); + = (phys_addr_t)dev->channel->ringbuffer_pages; pdata->info.mem[TXRX_RING_MAP].size - = dev->channel->ringbuffer_pagecount * PAGE_SIZE; + = dev->channel->ringbuffer_pagecount << PAGE_SHIFT; pdata->info.mem[TXRX_RING_MAP].memtype = UIO_MEM_LOGICAL; pdata->info.mem[INT_PAGE_MAP].name = "int_page"; - pdata->info.mem[INT_PAGE_MAP].addr = - virt_to_phys(vmbus_connection.int_page); + pdata->info.mem[INT_PAGE_MAP].addr + = (phys_addr_t)vmbus_connection.int_page; pdata->info.mem[INT_PAGE_MAP].size = PAGE_SIZE; pdata->info.mem[INT_PAGE_MAP].memtype = UIO_MEM_LOGICAL; - pdata->info.mem[MON_PAGE_MAP].name = "monitor_pages"; - pdata->info.mem[MON_PAGE_MAP].addr = - virt_to_phys(vmbus_connection.monitor_pages[1]); + pdata->info.mem[MON_PAGE_MAP].name = "monitor_page"; + pdata->info.mem[MON_PAGE_MAP].addr + = (phys_addr_t)vmbus_connection.monitor_pages[1]; pdata->info.mem[MON_PAGE_MAP].size = PAGE_SIZE; pdata->info.mem[MON_PAGE_MAP].memtype = UIO_MEM_LOGICAL; From patchwork Fri Jun 7 19:38:41 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: 1112222 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 45LCX90Rskz9s6w; Sat, 8 Jun 2019 05:39:21 +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 1hZKho-0007C8-3w; Fri, 07 Jun 2019 19:39:16 +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 1hZKhj-00077r-A5 for kernel-team@lists.ubuntu.com; Fri, 07 Jun 2019 19:39:11 +0000 Received: from mail-qt1-f199.google.com ([209.85.160.199]) by youngberry.canonical.com with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.76) (envelope-from ) id 1hZKhi-00071K-E3 for kernel-team@lists.ubuntu.com; Fri, 07 Jun 2019 19:39:10 +0000 Received: by mail-qt1-f199.google.com with SMTP id l11so2718041qtp.22 for ; Fri, 07 Jun 2019 12:39:10 -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=f38D0P/2Kr3cMbeeAjVHxX6doHHyjHJtAAtqg+YM2u8=; b=RvTdvkYkSSl2XwdNJbzcaY7B1jBGFXzL+FPHP+4zWqQOHyugeryiU1KyfOZAnl9ahy eLeVpEKweFbs9j+d2UkqdFAufiYvhIeVk2dvuRoJySvWUlUJcd2iA+JNruB9vOrbmxn8 EdHVjIix/Hq9wPsm+u/1ybXruE0p/nGPlU9UKju9HX7kzbuSHQCmAnMzVkGBdZr1ZBbF ZM1TSHMTnxwaIPGcr2+MOhgPC9uxW5II0J0lAa6CfmRfd+JjMlOHPVwLkunbzppLw+1U vDvMgqCpe9rr/Og/HCmr7ZTPliXmMs6c7Tly72OjokT8evJR+NhFn/X4YiifUabVPeMg B+sw== X-Gm-Message-State: APjAAAWXdFJCnfjy3jK6pUg6PAKX3tHqT2GW+JOmF2Vc7efLqRiltA7Q NtklfszOHs2/ZfYf6WfHrvtqdyFyjqOgh84P+KhbS3bwj+XYFVfSGpoAMge20cnF0C5z4zWZbct x1/eQI99v9Nd3rFwshJ+qfhaOZ1xzwXe1Sb0zNf3P X-Received: by 2002:ac8:156:: with SMTP id f22mr30027738qtg.58.1559936349144; Fri, 07 Jun 2019 12:39:09 -0700 (PDT) X-Google-Smtp-Source: APXvYqxccC2OYnggxrkeqBXyfsXyKq3eWIY+U6WuHfYvuvwaFu0MOxdKfZGCij5Zihe2VLyj//BTIQ== X-Received: by 2002:ac8:156:: with SMTP id f22mr30027724qtg.58.1559936348838; Fri, 07 Jun 2019 12:39:08 -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.07 for (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Fri, 07 Jun 2019 12:39:08 -0700 (PDT) From: Marcelo Henrique Cerri To: kernel-team@lists.ubuntu.com Subject: [x/azure][PATCH 07/17] vmbus: keep pointer to ring buffer page Date: Fri, 7 Jun 2019 16:38:41 -0300 Message-Id: <20190607193851.21914-8-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 Avoid going from struct page to virt address (and back) by just keeping pointer to the allocated pages instead of virt address. Signed-off-by: Stephen Hemminger Signed-off-by: Greg Kroah-Hartman (backported from commit 52a42c2a90226dc61c99bbd0cb096deeb52c334b) [marcelo.cerri@canonical.com: fixed small context conflict in hv_uio_probe()] Signed-off-by: Marcelo Henrique Cerri --- drivers/hv/channel.c | 20 +++++++++----------- drivers/uio/uio_hv_generic.c | 5 +++-- include/linux/hyperv.h | 2 +- 3 files changed, 13 insertions(+), 14 deletions(-) diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c index 4138fe783578..c94ded629518 100644 --- a/drivers/hv/channel.c +++ b/drivers/hv/channel.c @@ -90,11 +90,14 @@ int vmbus_open(struct vmbus_channel *newchannel, u32 send_ringbuffer_size, unsigned long flags; int ret, err = 0; struct page *page; + unsigned int order; if (send_ringbuffer_size % PAGE_SIZE || recv_ringbuffer_size % PAGE_SIZE) return -EINVAL; + order = get_order(send_ringbuffer_size + recv_ringbuffer_size); + spin_lock_irqsave(&newchannel->lock, flags); if (newchannel->state == CHANNEL_OPEN_STATE) { newchannel->state = CHANNEL_OPENING_STATE; @@ -109,21 +112,17 @@ int vmbus_open(struct vmbus_channel *newchannel, u32 send_ringbuffer_size, /* Allocate the ring buffer */ page = alloc_pages_node(cpu_to_node(newchannel->target_cpu), - GFP_KERNEL|__GFP_ZERO, - get_order(send_ringbuffer_size + - recv_ringbuffer_size)); + GFP_KERNEL|__GFP_ZERO, order); if (!page) - page = alloc_pages(GFP_KERNEL|__GFP_ZERO, - get_order(send_ringbuffer_size + - recv_ringbuffer_size)); + page = alloc_pages(GFP_KERNEL|__GFP_ZERO, order); if (!page) { err = -ENOMEM; goto error_set_chnstate; } - newchannel->ringbuffer_pages = page_address(page); + newchannel->ringbuffer_page = page; newchannel->ringbuffer_pagecount = (send_ringbuffer_size + recv_ringbuffer_size) >> PAGE_SHIFT; @@ -238,8 +237,7 @@ int vmbus_open(struct vmbus_channel *newchannel, u32 send_ringbuffer_size, error_free_pages: hv_ringbuffer_cleanup(&newchannel->outbound); hv_ringbuffer_cleanup(&newchannel->inbound); - __free_pages(page, - get_order(send_ringbuffer_size + recv_ringbuffer_size)); + __free_pages(page, order); error_set_chnstate: newchannel->state = CHANNEL_OPEN_STATE; return err; @@ -656,8 +654,8 @@ static int vmbus_close_internal(struct vmbus_channel *channel) hv_ringbuffer_cleanup(&channel->outbound); hv_ringbuffer_cleanup(&channel->inbound); - free_pages((unsigned long)channel->ringbuffer_pages, - get_order(channel->ringbuffer_pagecount * PAGE_SIZE)); + __free_pages(channel->ringbuffer_page, + get_order(channel->ringbuffer_pagecount << PAGE_SHIFT)); out: /* re-enable tasklet for use on re-open */ diff --git a/drivers/uio/uio_hv_generic.c b/drivers/uio/uio_hv_generic.c index 75094605dd02..3ebd6289d124 100644 --- a/drivers/uio/uio_hv_generic.c +++ b/drivers/uio/uio_hv_generic.c @@ -130,11 +130,12 @@ static int hv_uio_ring_mmap(struct file *filp, struct kobject *kobj, = container_of(kobj, struct vmbus_channel, kobj); struct hv_device *dev = channel->primary_channel->device_obj; u16 q_idx = channel->offermsg.offer.sub_channel_index; + void *ring_buffer = page_address(channel->ringbuffer_page); dev_dbg(&dev->device, "mmap channel %u pages %#lx at %#lx\n", q_idx, vma_pages(vma), vma->vm_pgoff); - return vm_iomap_memory(vma, virt_to_phys(channel->ringbuffer_pages), + return vm_iomap_memory(vma, virt_to_phys(ring_buffer), channel->ringbuffer_pagecount << PAGE_SHIFT); } @@ -224,7 +225,7 @@ hv_uio_probe(struct hv_device *dev, /* mem resources */ pdata->info.mem[TXRX_RING_MAP].name = "txrx_rings"; pdata->info.mem[TXRX_RING_MAP].addr - = (phys_addr_t)dev->channel->ringbuffer_pages; + = (uintptr_t)page_address(dev->channel->ringbuffer_page); pdata->info.mem[TXRX_RING_MAP].size = dev->channel->ringbuffer_pagecount << PAGE_SHIFT; pdata->info.mem[TXRX_RING_MAP].memtype = UIO_MEM_LOGICAL; diff --git a/include/linux/hyperv.h b/include/linux/hyperv.h index 5f11b715e075..307cd1c5d754 100644 --- a/include/linux/hyperv.h +++ b/include/linux/hyperv.h @@ -712,7 +712,7 @@ struct vmbus_channel { u32 ringbuffer_gpadlhandle; /* Allocated memory for ring buffer */ - void *ringbuffer_pages; + struct page *ringbuffer_page; u32 ringbuffer_pagecount; struct hv_ring_buffer_info outbound; /* send to parent */ struct hv_ring_buffer_info inbound; /* receive from parent */ From patchwork Fri Jun 7 19:38:42 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: 1112223 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 45LCXB3kYbz9sBp; Sat, 8 Jun 2019 05:39:22 +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 1hZKhp-0007Di-RB; Fri, 07 Jun 2019 19:39:17 +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 1hZKhl-00079H-Sd for kernel-team@lists.ubuntu.com; Fri, 07 Jun 2019 19:39:13 +0000 Received: from mail-qt1-f197.google.com ([209.85.160.197]) by youngberry.canonical.com with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.76) (envelope-from ) id 1hZKhk-00071X-Bp for kernel-team@lists.ubuntu.com; Fri, 07 Jun 2019 19:39:12 +0000 Received: by mail-qt1-f197.google.com with SMTP id 97so2737150qtb.16 for ; Fri, 07 Jun 2019 12:39:12 -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=kLLelfHGrBgvNiKw3MAy7PUDtPNwN09iWDm7TKN5ZPM=; b=ILXm8ea4lMznCIau9kjZBWbJIoR4fBj0nd89hWk8TTNymzE6fmal6WiXOiAIP0uJv1 hWsWbgP0e29i7U1yCheOtsupjnXQqH/rDiWUOhjXeQBPeK45+LxCEK4vQn+DT2oO5kmQ FQwp1o8jzjI3YZfUM6fXxZBZ99T0jpAsvUMgDJDJWmzX3j7kF7pEllvu0c4FzABLjbbw dz3wdjZk9iDcF+Mn0UbB0QX+dlcuYAcrpJRjH2uaucrsTEhDLzKGLQ1KSfYqWWeV3k/o GWtb8HRgdEDp8sIP3IErUjZBm3ilNoe14dIOPMfuOKRu67RDQj785Dxiu77/OnEYC+Ou s7Fg== X-Gm-Message-State: APjAAAVhj6wdYIFiwo7Ayelne766V1akZLVZVG77yr1A8ntaFVvnz3py zcROpAzxfF4qq9pE9MogLyiX1NDyzDiiScRlrVI4Msd6kc7FYU1l2VKwqzJRkEjno5X3rFCXIlD Ofo9p21oUh+JJxPK2mf9PcSktvK2u69H6NuXi2vWT X-Received: by 2002:ac8:34f4:: with SMTP id x49mr41281793qtb.95.1559936351117; Fri, 07 Jun 2019 12:39:11 -0700 (PDT) X-Google-Smtp-Source: APXvYqyTEEhFMtMqxm2nGdAkBBxWk3P3iSPhF0/IR2OPYK3++0d+4zb9yh3RPlSbFPjf0ybZJLaC5Q== X-Received: by 2002:ac8:34f4:: with SMTP id x49mr41281772qtb.95.1559936350797; Fri, 07 Jun 2019 12:39:10 -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.09 for (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Fri, 07 Jun 2019 12:39:10 -0700 (PDT) From: Marcelo Henrique Cerri To: kernel-team@lists.ubuntu.com Subject: [x/azure][PATCH 08/17] uio: introduce UIO_MEM_IOVA Date: Fri, 7 Jun 2019 16:38:42 -0300 Message-Id: <20190607193851.21914-9-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 Introduce the concept of mapping physical memory locations that are normal memory. The new type UIO_MEM_IOVA are similar to existing UIO_MEM_PHYS but the backing memory is not marked as uncached. Also, indent related switch to the currently used style. Signed-off-by: Stephen Hemminger Signed-off-by: Greg Kroah-Hartman (backported from commit bfddabfa230452cea32aae82f9cd85ab22601acf) [marcelo.cerri@canonical.com: fixed context in uio_mmap()] Signed-off-by: Marcelo Henrique Cerri --- drivers/uio/uio.c | 18 ++++++++++-------- include/linux/uio_driver.h | 1 + 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c index ff04b7f8549f..ff695bdee0a7 100644 --- a/drivers/uio/uio.c +++ b/drivers/uio/uio.c @@ -656,7 +656,8 @@ static int uio_mmap_physical(struct vm_area_struct *vma) return -EINVAL; vma->vm_ops = &uio_physical_vm_ops; - vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot); + if (idev->info->mem[mi].memtype == UIO_MEM_PHYS) + vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot); /* * We cannot use the vm_iomap_memory() helper here, @@ -703,13 +704,14 @@ static int uio_mmap(struct file *filep, struct vm_area_struct *vma) } switch (idev->info->mem[mi].memtype) { - case UIO_MEM_PHYS: - return uio_mmap_physical(vma); - case UIO_MEM_LOGICAL: - case UIO_MEM_VIRTUAL: - return uio_mmap_logical(vma); - default: - return -EINVAL; + case UIO_MEM_IOVA: + case UIO_MEM_PHYS: + return uio_mmap_physical(vma); + case UIO_MEM_LOGICAL: + case UIO_MEM_VIRTUAL: + return uio_mmap_logical(vma); + default: + return -EINVAL; } } diff --git a/include/linux/uio_driver.h b/include/linux/uio_driver.h index 3c85c81b0027..afa0bed36650 100644 --- a/include/linux/uio_driver.h +++ b/include/linux/uio_driver.h @@ -131,6 +131,7 @@ extern void uio_event_notify(struct uio_info *info); #define UIO_MEM_PHYS 1 #define UIO_MEM_LOGICAL 2 #define UIO_MEM_VIRTUAL 3 +#define UIO_MEM_IOVA 4 /* defines for uio_port->porttype */ #define UIO_PORT_NONE 0 From patchwork Fri Jun 7 19:38:43 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: 1112224 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 45LCXD53Zcz9s6w; Sat, 8 Jun 2019 05:39:24 +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 1hZKhr-0007FA-Ck; Fri, 07 Jun 2019 19:39:19 +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 1hZKhn-0007Av-If for kernel-team@lists.ubuntu.com; Fri, 07 Jun 2019 19:39:15 +0000 Received: from mail-qt1-f200.google.com ([209.85.160.200]) by youngberry.canonical.com with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.76) (envelope-from ) id 1hZKhm-00071e-8a for kernel-team@lists.ubuntu.com; Fri, 07 Jun 2019 19:39:14 +0000 Received: by mail-qt1-f200.google.com with SMTP id o16so2760198qtj.6 for ; Fri, 07 Jun 2019 12:39:14 -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=k9jb1QpQ/DZVMnidtyma/fMbF+5+hOW2YjypjV4/+uw=; b=HJM+ex65ZWxK6jCD1NZL+KKA7DHjWA0M9E/ZLtgdJoB2KuQd/58LbA5eymCzY2LDoS GaN+aN+M05xPF3/cUzMW3k91wuiPHcHwR+daTGdvf6DjWlsC48N2ZVWlNnjlMfiFOTPm FYA5EwDpDSQrvrrlzulxjRp5udwRulIRxvyuqySYZqyjqDBC0d/kePAlhrxmQTN46dDv N8oK+giI2GDE6QbHElONOfHPDGKWYx/F8LcroCYVPFYcsRVdc2uvgRAv1rytwKqawsPl v7bcH9uiZfqI9nxMl1h8SiesMNIQ03CFo8x7kW2o5whpWOqzgMUr0SxzGqYhkqYkt4qJ dzXw== X-Gm-Message-State: APjAAAUVdwcHZMk47+HaKhZhyDMt3Y0ANxfHAddWgCjzlL0b42xyjO9x V5eAvuCFFly40zlK2h1Nta6+HnOQ5HmMaBWGXeDy9j8LtolO/FIMgwA+UmWEBvtKObMQK49tjoY B/SJZfx4I89hXp+KvxJz4/P9QsJaWe464hXd5i4eq X-Received: by 2002:ac8:381d:: with SMTP id q29mr47418487qtb.347.1559936352988; Fri, 07 Jun 2019 12:39:12 -0700 (PDT) X-Google-Smtp-Source: APXvYqxr4z+L8b9kJ4fNs8jk3WW9rOIaz7jLZokpel+Niv2KoG+7wastOZLo1FJazyOnpL8CFjyBRA== X-Received: by 2002:ac8:381d:: with SMTP id q29mr47418474qtb.347.1559936352724; Fri, 07 Jun 2019 12:39:12 -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.11 for (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Fri, 07 Jun 2019 12:39:12 -0700 (PDT) From: Marcelo Henrique Cerri To: kernel-team@lists.ubuntu.com Subject: [x/azure][PATCH 09/17] hv_uio_generic: map ringbuffer phys addr Date: Fri, 7 Jun 2019 16:38:43 -0300 Message-Id: <20190607193851.21914-10-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 ring buffer is contiguous IOVA and is mapped via phys addr for sysfs file. Use same method for the UIO mapping. Signed-off-by: Stephen Hemminger Signed-off-by: Greg Kroah-Hartman (cherry picked from commit 9da197f1df40c838f0f06abf94cd23b4ed81e522) Signed-off-by: Marcelo Henrique Cerri --- drivers/uio/uio_hv_generic.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/uio/uio_hv_generic.c b/drivers/uio/uio_hv_generic.c index 3ebd6289d124..3a29e0ce35bc 100644 --- a/drivers/uio/uio_hv_generic.c +++ b/drivers/uio/uio_hv_generic.c @@ -225,10 +225,10 @@ hv_uio_probe(struct hv_device *dev, /* mem resources */ pdata->info.mem[TXRX_RING_MAP].name = "txrx_rings"; pdata->info.mem[TXRX_RING_MAP].addr - = (uintptr_t)page_address(dev->channel->ringbuffer_page); + = (uintptr_t)virt_to_phys(page_address(dev->channel->ringbuffer_page)); pdata->info.mem[TXRX_RING_MAP].size = dev->channel->ringbuffer_pagecount << PAGE_SHIFT; - pdata->info.mem[TXRX_RING_MAP].memtype = UIO_MEM_LOGICAL; + pdata->info.mem[TXRX_RING_MAP].memtype = UIO_MEM_IOVA; pdata->info.mem[INT_PAGE_MAP].name = "int_page"; pdata->info.mem[INT_PAGE_MAP].addr From patchwork Fri Jun 7 19:38:44 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: 1112225 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 45LCXJ280Nz9sBp; Sat, 8 Jun 2019 05:39:28 +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 1hZKhu-0007Hv-SB; Fri, 07 Jun 2019 19:39:22 +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 1hZKho-0007CQ-JA for kernel-team@lists.ubuntu.com; Fri, 07 Jun 2019 19:39:16 +0000 Received: from mail-qt1-f200.google.com ([209.85.160.200]) by youngberry.canonical.com with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.76) (envelope-from ) id 1hZKho-00071n-1R for kernel-team@lists.ubuntu.com; Fri, 07 Jun 2019 19:39:16 +0000 Received: by mail-qt1-f200.google.com with SMTP id z8so2774187qti.1 for ; Fri, 07 Jun 2019 12:39:16 -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=3Scm9KlWy+LEXp9cyqU7DwhNLj9yakAZLVGEpzvxCXc=; b=e9dXkQj0o5sOpHCw7rCF/4vD7sGCBgiSRo6RcW1SVXMmWUphmdW67Cux/Lm8bw80Ci GFAk53xScYIw0ZeztDUjmY1j1g+cFRtisHtZZt69fw0SVoITGSm73CqHoiroO/2II7cz xw6bOX/G/vqfZUeUvFsyM3si7PYncnvpJONax7fTJtuNR7txFCbAQLs/5FNUpyARdWSt D/fhuavu8e8Du/GdzUGzLPOLIhPs+6dD9aqiM+abMfnTLa9FvAYCM7X4yq2k7enbCj9E 9rwfHORPbchXIcPmkIAb5JoglikkDfKW8kUDZPG5ybP/b/G8CiHRCu0QVsmPm1W+9DtJ dNPA== X-Gm-Message-State: APjAAAXDzJIHZ0ugdZYFCwXfijfr1oM9p3kH9Y8sAjVn97EvhxoSH6g4 Iayg2mu21uiHQ9LiDO+8bBrDu1vDC2zQaOjDmB2yp0wdYrvZ4kkG9YmQ3WWf3yj/mIKd7qhaNDS 7hcR0RLNoSPINaTfKgbdQkKyD+iV8sLa7Dpt727vD X-Received: by 2002:a37:dcc4:: with SMTP id v187mr45620089qki.290.1559936354852; Fri, 07 Jun 2019 12:39:14 -0700 (PDT) X-Google-Smtp-Source: APXvYqxpOi+n+4A/oauZw2YnmTAi6V137JYzBvlGhbMHBiLBlUtk1bbE05roFcOvdj3p5+5Bu126Mw== X-Received: by 2002:a37:dcc4:: with SMTP id v187mr45620061qki.290.1559936354581; Fri, 07 Jun 2019 12:39:14 -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.12 for (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Fri, 07 Jun 2019 12:39:13 -0700 (PDT) From: Marcelo Henrique Cerri To: kernel-team@lists.ubuntu.com Subject: [x/azure][PATCH 10/17] uio_hv_generic: use ISR callback method Date: Fri, 7 Jun 2019 16:38:44 -0300 Message-Id: <20190607193851.21914-11-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 UIO IRQ handler doesn't need to be called from a tasklet. Signed-off-by: Stephen Hemminger Signed-off-by: Greg Kroah-Hartman (cherry picked from commit 2141a8457f16bac72ef4b4c38885612d1f2232cb) Signed-off-by: Marcelo Henrique Cerri --- drivers/uio/uio_hv_generic.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/uio/uio_hv_generic.c b/drivers/uio/uio_hv_generic.c index 3a29e0ce35bc..50656530528d 100644 --- a/drivers/uio/uio_hv_generic.c +++ b/drivers/uio/uio_hv_generic.c @@ -214,7 +214,7 @@ hv_uio_probe(struct hv_device *dev, } dev->channel->inbound.ring_buffer->interrupt_mask = 1; - set_channel_read_mode(dev->channel, HV_CALL_DIRECT); + set_channel_read_mode(dev->channel, HV_CALL_ISR); /* Fill general uio info */ pdata->info.name = "uio_hv_generic"; From patchwork Fri Jun 7 19:38:45 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: 1112226 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 45LCXK5bqnz9sBp; Sat, 8 Jun 2019 05:39:29 +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 1hZKhw-0007J5-5u; Fri, 07 Jun 2019 19:39:24 +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 1hZKhr-0007ED-6Q for kernel-team@lists.ubuntu.com; Fri, 07 Jun 2019 19:39:19 +0000 Received: from mail-qk1-f199.google.com ([209.85.222.199]) by youngberry.canonical.com with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.76) (envelope-from ) id 1hZKhp-00071t-TU for kernel-team@lists.ubuntu.com; Fri, 07 Jun 2019 19:39:18 +0000 Received: by mail-qk1-f199.google.com with SMTP id i4so2454231qkk.22 for ; Fri, 07 Jun 2019 12:39:17 -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=MhGAc+5rtXdAm6vUc9lI+NmcFjCfUfxs2kTDC/PEjpE=; b=RHcWyzqxqHKud/QE9w1Jk9mfZueB2C8Vf3wrv/mW9Xq0xauycJK8ifffhpGcPOcWGw 8C2IE5sXE1eWelnhw6ah1rJrosqf218/vDD4AsFGiGglYSb2g7BM3p0nKLRsPDfxPERs hfsLSo6MgJgwd1Ha8KKsaowRMULnGngaiQZfL/Cm/YsZRx2mUUpSk/9lSGSjpho4Wl0r V+TDQphGMgvE4g6q+E1e0IdJM6L01NwQlPjdmyDTmTCa2IT7ScVQsdj/Bsb+fXNs98MF n8h0Fw4TNePU40gV1lBTBw2WKRBckGeloPrdGOC+xgMiZVOlkwQgPQfUMEr/X52/6hC/ dxGw== X-Gm-Message-State: APjAAAV9G6Wh/EtPsgmPbh7OHDFyFEICCCKHhRbAhk2kw2H/++AfXUE0 2TBa+F3hbqw2e1qVIyU3vbZG9KaWpzpros/XBshBCbfQA9Dr5n/glzZkA7RH7AW58TK/2mVd/VV 9Jb1e1e8g3K42PQp+ewIhchxK0WtLKMvRuxTM+llY X-Received: by 2002:a05:620a:16c1:: with SMTP id a1mr2666494qkn.269.1559936356691; Fri, 07 Jun 2019 12:39:16 -0700 (PDT) X-Google-Smtp-Source: APXvYqyzGqQ16yNgqCeqQ4KRDAZmuqQdoJ4vdfUn0MSaPV+2ddWrjvM08IE7rBXiZqLoejgCmAfkag== X-Received: by 2002:a05:620a:16c1:: with SMTP id a1mr2666480qkn.269.1559936356406; Fri, 07 Jun 2019 12:39:16 -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.14 for (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Fri, 07 Jun 2019 12:39:15 -0700 (PDT) From: Marcelo Henrique Cerri To: kernel-team@lists.ubuntu.com Subject: [x/azure][PATCH 11/17] uio_hv_generic: use correct channel in isr Date: Fri, 7 Jun 2019 16:38:45 -0300 Message-Id: <20190607193851.21914-12-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 Need to mask the correct sub-channel in the callback from VMBUS isr. Otherwise, can get in to infinite interrupt storm. Fixes: 37b96a4931db ("uio_hv_generic: support sub-channels") Signed-off-by: Stephen Hemminger Signed-off-by: Greg Kroah-Hartman (cherry picked from commit 135db384a2efde3718fd551e3968e97fcb400c84) Signed-off-by: Marcelo Henrique Cerri --- drivers/uio/uio_hv_generic.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/drivers/uio/uio_hv_generic.c b/drivers/uio/uio_hv_generic.c index 50656530528d..ab7a60fc02e7 100644 --- a/drivers/uio/uio_hv_generic.c +++ b/drivers/uio/uio_hv_generic.c @@ -92,10 +92,11 @@ hv_uio_irqcontrol(struct uio_info *info, s32 irq_state) */ static void hv_uio_channel_cb(void *context) { - struct hv_uio_private_data *pdata = context; - struct hv_device *dev = pdata->device; + struct vmbus_channel *chan = context; + struct hv_device *hv_dev = chan->device_obj; + struct hv_uio_private_data *pdata = hv_get_drvdata(hv_dev); - dev->channel->inbound.ring_buffer->interrupt_mask = 1; + chan->inbound.ring_buffer->interrupt_mask = 1; virt_mb(); uio_event_notify(&pdata->info); @@ -148,19 +149,18 @@ static struct bin_attribute ring_buffer_bin_attr __ro_after_init = { .mmap = hv_uio_ring_mmap, }; -/* Callback from VMBUS subystem when new channel created. */ +/* Callback from VMBUS subsystem when new channel created. */ static void hv_uio_new_channel(struct vmbus_channel *new_sc) { struct hv_device *hv_dev = new_sc->primary_channel->device_obj; struct device *device = &hv_dev->device; - struct hv_uio_private_data *pdata = hv_get_drvdata(hv_dev); const size_t ring_bytes = HV_RING_SIZE * PAGE_SIZE; int ret; /* Create host communication ring */ ret = vmbus_open(new_sc, ring_bytes, ring_bytes, NULL, 0, - hv_uio_channel_cb, pdata); + hv_uio_channel_cb, new_sc); if (ret) { dev_err(device, "vmbus_open subchannel failed: %d\n", ret); return; @@ -202,7 +202,7 @@ hv_uio_probe(struct hv_device *dev, ret = vmbus_open(dev->channel, HV_RING_SIZE * PAGE_SIZE, HV_RING_SIZE * PAGE_SIZE, NULL, 0, - hv_uio_channel_cb, pdata); + hv_uio_channel_cb, dev->channel); if (ret) goto fail; From patchwork Fri Jun 7 19:38:46 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: 1112227 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 45LCXP0yymz9s4Y; Sat, 8 Jun 2019 05:39:33 +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 1hZKhy-0007LB-Dj; Fri, 07 Jun 2019 19:39:26 +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 1hZKht-0007GI-Jr for kernel-team@lists.ubuntu.com; Fri, 07 Jun 2019 19:39:21 +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 1hZKhs-000720-50 for kernel-team@lists.ubuntu.com; Fri, 07 Jun 2019 19:39:20 +0000 Received: by mail-qk1-f198.google.com with SMTP id u129so2472602qkd.12 for ; Fri, 07 Jun 2019 12:39:20 -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=IaTKyB7xxKJf3ZJVHN/5/Ar0Uf5KEvqMMBqW0cwNoSg=; b=pDVe28wA62Y44KW0gbQkyQTky18Wyvzuixfp0tMndZFEgPL+c8VwtAwXMV6ZslvlAh FTq8VXZtdrZXvN1U69/3ljPoKXIGOEd+yZhutfWL4Uawc2Z8xU4tYsox6jciqDuduLSV rCDPkqB9QVj5sAQvnxU3ZftEe6JsrMN8qeWL8x0maM9m0a7K8jF9LhpNYEN+ubQCZHtQ gBmrRV7KVgwtEIvQZfUSyxICQzxq6GW6e8laYZQj5BX+3+AMGsq8qMpe0YpYoapN2aMg GjQh8ErJgjjSLo94XvkBJDWAN2n/dYAvfoNvEI5edE55YhDEyF7BhcE8YKcidKJdVQHx Zugw== X-Gm-Message-State: APjAAAUC0DdX5fhKdn+T8olsOrFcNbkl2K3ABNgsNKKf+Fzx8NmsBJST peV4JF6yMZEbDvBDHMH+kf6f4jfyNNyozzWlpiZcUj1sadkY6uCjys+WB/cYri1juJB6DjA+pgg +Vxwx/gLlK4E0WeerCk9MWcmnFCA6QEQLPNay0+rE X-Received: by 2002:a37:8c45:: with SMTP id o66mr20840015qkd.317.1559936358579; Fri, 07 Jun 2019 12:39:18 -0700 (PDT) X-Google-Smtp-Source: APXvYqwB6KJL0837lh3QTLWJ4H9Tk2pvo/CwRciCwXt+z3M8jXa7B06jKxSadfqzLmYyFGTz//QZuQ== X-Received: by 2002:a37:8c45:: with SMTP id o66mr20840003qkd.317.1559936358281; Fri, 07 Jun 2019 12:39:18 -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.16 for (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Fri, 07 Jun 2019 12:39:17 -0700 (PDT) From: Marcelo Henrique Cerri To: kernel-team@lists.ubuntu.com Subject: [x/azure][PATCH 12/17] uio_hv_generic: make ring buffer attribute for primary channel Date: Fri, 7 Jun 2019 16:38:46 -0300 Message-Id: <20190607193851.21914-13-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 primary channel also needs a ring buffer attribute. This allows application to check if kernel supports uio sub channels, and also makes all channels use consistent API. Fixes: 37b96a4931db ("uio_hv_generic: support sub-channels") Signed-off-by: Stephen Hemminger Signed-off-by: Greg Kroah-Hartman (cherry picked from commit 9ab877a6ccf820483d79602bede0c1aa1da4d26a) Signed-off-by: Marcelo Henrique Cerri --- drivers/uio/uio_hv_generic.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/uio/uio_hv_generic.c b/drivers/uio/uio_hv_generic.c index ab7a60fc02e7..73ed0f201764 100644 --- a/drivers/uio/uio_hv_generic.c +++ b/drivers/uio/uio_hv_generic.c @@ -294,6 +294,11 @@ hv_uio_probe(struct hv_device *dev, vmbus_set_chn_rescind_callback(dev->channel, hv_uio_rescind); vmbus_set_sc_create_callback(dev->channel, hv_uio_new_channel); + ret = sysfs_create_bin_file(&dev->channel->kobj, &ring_buffer_bin_attr); + if (ret) + dev_notice(&dev->device, + "sysfs create ring bin file failed; %d\n", ret); + hv_set_drvdata(dev, pdata); return 0; From patchwork Fri Jun 7 19:38:47 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: 1112229 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 45LCXS58ztz9s4Y; Sat, 8 Jun 2019 05:39:36 +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 1hZKi3-0007Ox-1L; Fri, 07 Jun 2019 19:39:31 +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 1hZKhv-0007Hp-US for kernel-team@lists.ubuntu.com; Fri, 07 Jun 2019 19:39:23 +0000 Received: from mail-qt1-f200.google.com ([209.85.160.200]) by youngberry.canonical.com with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.76) (envelope-from ) id 1hZKht-00072G-UU for kernel-team@lists.ubuntu.com; Fri, 07 Jun 2019 19:39:22 +0000 Received: by mail-qt1-f200.google.com with SMTP id c48so2734714qta.19 for ; Fri, 07 Jun 2019 12:39:21 -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=qvH2n6ud/SllpkYVMJpes8OHfabiJUM8Y8yDTwOlmK4=; b=dQfVcX+ayOmWmI7pm1CihbtkMYRxEMknrqH+P62l6J9ybtN5GgDRyziCU1Pc0+VIFf S6n1Oz1Jxqcv6MWnPR2MvPnGeCk8+V1B2CEVczwJE5r6BobZ5OWRGWuuiCjcnQsnCaAr FemD1I3HMMkDY2WHhYWSQiVULkJnmp+HNLIME7y5wKlGgh+VrMBuzTV8dwlpfLqzIFX3 NsiB+lMShheQCuVRgGe31eq9epEE7kzxRMjehWqaOvjb/68Q09b/3eptvThEQoY4R2qJ glBayx8MCOqxxcDKkSmDcf4a/8RZqUgxNIcJ8hTwpmCeYnvSCUxGEmib0eG1cFmTRGwk 06uQ== X-Gm-Message-State: APjAAAXI/ioEsyx7pHP+IG9FJ1PUKFFOIZqAbd+L44EU0IG1ageGC8Bb KqOipy+2bMgchJN8klLLQmGSH2+KUVthYYlPedUe3xtitoWvF0vcR6ZLWyNr4g4CvlKTsXxeZ6N DeStNLXl3SjWbX2MAj4u91XyMuhRFf9ItMkvSacNM X-Received: by 2002:ac8:28bc:: with SMTP id i57mr16589756qti.288.1559936360690; Fri, 07 Jun 2019 12:39:20 -0700 (PDT) X-Google-Smtp-Source: APXvYqzHEOrY+TBVwHcO7eYEcX7It7I/lmfVPhTzLH2pY84HbyMtet6PPqE/ZPOwlKhFmo//53Y0Mw== X-Received: by 2002:ac8:28bc:: with SMTP id i57mr16589739qti.288.1559936360386; Fri, 07 Jun 2019 12:39:20 -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.18 for (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Fri, 07 Jun 2019 12:39:19 -0700 (PDT) From: Marcelo Henrique Cerri To: kernel-team@lists.ubuntu.com Subject: [x/azure][PATCH 13/17] uio_hv_generic: defer opening vmbus until first use Date: Fri, 7 Jun 2019 16:38:47 -0300 Message-Id: <20190607193851.21914-14-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 This fixes two design flaws in hv_uio_generic. Since hv_uio_probe is called from vmbus_probe with lock held it potentially can cause sleep in an atomic section because vmbus_open will wait for response from host. The hv_uio_generic driver could not handle applications exiting and restarting because the vmbus channel was persistent. Change the semantics so that the buffers are allocated on probe, but not attached to host until device is opened. Signed-off-by: Stephen Hemminger Signed-off-by: Greg Kroah-Hartman (cherry picked from commit cdfa835c6e5e87d145f9f632b58843de97509f2b) Signed-off-by: Marcelo Henrique Cerri --- drivers/uio/uio_hv_generic.c | 104 +++++++++++++++++++++++++---------- 1 file changed, 74 insertions(+), 30 deletions(-) diff --git a/drivers/uio/uio_hv_generic.c b/drivers/uio/uio_hv_generic.c index 73ed0f201764..c9b43163587a 100644 --- a/drivers/uio/uio_hv_generic.c +++ b/drivers/uio/uio_hv_generic.c @@ -56,6 +56,7 @@ enum hv_uio_map { struct hv_uio_private_data { struct uio_info info; struct hv_device *device; + atomic_t refcnt; void *recv_buf; u32 recv_gpadl; @@ -129,12 +130,10 @@ static int hv_uio_ring_mmap(struct file *filp, struct kobject *kobj, { struct vmbus_channel *channel = container_of(kobj, struct vmbus_channel, kobj); - struct hv_device *dev = channel->primary_channel->device_obj; - u16 q_idx = channel->offermsg.offer.sub_channel_index; void *ring_buffer = page_address(channel->ringbuffer_page); - dev_dbg(&dev->device, "mmap channel %u pages %#lx at %#lx\n", - q_idx, vma_pages(vma), vma->vm_pgoff); + if (channel->state != CHANNEL_OPENED_STATE) + return -ENODEV; return vm_iomap_memory(vma, virt_to_phys(ring_buffer), channel->ringbuffer_pagecount << PAGE_SHIFT); @@ -177,57 +176,103 @@ hv_uio_new_channel(struct vmbus_channel *new_sc) } } +/* free the reserved buffers for send and receive */ static void hv_uio_cleanup(struct hv_device *dev, struct hv_uio_private_data *pdata) { - if (pdata->send_gpadl) + if (pdata->send_gpadl) { vmbus_teardown_gpadl(dev->channel, pdata->send_gpadl); - vfree(pdata->send_buf); + pdata->send_gpadl = 0; + vfree(pdata->send_buf); + } - if (pdata->recv_gpadl) + if (pdata->recv_gpadl) { vmbus_teardown_gpadl(dev->channel, pdata->recv_gpadl); - vfree(pdata->recv_buf); + pdata->recv_gpadl = 0; + vfree(pdata->recv_buf); + } +} + +/* VMBus primary channel is opened on first use */ +static int +hv_uio_open(struct uio_info *info, struct inode *inode) +{ + struct hv_uio_private_data *pdata + = container_of(info, struct hv_uio_private_data, info); + struct hv_device *dev = pdata->device; + int ret; + + if (atomic_inc_return(&pdata->refcnt) != 1) + return 0; + + ret = vmbus_connect_ring(dev->channel, + hv_uio_channel_cb, dev->channel); + + if (ret == 0) + dev->channel->inbound.ring_buffer->interrupt_mask = 1; + else + atomic_dec(&pdata->refcnt); + + return ret; +} + +/* VMBus primary channel is closed on last close */ +static int +hv_uio_release(struct uio_info *info, struct inode *inode) +{ + struct hv_uio_private_data *pdata + = container_of(info, struct hv_uio_private_data, info); + struct hv_device *dev = pdata->device; + int ret = 0; + + if (atomic_dec_and_test(&pdata->refcnt)) + ret = vmbus_disconnect_ring(dev->channel); + + return ret; } static int hv_uio_probe(struct hv_device *dev, const struct hv_vmbus_device_id *dev_id) { + struct vmbus_channel *channel = dev->channel; struct hv_uio_private_data *pdata; + void *ring_buffer; int ret; + /* Communicating with host has to be via shared memory not hypercall */ + if (!channel->offermsg.monitor_allocated) { + dev_err(&dev->device, "vmbus channel requires hypercall\n"); + return -ENOTSUPP; + } + pdata = kzalloc(sizeof(*pdata), GFP_KERNEL); if (!pdata) return -ENOMEM; - ret = vmbus_open(dev->channel, HV_RING_SIZE * PAGE_SIZE, - HV_RING_SIZE * PAGE_SIZE, NULL, 0, - hv_uio_channel_cb, dev->channel); + ret = vmbus_alloc_ring(channel, HV_RING_SIZE * PAGE_SIZE, + HV_RING_SIZE * PAGE_SIZE); if (ret) goto fail; - /* Communicating with host has to be via shared memory not hypercall */ - if (!dev->channel->offermsg.monitor_allocated) { - dev_err(&dev->device, "vmbus channel requires hypercall\n"); - ret = -ENOTSUPP; - goto fail_close; - } - - dev->channel->inbound.ring_buffer->interrupt_mask = 1; - set_channel_read_mode(dev->channel, HV_CALL_ISR); + set_channel_read_mode(channel, HV_CALL_ISR); /* Fill general uio info */ pdata->info.name = "uio_hv_generic"; pdata->info.version = DRIVER_VERSION; pdata->info.irqcontrol = hv_uio_irqcontrol; + pdata->info.open = hv_uio_open; + pdata->info.release = hv_uio_release; pdata->info.irq = UIO_IRQ_CUSTOM; + atomic_set(&pdata->refcnt, 0); /* mem resources */ pdata->info.mem[TXRX_RING_MAP].name = "txrx_rings"; + ring_buffer = page_address(channel->ringbuffer_page); pdata->info.mem[TXRX_RING_MAP].addr - = (uintptr_t)virt_to_phys(page_address(dev->channel->ringbuffer_page)); + = (uintptr_t)virt_to_phys(ring_buffer); pdata->info.mem[TXRX_RING_MAP].size - = dev->channel->ringbuffer_pagecount << PAGE_SHIFT; + = channel->ringbuffer_pagecount << PAGE_SHIFT; pdata->info.mem[TXRX_RING_MAP].memtype = UIO_MEM_IOVA; pdata->info.mem[INT_PAGE_MAP].name = "int_page"; @@ -248,7 +293,7 @@ hv_uio_probe(struct hv_device *dev, goto fail_close; } - ret = vmbus_establish_gpadl(dev->channel, pdata->recv_buf, + ret = vmbus_establish_gpadl(channel, pdata->recv_buf, RECV_BUFFER_SIZE, &pdata->recv_gpadl); if (ret) goto fail_close; @@ -262,14 +307,13 @@ hv_uio_probe(struct hv_device *dev, pdata->info.mem[RECV_BUF_MAP].size = RECV_BUFFER_SIZE; pdata->info.mem[RECV_BUF_MAP].memtype = UIO_MEM_VIRTUAL; - pdata->send_buf = vzalloc(SEND_BUFFER_SIZE); if (pdata->send_buf == NULL) { ret = -ENOMEM; goto fail_close; } - ret = vmbus_establish_gpadl(dev->channel, pdata->send_buf, + ret = vmbus_establish_gpadl(channel, pdata->send_buf, SEND_BUFFER_SIZE, &pdata->send_gpadl); if (ret) goto fail_close; @@ -291,10 +335,10 @@ hv_uio_probe(struct hv_device *dev, goto fail_close; } - vmbus_set_chn_rescind_callback(dev->channel, hv_uio_rescind); - vmbus_set_sc_create_callback(dev->channel, hv_uio_new_channel); + vmbus_set_chn_rescind_callback(channel, hv_uio_rescind); + vmbus_set_sc_create_callback(channel, hv_uio_new_channel); - ret = sysfs_create_bin_file(&dev->channel->kobj, &ring_buffer_bin_attr); + ret = sysfs_create_bin_file(&channel->kobj, &ring_buffer_bin_attr); if (ret) dev_notice(&dev->device, "sysfs create ring bin file failed; %d\n", ret); @@ -305,7 +349,6 @@ hv_uio_probe(struct hv_device *dev, fail_close: hv_uio_cleanup(dev, pdata); - vmbus_close(dev->channel); fail: kfree(pdata); @@ -323,7 +366,8 @@ hv_uio_remove(struct hv_device *dev) uio_unregister_device(&pdata->info); hv_uio_cleanup(dev, pdata); hv_set_drvdata(dev, NULL); - vmbus_close(dev->channel); + + vmbus_free_ring(dev->channel); kfree(pdata); return 0; } From patchwork Fri Jun 7 19:38:48 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: 1112228 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 45LCXR20F4z9s6w; Sat, 8 Jun 2019 05:39:35 +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 1hZKi1-0007NZ-Ll; Fri, 07 Jun 2019 19:39:29 +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 1hZKhw-0007J1-Ib for kernel-team@lists.ubuntu.com; Fri, 07 Jun 2019 19:39:24 +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 1hZKhv-00072S-QM for kernel-team@lists.ubuntu.com; Fri, 07 Jun 2019 19:39:23 +0000 Received: by mail-qk1-f198.google.com with SMTP id o4so2476007qko.8 for ; Fri, 07 Jun 2019 12:39:23 -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=K5b4I5n0U4KJjwF7Ry7vtNW+7uCY54BIMupvf0zJy0g=; b=ehNTNOr8bCzDEBh4tOygGdftydgQTWXyHD+CFrYozlWcjo12vI5d59S4l2QPMYMVwD wqJdG768lruySSkhFn7m6J7FQXniAJE0biRUZaBjiOr44y95bTpev4lRUtm5rkGxGt8y kGMHRHd5XPXA/Agd7M3BOx2KFMcWKL7g9hwIkdcBDE5rPoqJkxR9wDWJp0JzwbK6e2eZ h7jQkIBITcIfqMjztGOAuRb1jRqNeu7NPHtW8oy5MSntxl/ff3m35Qco3KbzCSDCw3KC Z0wtqxaylzluB7mP0KiPo4HkjKXqYzhaEiQrXVOupRsLmUPB28IR5iz2rQyN+89q4P7A Y4Sw== X-Gm-Message-State: APjAAAVg7bERyeBz6mnXBD9hNPbO9i+5H+3aD+SocBKcUiQXpLcDrq4v QTenk3vp+/t0asjpirBtFx7Yvxh6G9qdCpUn77hpPCbLuv0dXhg0aGrtj/rJiAVgOpRAuWZJy94 0xTZHJfC1jpfde3C1QE+TJmxBXO31e7ro6O6SfEVi X-Received: by 2002:aed:21ca:: with SMTP id m10mr44261821qtc.97.1559936362601; Fri, 07 Jun 2019 12:39:22 -0700 (PDT) X-Google-Smtp-Source: APXvYqzMQ9GQ3iGCcU+YfdTpml7zbyYY03TT0g6SeSXKq1CJE1acGYfpo6bSXOELVZc9Hi4y1ExKSg== X-Received: by 2002:aed:21ca:: with SMTP id m10mr44261803qtc.97.1559936362334; Fri, 07 Jun 2019 12:39:22 -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.20 for (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Fri, 07 Jun 2019 12:39:21 -0700 (PDT) From: Marcelo Henrique Cerri To: kernel-team@lists.ubuntu.com Subject: [x/azure][PATCH 14/17] uio_hv_generic: set callbacks on open Date: Fri, 7 Jun 2019 16:38:48 -0300 Message-Id: <20190607193851.21914-15-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 This fixes the problem where uio application was unable to use multple queues on restart. The root cause is that the callbacks are cleared on disconnect. Change to setting up callbacks everytime in open. Fixes: cdfa835c6e5e ("uio_hv_generic: defer opening vmbus until first use") Reported-by: Mohammed Gamal Signed-off-by: Stephen Hemminger Signed-off-by: Greg Kroah-Hartman (cherry picked from commit 5e3c420dcca53766dec57d5bf4df8eecdb953c03) Signed-off-by: Marcelo Henrique Cerri --- drivers/uio/uio_hv_generic.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/drivers/uio/uio_hv_generic.c b/drivers/uio/uio_hv_generic.c index c9b43163587a..ad7a9eb82870 100644 --- a/drivers/uio/uio_hv_generic.c +++ b/drivers/uio/uio_hv_generic.c @@ -205,9 +205,11 @@ hv_uio_open(struct uio_info *info, struct inode *inode) if (atomic_inc_return(&pdata->refcnt) != 1) return 0; + vmbus_set_chn_rescind_callback(dev->channel, hv_uio_rescind); + vmbus_set_sc_create_callback(dev->channel, hv_uio_new_channel); + ret = vmbus_connect_ring(dev->channel, hv_uio_channel_cb, dev->channel); - if (ret == 0) dev->channel->inbound.ring_buffer->interrupt_mask = 1; else @@ -335,9 +337,6 @@ hv_uio_probe(struct hv_device *dev, goto fail_close; } - vmbus_set_chn_rescind_callback(channel, hv_uio_rescind); - vmbus_set_sc_create_callback(channel, hv_uio_new_channel); - ret = sysfs_create_bin_file(&channel->kobj, &ring_buffer_bin_attr); if (ret) dev_notice(&dev->device, From patchwork Fri Jun 7 19:38:49 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: 1112230 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 45LCXW1HY5z9s4Y; Sat, 8 Jun 2019 05:39:39 +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 1hZKi5-0007QZ-8h; Fri, 07 Jun 2019 19:39:33 +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 1hZKhz-0007LF-BT for kernel-team@lists.ubuntu.com; Fri, 07 Jun 2019 19:39:27 +0000 Received: from mail-qk1-f199.google.com ([209.85.222.199]) by youngberry.canonical.com with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.76) (envelope-from ) id 1hZKhx-00072i-SV for kernel-team@lists.ubuntu.com; Fri, 07 Jun 2019 19:39:26 +0000 Received: by mail-qk1-f199.google.com with SMTP id w184so2471236qka.15 for ; Fri, 07 Jun 2019 12:39:25 -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=W7Og8jCkrOrj6oywNe+7llJ7OP1MHNFh1OZ1mM1/0pA=; b=hf0kuiIT3lxeUPTmWrdv2ekhcfYNOJUGwIyhaNip6xM5USDA929jem1/cjd6zSrmZu c0Ug/0EgFv1n9PXRWRNbqY4xo6xdcAIwOvrYLhh9yT2Mbm7+CUwglsrMlrq9hz3NvZMg A89Sq9T6E++iqytK0BIkGWBxFOclREyJgyUN44CHaC4ah63S0oiTS42qhZxKNyeBi3ZJ QnYJ8VDBJS2Ic2EGkPZyn0vQ2cjH0ipI9miHqFJUr87dQWo5CqRdFPnGW7OGOQ+1N+s7 NxShZbiTYGtcqtUO5f9W1LQdIayhL07+w/03t2Ypda1m/pjsymLmQ6i8HYrwhwwer+eg /dZQ== X-Gm-Message-State: APjAAAVRyIwmSctrTgdCYeE8F9YbRSDMjJJGTIiPIjBfR/iqxRtuKX2J kNmRgRa1c571FnsaJ2Dek1r7anfQDSjifxlLZulnV+dUSG+1tO8IwP3aGS1wHV4zk7NdUnw7XgA SRzbM+xgN84ov2kzwovYcG1xJZqTWxfVEjznavwEA X-Received: by 2002:ac8:6b06:: with SMTP id w6mr44963727qts.80.1559936364624; Fri, 07 Jun 2019 12:39:24 -0700 (PDT) X-Google-Smtp-Source: APXvYqwpRZY1oXxtpvpBot84UcGAU8xsefQ2RtBPK1/0+cp+OE8t5pTfI09XDNQ8hnZCLnHW9a7RAw== X-Received: by 2002:ac8:6b06:: with SMTP id w6mr44963706qts.80.1559936364341; Fri, 07 Jun 2019 12:39:24 -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.22 for (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Fri, 07 Jun 2019 12:39:23 -0700 (PDT) From: Marcelo Henrique Cerri To: kernel-team@lists.ubuntu.com Subject: [x/azure][PATCH 15/17] vmbus: pass channel to hv_process_channel_removal Date: Fri, 7 Jun 2019 16:38:49 -0300 Message-Id: <20190607193851.21914-16-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 Rather than passing relid and then looking up the channel. Pass the channel directly, since caller already knows it. Signed-off-by: Stephen Hemminger Signed-off-by: Greg Kroah-Hartman (cherry picked from commit 800b932969c53c4044ff9f9fd1ee793a87fa8ef0) Signed-off-by: Marcelo Henrique Cerri --- drivers/hv/channel.c | 3 +-- drivers/hv/channel_mgmt.c | 17 +++++------------ drivers/hv/vmbus_drv.c | 3 +-- include/linux/hyperv.h | 2 +- 4 files changed, 8 insertions(+), 17 deletions(-) diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c index c94ded629518..0c4a943c4275 100644 --- a/drivers/hv/channel.c +++ b/drivers/hv/channel.c @@ -688,8 +688,7 @@ void vmbus_close(struct vmbus_channel *channel) wait_for_completion(&cur_channel->rescind_event); mutex_lock(&vmbus_connection.channel_mutex); vmbus_close_internal(cur_channel); - hv_process_channel_removal( - cur_channel->offermsg.child_relid); + hv_process_channel_removal(cur_channel); } else { mutex_lock(&vmbus_connection.channel_mutex); vmbus_close_internal(cur_channel); diff --git a/drivers/hv/channel_mgmt.c b/drivers/hv/channel_mgmt.c index b9bc1f3f2110..975d471f4d21 100644 --- a/drivers/hv/channel_mgmt.c +++ b/drivers/hv/channel_mgmt.c @@ -385,21 +385,14 @@ static void vmbus_release_relid(u32 relid) trace_vmbus_release_relid(&msg, ret); } -void hv_process_channel_removal(u32 relid) +void hv_process_channel_removal(struct vmbus_channel *channel) { + struct vmbus_channel *primary_channel; unsigned long flags; - struct vmbus_channel *primary_channel, *channel; BUG_ON(!mutex_is_locked(&vmbus_connection.channel_mutex)); - - /* - * Make sure channel is valid as we may have raced. - */ - channel = relid2channel(relid); - if (!channel) - return; - BUG_ON(!channel->rescind); + if (channel->target_cpu != get_cpu()) { put_cpu(); smp_call_function_single(channel->target_cpu, @@ -429,7 +422,7 @@ void hv_process_channel_removal(u32 relid) cpumask_clear_cpu(channel->target_cpu, &primary_channel->alloced_cpus_in_node); - vmbus_release_relid(relid); + vmbus_release_relid(channel->offermsg.child_relid); free_channel(channel); } @@ -1003,7 +996,7 @@ static void vmbus_onoffer_rescind(struct vmbus_channel_message_header *hdr) * The channel is currently not open; * it is safe for us to cleanup the channel. */ - hv_process_channel_removal(rescind->child_relid); + hv_process_channel_removal(channel); } else { complete(&channel->rescind_event); } diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c index f699d5777c78..1bdc8fc8bec8 100644 --- a/drivers/hv/vmbus_drv.c +++ b/drivers/hv/vmbus_drv.c @@ -819,10 +819,9 @@ static void vmbus_device_release(struct device *device) struct vmbus_channel *channel = hv_dev->channel; mutex_lock(&vmbus_connection.channel_mutex); - hv_process_channel_removal(channel->offermsg.child_relid); + hv_process_channel_removal(channel); mutex_unlock(&vmbus_connection.channel_mutex); kfree(hv_dev); - } /* The one and only one */ diff --git a/include/linux/hyperv.h b/include/linux/hyperv.h index 307cd1c5d754..c174b3bc7492 100644 --- a/include/linux/hyperv.h +++ b/include/linux/hyperv.h @@ -1421,7 +1421,7 @@ extern bool vmbus_prep_negotiate_resp(struct icmsg_hdr *icmsghdrp, u8 *buf, const int *srv_version, int srv_vercnt, int *nego_fw_version, int *nego_srv_version); -void hv_process_channel_removal(u32 relid); +void hv_process_channel_removal(struct vmbus_channel *channel); void vmbus_setevent(struct vmbus_channel *channel); /* From patchwork Fri Jun 7 19:38:50 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: 1112231 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 45LCXY3PvKz9sDB; Sat, 8 Jun 2019 05:39:41 +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 1hZKi7-0007SZ-Vf; Fri, 07 Jun 2019 19:39:35 +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 1hZKi1-0007N1-Sn for kernel-team@lists.ubuntu.com; Fri, 07 Jun 2019 19:39:29 +0000 Received: from mail-qk1-f199.google.com ([209.85.222.199]) by youngberry.canonical.com with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.76) (envelope-from ) id 1hZKi0-00072q-1m for kernel-team@lists.ubuntu.com; Fri, 07 Jun 2019 19:39:28 +0000 Received: by mail-qk1-f199.google.com with SMTP id s67so2487372qkc.6 for ; Fri, 07 Jun 2019 12:39:28 -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=a23UyNoHChj+gqmbm5w5i14Wbd9VgL5tbn2qhYpzXBw=; b=BZJ//uwjM84xL3wz6lwDcbYMcBAUyVb7z8JzBM9NtcON/T2civBgpxf1pDcVTruxw7 Y6HOOhuPgDM3mNK+oRiClphXfhStfGefYICBxftTyTdiV0Zc2SSnzEPeuyYMJrcN44xd v+Bmz3Rtv2jRWguO1imYbUqGKmOT/BUQytmNfSkDehGi6d8geSUu/6Y65QrOHkub84Yy DyHRydk0GjUG5zgraxuzh8WykRIiHsR7XOQnQJq+xQEX+xmRTHuray99yhVnSz+l7Qc4 dh0nJXlfQ7NE0BgmfhWIjjP3ID4TTcHfT2ME7192b9zASCq1cwuiMnqefL7npnvOxFs1 NBrA== X-Gm-Message-State: APjAAAULurBE+rAtb0llKXiL0awmqDghr+oT3DdQPjERCH/+rwkoSBxy HbU6dIII2d6x9EDCdtt/R4Cdsf5RNjjB/Ccnq6+nZ+yNsO/DX3fcixZNXmgHnly7eNbsIr8f/Ur v4uNpjPMvEwDNSRjSzE16BgyoejoJWhVE+MsY8YJN X-Received: by 2002:a05:620a:533:: with SMTP id h19mr45558043qkh.325.1559936366755; Fri, 07 Jun 2019 12:39:26 -0700 (PDT) X-Google-Smtp-Source: APXvYqxHA3v0wFYnjAqfWHEiDkQtHAodV7qBugqIv+2yEPUTRZJ7P+q6QsKqO7DZbZ+DQMoAaH5Xrw== X-Received: by 2002:a05:620a:533:: with SMTP id h19mr45558015qkh.325.1559936366409; Fri, 07 Jun 2019 12:39:26 -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.24 for (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Fri, 07 Jun 2019 12:39:25 -0700 (PDT) From: Marcelo Henrique Cerri To: kernel-team@lists.ubuntu.com Subject: [x/azure][PATCH 16/17] vmbus: split ring buffer allocation from open Date: Fri, 7 Jun 2019 16:38:50 -0300 Message-Id: <20190607193851.21914-17-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 UIO driver needs the ring buffer to be persistent(reused) across open/close. Split the allocation and setup of ring buffer out of vmbus_open. For normal usage vmbus_open/vmbus_close there are no changes; only impacts uio_hv_generic which needs to keep ring buffer memory and reuse when application restarts. Signed-off-by: Stephen Hemminger Signed-off-by: Greg Kroah-Hartman (backported from commit ae6935ed7d424ffa74d634da00767e7b03c98fd3) [marcelo.cerri@canonical.com: fixed context in vmbus_close_internal() and kept the tasklet] Signed-off-by: Marcelo Henrique Cerri --- drivers/hv/channel.c | 260 ++++++++++++++++++++++----------------- drivers/hv/ring_buffer.c | 1 + include/linux/hyperv.h | 9 ++ 3 files changed, 160 insertions(+), 110 deletions(-) diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c index 0c4a943c4275..1bbf048dd931 100644 --- a/drivers/hv/channel.c +++ b/drivers/hv/channel.c @@ -78,84 +78,96 @@ void vmbus_setevent(struct vmbus_channel *channel) } EXPORT_SYMBOL_GPL(vmbus_setevent); -/* - * vmbus_open - Open the specified channel. - */ -int vmbus_open(struct vmbus_channel *newchannel, u32 send_ringbuffer_size, - u32 recv_ringbuffer_size, void *userdata, u32 userdatalen, - void (*onchannelcallback)(void *context), void *context) +/* vmbus_free_ring - drop mapping of ring buffer */ +void vmbus_free_ring(struct vmbus_channel *channel) { - struct vmbus_channel_open_channel *open_msg; - struct vmbus_channel_msginfo *open_info = NULL; - unsigned long flags; - int ret, err = 0; - struct page *page; - unsigned int order; + hv_ringbuffer_cleanup(&channel->outbound); + hv_ringbuffer_cleanup(&channel->inbound); - if (send_ringbuffer_size % PAGE_SIZE || - recv_ringbuffer_size % PAGE_SIZE) - return -EINVAL; + if (channel->ringbuffer_page) { + __free_pages(channel->ringbuffer_page, + get_order(channel->ringbuffer_pagecount + << PAGE_SHIFT)); + channel->ringbuffer_page = NULL; + } +} +EXPORT_SYMBOL_GPL(vmbus_free_ring); - order = get_order(send_ringbuffer_size + recv_ringbuffer_size); +/* vmbus_alloc_ring - allocate and map pages for ring buffer */ +int vmbus_alloc_ring(struct vmbus_channel *newchannel, + u32 send_size, u32 recv_size) +{ + struct page *page; + int order; - spin_lock_irqsave(&newchannel->lock, flags); - if (newchannel->state == CHANNEL_OPEN_STATE) { - newchannel->state = CHANNEL_OPENING_STATE; - } else { - spin_unlock_irqrestore(&newchannel->lock, flags); + if (send_size % PAGE_SIZE || recv_size % PAGE_SIZE) return -EINVAL; - } - spin_unlock_irqrestore(&newchannel->lock, flags); - - newchannel->onchannel_callback = onchannelcallback; - newchannel->channel_callback_context = context; /* Allocate the ring buffer */ + order = get_order(send_size + recv_size); page = alloc_pages_node(cpu_to_node(newchannel->target_cpu), GFP_KERNEL|__GFP_ZERO, order); if (!page) page = alloc_pages(GFP_KERNEL|__GFP_ZERO, order); - if (!page) { - err = -ENOMEM; - goto error_set_chnstate; - } + if (!page) + return -ENOMEM; newchannel->ringbuffer_page = page; - newchannel->ringbuffer_pagecount = (send_ringbuffer_size + - recv_ringbuffer_size) >> PAGE_SHIFT; + newchannel->ringbuffer_pagecount = (send_size + recv_size) >> PAGE_SHIFT; + newchannel->ringbuffer_send_offset = send_size >> PAGE_SHIFT; - ret = hv_ringbuffer_init(&newchannel->outbound, page, - send_ringbuffer_size >> PAGE_SHIFT); + return 0; +} +EXPORT_SYMBOL_GPL(vmbus_alloc_ring); - if (ret != 0) { - err = ret; - goto error_free_pages; - } +static int __vmbus_open(struct vmbus_channel *newchannel, + void *userdata, u32 userdatalen, + void (*onchannelcallback)(void *context), void *context) +{ + struct vmbus_channel_open_channel *open_msg; + struct vmbus_channel_msginfo *open_info = NULL; + struct page *page = newchannel->ringbuffer_page; + u32 send_pages, recv_pages; + unsigned long flags; + int err; - ret = hv_ringbuffer_init(&newchannel->inbound, - &page[send_ringbuffer_size >> PAGE_SHIFT], - recv_ringbuffer_size >> PAGE_SHIFT); - if (ret != 0) { - err = ret; - goto error_free_pages; + if (userdatalen > MAX_USER_DEFINED_BYTES) + return -EINVAL; + + send_pages = newchannel->ringbuffer_send_offset; + recv_pages = newchannel->ringbuffer_pagecount - send_pages; + + spin_lock_irqsave(&newchannel->lock, flags); + if (newchannel->state != CHANNEL_OPEN_STATE) { + spin_unlock_irqrestore(&newchannel->lock, flags); + return -EINVAL; } + spin_unlock_irqrestore(&newchannel->lock, flags); + + newchannel->state = CHANNEL_OPENING_STATE; + newchannel->onchannel_callback = onchannelcallback; + newchannel->channel_callback_context = context; + err = hv_ringbuffer_init(&newchannel->outbound, page, send_pages); + if (err) + goto error_clean_ring; + + err = hv_ringbuffer_init(&newchannel->inbound, + &page[send_pages], recv_pages); + if (err) + goto error_clean_ring; /* Establish the gpadl for the ring buffer */ newchannel->ringbuffer_gpadlhandle = 0; - ret = vmbus_establish_gpadl(newchannel, - page_address(page), - send_ringbuffer_size + - recv_ringbuffer_size, + err = vmbus_establish_gpadl(newchannel, + page_address(newchannel->ringbuffer_page), + (send_pages + recv_pages) << PAGE_SHIFT, &newchannel->ringbuffer_gpadlhandle); - - if (ret != 0) { - err = ret; - goto error_free_pages; - } + if (err) + goto error_clean_ring; /* Create and init the channel open message */ open_info = kmalloc(sizeof(*open_info) + @@ -174,15 +186,9 @@ int vmbus_open(struct vmbus_channel *newchannel, u32 send_ringbuffer_size, open_msg->openid = newchannel->offermsg.child_relid; open_msg->child_relid = newchannel->offermsg.child_relid; open_msg->ringbuffer_gpadlhandle = newchannel->ringbuffer_gpadlhandle; - open_msg->downstream_ringbuffer_pageoffset = send_ringbuffer_size >> - PAGE_SHIFT; + open_msg->downstream_ringbuffer_pageoffset = newchannel->ringbuffer_send_offset; open_msg->target_vp = newchannel->target_vp; - if (userdatalen > MAX_USER_DEFINED_BYTES) { - err = -EINVAL; - goto error_free_gpadl; - } - if (userdatalen) memcpy(open_msg->userdata, userdata, userdatalen); @@ -193,18 +199,16 @@ int vmbus_open(struct vmbus_channel *newchannel, u32 send_ringbuffer_size, if (newchannel->rescind) { err = -ENODEV; - goto error_free_gpadl; + goto error_free_info; } - ret = vmbus_post_msg(open_msg, + err = vmbus_post_msg(open_msg, sizeof(struct vmbus_channel_open_channel), true); - trace_vmbus_open(open_msg, ret); + trace_vmbus_open(open_msg, err); - if (ret != 0) { - err = ret; + if (err != 0) goto error_clean_msglist; - } wait_for_completion(&open_info->waitevent); @@ -214,12 +218,12 @@ int vmbus_open(struct vmbus_channel *newchannel, u32 send_ringbuffer_size, if (newchannel->rescind) { err = -ENODEV; - goto error_free_gpadl; + goto error_free_info; } if (open_info->response.open_result.status) { err = -EAGAIN; - goto error_free_gpadl; + goto error_free_info; } newchannel->state = CHANNEL_OPENED_STATE; @@ -230,18 +234,50 @@ int vmbus_open(struct vmbus_channel *newchannel, u32 send_ringbuffer_size, spin_lock_irqsave(&vmbus_connection.channelmsg_lock, flags); list_del(&open_info->msglistentry); spin_unlock_irqrestore(&vmbus_connection.channelmsg_lock, flags); - +error_free_info: + kfree(open_info); error_free_gpadl: vmbus_teardown_gpadl(newchannel, newchannel->ringbuffer_gpadlhandle); - kfree(open_info); -error_free_pages: + newchannel->ringbuffer_gpadlhandle = 0; +error_clean_ring: hv_ringbuffer_cleanup(&newchannel->outbound); hv_ringbuffer_cleanup(&newchannel->inbound); - __free_pages(page, order); -error_set_chnstate: newchannel->state = CHANNEL_OPEN_STATE; return err; } + +/* + * vmbus_connect_ring - Open the channel but reuse ring buffer + */ +int vmbus_connect_ring(struct vmbus_channel *newchannel, + void (*onchannelcallback)(void *context), void *context) +{ + return __vmbus_open(newchannel, NULL, 0, onchannelcallback, context); +} +EXPORT_SYMBOL_GPL(vmbus_connect_ring); + +/* + * vmbus_open - Open the specified channel. + */ +int vmbus_open(struct vmbus_channel *newchannel, + u32 send_ringbuffer_size, u32 recv_ringbuffer_size, + void *userdata, u32 userdatalen, + void (*onchannelcallback)(void *context), void *context) +{ + int err; + + err = vmbus_alloc_ring(newchannel, send_ringbuffer_size, + recv_ringbuffer_size); + if (err) + return err; + + err = __vmbus_open(newchannel, userdata, userdatalen, + onchannelcallback, context); + if (err) + vmbus_free_ring(newchannel); + + return err; +} EXPORT_SYMBOL_GPL(vmbus_open); /* Used for Hyper-V Socket: a guest client's connect() to the host */ @@ -633,11 +669,10 @@ static int vmbus_close_internal(struct vmbus_channel *channel) * If we failed to post the close msg, * it is perhaps better to leak memory. */ - goto out; } /* Tear down the gpadl for the channel's ring buffer */ - if (channel->ringbuffer_gpadlhandle) { + else if (channel->ringbuffer_gpadlhandle) { ret = vmbus_teardown_gpadl(channel, channel->ringbuffer_gpadlhandle); if (ret) { @@ -646,16 +681,10 @@ static int vmbus_close_internal(struct vmbus_channel *channel) * If we failed to teardown gpadl, * it is perhaps better to leak memory. */ - goto out; } - } - - /* Cleanup the ring buffers for this channel */ - hv_ringbuffer_cleanup(&channel->outbound); - hv_ringbuffer_cleanup(&channel->inbound); - __free_pages(channel->ringbuffer_page, - get_order(channel->ringbuffer_pagecount << PAGE_SHIFT)); + channel->ringbuffer_gpadlhandle = 0; + } out: /* re-enable tasklet for use on re-open */ @@ -663,44 +692,55 @@ static int vmbus_close_internal(struct vmbus_channel *channel) return ret; } -/* - * vmbus_close - Close the specified channel - */ -void vmbus_close(struct vmbus_channel *channel) +/* disconnect ring - close all channels */ +int vmbus_disconnect_ring(struct vmbus_channel *channel) { - struct list_head *cur, *tmp; - struct vmbus_channel *cur_channel; + struct vmbus_channel *cur_channel, *tmp; + unsigned long flags; + LIST_HEAD(list); + int ret; - if (channel->primary_channel != NULL) { - /* - * We will only close sub-channels when - * the primary is closed. - */ - return; - } - /* - * Close all the sub-channels first and then close the - * primary channel. - */ - list_for_each_safe(cur, tmp, &channel->sc_list) { - cur_channel = list_entry(cur, struct vmbus_channel, sc_list); - if (cur_channel->rescind) { + if (channel->primary_channel != NULL) + return -EINVAL; + + /* Snapshot the list of subchannels */ + spin_lock_irqsave(&channel->lock, flags); + list_splice_init(&channel->sc_list, &list); + channel->num_sc = 0; + spin_unlock_irqrestore(&channel->lock, flags); + + list_for_each_entry_safe(cur_channel, tmp, &list, sc_list) { + if (cur_channel->rescind) wait_for_completion(&cur_channel->rescind_event); - mutex_lock(&vmbus_connection.channel_mutex); - vmbus_close_internal(cur_channel); - hv_process_channel_removal(cur_channel); - } else { - mutex_lock(&vmbus_connection.channel_mutex); - vmbus_close_internal(cur_channel); + + mutex_lock(&vmbus_connection.channel_mutex); + if (vmbus_close_internal(cur_channel) == 0) { + vmbus_free_ring(cur_channel); + + if (cur_channel->rescind) + hv_process_channel_removal(cur_channel); } mutex_unlock(&vmbus_connection.channel_mutex); } + /* * Now close the primary. */ mutex_lock(&vmbus_connection.channel_mutex); - vmbus_close_internal(channel); + ret = vmbus_close_internal(channel); mutex_unlock(&vmbus_connection.channel_mutex); + + return ret; +} +EXPORT_SYMBOL_GPL(vmbus_disconnect_ring); + +/* + * vmbus_close - Close the specified channel + */ +void vmbus_close(struct vmbus_channel *channel) +{ + if (vmbus_disconnect_ring(channel) == 0) + vmbus_free_ring(channel); } EXPORT_SYMBOL_GPL(vmbus_close); diff --git a/drivers/hv/ring_buffer.c b/drivers/hv/ring_buffer.c index 74c1dfb8183b..0233b6146da4 100644 --- a/drivers/hv/ring_buffer.c +++ b/drivers/hv/ring_buffer.c @@ -215,6 +215,7 @@ int hv_ringbuffer_init(struct hv_ring_buffer_info *ring_info, void hv_ringbuffer_cleanup(struct hv_ring_buffer_info *ring_info) { vunmap(ring_info->ring_buffer); + ring_info->ring_buffer = NULL; } /* Write to the ring buffer. */ diff --git a/include/linux/hyperv.h b/include/linux/hyperv.h index c174b3bc7492..7526cb9ed9db 100644 --- a/include/linux/hyperv.h +++ b/include/linux/hyperv.h @@ -714,6 +714,7 @@ struct vmbus_channel { /* Allocated memory for ring buffer */ struct page *ringbuffer_page; u32 ringbuffer_pagecount; + u32 ringbuffer_send_offset; struct hv_ring_buffer_info outbound; /* send to parent */ struct hv_ring_buffer_info inbound; /* receive from parent */ @@ -1001,6 +1002,14 @@ struct vmbus_packet_mpb_array { struct hv_mpb_array range; } __packed; +int vmbus_alloc_ring(struct vmbus_channel *channel, + u32 send_size, u32 recv_size); +void vmbus_free_ring(struct vmbus_channel *channel); + +int vmbus_connect_ring(struct vmbus_channel *channel, + void (*onchannel_callback)(void *context), + void *context); +int vmbus_disconnect_ring(struct vmbus_channel *channel); extern int vmbus_open(struct vmbus_channel *channel, u32 send_ringbuffersize, From patchwork Fri Jun 7 19:38:51 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: 1112232 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 45LCXZ6kdRz9s6w; Sat, 8 Jun 2019 05:39:42 +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 1hZKiA-0007Ue-G3; Fri, 07 Jun 2019 19:39:38 +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 1hZKi3-0007OX-Pw for kernel-team@lists.ubuntu.com; Fri, 07 Jun 2019 19:39:31 +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 1hZKi1-00072z-V2 for kernel-team@lists.ubuntu.com; Fri, 07 Jun 2019 19:39:30 +0000 Received: by mail-qk1-f198.google.com with SMTP id y190so2463773qkc.21 for ; Fri, 07 Jun 2019 12:39:29 -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=PPB3Fb68Cjd7XH7PZTlZqoA6ecfep0lvm8FTpLXq0YM=; b=GD5hhKz8mkcwsVV+V7Cp+pUFG/8R4QdOIXRrGLvROQgs1Ei1uThj5J2ZM5vjkYpPTT /ufg+D95uoBezAIDQST4E2Yfifp4mnVC/kUhNmnm+L3wL0eYJvBOvfxp2QLzf7LTSYnn x8XV8eKrL4YIDSaGQ6H65cYksW++u0r1a7SLputSH5TAmdeel07ewXNLtQdET1+eQu7X lOeQTFPfYCP9UZaPBWH2lVc1yLlRbBXVp7owJyTQSum76I782ZsbZXmyO2A9XgdvAOqG 5Fefq4QNq1F/r7JEJgwvS+9ZcKb8S1peI6uMtMCpZM1m+t3lM2HiurJDAFXWObsUFAuH xi0g== X-Gm-Message-State: APjAAAUWAtxhigjZOeh/88J+2dXwoVyeY7adNr/HzGoVqZJMajxyXBXj vrR5ilQsS1uAdQWV7Ar6FQLur9KJDLkScbwOovf8wgtFgZmMWIUxGvPEn+2/Uj4ncTO05qa2z9i JNJ8JQ8J//QBPsjcGmFYDZGQUWbjBkluf7mBnwbyf X-Received: by 2002:a0c:9e58:: with SMTP id z24mr26569525qve.214.1559936368726; Fri, 07 Jun 2019 12:39:28 -0700 (PDT) X-Google-Smtp-Source: APXvYqxDsmLvVuzK4gTGNT8Y0+IyLO8ETCJs0NPW+MeUv+zUcivXyNrLeMaXG1ZazcXgUW/yXE8DwA== X-Received: by 2002:a0c:9e58:: with SMTP id z24mr26569512qve.214.1559936368432; Fri, 07 Jun 2019 12:39:28 -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.26 for (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Fri, 07 Jun 2019 12:39:27 -0700 (PDT) From: Marcelo Henrique Cerri To: kernel-team@lists.ubuntu.com Subject: [x/azure][PATCH 17/17] vmbus: fix subchannel removal Date: Fri, 7 Jun 2019 16:38:51 -0300 Message-Id: <20190607193851.21914-18-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: Dexuan Cui BugLink: http://bugs.launchpad.net/bugs/1812123 The changes to split ring allocation from open/close, broke the cleanup of subchannels. This resulted in problems using uio on network devices because the subchannel was left behind when the network device was unbound. The cause was in the disconnect logic which used list splice to move the subchannel list into a local variable. This won't work because the subchannel list is needed later during the process of the rescind messages (relid2channel). The fix is to just leave the subchannel list in place which is what the original code did. The list is cleaned up later when the host rescind is processed. Without the fix, we have a lot of "hang" issues in netvsc when we try to change the NIC's MTU, set the number of channels, etc. Fixes: ae6935ed7d42 ("vmbus: split ring buffer allocation from open") Cc: stable@vger.kernel.org Signed-off-by: Stephen Hemminger Signed-off-by: Dexuan Cui Signed-off-by: Sasha Levin (backported from commit b5679cebf780c6f1c2451a73bf1842a4409840e7) [marcelo.cerri: kept `channel->num_sc = 0;` to avoid cherry picking 4d3c5c69191f ("Drivers: hv: vmbus: Remove the useless API vmbus_get_outgoing_channel()")] Signed-off-by: Marcelo Henrique Cerri --- drivers/hv/channel.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c index 1bbf048dd931..cfea80530325 100644 --- a/drivers/hv/channel.c +++ b/drivers/hv/channel.c @@ -696,20 +696,14 @@ static int vmbus_close_internal(struct vmbus_channel *channel) int vmbus_disconnect_ring(struct vmbus_channel *channel) { struct vmbus_channel *cur_channel, *tmp; - unsigned long flags; - LIST_HEAD(list); int ret; if (channel->primary_channel != NULL) return -EINVAL; - /* Snapshot the list of subchannels */ - spin_lock_irqsave(&channel->lock, flags); - list_splice_init(&channel->sc_list, &list); channel->num_sc = 0; - spin_unlock_irqrestore(&channel->lock, flags); - list_for_each_entry_safe(cur_channel, tmp, &list, sc_list) { + list_for_each_entry_safe(cur_channel, tmp, &channel->sc_list, sc_list) { if (cur_channel->rescind) wait_for_completion(&cur_channel->rescind_event);