Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp372628pxj; Fri, 11 Jun 2021 01:03:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwI7Q6a/nEwozwr1/LvnVhbvvm5JAey2+gFwcnL7VqCU20GgHYbK7AYy03nkGPqUUNZymbJ X-Received: by 2002:a17:906:4e81:: with SMTP id v1mr2499617eju.125.1623398637481; Fri, 11 Jun 2021 01:03:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623398637; cv=none; d=google.com; s=arc-20160816; b=GSz7RqHBIIRDLGgMopLvg2gfN/tRidKR3R5yE8hiK70O2OHxk4sIAgma2/vqC3hn9N +jw5B1dM496jQUodTOPL3HZll0vbiXssYIE2S88ERUFYPruoEkH4JM90hmUdwbThgjzu +hS+wIMlwx+JJU7XSrC+MHF6TL3e3kdTe7cMThnaaMWbbYoU9JE5WXCa5GLoeEcFdpBQ nRxF86l5L9p7FR9LDgOB7Igtp8k8BhEgTDnwRMb/GdadOD314tnh53PonliCNJY7VTqK c5/NqiyjfkddFIQ+pj4GXJzuOQJSFUgR8AWZLl9dnNvaz+0tN9eg3uSgydhW8UoJTNrX LsiA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=dDD6ozQuHkfsjJXIeMviIaHXaasyFUacyXt/Ls+8R/4=; b=TgQaalNVoYcwIFs250eLtSPYDJrGvgZBnYzfCQwqRLHezUEI13m7JrbDtY0HqwFG9s gLEyBb4GJHv62eiN5g12dWNq3E0WyYMmofqOKHDGXxA98KR90NM1umV3NXeNaMR6Yp4/ Xf7QEG8mEuaftURnOKMP5gTI8NfxW/9/bjsm0PPpg0LkjFRaCUPp36nmBPW693FIveJz 9nk0bvu3F/AuQrd+ZV54GiiHlQDJAJjT5hot/Zt9h+uytlbT7dRpLpJOJ/3yksTVMlj9 7emkEiGou8TxbQrSgxCQH/b5p/F5vOXpISN/dH5JHyVxgCRIte1C8L0OVSRI+Rzt8Cpk OBHQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=H2vJeZvj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id yd10si3639763ejb.249.2021.06.11.01.03.34; Fri, 11 Jun 2021 01:03:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=H2vJeZvj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231391AbhFKIDY (ORCPT + 99 others); Fri, 11 Jun 2021 04:03:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52456 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231322AbhFKIDW (ORCPT ); Fri, 11 Jun 2021 04:03:22 -0400 Received: from mail-pg1-x52e.google.com (mail-pg1-x52e.google.com [IPv6:2607:f8b0:4864:20::52e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 066ECC061574 for ; Fri, 11 Jun 2021 01:01:25 -0700 (PDT) Received: by mail-pg1-x52e.google.com with SMTP id e22so1796852pgv.10 for ; Fri, 11 Jun 2021 01:01:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=dDD6ozQuHkfsjJXIeMviIaHXaasyFUacyXt/Ls+8R/4=; b=H2vJeZvjIh9pgu2UG0sKGBhDj+x8aQhG/MfT1Cxtztd+CblLvs4QSwrLvNWyQ01BVy i6rUSqwWT6YxqHNCSJ0o4eDEUa0E51TjjqikU8ZGPtTjHvKJxcqAci0jvgffQrMqqyPl 5GWj7dgoSke+cSE0YiCPmRTujqWqKuHKMMo10p8azW1mM7x/cuOtHMabsZUBU5OBD2+a lUX+G37CNYrOL0Gt8PzG3CIysFGvU9gqaETpWcWCaPrG5IBtUfmv9N79D9bToGBjgCRR i2ThzGT/BoEAOF2sV+5EkiQxPUywzJwdzzTtLePbsw7q6Z2f4vkYfFjgP4ws+Otgcu8Q G/+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=dDD6ozQuHkfsjJXIeMviIaHXaasyFUacyXt/Ls+8R/4=; b=Fpa4UFPnhTNCw1gTG/ZKW59CUTpUN3JO5kNkMs87eZXdQPHvXjdvTHs2wzrAswwXbZ 1FcxNozEQqe70tguFJa62U5Di9Z0g+VYYPeln6RpLB5z+H/HDoVVF0hOm6Gpr9VZHloT qcW34/gRKu37rWBUVXkD07bhzCre5CjUwYhe4Ijd17tD6ovF3JjyrvDs4fdlPvmj82IN zBu2TwycIIzcPM9zugrw5B5hC+chNury/CzTLE8fcHD4GwMzAdaOVd9UgRQLxuGK/jG/ ALm0v07x+cltIEsF2Zk6RzKbe0/qA9P2RkuU1Y/TnCN87VDZcwegATitM+5Rku6Fzl6j jC6A== X-Gm-Message-State: AOAM532DxXXDKB8iep0Y4qQjSXXhd0g8Aim4pQzikLXcJAO+RIrhjjYc kLsR8OUR+62yia/b5EzqWtczYA== X-Received: by 2002:a62:2c92:0:b029:2ef:6118:a934 with SMTP id s140-20020a622c920000b02902ef6118a934mr7063663pfs.80.1623398484479; Fri, 11 Jun 2021 01:01:24 -0700 (PDT) Received: from localhost ([136.185.134.182]) by smtp.gmail.com with ESMTPSA id j4sm4258445pfj.111.2021.06.11.01.01.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Jun 2021 01:01:23 -0700 (PDT) Date: Fri, 11 Jun 2021 13:31:22 +0530 From: Viresh Kumar To: Geert Uytterhoeven Cc: Linus Walleij , Bjorn Andersson , Bartosz Golaszewski , "Enrico Weigelt, metux IT consult" , Viresh Kumar , "Michael S. Tsirkin" , Jason Wang , Vincent Guittot , Bill Mills , Alex =?utf-8?Q?Benn=C3=A9e?= , stratos-dev@op-lists.linaro.org, "open list:GPIO SUBSYSTEM" , linux-kernel , Stefan Hajnoczi , "Stefano Garzarella --cc virtualization @ lists . linux-foundation . org" , virtualization@lists.linux-foundation.org, Alistair Strachan Subject: Re: [PATCH V3 1/3] gpio: Add virtio-gpio driver Message-ID: <20210611080122.tlkidv6bowuka6fw@vireshk-i7> References: <10442926ae8a65f716bfc23f32339a6b35e51d5a.1623326176.git.viresh.kumar@linaro.org> <20210611035623.z4f2ynumzozigqnv@vireshk-i7> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: NeoMutt/20180716-391-311a52 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 11-06-21, 09:42, Geert Uytterhoeven wrote: > Hi Viresh, Linus, > > On Fri, Jun 11, 2021 at 5:56 AM Viresh Kumar wrote: > > On 10-06-21, 22:46, Linus Walleij wrote: > > > thanks for working on this, it's a really interesting driver. > > > > > > My first question is conceptual: > > > > > > We previously have Geerts driver for virtualization: > > > drivers/gpio/gpio-aggregator.c > > > > > > The idea with the aggregator is that a host script sets up a > > > unique gpiochip for the virtualized instance using some poking > > > in sysfs and pass that to the virtual machine. > > > So this is Linux acting as virtualization host by definition. > > The gpio-aggregator is running on the host... > > > > I think virtio is more abstract and intended for the usecase > > > where the hypervisor is not Linux, so this should be mentioned > > > in the commit, possibly also in Kconfig so users immediately > > > know what usecases the two different drivers are for. > > ... while the virtio-gpio driver is meant for the guest kernel. > > I my PoC "[PATCH QEMU v2 0/5] Add a GPIO backend"[1], I didn't have > a virtio transport, but just hooked into the PL061 GPIO emulation > in QEMU. The PL061 QEMU driver talked to the GPIO backend, which > talked to /dev/gpiochipN on the host. Hmm, interesting. > > Well, not actually. > > > > The host can actually be anything. It can be a Xen based dom0, which > > runs some proprietary firmware, or Qemu running over Linux. > > > > It is left for the host to decide how it wants to club together the > > GPIO pins from host and access them, with Linux host userspace it > > would be playing with /dev/gpiochipN, while for a raw one it may > > be accessing registers directly. > > > > And so the backend running at host, needs to pass the gpiochip > > configurations and only the host understand it. > > So QEMU has to translate the virtio-gpio communication to e.g. > /dev/gpiochipN on the host (or a different backend on non-Linux or > bare-metal HV). No, QEMU passes the raw messages to the backend daemon running in host userspace (which shares a socket with qemu). The backend understands the virtio/vhost protocols and so won't be required to change at all if we move from Qemu to something else. And that's what we (Linaro) are looking to do here with Project Stratos. Create virtio based hypervisor agnostic backends. > > The way I test it for now is by running this with Qemu over my x86 > > box, so my host side is indeed playing with sysfs Linux. > > Can you please share a link to the QEMU patches? Unfortunately, they aren't in good shape right now and the backend is a bit hacky (Just checking the data paths, but not touching /dev/gpiochipN at all for now). I didn't implement one as I am going to implement the backend in Rust and not Qemu. So it doesn't depend on Qemu at all. To give you an idea of the whole thing, here is what we have done for I2c for example, GPIO one will look very similar. The Qemu patches: https://yhbt.net/lore/all/cover.1617278395.git.viresh.kumar@linaro.org/T/ The stuff from tools/vhost-user-i2c/ directory (or patch 4/6) isn't used anymore and the following Rust implementation replaces it: https://github.com/vireshk/vhost-device/tree/master/src/i2c I can share the GPIO code once I have the Rust implementation ready. > The GPIO aggregator came into play after talking to Alexander Graf and > Peter Maydell. To reduce the attack surface, they didn't want QEMU > to be responsible for exporting to the guest a subset of all GPIOs of > a gpiochip, only a full gpiochip. However, the full gpiochip may > contain critical GPIOs you do not want the guest to tamper with. > Hence the GPIO aggregator was born, to take care of aggregating all > GPIOs you want to export to a guest into a new virtual gpiochip. > > You can find more information about the GPIO Aggregator's use cases in > "[PATCH v7 0/6] gpio: Add GPIO Aggregator"[2]. So I was actually looking to do some kind of aggregation on the host side's backend daemon to share only a subset of GPIO pins, I will see if that is something I can reuse. Thanks for sharing details. -- viresh