From nobody Sun Nov 24 02:57:31 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=reject dis=none) header.from=citrix.com ARC-Seal: i=1; a=rsa-sha256; t=1729636836; cv=none; d=zohomail.com; s=zohoarc; b=e9V58RSgJt+MsYgpq4Mw+76+vKJ/qVeTk8tcx0ezwAPQoVkAGGiELLfOc5QfskkgBqHAnGbfX0niMotO0qcXrNjUtgj1Ced5ROfFDOC7yPtYnYvU8Lh+TzZsXcN/28lwWDFdz5TUwV2wNx+ZK3CCrjx6CDvpDZQrzCJaij+F04c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1729636836; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=rdLdfba2PiBiA/2L4zZymgw8I8BN4e9PskPZBu3Nv6w=; b=RjfdQCuOsanOYVCNrcCzScLlRaHa7f3g/dpcNAJQpbw9vGhdPSNvt5N18oRAeH7oJ2zjJZJNa9PzgLyvPezrCBXpLz/oTByMMmRJIeJWU8lTx0bxgT1Dux32c4LLWbkw0EZ11Iambseq7M0WvMEI6hq7f45/8wDk0RCemtWYhI0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1729636836014352.3252028214363; Tue, 22 Oct 2024 15:40:36 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.824297.1238400 (Exim 4.92) (envelope-from ) id 1t3NXo-0002ar-71; Tue, 22 Oct 2024 22:40:04 +0000 Received: by outflank-mailman (output) from mailman id 824297.1238400; Tue, 22 Oct 2024 22:40:04 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1t3NXo-0002ZQ-2u; Tue, 22 Oct 2024 22:40:04 +0000 Received: by outflank-mailman (input) for mailman id 824297; Tue, 22 Oct 2024 22:40:01 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1t3NXl-00026E-Sc for xen-devel@lists.xenproject.org; Tue, 22 Oct 2024 22:40:01 +0000 Received: from mail-ej1-x632.google.com (mail-ej1-x632.google.com [2a00:1450:4864:20::632]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 91e98bd7-90c6-11ef-a0be-8be0dac302b0; Wed, 23 Oct 2024 00:40:00 +0200 (CEST) Received: by mail-ej1-x632.google.com with SMTP id a640c23a62f3a-a9a4031f69fso890427866b.0 for ; Tue, 22 Oct 2024 15:39:59 -0700 (PDT) Received: from andrewcoop.eng.citrite.net ([185.25.67.249]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a9a913076f5sm396704066b.95.2024.10.22.15.39.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Oct 2024 15:39:58 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 91e98bd7-90c6-11ef-a0be-8be0dac302b0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.com; s=google; t=1729636799; x=1730241599; darn=lists.xenproject.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=rdLdfba2PiBiA/2L4zZymgw8I8BN4e9PskPZBu3Nv6w=; b=Ihjnr8/+wom3b/zS/Ia1BfcNE8bMXF1u2KR9Ul7dX+biBWfkvuzkl12w2CoXzj4N0b M16uiHZU0p1hcPHchO9wJRyKfETvtANvEF4vPlpgY9squBbh6QkA4rbCQSJtnSqnpg8C o1y9MYMkMKekDk3K0gQy7KZA76eF4qnyCzMe8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729636799; x=1730241599; 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=rdLdfba2PiBiA/2L4zZymgw8I8BN4e9PskPZBu3Nv6w=; b=sP6QrB/42gFFst3wtWfEJBFpdvaalhEx3OMf5EpGzefMiU85IapOZM2hqIrbw/FCIX 8bdo5teOfgK7WkgcAPLpIu3Tc51FleD6gYqKeZ16gyszAnbYGbqFjb+XzzeWe/DFN/im MMsZCwriRs/1AevfvB1dQT5CY3AJGZ3yEqdpQaazzBqsJp9pVcqqtEn6sxUPWcAqF24W 20A9DtES5Busj/QanReJLyYo3hvctHk97aL/WVkFvTDqZdaSplvWAxB3/F5zFXu6V2Ga Q0dMMR39Olhu2afYS7KTsAHD0ViU151yN/4f+K3iwgWBo0HoNVzLtbBySznx0Jn4/v+h /l7g== X-Gm-Message-State: AOJu0YyYlN6p+ptvHjvkZVDLol4Ysb9iR3C/GxCISx63Q18Cl0A8Ks7P 1mSVFo2kXC7dXnBEB3kauDlWpUeq0Vknrn+c2S+BhB2iiV8DJKskKmWir6hhmZ3SwYL0j2AVpoR 8 X-Google-Smtp-Source: AGHT+IGVn6i0LkXUb+yXm4tFD12xZCnycC5rC6hMgzmTv7Rd+Ezlg7+7CgXEXOhLqSGyFukr8Be94g== X-Received: by 2002:a17:907:3d92:b0:a99:fc3d:7c76 with SMTP id a640c23a62f3a-a9abf8a8f8dmr43877566b.37.1729636798692; Tue, 22 Oct 2024 15:39:58 -0700 (PDT) From: Andrew Cooper To: Xen-devel Cc: Andrew Cooper , Jan Beulich , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , "Daniel P . Smith" Subject: [PATCH 1/3] x86/boot: Convert move_memory() to use bootstrap_map_addr() Date: Tue, 22 Oct 2024 23:39:52 +0100 Message-Id: <20241022223954.432554-2-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20241022223954.432554-1-andrew.cooper3@citrix.com> References: <20241022223954.432554-1-andrew.cooper3@citrix.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @citrix.com) X-ZM-MESSAGEID: 1729636837833116600 move_memory() is very complicated, and buggy. In order to fix the latter, = we have to address the former. Given prior cleanup, bootstrap_map() is now implemented in terms of bootstrap_map_addr(), meaining that it is counterproductive to plumb the mapping through module_t. Delete mod, and introduce two same-sized/named fields. At this point in bo= ot, neither fields have their named purpose, so indicate the purpose in comment= s. No functional change. Signed-off-by: Andrew Cooper Reviewed-by: Daniel P. Smith --- CC: Jan Beulich CC: Roger Pau Monn=C3=A9 CC: Daniel P. Smith This is broken out both to ease review (I recommend git diff --color-words), and for bisection purposes given how many times I've failed to edit this lo= gic correctly. This does not conflict with anything in Hyperlaunch v7, but it does remove = the only callers of bootstrap_map() remaining by the end of the series, allowing for even more cleanup. In terms of bugs. The ones I've spotted so far are: * The blksz calculation depends on the previous thing having been unmapped first. * The calculation halving blksz based on BOOTSTRAP_MAP_BASE is bogus. It might plausibly be a remnent of 32bit Xen with the absence of highmem. * The caller of move_memory() is strictly moving modules forward in memory (dst > src) with a possibility of partial overlap. The while loop maps dst and src, blksz chunks at a time, ascending, with s < d. This results in memmove() doing an unconditional backwards copy. I don't see how this logic could ever have worked for an overlapping mov= e. * The caller of move_memory() already has a good mapping for dst, so we do= n't even need to split BOOTSTRAP_MAP_LIMIT in half to map both parts. --- xen/arch/x86/setup.c | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/xen/arch/x86/setup.c b/xen/arch/x86/setup.c index 059b597331a7..46a0b3093c2c 100644 --- a/xen/arch/x86/setup.c +++ b/xen/arch/x86/setup.c @@ -492,26 +492,29 @@ static void __init noinline move_memory( =20 while ( size ) { - module_t mod; + unsigned int start /* frame */; + unsigned int end /* mapsz */; unsigned int soffs =3D src & mask; unsigned int doffs =3D dst & mask; unsigned int sz; void *d, *s; =20 - mod.mod_start =3D (src - soffs) >> PAGE_SHIFT; - mod.mod_end =3D soffs + size; - if ( mod.mod_end > blksz ) - mod.mod_end =3D blksz; - sz =3D mod.mod_end - soffs; - s =3D bootstrap_map(&mod); - - mod.mod_start =3D (dst - doffs) >> PAGE_SHIFT; - mod.mod_end =3D doffs + size; - if ( mod.mod_end > blksz ) - mod.mod_end =3D blksz; - if ( sz > mod.mod_end - doffs ) - sz =3D mod.mod_end - doffs; - d =3D bootstrap_map(&mod); + start =3D (src - soffs) >> PAGE_SHIFT; + end =3D soffs + size; + if ( end > blksz ) + end =3D blksz; + sz =3D end - soffs; + s =3D bootstrap_map_addr(pfn_to_paddr(start), + pfn_to_paddr(start) + end); + + start =3D (dst - doffs) >> PAGE_SHIFT; + end =3D doffs + size; + if ( end > blksz ) + end =3D blksz; + if ( sz > end - doffs ) + sz =3D end - doffs; + d =3D bootstrap_map_addr(pfn_to_paddr(start), + pfn_to_paddr(start) + end); =20 memmove(d + doffs, s + soffs, sz); =20 @@ -519,7 +522,7 @@ static void __init noinline move_memory( src +=3D sz; size -=3D sz; =20 - bootstrap_map(NULL); + bootstrap_map_addr(0, 0); } } =20 --=20 2.39.5 From nobody Sun Nov 24 02:57:31 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=reject dis=none) header.from=citrix.com ARC-Seal: i=1; a=rsa-sha256; t=1729636842; cv=none; d=zohomail.com; s=zohoarc; b=XMibqYoNC2MdIIMbGpQp4rMH+Z/kZkaSBIEWQ9m6wQWzyVdO6kNUhayp/TDd8vxMBhmv+UXQUAyiap22B1yB+lgk9aPKUrx5ZNYt45gegJqLInDuUqMmIS9VzW0MVpASHRvGiYgNrZ6lmNdR05bJo5tDfrVNcQnb/X5J00j1SG8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1729636842; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=C87F54BHlnewuAYUBvjYbM5M2wyL7R+xBacmzm9+EfQ=; b=ECIIS80Zltx8/MDnjE4PpXM4adN70a8KeMx7FmSqEv0XsTtyGgj6CKa8Va7IFfkVJGBGM/3yJDLL4qUZFJgnuUwXJo+njUe7IhugD4JLhIN0ClmcjWT9S5WAhZO4Ul0toyF/40aYbl9bwSKy2MLA58/prx4u2vCoCiGuCfX8gts= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1729636842203923.7629763360012; Tue, 22 Oct 2024 15:40:42 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.824299.1238415 (Exim 4.92) (envelope-from ) id 1t3NXp-0002sW-0n; Tue, 22 Oct 2024 22:40:05 +0000 Received: by outflank-mailman (output) from mailman id 824299.1238415; Tue, 22 Oct 2024 22:40:04 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1t3NXo-0002pu-PP; Tue, 22 Oct 2024 22:40:04 +0000 Received: by outflank-mailman (input) for mailman id 824299; Tue, 22 Oct 2024 22:40:03 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1t3NXn-000277-9S for xen-devel@lists.xenproject.org; Tue, 22 Oct 2024 22:40:03 +0000 Received: from mail-ed1-x52c.google.com (mail-ed1-x52c.google.com [2a00:1450:4864:20::52c]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 92fdf875-90c6-11ef-99a3-01e77a169b0f; Wed, 23 Oct 2024 00:40:01 +0200 (CEST) Received: by mail-ed1-x52c.google.com with SMTP id 4fb4d7f45d1cf-5c903f5bd0eso3114901a12.3 for ; Tue, 22 Oct 2024 15:40:01 -0700 (PDT) Received: from andrewcoop.eng.citrite.net ([185.25.67.249]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a9a913076f5sm396704066b.95.2024.10.22.15.39.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Oct 2024 15:39:59 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 92fdf875-90c6-11ef-99a3-01e77a169b0f DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.com; s=google; t=1729636800; x=1730241600; darn=lists.xenproject.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=C87F54BHlnewuAYUBvjYbM5M2wyL7R+xBacmzm9+EfQ=; b=TkcQYSG+fVoVvmvpw4y1IOjAsh6v3C8xtNs9ejvlTnJjD0BGPKvu/Xp6rp+b+mQUZa 1yRbPX2F8ZlNav6Euz76T8iEcjYs1an49rVSj/rhD98PaObv9AcbkGBS8lQLxU6uGEWR +FDwsoKljC/TPZsufuyT/be7hBXMvi8K+5ADQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729636800; x=1730241600; 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=C87F54BHlnewuAYUBvjYbM5M2wyL7R+xBacmzm9+EfQ=; b=EUfKxRsmPnON0T5q4dqlRBXUkHCNRczVjaeSC8EGdyBmTftw1t8/2Nc7AzP00ZEV0o +epR3GmBx0ldcfzCt1yUm9EiTVPqgEfvhvje/E4ntUC5Txf9g87HC/J0EWcs1wrpeuxo sMuUm2k6j6RXw79/HVHlGdv52skMUQBmkwDohnEm1qfbgGWJ+oMal76/xaifwW5mw7EV vywOhsaQQisEjOXRbK3iQa6WqsbWwm2aEH550zRj/sDpJ3tGUsC76XzmUwcdW7UhOl0r PGuIzn2o7vLla8lMw0OFIvPxx6JuQ2Kj0Nr0+i/VldPGpS7I+DTpevA5uH4JZGHtXLi9 ZSvg== X-Gm-Message-State: AOJu0YwOPkI1xB3eUVVuysig+Vi+4zLred4YYLdJ1fBM++iACIxnGeRX VP3VO4zHR1LVnBFADETg0CxTD1uog46IRaiqJF+BbyTBRO4d+VBKjlfyF3BF9tkpFtYZBmoieUF P X-Google-Smtp-Source: AGHT+IGwkerqzCYPmxUQirCtPpPgH8/ENEiUF9o2wQYWSdRbqopzg6LlHTHKmeTfkmTH6WL+hcjxiQ== X-Received: by 2002:a17:907:9403:b0:a99:e98f:e73d with SMTP id a640c23a62f3a-a9abf8b06f9mr43186166b.37.1729636800293; Tue, 22 Oct 2024 15:40:00 -0700 (PDT) From: Andrew Cooper To: Xen-devel Cc: Andrew Cooper , Jan Beulich , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , "Daniel P . Smith" Subject: [PATCH 2/3] x86/boot: Simplify address calculations in move_memory() Date: Tue, 22 Oct 2024 23:39:53 +0100 Message-Id: <20241022223954.432554-3-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20241022223954.432554-1-andrew.cooper3@citrix.com> References: <20241022223954.432554-1-andrew.cooper3@citrix.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @citrix.com) X-ZM-MESSAGEID: 1729636843741116600 Given that soffs is the offset into the 2M superpage, start =3D (src - soffs) >> PAGE_SIFT is a complicated expression for the frame address of the containing superpa= ge. Except, start is converted straight back to a byte address to use, so the shifting is unnecessary too. The only done with the mapped pointer is to have soffs added back on for the memmove() call. bootstrap_map_addr() passes through the offset, so we can pass src directly in and simplify the memmove() call too. For the end mapp= ing address, this simplifies to just src + sz too. The same reasoning holds for dst and doffs. No functional change. Signed-off-by: Andrew Cooper Reviewed-by: Daniel P. Smith --- CC: Jan Beulich CC: Roger Pau Monn=C3=A9 CC: Daniel P. Smith --- xen/arch/x86/setup.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/xen/arch/x86/setup.c b/xen/arch/x86/setup.c index 46a0b3093c2c..152cd696d6c2 100644 --- a/xen/arch/x86/setup.c +++ b/xen/arch/x86/setup.c @@ -492,31 +492,26 @@ static void __init noinline move_memory( =20 while ( size ) { - unsigned int start /* frame */; unsigned int end /* mapsz */; unsigned int soffs =3D src & mask; unsigned int doffs =3D dst & mask; unsigned int sz; void *d, *s; =20 - start =3D (src - soffs) >> PAGE_SHIFT; end =3D soffs + size; if ( end > blksz ) end =3D blksz; sz =3D end - soffs; - s =3D bootstrap_map_addr(pfn_to_paddr(start), - pfn_to_paddr(start) + end); + s =3D bootstrap_map_addr(src, src + sz); =20 - start =3D (dst - doffs) >> PAGE_SHIFT; end =3D doffs + size; if ( end > blksz ) end =3D blksz; if ( sz > end - doffs ) sz =3D end - doffs; - d =3D bootstrap_map_addr(pfn_to_paddr(start), - pfn_to_paddr(start) + end); + d =3D bootstrap_map_addr(dst, dst + sz); =20 - memmove(d + doffs, s + soffs, sz); + memmove(d, s, sz); =20 dst +=3D sz; src +=3D sz; --=20 2.39.5 From nobody Sun Nov 24 02:57:31 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=reject dis=none) header.from=citrix.com ARC-Seal: i=1; a=rsa-sha256; t=1729636838; cv=none; d=zohomail.com; s=zohoarc; b=PBnyOC91fNeKWCdxUmCwEHav7GlfAi/TbxuVRtIiK6ya7pv3RC+86obiFBRNu+yy9XMfPL85rSufhIkIUwNvtFjSnxapzHNb4l90T+1SrgPwO6Pm7M8oXawKUx/mIt0uRIOnlUToSCJot/viXGh1UMT2bXFpN1355OWjn39nhls= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1729636838; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=WngS3EfMpOQgHq1eT2hKFkIIl1PwfdoEnZaYAyPIS0Y=; b=i6triW0OTU6KLvXZKkRFVzLicnz+KpdGJ2oM/Pf1nnij3NtfgsYRDaTyYCUJTPkvU6Hh+AaZMm2tVIhnVD0lGK6mz5nWECamoEsfkKsjg+QVEla9uIcwiyXjD3FS71Z5dxYfNJI3+KeUmaZ8AoVR+voZ3novoJ0WeU45IgscVQI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1729636838329526.9272514502682; Tue, 22 Oct 2024 15:40:38 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.824298.1238405 (Exim 4.92) (envelope-from ) id 1t3NXo-0002i0-Fj; Tue, 22 Oct 2024 22:40:04 +0000 Received: by outflank-mailman (output) from mailman id 824298.1238405; Tue, 22 Oct 2024 22:40:04 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1t3NXo-0002fX-BB; Tue, 22 Oct 2024 22:40:04 +0000 Received: by outflank-mailman (input) for mailman id 824298; Tue, 22 Oct 2024 22:40:02 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1t3NXm-00026E-PT for xen-devel@lists.xenproject.org; Tue, 22 Oct 2024 22:40:02 +0000 Received: from mail-ed1-x52c.google.com (mail-ed1-x52c.google.com [2a00:1450:4864:20::52c]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 934a1319-90c6-11ef-a0be-8be0dac302b0; Wed, 23 Oct 2024 00:40:02 +0200 (CEST) Received: by mail-ed1-x52c.google.com with SMTP id 4fb4d7f45d1cf-5c9362c26d8so498724a12.1 for ; Tue, 22 Oct 2024 15:40:02 -0700 (PDT) Received: from andrewcoop.eng.citrite.net ([185.25.67.249]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a9a913076f5sm396704066b.95.2024.10.22.15.40.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Oct 2024 15:40:00 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 934a1319-90c6-11ef-a0be-8be0dac302b0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.com; s=google; t=1729636801; x=1730241601; darn=lists.xenproject.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=WngS3EfMpOQgHq1eT2hKFkIIl1PwfdoEnZaYAyPIS0Y=; b=caVDELXM4yNVyesTEAxyBZrEvr80A+n5sW5OXcxsmZW3C+1iMmRa+aPPR15j0lNVcY Zn0fXPrS6PSlOcNcS05uhbyTdTqOSBzA75cAlfY2xz3JMzUFtBDz3RMmP976hEjSsPpx huXc/4wsO5YQSYYCCggkMZNPW3GckShNJrup4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729636801; x=1730241601; 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=WngS3EfMpOQgHq1eT2hKFkIIl1PwfdoEnZaYAyPIS0Y=; b=TYs4+zCjCd4ZyK12fSyyZiBgZMAQUgXxcuFoAeY6HPMBNgbYezIE3uFk2JXX0b13Ve 37S9Jhu7g5ofWatIeMa1pwwieGmYTvOm5d5RniU4WfK0WCVmZEWi4z5nKu6F4SHURHm9 xvROIcu9EZHqPPRRbs4CMtjpd8AkWQfU53u+bMe8TL6wYo6bbwapCQ+kQHzjDtAXhxcB TIvtOUTFcW3E0zBYMjog/5VelE408sV1NZaDCDooU4y1XQIIj0B+hoZXnxgJIwhCNCqY fWQQhwNzUaAkwYjgGCrkwRY6MyHcXz4RuRxZdhNfevS+eoKS9ushoC9SUaNA6tt5CqeE 829Q== X-Gm-Message-State: AOJu0Yw9fyPWSDCaVHSaDE6/ieoNRtt/kRgzFzMz9/YoIzpNLalSq5rN oKfR0sSO61PEZYsnM3g7lEvuT+rSbufpLxummAM1LngTeBTlNBwQ/pCTV2RNzP8HMK+Fi1Jy99x m X-Google-Smtp-Source: AGHT+IGYbzpAehcj4kjuhSByj7lL7Vk3fUVnYYt45ZxrfT07Vh8a70eWMMNBBW/cqUbEd6U548aJ1A== X-Received: by 2002:a17:907:2cc5:b0:a99:5f65:fd9a with SMTP id a640c23a62f3a-a9aaa620d5cmr534730466b.21.1729636801041; Tue, 22 Oct 2024 15:40:01 -0700 (PDT) From: Andrew Cooper To: Xen-devel Cc: Andrew Cooper , Jan Beulich , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , "Daniel P . Smith" Subject: [PATCH 3/3] x86/boot: Simplify size calculations in move_memory() Date: Tue, 22 Oct 2024 23:39:54 +0100 Message-Id: <20241022223954.432554-4-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20241022223954.432554-1-andrew.cooper3@citrix.com> References: <20241022223954.432554-1-andrew.cooper3@citrix.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @citrix.com) X-ZM-MESSAGEID: 1729636839704116600 While both src and dst are similar, src is mapped only accounting for src's size, while dst is mapped based on the minimum of both. This means that in some cases, an overly large mapping is requested for src. Rework the sz calcuation to be symmetric, and leave an explanation of how logic works. No functional change. Signed-off-by: Andrew Cooper Reviewed-by: Daniel P. Smith --- CC: Jan Beulich CC: Roger Pau Monn=C3=A9 CC: Daniel P. Smith And as if by magic, all transient fields from converting module_t are gone, with bloat-o-meter reporting: add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-74 (-74) Function old new delta move_memory 265 191 -74 which is all removal of logic inside the while loop. --- xen/arch/x86/setup.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/xen/arch/x86/setup.c b/xen/arch/x86/setup.c index 152cd696d6c2..bb525980cdd8 100644 --- a/xen/arch/x86/setup.c +++ b/xen/arch/x86/setup.c @@ -492,23 +492,22 @@ static void __init noinline move_memory( =20 while ( size ) { - unsigned int end /* mapsz */; unsigned int soffs =3D src & mask; unsigned int doffs =3D dst & mask; unsigned int sz; void *d, *s; =20 - end =3D soffs + size; - if ( end > blksz ) - end =3D blksz; - sz =3D end - soffs; - s =3D bootstrap_map_addr(src, src + sz); + /* + * We're copying between two arbitrary buffers, as they fall within + * 2M-aligned regions with a maximum bound of blksz. + * + * For [ds]offs + size <=3D blksz, sz =3D size. + * For [ds]offs + size > blksz, sz =3D blksz - [ds]offs. + */ + sz =3D max(soffs, doffs); + sz =3D min(sz + size, blksz) - sz; =20 - end =3D doffs + size; - if ( end > blksz ) - end =3D blksz; - if ( sz > end - doffs ) - sz =3D end - doffs; + s =3D bootstrap_map_addr(src, src + sz); d =3D bootstrap_map_addr(dst, dst + sz); =20 memmove(d, s, sz); --=20 2.39.5