From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.167.199 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1793069820; b=wmg8LRc4BbQWG17IGTc28SfaOUlfJ7nfonCp0Uq1zVpUEqpUirJzseM1iBh1ALHWVrUe Eb6L2OPvkFuFEfd4MKVkmZX1N7muyrr+cuxTbN99xGiYLFwhO+lNAHPFyQgP7WO7oZbRC cJUPo4IkuXeSgu3qTeYetRdfS5RskFoKgpO2H+xtLPKCtDoTA93clgK6Bkz+r9gllQZVJ jmWoE3HSuqxK2suK/QuznM9pGtnb+CWdfJh/E7DvNXaTgSYIz3ac4Awqsz3zC0oD+WObq TIMYQE6Fw5iQ3iK5JPmC3YCcJsQo+bMKPQiAyNZjlFha9rey8SJ1IORRx4TgsmcgK3A== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793069820; 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=j+w6uCJntt3i4Wr5zbmAS2QfetxR0x7f970do0XgFlo=; b=LAedJ9JGus2OYgyLuhoku0b14sZ4hwnRj2vPI4QmqVMP+FMd3nRNnyukdiaXsR2aPrZU 464YoT601dC/+Av4OiVIZjopG4y/kVr2wnQ5CabvfLGMvTD57vANsyKfc6QQp/ItYC1l6 GfzBKz5AIYqMd5a8gwGygClrCWbUGU1Oioz+AkG1DFOuY7zazsRHtguUfJIhVncFjS1cH Dlct9TWUVEQxxXXaNDspcd8JOcItvmIIQLRvYwHdzMP/6VrxJDiknygzx9UKe2oMCVWIa mDXNtxO9uGjLDhKFT56GCAq6+xRnUeLs7HZC8wE98pC/avMxdjIjhlDUKPVdQ6VdI1g== 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=uNMzfIBd; arc=none smtp.remote-ip=209.85.167.199 Received: from mail-oi1-f199.google.com (mail-oi1-f199.google.com [209.85.167.199]) (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 B0A6160A3808 for ; Tue, 27 Oct 2026 02:56:59 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org B0A6160A3808 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=uNMzfIBd Received: by mail-oi1-f199.google.com with SMTP id 5614622812f47-4c734afb8deso5325517b6e.1 for ; Mon, 26 Oct 2026 19:56:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1793069819; x=1793674619; 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=j+w6uCJntt3i4Wr5zbmAS2QfetxR0x7f970do0XgFlo=; b=uNMzfIBdZgy1KN8bFNHYHiLLIV46Yma9kQMtlPcXXX7T7zwVL/i/+ib96FOmt5+WL3 n1BuyeykqhM2dDAsutuCqTP+qaiftM6tMCYKdeJxOT/dhgZwRud9ipglpmeLiyTc2X1K trU8END+WQoLb46jffScMCnl6ZaLswuyFEfQ0qimov7DpefFYqEY4EM3GQ9FGU+z13w2 5WY6rE8qRK944Oq/DAzAyWIAnyog/b7XYFMymQ3u0W56oB/57ya5y9/wV0rmw651EsJU VRu7dz10YDkmjpEPcQtLIH7lbGZBUZ2HxvVB2BMakZ1BxsJMI14d2hx6PFe3ifCr5r38 SYzg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793069819; x=1793674619; 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=j+w6uCJntt3i4Wr5zbmAS2QfetxR0x7f970do0XgFlo=; b=EzJQVSGDyy9clT3uZviftccWCXzCqbsii/dKMbVUP0sp0u63FCP8bjzhkYhxYHIIl6 H+m9VdF65Sw+Z05cfGMBI+ZF24u4PnDjJQg5kWOb3sxNefN2WLFhWKqta7cvOV/+qW8H pL1AhOyp9m7k1uSq/IVyHyBEZ9y3dU2BcOnitmzhC9uJjJ+s53at/xT4ukuP0VZUif7r hvly4INi7HL6KT4d7InRchlNwPBA/nIidIOppAalV20t3I/zCn/1dRStqAyIDt5R3b9E Vifkns3SA2/ke6p3e6+2oyfsJ7q41jL+BnxNPtc7cnT/Z23UNq8PqWblYXkD7GPVTvZA AABg== X-Forwarded-Encrypted: i=1; AKwUvBxpGZfT8ShrHP+JdSrjOc5nMih2wc9RKTtjdRsoP91nKHsifpgHhpuK3dRSRUiTnljbpcAOzoi6Ju/kzmo=@vger.kernel.org X-Gm-Message-State: AFq9FYJqmTCn065I4mF/QgB4eYgOBeunuYsAV8JQ2f63pNFmcG+O5V0M SJTXNn/hsZc/fhzVlCoxduDHZVPar2QlaC8XrMyv0XIXLSIzx00NRwFMC4FzuS1IQn6sRz8119U Cm7yJaTFk/4qWRIE+KTzHWiUirbo40DIN3Q== X-Received: from ioo6-n2.prod.google.com ([2002:a05:6602:8646:20b0:9c7:5a22:a4be]) (user=kevinloughlin job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6808:1b2b:b0:4f4:73a9:f853 with SMTP id 5614622812f47-55bfff91bbdmr5294378b6e.1.1793069818445; Mon, 26 Oct 2026 19:56:58 -0700 (PDT) Date: Tue, 27 Oct 2026 02:56:14 +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-12-kevinloughlin@google.com> Subject: [PATCH 11/13] virtio_balloon: unaccept free reporting ranges 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 with dynamic unaccepted memory transitions, configure the free page reporting order to unaccepted_memory_order(). Invoke mark_memory_unaccepted() on each scatterlist range in virtballoon_free_page_report() before adding the scatterlist to reporting_vq and kicking the host. Unaccepting the pages prior to virtqueue_add_inbuf() and virtqueue_kick() guarantees that the guest finishes PVALIDATE(validate=false) before the host VMM can observe the reporting request in the virtqueue ring and punch a hole in guest_memfd, eliminating any race where the guest re-allocates and re-accepts a page before a deferred host hole-punch executes. Signed-off-by: Kevin Loughlin --- drivers/virtio/virtio_balloon.c | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/drivers/virtio/virtio_balloon.c b/drivers/virtio/virtio_balloon.c index d162c162b496..e10bd792ef7c 100644 --- a/drivers/virtio/virtio_balloon.c +++ b/drivers/virtio/virtio_balloon.c @@ -213,7 +213,26 @@ static int virtballoon_free_page_report(struct page_reporting_dev_info *pr_dev_i struct virtio_balloon *vb = container_of(pr_dev_info, struct virtio_balloon, pr_dev_info); struct virtqueue *vq = vb->reporting_vq; - unsigned int unused, err; + unsigned int unused; + int err; + + if (virtballoon_cc_needs_state_transition()) { + unsigned long unit_size = PAGE_SIZE << unaccepted_memory_order(); + struct scatterlist *sgl; + unsigned int i; + + for_each_sg(sg, sgl, nents, i) { + if (WARN_ON_ONCE(!IS_ALIGNED(sg_phys(sgl), unit_size) || + !IS_ALIGNED(sgl->length, unit_size))) + return -EINVAL; + } + for_each_sg(sg, sgl, nents, i) { + err = mark_memory_unaccepted(sg_phys(sgl), sgl->length); + if (err) + return err; + cond_resched(); + } + } /* We should always be able to add these buffers to an empty queue. */ err = virtqueue_add_inbuf(vq, sg, nents, vb, GFP_NOWAIT); @@ -1142,8 +1161,11 @@ static int virtballoon_probe(struct virtio_device *vdev) * host's base page size. However, it needs more work to report * that value. The hard-coded order would be fine currently. */ + if (virtballoon_cc_needs_state_transition()) + vb->pr_dev_info.order = unaccepted_memory_order(); #if defined(CONFIG_ARM64) && defined(CONFIG_ARM64_64K_PAGES) - vb->pr_dev_info.order = 5; + else + vb->pr_dev_info.order = 5; #endif vb->pr_dev_info.capacity = capacity; -- 2.56.0.307.g5fe7bd680c-goog