Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp2369754rwd; Fri, 19 May 2023 05:02:22 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7J39lPs5TwvUUhkY0s/Bbw/TQIQaNX4zij94VbBpU0Fb1hmsS4TGd4ej3v7Nz0NZbvUBia X-Received: by 2002:a05:6a00:23c7:b0:63d:2f13:200 with SMTP id g7-20020a056a0023c700b0063d2f130200mr3181362pfc.16.1684497741775; Fri, 19 May 2023 05:02:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684497741; cv=none; d=google.com; s=arc-20160816; b=rtIGEly/4vlx9vQ3xlSjXlNF/yLv0ml3hyla+CWbc3miSm0jVlYA7mAoXWyU7DpTGi qScX61l7UrO3VZ65MMnW2xoPMAASEzVAa9EJ9nhlDKbEc7CXTQ5ymi6wyz3H/1URhrOH KnCRe2QQcaEXTBxUV1wmhwNZbO7JSOZpQP7jlpkqJzL/JUAqJa5uq5jBVaMYamDiCV3/ +z5m2Rok4ZmDiaNEnSZ0/0QiljPPXoSoy8DkVnzLEwlL714RIXaOEi/vIeOGCK8gTi/Y EWwYpkt//HWmYMoWLAxF+LiT+GBp7rmRD3p+YoVYBpVfE9hFbUy+owW4KXTQOX2OQcwT jBrA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=81LQWVZ20OKuJ7l1NwvhXL2FzsCKUTZrf38wDasZGng=; b=IbgxMvbUOcuRyv9KQz5M/OSFGcxl20D52UxvfCIokZ0rGQa5+YqNt3QUGwqdlwSym2 VTeu8wOgQD2ye9B7Zr59v1MyPK9cMuQ0Ev+lH7558kWlD4TMlD2jzq9NNb9izS4HKIM7 VQYQ7nb2ei8swoZHf4Z/4YNVchMGNGwOgk3U9+HvwX6oaEFZzLirRYLHwcFdpJvhswfP SBe11yIY5yVnSOc+uhaU9j6/vcr7klHr4pg604WttB4ToC6wWuHLvz14K8P/r8ZdZoBG SE31J6Y8OqzmWazfxNkcSN6fpDYlxSHwbm/TI4FZDK5pDJE+wp5FZC/scCr5ArX4iaXW 4Fcg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=rl3XaIMl; 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=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f64-20020a625143000000b0063b356e36fesi3793147pfb.372.2023.05.19.05.02.04; Fri, 19 May 2023 05:02:21 -0700 (PDT) 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=@kernel.org header.s=k20201202 header.b=rl3XaIMl; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231169AbjESMAA (ORCPT + 99 others); Fri, 19 May 2023 08:00:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43974 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229571AbjESL77 (ORCPT ); Fri, 19 May 2023 07:59:59 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 05EADF5; Fri, 19 May 2023 04:59:58 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 955C765710; Fri, 19 May 2023 11:59:57 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E6ECCC433EF; Fri, 19 May 2023 11:59:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1684497597; bh=jGfCp1g8O5R8vITSnEGD8PGxEQbGPlY0ilYpANNCCaA=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=rl3XaIMlUbNbyDZRfTH8BGhpI6z9Y9DxA6Svt94cOsXYGzba520RDaU0XgL24vKdM La3NQRENMGf2yXJziYPJq+MzgzRZIzqWpoNcjDWRa6I8vGsvsbnl2o5eYY05go683w lHFsXp+mjrnKW1jVMXk4PIxcvEJoaaCPZAroSn/INjFJhJ+tl/k+cCS8asEYp5S2JM HsunLtnp4zHAklMhHbSSYxvWgnU3fKmC1A1JDYi+2tGAWV/fZ+Ev+2a+Chc9lFWh9c lq0yhdjf/BDk8+6xRkZq2gQwNkcLT4l2u4XlbmMjapUH+MZRGHNUVbDAb3AYkgn173 wsYZ/eTE+RuBQ== Date: Fri, 19 May 2023 12:59:49 +0100 From: Will Deacon To: Elliot Berman Cc: Alex Elder , Srinivas Kandagatla , Prakruthi Deepak Heragu , Murali Nalajala , Trilok Soni , Srivatsa Vaddagiri , Carl van Schaik , Dmitry Baryshkov , Bjorn Andersson , Konrad Dybcio , Arnd Bergmann , Greg Kroah-Hartman , Rob Herring , Krzysztof Kozlowski , Jonathan Corbet , Bagas Sanjaya , Andy Gross , Catalin Marinas , Jassi Brar , linux-arm-msm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: Re: [PATCH v13 10/24] gunyah: vm_mgr: Add/remove user memory regions Message-ID: <20230519115948.GB2637@willie-the-truck> References: <20230509204801.2824351-1-quic_eberman@quicinc.com> <20230509204801.2824351-11-quic_eberman@quicinc.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230509204801.2824351-11-quic_eberman@quicinc.com> User-Agent: Mutt/1.10.1 (2018-07-13) X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 Hi Elliot, On Tue, May 09, 2023 at 01:47:47PM -0700, Elliot Berman wrote: > When launching a virtual machine, Gunyah userspace allocates memory for > the guest and informs Gunyah about these memory regions through > SET_USER_MEMORY_REGION ioctl. > > Co-developed-by: Prakruthi Deepak Heragu > Signed-off-by: Prakruthi Deepak Heragu > Signed-off-by: Elliot Berman > --- > drivers/virt/gunyah/Makefile | 2 +- > drivers/virt/gunyah/vm_mgr.c | 59 +++++++- > drivers/virt/gunyah/vm_mgr.h | 26 ++++ > drivers/virt/gunyah/vm_mgr_mm.c | 236 ++++++++++++++++++++++++++++++++ > include/uapi/linux/gunyah.h | 37 +++++ > 5 files changed, 356 insertions(+), 4 deletions(-) > create mode 100644 drivers/virt/gunyah/vm_mgr_mm.c [...] > +int gh_vm_mem_alloc(struct gh_vm *ghvm, struct gh_userspace_memory_region *region) > +{ > + struct gh_vm_mem *mapping, *tmp_mapping; > + struct page *curr_page, *prev_page; > + struct gh_rm_mem_parcel *parcel; > + int i, j, pinned, ret = 0; > + unsigned int gup_flags; > + size_t entry_size; > + u16 vmid; > + > + if (!region->memory_size || !PAGE_ALIGNED(region->memory_size) || > + !PAGE_ALIGNED(region->userspace_addr) || > + !PAGE_ALIGNED(region->guest_phys_addr)) > + return -EINVAL; > + > + if (overflows_type(region->guest_phys_addr + region->memory_size, u64)) > + return -EOVERFLOW; > + > + ret = mutex_lock_interruptible(&ghvm->mm_lock); > + if (ret) > + return ret; > + > + mapping = __gh_vm_mem_find_by_label(ghvm, region->label); > + if (mapping) { > + ret = -EEXIST; > + goto unlock; > + } > + > + list_for_each_entry(tmp_mapping, &ghvm->memory_mappings, list) { > + if (gh_vm_mem_overlap(tmp_mapping, region->guest_phys_addr, > + region->memory_size)) { > + ret = -EEXIST; > + goto unlock; > + } > + } > + > + mapping = kzalloc(sizeof(*mapping), GFP_KERNEL_ACCOUNT); > + if (!mapping) { > + ret = -ENOMEM; > + goto unlock; > + } > + > + mapping->guest_phys_addr = region->guest_phys_addr; > + mapping->npages = region->memory_size >> PAGE_SHIFT; > + parcel = &mapping->parcel; > + parcel->label = region->label; > + parcel->mem_handle = GH_MEM_HANDLE_INVAL; /* to be filled later by mem_share/mem_lend */ > + parcel->mem_type = GH_RM_MEM_TYPE_NORMAL; > + > + ret = account_locked_vm(ghvm->mm, mapping->npages, true); > + if (ret) > + goto free_mapping; > + > + mapping->pages = kcalloc(mapping->npages, sizeof(*mapping->pages), GFP_KERNEL_ACCOUNT); > + if (!mapping->pages) { > + ret = -ENOMEM; > + mapping->npages = 0; /* update npages for reclaim */ > + goto unlock_pages; > + } > + > + gup_flags = FOLL_LONGTERM; > + if (region->flags & GH_MEM_ALLOW_WRITE) > + gup_flags |= FOLL_WRITE; > + > + pinned = pin_user_pages_fast(region->userspace_addr, mapping->npages, > + gup_flags, mapping->pages); > + if (pinned < 0) { > + ret = pinned; > + goto free_pages; > + } else if (pinned != mapping->npages) { > + ret = -EFAULT; > + mapping->npages = pinned; /* update npages for reclaim */ > + goto unpin_pages; > + } Sorry if I missed it, but I still don't see where you reject file mappings here. This is also the wrong interface for upstream. Please get involved with the fd-based guest memory discussions [1] and port your series to that. This patch cannot be merged in its current form. Will [1] https://lore.kernel.org/kvm/20221202061347.1070246-1-chao.p.peng@linux.intel.com/