Received: by 2002:a05:7412:8d23:b0:f7:29d7:fb05 with SMTP id bj35csp503789rdb; Sat, 16 Dec 2023 19:36:58 -0800 (PST) X-Google-Smtp-Source: AGHT+IHf4FtD7kaew4K3o+8H39XogA6NkpGTG8AQQpM+4q+zg5OsFJ8hlq5oAEwlVMTynS6CH1o9 X-Received: by 2002:a05:6808:1509:b0:3ae:5bf5:4ad1 with SMTP id u9-20020a056808150900b003ae5bf54ad1mr16600835oiw.33.1702784218207; Sat, 16 Dec 2023 19:36:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702784218; cv=none; d=google.com; s=arc-20160816; b=fyfsuWqP21wUpZVvMHUZPgfq+25aewkuhtqeWR3kp+yHN0yn9bnbgjiRBT2qhq3K35 Cw0g/945bgu18qRmeMSenjMz8A/iJNMFRAXWPztyn5xP7NM4juRRn61Phx41NxaYjZq0 /ObLyjmW6d1DJ84W7PmuZJK+MVwIFSeCQCOiVTmJRBvlzE964iS33RyXOR5NqskUUvOb 0bATCKSSsTVpgzKc8fVxmzR5c7FA8HsN3QSZu/1KJdwOJY4s/h9MPVHVkPaT8xIC6ZaI LOOMfrKeYj01PxlJbxoe/BxwthfIqetoVlk6OGZrz6zF5hHHwCvAuMPzQmd1rdT5ou1v thCA== 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=3V8gSp8bUEZWRGRAcmamI1zQxxCYsLgl6TFXIZtXR8g=; fh=OFqNsYX8N7CiaOh4T8ZVrBLcp4EV0r1YygOgFs6Ppdc=; b=p49vnJZ7tpBcwDJFk9Plvhj9hvJtXoxjc69/2naXwdYj5WA/riZJnX+CnRO2Vyf4ru 1lW13rWJPPU6igXOEhvrYbP8qdDCDzqPSSr3y4c3SrdDc5FdC9WkMyfQKLFeCp5+Vz9R dLYzdCC4vcVXgYEpqjfNhA2U7bQ9s6cf5Ote0jKykVe/cntZT3IBXZaVvVbuUypAO2oL 22xVuljMPJnPg8rZofSSkx6EIhMwujJxhPQ8SEZeimTH61sFrSHYoRzugkpiglMlh+2B DU+tAE3lXga+U96y9DTET49m3bZ4rbldsuLDuCYcuwVUu1eECjDUyCd+sAVQlIzlkzRI IGNw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=EoeD5l9w; spf=pass (google.com: domain of linux-kernel+bounces-2448-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-2448-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id j9-20020a056a00174900b006ce61c266e3si15546780pfc.318.2023.12.16.19.36.57 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 16 Dec 2023 19:36:58 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-2448-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=EoeD5l9w; spf=pass (google.com: domain of linux-kernel+bounces-2448-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-2448-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id D9DC9B21CF3 for ; Sun, 17 Dec 2023 03:36:56 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1ED9323B9; Sun, 17 Dec 2023 03:36:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="EoeD5l9w" X-Original-To: linux-kernel@vger.kernel.org Received: from mail-io1-f54.google.com (mail-io1-f54.google.com [209.85.166.54]) (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 18ACD20E3 for ; Sun, 17 Dec 2023 03:36:36 +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-io1-f54.google.com with SMTP id ca18e2360f4ac-7b7039d30acso166613539f.3 for ; Sat, 16 Dec 2023 19:36:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1702784195; x=1703388995; 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=3V8gSp8bUEZWRGRAcmamI1zQxxCYsLgl6TFXIZtXR8g=; b=EoeD5l9wXRKiqhPFr4HMPiqmhgEy/nUK37cKf/nqi7mVT00rz4Ic9rvd7x6GkSfbOK 0bzULEUQ1C6eW/Qj0YXEn2PP2XhXOnmVIktm714VE3h65fs24IxVMna6G1Iw+kpk3GqB 2xQumGTaD/EAZGpRsRt65e5atV8IE5/ly3zK2YWh40xFDxM7PEm9CV1zNvp4frqUWAEB f9wPcOO3EurGvi0sxzPGvHBE+bafgcQnLaZM1N67aC425bnTQQPStY2kJLppZTEdPLqW bX5GnktwTrL1XJc3fgrTgoak+9ZOOH30NhbbP2MIbLU5hior0iJUaIaySTmxnRLKugUP tdNw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702784195; x=1703388995; 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=3V8gSp8bUEZWRGRAcmamI1zQxxCYsLgl6TFXIZtXR8g=; b=dLJoRVXL/GEi2oXxrbXzmEQpQlgBWGssME9e1WcBgO9V/BkxMFxUlHcw8n/lmhXtJu dSdM0FipyigyX3+HfhjqrnCCpChSHlRkYqG1E0oajjpluhdKeP58N/WHsbYa1yhcMyAQ qaDgyvPK+9tyq4DcPPuICELAPSVfvZPFZpQXIg6xVmHEEuete1Qff1+njEz/JtvqajOa oGERM51fqYz4IG8663dkCarRQ9aeLVp1ry6xo8SCEuKzj0Sgu4o2aENYDwuuirYEqwPL Jml78m5ZMYEnZmg0eYy244tY6KFDKyrey7idQDonUOTrUTclb/7GPLdRLDke1FZzptEZ TrWA== X-Gm-Message-State: AOJu0Yy0Tof/wGgCI/OoMkWpaizTn2r8QDfmtZqkcO1YRUEZSsdiOjIv uXBsnli5fPbczFOJI+zg7ZYojffcjOw= X-Received: by 2002:a5d:8850:0:b0:7b4:28f8:526 with SMTP id t16-20020a5d8850000000b007b428f80526mr16927258ios.38.1702784195510; Sat, 16 Dec 2023 19:36:35 -0800 (PST) Received: from code.. ([144.202.108.46]) by smtp.gmail.com with ESMTPSA id x26-20020a62fb1a000000b006ce48a0b7c6sm15768820pfm.109.2023.12.16.19.36.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 16 Dec 2023 19:36:35 -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 , Baoquan He , Yuntao Wang Subject: [PATCH v5 2/3] kexec_file: fix incorrect temp_start value in locate_mem_hole_top_down() Date: Sun, 17 Dec 2023 11:35:27 +0800 Message-ID: <20231217033528.303333-3-ytcoode@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231217033528.303333-1-ytcoode@gmail.com> References: <20231217033528.303333-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 f9a419cd22d4..336d085cbc47 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