From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.167.200 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1793069804; b=aZn2oAbeW+yHejauksfinMF3MIVNu90G5ia5W+BEfuthvCXc0VGl9C+j22t1KSBN8GuQ vjHwuHlW6piqZ1qqKWsaMhBWef/PAC73rLW8Fo6FpdyVi6FKl4r+060SvNxA/6j2MFani EVZ8LXEKZlQw5cmTyU3KZrZQ8mpwTOCjmMBxf0eZsKCJG1By0JRuGQLny7YVv/AGLNDyD sJPwsP7An6pAEFiwmYtmI9J7A/2Kcidj563W1Mnj8s7jr3Y56bJaBj10iyZ+84cYElWfw fk+SUTHST0MExqN6BYnHV/An2/UYnn7D9u8hVIGYD3k64Hciw1j4ix/ts5783md7tcA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793069804; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Received:Date:In-Reply-To: Mime-Version:References:X-Mailer:Message-ID:Subject:From:To:Cc: Content-Type; bh=0uzqgwftXz/DV+yjf2QpwILGgyMTBZAoH8uvJ/r3lMk=; b=s5dliRCAnZYyZb+TzwLpJhoI7jA6C5sKdBQ9lUTjzins17h3gAX653PUhkMkw2qXltGm P4Aozk2GYClSCv7RtIS4j0Bhq2UHie3NqsJNZt7YVyukkprglwGrOxnntYCBf8NLvxoFW qGxsXfbRM8svX/zW4PSueoKO+mbWRGjhnYx1YZUxNATsHFmYDGpOVlgRfh3aXYfZxKnQK z6osOz4COfT7rSA5qb2i+G0R88j0kwEUOzQfA/uRn/4/6SgJOjbg5VkblQ6WC6EqoU8Sa c/oWRVC4X94J78PeeX9zq9RlbRGSiinNEEazIGiX+XG8DPCiuY4pLJEPeIgk1iLGCgA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=google.com; spf=pass smtp.mailfrom=flex--kevinloughlin.bounces.google.com; dkim=pass header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20251104 header.b=jHa9QGYh; arc=none smtp.remote-ip=209.85.167.200 Received: from mail-oi1-f200.google.com (mail-oi1-f200.google.com [209.85.167.200]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 29F06606A31D for ; Tue, 27 Oct 2026 02:56:44 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 29F06606A31D Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--kevinloughlin.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20251104 header.b=jHa9QGYh Received: by mail-oi1-f200.google.com with SMTP id 5614622812f47-4dab94dc3e7so5879414b6e.0 for ; Mon, 26 Oct 2026 19:56:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1793069803; x=1793674603; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=0uzqgwftXz/DV+yjf2QpwILGgyMTBZAoH8uvJ/r3lMk=; b=jHa9QGYh9X3IBMWXkVkIZOr+NsAFmipaU5nggTwDXLj19FELj902baUVTGkipnWe3Z E4YZQ8TxciuXuQz58f+GelwdXWhuaE1csqWkcUYit0yhtY3cs13AAznyIIJwRng05sIA dDLIKjP1s3OIxvq1+pkTXmok3LQQ3CsC2+i+riY33euyquXpE5vQOAcNeLQqZAvA4NrE dxZ5zftFUUltE6+LpVpQckECMQvhny7+11Us+5m4MzTr90U15pxueHcoQunGP9fGIR9C PfhgiYxrTvcpf6LtkGUVz8yVM4+dxa3yBWz5k6iPbmkgkYQW0oetuRTN1CWQtvxBh1Ep 8YLg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793069803; x=1793674603; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=0uzqgwftXz/DV+yjf2QpwILGgyMTBZAoH8uvJ/r3lMk=; b=JSS7y/lHaItdVBjPW+tm4Gtyc9uGJUtlMv6UENiy2OjXfrpLXKHjmi/ouXBTOy6t5o vvO9NXZj5Py7ARYVf1pKRJ9j2iDMtNRLjx0ji3s4j0uwtCosB50bmpFXlxCzc16UZaCB Q6ywaSokzkctChizDENK2ZbT/h2bXWgsSEVhS7vAzK54p5QiXRpobgdMPv+iHMtDMHzj zJ7Petm5/jb+kYK9Oeok4Ipu1ktj3+i9WddZvLURKfXqbIFuRCP6mGBvoO72sgUffKqR rJ78FyMUiFjB8kENkqRuovhwAozVkHguEgu+zdyCuqwYDv2p/zxmsh7kZbZe8DJHAbh8 2jFg== X-Forwarded-Encrypted: i=1; AKwUvBwcgO/XfhRRExYY2McxJlyctiGIoN4qqIEynPWtkF4HDZkP3Zs/B8JNYjYSAEmyjexnMsbJ0WY8RrOeL8g=@vger.kernel.org X-Gm-Message-State: AFq9FYKf9KgAD7lvbx4/R5HzzoMudTI0Ogju/kJlmfXOM8cuoq3GZO0Q /3HMcu4fctz/0RQFVv2ko6ry7DFBmlTOdrQ8mBA+ZryyzwYV5M/OxeFtKB/QBBc7C1iQI4qKjMy Kfbgf63ywphev8mEenj2B7sDrCliT7YJVfw== X-Received: from ioxz3.prod.google.com ([2002:a05:6602:17c3:b0:9c7:733a:80ab]) (user=kevinloughlin job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6808:448b:b0:4ea:14ab:142d with SMTP id 5614622812f47-55c002fc7b3mr5525425b6e.40.1793069802970; Mon, 26 Oct 2026 19:56:42 -0700 (PDT) Date: Tue, 27 Oct 2026 02:56:05 +0000 In-Reply-To: <20261027025616.1632690-1-kevinloughlin@google.com> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Mime-Version: 1.0 References: <20261027025616.1632690-1-kevinloughlin@google.com> X-Mailer: git-send-email 2.56.0.307.g5fe7bd680c-goog Message-ID: <20261027025616.1632690-3-kevinloughlin@google.com> Subject: [PATCH 02/13] virtio_balloon: add reporting_vq DMA map ops From: Kevin Loughlin To: "Michael S. Tsirkin" , David Hildenbrand , Jason Wang , "=?UTF-8?q?Eugenio=20P=C3=A9rez?=" , Xuan Zhuo , Ard Biesheuvel , Kiryl Shutsemau , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , Tom Lendacky , Ashish Kalra , Michael Roth , Rick Edgecombe , Andrew Morton , Vlastimil Babka , Mike Rapoport , Suren Baghdasaryan , Michal Hocko , Brendan Jackman , Johannes Weiner , Zi Yan , Alexander Duyck Cc: virtualization@lists.linux.dev, linux-coco@lists.linux.dev, linux-efi@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Sidharth Telang , Punit Salian , Peter Gonda , Ackerley Tng , Jacky Li , Steve Rutherford , David Skidmore , Kevin Loughlin Content-Type: text/plain; charset="UTF-8" In confidential computing guests where VIRTIO_F_ACCESS_PLATFORM is negotiated, the standard DMA mapping layer rejects mapping unencrypted or swiotlb-bounced scatterlists when reporting large free page blocks through reporting_vq. However, the host VMM only inspects the guest physical address and length of reported free page ranges in the virtqueue descriptor table and never reads or writes the reported guest memory payload. When guest memory encryption is active (CC_ATTR_GUEST_MEM_ENCRYPT), attach custom per-virtqueue mapping operations (balloon_reporting_map_ops) to reporting_vq that translate scatterlist entries directly to guest physical addresses without allocating swiotlb bounce buffers or decrypting guest memory. Signed-off-by: Kevin Loughlin --- drivers/virtio/virtio_balloon.c | 56 ++++++++++++++++++++++++++++++++- 1 file changed, 55 insertions(+), 1 deletion(-) diff --git a/drivers/virtio/virtio_balloon.c b/drivers/virtio/virtio_balloon.c index ab3e3d887e00..11f74848fdc4 100644 --- a/drivers/virtio/virtio_balloon.c +++ b/drivers/virtio/virtio_balloon.c @@ -19,6 +19,7 @@ #include #include #include +#include /* * Balloon device works in 4K page units. So each page is pointed to by @@ -580,6 +581,55 @@ static void update_balloon_size_func(struct work_struct *work) finish_wakeup_event(vb); } +static dma_addr_t balloon_reporting_map_page(union virtio_map map, + struct page *page, + unsigned long offset, size_t size, + enum dma_data_direction dir, + unsigned long attrs) +{ + /* + * Free page reporting transfers physical address and size metadata + * via vring descriptors; the device/host never accesses or transfers + * data on the page itself. Return the true physical address without + * DMA mapping / bounce buffering. + */ + return (dma_addr_t)page_to_phys(page) + offset; +} + +static void balloon_reporting_unmap_page(union virtio_map map, + dma_addr_t map_handle, size_t size, + enum dma_data_direction dir, + unsigned long attrs) +{ +} + +static void balloon_reporting_sync_single(union virtio_map map, + dma_addr_t map_handle, size_t size, + enum dma_data_direction dir) +{ +} + +static bool balloon_reporting_need_sync(union virtio_map map, + dma_addr_t map_handle) +{ + return false; +} + +static int balloon_reporting_mapping_error(union virtio_map map, + dma_addr_t map_handle) +{ + return 0; +} + +static const struct virtio_map_ops balloon_reporting_map_ops = { + .map_page = balloon_reporting_map_page, + .unmap_page = balloon_reporting_unmap_page, + .sync_single_for_cpu = balloon_reporting_sync_single, + .sync_single_for_device = balloon_reporting_sync_single, + .need_sync = balloon_reporting_need_sync, + .mapping_error = balloon_reporting_mapping_error, +}; + static int init_vqs(struct virtio_balloon *vb) { struct virtqueue_info vqs_info[VIRTIO_BALLOON_VQ_MAX] = {}; @@ -641,8 +691,12 @@ static int init_vqs(struct virtio_balloon *vb) if (virtio_has_feature(vb->vdev, VIRTIO_BALLOON_F_FREE_PAGE_HINT)) vb->free_page_vq = vqs[VIRTIO_BALLOON_VQ_FREE_PAGE]; - if (virtio_has_feature(vb->vdev, VIRTIO_BALLOON_F_REPORTING)) + if (virtio_has_feature(vb->vdev, VIRTIO_BALLOON_F_REPORTING)) { vb->reporting_vq = vqs[VIRTIO_BALLOON_VQ_REPORTING]; + if (cc_platform_has(CC_ATTR_GUEST_MEM_ENCRYPT)) + virtqueue_set_map_ops(vb->reporting_vq, + &balloon_reporting_map_ops); + } return 0; } -- 2.56.0.307.g5fe7bd680c-goog