Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp234445rwb; Wed, 7 Dec 2022 17:14:56 -0800 (PST) X-Google-Smtp-Source: AA0mqf5QNlj3wenTw0j1exjN4k4TabGmu3rX7sLIjq3kahwIon4kKe8zvtyzIcO+AU8mu8HyLBoX X-Received: by 2002:a17:902:7898:b0:188:584d:b6d4 with SMTP id q24-20020a170902789800b00188584db6d4mr76838877pll.170.1670462096202; Wed, 07 Dec 2022 17:14:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670462096; cv=none; d=google.com; s=arc-20160816; b=ogPaL/BVue4NwlPDXETqO6m9+QJXmkCvLSRA45Vw5CcuB3YREETmFmurVT+mNwqUW/ a/hf0P2gX7SKhz3KM3y03PTFOa13E2lJ2tPUNraNGOpMhqBXlM3I8ryFfvIJZFQNAiX1 hTx10ztUW4AmmPLbZk+uoyTDV6WrwBr0WxPlsSaggDR3X7CWTeaFfM8vBSAW22m7Ej+c ydsXNBLjQPbpUaDfqOW239l9HCBmESjp8rOp3GKqpiAW96cJjKJunTqbNRaLFGK1IXgE BQICcQwqdV/GGX4bJjBNAbgCtS2G7U8qJqXXSML5HdDPK941kH/qTgHvI2it0GHzowv5 ZE5A== 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=5SF1vNKH61lFm3hfk5Bb+AduHkT/A0rKp5e/levYr44=; b=pjuVE+grrXNksfQUuO6//Gb5oJt2BtAzB5ANoyVG9JI6gEU5O2XHPF7N4X+tDQJxdL lHp5LisqY3yhGHWaYBrEJHApBn8U84IvK5faAlkosD6zcUkswLB97UhJe87IQqjFLehu zE0NOveVpmMvs3d33LEsxGaMub5nrTEscWENNFRMV343Y9IipHJfF5ivMYL9f+NNIgQg qW4uK1AROhrtOqsYDGbutoCCPeeu2HTv2Q/t5F2+1/5l1+r1BLvTzEEoIyIu7LQmnQmS SZ4ykgW99Yl2iEC4dS4qbYMpbpoghUd8EaxpyKcDMXowgiYJ+zdhm7nysWUUNXdhWcRL 2LaQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=TxrIijlK; 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 n13-20020a65450d000000b00478ee0ffc8bsi4143206pgq.792.2022.12.07.17.14.46; Wed, 07 Dec 2022 17:14:56 -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=TxrIijlK; 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 S229680AbiLHAY3 (ORCPT + 74 others); Wed, 7 Dec 2022 19:24:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45376 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229523AbiLHAY1 (ORCPT ); Wed, 7 Dec 2022 19:24:27 -0500 Received: from mail-pf1-x42a.google.com (mail-pf1-x42a.google.com [IPv6:2607:f8b0:4864:20::42a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2E48788B47 for ; Wed, 7 Dec 2022 16:24:26 -0800 (PST) Received: by mail-pf1-x42a.google.com with SMTP id x66so18935532pfx.3 for ; Wed, 07 Dec 2022 16:24:26 -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=5SF1vNKH61lFm3hfk5Bb+AduHkT/A0rKp5e/levYr44=; b=TxrIijlKNemLsvVUWhbEvHLRzcC6kGYva9u4pTpNLVjZOSDgHPUtrPJcvdl7yu9EW3 gH0qAWTdI3PrrFOB2fKIFdUG4mm4d6rkIq/vrYaNyzOXXDSEnxnvi/pJaMS8u1deGkJD WnRUdOlmYdyFTSL9vEtdQSxevxVF+84aksPKWAT5+6Qg8xEn1zXneEe4PIIvU+fSqBWp rY2tugHj6Ftr8kAdI8/DEtGI59QMeqVjXtRQiJ8Q6a0WmVT3LbrXE1J+FzmeHSUeLAaj U1cZMf+fl9S0zPGeUYpOWdGWOwfey9jODY5T0UklNZnZj7+8fqXXltoTbKVw3qPZaYLv KoTQ== 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=5SF1vNKH61lFm3hfk5Bb+AduHkT/A0rKp5e/levYr44=; b=XPnRX9zfxtKFD75HKP/dwNRqPYkDX1wBW2lhBP2/jGSkkk0Q7v1O550rWzXA5pPalL QseS+hPSCCPXuvf9a38VgwfzCT3ew5o1sl5OSRlaPaKj3otMSPBrmXNwZX010jFQrkUJ lrdBCs2EAzLrlqj8d8zF6kkB5pOXZ5OwIOF09lKlWe6dfVHMyMnYeXurSPeV6Kcvq6GO 8jj86lj6tYjJOgsz1eUel2IwOTPTw1lU/VZjowbwFWXLyYzc1vuP6sbcsAlTJPNEZVRF 643PpB8r2H/6RKqjLBcry7vFPqpqXsXIDrHDXLaaGJxo8hVKBcLkojHb/0cnc+24zJNo M8ug== X-Gm-Message-State: ANoB5plgY6U0yPnL0B64vYDg6l0QEeRCVX6SbCog52uA6RpqMKRNVPsM QyAAWzY1kuuvZ2PiNf5W1rtKbQ== X-Received: by 2002:a62:b60d:0:b0:574:8995:c0d0 with SMTP id j13-20020a62b60d000000b005748995c0d0mr1460040pff.1.1670459064104; Wed, 07 Dec 2022 16:24:24 -0800 (PST) Received: from google.com (7.104.168.34.bc.googleusercontent.com. [34.168.104.7]) by smtp.gmail.com with ESMTPSA id k85-20020a628458000000b0057725613627sm4955021pfd.142.2022.12.07.16.24.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Dec 2022 16:24:23 -0800 (PST) Date: Thu, 8 Dec 2022 00:24:20 +0000 From: Sean Christopherson To: Oliver Upton 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-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, 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. > 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. Oooh, this crud: virt_pg_map(vm, mmio_gpa, mmio_gpa); Yeah, that needs to be fixed. But again, that's a separate issue, e.g. selftests can allocate a virtual address and map the read-only memslot.