Received: by 2002:a05:7412:3b8b:b0:fc:a2b0:25d7 with SMTP id nd11csp2944245rdb; Tue, 13 Feb 2024 01:55:25 -0800 (PST) X-Google-Smtp-Source: AGHT+IFdmdBcpHsy91eE7TIXR4dvm0LoHZYjGYfNUpA+bKfza+REQmALzm35vaQgS+d1FZ4i6gcE X-Received: by 2002:a05:620a:28ca:b0:787:18bc:52bb with SMTP id l10-20020a05620a28ca00b0078718bc52bbmr2287680qkp.20.1707818125565; Tue, 13 Feb 2024 01:55:25 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707818125; cv=pass; d=google.com; s=arc-20160816; b=FIPv/gUPRkMjaO6DmLd3J20o3enXzDNw6ZPPBPIkR5Z5gv0B+bplwsDfCR8popUAUW ES4M8jyMaQJTRAEX+CuUIqfL47/4GoqxIxxq7f4Vr3+Z7mRoH8Vhlr3PII0iLwe4G2ih liEYuzIo2Uj1liUbSBslTsNsCO3+SUXxT49x0hJxdvTO+r66GsH8Xe2N2AcvsRSsOEOO 668AxvMirH2elGONYZ0VPFMtexym7pQL0h5zOwE2JjGQwW+AdgQPIjMF9bakgtiJNIaQ hQgdtUMVViZ8Mf1d64MIb4dMBt80d2VZf4U3A1ddem88sMrHyU/0RRTCt2bvDEZ6BafQ vFfQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=TIA8t073Y1mWOrzngK+gZq8Rv9Ku8mU359Al0v0ZlVo=; fh=nbcJsW9dFfSJdZhfSjqnlCwQJao+FLGNJdeTN6Be9Yk=; b=e2bESbm5suHkxsrqZQWYcZiuQtPDDIpS9wPcnrxSM5ZI6EsIOkjM8tPOFDdkesXXEw g2CtE6ZkWbVVMDYHo/7IXdlH1PrPCXEUeGoNtasthqUueJxRYfhPbFH+Ha3EPhkIJNsd cECTu4VfW7R56YwuQYwVtyFCofVnU0jBM0cJY2GC78GK788GENxIeQ1e7UTEL6cMY7iW bix006k/C0MbIuPnXn4bZghGp2nAQZ4MSPYNJ/fN7TqiJpePfG1ns4faRRSyf550CNuO 2UWNCjiRpK1EYg0VJalczQAzvr6hk89hYh1Grx4JMGexf7MzqpRhJd7XA1gn5cz0kwaj T3NQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=pDp7fdCA; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-63258-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-63258-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev X-Forwarded-Encrypted: i=2; AJvYcCUuDEE5lJlZlocFtgi3yNqnMQEHWwQ1JD3WHcL6f9FJ5Wbot1DZyvl9FFvLxnZ6vA1q1VF3TzZo2bzUecPb2wvwNMBJVntR2HuoGQbe9w== Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id g17-20020a05620a109100b007830f79571fsi7850867qkk.436.2024.02.13.01.55.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Feb 2024 01:55:25 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-63258-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=pDp7fdCA; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-63258-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-63258-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id C9B551C26415 for ; Tue, 13 Feb 2024 09:50:58 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 297D2535DA; Tue, 13 Feb 2024 09:43:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="pDp7fdCA" Received: from out-174.mta0.migadu.com (out-174.mta0.migadu.com [91.218.175.174]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7C6E2535BD for ; Tue, 13 Feb 2024 09:43:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.174 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707817399; cv=none; b=OQYHbgtvvuSc6WZxma5Dabp8AIjNUahdqeRV0wFye8Dd0KJkHHpLoC6J7K5lHhLP5NjayqgFrT6V4tQIJ7xpIfFuEIp4bnk8eoLwFfVWOKTly2onE1e5hieA6udDZV1QGcV0FGMQEgWQCkaQf2W9qgMwcekhI9bkCA6humRLKag= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707817399; c=relaxed/simple; bh=Sv6AJeH0Hx+RUsbmtZwuRTSHKGXUdMSy3gQCRocBC3I=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=desjWchIvPuMZHVHF1u1xW0hJ2O/YWADHriHZhI8heHuctNFzPyPXlTM4mxhm+/FlWfZD1JALBdZ6dN1COIOOvP8LNz2Hem8iSTGVe/pUMzyTTPQJYXOPQfZTZm2kdvfdKnI7Fz9CoYVWYS78hWQ1Gm77DVTf8ycXw/Kt+H8YLk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=pDp7fdCA; arc=none smtp.client-ip=91.218.175.174 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1707817395; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=TIA8t073Y1mWOrzngK+gZq8Rv9Ku8mU359Al0v0ZlVo=; b=pDp7fdCAMJlgD8V76p/DKAEGmrfeT7I2UsWQvoLbAaKNLUT9y01KmaCeMZdTpFeS02R0Le JVNt7gKRp/mnkRddNuxjDZBgW/UEcqz04+uryRzYc036wRnehgDSRuyyN6abFiNmhdWvYG pcDSvuPC0fY3JGpzB25sF9KUkpP1R6w= From: Oliver Upton To: kvmarm@lists.linux.dev Cc: kvm@vger.kernel.org, Marc Zyngier , James Morse , Suzuki K Poulose , Zenghui Yu , linux-kernel@vger.kernel.org, Oliver Upton Subject: [PATCH v2 22/23] KVM: selftests: Hack in support for aligned page allocations Date: Tue, 13 Feb 2024 09:43:03 +0000 Message-ID: <20240213094303.3962318-1-oliver.upton@linux.dev> In-Reply-To: <20240213093250.3960069-1-oliver.upton@linux.dev> References: <20240213093250.3960069-1-oliver.upton@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT Many of the memory allocations handed off to a GIC ITS require 64K alignment. One would think that requesting 64K of pages would follow natural alignment in selftests (much like alloc_pages() in the kernel), however that is unfortunately not the case. Add a new helper to allow a caller to decide if they want naturally-aligned page allocations. Deliberately avoid making this the default in case this subtly breaks assumptions or memory overheads in other selftests. Signed-off-by: Oliver Upton --- .../selftests/kvm/include/kvm_util_base.h | 2 ++ tools/testing/selftests/kvm/lib/kvm_util.c | 27 ++++++++++++++++--- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/tools/testing/selftests/kvm/include/kvm_util_base.h b/tools/testing/selftests/kvm/include/kvm_util_base.h index 9e5afc472c14..750638cfa849 100644 --- a/tools/testing/selftests/kvm/include/kvm_util_base.h +++ b/tools/testing/selftests/kvm/include/kvm_util_base.h @@ -830,6 +830,8 @@ vm_paddr_t vm_phy_page_alloc(struct kvm_vm *vm, vm_paddr_t paddr_min, vm_paddr_t vm_phy_pages_alloc(struct kvm_vm *vm, size_t num, vm_paddr_t paddr_min, uint32_t memslot); vm_paddr_t vm_alloc_page_table(struct kvm_vm *vm); +vm_paddr_t vm_phy_pages_alloc_aligned(struct kvm_vm *vm, size_t num, + vm_paddr_t paddr_min, uint32_t memslot); /* * ____vm_create() does KVM_CREATE_VM and little else. __vm_create() also diff --git a/tools/testing/selftests/kvm/lib/kvm_util.c b/tools/testing/selftests/kvm/lib/kvm_util.c index e066d584c656..60948a004012 100644 --- a/tools/testing/selftests/kvm/lib/kvm_util.c +++ b/tools/testing/selftests/kvm/lib/kvm_util.c @@ -1984,8 +1984,9 @@ const char *exit_reason_str(unsigned int exit_reason) * and their base address is returned. A TEST_ASSERT failure occurs if * not enough pages are available at or above paddr_min. */ -vm_paddr_t vm_phy_pages_alloc(struct kvm_vm *vm, size_t num, - vm_paddr_t paddr_min, uint32_t memslot) +static vm_paddr_t __vm_phy_pages_alloc(struct kvm_vm *vm, size_t num, + vm_paddr_t paddr_min, uint32_t memslot, + bool aligned) { struct userspace_mem_region *region; sparsebit_idx_t pg, base; @@ -1997,14 +1998,20 @@ vm_paddr_t vm_phy_pages_alloc(struct kvm_vm *vm, size_t num, " paddr_min: 0x%lx page_size: 0x%x", paddr_min, vm->page_size); + TEST_ASSERT(!aligned || (paddr_min % vm->page_size * num) == 0, + "Min physical address isn't naturally aligned.\n" + " paddr_min: 0x%lx page_size: 0x%x num: %lu", + paddr_min, vm->page_size, num); + region = memslot2region(vm, memslot); base = pg = paddr_min >> vm->page_shift; do { for (; pg < base + num; ++pg) { if (!sparsebit_is_set(region->unused_phy_pages, pg)) { - base = pg = sparsebit_next_set(region->unused_phy_pages, pg); - break; + do { + base = pg = sparsebit_next_set(region->unused_phy_pages, pg); + } while (aligned && ((pg % num) != 0)); } } } while (pg && pg != base + num); @@ -2024,6 +2031,12 @@ vm_paddr_t vm_phy_pages_alloc(struct kvm_vm *vm, size_t num, return base * vm->page_size; } +vm_paddr_t vm_phy_pages_alloc(struct kvm_vm *vm, size_t num, + vm_paddr_t paddr_min, uint32_t memslot) +{ + return __vm_phy_pages_alloc(vm, num, paddr_min, memslot, false); +} + vm_paddr_t vm_phy_page_alloc(struct kvm_vm *vm, vm_paddr_t paddr_min, uint32_t memslot) { @@ -2036,6 +2049,12 @@ vm_paddr_t vm_alloc_page_table(struct kvm_vm *vm) vm->memslots[MEM_REGION_PT]); } +vm_paddr_t vm_phy_pages_alloc_aligned(struct kvm_vm *vm, size_t num, + vm_paddr_t paddr_min, uint32_t memslot) +{ + return __vm_phy_pages_alloc(vm, num, paddr_min, memslot, true); +} + /* * Address Guest Virtual to Host Virtual * -- 2.43.0.687.g38aa6559b0-goog