From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pg1-f201.google.com (mail-pg1-f201.google.com [209.85.215.201]) (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 AFA5A3B1EFC for ; Tue, 12 May 2026 15:56:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778601398; cv=none; b=a9Kx5kd4N3XvEC3xCreOGwq/0l2fLmybN4rO/PK2eenAvOx6fz16y6VvlU0i9tjkD3nNbrjGa0LuWpM/Qa2kO2ElJtXd84wPuyKbBzeejH9YRrXrZtZkEPJKOzg2nwL7OB4XhquHCMGYpwSjzELkMS1BOMe+lFeDwn/GH90Q2ok= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778601398; c=relaxed/simple; bh=yljjG8l8B69MlqrY+w1gCcEq2SscDsa0PKnhEBZTGA0=; h=Date:Mime-Version:Message-ID:Subject:From:To:Cc:Content-Type; b=TVKcEa0ysSFTY/DWmdk2cJpEZYGvos0WcOWepbrseQTK42mJ/0jg7QhtYfJQ5nsEv6j21bAh9KCRbEzY3GNcUWtLspmpcVgM1LL1MIxQ0/EEJeCV/TjgyNiU+IJL1CPtvdKnVjBOX63hkkx/f8ZueWGnnCs+8CGKgq8+ZswDETk= 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=BSOhWgfA; arc=none smtp.client-ip=209.85.215.201 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="BSOhWgfA" Received: by mail-pg1-f201.google.com with SMTP id 41be03b00d2f7-c827ee34adbso1437193a12.0 for ; Tue, 12 May 2026 08:56:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1778601396; x=1779206196; darn=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:reply-to:from:to:cc :subject:date:message-id:reply-to; bh=x4hiTjnHHAawTA+YjwYcN9iXdJb4DuQurxNnuEC+t9M=; b=BSOhWgfAKNRCMIWFgECaMHGu9oA6fhkORaBO8OVfSJfqarLqlhROd7wvb9LdGalqvT b1mUG4OW6648W7Wkm6WwXiQVEHshcHj3oUtqRsoAlXMPe6d1Noy8X0uc0c6SfJ+dRNBR kTwV4YCSQ/WKTUFTZdhrnihcbyUPHf3sN/y9hIWnLKMYbDVbi/LdQkmz33YVK/KfeZJp tY/QoMi+sHo/S0odTqFgQor4xS0YRLa9y8ZZdqtAzfABmZvCmMjLJm41Fr3oYRClBbXa I2v+QgvXxE0WfY9kRPMjysh7u2OAm/4Qx2+yW61T9hmWoAxCV+fS316eIV5VKj2D870A 9x5w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778601396; x=1779206196; h=cc:to:from:subject:message-id:mime-version:date:reply-to :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=x4hiTjnHHAawTA+YjwYcN9iXdJb4DuQurxNnuEC+t9M=; b=WBZDtoJjobiapkGAJfqVa/5LwjNCno2x1PvunBm2ctcKH2SlOgmvwBA7bz2TbaeJ/L hGyB9GSdcn5s1tDR1umexiLC6xIef1AKR91FGYi8oEaf2JZRNBXwppX3GxF+pPNzn5cI tZ847OA0t0V0Nb02dD8dEyvG6BULKujCQAKIFgmOfvuuTPlJEv3KI+LndeC2pTjWn47/ etUaOMGO2QfQ70juvZ4xjFvmzw4c9kErCkl43NRDaEt7Rl8w7rMCbBhs9ZvmlfGrB8oJ LP4xtyZasU1+MDKkKsAaEFavnjSQtcTA6hR1BWbL9+5o5A0sYA022iWs+qAeLhkEol4Y ADnA== X-Forwarded-Encrypted: i=1; AFNElJ/xVnD9Wm+qAk+lD6b0P0RstfNSIPPQsLpwK+fQJYzTW2Zwe1whZcC7qcfuCZxHhUPga1Y0u8Obtgx3/qg=@vger.kernel.org X-Gm-Message-State: AOJu0YyaccjDuYAK4XNxxrZi82H+RhuzlzABgz6BgfJkv4Vm9c79SUDa FLxPAOLo2IORJEldNSDOQW4vx614bat1gt0rQyS8yql2yWrv0TIa/dQ/FxFZWqmyp/tHEZGBEqr dW3n1Ng== X-Received: from pfbkw5.prod.google.com ([2002:a05:6a00:94f5:b0:839:5556:c979]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a00:a90f:b0:838:af72:fb44 with SMTP id d2e1a72fcca58-83cf4f760e7mr22440518b3a.2.1778601395691; Tue, 12 May 2026 08:56:35 -0700 (PDT) Reply-To: Sean Christopherson Date: Tue, 12 May 2026 08:56:34 -0700 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 X-Mailer: git-send-email 2.54.0.563.g4f69b47b94-goog Message-ID: <20260512155634.772602-1-seanjc@google.com> Subject: [PATCH] KVM: selftests: Ensure gmem file sizes are multiple of host page size From: Sean Christopherson To: Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Zenghui Yu , Sean Christopherson Content-Type: text/plain; charset="UTF-8" When creating a guest_memfd file and associated memslot to validate shared guest memory, size the file+memslot to the maximum of the host or guest page size. Attempting to allocate a single guest page will fail if the host page size is greater than the guest page size, as KVM requires that the size of memslots and guest_memfd files are a multiple of the host page size. For simplicity, verify the entire file can be shared between guest and host, e.g. instead of trying to validate "partial" mappings. Fixes: 42188667be38 ("KVM: selftests: Add guest_memfd testcase to fault-in on !mmap()'d memory") Reported-by: Zenghui Yu Closes: https://lore.kernel.org/all/0064952b-048c-455d-ad89-e27e5cb82591@linux.dev Signed-off-by: Sean Christopherson --- tools/testing/selftests/kvm/guest_memfd_test.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/kvm/guest_memfd_test.c b/tools/testing/selftests/kvm/guest_memfd_test.c index d6528c6f5e03..253e748c1d4a 100644 --- a/tools/testing/selftests/kvm/guest_memfd_test.c +++ b/tools/testing/selftests/kvm/guest_memfd_test.c @@ -510,7 +510,12 @@ static void test_guest_memfd_guest(void) "Default VM type should support INIT_SHARED, supported flags = 0x%x", vm_check_cap(vm, KVM_CAP_GUEST_MEMFD_FLAGS)); - size = vm->page_size; + /* + * Use the max of the host or guest page size for all operations, as + * KVM requires guest_memfd files and memslots to be sized to multiples + * of the host page size. + */ + size = max_t(size_t, vm->page_size, page_size); fd = vm_create_guest_memfd(vm, size, GUEST_MEMFD_FLAG_MMAP | GUEST_MEMFD_FLAG_INIT_SHARED); vm_set_user_memory_region2(vm, slot, KVM_MEM_GUEST_MEMFD, gpa, size, NULL, fd, 0); @@ -519,7 +524,7 @@ static void test_guest_memfd_guest(void) memset(mem, 0xaa, size); kvm_munmap(mem, size); - virt_pg_map(vm, gpa, gpa); + virt_map(vm, gpa, gpa, size / vm->page_size); vcpu_args_set(vcpu, 2, gpa, size); vcpu_run(vcpu); base-commit: 6d35786de28116ecf78797a62b84e6bf3c45aa5a -- 2.54.0.563.g4f69b47b94-goog