From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9F8EB38E8D0 for ; Mon, 10 Aug 2026 08:07:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786349236; cv=none; b=inx7mw4LNbG6I+XI0gkzsGEtiunPH6Tjzqb2Fzkmsq6pJQwJEuYyoqWlBfOQ8gELPlphuk/9vXx2iveKdVnSdhVb7PRBEzUyYah3aISoOyCo7k0tzHyJYwRdhHTpiI4RjEpHaX1EzBTrJmcxvx5ZQFnuS4+KXB8bQf/o/BOIpn4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786349236; c=relaxed/simple; bh=GmjbX1NHkXBLv/FHmi9swAkkunNfGLyNVsBGsQsGvOQ=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=eO62OOMdGSiYWdOa52UxKdwY++/l9GVZCewjrv5+uHJbtmAyQyB1ycUXOVp8Pg8aaUNnPSFZfL9y3lTbD3NT0ghKX5Oexj/EOiOsvrBTWRWuXIg1jmokcbzyftr9HbyhlsKQtX+X3iM2vmA8CRo0QKRv7D/bISriojQiTxcG7gE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=FWaySG9w; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=rKL2kIie; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="FWaySG9w"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="rKL2kIie" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1786349233; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=B4dFVWyu3xzRnl6oCpTVpkogt182ZU5pdL31lNneQJ8=; b=FWaySG9w/eUD3Pb+FlSiwZNf+yDfrQ8blqzKMhpHPzCOWEbg/8U+0gnO+VzAlXE+os2yBg 6+RMz50BZezbX7MDu6IO1zIcRFRhz8sBtbuZqbp+fexesbt5dnGge0XSCP3fWcGlANs/N2 mO6+oo+Aih91m55RKR+GWpy0WUkWMpc= Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-77-EK9zGeALMm-FNDF_R9y8SQ-1; Mon, 10 Aug 2026 04:07:10 -0400 X-MC-Unique: EK9zGeALMm-FNDF_R9y8SQ-1 X-Mimecast-MFC-AGG-ID: EK9zGeALMm-FNDF_R9y8SQ_1786349229 Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-4955ce558d8so15961115e9.3 for ; Mon, 10 Aug 2026 01:07:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1786349229; x=1786954029; darn=vger.kernel.org; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:from:date:from:to:cc:subject :date:message-id:reply-to:content-type; bh=B4dFVWyu3xzRnl6oCpTVpkogt182ZU5pdL31lNneQJ8=; b=rKL2kIieVEmmkSDUSB5lw4TINmFdlTQ97dXgDJH3l8lM489G34wZpW8s39KkZSXRKh 4mrmFe779MvZik2MnwMk+50sbbvL8DYILioWZtRJsrUb1u8JfH3OKwsXet43W7lRKerg lpTqptM7mzUkxCt6GF1f2EckJMeVPtAE0B6iMb9cVzfLtLKvlew6s8sa7WaRCsPPlhJl X2X3CX7qmWWHjRLK0Dn7OHyj1ovi3QI9aVpQBiwRgQbDByorN8BmwoJX42oE0JdLHKuv Tj5Ra09VwSYYoxjB3cfHk9lF/ELFIS3W7nNJXggu84/VATm9MLQS7MeaCdhwn7xD1pq9 QqFA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1786349229; x=1786954029; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:from:date:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=B4dFVWyu3xzRnl6oCpTVpkogt182ZU5pdL31lNneQJ8=; b=jKMQnES8DitwWcEwZL51ohUwIdzbkM2XSqwpFlxcd4wvVFrIV1YP7T1psN4gMJ3MVZ 318rwPdewysbUsb+u6lAKThHLAfC7LbeSHn9gFyoonGHa+3FjKJf79JgjOeNSq+S/6sJ Cq4RgSAvKDQkAeV/RoM8GJHv8UcxOsrp4RgopB3phaNj7eRaRFOH/vv/BkLgkJGIwdPI hQ0kaVRF6CrZnAm6cstCipRwoAbSe3TIyAaeMAb6aUA6bBHeu95rsFuKwsqw6qis1A1g ADVyKGrCdC++/U+saPkttvLloDFZKdfk3boXblA/g1sgnhFpsCk+K9MBSnBqque1mBeC sYow== X-Forwarded-Encrypted: i=1; AHgh+Rp81letoDhnDgFWeO6fylk2mFACHLD7Jb0JcZjmHzLpAeuj0YXjmiRnZlp2wjHWMYGFE8CFfTKWjzTFumA=@vger.kernel.org X-Gm-Message-State: AOJu0YxwyDhWIfdPmeasldwobHUt3KeZaRryNoRpz8yo/aMpYtmN7rVH QlvQy757bYCZpWCnKlDyKbFNLKGQMAxOxA2pywf5Xbuydmr9t8HQk6UmyW5VjT9OVaAdwiHtIQp I6Tge1/m1vuE9hANYAz6Q2LJgUR4jCO2+Cc5Mmr4m/vbzazDns6KW67HMejwDQf1Nvw== X-Gm-Gg: AR+sD12EDUJ2sxI1X8cQ6ZdKJVuuet3FLjedmVhv4C9MfNBhksonPODbWAWbJeWEOM6 CIjt3l0PPM2mkOx0cls1mZK74oy87Q/nAfQEj7c4d9aMsn349TzLLLMf2vNEEErSStMTkUaiv4W UeQIk9Ktz1jyYbDecqiikhMe0YvqheI8IMocOfegYzoCUwqnRCVL6ZYWe5fZ8e1PyAHIRbnfgfG Z3VtHB71BqfZlE6Xjr1jeKrt12l3OpYSBLpsGE1upioRm8RyeDg6e06pJQctcz2K9wdirVv0cwJ WWitHoC2WYVv7+oEgOfL3NCOD8YjYgpoJAgZ9ENmYeT7q6VR4pg4gC75ihIeG+y/i4d5lbbNqnq qBSL98PkpoPIBZL0djtdVpg== X-Received: by 2002:a05:600c:1912:b0:495:4d88:e630 with SMTP id 5b1f17b1804b1-499619928f5mr202686345e9.10.1786349228406; Mon, 10 Aug 2026 01:07:08 -0700 (PDT) X-Received: by 2002:a05:600c:1912:b0:495:4d88:e630 with SMTP id 5b1f17b1804b1-499619928f5mr202685355e9.10.1786349227606; Mon, 10 Aug 2026 01:07:07 -0700 (PDT) Received: from redhat.com (IGLD-80-230-39-98.inter.net.il. [80.230.39.98]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4995ea27ef0sm314197285e9.9.2026.08.10.01.07.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Aug 2026 01:07:07 -0700 (PDT) Date: Mon, 10 Aug 2026 04:07:04 -0400 From: "Michael S. Tsirkin" To: "Graf (AWS), Alexander" Cc: Jason Wang , Xuan Zhuo , Eugenio =?iso-8859-1?Q?P=E9rez?= , "linux-kernel@vger.kernel.org" , "virtualization@lists.linux.dev" , "nh-open-source@amazon.com" , Stefan Hajnoczi , Paolo Bonzini Subject: Re: [RFC PATCH 06/12] virtio: add a device memory buffer region allocator Message-ID: <20260810040540-mutt-send-email-mst@kernel.org> References: <20260809182010.32931-1-graf@amazon.com> <20260809182010.32931-7-graf@amazon.com> <20260809181455-mutt-send-email-mst@kernel.org> <6f34275a-6320-4be1-b8e4-b96aa3289344@amazon.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <6f34275a-6320-4be1-b8e4-b96aa3289344@amazon.com> On Mon, Aug 10, 2026 at 07:57:13AM +0000, Graf (AWS), Alexander wrote: > > On 10.08.26 00:38, Michael S. Tsirkin wrote: > > On Sun, Aug 09, 2026 at 06:20:04PM +0000, Alexander Graf wrote: > >> In preparation to support VIRTIO_F_DMB, create a mechanism to allocate > >> and map memory from the Device Memory Buffer (DMB). The DMB is a shared > >> memory region a device exposes and owns. A device that negotiates the > >> feature expects its virtqueues and all the buffers we hand it to live in > >> that region, and every address we publish to it is a byte offset into > >> the region. > >> > >> Add virtio_dmb_init(), which locates the region by the shared memory id > >> the device reports and builds a page-granular allocator over it, and > >> virtio_dmb_destroy() to tear that down. Add virtio_dmb_map_ops, a struct > >> virtio_map_ops implementation that hands out allocations from that > >> allocator as region offsets: alloc() places a virtqueue area in the > >> region, map_page() copies a buffer that lives elsewhere into it and > >> copies it back on unmap. The map operations reach that allocator through > >> a new dmb member of union virtio_map. > >> > >> The shared memory id is transport specific, so add a get_dmb_shm_id() > >> callback to struct virtio_config_ops for a transport to report it. A > >> transport that does not implement it must not accept VIRTIO_F_DMB. Add > >> CONFIG_VIRTIO_DMB to enable this support. It defaults to y, and a kernel > >> that will never meet such a device can turn it off to leave the > >> allocator and its bookkeeping out. > >> > >> Link: https://lore.kernel.org/virtio-comment/20260804161202.38619-1-graf@amazon.com/ > >> Assisted-by: Kiro:claude-opus-5 checkpatch sparse > >> Signed-off-by: Alexander Graf > > > > > > > >> --- > >> drivers/virtio/Kconfig | 15 + > >> drivers/virtio/Makefile | 3 +- > >> drivers/virtio/virtio_dmb.c | 1317 +++++++++++++++++++++++++++++++++ > >> drivers/virtio/virtio_dmb.h | 28 + > >> include/linux/virtio.h | 3 + > >> include/linux/virtio_config.h | 8 + > > > > Really >1000 lines to implement a virtio specific allocator? > > > > Can't we start e.g. with gen alloc and maybe xarray if you > > need some metadata? > > > > > > I guess virtio sync is annoying, it gets handle + offset is that the > > issue? We can fix them though. Or let's just not support them. There > > were there for premapped originally but now it uses page pool. > > > > Maybe I will send a patch to drop sync completely. > > > I started off with gen_alloc. And then over time it slowly morphed into > what you're seeing here when I ran into issues with multi-queue > allocations (split the buffer by VQ pair so that we don't run into lock > contention) and zero-copy vsock transfers (by keeping DMB buffers > statically allocated). > > I agree that it's a bit much for the initial post. How about I revert > back to the gen_alloc variant and we look at the optimizations as > follow-up? Since everything is guest driven, we can play with them as > much as we like in future improvements. > > > Alex Indeed. Or improve gen alloc) -- MST