From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 90852C4332F for ; Thu, 8 Dec 2022 18:48:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=4OSwLMHPh+IZN5qiPwhhqxRL977KFeN8cYHZ2v12rPs=; b=PRCt84Yqa3TQWg JtzfIqpX8Jy8xvLBoTj+USwEYSbrXc1FQK8wMAYl0VFAudCGqE4QcHtgoDq1Qf7DesnBwuyOBPDoA bEYbaf1SVyPv7MseFWKg8w3OzlyljaIll0nbWVcN/8NibKw0cR33ovlmlcaXIiASQtr8GZdhfTYW9 TmzrPfSV1LJoG2MGNjq9I7LoSnNJcK17X1sG2+fxgLNZG9tFMNBcaNy15g3QCXcYYi5cLMV87Mj0r P1/JIsP2sttGE4+h5dWek8lnv2kMoeSR5Nl+TmlguBGhC1ezTSKd/yMT7ElBPuCqaIITh54lF3Cu0 4uGbkVtvIBYx1a4qzXYQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1p3Lve-008et0-PO; Thu, 08 Dec 2022 18:47:30 +0000 Received: from mail-pl1-x62e.google.com ([2607:f8b0:4864:20::62e]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1p3Lvb-008egg-OQ for linux-arm-kernel@lists.infradead.org; Thu, 08 Dec 2022 18:47:29 +0000 Received: by mail-pl1-x62e.google.com with SMTP id p24so2396850plw.1 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=0PXSHevXkQYZnGKaI2P7AeRPRkZdn9Vj2T0hoXc1jMOPxHuYL1PiAMA+zCuSXKAPW1 sEn4F3WxHObnS6h8JS+TtR/CLMKs+AiZNjt+dggro5KilOY9gsAYLZjghh3TWkeNjQJJ WSRXZVo5rlE5T9auOn0L8JZ+WKzVmC/Lrzkj2FAvRQjHqUmynIIjZxFGR1ZR6L/8WKBc SSEVptGipau7KxcG3Ew3bNvGqWeoYg8t+23hTfZh3okJjF7I85gfcU3P77GB1vwygnEu Ols3UzBD+9WKt8iefVCM7YWAwdnJElhZNxKMe7xAgco1ZzALTbDV2xG3DY1g04E3cTYU 9OlA== X-Gm-Message-State: ANoB5pkKPVUdPgZ3Wj7BQ0otrxHQLTwBrwGBVfnDRX4EsGzmHetRu6XG 8efNx6Jys71z5Era2Jt3H/14Lg== X-Google-Smtp-Source: AA0mqf6vd6AxHTUbjUvIEUAz0NQ7pMMjNAHpvKix0UHaCOnCHjNJp+LLTMFG9Y68lb2WJ+Cv0Q2hGg== 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-Disposition: inline In-Reply-To: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20221208_104727_816841_88ED0461 X-CRM114-Status: GOOD ( 29.15 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.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 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel