Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp233941rwb; Wed, 7 Dec 2022 17:14:27 -0800 (PST) X-Google-Smtp-Source: AA0mqf5s9mhMTMQBCDDQEFpaBJxlbUXC38hlcTkifankOQgVUuOOEkptsyuKDYJPGOTCuHL5b/a4 X-Received: by 2002:a17:90a:12c5:b0:219:a02f:87ff with SMTP id b5-20020a17090a12c500b00219a02f87ffmr25141447pjg.27.1670462067650; Wed, 07 Dec 2022 17:14:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670462067; cv=none; d=google.com; s=arc-20160816; b=cCMppicbgIHez3SWca9tb30hsYmMvsY9YVZTTYBer1sP/mxkGX+ysM4AXn8Sj0Nq9j jRJa7n7EP3guXUeivUg5JnBWJzas0bJO948c3AxsSmRSRGJMIW2eL7Q7baoL+5ODA2+q Juw8vWdAksG5tWpOIzMjkXoDWk6EXRX/jU4t+dyVzRgJ4Zb540MZft88QeuAoqSpWkrv VDwecdup3Xk4pg6hcJx+dYju1k6HiZ5GPRLwmyqmUZFUb5IkV2GXK4ynUnG75Dug9ZuE abneI7Sbq2F2tVLkjaTgdRyyJ25kW6qYg7oystddqdmdi5krc5Fi4+bVdTMqSL501b+i GZPQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:dkim-signature:date; bh=mM+RUREs8XNQIXR9OLpX5FpMS6Cj+6d+9P8d8/tGhYQ=; b=edQWd64dq5cJ2PRWzds1eEDt/zqSA0ffvpjw383ET0kb5z3bTSsBBuqyWPGPAcj+xX siHWbkmc3l2aTmo3XPbqYcnnxSq0t6L4cv0p5nWCCEZATAlAoC35eaUXiYvzY5Fn20ia MzYPBxL4Gwfk2bmA8y28hORYJQu+MeUF8bBYeIn7N/ED4Dk8Jah0mu2LoxDHUkakvf3G j49ZnZA38g/O6AagXVxn0Q/L7Zr5B00GZbMHGuG/nGOyTFI9G846qLyj2XEP4JuKMI7y KHhgWudkgz+pEJsufD9pbI4gjypk0uefiCySnZAQm8znV+FF2rQHlDTqBFaaNGsdfUbS QYaA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b="ku/5sjzd"; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q14-20020a170902dace00b001893e9d712dsi23600575plx.557.2022.12.07.17.14.18; Wed, 07 Dec 2022 17:14:27 -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; dkim=pass header.i=@linux.dev header.s=key1 header.b="ku/5sjzd"; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229676AbiLHASB (ORCPT + 74 others); Wed, 7 Dec 2022 19:18:01 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42946 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229635AbiLHASA (ORCPT ); Wed, 7 Dec 2022 19:18:00 -0500 Received: from out2.migadu.com (out2.migadu.com [IPv6:2001:41d0:2:aacc::]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 172576150C; Wed, 7 Dec 2022 16:17:59 -0800 (PST) Date: Thu, 8 Dec 2022 00:17:53 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1670458677; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=mM+RUREs8XNQIXR9OLpX5FpMS6Cj+6d+9P8d8/tGhYQ=; b=ku/5sjzdHABEj1t0G+fh8i2C1G7TPlKULEuuL0AsGRUb9Ux6kV59QeDru18AX6//yF0gQQ qi9glC8ovSUnX0pEdAH+zSKl6LwdATrWKndnT9rxxTgYbq5nvQ5YxEWiKGiwHKt1PKXK4y q+b7skuzGcfVu+l+lCWV2z9h/98c+6U= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Oliver Upton To: Sean Christopherson Cc: Marc Zyngier , James Morse , Alexandru Elisei , Suzuki K Poulose , Paolo Bonzini , Shuah Khan , linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org, kvmarm@lists.linux.dev, Ricardo Koller , linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 2/4] KVM: selftests: Setup ucall after loading program into guest memory Message-ID: References: <20221207214809.489070-1-oliver.upton@linux.dev> <20221207214809.489070-3-oliver.upton@linux.dev> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Migadu-Flow: FLOW_OUT X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_PASS, 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 On Wed, Dec 07, 2022 at 11:57:27PM +0000, Sean Christopherson wrote: > On Wed, Dec 07, 2022, Oliver Upton wrote: > > 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 this actually working is to have the program image > > already loaded into guest memory. > > Ouch. Might be worth explicitly stating what goes wrong. Even though it's super > obvious in hindsight, it still took me a few seconds to understand what > precondition you were referring to, e.g. I was trying to figure out how selecting > the MMIO address depended on the guest code being loaded... > > > > > 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); > > Isn't there a hole after CODE_AND_DATA_MEMSLOT? I.e. after memslot 0? Sure, but that's only guaranteed in the PA space. > The reason > I ask is because if so, then we can do the temporarily heinous, but hopefully forward > looking thing of adding a helper to wrap kvm_vm_elf_load() + ucall_init(). > > E.g. I think we can do this immediately, and then at some point in the 6.2 cycle > add a dedicated region+memslot for the ucall MMIO page. Even still, that's just a kludge to make ucalls work. We have other MMIO devices (GIC distributor, for example) that work by chance since nothing conflicts with the constant GPAs we've selected in the tests. I'd rather we go down the route of having an address allocator for the for both the VA and PA spaces to provide carveouts at runtime. There's another issue with the new ucall implementation where identity mapping could stomp on a program segment that I'm fighting with right now which only further highlights the problems with our (mis)management of address spaces in selftests. -- Thanks, Oliver