From patchwork Wed Aug 7 18:17:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gregor Haas X-Patchwork-Id: 1970196 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=IIwue9q5; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=EFF4kpM8; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=patchwork.ozlabs.org) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4WfJLk1q7Sz1yfM for ; Thu, 8 Aug 2024 04:17:48 +1000 (AEST) 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:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=40eyrGamC2sIXdZjkFp56zyRYaPmLSYkOBMGgCYQuQ0=; b=IIwue9q5O3jXW1 //2nGh4p3xcgGiNc13XfZxbO4RC884kPFbdFrTYhIhsozbTmImhUzIcmPgvpdSAajvRtfo2ga+Z0S pEyKYw5F8Q1t4Pay17NYAunB5Mq+DTCiMCWdnUxC6aT3B4Twa3PH9QyHP7gGV7ZsukstHUXeHk/e0 Ig08YgErqeKo3Az5/TZxD+tH+yj7c5LKfdiNE2ry9xwY3HrVeA3CzArV3ZX4gKADKghpJD8knhT5j W8wM2qubXL304Q25DmRLrR7M+Tywpry5wv4p/FzJRhM3eYwzGWFVt2P2wAAyZlzCUIbdatTadVsEA SYJ3iZgKOxJY17gEAldQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sblE9-00000005vAI-3xLI; Wed, 07 Aug 2024 18:17:37 +0000 Received: from mail-pl1-f169.google.com ([209.85.214.169]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sblE6-00000005v8A-3zD3 for opensbi@lists.infradead.org; Wed, 07 Aug 2024 18:17:36 +0000 Received: by mail-pl1-f169.google.com with SMTP id d9443c01a7336-1fd65aaac27so8740475ad.1 for ; Wed, 07 Aug 2024 11:17:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1723054653; x=1723659453; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Kx75MaGI9b1p5pI2PT1PJd4fVmY8aoAVtchJIGKGpsk=; b=EFF4kpM84yHr42W4/ZM7MnvzgyT/Wm6vw8U8R4AQFOfa4njZw2ywRrdFunjHKRdIbZ UQXgfFqPvugGirTWetAzduAEnibjJLH/bT2KnR2463kz8/H3bJ6agEPsUOhrxvOi9hHd WDDm8ZfsUYAuZA7gGgbiCR+rFLTAQAeIVKrBraDFoM+XdWmEpyTUjc3HdkNfOZUhfD6f agV5WGndRsPWwwxM6vC/fXMhuQYV+ZOT20SgCUhzSPVqPGV4gM072F7k6QeJ3ekh4axG qN8bv4yGFeiWL+sCXALfK1hAD6qjQBdRM8aUoAcKCKriR0hkyOXPsYIIDhDv/T216Are 54iQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723054653; x=1723659453; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Kx75MaGI9b1p5pI2PT1PJd4fVmY8aoAVtchJIGKGpsk=; b=hbTcD7PBg9J/zNPuDCsVqzhPneMUyci/EczVNImpe1LGt2c2gv/IEJtAkQCJAmzNfj ze7VJ5xJB4tBZvRM21NdYCibLVk/GS1CVCFb2qsmZ0m5+2plCyfFk8jQRhgDIleMBXvN yXo4EAuCeCQZDnwssXGvTPJanz6j8c9it1uG23DjH74wOCgzAO9xUF1RL5XFVt6F7f70 VAl8A+XMA5MajDf7wN6MnB59wg7I6Fjh0TIaU59I37LO/Gk8Cx7LHRG7Bbpk+8WaligS fZao6EcncB2U596RjOi5D2C1pvES1ZViBRGbCUgAG9oZrHKFwWeonxygPxHGp5nPpX99 2PIw== X-Gm-Message-State: AOJu0YzGTaKcq26TwVNbwnkbDdsrK+zS/FWErvsWTtBtRXctmS7DEnol s7C5VDnEErymKjOy013eflK5NH4cs8Dx28GBAdD0vvWypCumscQOpdVMaFYw X-Google-Smtp-Source: AGHT+IGXwBZuE1r4m0wNf27iWFY6qUuFwrvRDJhH1cmdDCmm0nLK3zMIHmaRMOc9ImxBtY6k4Yqmgw== X-Received: by 2002:a17:903:181:b0:1fc:41c0:7a82 with SMTP id d9443c01a7336-20085201fe4mr49193675ad.0.1723054653442; Wed, 07 Aug 2024 11:17:33 -0700 (PDT) Received: from localhost ([136.27.11.53]) by smtp.gmail.com with UTF8SMTPSA id d9443c01a7336-1ff5905ca1bsm108712175ad.138.2024.08.07.11.17.32 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 07 Aug 2024 11:17:33 -0700 (PDT) From: Gregor Haas To: opensbi@lists.infradead.org Cc: atishp@rivosinc.com, anup@brainfault.org, Gregor Haas Subject: [PATCH v3 2/3] lib: sbi: Allocate from beginning of heap blocks Date: Wed, 7 Aug 2024 11:17:18 -0700 Message-ID: <20240807181719.244099-3-gregorhaas1997@gmail.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240807181719.244099-1-gregorhaas1997@gmail.com> References: <20240807181719.244099-1-gregorhaas1997@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240807_111735_013877_ABC2CCEA X-CRM114-Status: GOOD ( 11.13 ) X-Spam-Score: -1.8 (-) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: In the next commit, we'll add a new sbi_memalign() function. In order to allocate aligned memory, we'll sometimes need to allocate from the middle of a heap block, effectively splitting it in two. All [...] Content analysis details: (-1.8 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [209.85.214.169 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] 0.2 FREEMAIL_ENVFROM_END_DIGIT Envelope-from freemail username ends in digit [gregorhaas1997(at)gmail.com] 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [gregorhaas1997(at)gmail.com] 0.0 RCVD_IN_VALIDITY_CERTIFIED_BLOCKED RBL: ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. [209.85.214.169 listed in sa-trusted.bondedsender.org] 0.0 RCVD_IN_VALIDITY_SAFE_BLOCKED RBL: ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. [209.85.214.169 listed in sa-accredit.habeas.com] 0.0 RCVD_IN_MSPIKE_H3 RBL: Good reputation (+3) [209.85.214.169 listed in wl.mailspike.net] 0.0 RCVD_IN_VALIDITY_RPBL_BLOCKED RBL: ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. [209.85.214.169 listed in bl.score.senderscore.com] 0.0 RCVD_IN_MSPIKE_WL Mailspike good senders X-BeenThere: opensbi@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "opensbi" Errors-To: opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org In the next commit, we'll add a new sbi_memalign() function. In order to allocate aligned memory, we'll sometimes need to allocate from the middle of a heap block, effectively splitting it in two. Allocating from the beginning of a heap block in the nonaligned case more closely matches this behavior, reducing the complexity of understanding the heap implementation. Signed-off-by: Gregor Haas Reviewed-by: Anup Patel --- lib/sbi/sbi_heap.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/sbi/sbi_heap.c b/lib/sbi/sbi_heap.c index e43d77c..cc4893d 100644 --- a/lib/sbi/sbi_heap.c +++ b/lib/sbi/sbi_heap.c @@ -63,8 +63,9 @@ void *sbi_malloc_from(struct sbi_heap_control *hpctrl, size_t size) n = sbi_list_first_entry(&hpctrl->free_node_list, struct heap_node, head); sbi_list_del(&n->head); - n->addr = np->addr + np->size - size; + n->addr = np->addr; n->size = size; + np->addr += size; np->size -= size; sbi_list_add_tail(&n->head, &hpctrl->used_space_list); ret = (void *)n->addr;