From patchwork Tue Feb 20 02:11:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "yang.zhang" X-Patchwork-Id: 203372 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp148339dyc; Mon, 19 Feb 2024 18:12:17 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVW1TCr3u0A2IwLi0lPAG6WRNWUhu+O4Sd/CP3qhtOtH5rRMjSJYoF7bRUhiM2Ua0/GjRfu6WGv6kDecdZiDJIRDSfvfw== X-Google-Smtp-Source: AGHT+IEwWBHiRw3wvoI5i+UhiUKGAGK8kBlRvYI7P6qdQyr2U/NuCRF8mCqaVufI+FoMd6WL2ZEJ X-Received: by 2002:a05:6214:4114:b0:68f:3d9d:e6f2 with SMTP id kc20-20020a056214411400b0068f3d9de6f2mr11258751qvb.54.1708395137414; Mon, 19 Feb 2024 18:12:17 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708395137; cv=pass; d=google.com; s=arc-20160816; b=YIox44ZsOm2GO4p4vZNA1a33GJIProPjjA+HQMquUBYqfZQvLYtnorUP0pev9cgAey 6UsKy5F0GsWUNLpBA8eyEgaWVAwYieWwb15CXDAwlvEEecfzf9JLsqEfS0Ec6g4HkNCk mzCXY6WKLKMVM55ZAUmwiNaEKx1dbDDdAQtjSR08LvZB0sOPp537/c5DH0Fzaxx/wQhy gVBqpYlWn4aTtVV2Gs1CzBhnABjZ6rFyGojPuRlZrmHQCjMpCxtL3rgcZnbPUwHTkxui AbpwVt8DPHoJrgvH2dtTTQuZEbnAdJ5zJP+NYVyW3xhgCkusbaPVM1nMHJzl9fEaIwYP b2sA== ARC-Message-Signature: i=2; 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:message-id:date:subject:cc:to :from:dkim-signature; bh=hfqV3prgl2YOJl/pulYljFe3VTVS7nYpmcsCfsx02Kg=; fh=QzljFfWK8fjv7j47o1Og3DkOruNY6wIcTTKmCLILTgs=; b=Ou3XXVWJaDpqupfIaNSMpsGFTIj1FSJyryRPRwG8IJVh9DPHEHoLsr0VQgItb8rCGE W+Ryj5ZoEx097ec1uus0D665lWYlCPHOz2HB9ops2kYUZ5tqVwSdMrXpeoY15A/r9s+c iOTaJ63AYlZ8X20xMUr1w1hd0T8aRjv4tYiJ3qPIjLpacRMTjM8pNkM33UU0mxX5zHhK hzZ2huuxQzt0fBOSz3zp/EzcMHrGuj/9pIt3sXXNRCbMTbp3CXykOuJ36p23TvtR1lbA tQ6uwsuvDajjlyrVTtbpSSHabLNiHq4Emh85RNpH/XS/CDG5nsCvn07Usvxi2dItnjO0 gTbA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@163.com header.s=s110527 header.b=hk9ERh2B; arc=pass (i=1 spf=pass spfdomain=163.com dkim=pass dkdomain=163.com dmarc=pass fromdomain=163.com); spf=pass (google.com: domain of linux-kernel+bounces-72203-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-72203-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=163.com Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id 6-20020a0562140d4600b0068f5fc4942bsi4687639qvr.163.2024.02.19.18.12.17 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Feb 2024 18:12:17 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-72203-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@163.com header.s=s110527 header.b=hk9ERh2B; arc=pass (i=1 spf=pass spfdomain=163.com dkim=pass dkdomain=163.com dmarc=pass fromdomain=163.com); spf=pass (google.com: domain of linux-kernel+bounces-72203-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-72203-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=163.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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 39CD31C21F69 for ; Tue, 20 Feb 2024 02:12:17 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4864F4596D; Tue, 20 Feb 2024 02:12:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b="hk9ERh2B" Received: from m16.mail.163.com (m16.mail.163.com [220.197.31.3]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4B6C0171AA for ; Tue, 20 Feb 2024 02:12:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=220.197.31.3 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708395124; cv=none; b=sA6YLmcTHMymO5FN5USH++yS3876aW7dlnLDQly2f3lOeENMcOKMq6iM+ehQLPdHhSFoq71RG7DCDDwG9TWC63nDNilYPG1XYfYH2Cxf7Dr8knBjIVkwpOdSK4J5nSC4kmm7fenF1maox0JpfgLFkQ20BWS7N+VUpgILG+DmaVw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708395124; c=relaxed/simple; bh=bDNG2Mey+KC6KZ1T8yZBEYKkBjWpo5P+1ge2mZuklTI=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=ddWTmlxXzheiLij+27Nt30ZrAtGokbWX2bpc6g9nzIuszkWnfU/MPMQhmRFHQyQgPwOf/TOEe+dcIa4e+/M4eOUxpLOo6sDfkyX5aF33GKZx0x/7LwLT22rdnoEUTwxRVCaMiYSn9apvhdeIYcRL1aNCaCn1GSGfwvVQy2UeDUQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com; spf=pass smtp.mailfrom=163.com; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b=hk9ERh2B; arc=none smtp.client-ip=220.197.31.3 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=163.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-Id:MIME-Version; bh=hfqV3 prgl2YOJl/pulYljFe3VTVS7nYpmcsCfsx02Kg=; b=hk9ERh2Bu9lud3FFYD15Y 2yRLx2UcqL6yNR6bKtcs0gIA9xbROdx4gadQeaTff2PwcpVPlDZnOMyDmA+1sLKg yVAeIasTI+9SRJJPk5D/qmqgJUFiiKmbMrLShH5Lazs16kHRYnJjNjGo+7ZONsKf Gk8RfZnEuFxNHV0eyxpw8Y= Received: from yangzhang2020.localdomain (unknown [60.24.209.108]) by gzga-smtp-mta-g1-2 (Coremail) with SMTP id _____wDn9_o7CtRlEnztDA--.4655S2; Tue, 20 Feb 2024 10:11:08 +0800 (CST) From: "yang.zhang" To: ebiederm@xmission.com Cc: kexec@lists.infradead.org, linux-kernel@vger.kernel.org, bhe@redhat.com, akpm@linux-foundation.org, "yang.zhang" Subject: [PATCH v2] kexec: copy only happens before uchunk goes to zero Date: Tue, 20 Feb 2024 10:11:06 +0800 Message-Id: <20240220021106.694-1-gaoshanliukou@163.com> X-Mailer: git-send-email 2.25.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-CM-TRANSID: _____wDn9_o7CtRlEnztDA--.4655S2 X-Coremail-Antispam: 1Uf129KBjvJXoW7ur4xtr4UArykCw17GF1DAwb_yoW8KFWDp3 9xGr10grWrJr9rXrn7tF98C3yfJ3s7GrWru3yUCF95KrnI93Wvq34F93Wj93yUKryFkrn5 Jw4qkFyaga4UX37anT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07jv1v3UUUUU= X-CM-SenderInfo: pjdr2x5dqox3xnrxqiywtou0bp/xtbBZRyK8mV4H46InwAAsa X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791382139625669384 X-GMAIL-MSGID: 1791382139625669384 From: "yang.zhang" When load segments, all of the copying and the rest only happens before uchunk goes to zero. Signed-off-by: yang.zhang Acked-by: Baoquan He --- v1 -> v2: - Only copy before uchunk goes to zero V1: https://lore.kernel.org/lkml/20240130101802.23850-1-gaoshanliukou@163.com/ --- kernel/kexec_core.c | 44 ++++++++++++++++++++++++-------------------- 1 file changed, 24 insertions(+), 20 deletions(-) diff --git a/kernel/kexec_core.c b/kernel/kexec_core.c index d08fc7b5db97..2fc3d0e3715a 100644 --- a/kernel/kexec_core.c +++ b/kernel/kexec_core.c @@ -800,22 +800,24 @@ static int kimage_load_normal_segment(struct kimage *image, PAGE_SIZE - (maddr & ~PAGE_MASK)); uchunk = min(ubytes, mchunk); - /* For file based kexec, source pages are in kernel memory */ - if (image->file_mode) - memcpy(ptr, kbuf, uchunk); - else - result = copy_from_user(ptr, buf, uchunk); + if (uchunk) { + /* For file based kexec, source pages are in kernel memory */ + if (image->file_mode) + memcpy(ptr, kbuf, uchunk); + else + result = copy_from_user(ptr, buf, uchunk); + ubytes -= uchunk; + if (image->file_mode) + kbuf += uchunk; + else + buf += uchunk; + } kunmap_local(ptr); if (result) { result = -EFAULT; goto out; } - ubytes -= uchunk; maddr += mchunk; - if (image->file_mode) - kbuf += mchunk; - else - buf += mchunk; mbytes -= mchunk; cond_resched(); @@ -866,11 +868,18 @@ static int kimage_load_crash_segment(struct kimage *image, memset(ptr + uchunk, 0, mchunk - uchunk); } - /* For file based kexec, source pages are in kernel memory */ - if (image->file_mode) - memcpy(ptr, kbuf, uchunk); - else - result = copy_from_user(ptr, buf, uchunk); + if (uchunk) { + /* For file based kexec, source pages are in kernel memory */ + if (image->file_mode) + memcpy(ptr, kbuf, uchunk); + else + result = copy_from_user(ptr, buf, uchunk); + ubytes -= uchunk; + if (image->file_mode) + kbuf += uchunk; + else + buf += uchunk; + } kexec_flush_icache_page(page); kunmap_local(ptr); arch_kexec_pre_free_pages(page_address(page), 1); @@ -878,12 +887,7 @@ static int kimage_load_crash_segment(struct kimage *image, result = -EFAULT; goto out; } - ubytes -= uchunk; maddr += mchunk; - if (image->file_mode) - kbuf += mchunk; - else - buf += mchunk; mbytes -= mchunk; cond_resched();