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 mm01.cs.columbia.edu (mm01.cs.columbia.edu [128.59.11.253]) by smtp.lore.kernel.org (Postfix) with ESMTP id AC15BC4167B for ; Thu, 8 Dec 2022 18:47:26 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by mm01.cs.columbia.edu (Postfix) with ESMTP id 172B84B992; Thu, 8 Dec 2022 13:47:26 -0500 (EST) X-Virus-Scanned: at lists.cs.columbia.edu Authentication-Results: mm01.cs.columbia.edu (amavisd-new); dkim=softfail (fail, message has been altered) header.i=@google.com Received: from mm01.cs.columbia.edu ([127.0.0.1]) by localhost (mm01.cs.columbia.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id bjYdwIzj4ZhE; Thu, 8 Dec 2022 13:47:24 -0500 (EST) Received: from mm01.cs.columbia.edu (localhost [127.0.0.1]) by mm01.cs.columbia.edu (Postfix) with ESMTP id E1A2F4BA0C; Thu, 8 Dec 2022 13:47:24 -0500 (EST) Received: from localhost (localhost [127.0.0.1]) by mm01.cs.columbia.edu (Postfix) with ESMTP id BE6FD4B992 for ; Thu, 8 Dec 2022 13:47:23 -0500 (EST) X-Virus-Scanned: at lists.cs.columbia.edu Received: from mm01.cs.columbia.edu ([127.0.0.1]) by localhost (mm01.cs.columbia.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id H32FF4s43Jxg for ; Thu, 8 Dec 2022 13:47:22 -0500 (EST) Received: from mail-pj1-f50.google.com (mail-pj1-f50.google.com [209.85.216.50]) by mm01.cs.columbia.edu (Postfix) with ESMTPS id 6664549E4B for ; Thu, 8 Dec 2022 13:47:22 -0500 (EST) Received: by mail-pj1-f50.google.com with SMTP id gt4so768125pjb.1 for ; Thu, 08 Dec 2022 10:47:22 -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=D2nUZPGSzPL5mKbd4f7LO7KE3dzZVWDHiXKuwDl6itxp5GCA3BQ/6D9GICV656D3+X G/G5u2Z+YV8Nv7kgMf9nNX9uVV+je8Vtyijswgg+Zwzz++mW9nNRZaQFztbks54kDi7S tHv6x+6HSKZHgDVXinyKneS6eN3w6ETHIPCE/QnwZeXo8S+Q6CVcg/v1nTGPdtSGenQe E44Dz84oa42hR45SQ95o3Bv9Q9s2+1DznDwFpRo2f9tqyFGBcf5fkctevUD3BHfeO2W6 R+v+Khv2e8RKN9+XWf4aq1Ru47MtVgpQFTKFHY6FNUqhhqX0JpH6L8PLWVsjn/zT9F0V X5DA== X-Gm-Message-State: ANoB5pnfeWmSXbxUyf0tRfzDGRoY/ZOYLHTAnWx4u8ulhGEtoW5Q8Bzo X0hkZ+4v6K+JmQT6bAp0XRMQOQ== 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 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: Cc: Shuah Khan , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, Marc Zyngier , kvmarm@lists.linux.dev, Paolo Bonzini , kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org X-BeenThere: kvmarm@lists.cs.columbia.edu X-Mailman-Version: 2.1.14 Precedence: list List-Id: Where KVM/ARM decisions are made List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: kvmarm-bounces@lists.cs.columbia.edu Sender: kvmarm-bounces@lists.cs.columbia.edu 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 _______________________________________________ kvmarm mailing list kvmarm@lists.cs.columbia.edu https://lists.cs.columbia.edu/mailman/listinfo/kvmarm From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pj1-f51.google.com (mail-pj1-f51.google.com [209.85.216.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0B478320D for ; Thu, 8 Dec 2022 18:47:21 +0000 (UTC) Received: by mail-pj1-f51.google.com with SMTP id js9so1414875pjb.2 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=0iOMJpWdAb5CSy1lZ3QbxAyOUS1k3wo9vah7lVY6JjIKdrav9WjvfmGIqZMP2JWzMZ 6ORzYMyIkUXIdTbK9ioUCmTuo5e1uxeqxR8fP8K5hLL5NAEkPck1sCfj9CGOSYUfvVHR 2PVZPxC+nftAw4aIy79bAmBe+CRZ1VDH0W6fknfEI44WOV4rJWrhz68ygpCYjgBrL+0H +44F7f5+q6KSLmnURgo8GOsHCbAHmFuM+4/e1kYpO8u5VSRHpiF9qMUZnrafYknqwDeJ VMQaHHpxE5WrUSMPdQ6HNXwHZihaVabp9yLmto4nQjz/diSNEoS5NZbP7efI4oHgmtKA 93+g== X-Gm-Message-State: ANoB5plNuDZluEo3Fl+C1xhFpFmIDKDSnoYV+lXkQaN67TrZhEuaKj/E SB5Mf41s7dGgdvAn/BnHQNEbYw== 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> Precedence: bulk X-Mailing-List: kvmarm@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Message-ID: <20221208184717.i7hDvRpYOZoPEJEYXXKaa8BA-cpaM0jF546PqznRn7s@z> 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 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