From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-qt1-f171.google.com (mail-qt1-f171.google.com [209.85.160.171]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A824C4C6F08 for ; Thu, 11 Jun 2026 18:25:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=209.85.160.171 ARC-Seal:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781202332; cv=pass; b=fP4UNMzU+O/X6+Nx3F3RmQyOJuBFztyj34fVoo+SZeEFBEU5ldLwAB8oZRik8qNGf/BQWEhvD6+4MZhhVjDmMd1KD377hGLg0C/UvwLL1FwWs6DKtiknZ7g7+WMGK1mF8ffDOaep3Yfi4PP4SBDA84+CtDnwhkn8hWeuwuW0zbM= ARC-Message-Signature:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781202332; c=relaxed/simple; bh=9KXgna/nwfEIF7S1Yx4SAsalr5XgJDJshnViSXgFlJs=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=JmmrvoVMe6LUKJFOssimb2sjIg4Fqh3JIENvmbaWpGs9Jb88lNrL9h7eNQkuH02tM8EY0udzNRT8sZvhySiMAJsA0zLbzYWACp2Puv0qyhteoZFzl3+aVgn1koi2z5DZG4wcUH8F2sbCHj2ifm3PTa5wMzb4pODURMnAnKeOZjk= ARC-Authentication-Results:i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=Qttur0NS; arc=pass smtp.client-ip=209.85.160.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="Qttur0NS" Received: by mail-qt1-f171.google.com with SMTP id d75a77b69052e-5177d1ff061so57811cf.1 for ; Thu, 11 Jun 2026 11:25:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1781202328; cv=none; d=google.com; s=arc-20240605; b=WgH8ifqsjBvGpzBiBP3uur3ApALLk67LKZ5Yk1X/8KoA/9croJO7WnKUK7QvjMxl1g QCl1agdteb7ZWrN7Qr9IPJQwD+20AkR4eNzfV8uRXkjDchi3JdK2OXXPSR7KIWnVCtyL RXRnSE9/O5hhUn97cnCmGw/jryL4r+cuNdC0Z7lslVRObV9sjfxyLuP6t+6O+zilB06b WakAzEPv+XkFiKuBFWqO+g76xaReKjXGpOVikhS5nVyamcfWEXJz2XWnLK1bxDAJ+/5v JAXBC503c3YmwP/MyviUDB7DiVZhjyGoHI/eHGXFr55QKzKuUzx3xAQwZAbYqZMTaxdP 0dxA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=9KXgna/nwfEIF7S1Yx4SAsalr5XgJDJshnViSXgFlJs=; fh=2JKIDqgX6aYGfCkj6ADXK3paxn4v5hqmH3EbHSgTsWM=; b=AO2tdM9f6Aq5/2pg+jDWKeAaSQM0agbaMc0a6XHpl9vjoIEV2wKs7fZcQRaXDMgl0M Bk8RlhYDkwS9Sjx1SQLHk+8XnpaRidb+BARl4yWXsE3xO+G5p8hA+B7znzrfcFx4XOGh xBjpi0RCdm3RQ2oWHb9G9ZmGU7Cccci5rU0mzg/n8EvJ8UP9XgULw6Vs7gYWN73sLKac YPzu+yjzc8l6EldiXJ3rFMyCaT5kw5EwV57ym6qZVJDwcxmXu3I1pj6qG+CTRFG2zdQI sSvLsnQzh0tOP5aLMZXOfF7568XDTqo/FV27YEzgfmJnjmK4kV6jWNQEl69OteqdKleE CecQ==; darn=vger.kernel.org ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1781202328; x=1781807128; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=9KXgna/nwfEIF7S1Yx4SAsalr5XgJDJshnViSXgFlJs=; b=Qttur0NS3fFLjDE54LJqlQKOmHCQLE5fa/7eh8CWm6wDv3iVxNDzli1fOu8O3t1h2+ w7Fq1vRhqJRhDSSR1j+glcW8B4QmefOMySSY54jp6zRPl6hsiYL9bAxB+AbDbkXGvnU8 W9vh/ogmqw3lhRk88Ddj+SUJn1VCbDRErvL4Rej0D0NqPSk+pBMOgQgCvQCvH4Fb+rG0 AUwi0Ar20ywO4PuqjnNwOBX+CK+fspqrWAoO6SdisgrP+AULHSBEeea6Gk8h/qZY+Occ BHubIU0MBv7aJssBB/I0RVhElze2cKk/vyE8xWeUsClabPX1D19PpAtBmc+0ZG+w8UJS tYZg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1781202328; x=1781807128; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=9KXgna/nwfEIF7S1Yx4SAsalr5XgJDJshnViSXgFlJs=; b=XxeJ+wVl+3N+/4vHCCbkiy1FLc0crxI83/MVQaHc9oiX8X5z14qftVB91PsqHyrk2Q vje6XJpQt7Tm9+GmNPqmkiv+6N8frIk81buGHHPMXQJ+zXDHUraE+IfsTHGNrINSSBku GqpNjQiJn7/ICmeSUCJccoJCjWnryGuw/uoWzG8TYn9hEZ+UvYqoz1hyqEf7Z+5/3I3g /+0etgrtErwc75sIInJC8LbIf6KrlOHLsN+efDeakhSCxWb3lSX8SrtrWhHgrib9MCaE E59Qqnx1Sqg636q1mntfV617mM0NiefM4LuponAJmVd3z4QVjuCKpisuiqGcsN50knol bupQ== X-Forwarded-Encrypted: i=1; AFNElJ+4Yd3Tx7H8iHAGkHpGpWzYy8bF52ClBWFJ/Cyq1v9Qkaxr/3zQc1X4yY27u4c/R63rdxNf9OarYmKqB3g=@vger.kernel.org X-Gm-Message-State: AOJu0YxCuGDagVB62R6OKQyoXO/3LDKcn/9MrarCmhWMD8QTH45PFLII 53OjbBK+Z74LvyK/PHZbQXHrYQruaxCFfGA7hj0KWUsUOVznC/avFgxnmkRo9oSTKkI+kF2ZWIH +1xRacVgeeFmsr4mpjKhROS7mHOqRsj5uLnhrsXWE X-Gm-Gg: Acq92OEqKyekcR9AR/bLHm8HaigRQrLuU72qDJxQU/AzYpBKZVnj7RpgdNa30VCM5b6 6ygXAgEMV00wyH9cy5aeJCUClzju66QRR6k5IiLe2GiPl62dClEcBaRuEJImHP5eYY9Gy/W9Fqh +sAaPshTZC44GOzqcBHfc5V1Ydx7AUmDleRnbkXzRP1DLAro5Xte//47si6/U3idv+p19XxdVGZ Bqhp/DURLOUZeOqFdo+nBbvmdEYVCvQUq3OJmPs/0X5TTTsd6xmJZ1+XZDFOaiP+tjsraeTz5bl 6bRFbHZbiXNTp6NkTtbHEW/OggcbDYy9enyb+njb X-Received: by 2002:ac8:5d16:0:b0:517:6dc0:698d with SMTP id d75a77b69052e-517facbda8fmr1217551cf.0.1781202327712; Thu, 11 Jun 2026 11:25:27 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20260526023515.288829-1-rick.p.edgecombe@intel.com> <20260526023515.288829-2-rick.p.edgecombe@intel.com> In-Reply-To: <20260526023515.288829-2-rick.p.edgecombe@intel.com> From: Vishal Annapurve Date: Thu, 11 Jun 2026 11:25:16 -0700 X-Gm-Features: AVVi8Cc_4ND7d7yx-9ajFnqcQ8evQgoIAwHtu_wkSwUVPyjfFy-YFFdjIGUufDs Message-ID: Subject: Re: [PATCH v6 01/11] x86/virt/tdx: Simplify tdmr_get_pamt_sz() To: Rick Edgecombe Cc: bp@alien8.de, dave.hansen@intel.com, hpa@zytor.com, kas@kernel.org, kvm@vger.kernel.org, linux-coco@lists.linux.dev, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, mingo@redhat.com, nik.borisov@suse.com, pbonzini@redhat.com, seanjc@google.com, tglx@kernel.org, x86@kernel.org, chao.gao@intel.com, yan.y.zhao@intel.com, kai.huang@intel.com, Binbin Wu Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Mon, May 25, 2026 at 7:35=E2=80=AFPM Rick Edgecombe wrote: > > For each memory region that the TDX module might use (called TDMR), three > separate traditional PAMT allocations are needed. One for each supported > page size (1GB, 2MB, 4KB). These store information on each page in the > TDMR. In Linux, they are allocated out of one physically contiguous block= , > in order to more efficiently use some internal TDX module book keeping > resources. So some simple math is needed to break the single large > allocation into three smaller allocations for each page size. > > There are some commonalities in the math needed to calculate the base and > size for each smaller allocation, and so an effort was made to share logi= c > across the three. Unfortunately doing this turned out unnaturally torture= d, > with a loop iterating over the three page sizes, only to call into a > function with cases statement for each page size. In the future Dynamic > PAMT will add more logic that is special to the 4KB page size, making the > benefit of the math sharing even more questionable. > > Three is not a very high number, so get rid of the loop and just duplicat= e > the small calculation three times. In doing so, setup for future Dynamic > PAMT changes. > > Since the loop that iterates over it is gone, further simplify the code b= y > dropping the array of intermediate size and base storage. Just store the > values to their final locations. Accept the small complication of having > to clear tdmr->pamt_4k_base in the error path, so that tdmr_do_pamt_func(= ) > will not try to operate on the TDMR struct when attempting to free it. > > Assisted-by: GitHub Copilot:claude-opus-4-6 Claude:claude-opus-4-7 > Reviewed-by: Binbin Wu > Signed-off-by: Rick Edgecombe Reviewed-by: Vishal Annapurve