From patchwork Fri Dec 9 01:53:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Oliver Upton X-Patchwork-Id: 31577 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp529181wrr; Thu, 8 Dec 2022 17:55:51 -0800 (PST) X-Google-Smtp-Source: AA0mqf4VOYlGuxXdHGSdeYK/UNSnZIII4xdzNBC/Yr3C1l+H6pn4Oo6IDbGoCDQOPgsHix0AOEDo X-Received: by 2002:a17:906:4a9a:b0:7c1:2529:2760 with SMTP id x26-20020a1709064a9a00b007c125292760mr3212141eju.27.1670550951683; Thu, 08 Dec 2022 17:55:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670550951; cv=none; d=google.com; s=arc-20160816; b=VQsOJB3oZFSroxS/apyz7e6yNbsGTt+XMHVzVzjmcve2ROVandHnyEnJgcazFhYICt 5dRNjtUhxUbRUgC1ad33qEw9LT+gWvKLWAvYi+m8Soxwu0FNue1FRyytEtzcBCsOJl8t ta+oz+K13L4cm3i98NhyQEuu928mv3xywvftsxCKCAoBUn1jhRK9AOepuhIMHPp747zE Tj8rG7XDIUBgK13PwrkmP7pO2Ceob3d2gwMq9tIXwaq0RvyYOmFHqJ5Srn2p3uyHEaFC rB6DOglPlE3or4KagTWTnsyx04YWuSTA2YVaPSrlMZHTXBoK1Hqm5Tk1H+Ie7FXtQ7Rh Kveg== 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=ISfI/YSG7Qif79sWhqZQ3Q+oWPgCT/GJolR284CKCpc=; b=nCVN8nruzODA+HGmM4DXh8oL+ZIA+b32qu+BpKSYjB0n4swY0TCzjyW5BoIj9uswnK 9NmDsohSbHym3/BuJPS6OOwhiBLMceV7io6nXh2ZAXdrNL3eVwzrL1uAK+GmC9OUHaMG lQAfj6E8754jIZ2xNH8H4noCqSMgiplM2C8e3D6gVMpX5toV4hVZApgSvNvpWoriX2gE 2/ynksm8Y7tfbshDPrOwGwDZh8dO/rWnw5ggoVRD/BBg5nHXl4YrV4a/b9aAzeF/ZBop ugzpIN0LBeH0/iz4zFFe7nhx/14cCRfg1a3m6r6vDgf2EADDPOh/lsVaQa1PjicyYxac leIw== 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 g34-20020a056402322200b0046d52eaa5b1si268791eda.120.2022.12.08.17.55.28; Thu, 08 Dec 2022 17:55:51 -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 S229942AbiLIBxc (ORCPT + 99 others); Thu, 8 Dec 2022 20:53:32 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52980 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229756AbiLIBxa (ORCPT ); Thu, 8 Dec 2022 20:53:30 -0500 Received: from out-69.mta0.migadu.com (out-69.mta0.migadu.com [IPv6:2001:41d0:1004:224b::45]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 993679419A for ; Thu, 8 Dec 2022 17:53:29 -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 , Sean Christopherson , Andrew Jones , Ricardo Koller Cc: linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org, kvmarm@lists.linux.dev, Mark Brown , linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 1/7] KVM: selftests: Fix build due to ucall_uninit() removal Date: Fri, 9 Dec 2022 01:53:00 +0000 Message-Id: <20221209015307.1781352-2-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=unavailable 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?1751699634781528740?= X-GMAIL-MSGID: =?utf-8?q?1751699634781528740?= From: Mark Brown Today's -next fails to build on arm64 due to: In file included from include/kvm_util.h:11, from aarch64/page_fault_test.c:15: include/ucall_common.h:36:47: note: expected ‘vm_paddr_t’ {aka ‘long unsigned int’} but argument is of type ‘void *’ 36 | void ucall_init(struct kvm_vm *vm, vm_paddr_t mmio_gpa); | ~~~~~~~~~~~^~~~~~~~ aarch64/page_fault_test.c:725:2: warning: implicit declaration of function ‘ucall_uninit’; did you mean ‘ucall_init’? [-Wimplicit-function-declaration] 725 | ucall_uninit(vm); | ^~~~~~~~~~~~ | ucall_init which is caused by commit interacting poorly with commit 28a65567acb5 ("KVM: selftests: Drop now-unnecessary ucall_uninit()") As is done for other ucall_uninit() users remove the call in the newly added page_fault_test.c. Fixes: 28a65567acb5 ("KVM: selftests: Drop now-unnecessary ucall_uninit()") Fixes: 35c581015712 ("KVM: selftests: aarch64: Add aarch64/page_fault_test") Signed-off-by: Mark Brown Cc: Sean Christopherson Cc: Ricardo Koller Cc: Marc Zyngier Signed-off-by: Oliver Upton --- tools/testing/selftests/kvm/aarch64/page_fault_test.c | 1 - 1 file changed, 1 deletion(-) diff --git a/tools/testing/selftests/kvm/aarch64/page_fault_test.c b/tools/testing/selftests/kvm/aarch64/page_fault_test.c index 0cda70bef5d5..92d3a91153b6 100644 --- a/tools/testing/selftests/kvm/aarch64/page_fault_test.c +++ b/tools/testing/selftests/kvm/aarch64/page_fault_test.c @@ -722,7 +722,6 @@ static void run_test(enum vm_guest_mode mode, void *arg) vcpu_run_loop(vm, vcpu, test); - ucall_uninit(vm); kvm_vm_free(vm); free_uffd(test, pt_uffd, data_uffd); From patchwork Fri Dec 9 01:53:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oliver Upton X-Patchwork-Id: 31588 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp529736wrr; Thu, 8 Dec 2022 17:57:38 -0800 (PST) X-Google-Smtp-Source: AA0mqf4lc2WmD9lt/P6qq9whoWuYCwhj34eVSTwHnxQGPwHybf46ezw0qvtJwXdg6+dCs8JDi9Dq X-Received: by 2002:a05:6402:3985:b0:461:3ae6:8bfc with SMTP id fk5-20020a056402398500b004613ae68bfcmr4060970edb.34.1670551058544; Thu, 08 Dec 2022 17:57:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670551058; cv=none; d=google.com; s=arc-20160816; b=Rl9glNCj/W/rEXUbrIMd1uYR2mWWWkUaMvTb2l5hLfk4LUI2Mi1xQ9LjpVeZUVJVgO q/V5HNIkxirARBWNlpBYTvaPJLqk8ydjHnINDyi7zq2l4eKzzC3lkX61Oeyv/XLWJN/g HEGqsTW/4QH5wqpenMpyQhy4aNzn8JRdwWhzHigkK77nfJzidjiM0+CobpH+XoymjxN4 2Q5dJYd+UQI9POtVoP1idR3mFPbqKMytnbVkSfwIctbfK0ob2/ZmZLwpzc1sLWn+uDb9 63dLU+iQLcgoRQJq/JTAmq65/kaEuMwLM9Xf5U63iRigSl4KQjfW9kwN3BCOz0vEq9NA Z4sA== 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=iNaQ8cVFg6rq2AduHYUK2UWrWd1BcZJaAQrRI7/Dw7A=; b=UZmTfLWsQezFhJbX+dnHD9xrikMJMpfKD+LKC/UHxesWM0lUN7FOsmi6L5Ls1eNdxh 8tU41bnvqfDIKLs2Qre3f2sfS4YHUZDM1+Mok2sYZtyydaSxgRMiQhac7fk1zyiTDyLl bkYDvkw/lz18lUMNRdst3DQWLtrcfIqZ56yGie7oOJmfyojFBlFLgX92oT+kZjuZadrI +8EZpT7Ri7v2qAMHJmotkEr1ST953O/IeV9IMynpr4nqOr8Pmjloe/T2EYbPdZRzmcRG 2/S32HcS0BEPhy1T0dB7AmyafcZV4MmQDp0XmaihXKRFVdGkpJUHRYMHve+iz0Jtz445 3ACQ== 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 z10-20020a05640235ca00b0046b9f6d9a96si305820edc.280.2022.12.08.17.57.15; Thu, 08 Dec 2022 17:57:38 -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 S229997AbiLIBxk (ORCPT + 99 others); Thu, 8 Dec 2022 20:53:40 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53060 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229813AbiLIBxe (ORCPT ); Thu, 8 Dec 2022 20:53:34 -0500 Received: from out-233.mta0.migadu.com (out-233.mta0.migadu.com [IPv6:2001:41d0:1004:224b::e9]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A441D941AB for ; Thu, 8 Dec 2022 17:53:32 -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 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 Subject: [PATCH v2 2/7] KVM: selftests: Setup ucall after loading program into guest memory Date: Fri, 9 Dec 2022 01:53:01 +0000 Message-Id: <20221209015307.1781352-3-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=unavailable 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?1751699746818484052?= X-GMAIL-MSGID: =?utf-8?q?1751699746818484052?= The new ucall infrastructure needs to update a couple of guest globals to pass through the ucall MMIO addr and pool of ucall structs. A precondition of writing to the guest's program image is to have it already loaded into guest memory. Call ucall_init() after kvm_vm_elf_load(). Continue to park the ucall MMIO addr after MEM_REGION_TEST_DATA. Signed-off-by: Oliver Upton --- tools/testing/selftests/kvm/aarch64/page_fault_test.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/kvm/aarch64/page_fault_test.c b/tools/testing/selftests/kvm/aarch64/page_fault_test.c index 92d3a91153b6..95d22cfb7b41 100644 --- a/tools/testing/selftests/kvm/aarch64/page_fault_test.c +++ b/tools/testing/selftests/kvm/aarch64/page_fault_test.c @@ -609,8 +609,13 @@ static void setup_memslots(struct kvm_vm *vm, struct test_params *p) data_size / guest_page_size, p->test_desc->data_memslot_flags); vm->memslots[MEM_REGION_TEST_DATA] = TEST_DATA_MEMSLOT; +} + +static void setup_ucall(struct kvm_vm *vm) +{ + struct userspace_mem_region *region = vm_get_mem_region(vm, MEM_REGION_TEST_DATA); - ucall_init(vm, data_gpa + data_size); + ucall_init(vm, region->region.guest_phys_addr + region->region.memory_size); } static void setup_default_handlers(struct test_desc *test) @@ -702,6 +707,7 @@ static void run_test(enum vm_guest_mode mode, void *arg) vm = ____vm_create(mode); setup_memslots(vm, p); kvm_vm_elf_load(vm, program_invocation_name); + setup_ucall(vm); vcpu = vm_vcpu_add(vm, 0, guest_code); setup_gva_maps(vm); From patchwork Fri Dec 9 01:53:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oliver Upton X-Patchwork-Id: 31581 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp529289wrr; Thu, 8 Dec 2022 17:56:12 -0800 (PST) X-Google-Smtp-Source: AA0mqf6wrs5KJbUe493JvWUR4p6pyhceU5xwOFezActQNNOf5GJgaPQ6yhKqPKa9NjD/WW3Jl89G X-Received: by 2002:a05:6402:e98:b0:45c:835c:eab1 with SMTP id h24-20020a0564020e9800b0045c835ceab1mr3752732eda.31.1670550972089; Thu, 08 Dec 2022 17:56:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670550972; cv=none; d=google.com; s=arc-20160816; b=HGKpb35ZVa1ABbsCmPO8DGjU/mzfxNJ+GG0lfbLgn9faeHeR+sNSZO3VEVbpuf/oWv juMMzlx4GWrS6vhzhZ6v03BAN1oUWtCWU6AfJKI/YpYfEOHUZ6mRImL4Tv4tw9ahSbKR 77jGHbsnu7mJsRaJYfwnechVbEzBF6coa2KEdonkxLGcACFMeh3cUDVIEfWkjclBUQiA b76Z8jwnSIYanGYK/0l/0X5eOsGPTJ0gyhrtcCfnA7LAFyT+LyNfAZmhE706zQHBIHEZ Q8RV6O2s5a5tUNBQa0ycxBQunTdj2tDeUDYRCZ1B2k28s/hqY+YQeY/swXPC+pweVSr+ oxEQ== 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=3lSpaVAFxsrE5e9IIvgtegxsRjzp2l3Pd0bb8fOJe2A=; b=ohlSr3IqvWkRRfMRqdSLEk2IMtYHKmusv/8mSbv0JERKZXpyPVGDa8Qun0RtsYw3AA GZ/9cA3GbBF3BLZC3JzGBF7JP9k/VcN07eT/TlLBme/tUIdJ84uEQBqzNJwxJTg7zV3d Km5rXxZt9nJChR6owjX5nTnImdCCVgiMd5d2Ob0OOX9V4t8yuw6DSyuVY/jgNabt5bvs aVvFCulEr2/2Qc7iemlZbPrPkZvF3+T8S0yWtu1xaCEHg36bVAzsxxBccCn/ENrFHJp3 SH/WkbD/kvgVv74Ah0cG5jzYTJ+6bH/1HZZ7ujqVXd5GLEEign6melcCnbtU5IzuMifs q61g== 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 r8-20020a05640251c800b0046b44b34d88si281593edd.310.2022.12.08.17.55.48; Thu, 08 Dec 2022 17:56:12 -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 S229985AbiLIBxp (ORCPT + 99 others); Thu, 8 Dec 2022 20:53:45 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53080 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229995AbiLIBxk (ORCPT ); Thu, 8 Dec 2022 20:53:40 -0500 Received: from out-94.mta0.migadu.com (out-94.mta0.migadu.com [91.218.175.94]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 01C8798EB7 for ; Thu, 8 Dec 2022 17:53:35 -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 , Paolo Bonzini , Shuah Khan , Sean Christopherson , Vitaly Kuznetsov , Andrew Jones Cc: linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org, kvmarm@lists.linux.dev, Ricardo Koller , Oliver Upton , linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 3/7] KVM: selftests: Mark correct page as mapped in virt_map() Date: Fri, 9 Dec 2022 01:53:02 +0000 Message-Id: <20221209015307.1781352-4-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=unavailable 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?1751699656241579584?= X-GMAIL-MSGID: =?utf-8?q?1751699656241579584?= The loop marks vaddr as mapped after incrementing it by page size, thereby marking the *next* page as mapped. Set the bit in vpages_mapped first instead. Fixes: 56fc7732031d ("KVM: selftests: Fill in vm->vpages_mapped bitmap in virt_map() too") Signed-off-by: Oliver Upton --- tools/testing/selftests/kvm/lib/kvm_util.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/kvm/lib/kvm_util.c b/tools/testing/selftests/kvm/lib/kvm_util.c index e9607eb089be..a256ec67aff6 100644 --- a/tools/testing/selftests/kvm/lib/kvm_util.c +++ b/tools/testing/selftests/kvm/lib/kvm_util.c @@ -1411,10 +1411,10 @@ void virt_map(struct kvm_vm *vm, uint64_t vaddr, uint64_t paddr, while (npages--) { virt_pg_map(vm, vaddr, paddr); + sparsebit_set(vm->vpages_mapped, vaddr >> vm->page_shift); + vaddr += page_size; paddr += page_size; - - sparsebit_set(vm->vpages_mapped, vaddr >> vm->page_shift); } } From patchwork Fri Dec 9 01:53:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oliver Upton X-Patchwork-Id: 31583 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp529350wrr; Thu, 8 Dec 2022 17:56:21 -0800 (PST) X-Google-Smtp-Source: AA0mqf729m8mETKJPlWT2cPMNH/+YAQD3lQQJQapgMjrTHfAgGctpBaH/upjfKsXtxkJbAWrUfA9 X-Received: by 2002:a17:906:a157:b0:7ae:83f4:3bf5 with SMTP id bu23-20020a170906a15700b007ae83f43bf5mr3255816ejb.68.1670550981316; Thu, 08 Dec 2022 17:56:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670550981; cv=none; d=google.com; s=arc-20160816; b=VQV37vaQXICcAOpU5c6lMiWDdoHK5Sm5CjwEZdDAFnQEP8EcKs+XVFGx5iSAO2eWdb pc2vPIrLWkhROndawvNVLbeE+n5gbslvLrKYt5hILvfIuq118D85fD5cV2Tvr4zk0Mhy o8x8lJXM9UpxIodDSt5m3e8jILPB3A5guGJFvOd7RCxip5H5DccOGbv5EVNRSQ+9hx0D g+DNJ77vV7QYCwSF6g0SVFN6lUERV0q9bmNKk6aVbK0jm1fAetwe/SZNQleeOAwFfiHU ieLEJHcpbNonu0XFpROSTeQfQJhYDY88snmlmdmo9rn062k4hpUR4/ENe5JO4Eqf7Qls ueUw== 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=qeDCINM5qi4wL30iS+1rkk+p7Q2x38wiXkq2to0m68Y=; b=zGMypv4SwbE+iJJpM5AcwNNDwH8lVAKa8ZcQfM0C1yANkJWwrpB0GP+NGgLaWckzWe sFuzT8DGkAMgcbO/RR7mtKFIkf4rUORjorbOqj9gRC0Z310uLzQTh2bHof5ulQjxzUHf UtvdztWKVRONOtLRD7YWLNn58aR2ZJmZyRrBXBMj5o/iWAaxgEMedq2CIhOeTxJQZ3bv E/jMD0XRlgmFX3KL8i58PU5SacVY9CJkhUyW5rlIIM/gylkzNvOogzki7bsoBPqtDNtz L6vKX8kfHs1CwuzYlCO6ZbqET+93m9rUy7qO4OAaYlbiSTWg/vFVMYla27f8QeJb1hEq eqOw== 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 dd12-20020a1709069b8c00b007c10534516csi57713ejc.554.2022.12.08.17.55.58; Thu, 08 Dec 2022 17:56:21 -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 S230078AbiLIBxw (ORCPT + 99 others); Thu, 8 Dec 2022 20:53:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53058 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229964AbiLIBxl (ORCPT ); Thu, 8 Dec 2022 20:53:41 -0500 Received: from out-54.mta0.migadu.com (out-54.mta0.migadu.com [91.218.175.54]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EBF01944DE for ; Thu, 8 Dec 2022 17:53:38 -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 , Paolo Bonzini , Shuah Khan Cc: linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org, kvmarm@lists.linux.dev, Ricardo Koller , Sean Christopherson , Oliver Upton , linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 4/7] KVM: selftests: Correctly initialize the VA space for TTBR0_EL1 Date: Fri, 9 Dec 2022 01:53:03 +0000 Message-Id: <20221209015307.1781352-5-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?1751699665889607945?= X-GMAIL-MSGID: =?utf-8?q?1751699665889607945?= An interesting feature of the Arm architecture is that the stage-1 MMU supports two distinct VA regions, controlled by TTBR{0,1}_EL1. As KVM selftests on arm64 only uses TTBR0_EL1, the VA space is constrained to [0, 2^(va_bits)). This is different from other architectures that allow for addressing low and high regions of the VA space from a single page table. KVM selftests' VA space allocator presumes the valid address range is split between low and high memory based the MSB, which of course is a poor match for arm64's TTBR0 region. Add a helper that correctly handles both addressing schemes with a comment describing each. Signed-off-by: Oliver Upton Reviewed-by: Sean Christopherson --- .../selftests/kvm/include/kvm_util_base.h | 1 + tools/testing/selftests/kvm/lib/kvm_util.c | 49 ++++++++++++++++--- 2 files changed, 44 insertions(+), 6 deletions(-) diff --git a/tools/testing/selftests/kvm/include/kvm_util_base.h b/tools/testing/selftests/kvm/include/kvm_util_base.h index 6cd86da698b3..b193863d754f 100644 --- a/tools/testing/selftests/kvm/include/kvm_util_base.h +++ b/tools/testing/selftests/kvm/include/kvm_util_base.h @@ -103,6 +103,7 @@ struct kvm_vm { struct sparsebit *vpages_mapped; bool has_irqchip; bool pgd_created; + bool has_split_va_space; vm_paddr_t ucall_mmio_addr; vm_paddr_t pgd; vm_vaddr_t gdt; diff --git a/tools/testing/selftests/kvm/lib/kvm_util.c b/tools/testing/selftests/kvm/lib/kvm_util.c index a256ec67aff6..53d15f32f220 100644 --- a/tools/testing/selftests/kvm/lib/kvm_util.c +++ b/tools/testing/selftests/kvm/lib/kvm_util.c @@ -186,6 +186,43 @@ const struct vm_guest_mode_params vm_guest_mode_params[] = { _Static_assert(sizeof(vm_guest_mode_params)/sizeof(struct vm_guest_mode_params) == NUM_VM_MODES, "Missing new mode params?"); +/* + * Initializes vm->vpages_valid to match the canonical VA space of the + * architecture. + * + * Most architectures split the range addressed by a single page table into a + * low and high region based on the MSB of the VA. On architectures with this + * behavior the VA region spans [0, 2^(va_bits - 1)), [-(2^(va_bits - 1), -1]. + * + * arm64 is a bit different from the rest of the crowd, as the low and high + * regions of the VA space are addressed by distinct paging structures + * (TTBR{0,1}_EL1). KVM selftests on arm64 only uses TTBR0_EL1, meaning that we + * only have a low VA region. As there is no VA split based on the MSB, the VA + * region spans [0, 2^va_bits). + */ +static void vm_vaddr_populate_bitmap(struct kvm_vm *vm) +{ + sparsebit_num_t contig_va_bits = vm->va_bits; + sparsebit_num_t nr_contig_pages; + + /* + * Depending on the architecture, the MSB of the VA could split between + * low and high regions. When that is the case each region has + * va_bits - 1 of address. + */ + if (vm->has_split_va_space) + contig_va_bits--; + + nr_contig_pages = (1ULL << contig_va_bits) >> vm->page_shift; + + sparsebit_set_num(vm->vpages_valid, 0, nr_contig_pages); + + if (vm->has_split_va_space) + sparsebit_set_num(vm->vpages_valid, + -(1ULL << contig_va_bits), + nr_contig_pages); +} + struct kvm_vm *____vm_create(enum vm_guest_mode mode) { struct kvm_vm *vm; @@ -268,17 +305,17 @@ struct kvm_vm *____vm_create(enum vm_guest_mode mode) #ifdef __aarch64__ if (vm->pa_bits != 40) vm->type = KVM_VM_TYPE_ARM_IPA_SIZE(vm->pa_bits); + + /* selftests use TTBR0 only, meaning there is a single VA region. */ + vm->has_split_va_space = false; +#else + vm->has_split_va_space = true; #endif vm_open(vm); - /* Limit to VA-bit canonical virtual addresses. */ vm->vpages_valid = sparsebit_alloc(); - sparsebit_set_num(vm->vpages_valid, - 0, (1ULL << (vm->va_bits - 1)) >> vm->page_shift); - sparsebit_set_num(vm->vpages_valid, - (~((1ULL << (vm->va_bits - 1)) - 1)) >> vm->page_shift, - (1ULL << (vm->va_bits - 1)) >> vm->page_shift); + vm_vaddr_populate_bitmap(vm); /* Limit physical addresses to PA-bits. */ vm->max_gfn = vm_compute_max_gfn(vm); 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) From patchwork Fri Dec 9 01:53:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oliver Upton X-Patchwork-Id: 31587 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp529577wrr; Thu, 8 Dec 2022 17:57:06 -0800 (PST) X-Google-Smtp-Source: AA0mqf7qD1vCOx6JCi7f74Og+nFyaX6+Kz9mQm1iiRr3WC3jF1fJMRPNJ+6LGbIvr3dwRJM0rvRN X-Received: by 2002:a17:906:86ca:b0:7c0:f2cf:23fb with SMTP id j10-20020a17090686ca00b007c0f2cf23fbmr3521354ejy.52.1670551026038; Thu, 08 Dec 2022 17:57:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670551026; cv=none; d=google.com; s=arc-20160816; b=tD2hAVH62cEGL0LLxpDu9vHGfzgl0tO2KLoqaeSlZkMfmn71aGrumTMp9/Q5hILp1F 6lOrXoyVtZ1TdCv8e20eDep8Qs2ehmewff2uHl2xKSQK9lnlxitaJabLGZHNDmSQ+lnA YPI68AevU9NURKs0SFpOGLb5aCD01QULyl+5N2yXLa58LSS76umTa0+KuK7L58Oy+tbF fAAt1QEtf6x8429x4cx9O1wJQjsxLUXVT2k57kdeGG8nFX512ocxyl/SSd7EjP4h2Zst 1ONuyZcYczAD7ofh72WvuM9a681mcoZ4e1nlCUEmzhOz2QdrxEXJF6i5BZ5/1hzvq0UB 3ayA== 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=W5GuQXMbrC3IysNjrIOVqfKPv5wEvVUNlxTgUAZczI8=; b=D+ljie/k/FwkCBMRGXMpG9jqo9xgAjDknraMMBmxvDL6BJ9aJA2g8SDRRpo2yJP8gY /ZPX+ESxg8qbtjP4A39LHLx2PeUmNDAkCob5VHBQNkzQZQxi7TNc+Ot48IewBp3h/+K0 9z4W22M/HZqx53A6RIKZtUfmbF7f1iECl7VJ2ssQ7jtyPpBmtgAN9cV2A5G0rlFLYSwF AW/XcEFQJHqhL2ux3UALRpe7GMHDPgBkQBAE1s6bXC+77oHjjXU+mK8WmRyg2D8lixpT xad+V2NZCjvVoHu1qs7Z7xwaEx1IFrUZ5ex+0S8QRkHAqHiVGNpaoIIxsC3eDZnuK1P+ VmkQ== 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 i6-20020a1709063c4600b007c0a70496desi22745ejg.724.2022.12.08.17.56.42; Thu, 08 Dec 2022 17:57:06 -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 S230150AbiLIByW (ORCPT + 99 others); Thu, 8 Dec 2022 20:54:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53834 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230102AbiLIBxy (ORCPT ); Thu, 8 Dec 2022 20:53:54 -0500 Received: from out-116.mta0.migadu.com (out-116.mta0.migadu.com [91.218.175.116]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 75B29AE4E5 for ; Thu, 8 Dec 2022 17:53:45 -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 , Paolo Bonzini , Shuah Khan Cc: linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org, kvmarm@lists.linux.dev, Ricardo Koller , Sean Christopherson , Oliver Upton , linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 6/7] KVM: selftests: Allocate ucall pool from MEM_REGION_DATA Date: Fri, 9 Dec 2022 01:53:05 +0000 Message-Id: <20221209015307.1781352-7-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?1751699712321747089?= X-GMAIL-MSGID: =?utf-8?q?1751699712321747089?= MEM_REGION_TEST_DATA is meant to hold data explicitly used by a selftest, not implicit allocations due to the selftests infrastructure. Allocate the ucall pool from MEM_REGION_DATA much like the rest of the selftests library allocations. Reviewed-by: Sean Christopherson Signed-off-by: Oliver Upton --- tools/testing/selftests/kvm/lib/ucall_common.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/testing/selftests/kvm/lib/ucall_common.c b/tools/testing/selftests/kvm/lib/ucall_common.c index 820ce6c82829..0cc0971ce60e 100644 --- a/tools/testing/selftests/kvm/lib/ucall_common.c +++ b/tools/testing/selftests/kvm/lib/ucall_common.c @@ -22,7 +22,7 @@ void ucall_init(struct kvm_vm *vm, vm_paddr_t mmio_gpa) vm_vaddr_t vaddr; int i; - vaddr = vm_vaddr_alloc(vm, sizeof(*hdr), KVM_UTIL_MIN_VADDR); + vaddr = __vm_vaddr_alloc(vm, sizeof(*hdr), KVM_UTIL_MIN_VADDR, MEM_REGION_DATA); hdr = (struct ucall_header *)addr_gva2hva(vm, vaddr); memset(hdr, 0, sizeof(*hdr)); From patchwork Fri Dec 9 01:53:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oliver Upton X-Patchwork-Id: 31590 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp529958wrr; Thu, 8 Dec 2022 17:58:28 -0800 (PST) X-Google-Smtp-Source: AA0mqf7eDp1l/OAkBb0263jxc/qpI/KzUgfQq9UHFzR6v1MwnetK5vj9H61ZLheO5R/c+VD0IoBP X-Received: by 2002:a17:907:3e14:b0:7c0:f719:838d with SMTP id hp20-20020a1709073e1400b007c0f719838dmr4573645ejc.36.1670551108753; Thu, 08 Dec 2022 17:58:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670551108; cv=none; d=google.com; s=arc-20160816; b=jVDZVRBGPTYa2iLDMByjAhMsQv78hK8ZTP7QCw1LN439K1zuvwYtsTqJOUvZnkoH8n vI9iAEi6GaiY5m9VPoa2snEJy5ZkbabZTya6rX19LVGx/2/WpIAwpikm0OQLieNXj13P k/79TvE1hwc/TNA+iyNDQ6ia/2vBpSsNDo0Ej+G2RMpmeiEW4HJUX8O5wRzBpulSESZ2 9P42AH7E9OY01CPBifUK4zVIcMmjX3tpR7Z/jbKMvTuwOKWzjjrbPQERgncDqNL6B1Ye iyZPv5Gvx+yTDz3D3QO8pyDt9xaqlPNNQVQml8xRNjnMc9YBwa7I4ZBMaNjoftgXRnah biVg== 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=iGqzh1nn8M8qIu2HMX7NJCgwvQUB1383Z9Wplc2q4DE=; b=tKAveaWpebKHbCoa0WXrsjzKDBM2gcpE4xEitsMVA3dDa2oHz/gdnqHWIsvAk+uBaq I8Tdur7NKksekpmmZ8m3vfkS34rRCFl20OKtyUcp+yvQwXmU6Tul4ippVuAbGyH9/Jby ptYdJS7JAKD7wgnmcbBMyv5vLvN06X7CJkH0vDXIoiF/dHJSiZTec5HrDD/fjl9h3VU6 ugLR56IVr1X8IYtfUvnizSbQupG9ju6/LpkxxMbutb/bgmuRwuUe1Jbwch/5knq6dCUa O5Gn4bEYD8pJzJcsvKX+KLbBgNXSRbFZJlbG0JwWWQ2Gs3kefaSecVT5vEXoZwy8qZcn l5eQ== 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 hx9-20020a170906846900b007c10a0c590dsi72518ejc.25.2022.12.08.17.58.05; Thu, 08 Dec 2022 17:58:28 -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 S230048AbiLIByk (ORCPT + 99 others); Thu, 8 Dec 2022 20:54:40 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54184 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230129AbiLIByG (ORCPT ); Thu, 8 Dec 2022 20:54:06 -0500 Received: from out-74.mta0.migadu.com (out-74.mta0.migadu.com [91.218.175.74]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CE657B1066 for ; Thu, 8 Dec 2022 17:53:48 -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 , Paolo Bonzini , Shuah Khan , Andrew Jones , Peter Gonda , Sean Christopherson Cc: linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org, kvmarm@lists.linux.dev, Ricardo Koller , Oliver Upton , linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 7/7] KVM: selftests: Avoid infinite loop if ucall_alloc() fails Date: Fri, 9 Dec 2022 01:53:06 +0000 Message-Id: <20221209015307.1781352-8-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=unavailable 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?1751699799672183925?= X-GMAIL-MSGID: =?utf-8?q?1751699799672183925?= Guest assertions depend on successfully allocating a ucall structure. As such, the use of guest assertions when ucall_alloc() fails simply leads to an infinite loop in guest code. Use GUEST_UCALL_NONE() to indicate failure instead. Though not technically necessary, use a goto to have a single callsite and an associated comment about why assertions don't work here. It isn't perfect, at least the poor developer gets some signal out of the guest... Fixes: 426729b2cf2e ("KVM: selftests: Add ucall pool based implementation") Signed-off-by: Oliver Upton Reported-by: Oliver Upton Signed-off-by: Sean Christopherson --- tools/testing/selftests/kvm/lib/ucall_common.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/kvm/lib/ucall_common.c b/tools/testing/selftests/kvm/lib/ucall_common.c index 0cc0971ce60e..e8370da3de24 100644 --- a/tools/testing/selftests/kvm/lib/ucall_common.c +++ b/tools/testing/selftests/kvm/lib/ucall_common.c @@ -41,7 +41,8 @@ static struct ucall *ucall_alloc(void) struct ucall *uc; int i; - GUEST_ASSERT(ucall_pool); + if (!ucall_pool) + goto out; for (i = 0; i < KVM_MAX_VCPUS; ++i) { if (!test_and_set_bit(i, ucall_pool->in_use)) { @@ -51,7 +52,14 @@ static struct ucall *ucall_alloc(void) } } - GUEST_ASSERT(0); +out: + /* + * If the guest cannot grab a ucall structure from the pool then the + * only option to get out to userspace is a bare ucall. This is probably + * a good time to mention that guest assertions depend on ucalls with + * arguments too. + */ + GUEST_UCALL_NONE(); return NULL; }