Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1572197pxb; Thu, 4 Feb 2021 17:14:11 -0800 (PST) X-Google-Smtp-Source: ABdhPJyHvWQVBwCCtDxO8vDPmjDiFDc/Jnn3RzajtawLj5d6S11flRyPGAXXSZGAaig+CR71DFv3 X-Received: by 2002:a17:906:7f06:: with SMTP id d6mr1645126ejr.169.1612487651284; Thu, 04 Feb 2021 17:14:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612487651; cv=none; d=google.com; s=arc-20160816; b=qJRChm485tWh1K0oA44im2mpqYZhwfoNTnT4EMF7Ul7eP4DSmrmVswq/B5tmCUeToK 4R5hdHI+IJkzBY8m+6xzBoOyz47k1XuMpqb/xrEBQUArzLDu4pKa4UeIUq42aoH8B7C7 J412IRd54LDMiEKsoFzi7GEooSOHqwSRPnc5FoU7CW9Q3HeX20D94RyBsuhHtALRbenD jMAFaMXGWNOqV0Vf/fdTUlCynyj+fsLap4gQ1vzR8PyuE77+fV+oiIjKKaCukv5fTb2W LKIpxxmOVlNPOpKUL+BKRgt8yQIluKWTxdYwc+u2fWeHONda5ysoPyL1rEirRXqGbTZ3 6d7Q== 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=NtSTj5Jy9eiurVkeHJhz16D5zSFBcckxfPSAuEaUWTA=; b=QdvHke7zOHdpnvi/yJA73TiF8UoQdQtOM82QwUHnE3CPjTav89j+/TQdLMc3v97i0S MT3YRDNGmuDM/eUj/C2z58Dv1YHsVd1sPz6oKUlPWaKONwvCH367SXskJ/dPQCFy2Gwn KFrjNF4QggFbHE85vfgwC4Gn5OUgW14SvC/rMQrbe1zNnyDeQYFp9yJNrs4sEspXNkqP lHZAHkt1YhSHHuSL3qm+uKMD51jTgnCE+omBAagFFCN6LBzGH94oLaZszkEfhZ/WA8fl 68iq2rHJPSPNAHWXXqLcdCEKcpovY6m+IGUHq9ZWxveXUTsuTJwLvLgOKjaFJpe5X5g0 ZLqw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="Rd/0Jes6"; 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 g1si4811600ejf.121.2021.02.04.17.13.46; Thu, 04 Feb 2021 17:14:11 -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="Rd/0Jes6"; 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 S238850AbhBDSPc (ORCPT + 99 others); Thu, 4 Feb 2021 13:15:32 -0500 Received: from mail.kernel.org ([198.145.29.99]:41774 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239010AbhBDSOF (ORCPT ); Thu, 4 Feb 2021 13:14:05 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 842EB64F44; Thu, 4 Feb 2021 18:13:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1612462404; bh=zbLV6tzEcrYE6Zr1vCAoOlEuk2uUe3OTj1GoEj/vbsQ=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=Rd/0Jes6vV9yhhSHANL1rZUNuB/fQhP/iQfuTS2kgxeRItC0waSOIU/ltYfOmsQM0 ZOh5bzruLkhY7RB7lxLFOiSL9Kjd69Q+qgJS3+fMStjqDUqEZaHW3SgnJ+U6Uxmbtf JuHL4djLRKjhNdUibBNSXtkiMpM2SaAoKfcd6dJCeStsbY+3lqJfvoSwZc+0p+nhdk IrxtdsVlS5TwIZIajddo+hofOfxWHdUjicQRnmuHEJYEm6P8vftmPm9YU+O9eGrpPH sqZYPYp+4xXVacbgRM8c7kQu0NeNmolcwTczxstovtLGDGbp+hlTPjBeVn9wd2gz+N FsPz5jPY6jH+Q== Date: Thu, 4 Feb 2021 18:13:18 +0000 From: Will Deacon To: Quentin Perret Cc: Catalin Marinas , Marc Zyngier , James Morse , Julien Thierry , Suzuki K Poulose , Rob Herring , Frank Rowand , devicetree@vger.kernel.org, android-kvm@google.com, linux-kernel@vger.kernel.org, kernel-team@android.com, kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org, Fuad Tabba , Mark Rutland , David Brazdil Subject: Re: [RFC PATCH v2 12/26] KVM: arm64: Introduce a Hyp buddy page allocator Message-ID: <20210204181317.GE21303@willie-the-truck> References: <20210108121524.656872-1-qperret@google.com> <20210108121524.656872-13-qperret@google.com> <20210202181307.GA17311@willie-the-truck> <20210204143106.GA20792@willie-the-truck> <20210204174849.GA21303@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 Thu, Feb 04, 2021 at 06:01:12PM +0000, Quentin Perret wrote: > On Thursday 04 Feb 2021 at 17:48:49 (+0000), Will Deacon wrote: > > On Thu, Feb 04, 2021 at 02:52:52PM +0000, Quentin Perret wrote: > > > On Thursday 04 Feb 2021 at 14:31:08 (+0000), Will Deacon wrote: > > > > On Wed, Feb 03, 2021 at 06:33:30PM +0000, Quentin Perret wrote: > > > > > On Tuesday 02 Feb 2021 at 18:13:08 (+0000), Will Deacon wrote: > > > > > > On Fri, Jan 08, 2021 at 12:15:10PM +0000, Quentin Perret wrote: > > > > > > > + * __find_buddy(pool, page 0, order 0) => page 1 > > > > > > > + * __find_buddy(pool, page 0, order 1) => page 2 > > > > > > > + * __find_buddy(pool, page 1, order 0) => page 0 > > > > > > > + * __find_buddy(pool, page 2, order 0) => page 3 > > > > > > > + */ > > > > > > > +static struct hyp_page *__find_buddy(struct hyp_pool *pool, struct hyp_page *p, > > > > > > > + unsigned int order) > > > > > > > +{ > > > > > > > + phys_addr_t addr = hyp_page_to_phys(p); > > > > > > > + > > > > > > > + addr ^= (PAGE_SIZE << order); > > > > > > > + if (addr < pool->range_start || addr >= pool->range_end) > > > > > > > + return NULL; > > > > > > > > > > > > Are these range checks only needed because the pool isn't required to be > > > > > > an exact power-of-2 pages in size? If so, maybe it would be more > > > > > > straightforward to limit the max order on a per-pool basis depending upon > > > > > > its size? > > > > > > > > > > More importantly, it is because pages outside of the pool are not > > > > > guaranteed to be covered by the hyp_vmemmap, so I really need to make > > > > > sure I don't dereference them. > > > > > > > > Wouldn't having a per-pool max order help with that? > > > > > > The issue is, I have no alignment guarantees for the pools, so I may end > > > up with max_order = 0 ... > > > > Yeah, so you would still need the range tracking, > > Hmm actually I don't think I would, but that would essentially mean the > 'buddy' allocator is now turned into a free list of single pages > (because we cannot create pages of order 1). Right, I'm not suggesting we do that. > > but it would at least help > > to reduce HYP_MAX_ORDER failed searches each time. Still, we can always do > > that later. > > Sorry but I am not following. In which case do we have HYP_MAX_ORDER > failed searches? I was going from memory, but the loop in __hyp_alloc_pages() searches up to HYP_MAX_ORDER, whereas this is _never_ going to succeed beyond some per-pool order determined by the size of the pool. But I doubt it matters -- I thought we did more than just check a list. Will