Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp6516319rdb; Fri, 15 Dec 2023 00:10:48 -0800 (PST) X-Google-Smtp-Source: AGHT+IE0gT+nsOqW0Z49jenoBXtL36m09MNsZKbtJYgK7ykHNDqwj/0m/gIc/k/pTnfVDb9KNye3 X-Received: by 2002:a2e:a99d:0:b0:2cb:2ead:705 with SMTP id x29-20020a2ea99d000000b002cb2ead0705mr5257127ljq.5.1702627848045; Fri, 15 Dec 2023 00:10:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702627848; cv=none; d=google.com; s=arc-20160816; b=JF37osB7n5QgGwd7w4qeaWbBp5LkEG8xHlS2P6nPBbD84o8uk+WUcEO+GfWiOenviF tMRICxhCeQjl19HRrvebx75G34+ELGZzs15RAVGFH0Ktu6vagxwEloJhF9Z61sgHsgFv RFX1BgxmufEZdz6BCC6qYSI6D4WW9gGZA6UKsIjtVepXXyzfEp4YWItoiMChMCXEna2b hFC1VTia8h3dxpMakWorcM/Zuk7lAoiTrzV4iM05IAnbYVvDpwbyFOhvaNGtakS0mSnL OerkfHDgesDuqaHeQ4TLphW/QEKC6mVbSgeDDKVZT5u1BgMdj+GnQVcwLNjboxV5NKkX WB9w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=sICzlYhaSfeV+0O8ybAajGk8fmRoPkGoJtHOPJtKgUM=; fh=HJZfX/0DhGqiPikMMxrlANwXs9+oMsvND+y1WZrHDWQ=; b=IkUQxI56TSTOcpkG9ePIuXZQtAtDxaU2YRSQ69CVKvD1EBMGzFd/q7cJ5Ly6OqX74Y 6AY0dQtpavWNtR8EoRMh936HKZT0PomjveDO+cIZtQfABtaKLerefF1Yn8xU/pzdxukh XzOG3yi6iblM8YPo5AoKMS1/MwAWqoHPw71PjxdrJMbniGvc9LghT9/3+GaUJWR2WmL5 N5fl0TUIooCidlSMLLed3Wgqvz1470LWIHXKgEvuPBCzeK/cTJXwGUZQbd1vJecErYGY XCPKPdEnQgowOJdeTXQE7r/3Ws0dd/op66OytOZ+KAPM2jlCdl6eak+VVbsJ/EekVWfF JoRA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=cNk9e8PW; spf=pass (google.com: domain of linux-kernel+bounces-593-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-593-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id c10-20020a50f60a000000b005525b851e2esi1675381edn.75.2023.12.15.00.10.45 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Dec 2023 00:10:48 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-593-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=cNk9e8PW; spf=pass (google.com: domain of linux-kernel+bounces-593-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-593-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 63D391F23189 for ; Fri, 15 Dec 2023 08:10:45 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DBF10182A3; Fri, 15 Dec 2023 08:10:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="cNk9e8PW" X-Original-To: linux-kernel@vger.kernel.org Received: from mail-pf1-f178.google.com (mail-pf1-f178.google.com [209.85.210.178]) (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 D895017981 for ; Fri, 15 Dec 2023 08:10:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pf1-f178.google.com with SMTP id d2e1a72fcca58-6ce7632b032so155642b3a.1 for ; Fri, 15 Dec 2023 00:10:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1702627803; x=1703232603; darn=vger.kernel.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=sICzlYhaSfeV+0O8ybAajGk8fmRoPkGoJtHOPJtKgUM=; b=cNk9e8PWUD7XMBzEF6I6Z+tin57f8mtN7o0Fx7D5m0klA/J+2RzSk+V2DzetjkuPMy HYLHHwwgkmvj6kVkf1rNpB6I7jLv3TDiTUZ+tf6mhelO9p2opaQSZemmNMDVRd6Bzamb BU0Nu8ZSF/r0lLeuk4z9uyDfM7bglBilia2E3WePKrMXsAWEBL/ufk52HtMpMZJq9PC8 ViWF/Dz+O7IFPYm5Ld3sTPDZ2FrSDgrHa2ekAimw79SLTJu7BgNT4gFeFLXlBMCwL1Qb 4QOz1fVV0HEEfdvhBUFqUwLHkAneSnC4+8vhPrwPpkTF7SsXjHVPb3MkPWiKN6bVGfyH a9SQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702627803; x=1703232603; 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=sICzlYhaSfeV+0O8ybAajGk8fmRoPkGoJtHOPJtKgUM=; b=YlERiJ64IPUQ5eDqJSVaim9Ka3RvhSVe8TGy/IdHj10P/U6B8uss1iKFNADwv5ciyT 2ZZMP956tinXlhK+gX8mK9O+mHxt6eJ32jEZFYHlFLT6ElxYmLYBh5B8wv8MTY1uy/ON 9cx7j3Wk1hRYGHWgTVI0WT35VKUhJp0gf9tQmNeL1NIch10B8Lxajhj//u73V8tmLUFA jmxNf5AwrdHKlisbCbyX0mTOnF6iZryCgIiODPZ2AZCRGANd0DYS64AJWO4hvZlU0/wu 1AAeKr0nkgBxt8WxiJMT34Psg7p7O9Oz3kiJ4vukB0dPNc5lKP4GCXV98ZCw4+FpicDt oQvg== X-Gm-Message-State: AOJu0YxLJsow9Nr4d4jK+W0rUBI5Cjj7vh+qKSoZW0zHkAgdZIbFnh+9 5KEHvv3bC6HxoErdajWLrqjzz+b6/Fs= X-Received: by 2002:a05:6a00:d76:b0:6ce:f665:ab1 with SMTP id n54-20020a056a000d7600b006cef6650ab1mr3875430pfv.11.1702627802891; Fri, 15 Dec 2023 00:10:02 -0800 (PST) Received: from code.. ([144.202.108.46]) by smtp.gmail.com with ESMTPSA id d8-20020a056a00198800b006cee656cb35sm11783792pfl.156.2023.12.15.00.09.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Dec 2023 00:10:02 -0800 (PST) From: Yuntao Wang To: linux-kernel@vger.kernel.org, kexec@lists.infradead.org, x86@kernel.org Cc: Andrew Morton , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" , Jonathan Corbet , Eric Biederman , Yuntao Wang Subject: [PATCH 2/3] kexec_file: fix incorrect temp_start value in locate_mem_hole_top_down() Date: Fri, 15 Dec 2023 16:09:09 +0800 Message-ID: <20231215080910.173338-3-ytcoode@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231215080910.173338-1-ytcoode@gmail.com> References: <20231215080910.173338-1-ytcoode@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit temp_end represents the address of the last available byte. Therefore, the starting address of the memory segment with temp_end as its last available byte and a size of `kbuf->memsz`, that is, the value of temp_start, should be `temp_end - kbuf->memsz + 1` instead of `temp_end - kbuf->memsz`. Additionally, use the ALIGN_DOWN macro instead of open-coding it directly in locate_mem_hole_top_down() to improve code readability. Signed-off-by: Yuntao Wang --- kernel/kexec_file.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/kernel/kexec_file.c b/kernel/kexec_file.c index 26be070d3bdd..c3bf52a9a8ad 100644 --- a/kernel/kexec_file.c +++ b/kernel/kexec_file.c @@ -426,11 +426,11 @@ static int locate_mem_hole_top_down(unsigned long start, unsigned long end, unsigned long temp_start, temp_end; temp_end = min(end, kbuf->buf_max); - temp_start = temp_end - kbuf->memsz; + temp_start = temp_end - kbuf->memsz + 1; do { /* align down start */ - temp_start = temp_start & (~(kbuf->buf_align - 1)); + temp_start = ALIGN_DOWN(temp_start, kbuf->buf_align); if (temp_start < start || temp_start < kbuf->buf_min) return 0; -- 2.43.0