Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp1465908rwb; Thu, 8 Dec 2022 11:00:49 -0800 (PST) X-Google-Smtp-Source: AA0mqf6uZFXxX2oV5TdCmfw7uVcLS30xBy7Zo9wDamalguf/enhic0wevAN4JMogcR6zcSQGmMbI X-Received: by 2002:a63:334a:0:b0:478:d2ac:c963 with SMTP id z71-20020a63334a000000b00478d2acc963mr12453084pgz.446.1670526049284; Thu, 08 Dec 2022 11:00:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670526049; cv=none; d=google.com; s=arc-20160816; b=LhYcLgV8uORYh+9w5Xa8SoP91xUQr4X6ZNtrXaaCZHLXP7cILyoG7IMTNrcRFqAemG MXwqtk0R1ODc1JE3sQ4sx/oeVoc8+YP9dqfXc9l1WCI6cC04DrkUhzirCdwa/UvxKCOX eEAO+/hM85PgU6IwbEinrplArcyl+kDBSbT55Ugoohq2IbVmabD/M3sBR2ueDl6DFEOH pu3zSYo6QcS4ncKuYee2FN8v+tohYxG/RaCG+/gxDEYfaWBsvK2TsDaE9+yd0+HceCvy dJlm6ozHsVKnXT0lQjFfIUkZSCF7GrnkNH8/35jJIch8ZI9vuT3bhSMr4GRJP1zb7RZn 6bZA== 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:date:dkim-signature; bh=j7cHwl40udJhj8Y5X5w0jT3sEs53ZGdIUSJNwRYVu/w=; b=dximdQ40h47VKCr/3ScW1KoPZ88ePq78xySckesLfEz46OnDr6CFoYsA7OUmaiOd0X /woLxWE9jCFWJ5wkUG0fPbU5oiyKZSq2V3hncM9aG/k50j0qEXgDPTZOBDpBLYT99OUF EZB82+5VVW0ZzWWHKCGF41rhya9NyHfyA4WU3bRvBnk4M5EwKmVriwSbW//xd4MS4Zjm LUqI8aLTAB9N2hcvRJQ05exmv8Sk1uD/n/L4vM2TjF2dNyreWbh83JqNlLtYZdkarkL9 t0FbAd3EJ+Ji0DpQ6XI77JUnhWBonsm5o533szraiXPFLB5qgJnzrXr0RrDOdrLVtF/a r2gg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b="Kk0pmB/x"; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w6-20020a63f506000000b00478bf145f38si11943956pgh.41.2022.12.08.11.00.39; Thu, 08 Dec 2022 11:00:49 -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=@google.com header.s=20210112 header.b="Kk0pmB/x"; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229841AbiLHSr0 (ORCPT + 74 others); Thu, 8 Dec 2022 13:47:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56374 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229605AbiLHSrX (ORCPT ); Thu, 8 Dec 2022 13:47:23 -0500 Received: from mail-pj1-x1036.google.com (mail-pj1-x1036.google.com [IPv6:2607:f8b0:4864:20::1036]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EA11784267 for ; Thu, 8 Dec 2022 10:47:21 -0800 (PST) Received: by mail-pj1-x1036.google.com with SMTP id u5so2406816pjy.5 for ; Thu, 08 Dec 2022 10:47:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=j7cHwl40udJhj8Y5X5w0jT3sEs53ZGdIUSJNwRYVu/w=; b=Kk0pmB/xVnaM5ZpgSosT/bmJl6omVaUQZP2piO1stBvkhoJj09JAMEnLa5p0gtxaGp VB7g+dz6WsXuzFyafcY8UNr3vvtXehmmHe02Mm9nFxmyuMsh/wLMv8H3DERotIKWi6AO znLK5EtaINJvDL0b5Oo99YEUgZo45VxCAEobT8jJtFugipi/9yBthEL78JaKdg08Xbph pXkMrQOicMZtmPej55vRfzNvlAHJWxAl6d+e88VeYqBJThVpJ8xmvTsam41HzLJ8vSx+ pcYvIRTsXUGU4NF/+rQgmSnF2q0eoUpL4dRNVUkSoHlur/WtaG74BlpZUGwEzD/yuL7l GLFw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=j7cHwl40udJhj8Y5X5w0jT3sEs53ZGdIUSJNwRYVu/w=; b=23fT5h51AqqDUCPSffvA2XMbptCW19Rvb/a9+ik3AVDsQb7tHS0SSsXmdRjJFpKVxh IYvzSSWDgKL1W1qMNL1NjFusfprVqQyD8T5b1eM5WE2NmOw5MJ1oBcHX9zqb5RiwH63E VEktyx6tMR5rKMj74NUD2nl9lVVtF0XPlmCbL4xcdE8/98isSpJ6acRMz92+dxFkYYGF gvjdy/LYaOgLQBjk3O+CcJXDSXy5KiULhuLedm0omlKKAl2g3bKCKsg4WKsyIc1deafv vs4ZAKafJ7j2LliRfmSzYtNA3ZLMZH+s+iKiMhxrSO/WAwDrjT3Zb1OVMyIiY5/YN4OF FDjA== X-Gm-Message-State: ANoB5pli0bsZLc9zwG+bNYVnNVtUB2WilyDVyAxIvY6EPaxkEq+Lhssx vKkAoyy7R358mQxG6BnmZrCgFQ== X-Received: by 2002:a17:90a:fd0d:b0:219:828e:ba2 with SMTP id cv13-20020a17090afd0d00b00219828e0ba2mr1498746pjb.0.1670525241105; Thu, 08 Dec 2022 10:47:21 -0800 (PST) Received: from google.com (220.181.82.34.bc.googleusercontent.com. [34.82.181.220]) by smtp.gmail.com with ESMTPSA id ay22-20020a17090b031600b001fd6066284dsm13381pjb.6.2022.12.08.10.47.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Dec 2022 10:47:20 -0800 (PST) Date: Thu, 8 Dec 2022 10:47:17 -0800 From: Ricardo Koller To: Oliver Upton Cc: Sean Christopherson , 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, 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-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL 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 Thu, Dec 08, 2022 at 12:37:23AM +0000, Oliver Upton wrote: > On Thu, Dec 08, 2022 at 12:24:20AM +0000, Sean Christopherson wrote: > > On Thu, Dec 08, 2022, Oliver Upton wrote: > > > On Wed, Dec 07, 2022 at 11:57:27PM +0000, Sean Christopherson wrote: > > > > > 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. > > > > Aren't those two separate issues? The PA, a.k.a. memslots space, can be solved > > by allocating a dedicated memslot, i.e. doesn't need a carve. At worst, collisions > > will yield very explicit asserts, which IMO is better than whatever might go wrong > > with a carve out. > > Perhaps the use of the term 'carveout' wasn't right here. > > What I'm suggesting is we cannot rely on KVM memslots alone to act as an > allocator for the PA space. KVM can provide devices to the guest that > aren't represented as memslots. If we're trying to fix PA allocations > anyway, why not make it generic enough to suit the needs of things > beyond ucalls? One extra bit of information: in arm, IO is any access to an address (within bounds) not backed by a memslot. Not the same as x86 where MMIO are writes to read-only memslots. No idea what other arches do. > > -- > Thanks, > Oliver I think that we should use these proposed changes, and then move to an ideal solution. These are the changes I propose: 1. add an arch specific API for allocating MMIO physical ranges: vm_arch_mmio_region_add(vm, npages). The x86 version creates a read-only memslot, and the arm one allocates physical space without a memslot in it. 2. Then change all IO related users (including ucall) to use vm_arch_mmio_region_add(). Ex: pa = vm_arch_mmio_region_add(vm, npages); ucall_init(vm, pa); page_fault_test needs to be adapted to use vm_arch_mmio_region_add() as well. Thanks, Ricardo