Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1mpgbj-00066n-IO for mharc-grub-devel@gnu.org; Tue, 23 Nov 2021 19:57:55 -0500 Received: from eggs.gnu.org ([209.51.188.92]:54632) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mpgbh-00062d-PL for grub-devel@gnu.org; Tue, 23 Nov 2021 19:57:53 -0500 Received: from [2607:f8b0:4864:20::435] (port=41925 helo=mail-pf1-x435.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mpgbf-0004VR-A3 for grub-devel@gnu.org; Tue, 23 Nov 2021 19:57:53 -0500 Received: by mail-pf1-x435.google.com with SMTP id g19so933851pfb.8 for ; Tue, 23 Nov 2021 16:57:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=axtens.net; s=google; h=from:to:cc:subject:in-reply-to:references:date:message-id :mime-version; bh=uHgW0W2+o6DXjuZGJNxoUKJpwKEBome35BREtW1tQOk=; b=PjlH9b9aVqnrW1uwdrsuFI0RQhflVcrqCl8q9D717ELJAscVu98+yb7uO+/SRykx18 OwjACw5mZ7VuPdux8H20z5VsZbd08HvJOUaIn2EIuhRBoJ7mEOY7E4tCmWjx5dyl8sTC kEGwcK8eSsFgzt0cStgvnLlwrHXmZ2EGM8bME= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:in-reply-to:references:date :message-id:mime-version; bh=uHgW0W2+o6DXjuZGJNxoUKJpwKEBome35BREtW1tQOk=; b=fsCfNicFX6SPRTc6/ulWBH+srYW9OOF+0Cfqa4NPR0qco/JyH1RZpK+zjlrJ2fqErL eRrNti6BbHHEkj7uFSaFK79IajrC/gClbZX06iAVIlOtMQYZq3TKYxhZsQB1KV8H6VES 13ZzM0PNTPC7cntxh1EyNslVQaNo6E4qNvVJIQVT7LMcxxjUlGUKNMkdH7O9nGBL6ddB dXH4+Qfm+ZHvv9cH2J36bFCdIv/PMl5F1Ft+Br6vT0fvZQLDJSZ2PElN56k/YALE11aA Fq4u3B/Nzb+XC/aMO3jE9pN617s+4TRag2OKgdpO2hLz3BtZC9cMLH5fVAQQpcUe4QdY aVOg== X-Gm-Message-State: AOAM531PH+Lukjlk/elAUXVl1MSm9lK189Tu/o82M4a60iEquUUhYwf5 yr07ZENmZJ4r+W9A11qrTDvdKw== X-Google-Smtp-Source: ABdhPJzqkerAdESROjV4IyWkyb2m+KKhSqldIO4XiR9pIMXjTQyWSb0EFJMbSR042647RiFFAXtsGQ== X-Received: by 2002:a62:1cc4:0:b0:49f:99b6:3507 with SMTP id c187-20020a621cc4000000b0049f99b63507mr1655422pfc.76.1637715469718; Tue, 23 Nov 2021 16:57:49 -0800 (PST) Received: from localhost ([2001:4479:e000:e400:4a7:5a98:de98:1432]) by smtp.gmail.com with ESMTPSA id k14sm9981503pga.65.2021.11.23.16.57.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Nov 2021 16:57:49 -0800 (PST) From: Daniel Axtens To: development@efficientek.com Cc: The development of GNU GRUB , leif@nuviainc.com, stefanb@linux.ibm.com, ps@pks.im, dkiper@net-space.pl Subject: Re: [PATCH 03/19] mm: document grub internal memory management structures In-Reply-To: <20211012141802.62e22520@crass-HP-ZBook-15-G2> References: <20211012073008.4059133-1-dja@axtens.net> <20211012073008.4059133-4-dja@axtens.net> <20211012141802.62e22520@crass-HP-ZBook-15-G2> Date: Wed, 24 Nov 2021 11:57:46 +1100 Message-ID: <87r1b6cqut.fsf@dja-thinkpad.axtens.net> MIME-Version: 1.0 Content-Type: text/plain X-Host-Lookup-Failed: Reverse DNS lookup failed for 2607:f8b0:4864:20::435 (failed) Received-SPF: pass client-ip=2607:f8b0:4864:20::435; envelope-from=dja@axtens.net; helo=mail-pf1-x435.google.com X-Spam_score_int: -12 X-Spam_score: -1.3 X-Spam_bar: - X-Spam_report: (-1.3 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, PDS_HP_HELO_NORDNS=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 24 Nov 2021 00:57:54 -0000 Glenn Washburn writes: > On Tue, 12 Oct 2021 18:29:52 +1100 > Daniel Axtens wrote: > >> I spent more than a trivial quantity of time figuring out pre_size and >> whether a memory region's size contains the header cell or not. >> >> Document the meanings of all the properties. Hopefully now no-one else >> has to figure it out! >> >> Signed-off-by: Daniel Axtens >> --- >> include/grub/mm_private.h | 21 +++++++++++++++++++++ >> 1 file changed, 21 insertions(+) >> >> diff --git a/include/grub/mm_private.h b/include/grub/mm_private.h >> index c2c4cb1511c6..e80a059dd4e4 100644 >> --- a/include/grub/mm_private.h >> +++ b/include/grub/mm_private.h >> @@ -25,11 +25,18 @@ >> #define GRUB_MM_FREE_MAGIC 0x2d3c2808 >> #define GRUB_MM_ALLOC_MAGIC 0x6db08fa4 >> >> +/* A header describing a block of memory - either allocated or free */ >> typedef struct grub_mm_header >> { >> + /* The 'next' free block in this region. A circular list. >> + Only meaningful if the block is free. >> + */ >> struct grub_mm_header *next; > > This and the subsequent comments do not follow the multiline comment > style[1]. Will fix, thanks. > One nit, "region. A circular" -> "region's circular". Sure, will do. > This comment leads me to wonder if the block is not free, what is the > value of next? Seems like it should be NULL, if its not meaningful. In practice the value will be: - if the block was converted from an existing free block: whatever the 'next' pointer was when the block was free - if the block was carved out of the middle or end of an existing free block: whatever happened to be at that offset in memory. We certainly _could_ null it out. I don't think there's any real value in doing so but I'm open to being convinced. I suppose you could make an argument that it reduces the chance that we'll follow a pointer to somewhere random in memory but we check the magic before we check next so we're fairly safe. > https://www.gnu.org/software/grub/manual/grub-dev/grub-dev.html#Multi_002dLine-Comments > >> + /* The region size in cells (not bytes). Includes the header cell. */ > > What exactly does "cell" mean in this context? I'm gathering cell is > not defined as in this link[2], which is equivalent to "bit". Perhaps > "size" should be renamed to "ncells" or something more descriptive. > > [2] https://en.wikipedia.org/wiki/Memory_cell_(computing) The definition of cell is from mm.c: The memory space is used as cells instead of bytes for simplicity. This is important for some CPUs which may not access multiple bytes at a time when the first byte is not aligned at a certain boundary (typically, 4-byte or 8-byte). The size of each cell is equal to the size of struct grub_mm_header, so the header of each allocated/free block fits into one cell precisely. One cell is 16 bytes on 32-bit platforms and 32 bytes on 64-bit platforms. I don't want to change variable names in this patch but I will update the comment. Kind regards, Daniel