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 X-Spam-Level: X-Spam-Status: No, score=-3.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CA1B6C433DB for ; Thu, 4 Mar 2021 15:51:08 +0000 (UTC) Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 623AC64F02 for ; Thu, 4 Mar 2021 15:51:08 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 623AC64F02 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=desiato.20200630; 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=2bXzahX9+XUwhoB8kMgOhcFzPGUGHriSZCoRb2kSq2U=; b=JwH0wynr+F/4panaplA9U/pzR DKK4byTDYVMnRGTpd6BqoAh9BmG3DqBVK1P32z+xqwuAJT0qq2ssypedTmQqvlaE25aZxetGeWFWk 9nv3f/nmGiFYE7Khapk2rzHrfVa1I2o7+MwGOFG+5O4eL9mFQTPj3MtCoXShDz6zVgpf9ZgbD5o8N 0ve63XBGW7OTtH4DXTKGdnyp/uWLcSTpNZEmylDiKqvXdxa/9gbdmOCQ3TZQi+xpGFyG3YNVdhEPk rfM6EN0R9NoKp9iezD51kHPEqpb5Jdjasr3CMlhHblyxd5X4uGgNJ5zK1N6L+LDuy+31Dyaa58U0S 4dad+hXbQ==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lHqE4-0097y2-Og; Thu, 04 Mar 2021 15:49:21 +0000 Received: from mail-wr1-x42f.google.com ([2a00:1450:4864:20::42f]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lHqDt-0097wg-Ls for linux-arm-kernel@lists.infradead.org; Thu, 04 Mar 2021 15:49:13 +0000 Received: by mail-wr1-x42f.google.com with SMTP id e10so27936236wro.12 for ; Thu, 04 Mar 2021 07:49:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=LhGupbzdEthuR24ULnc5046PaiLJrBs+er9+oVApeFU=; b=EWHLHh+IyVUqUgAF4LFZSuMlY9wO0QpbQ806Aov0N14LnzY3kFNc0MBKZlNk0fMhBa 7g4Vv/tUs3yoiKwACuE890DOhAPuphZYbSCPPuUaBxUgawsBJAdJTCBLXVzt5wVIYVUt zc8bT49uF5u2iGpc6PKcZNdkMzvNW6RSaF2yAKzUaTiHmSf1WpEgc5Yhp8f7q+4albDc nF4lron7w2kjGuZ+LtZ6whwHeQQrh6JNZcPXFeccx3iXxxUL7VHPFH6MEx27zPsugvH7 ZyGHw9Tchk2qVIeN2zMA+sCqvgrf1e2fXQObBmKBSPKY2GJeESgGs+oXFyLQCjmcCF1l u3jw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=LhGupbzdEthuR24ULnc5046PaiLJrBs+er9+oVApeFU=; b=UheqxC1/SmZxIRTXGeB2C7mmd6jCvAy1TcHn9ZqWIaFLVj89m3BO/RoN8lfeRiyz8w 3NqXILhDHXpc3eIuNhIjc4c19I3SKJEICSju/17O8n8ilpjWghXOw1jCz+YqFUxU1B58 cMmeDDLSDFto0LRO4/gBZvyNTPbLoiriDzQA6dfkatvXmI11kRYZsKPLfSsHfvKygkPD pSicU0yPjjdUBM95mrtpxlekvxGmvMH6p2AVj6DQc8iUjovQ1BUl3avX3Z9ivHQz2pYQ d7OPQD1DGbpr7EyJjxsZc+bv56vlAJT/cUUzO+cUXCtmwc+u2KCbBTIM3Di99wusS7Eg 1v3A== X-Gm-Message-State: AOAM533Phzz11XFJ22A8sfliRI9Ln9s5NQGvGIlSDNShuFblWHPnBlAR eBswZJZZPu4K2ezq3CM+KDCSng== X-Google-Smtp-Source: ABdhPJwAMOHT+NpKRPC4qB1GLJVh8vLpTUsT2vC7aS+EbNwN1mBpqTrXaelCzUyIK9ZPcLvl/WPgqA== X-Received: by 2002:adf:9bcf:: with SMTP id e15mr4631058wrc.276.1614872947974; Thu, 04 Mar 2021 07:49:07 -0800 (PST) Received: from google.com (230.69.233.35.bc.googleusercontent.com. [35.233.69.230]) by smtp.gmail.com with ESMTPSA id m10sm10074082wmh.13.2021.03.04.07.49.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Mar 2021 07:49:07 -0800 (PST) Date: Thu, 4 Mar 2021 15:49:05 +0000 From: Quentin Perret To: Will Deacon 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 12/32] KVM: arm64: Introduce a Hyp buddy page allocator Message-ID: References: <20210302150002.3685113-1-qperret@google.com> <20210302150002.3685113-13-qperret@google.com> <20210304153036.GA21507@willie-the-truck> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20210304153036.GA21507@willie-the-truck> 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 Thursday 04 Mar 2021 at 15:30:36 (+0000), Will Deacon wrote: > On Tue, Mar 02, 2021 at 02:59:42PM +0000, Quentin Perret wrote: > > +void *hyp_alloc_pages(struct hyp_pool *pool, unsigned int order) > > +{ > > + unsigned int i = order; > > + struct hyp_page *p; > > + > > + hyp_spin_lock(&pool->lock); > > + > > + /* Look for a high-enough-order page */ > > + while (i < pool->max_order && list_empty(&pool->free_area[i])) > > + i++; > > + if (i >= pool->max_order) { > > + hyp_spin_unlock(&pool->lock); > > + return NULL; > > + } > > + > > + /* Extract it from the tree at the right order */ > > + p = list_first_entry(&pool->free_area[i], struct hyp_page, node); > > + p = __hyp_extract_page(pool, p, order); > > + > > + hyp_spin_unlock(&pool->lock); > > + hyp_page_ref_inc(p); > > I find this a little scary, as we momentarily drop the lock. It think > it's ok because the reference count on the page must be 0 at this point, Yep, @p shouldn't be visible to the caller yet so this should be fine. > but actually then I think it would be clearer to have a > hyp_page_ref_init() function which could take the lock, check that the > refcount is indeed 0 and then set it to 1. Works for me. Maybe I'll use another name for the API to stay consistent with the kernel gfp code (hyp_page_ref_inc() and friends are inspired from their kernel counterpart). And I guess I can hyp_panic() if the refcount is not 0 at this point to match the VM_BUG_ON_PAGE() in set_page_refcounted(). Thanks! Quentin _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel