From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: MIME-Version: 1.0 References: <1666161802.3034256-2-xuanzhuo@linux.alibaba.com> <90A95AD3-DCC6-474C-A0E6-13347B13A2B3@linux.alibaba.com> <20221019082136.GA63658@linux.alibaba.com> <1666170632.2841902-1-xuanzhuo@linux.alibaba.com> <1666171438.2142851-3-xuanzhuo@linux.alibaba.com> <20221021033012.GB63658@linux.alibaba.com> In-Reply-To: <20221021033012.GB63658@linux.alibaba.com> From: Jason Wang Date: Fri, 21 Oct 2022 14:37:20 +0800 Message-ID: Subject: Re: [virtio-dev] [PATCH 0/2] introduce virtio-ism: internal shared memory device Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable To: dust.li@linux.alibaba.com Cc: Xuan Zhuo , Gerry , virtio-dev@lists.oasis-open.org, hans@linux.alibaba.com, herongguang@linux.alibaba.com, zmlcc@linux.alibaba.com, tonylu@linux.alibaba.com, zhenzao@linux.alibaba.com, helinguo@linux.alibaba.com, mst@redhat.com, cohuck@redhat.com, Stefan Hajnoczi List-ID: On Fri, Oct 21, 2022 at 11:30 AM Dust Li wrote: > > On Fri, Oct 21, 2022 at 10:41:26AM +0800, Jason Wang wrote: > >On Wed, Oct 19, 2022 at 5:27 PM Xuan Zhuo w= rote: > >> > >> On Wed, 19 Oct 2022 17:15:23 +0800, Jason Wang w= rote: > >> > On Wed, Oct 19, 2022 at 5:12 PM Xuan Zhuo wrote: > >> > > > >> > > On Wed, 19 Oct 2022 17:08:29 +0800, Jason Wang wrote: > >> > > > On Wed, Oct 19, 2022 at 4:21 PM Dust Li wrote: > >> > > > > > >> > > > > On Wed, Oct 19, 2022 at 04:03:42PM +0800, Gerry wrote: > >> > > > > > > >> > > > > > > >> > > > > >> 2022=E5=B9=B410=E6=9C=8819=E6=97=A5 16:01=EF=BC=8CJason Wan= g =E5=86=99=E9=81=93=EF=BC=9A > >> > > > > >> > >> > > > > >> On Wed, Oct 19, 2022 at 3:00 PM Xuan Zhuo wrote: > >> > > > > >>> > >> > > > > >>> On Tue, 18 Oct 2022 14:54:22 +0800, Jason Wang wrote: > >> > > > > >>>> On Mon, Oct 17, 2022 at 8:31 PM Xuan Zhuo wrote: > >> > > > > >>>>> > >> > > > > >>>>> On Mon, 17 Oct 2022 16:17:31 +0800, Jason Wang wrote: > >> > > > > >>>>>> Adding Stefan. > >> > > > > >>>>>> > >> > > > > >>>>>> > >> > > > > >>>>>> On Mon, Oct 17, 2022 at 3:47 PM Xuan Zhuo wrote: > >> > > > > >>>>>>> > >> > > > > >>>>>>> Hello everyone, > >> > > > > >>>>>>> > >> > > > > >>>>>>> # Background > >> > > > > >>>>>>> > >> > > > > >>>>>>> Nowadays, there is a common scenario to accelerate com= munication between > >> > > > > >>>>>>> different VMs and containers, including light weight v= irtual machine based > >> > > > > >>>>>>> containers. One way to achieve this is to colocate the= m on the same host. > >> > > > > >>>>>>> However, the performance of inter-VM communication thr= ough network stack is not > >> > > > > >>>>>>> optimal and may also waste extra CPU cycles. This scen= ario has been discussed > >> > > > > >>>>>>> many times, but still no generic solution available [1= ] [2] [3]. > >> > > > > >>>>>>> > >> > > > > >>>>>>> With pci-ivshmem + SMC(Shared Memory Communications: [= 4]) based PoC[5], > >> > > > > >>>>>>> We found that by changing the communication channel be= tween VMs from TCP to SMC > >> > > > > >>>>>>> with shared memory, we can achieve superior performanc= e for a common > >> > > > > >>>>>>> socket-based application[5]: > >> > > > > >>>>>>> - latency reduced by about 50% > >> > > > > >>>>>>> - throughput increased by about 300% > >> > > > > >>>>>>> - CPU consumption reduced by about 50% > >> > > > > >>>>>>> > >> > > > > >>>>>>> Since there is no particularly suitable shared memory = management solution > >> > > > > >>>>>>> matches the need for SMC(See ## Comparison with existi= ng technology), and virtio > >> > > > > >>>>>>> is the standard for communication in the virtualizatio= n world, we want to > >> > > > > >>>>>>> implement a virtio-ism device based on virtio, which c= an support on-demand > >> > > > > >>>>>>> memory sharing across VMs, containers or VM-container.= To match the needs of SMC, > >> > > > > >>>>>>> the virtio-ism device need to support: > >> > > > > >>>>>>> > >> > > > > >>>>>>> 1. Dynamic provision: shared memory regions are dynami= cally allocated and > >> > > > > >>>>>>> provisioned. > >> > > > > >>>>>>> 2. Multi-region management: the shared memory is divid= ed into regions, > >> > > > > >>>>>>> and a peer may allocate one or more regions from the= same shared memory > >> > > > > >>>>>>> device. > >> > > > > >>>>>>> 3. Permission control: The permission of each region c= an be set seperately. > >> > > > > >>>>>> > >> > > > > >>>>>> Looks like virtio-ROCE > >> > > > > >>>>>> > >> > > > > >>>>>> https://lore.kernel.org/all/20220511095900.343-1-xieyon= gji@bytedance.com/T/ > >> > > > > >>>>>> > >> > > > > >>>>>> and virtio-vhost-user can satisfy the requirement? > >> > > > > >>>>>> > >> > > > > >>>>>>> > >> > > > > >>>>>>> # Virtio ism device > >> > > > > >>>>>>> > >> > > > > >>>>>>> ISM devices provide the ability to share memory betwee= n different guests on a > >> > > > > >>>>>>> host. A guest's memory got from ism device can be shar= ed with multiple peers at > >> > > > > >>>>>>> the same time. This shared relationship can be dynamic= ally created and released. > >> > > > > >>>>>>> > >> > > > > >>>>>>> The shared memory obtained from the device is divided = into multiple ism regions > >> > > > > >>>>>>> for share. ISM device provides a mechanism to notify o= ther ism region referrers > >> > > > > >>>>>>> of content update events. > >> > > > > >>>>>>> > >> > > > > >>>>>>> # Usage (SMC as example) > >> > > > > >>>>>>> > >> > > > > >>>>>>> Maybe there is one of possible use cases: > >> > > > > >>>>>>> > >> > > > > >>>>>>> 1. SMC calls the interface ism_alloc_region() of the i= sm driver to return the > >> > > > > >>>>>>> location of a memory region in the PCI space and a t= oken. > >> > > > > >>>>>>> 2. The ism driver mmap the memory region and return to= SMC with the token > >> > > > > >>>>>>> 3. SMC passes the token to the connected peer > >> > > > > >>>>>>> 3. the peer calls the ism driver interface ism_attach_= region(token) to > >> > > > > >>>>>>> get the location of the PCI space of the shared memo= ry > >> > > > > >>>>>>> > >> > > > > >>>>>>> > >> > > > > >>>>>>> # About hot plugging of the ism device > >> > > > > >>>>>>> > >> > > > > >>>>>>> Hot plugging of devices is a heavier, possibly faile= d, time-consuming, and > >> > > > > >>>>>>> less scalable operation. So, we don't plan to suppor= t it for now. > >> > > > > >>>>>>> > >> > > > > >>>>>>> # Comparison with existing technology > >> > > > > >>>>>>> > >> > > > > >>>>>>> ## ivshmem or ivshmem 2.0 of Qemu > >> > > > > >>>>>>> > >> > > > > >>>>>>> 1. ivshmem 1.0 is a large piece of memory that can b= e seen by all devices that > >> > > > > >>>>>>> use this VM, so the security is not enough. > >> > > > > >>>>>>> > >> > > > > >>>>>>> 2. ivshmem 2.0 is a shared memory belonging to a VM = that can be read-only by all > >> > > > > >>>>>>> other VMs that use the ivshmem 2.0 shared memory dev= ice, which also does not > >> > > > > >>>>>>> meet our needs in terms of security. > >> > > > > >>>>>>> > >> > > > > >>>>>>> ## vhost-pci and virtiovhostuser > >> > > > > >>>>>>> > >> > > > > >>>>>>> Does not support dynamic allocation and therefore no= t suitable for SMC. > >> > > > > >>>>>> > >> > > > > >>>>>> I think this is an implementation issue, we can support= VHOST IOTLB > >> > > > > >>>>>> message then the regions could be added/removed on dema= nd. > >> > > > > >>>>> > >> > > > > >>>>> > >> > > > > >>>>> 1. After the attacker connects with the victim, if the a= ttacker does not > >> > > > > >>>>> dereference memory, the memory will be occupied under = virtiovhostuser. In the > >> > > > > >>>>> case of ism devices, the victim can directly release t= he reference, and the > >> > > > > >>>>> maliciously referenced region only occupies the attack= er's resources > >> > > > > >>>> > >> > > > > >>>> Let's define the security boundary here. E.g do we trust = the device or > >> > > > > >>>> not? If yes, in the case of virtiovhostuser, can we simpl= e do > >> > > > > >>>> VHOST_IOTLB_UNMAP then we can safely release the memory f= rom the > >> > > > > >>>> attacker. > >> > > > > >>>> > >> > > > > >>>>> > >> > > > > >>>>> 2. The ism device of a VM can be shared with multiple (1= 000+) VMs at the same > >> > > > > >>>>> time, which is a challenge for virtiovhostuser > >> > > > > >>>> > >> > > > > >>>> Please elaborate more the the challenges, anything make > >> > > > > >>>> virtiovhostuser different? > >> > > > > >>> > >> > > > > >>> I understand (please point out any mistakes), one vvu devi= ce corresponds to one > >> > > > > >>> vm. If we share memory with 1000 vm, do we have 1000 vvu d= evices? > >> > > > > >> > >> > > > > >> There could be some misunderstanding here. With 1000 VM, yo= u still > >> > > > > >> need 1000 virtio-sim devices I think. > >> > > > > >We are trying to achieve one virtio-ism device per vm instead= of one virtio-ism device per SMC connection. > >> > > > > >> > > > I wonder if we need something to identify a virtio-ism device si= nce I > >> > > > guess there's still a chance to have multiple virtio-ism device = per VM > >> > > > (different service chain etc). > >> > > > >> > > Yes, there will be such a situation, a vm has multiple virtio-ism = devices. > >> > > > >> > > What exactly do you mean by "identify"? > >> > > >> > E.g we can differ two virtio-net through mac address, do we need > >> > something similar for ism, or it's completely unncessary (e.g via > >> > token or other) ? > >> > >> Currently, we have not encountered such a request. > >> > >> It is conceivable that all physical shared memory ism regions are inde= xed by > >> tokens. virtio-ism is a way to obtain these ism regions, so there is n= o need to > >> distinguish multiple virtio-ism devices under one vm on the host. > > > >So consider a case: > > > >VM1 shares ism1 with VM2 > >VM1 shares ism2 with VM3 > > > >How do application/smc address the different ism device in this case? > >E.g if VM1 want to talk with VM3 it needs to populate regions in ism2, > >but how can application or protocol knows this and how can a specific > >device to be addressed (via BDF?) > > In our design, we do have a dev_id for each ISM device. > Currently, we used it to do permission management, I think > it can be used to identify different ISM devices. > > The spec says: > > +\begin{description} > +\item[\field{dev_id}] the id of the device. I see, we need some clarification. E.g is it a UUID or not? Thanks > +\item[\field{region_size}] the size of the every ism region > +\item[\field{notify_size}] the size of the notify address. > > <...> > > +The device MUST regenerate a \field{dev_id}. \field{dev_id} remains unch= anged > +during reset. \field{dev_id} MUST NOT be 0; > > Thanks > > > > >Thanks > > > >> > >> Thanks. > >> > >> > >> > > >> > Thanks > >> > > >> > > > >> > > Thanks. > >> > > > >> > > > >> > > > > >> > > > Thanks > >> > > > > >> > > > > > >> > > > > I think we must achieve this if we want to meet the requiremen= ts of SMC. > >> > > > > In SMC, a SMC socket(Corresponding to a TCP socket) need 2 mem= ory > >> > > > > regions(1 for Tx and 1 for Rx). So if we have 1K TCP connectio= ns, > >> > > > > we'll need 2K share memory regions, and those memory regions a= re > >> > > > > dynamically allocated and freed with the TCP socket. > >> > > > > > >> > > > > > > >> > > > > >> > >> > > > > >>> > >> > > > > >>> > >> > > > > >>>> > >> > > > > >>>>> > >> > > > > >>>>> 3. The sharing relationship of ism is dynamically increa= sed, and virtiovhostuser > >> > > > > >>>>> determines the sharing relationship at startup. > >> > > > > >>>> > >> > > > > >>>> Not necessarily with IOTLB API? > >> > > > > >>> > >> > > > > >>> Unlike virtio-vhost-user, which shares the memory of a vm = with another vm, we > >> > > > > >>> provide the same memory on the host to two vms. So the imp= lementation of this > >> > > > > >>> part will be much simpler. This is why we gave up virtio-v= host-user at the > >> > > > > >>> beginning. > >> > > > > >> > >> > > > > >> Ok, just to make sure we're at the same page. From spec lev= el, > >> > > > > >> virtio-vhost-user doesn't (can't) limit the backend to be i= mplemented > >> > > > > >> in another VM. So it should be ok to be used for sharing me= mory > >> > > > > >> between a guest and host. > >> > > > > >> > >> > > > > >> Thanks > >> > > > > >> > >> > > > > >>> > >> > > > > >>> Thanks. > >> > > > > >>> > >> > > > > >>> > >> > > > > >>>> > >> > > > > >>>>> > >> > > > > >>>>> 4. For security issues, the device under virtiovhostuser= may mmap more memory, > >> > > > > >>>>> while ism only maps one region to other devices > >> > > > > >>>> > >> > > > > >>>> With VHOST_IOTLB_MAP, the map could be done per region. > >> > > > > >>>> > >> > > > > >>>> Thanks > >> > > > > >>>> > >> > > > > >>>>> > >> > > > > >>>>> Thanks. > >> > > > > >>>>> > >> > > > > >>>>>> > >> > > > > >>>>>> Thanks > >> > > > > >>>>>> > >> > > > > >>>>>>> > >> > > > > >>>>>>> # Design > >> > > > > >>>>>>> > >> > > > > >>>>>>> This is a structure diagram based on ism sharing bet= ween two vms. > >> > > > > >>>>>>> > >> > > > > >>>>>>> |--------------------------------------------------= -----------------------------------------------------------| > >> > > > > >>>>>>> | |------------------------------------------------= | |------------------------------------------------| | > >> > > > > >>>>>>> | | Guest = | | Guest | | > >> > > > > >>>>>>> | | = | | | | > >> > > > > >>>>>>> | | ---------------- = | | ---------------- | | > >> > > > > >>>>>>> | | | driver | [M1] [M2] [M3] = | | | driver | [M2] [M3] | | > >> > > > > >>>>>>> | | ---------------- | | | = | | ---------------- | | | | > >> > > > > >>>>>>> | | |cq| |map |map |map = | | |cq| |map |map | | > >> > > > > >>>>>>> | | | | | | | = | | | | | | | | > >> > > > > >>>>>>> | | | | ------------------- = | | | | -------------------- | | > >> > > > > >>>>>>> | |----|--|----------------| device memory |-----= | |----|--|----------------| device memory |----| | > >> > > > > >>>>>>> | | | | ------------------- = | | | | -------------------- | | > >> > > > > >>>>>>> | | | = | | | | | > >> > > > > >>>>>>> | | | = | | | | | > >> > > > > >>>>>>> | | Qemu | = | | Qemu | | | > >> > > > > >>>>>>> | |--------------------------------+---------------= | |-------------------------------+----------------| | > >> > > > > >>>>>>> | | = | | > >> > > > > >>>>>>> | | = | | > >> > > > > >>>>>>> | |---------------= ---------------+------------------------| | > >> > > > > >>>>>>> | = | | > >> > > > > >>>>>>> | = | | > >> > > > > >>>>>>> | = -------------------------- | > >> > > > > >>>>>>> | = | M1 | | M2 | | M3 | | > >> > > > > >>>>>>> | = -------------------------- | > >> > > > > >>>>>>> | = | > >> > > > > >>>>>>> | HOST = | > >> > > > > >>>>>>> ---------------------------------------------------= ------------------------------------------------------------ > >> > > > > >>>>>>> > >> > > > > >>>>>>> # POC code > >> > > > > >>>>>>> > >> > > > > >>>>>>> Kernel: https://github.com/fengidri/linux-kernel-vir= tio-ism/commits/ism > >> > > > > >>>>>>> Qemu: https://github.com/fengidri/qemu/commits/ism > >> > > > > >>>>>>> > >> > > > > >>>>>>> If there are any problems, please point them out. > >> > > > > >>>>>>> > >> > > > > >>>>>>> Hope to hear from you, thank you. > >> > > > > >>>>>>> > >> > > > > >>>>>>> [1] https://projectacrn.github.io/latest/tutorials/ena= ble_ivshmem.html > >> > > > > >>>>>>> [2] https://dl.acm.org/doi/10.1145/2847562 > >> > > > > >>>>>>> [3] https://hal.archives-ouvertes.fr/hal-00368622/docu= ment > >> > > > > >>>>>>> [4] https://lwn.net/Articles/711071/ > >> > > > > >>>>>>> [5] https://lore.kernel.org/netdev/20220720170048.2080= 6-1-tonylu@linux.alibaba.com/T/ > >> > > > > >>>>>>> > >> > > > > >>>>>>> > >> > > > > >>>>>>> Xuan Zhuo (2): > >> > > > > >>>>>>> Reserve device id for ISM device > >> > > > > >>>>>>> virtio-ism: introduce new device virtio-ism > >> > > > > >>>>>>> > >> > > > > >>>>>>> content.tex | 3 + > >> > > > > >>>>>>> virtio-ism.tex | 340 +++++++++++++++++++++++++++++++++= ++++++++++++++++ > >> > > > > >>>>>>> 2 files changed, 343 insertions(+) > >> > > > > >>>>>>> create mode 100644 virtio-ism.tex > >> > > > > >>>>>>> > >> > > > > >>>>>>> -- > >> > > > > >>>>>>> 2.32.0.3.g01195cf9f > >> > > > > >>>>>>> > >> > > > > >>>>>>> > >> > > > > >>>>>>> ------------------------------------------------------= --------------- > >> > > > > >>>>>>> To unsubscribe, e-mail: virtio-dev-unsubscribe@lists.o= asis-open.org > >> > > > > >>>>>>> For additional commands, e-mail: virtio-dev-help@lists= .oasis-open.org > >> > > > > >>>>>>> > >> > > > > >>>>>> > >> > > > > >>>>> > >> > > > > >>>>> --------------------------------------------------------= ------------- > >> > > > > >>>>> To unsubscribe, e-mail: virtio-dev-unsubscribe@lists.oas= is-open.org > >> > > > > >>>>> For additional commands, e-mail: virtio-dev-help@lists.o= asis-open.org > >> > > > > >>>>> > >> > > > > >>>> > >> > > > > >>> > >> > > > > > >> > > > > >> > > > >> > > ------------------------------------------------------------------= --- > >> > > To unsubscribe, e-mail: virtio-dev-unsubscribe@lists.oasis-open.or= g > >> > > For additional commands, e-mail: virtio-dev-help@lists.oasis-open.= org > >> > > > >> > > >> > >> --------------------------------------------------------------------- > >> To unsubscribe, e-mail: virtio-dev-unsubscribe@lists.oasis-open.org > >> For additional commands, e-mail: virtio-dev-help@lists.oasis-open.org > >> >