From patchwork Tue Jun 8 11:45:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Quentin Perret X-Patchwork-Id: 12306685 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=-16.9 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham 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 9F9B5C47082 for ; Tue, 8 Jun 2021 12:19:45 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (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 64A606124C for ; Tue, 8 Jun 2021 12:19:45 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 64A606124C 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=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:References: Mime-Version:Message-Id:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=re+dR2bcEXACL6if4lagLEoe+P9tMjykmxzpZ9w8GFA=; b=jXMzheAWJpNq6zylAsMK3y65Vl TgMpy8xsmGTcMWJfNK7U2/Fefc2g14rOR9DwfZctyWbjKj91NvIDHFHL+0eBWA7ayiRIbY8HSFG16 mpM0qm2AfOPBNfdnNxbMdt1MScq6ZfZIBmuLaQLCg2gl8E/XlQgl4ykIyAcnxJEDPhxfM0QClNYuZ kw9FzTo42ZLJJpDqc8ZrsMo0M81vOvG4qp8kF3/HCQMrs63qR5X1oc9JBIhV2UIFyycQzVHanZ+XG yChfMN8q+gI3ZbjkKoammlm9oAjkXgkh2P2h16yqHjCNXD4WDrlowmgo8aCmuyWlXoVVT3k8xfxY0 G6OV2XVw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1lqafl-008HhA-V5; Tue, 08 Jun 2021 12:17:35 +0000 Received: from mail-qk1-f202.google.com ([209.85.222.202]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1lqaBu-0086g8-8b for linux-arm-kernel@lists.infradead.org; Tue, 08 Jun 2021 11:46:44 +0000 Received: by mail-qk1-f202.google.com with SMTP id 190-20020a3708c70000b02903aa60e6d8c1so8020302qki.19 for ; Tue, 08 Jun 2021 04:46:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=Ht6ZsPME0dKrsaoX0sOEJfkD40JHGHh+tjBgtM1a8+s=; b=Qo1Sme4AtGquqBbZ3++fnxMhekv/Q/MZQsj0pdKrYdhOBKiGTd8NVlwwFib6WIoU58 F/EuzAQZ227O9LOmq4TCiKU/lJ8OrmXe6Y0du8LPrkFaVPb0SGCrPQJv74dFr1t0hqw8 fy3V1IQhwl0eJmdKIpBflmQh37xHque8Fsm6v0wEp/y/OgDqet2jyq2u4FWH0X8QyMPE 8EBHAgM2ApfYABHvqv9V/vrHhpzSbPnhcEwwZjjctlPFZTxsppMlccDEn5h8VEiJGS/5 JaBuvCt6pEeETZ4wx1vNc3NkTiRSK/5Rul/LHPAj4crdEwXvDQar9+UrZw0QonuKMKSv EAsw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=Ht6ZsPME0dKrsaoX0sOEJfkD40JHGHh+tjBgtM1a8+s=; b=hnMJVfmfa4HP1Y7sWp7PLLZYUCBkrGPOR+VcWkjuHYOP83MdSNstC97wv97bVrgdsk SPHxlGCki4CTLvyX7C/I5+FhF0kElNzUSOlJ63hFHrDoOTK+wi2AevDt1T/9gh4X9tp0 /q/cXnBoacQ0jfiX9FFcmQtuzU+qYZ+rjy8cut2rDb59J4LpnfQ/EVacX73OgVu7BsK7 CfT9avpicISDKgk/Fc/kZefWrPEFGZJCrSy4kbXZuAjXP2Kd2OJ+C0aRF6CPrRTntGOb JQtP/XCSclPd/sJbI71x95YNP0xD7kbeHoVbyPNqrB6ZNhcpkQR0y1vtMEt0sQM1T3xG N2SA== X-Gm-Message-State: AOAM533MZ0pgGaOL7IbG4eG2zp+isINsUJsI9chcnIg8HjhAUP0k/QXu McRt4Z+K3PU0KkpZNMaNo/CrKB9T2ykH X-Google-Smtp-Source: ABdhPJwKoD8tOLvO/LYUpyfEnSdl9NSUO/u5qM43SN4f3kxfrNxeCZtg5Givdh9sHlYANNlP3HYBgBNwoPfX X-Received: from r2d2-qp.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:1652]) (user=qperret job=sendgmr) by 2002:ad4:4241:: with SMTP id l1mr22892455qvq.2.1623152739555; Tue, 08 Jun 2021 04:45:39 -0700 (PDT) Date: Tue, 8 Jun 2021 11:45:18 +0000 In-Reply-To: <20210608114518.748712-1-qperret@google.com> Message-Id: <20210608114518.748712-8-qperret@google.com> Mime-Version: 1.0 References: <20210608114518.748712-1-qperret@google.com> X-Mailer: git-send-email 2.32.0.rc1.229.g3e70b5a671-goog Subject: [PATCH v3 7/7] KVM: arm64: Use less bits for hyp_page refcount From: Quentin Perret To: maz@kernel.org, will@kernel.org, james.morse@arm.com, alexandru.elisei@arm.com, catalin.marinas@arm.com, suzuki.poulose@arm.com Cc: linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, kernel-team@android.com, linux-kernel@vger.kernel.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210608_044642_345508_D2DF0E27 X-CRM114-Status: GOOD ( 13.71 ) 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: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org The hyp_page refcount is currently encoded on 4 bytes even though we never need to count that many objects in a page. Make it 2 bytes to save some space in the vmemmap. As overflows are more likely to happen as well, make sure to catch those with a BUG in the increment function. Signed-off-by: Quentin Perret --- arch/arm64/kvm/hyp/include/nvhe/memory.h | 2 +- arch/arm64/kvm/hyp/nvhe/page_alloc.c | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/arch/arm64/kvm/hyp/include/nvhe/memory.h b/arch/arm64/kvm/hyp/include/nvhe/memory.h index 3fe34fa30ea4..592b7edb3edb 100644 --- a/arch/arm64/kvm/hyp/include/nvhe/memory.h +++ b/arch/arm64/kvm/hyp/include/nvhe/memory.h @@ -8,7 +8,7 @@ #include struct hyp_page { - unsigned int refcount; + unsigned short refcount; unsigned short order; }; diff --git a/arch/arm64/kvm/hyp/nvhe/page_alloc.c b/arch/arm64/kvm/hyp/nvhe/page_alloc.c index be07055bbc10..41fc25bdfb34 100644 --- a/arch/arm64/kvm/hyp/nvhe/page_alloc.c +++ b/arch/arm64/kvm/hyp/nvhe/page_alloc.c @@ -146,6 +146,7 @@ static struct hyp_page *__hyp_extract_page(struct hyp_pool *pool, static inline void hyp_page_ref_inc(struct hyp_page *p) { + BUG_ON(p->refcount == USHRT_MAX); p->refcount++; }