Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp2185053rwl; Thu, 13 Apr 2023 02:55:44 -0700 (PDT) X-Google-Smtp-Source: AKy350YNZK85yP6oN4ZFpsqqeN/SZ5B7ikqEuI4wBDQ3RoAxr3H9XWI3D/wCf6hmklaqOI5OFOmJ X-Received: by 2002:a17:902:ce92:b0:1a6:494b:5b0 with SMTP id f18-20020a170902ce9200b001a6494b05b0mr1732041plg.40.1681379744248; Thu, 13 Apr 2023 02:55:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681379744; cv=none; d=google.com; s=arc-20160816; b=mbgT2AOlb9DXJAhRW4O3zen3CQ2PIyMHlIsxqqjcJ2/clq7J1zDbd4gncYGxGbD4CQ MgcuIqnzLlg4V/iAko1Clal3N/UARGsv7A+dztgn9/gG28iGNJNTqAR7zcYd1/t20jIV rAAEh9t5c6YJ9rMTCoP1JPIZY1yf547ZZXxWC7/NDRur/7mpHoKqwxkmCnH8O8Qhu9um AQIFpMGBFfFwVDr/95i0KFe+zUPLvSHvmaNoR4TX8g+GZp23U9ymFxqrLvg63yZiCl8v +vynq+kA3VlCn+LCzCDsnl4r3Jwe4pp3MBHZfhjlWG3JmdIj282S55+pGPhxvktoVkbm LXPQ== 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=4bGZ09AQC0vBrHCyowPhxPIQB9fKnG+5BM2lavhm+As=; b=Lp4tG5PMACQU4Q125eCNkjC2LYqFdU7hteVLoohvjTqKEBLTI0wo4lO98AN8PScw1L oXu4AWFSNQhhPrx2WUXowUH8dV0SLKRPJ70wMwyVdJPOP2C9pJ48AVpu5dtBQW6h2YJf NMiTMHQvB8vnAK/rEXkY4IDXdGdTyx2Y1trcpUpSpgyT+siCCkWsMzLCdcVtaaQz1bJk 9oB/V3pA1e3Pp8aLkSc9Y3DafnsR4w5LhjY+ljfI+vu9jUtZKpdAk1f7FWkFk+GNVssr hKSwzjUXuxKPKSzs9TaT2cEv7R7kTxJGEfpUt2+pbrsdnZiI15fyEuwDE/49EggvxT1o lWGA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=EdN+myph; 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 h18-20020a63df52000000b004fc257265cfsi1753038pgj.267.2023.04.13.02.55.33; Thu, 13 Apr 2023 02:55:44 -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=EdN+myph; 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 S230007AbjDMJyd (ORCPT + 99 others); Thu, 13 Apr 2023 05:54:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44154 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229935AbjDMJya (ORCPT ); Thu, 13 Apr 2023 05:54:30 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D2DA29772; Thu, 13 Apr 2023 02:54:27 -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 6B67363AF8; Thu, 13 Apr 2023 09:54:27 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id AC81FC433D2; Thu, 13 Apr 2023 09:54:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1681379666; bh=0DrIy6L0mgWBKpbiTpq/w5yQJ7iegdOLGEBJBIpU3z4=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=EdN+myph2daeRxjNIkFWfOM2t26TzhiMQWFyoSYKoocfQSYMVwt5SRXo47+M1kbZv Y1xnQKPqWNUeBYKFGYZY2NFHGl3ZzGYsbjmq3UNekcihjdKBOQ3o2mFqnNRHK8z+Kl 7sL78rTsa/8W3U4KnUKPRtOqGmFO1Oiha6zimkCB8s+ZZREiO1GnHvwivWaYTG+lG7 FGOBzjCckphv4nxlAuPtjuTDqm0MiQC9HiGE825z9qiNBlJlyBxGZxfYcNNsRp+Ssx dBvCDP9AYH/khreMqUT+Fd3C3HWkjjXJAKjTswQvrt4KsDyyKru2otjlwS4cZqPyJ+ oHQNQ7FB0MrOg== Date: Thu, 13 Apr 2023 10:54:18 +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 v11 12/26] gunyah: vm_mgr: Add/remove user memory regions Message-ID: <20230413095418.GA25922@willie-the-truck> References: <20230304010632.2127470-1-quic_eberman@quicinc.com> <20230304010632.2127470-13-quic_eberman@quicinc.com> <20230324183659.GB28266@willie-the-truck> <5d1c6160-6bc4-5246-2a0b-de5ddcbbc2c4@quicinc.com> <20230411211940.GC23890@willie-the-truck> <67209a0d-1dc5-ce96-e916-85bfd8f6a7f8@quicinc.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <67209a0d-1dc5-ce96-e916-85bfd8f6a7f8@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 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 Wed, Apr 12, 2023 at 01:48:07PM -0700, Elliot Berman wrote: > > > On 4/11/2023 2:19 PM, Will Deacon wrote: > > On Tue, Apr 11, 2023 at 01:34:34PM -0700, Elliot Berman wrote: > > > On 3/24/2023 11:37 AM, Will Deacon wrote: > > > > On Fri, Mar 03, 2023 at 05:06:18PM -0800, Elliot Berman wrote: > > > > > + > > > > > + pinned = pin_user_pages_fast(region->userspace_addr, mapping->npages, > > > > > + FOLL_WRITE | FOLL_LONGTERM, mapping->pages); > > > > > + if (pinned < 0) { > > > > > + ret = pinned; > > > > > + mapping->npages = 0; /* update npages for reclaim */ > > > > > + goto reclaim; > > > > > + } else if (pinned != mapping->npages) { > > > > > + ret = -EFAULT; > > > > > + mapping->npages = pinned; /* update npages for reclaim */ > > > > > + goto reclaim; > > > > > + } > > > > > > > > I think Fuad mentioned this on an older version of these patches, but it > > > > looks like you're failing to account for the pinned memory here which is > > > > a security issue depending on who is able to issue the ioctl() calling > > > > into here. > > > > > > > > Specifically, I'm thinking that your kXalloc() calls should be using > > > > GFP_KERNEL_ACCOUNT in this function and also that you should be calling > > > > account_locked_vm() for the pages being pinned. > > > > > > > > > > Added the accounting for the v12. > > > > > > > Finally, what happens if userspace passes in a file mapping? > > > > > > Userspace will get EBADADDR (-14) back when trying to launch the VM > > > (pin_user_pages_fast returns this as you might have been expecting). We > > > haven't yet had any need to support file-backed mappings. > > > > Hmm, no, that's actually surprising to me. I'd have thought GUP would > > happily pin page-cache pages for file mappings, so I'm intrigued as to > > which FOLL_ flag is causing you to get an error code back. Can you > > enlighten me on where the failure originates, please? > > Ah this ended up being an error on my part. Userspace was opening the file > as RO and Gunyah driver will unconditionally add FOLL_WRITE as part of the > gup flags. I got the flags aligned and seemed to be able to boot the VM ok > and it works as expected. I suspect you can run into latent filesystem corruption issues in this case, as the VM can dirty pages without the filesystem knowing. That's why we restricted anonymous memory with pKVM for now. Will