From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pj1-f49.google.com (mail-pj1-f49.google.com [209.85.216.49]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BD5468F49 for ; Fri, 10 Jul 2026 00:23:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=209.85.216.49 ARC-Seal:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783643016; cv=pass; b=U7/RgUE/67WTm3i8cJKwbi0shGtehQCjX65B/VoQ6gy8aFS95g9zfvrb4j/sUfm9zEdvAuBoxUbdOAwcHkkwofrD/LYDpsbUMpLquYRdjsmYNbRGR3r5CRgT82EZ7zjWQw9QVDaCjcCRW7rKdUJwyI6aZelUfh0L4Qoe8zUP19o= ARC-Message-Signature:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783643016; c=relaxed/simple; bh=hEG9UlASRQUW1/Ek7Bp1focRgkPzyR4Dh5Hvtz1uRIE=; h=From:In-Reply-To:References:MIME-Version:Date:Message-ID:Subject: To:Cc:Content-Type; b=OTuBRAx0zZ0ybqy6tx6B0GoQ0x2/Ndm5DUUiiMh1u3XW/tDUyZ30luUAq7hA8cJPkylXoT7AkNCFwPE1dTjYfQweYpg+NPGravRkAczP0XYfhZnMmtu5SMhmJkjWj3K+wtj7CiCymSYOFNV//U8ux0EU0naZFYvOUdp0rCQjsp0= ARC-Authentication-Results:i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=kAU82VJN; arc=pass smtp.client-ip=209.85.216.49 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=google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="kAU82VJN" Received: by mail-pj1-f49.google.com with SMTP id 98e67ed59e1d1-38d489b6b71so136465a91.0 for ; Thu, 09 Jul 2026 17:23:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1783643014; cv=none; d=google.com; s=arc-20260327; b=mhNXPf9Pnw8NsNgijKazICVObzSZd7HP/OpglRr5docQGQDEZdsy5LcuFOsITEn8sD 8Jw0h0y5DI82YqJZJYNG/UAfDypXv4MogZvAuLawKtDhjbh4iQds5lz7ylSfx0ChTPa3 U0yvnGpgwDhn2DWVIAX9/L+QzJKmO5X7SXwvhchYRxnw7lA68D0GnFGWWI/cGzhg8YvX L+asm09Ua1N+8kPZkAKARbXIW9b7tWwkhwV45LI2FQXI4g4XqnZDE2SLYUlPgGGoYw+d cxwDuBr2O/uhhq0q2aD1qo5y/p6YW+h5M62ZGSFVmSy+sTVaDPETCbEXM5j7R+D54Jfe BTEg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20260327; h=cc:to:subject:message-id:date:mime-version:references:in-reply-to :from:dkim-signature; bh=U4nqKpI/9AfExtjoOB2QAK1s1zSR0lW8GkqUQ83jroc=; fh=j4GP+WL+J6WBWWEb5syjt6/GjnuWXsmZKOg4+9A4lp4=; b=EgQNietsG22+9mwvdek940w3dkKm7Gc1Xdfg6szuzaTILBFWAudDExtBfFE1o/0J/7 dIOeoQJOSmiXrqBpgN0vlEn5Je3L3Acsqr+6esPuvd2IXkW5rr7YO5p9YskX5+5wNLiC tb5UwMR2gi1A+QpuR2QB0CeDUzm2T/XN5mHpnIvSix0ERIc5VGKdYIs5/+tJ16aWPier nJdMsGpf2DUAA7/3K0hyBDib2B/YWh/LRZ32u8IVJt0WCnhlnCG3Nt+ud6MEk8+xWCe9 /X3fBf7KZwxXGevxycpuwnMmhKB2uFu/QNbel/Qa6A/5S4LSSYkTbHOjr9hEcGQWMl8s rheQ==; darn=vger.kernel.org ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1783643014; x=1784247814; darn=vger.kernel.org; h=content-type:cc:to:subject:message-id:date:mime-version:references :in-reply-to:from:from:to:cc:subject:date:message-id:reply-to :content-type; bh=U4nqKpI/9AfExtjoOB2QAK1s1zSR0lW8GkqUQ83jroc=; b=kAU82VJN6GnQD7fDy2z8Y02tdrWxrj6mF9q9SJyshwL3at6QeBg2Jv4iUNQWWaGs3y Z0hQkS3Q96IJm+J7FnJSgkrzBwmFalbAHFpRPZ2AmbPPfSjxN749a44+lOtKocyHbAyR BKBBBwoyKIj3fovr1lGrDM7zdN61nglrq5NzCI2ljX0qSIPiBWn0XcYbr6YWqz/GBHjJ LJPr2CE2RQLEDmMjTwMb0OL8hUIMkRBcUbjCE36T0VJj9+hncKjKrWnq0N6VxbWm5Ly3 abNpySHb1QJZgdVuuoadqXqXjEiwKhSgNjTbpTwyvUrJ1nIY+ThGZwCI5PSCle8kQIhz 9teQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1783643014; x=1784247814; h=content-type:cc:to:subject:message-id:date:mime-version:references :in-reply-to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=U4nqKpI/9AfExtjoOB2QAK1s1zSR0lW8GkqUQ83jroc=; b=KyEa8s/9Oa4Th+uXDzmYnznmIdrq68nv40ttfW6GqHAs0Iz//ybvRxyVPfQbRV2b1C r16pG2254f5VLm2JWBhujQDCiLvljNWWrE5+2/BiV0yeRP/muMJZoN35o5Q/4c/+o9k1 gfI/u06/gZRXMzXYaSKsaW0eKqjw/d4b72HLgIsXwjWAOYjHdPZwVMYKF/OzBi3NHo+X ibC5amLgt9gzoitt0TdocP/x9jOi/OHn/5yWkDT4tWJ4i0BaCwCOKEK24mDQRA2Yo8Q9 SWoobYxd/4t/JnumhV0VI+6y/4mIVhgV//jwilYpwlIxNNLjgyh+8KmhYVJaDpUTFVro 238g== X-Forwarded-Encrypted: i=1; AHgh+RqyL9jGybEm6N80H4qkvon0dvyi4JWGfHpe0lSlYZ6dAxLEG1yJQsfVKCY+emJOuyQ+nB5HW5oRHPPFXn0=@vger.kernel.org X-Gm-Message-State: AOJu0YxxBjpEzQE4hf0hDAHsLfkRksjm5NsscCxBretaM9dRRraqjm97 GzcryNpmTzZfi5QYGf0sOPda6lvj4xmCx6sZcmBfJHYwrO2+nSqAbpbw3LiIDr2pNb0imVLtnCY RRJR78QHbLb0E3aJuqCVEfpJvPaPXGbjMsyd99cg9 X-Gm-Gg: AfdE7cm3mHhOEJpjdAoGHcRB+iyQLBJ2IpuFMPWlUELClaIyfdwfZ70XRL9c3UToSVE eVtlFi/Umg+5QchKc6Qp4aGax4Dkgpmlz6sqmBhmMnQXwdgLe9Y98VADyoxLJVDA4U2AGX4g1MJ waqzRa2VOahwE1SLwsZ2miR+wKB+YBjASHQ0DvxJnd+1CcqZfvKUxPnDY7jmhtJKuXXeyr/VdJt zNzfjHgeUINZeq0tKKN1rH0RUgoUKZU8s0PluGMw1fJt121uo5gDV6SG9bf3yE42NPFkcoUm1lC gZwGhmDvPvdGl9DcOMeNaFKiWt5wxgtDQ5ma1yfGPWfja/WBkHF4LbUHH0RyEOrNrVuGeA== X-Received: by 2002:a05:6a20:d708:b0:3bf:e761:6285 with SMTP id adf61e73a8af0-3c0bc9e3763mr11182161637.29.1783643013610; Thu, 09 Jul 2026 17:23:33 -0700 (PDT) Received: from 176938342045 named unknown by gmailapi.google.com with HTTPREST; Thu, 9 Jul 2026 17:23:32 -0700 Received: from 176938342045 named unknown by gmailapi.google.com with HTTPREST; Thu, 9 Jul 2026 17:23:32 -0700 From: Ackerley Tng In-Reply-To: <20260709204948.1988414-17-seanjc@google.com> References: <20260709204948.1988414-1-seanjc@google.com> <20260709204948.1988414-17-seanjc@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Date: Thu, 9 Jul 2026 17:23:32 -0700 X-Gm-Features: AVVi8CeiGn97SLpqHdPUtNb7ZMExMtOy6pIhGUUKZCGIJyopDpeEsz4KwUOJXIM Message-ID: Subject: Re: [PATCH v4 16/18] KVM: guest_memfd: Explicitly pass number of pages to kvm_arch_gmem_prepare() To: Sean Christopherson , Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Michael Roth , Hyunwoo Kim , Tom Lendacky , =?UTF-8?B?SsO2cmcgUsO2ZGVs?= , Fuad Tabba Content-Type: text/plain; charset="UTF-8" Sean Christopherson writes: > Tweak the guest_memfd prepare() hook to explicitly pass the number of pages > to "prepare", so that the prepare() and invalidate() hooks can be combined > into a single convert() hook, and because the existing code is outright > broken if a guest_memfd folio is comprised of more than one page (which > can't happen, yet). guest_memfd aligns the pfn down, and the SNP code > *tries* to create a corresponding huge entry, but if the RMP must use 4KiB > entries for whatever reason, KVM will only "prepare" the first pfn, and not > the actual pfn that needs to be converted/prepared. > > Alternatively, @max_order could simply be repurposed as _the_ @order, but > that will fall apart when in-place conversion comes along, at which point > KVM will need to deal with conversions that aren't strictly bound to a one > folio. > > Note, kvm_gmem_prepare_folio() still mishandles hugepages, as it aligns > only the pfn, i.e. would pass the wrong gfn+pfn pair. This will be fixed > shortly. > > WARN in the SNP code if the number of pages to prepare is anything other > than '1', i.e. if guest_memfd is trying to prepare/convert more than a > single 4KiB page, as sev_gmem_prepare() doesn't actually handle conversion > greater than order-0 folios. > > Opportunistically convert the existing WARN in the prepare flow to a only > fire once, e.g. so that a guest_memfd bug doesn't unintentionally Dos the > kernel by spamming the log. > > Fixes: b85524314a3d ("KVM: guest_memfd: delay kvm_gmem_prepare_folio() until the memory is passed to the guest") > Signed-off-by: Sean Christopherson > > [...snip...] > Reviewed-by: Ackerley Tng