From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f202.google.com (mail-pl1-f202.google.com [209.85.214.202]) (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 26B3D4343E8 for ; Thu, 9 Jul 2026 20:50:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.202 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783630211; cv=none; b=rLY7d+31acrrOuCPWgo9pnfZgIZhxuY0FBZ85gieeSLMnKE699v2wQ3voWjS6SZkMlFtkuG93eftHcmNqtRVRrnTjcMTkp4GEAwHbQUEPrEMCdS8kT4gk6PibWCA7s5+vWPhgh5yaUtg/5Nl4ta8g185rT3vZpE44HR5x0BMFFA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783630211; c=relaxed/simple; bh=sN7EOmhfbdWWBf6tg/SVHJ9RGHkeFOcz/Gn/S9KQhZs=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=Od6xpXxxBH5+2wAiBgkjC3c2CXOceht02aVOY6cHQD3V3CRQnCXdziflP3GgYhYBtFhDd+ZEdsKYNQdicsy2AC6ZPfRYnS+jj0MLlRGoQsOKXuiHGzmk8NzvZw8mPMQpHrOgXCpZYmcApK6w7DLPhVfoACVoblEiVefJKd/PUp0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=uJdA/f1V; arc=none smtp.client-ip=209.85.214.202 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--seanjc.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="uJdA/f1V" Received: by mail-pl1-f202.google.com with SMTP id d9443c01a7336-2ccf43f7a99so2806645ad.2 for ; Thu, 09 Jul 2026 13:50:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1783630209; x=1784235009; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:reply-to:from:to:cc:subject:date:message-id :reply-to:content-type; bh=U+3Iis0sU29jrcmmXd/DJV03ZbZygojCmBlJWK/r8Oo=; b=uJdA/f1VUsxPHyQwt7vNaRhWRMx8Vjlz3kBp47RSSbxV/JiWTPJfm5OCjAttUbZgVz dx3SjJEPfToO43Bsyxp9C6tX2KU9aavADSU8lMPidgcPuK4xiypK9yjdNXYoeSvJP/E8 qa2S+V97e4QfIqwadMFKBuAcQuvRlCGIsKWLSGKU81WE4txv4iXUg1d57gJZC5pW8YDd V7XaV3O24Ptm615dKybO2OZD74kPvoGOYEashuhyIl6Ktj/VyJmCWgQ9jcI6Eu9Fvj7f SnjBMf+0HQwSmV9O20qR6t79R/my6JAxYQFlE8CZ7TtYktTtrkn3qwvDZOy9db2tE1t2 x0Rg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1783630209; x=1784235009; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:reply-to:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to:content-type; bh=U+3Iis0sU29jrcmmXd/DJV03ZbZygojCmBlJWK/r8Oo=; b=R8pak989AMSx5vgK8EtGc4PZ1UTqKj5B29FLyDqG9joFX+PoiVEyN80qKjAICn7vxt VJRg+BstZtuVMUBHuMO7gaRKTe8ygzCY+Ro0twuS9rgL67GOn+snjtiWgfjuBOgdHgrU xfZkNvL+FixwAnBuy4/M9sDD9OgFsalndhZybWfr7EtlQVb6XGqnfzE/N1+M8w5heZrY tf1DalLlZoc1oB5f4F205NcDR2D0uqIyII9/vYHWl/ju7gOH8S+NmyWLzgtS1dgwA9m0 dKkRA3eFN1OZ1um6lHBMja/CDI94s34zT8QQo9crxC8135HF3VV5v6H1husxwXqTFVTg c85w== X-Forwarded-Encrypted: i=1; AHgh+RqlvKUnhAb8MPGprAbTDGwHnnx6ByJ05xqLe/bLjF6KeQRphfxK+31h+zcMhZLtdfKZYP98xUUUWbMi/Os=@vger.kernel.org X-Gm-Message-State: AOJu0YwBlfxdSMUvERTIEld2EyXZJ44XdBhQhyRDhPMbshJKP3pBJFO9 +0lXDdI730scNbgVTBBm+qjJvAcXAr4HHX8OHKCwjM6atccu684F5gw7wNEwFvl4H4KLKSUrbrD tWS7TmQ== X-Received: from plsr16.prod.google.com ([2002:a17:902:be10:b0:2c8:219a:17e8]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a17:903:b83:b0:2c6:9f66:d573 with SMTP id d9443c01a7336-2ccea373102mr99680565ad.2.1783630209448; Thu, 09 Jul 2026 13:50:09 -0700 (PDT) Reply-To: Sean Christopherson Date: Thu, 9 Jul 2026 13:49:47 -0700 In-Reply-To: <20260709204948.1988414-1-seanjc@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260709204948.1988414-1-seanjc@google.com> X-Mailer: git-send-email 2.55.0.795.g602f6c329a-goog Message-ID: <20260709204948.1988414-18-seanjc@google.com> Subject: [PATCH v4 17/18] KVM: guest_memfd: Align the gfn as well as the pfn when "preparing" a folio From: Sean Christopherson To: Sean Christopherson , Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Michael Roth , Hyunwoo Kim , Tom Lendacky , "=?UTF-8?q?J=C3=B6rg=20R=C3=B6del?=" , Fuad Tabba , Ackerley Tng Content-Type: text/plain; charset="UTF-8" When preparing a guest_memfd folio, align the gfn as well as the pfn, i.e. preserve the effective gfn+pfn pair provided by the caller. If the folio is larger than order-0, aligning the pfn but not the gfn would create a mismatch set and unintentionally crash the guest due to assigning the pfn at the wrong gfn. Fixes: b85524314a3d ("KVM: guest_memfd: delay kvm_gmem_prepare_folio() until the memory is passed to the guest") Signed-off-by: Sean Christopherson --- virt/kvm/guest_memfd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/virt/kvm/guest_memfd.c b/virt/kvm/guest_memfd.c index cd7a795834cb..4082cde3f3fc 100644 --- a/virt/kvm/guest_memfd.c +++ b/virt/kvm/guest_memfd.c @@ -87,8 +87,8 @@ static int kvm_gmem_prepare_folio(struct kvm *kvm, struct kvm_memory_slot *slot, * checked when creating memslots. */ WARN_ON_ONCE(!IS_ALIGNED(slot->gmem.pgoff, nr_pages)); + gfn = ALIGN_DOWN(gfn, nr_pages); index = kvm_gmem_get_index(slot, gfn); - index = ALIGN_DOWN(index, nr_pages); return kvm_arch_gmem_prepare(kvm, gfn_to_gpa(gfn), folio_file_pfn(folio, index), nr_pages, -- 2.55.0.795.g602f6c329a-goog