Received: by 10.223.176.5 with SMTP id f5csp4031158wra; Tue, 30 Jan 2018 00:45:39 -0800 (PST) X-Google-Smtp-Source: AH8x227R/ID/V0IsjMCunDxUZMzUqrb6fZqIyfj9SYzXlKtTN8JduVaIcV8hc3o+YeUsZFM6op06 X-Received: by 2002:a17:902:6b05:: with SMTP id o5-v6mr24108524plk.179.1517301939719; Tue, 30 Jan 2018 00:45:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517301939; cv=none; d=google.com; s=arc-20160816; b=Ehg3LJvkIywto3uXR4cgLiiOOj/q6StdcV08wDwIxb8l7+z4/l7KK+gzLNy+VRjFbq 69TtxAd8GwGw9kh2X4uoh86q56Gic5bFxrXnLzBhIodSmbZ/U2tuCkI7WKTlMUta1kK4 mMuyDYA+AGXR+aV2tzkBDfjHTYVax31ztdoJ5mfXIWQ5iIYjEu71IUJM7g/9tAP0zGC9 7mZvoJaBZvEqOlgJh/4MqbYvpgl2Ek0bsqIZTaBMVHHYEA0ZGmQlfzds5yJRqj6Gv5hC pWhGLJmGPD3pMYnaz5VlddixG97gTdY62wSFqGZgCpdXkfXSm/5IiFEMvDzrVYw4fcp1 pVwg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :arc-authentication-results; bh=vGvlon/7GbLszJuWBsErCkb5Be0TKe8SuKEnxIU42MA=; b=qOFI0zqctE7VbXnCojTAEfsII7FYJvY9wGm8jL1nvoI50xchtmKVw5JslQSD0uEdQB 0wVWwt5OOenGXkkOCoJuz1fZBSmUI15seSnm0gFo+e/4yrvzez+pZH510OzoIichEfRm OfDUlTGJAdndUgJQe0QTG7vs4BP+8mm/0LSQUGtrOV69mTg3HDOmrcQBVv8K+nasN7E/ cu3r+ULLbN7TnQEOV7gMUfm2n0IH8+l7ibAmIrwjXikswpx1msJ/Xf0fHgJxHqpnQQ94 QGFIUp4XJjhqlwkUKJ0p4t75AUsmcbMqE9SStlSnYalM8UaDwYApK7BBfiMsvjlO6ozk XfQQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 67-v6si1550612ple.609.2018.01.30.00.45.25; Tue, 30 Jan 2018 00:45:39 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751842AbeA3IoP (ORCPT + 99 others); Tue, 30 Jan 2018 03:44:15 -0500 Received: from smtp.qindel.com ([89.140.90.34]:59711 "EHLO thor.qindel.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751606AbeA3IoN (ORCPT ); Tue, 30 Jan 2018 03:44:13 -0500 Received: from localhost (localhost [127.0.0.1]) by thor.qindel.com (Postfix) with ESMTP id 6D3B9601E5; Tue, 30 Jan 2018 09:36:49 +0100 (CET) Received: from thor.qindel.com ([127.0.0.1]) by localhost (thor.qindel.com [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id oYLLDNo5m3tC; Tue, 30 Jan 2018 09:36:49 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by thor.qindel.com (Postfix) with ESMTP id 39EBD601EC; Tue, 30 Jan 2018 09:36:49 +0100 (CET) X-Virus-Scanned: amavisd-new at thor.qindel.com Received: from thor.qindel.com ([127.0.0.1]) by localhost (thor.qindel.com [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id c1zl_aauFyin; Tue, 30 Jan 2018 09:36:49 +0100 (CET) Received: from atun.int.qindel.com (unknown [172.26.9.84]) by thor.qindel.com (Postfix) with ESMTP id C50A9601E5; Tue, 30 Jan 2018 09:36:43 +0100 (CET) From: Salvador Fandino To: linux-usb@vger.kernel.org Cc: gregkh@linuxfoundation.org, valentina.manea.m@gmail.com, shuah@kernel.org, linux-kernel@vger.kernel.org Subject: [PATH 0/4] usbip: make vhci_hcd.* objects independent of vhci_hcd.0 Date: Tue, 30 Jan 2018 09:36:26 +0100 Message-Id: <20180130083630.26501-1-salva@qindel.com> X-Mailer: git-send-email 2.14.1 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Let me start by explaining the problem that have motivated me to write this patches: I work on the QVD, a virtual desktop platform for Linux. This software runs Linux desktops (i.e. XFCE, KDE) and their applications inside LXC containers, and makes then available through the network to remote users. Supporting USB devices is a common feature customers have been requesting us for a long time (in order to use, for instance, remote signature pads, bar-code scanners, fingerprint readers, etc.). So, we have been working on that feature using the USB/IP layer on the kernel. Connecting and disconnecting devices and transferring data works seamless for the devices listed above. But we also want to make the usbip operations private to the container where they are run. For instance, it is unacceptable for our product, that one user could list the devices connected by other users or access them. We can control how can access every device using cgroups once those are attached, but the usbip layer is not providing any mechanism for controlling who can attach, detach or list the devices. So, we got the idea that in order to enforce that remote usbip devices are only visible inside the container where they were imported, we could conveniently mount-bind inside every container just one of the vhci_hcd directories below /sys/devices/platform. So that it is as if every container had a vhci_hcd just for itself (and also, we restrict access to the matching USB ports in cgroups). Unfortunately, all the vhci_hcd.* devices are controlled through attributes in vhci_hcd.0 making our approach fail and so... well, that is what this patch series changes. It makes every vhci_hcd device controllable through attributes inside its own sysfs directory. The first patch, does that in the kernel, and the second and third patches change user space, adapting the libusbip and the usbip tools code respectively. Then there is a fourth patch, that allows to create much more USB hubs per machine. It was limited to 64 and we are running thousands of containers (every one requiring a hub) per host. These changes are not completely backward compatible. In the sysfs side, besides moving around the attribute files, now the port numbers go from 0 to CONFIG_USBIP_VHCI_HC_PORTS * 2 - 1 and are reused for every vhci_hcd device. I could have maintained the absolute numeration but I think reusing the numbers is a better and simpler approach. I have considered that until very recently, support for vhci_hcd devices above the .0 was broken in the uspip tools (see 1ac7c8a78be85f84b019d3d2742d1a9f07255cc5 "usbip: fix usbip attach to find a port that matches the requested speed") and that has been the place where I have set the bar for backward compatibility: usage of the tools must remain unchanged for accessing "vhci_hcd.0", but may require changes otherwise. The same is true for the library functions which now provides new functions for selecting the target vhci_hcd device. The old functions now always target "vhci_hcd.0". So, for instance, now, "usbip port" by default only shows "vhci_hcd.0" ports but "usbip port -a" shows all of them, and, for instance, "usbip port -i 4", shows the ports in "vhci_hcd.4". Cheers.