From patchwork Fri Dec 9 01:53:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oliver Upton X-Patchwork-Id: 31585 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp529509wrr; Thu, 8 Dec 2022 17:56:50 -0800 (PST) X-Google-Smtp-Source: AA0mqf5dpYnf6IXl9phKMvRwg5BT0hYk9UqpEKSHkYyCezh28YH0kQwcSOiP8xgdhxWDgW+vWPsp X-Received: by 2002:a17:906:7751:b0:7ae:df97:c020 with SMTP id o17-20020a170906775100b007aedf97c020mr3237402ejn.13.1670551010761; Thu, 08 Dec 2022 17:56:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670551010; cv=none; d=google.com; s=arc-20160816; b=0O2GAiKiTP5ra1zV+Vh3YgXMdEC+3rSMiI1TPwrb7mR2E02w6grd4vDsUK2rlJodgo qoXGgNPotWjJvQ5Z39+Cq6IAEFg5UxUBd5HyYGezqC1rECJ2T+mAUD5v5OgnSsGxzIgU Xhbz0hzFvcxm8IStMN1qI8NxxU3Yfa/MHJJUiRYNuZhgXyK1SrcP/H+UPAD2npgv1auk WQr/eiojhgImuVmDYpprrzfjjwf4nDQaSNAxaTAeS/6OzXu8zsct5BD7pQGGlk8kP/+A fmaKKzM1aZE04SkwWVC3PG1OPH3ujZgRwePLOdYo0Us7z3TL3AHDVL/PzxWz5xudwIFM jt+g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=qZMCjgWfjbfYBycq79hF9R9CkWiOAgpLZz+FN8edLKs=; b=k6DCnbiZEVUn8vMkrqox3D8wTODdJzcU1Q/A5ykrnXrgq/TuQYkCcdlukFvDY7kqIR LBohfBXWZs3MlYgHt20+pRRvZmh22KARKpCrRazIYrVPrJfbZ6XCBnKuNGBo9PDAmNc6 UK55Ck5KPvuUJuiyCXYHsp22iTlxnp+/Mb5okBHqW2NMjG9HBESohTCU4qQUCJRQgLG3 XHnW9/f8jcukSUJqPQ7TxbE5CgLkSvOK/FqzO9U8ey/rVb881lqp8mqaAhswHjykSfLw VFOGq49hFiUJ3EmrBgtelY8i0SuQYoP1ouztgXagDOPJCTyU0WdCixJGfGrRYsP4Z9dz EMFw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id qk38-20020a1709077fa600b007c098f5e5f4si89246ejc.233.2022.12.08.17.56.26; Thu, 08 Dec 2022 17:56:50 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230139AbiLIByL (ORCPT + 99 others); Thu, 8 Dec 2022 20:54:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53292 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230053AbiLIBxu (ORCPT ); Thu, 8 Dec 2022 20:53:50 -0500 Received: from out-155.mta0.migadu.com (out-155.mta0.migadu.com [IPv6:2001:41d0:1004:224b::9b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9F034944DA for ; Thu, 8 Dec 2022 17:53:42 -0800 (PST) X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Oliver Upton To: Marc Zyngier , James Morse , Alexandru Elisei , Suzuki K Poulose , Oliver Upton , Paolo Bonzini , Shuah Khan , Nathan Chancellor , Nick Desaulniers , Tom Rix Cc: linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org, kvmarm@lists.linux.dev, Ricardo Koller , Sean Christopherson , linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, llvm@lists.linux.dev Subject: [PATCH v2 5/7] KVM: arm64: selftests: Don't identity map the ucall MMIO hole Date: Fri, 9 Dec 2022 01:53:04 +0000 Message-Id: <20221209015307.1781352-6-oliver.upton@linux.dev> In-Reply-To: <20221209015307.1781352-1-oliver.upton@linux.dev> References: <20221209015307.1781352-1-oliver.upton@linux.dev> MIME-Version: 1.0 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1751699696536440299?= X-GMAIL-MSGID: =?utf-8?q?1751699696536440299?= Currently the ucall MMIO hole is placed immediately after slot0, which is a relatively safe address in the PA space. However, it is possible that the same address has already been used for something else (like the guest program image) in the VA space. At least in my own testing, building the vgic_irq test with clang leads to the MMIO hole appearing underneath gicv3_ops. Stop identity mapping the MMIO hole and instead find an unused VA to map to it. Yet another subtle detail of the KVM selftests library is that virt_pg_map() does not update vm->vpages_mapped. Switch over to virt_map() instead to guarantee that the chosen VA isn't to something else. Signed-off-by: Oliver Upton --- tools/testing/selftests/kvm/lib/aarch64/ucall.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/kvm/lib/aarch64/ucall.c b/tools/testing/selftests/kvm/lib/aarch64/ucall.c index 562c16dfbb00..f212bd8ab93d 100644 --- a/tools/testing/selftests/kvm/lib/aarch64/ucall.c +++ b/tools/testing/selftests/kvm/lib/aarch64/ucall.c @@ -14,11 +14,13 @@ static vm_vaddr_t *ucall_exit_mmio_addr; void ucall_arch_init(struct kvm_vm *vm, vm_paddr_t mmio_gpa) { - virt_pg_map(vm, mmio_gpa, mmio_gpa); + vm_vaddr_t mmio_gva = vm_vaddr_unused_gap(vm, vm->page_size, KVM_UTIL_MIN_VADDR); + + virt_map(vm, mmio_gva, mmio_gpa, 1); vm->ucall_mmio_addr = mmio_gpa; - write_guest_global(vm, ucall_exit_mmio_addr, (vm_vaddr_t *)mmio_gpa); + write_guest_global(vm, ucall_exit_mmio_addr, (vm_vaddr_t *)mmio_gva); } void ucall_arch_do_ucall(vm_vaddr_t uc)