From nobody Wed Dec 17 08:56:32 2025 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=quarantine dis=none) header.from=kernel.org ARC-Seal: i=1; a=rsa-sha256; t=1742353419; cv=none; d=zohomail.com; s=zohoarc; b=X2/5KH1zjXfoYA63gS0RFKnB58GMymDqqY3bf+7Odl0veuODDthZU2nex4O9PA+XqhyIORMs/AfdFp43SHor9w2WV+ZAeBRmALoTJ65uTbw4nRrfWytpe92AAlYdHem00oWdTUK0Z5SoVNB0TrjYN0lG+lhj7mQOgc7fAKfuCIQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1742353419; h=Content-Type:Cc:Cc:Date:Date:From:From:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=t9C3oPfevfJdqD3c0VKk6LJp8G8Vc8fl7G4Flx29O+k=; b=FrVoKw0nkNZgpZCHyi8Qf5nYPRF5H/YHjnvv6CaZZ/yKN1skhCGVZt6Si+nFEtJz4M5jPwNfLE6kuifT/8VxgdrfLZ78MXy3oi83MUSo4YsBedXY+Ua//gQeGKofvTwTlYJ5ZUN/RW784CeGyN/0n3zaAKeykoQE+u6n+DZa+eE= 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=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 17423534191131008.9445986623681; Tue, 18 Mar 2025 20:03:39 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.920032.1324326 (Exim 4.92) (envelope-from ) id 1tuji1-0006RZ-EA; Wed, 19 Mar 2025 03:03:09 +0000 Received: by outflank-mailman (output) from mailman id 920032.1324326; Wed, 19 Mar 2025 03:03:09 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tuji1-0006RR-8c; Wed, 19 Mar 2025 03:03:09 +0000 Received: by outflank-mailman (input) for mailman id 920032; Wed, 19 Mar 2025 03:03:07 +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 1tujhz-0006RL-KQ for xen-devel@lists.xenproject.org; Wed, 19 Mar 2025 03:03:07 +0000 Received: from dfw.source.kernel.org (dfw.source.kernel.org [2604:1380:4641:c500::1]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id ad1ab199-046e-11f0-9abc-95dc52dad729; Wed, 19 Mar 2025 04:03:05 +0100 (CET) Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id CB8455C59DF; Wed, 19 Mar 2025 03:00:46 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2280DC4CEDD; Wed, 19 Mar 2025 03:03:01 +0000 (UTC) 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: ad1ab199-046e-11f0-9abc-95dc52dad729 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1742353383; bh=yDB6nuHNy9qBbv0m+m/Z+LEHLUc/+2/863la7Ks+h6g=; h=Date:From:To:cc:Subject:From; b=sEoZnpahNOQBHxa9HZV2W4G/1lO9niWC3SvfB3o0S+kGImUAnw+qvOK/ti37F1pGn sSxHQ/GHGuZzrKm7kxcXvWkdyeATmKXCgXhx1mo8Od7bjegB8HvdoHE+z+J9EZ55xq +ZbtLkI5T6HxvcUaGX5nZdXVVnIdRzQVnd7hp6ALLEEP8MgZf4ejxXiW4/cShNNSYZ f8fXTC9EQeMA4uxGdEyfEPfv1OQXSAGId4MHxZVGoowQfuMDpKGCvGpSSVo3DiFSAz cN9Kbu16GKGeTvMqBn3Ht8PxI4rzae/YnkIVKvCcYTpMla7qcB/p/T1F23N71QmtR2 L/Jr+5VFBf0Dw== Date: Tue, 18 Mar 2025 20:03:00 -0700 (PDT) From: Stefano Stabellini X-X-Sender: sstabellini@ubuntu-linux-20-04-desktop To: xen-devel@lists.xenproject.org cc: sstabellini@kernel.org, andrew.cooper3@citrix.com, michal.orzel@amd.com, jbeulich@suse.com, julien@xen.org, roger.pau@citrix.com, bertrand.marquis@arm.com Subject: [PATCH] xen: simplify bitmap_to_xenctl_bitmap for little endian Message-ID: User-Agent: Alpine 2.22 (DEB 394 2020-01-19) MIME-Version: 1.0 X-ZohoMail-DKIM: pass (identity @kernel.org) X-ZM-MESSAGEID: 1742353421024019000 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The little endian implementation of bitmap_to_xenctl_bitmap leads to unnecessary xmallocs and xfrees. Given that Xen only supports little endian architectures, it is worth optimizing. This patch removes the need for the xmalloc on little endian architectures. Signed-off-by: Stefano Stabellini diff --git a/xen/common/bitmap.c b/xen/common/bitmap.c index 3da63a32a6..38d77fc876 100644 --- a/xen/common/bitmap.c +++ b/xen/common/bitmap.c @@ -384,21 +384,26 @@ int bitmap_to_xenctl_bitmap(struct xenctl_bitmap *xen= ctl_bitmap, uint8_t zero =3D 0; int err =3D 0; unsigned int xen_bytes =3D DIV_ROUND_UP(nbits, BITS_PER_BYTE); - uint8_t *bytemap =3D xmalloc_array(uint8_t, xen_bytes); - - if ( !bytemap ) - return -ENOMEM; + uint8_t *bytemap =3D (uint8_t *)bitmap; =20 guest_bytes =3D DIV_ROUND_UP(xenctl_bitmap->nr_bits, BITS_PER_BYTE); copy_bytes =3D min(guest_bytes, xen_bytes); =20 - bitmap_long_to_byte(bytemap, bitmap, nbits); + if ( IS_ENABLED(__BIG_ENDIAN) ) + { + bytemap =3D xmalloc_array(uint8_t, xen_bytes); + if ( !bytemap ) + return -ENOMEM; + + bitmap_long_to_byte(bytemap, bitmap, nbits); + } =20 if ( copy_bytes && copy_to_guest(xenctl_bitmap->bitmap, bytemap, copy_bytes) ) err =3D -EFAULT; =20 - xfree(bytemap); + if ( IS_ENABLED(__BIG_ENDIAN) ) + xfree(bytemap); =20 for ( i =3D copy_bytes; !err && i < guest_bytes; i++ ) if ( copy_to_guest_offset(xenctl_bitmap->bitmap, i, &zero, 1) )