Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp2180074pxb; Fri, 5 Mar 2021 09:03:14 -0800 (PST) X-Google-Smtp-Source: ABdhPJza3weysmYma55CgHmueXT8aSdxgFlSJuP8Cw7182aSJvnmj7CxDDq+tPMAomoJJNTt9IEP X-Received: by 2002:aa7:d2d5:: with SMTP id k21mr9678474edr.216.1614963793846; Fri, 05 Mar 2021 09:03:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614963793; cv=none; d=google.com; s=arc-20160816; b=tnpV6KdUiavxIVNGK6tWGim08qWzdMACrXnkry6Z1BCwzS/eKUT1V735PYCff5qnFv FUMA0sAsl3IDvaismUDi97uGHH7F98fcdkB7mtq2Kr7yOVR3mJuWG2J1iXEeUKkyxUqS +DrDgTOMZfZwvx2ZNCBHIiCKjkvLIRdCZeSL7vYs374zSm9NDLuzncyxd7jFmtGcLMJn JjTEVfyyLmtwhv+lJiuUlrLpVOZnn4kzEGe82ql22d3RzE9zi2qE5XLkT5TVUltwzs2+ 6AVu/3z00tnvmwLl6V4ejfbU/SdHww2sHTCffu9PiMFUCFuIy55aT22izShCJEOYCBxI N+8w== 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=+mXWzmd1ensOX7RRJJW6FMjyJgakGCM4rxYF2EocL50=; b=qYoSki/9iWJyCEp/VQ6uwMn/PXE5/9/jL0lgq/y9Hfijc+JPzMzqXuj/nmSOmPbZ/t 9s4WxP1Fb8q1D+waft2kLjndruE9sCL917ssLbDvckeNGbAvxUPHaPMio505HJCvfBbJ KegWWlMQzTPXyUW5LcwHVc9QUlX+tCGN9XkcBAUr9vo80seKwOIGdqCChPDOLguY6C1u Fz4ymEKZGztWiH0VmrgPqJZ0vYiYZdWjp9bm1dw1GZ4evZDtcpqDxiBrhoO9j+OpJsG1 AiUwH4ctlDINrMsP/XnhmEryHljEAk8VKPDjFnRmTOsOvw8GSOcbDy4NBZjjH2ONEt6t TeGw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ZUPrT4Wr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id yd6si1655171ejb.302.2021.03.05.09.02.48; Fri, 05 Mar 2021 09:03:13 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ZUPrT4Wr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S231313AbhCEQ7Q (ORCPT + 99 others); Fri, 5 Mar 2021 11:59:16 -0500 Received: from mail.kernel.org ([198.145.29.99]:44102 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230387AbhCEQ7L (ORCPT ); Fri, 5 Mar 2021 11:59:11 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 5B31D64F1E; Fri, 5 Mar 2021 16:59:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1614963551; bh=Anr2szlxokrML4bcZ0Hk4njlruTj6i3bBKAsz8Ik/i8=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=ZUPrT4WrxDvcA5waC/JCToBDhp1Kk6d3fuhFTFtApJbxl0DgugRoL98HlHKCN+L7k tDU5jCwdV+7H8hoi0mdwLKsCb6Sb6+QgoyLpevCgAngM79HAAGqMdDWgx6G4KN1p0z 3jQAWjeCtBm8z+uq76vuvHzUu3XyyM/ucb1oWgdgFZeql/ibvBWxASXsCw5Ya/5Bj9 66KUukox4oZMKGGxtCD3+ISsnUhlVKb4PZPuMde71ut26Ojz2C/0qfpL0Lex4NeBt9 /cwZFHGTuCvZyl0jAguHl1gtlz88pIRcTXtKzXA0H3PgovHmIkSq6dLJSpA1aSfQur Wkmsn/I2oG+ZQ== Date: Fri, 5 Mar 2021 16:59:05 +0000 From: Will Deacon To: Quentin Perret Cc: catalin.marinas@arm.com, maz@kernel.org, james.morse@arm.com, julien.thierry.kdev@gmail.com, suzuki.poulose@arm.com, android-kvm@google.com, linux-kernel@vger.kernel.org, kernel-team@android.com, kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org, tabba@google.com, mark.rutland@arm.com, dbrazdil@google.com, mate.toth-pal@arm.com, seanjc@google.com, robh+dt@kernel.org Subject: Re: [PATCH v3 28/32] KVM: arm64: Add kvm_pgtable_stage2_idmap_greedy() Message-ID: <20210305165904.GA23172@willie-the-truck> References: <20210302150002.3685113-1-qperret@google.com> <20210302150002.3685113-29-qperret@google.com> <20210305143941.GA23017@willie-the-truck> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Mar 05, 2021 at 03:03:36PM +0000, Quentin Perret wrote: > On Friday 05 Mar 2021 at 14:39:42 (+0000), Will Deacon wrote: > > On Tue, Mar 02, 2021 at 02:59:58PM +0000, Quentin Perret wrote: > > > + /* Reduce the kvm_mem_range to a granule size */ > > > + ret = __stage2_reduce_range(&data, range->end); > > > + if (ret) > > > + return ret; > > > + > > > + /* Walk the range to check permissions and reduce further if needed */ > > > + do { > > > + ret = kvm_pgtable_walk(pgt, range->start, range->end, &walker); > > > > (we spent some time debugging an issue here and you spotted that you're > > passing range->end instead of the size ;) > > Yep, I have the fix applied locally, and ready to fly in v4 :) > > > > + } while (ret == -EAGAIN); > > > > I'm a bit nervous about this loop -- what guarantees forward progress here? > > Can we return to the host after a few tries instead? > > -EAGAIN only happens when we've been able to successfully reduce the > range to a potentially valid granule size. That can't happen infinitely. > > We're guaranteed to fail when trying to reduce the range to a > granularity smaller than PAGE_SIZE (the -EINVAL case of > __stage2_reduce_range), which is indicative of a host memory abort in a > page it should not access (because marked PROT_NONE for instance). Can you compute an upper bound on the number of iterations based on the number of page-table levels then? I'm just conscious that all of this is effectively running with irqs disabled, and so being able to reason about the amount of work we're going to do makes me much more comfortable. Will