From patchwork Thu May 27 12:51:34 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Quentin Perret X-Patchwork-Id: 12284089 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=-17.1 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 6D911C4707F for ; Thu, 27 May 2021 12:57:40 +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 33AF560FE6 for ; Thu, 27 May 2021 12:57:40 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 33AF560FE6 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=V9l+cqS83BH0S1zJYUgwCRjELHmn2uVnorcxxUlREVM=; b=bSWWVVuIYS+RWl4OdyZt536u7v KBvTK/r38XPqwJKGhO2Ro38eYnCrPGFnGusviDdjInN/zaMJr1meAx1oKsLScbvJTXD0C+rSQGn2y 2dWItX3jUr4SYUf6v9Ych2cKdBfQJkp5vxE57VlcUs43jkTCQCemTdQ0V/IsDrDu0lcaS0TV8qNxI /qud+P5k99nB18IrIYU6pEbROh0EOFNOy7Ypo8xXUH33UAjDngY7/yIjE4uUOFqbR+E/2yHZ+axJL 1b+IUdozmGgoqXK6kKjARPorR7e5kTQ0n0FyShydufACN3gEstzhaaodzwRQAzNI+U1OLO3RDaMTt g+AOiZcw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1lmFXS-005vF3-Nx; Thu, 27 May 2021 12:55:02 +0000 Received: from mail-wm1-x349.google.com ([2a00:1450:4864:20::349]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1lmFUQ-005tWD-Vx for linux-arm-kernel@lists.infradead.org; Thu, 27 May 2021 12:51:56 +0000 Received: by mail-wm1-x349.google.com with SMTP id u203-20020a1cddd40000b029016dbb86d796so1462566wmg.0 for ; Thu, 27 May 2021 05:51:53 -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=Byq3teaLV2n+YzpfRy9Lkrwtyz9tACaM8wDIjUMnhpc=; b=lh3itUSKrY99HR4eVX5Kbop9zhHjelSV5Tk0fWZiJ9sUfR4ERy+T5lGBjCz/duYdnl kGkbRalNQtA2P8Y0x9AuQts+PtFMMV4Twn9z5LBtYsCtzuOsQwApQ9msA6YyUSd0L9kr 9uo4im5pV2Vfxkb39c1oXswe8RHMs28B40q7MqOi3d5tWR8vdUH1kSgUwquRqY9ZHNYh DPiymqTjegRTcs/yRjGTDtnhWm70YHVyMrJdLewGX2zGwBjl7lV8+fHtPLOB5VBtFc23 shccUlzY2zH/UCB6UeC1Jr/WQJf3uNRFlQ+E8cRqzchohQRyWGeILnf9albgfmXsYbY4 29Nw== 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=Byq3teaLV2n+YzpfRy9Lkrwtyz9tACaM8wDIjUMnhpc=; b=lghigj/m2La3L7SruzEElMBR7tZ6n0zyT83pIvB+rZ2KTcR4DNgsGxDRlZxoccwXs3 dy4WYVscY/3N/kF5X60pUHJIT/lGxUb/cbGBsloI3B8dXfIKs/FtqL6abzkZLayShx0F EaG2iLGW9Bu71Gavwt3lcl27md+FOiSOivBWnvUSg9gQyDfI6P6YRiDowPPTLurIu63i ZrQx5/XqbCQv+kOIco/pcqY8mLR5r9/GbrFHxBPpEF4CUzNPbiMDwQ5bd06BOWB61fN2 2SsbBo/5cEh4RAYncE1eh3dUSWP29wVBf7RFsax1x7F8UjLzlZktwIj+4JjGj5wEa576 p3dA== X-Gm-Message-State: AOAM531F8DTug1wGDrL4tE+UgDR4nHAGW9OoElzzTtsKOQXe8spp405n uA3eoG0Tb2jtXcWd02kp6IY6xlpK1OM7 X-Google-Smtp-Source: ABdhPJx/lfTo0VRFwUG+jBpYqhQ9SqHdKxuCeQn/auIpBlo6JTHBRUm8dOoTIg4a0j6u0pDOtb1DO+Pb2vgH X-Received: from r2d2-qp.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:1652]) (user=qperret job=sendgmr) by 2002:a05:600c:3515:: with SMTP id h21mr8321374wmq.148.1622119912227; Thu, 27 May 2021 05:51:52 -0700 (PDT) Date: Thu, 27 May 2021 12:51:34 +0000 In-Reply-To: <20210527125134.2116404-1-qperret@google.com> Message-Id: <20210527125134.2116404-8-qperret@google.com> Mime-Version: 1.0 References: <20210527125134.2116404-1-qperret@google.com> X-Mailer: git-send-email 2.31.1.818.g46aad6cb9e-goog Subject: [PATCH 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-20210527_055155_061135_5D2C5ED4 X-CRM114-Status: GOOD ( 13.02 ) 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/gfp.h | 2 ++ arch/arm64/kvm/hyp/include/nvhe/memory.h | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/arch/arm64/kvm/hyp/include/nvhe/gfp.h b/arch/arm64/kvm/hyp/include/nvhe/gfp.h index d420e5c0845f..a82f73faf41e 100644 --- a/arch/arm64/kvm/hyp/include/nvhe/gfp.h +++ b/arch/arm64/kvm/hyp/include/nvhe/gfp.h @@ -24,6 +24,8 @@ struct hyp_pool { static inline void hyp_page_ref_inc(struct hyp_page *p) { + if (p->refcount == USHRT_MAX) + BUG(); p->refcount++; } 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; };