From patchwork Sat Jul 29 00:36:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 13332803 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 46898C001DE for ; Sat, 29 Jul 2023 00:37:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:Reply-To:List-Subscribe:List-Help: List-Post:List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:Message-ID :References:Mime-Version:In-Reply-To:Date:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=r4EENDMABdqJAmKsdUbxc4DC7ulqJ7KAja62gi9hR7E=; b=2XiHZtcTMsUM/4 WuP4JQS5ooGu3kthdWM0hkZkXeAo81+GeUl4RIUWzDrFhPHNWtRuA1EEGQc0nt6q92q35Rm/fxqYu 3WCPickH+5VA4OL5FJkVyoGvZDoA8yr/Z5tpFOmtFAnl0GT+Nfsg5ix+NTqyuifIFhpMl8wMAxItb QJLQbp2U0BxGfNlSavII9QSJNGu6+NukCIckiJbC1LQJnNlo+xs1NpnQOxVqNDG42iEAo1WLehFLO 74MPsDcZqWIrzJWHDUXsvg9D5UmWopgClGPv+Uz4Z7qajjYoy+rEtKd6gyDrpBDIyFr6nxDL58py4 0HwlYcJJ6kNRlT4jbjqw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qPXxF-005chT-0Z; Sat, 29 Jul 2023 00:37:09 +0000 Received: from mail-yw1-x114a.google.com ([2607:f8b0:4864:20::114a]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qPXx4-005cc4-2d for linux-arm-kernel@lists.infradead.org; Sat, 29 Jul 2023 00:37:00 +0000 Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-5704970148dso27746347b3.3 for ; Fri, 28 Jul 2023 17:36:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1690591017; x=1691195817; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:from:to:cc:subject:date:message-id:reply-to; bh=yrzuMhAa5ZwKSNV65AbGOyhxR2CbeFJJoK4NwSTk8zA=; b=dN9YT0VxVpTnTjGk/rv/FxwHOjp1VRvYhtyRfTVCAOoulkUZDNhTZRIAQk8NOYfzZZ GWEnyWCXZ+uS6SH++isxPQAlqFS/lA6695c9u+iCiY2gzPBkcDkFB1xdiizMtZDxh38s JhdAaexpefMPKDWwwntmojHOAbSw2wFqTgQFuSAyMXENyvM48ivs3AXaTMZ82Kx5J4jW 1kfdHVfh4dZh8FWhvcm03R9vowpN+JAwtXDm6Wy6OKafqBDFo6Zl0dqWCqKvEmo3qZ+L Tw0U7sTciY5PsfKaJJzXUgwKlmw8zZcjJQZ7mmloZZWEM4wOySbaCh0bwzOyHfTy2Dw+ qQuw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690591017; x=1691195817; h=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; bh=yrzuMhAa5ZwKSNV65AbGOyhxR2CbeFJJoK4NwSTk8zA=; b=edXlIeLPNhQFdjGzqYm76dvkvM13ICAeJofpK31FVwJ6Gmd4yxyAXRghsD3DPLTCOv 6ZloG5rni64SzDKcRu85n1z3QojKoUG2H50iN7IVSYCFrL8MxCO/CDLx5NHPCjxpVOIx B068kN3Dh5wuU/2LsTktgmRmsB0jjw731YiZRWmbFj4XPxWPfZmBL7Uh1P4sJvs7aswG 4shENM863hX5kp+kSwEN5pWtDKFQBhXv25fEG1NlOhZj186NkypT5psBlMd4QzTZ5W8M 2VygqMJa5YnJ//KUE4BxOjCPaX4nOycoDc+mzrPUedEUAVwpFnz1XwrAEu2VIqELnUzU eCEQ== X-Gm-Message-State: ABy/qLaD5iE2AYImvgMQAIwXOrzbo/tQVhlqeDaGdgp8LGelyJFVgL8H oUIIvBIHfrgim91OEA6+UXBdEC/8+f8= X-Google-Smtp-Source: APBJJlEZT09RPLsuDS5f8Sg2OFhpONKGw2AX4nW13KrfxH17cPvEic/pdQPcg0HACBrHFD9tkqER2tbLXyU= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a25:ccd1:0:b0:d1c:5506:9761 with SMTP id l200-20020a25ccd1000000b00d1c55069761mr23062ybf.1.1690591017810; Fri, 28 Jul 2023 17:36:57 -0700 (PDT) Date: Fri, 28 Jul 2023 17:36:15 -0700 In-Reply-To: <20230729003643.1053367-1-seanjc@google.com> Mime-Version: 1.0 References: <20230729003643.1053367-1-seanjc@google.com> X-Mailer: git-send-email 2.41.0.487.g6d72f3e995-goog Message-ID: <20230729003643.1053367-7-seanjc@google.com> Subject: [PATCH v4 06/34] KVM: selftests: Add additional pages to the guest to accommodate ucall From: Sean Christopherson To: Paolo Bonzini , Marc Zyngier , Oliver Upton , Christian Borntraeger , Janosch Frank , Claudio Imbrenda Cc: kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-kernel@vger.kernel.org, Sean Christopherson , Thomas Huth , " =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= " , Aaron Lewis X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230728_173658_852611_13F9D826 X-CRM114-Status: GOOD ( 13.07 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Sean Christopherson Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Aaron Lewis Add additional pages to the guest to account for the number of pages the ucall headers need. The only reason things worked before is the ucall headers are fairly small. If they were ever to increase in size the guest could run out of memory. This is done in preparation for adding string formatting options to the guest through the ucall framework which increases the size of the ucall headers. Fixes: 426729b2cf2e ("KVM: selftests: Add ucall pool based implementation") Signed-off-by: Aaron Lewis Signed-off-by: Sean Christopherson --- tools/testing/selftests/kvm/include/ucall_common.h | 1 + tools/testing/selftests/kvm/lib/kvm_util.c | 4 ++++ tools/testing/selftests/kvm/lib/ucall_common.c | 5 +++++ 3 files changed, 10 insertions(+) diff --git a/tools/testing/selftests/kvm/include/ucall_common.h b/tools/testing/selftests/kvm/include/ucall_common.h index 1a6aaef5ccae..bcbb362aa77f 100644 --- a/tools/testing/selftests/kvm/include/ucall_common.h +++ b/tools/testing/selftests/kvm/include/ucall_common.h @@ -34,6 +34,7 @@ void *ucall_arch_get_ucall(struct kvm_vcpu *vcpu); void ucall(uint64_t cmd, int nargs, ...); uint64_t get_ucall(struct kvm_vcpu *vcpu, struct ucall *uc); void ucall_init(struct kvm_vm *vm, vm_paddr_t mmio_gpa); +int ucall_nr_pages_required(uint64_t page_size); /* * Perform userspace call without any associated data. This bare call avoids diff --git a/tools/testing/selftests/kvm/lib/kvm_util.c b/tools/testing/selftests/kvm/lib/kvm_util.c index 3170d7a4520b..7a8af1821f5d 100644 --- a/tools/testing/selftests/kvm/lib/kvm_util.c +++ b/tools/testing/selftests/kvm/lib/kvm_util.c @@ -312,6 +312,7 @@ static uint64_t vm_nr_pages_required(enum vm_guest_mode mode, uint32_t nr_runnable_vcpus, uint64_t extra_mem_pages) { + uint64_t page_size = vm_guest_mode_params[mode].page_size; uint64_t nr_pages; TEST_ASSERT(nr_runnable_vcpus, @@ -340,6 +341,9 @@ static uint64_t vm_nr_pages_required(enum vm_guest_mode mode, */ nr_pages += (nr_pages + extra_mem_pages) / PTES_PER_MIN_PAGE * 2; + /* Account for the number of pages needed by ucall. */ + nr_pages += ucall_nr_pages_required(page_size); + return vm_adjust_num_guest_pages(mode, nr_pages); } diff --git a/tools/testing/selftests/kvm/lib/ucall_common.c b/tools/testing/selftests/kvm/lib/ucall_common.c index 2f0e2ea941cc..77ada362273d 100644 --- a/tools/testing/selftests/kvm/lib/ucall_common.c +++ b/tools/testing/selftests/kvm/lib/ucall_common.c @@ -11,6 +11,11 @@ struct ucall_header { struct ucall ucalls[KVM_MAX_VCPUS]; }; +int ucall_nr_pages_required(uint64_t page_size) +{ + return align_up(sizeof(struct ucall_header), page_size) / page_size; +} + /* * ucall_pool holds per-VM values (global data is duplicated by each VM), it * must not be accessed from host code.