From nobody Fri Nov 22 08:07:57 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=1718814681; cv=none; d=zohomail.com; s=zohoarc; b=keI/TDbqen1mHxDHk5j4KypaQvlr9PAaglctbEmBcpIP6VU2HmR/3fJ8xFgI39MOWoDzrzptG+xY2Bvv5prKP8iipz17V5RjBBcbpPJuJImPLjezhrY+KL31m5hYUrzJjfrhYsxhAZAllRdgybD7tBTl8uO4+m/hGJ6e/qTYM7c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1718814681; h=Content-Type:Content-Transfer-Encoding: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=eNRqIMjqDxOHB6YZkGrW+54h7mw46IrFeNy59xj3dpo=; b=W8aZ9K9CR6NKr/CpTlQUN8CEGOCbVxYkPqFX3/uq4a2iLFNvUFJluDaRxJL7vLSgbaDfn3L5qdPiuRo87//PTGcM2VP+sUUApDhG0kmZh1vX03k7im3Njn5b8iJekXfJoddWllDpwJLK5PonKMZIPfcElQJPx3fzz6TeNc7JSs8= 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 1718814681281642.1819793305882; Wed, 19 Jun 2024 09:31:21 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.743931.1150932 (Exim 4.92) (envelope-from ) id 1sJyDB-0007J9-3L; Wed, 19 Jun 2024 16:31:05 +0000 Received: by outflank-mailman (output) from mailman id 743931.1150932; Wed, 19 Jun 2024 16:31:05 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1sJyDB-0007J2-0p; Wed, 19 Jun 2024 16:31:05 +0000 Received: by outflank-mailman (input) for mailman id 743931; Wed, 19 Jun 2024 16:31:03 +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 1sJyD9-0007IR-Uk for xen-devel@lists.xenproject.org; Wed, 19 Jun 2024 16:31:03 +0000 Received: from mail-ed1-x535.google.com (mail-ed1-x535.google.com [2a00:1450:4864:20::535]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 51b6ff07-2e59-11ef-90a3-e314d9c70b13; Wed, 19 Jun 2024 18:31:03 +0200 (CEST) Received: by mail-ed1-x535.google.com with SMTP id 4fb4d7f45d1cf-57d1782679fso786922a12.0 for ; Wed, 19 Jun 2024 09:31:03 -0700 (PDT) Received: from andrewcoop.eng.citrite.net ([160.101.139.1]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-57cb72cdfc4sm8468996a12.19.2024.06.19.09.31.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Jun 2024 09:31:01 -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: 51b6ff07-2e59-11ef-90a3-e314d9c70b13 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.com; s=google; t=1718814662; x=1719419462; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=eNRqIMjqDxOHB6YZkGrW+54h7mw46IrFeNy59xj3dpo=; b=M7hKZOBO7JcfPJIh6JIVbbNZT/XHlGxZGqEhjsY5Y05NfiN/bP0su80St5wX0ZgSGJ +UEFuh0vKLs3KC+jzMKxiQsrQY4q/1Dk9k1JoEM64LGxB9Stg2BmLp9an9834WDesQu5 mXncwU7Lv05qo/RzaL4v6qrk3ra1b8ec5CSYI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718814662; x=1719419462; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=eNRqIMjqDxOHB6YZkGrW+54h7mw46IrFeNy59xj3dpo=; b=rYCWVAOVSgoEciYXX5g1H8ce4YdXO+Jl02V+x/khjb/sUAQpRDkkyiypXQP3scWUs3 N8GNLUR6qBQWDlakp9i+e3uIaa3aPfaHeMnfJFdXzJ5vBk93LH3ypqvAddn/ygo2k4mb +iJgrRCvqyD5WvYvP0NtUQYI95dfD6jGMKPqaTTUGElh3cbkCyUlHc4CFMA6isNaV2e2 V7dPRr1rMbXF4BWMfUVj4PRgkPBTZrr+0Bh44TxmUdEr0vqXCVMJPpWXhXOIkqtXlhAg v9g8VaDErx2+O3YF4K7qq7GZQ27izZS1V/UMz4jSbo12Sc8tX8+C7f8+Cx5PAX1S91iI OyLQ== X-Gm-Message-State: AOJu0YyDxy3FqXIlbUGZ35KjiwgCR1mPS9BlMy7O3afIEaJGLnoDRV/u R5xXfIPf1HHn2RSf51qU1gXLKifIE9Ngv3rhY+PDr7htHnkbPzKvhjCuR2siqeRSZYLZ0FzmQI4 I+TM= X-Google-Smtp-Source: AGHT+IEgA4/HyMhc+2wKZZn6cXI1BIGalLsPk0Gby+OcIz04oDGrUjOq1SQIC2Hlmrzn0Usi6pTxeg== X-Received: by 2002:a50:d50a:0:b0:57c:628d:f0eb with SMTP id 4fb4d7f45d1cf-57d07e6f85emr1809324a12.24.1718814661884; Wed, 19 Jun 2024 09:31:01 -0700 (PDT) From: Andrew Cooper To: Xen-devel Cc: Andrew Cooper , George Dunlap , Jan Beulich , Stefano Stabellini , Julien Grall , Oleksii Kurochko Subject: [PATCH] xen/guest_access: Fix accessors for 32bit builds of Xen Date: Wed, 19 Jun 2024 17:31:00 +0100 Message-Id: <20240619163100.2556555-1-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.39.2 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: 1718814683146100001 Gitlab CI reports an ARM32 randconfig failure as follows: In file included from common/livepatch.c:9: common/livepatch.c: In function =E2=80=98livepatch_list=E2=80=99: ./include/xen/guest_access.h:130:25: error: cast to pointer from integer = of different size [-Werror=3Dint-to-pointer-cast] 130 | __raw_copy_to_guest((void *)(d_ + (off) * sizeof(*_s)), \ | ^ common/livepatch.c:1283:18: note: in expansion of macro =E2=80=98__copy_t= o_guest_offset=E2=80=99 1283 | if ( __copy_to_guest_offset(list->name, name_offset, | ^~~~~~~~~~~~~~~~~~~~~~ ./include/xen/guest_access.h:130:25: error: cast to pointer from integer = of different size [-Werror=3Dint-to-pointer-cast] 130 | __raw_copy_to_guest((void *)(d_ + (off) * sizeof(*_s)), \ | ^ common/livepatch.c:1287:17: note: in expansion of macro =E2=80=98__copy_t= o_guest_offset=E2=80=99 1287 | __copy_to_guest_offset(list->metadata, metadata_o= ffset, | ^~~~~~~~~~~~~~~~~~~~~~ This isn't specific to ARM32; it's LIVEPATCH on any 32bit build of Xen. Both name_offset and metadata_offset are uint64_t, meaning that the expression: (d_ + (off) * sizeof(*(hnd).p) gets promoted to uint64_t, and is too wide to cast back to a pointer in 32b= it builds. The expression needs casting through (unsigned long) before it can= be cast to (void *). Xen has the _p() wrapper to do precisely this. No functional change. Link: https://gitlab.com/xen-project/xen/-/jobs/7136417308 Fixes: 43d5c5d5f70b ("xen: avoid UB in guest handle arithmetic") Signed-off-by: Andrew Cooper --- CC: George Dunlap CC: Jan Beulich CC: Stefano Stabellini CC: Julien Grall CC: Oleksii Kurochko For 4.19, as this was found by CI. --- xen/include/xen/guest_access.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/xen/include/xen/guest_access.h b/xen/include/xen/guest_access.h index 96dbef2e0251..969813762c25 100644 --- a/xen/include/xen/guest_access.h +++ b/xen/include/xen/guest_access.h @@ -65,7 +65,7 @@ /* Check that the handle is not for a const type */ \ void *__maybe_unused _t =3D (hnd).p; \ (void)((hnd).p =3D=3D _s); \ - raw_copy_to_guest((void *)(d_ + (off) * sizeof(*_s)), \ + raw_copy_to_guest(_p(d_ + (off) * sizeof(*_s)), \ _s, (nr) * sizeof(*_s)); \ }) =20 @@ -75,7 +75,7 @@ */ #define clear_guest_offset(hnd, off, nr) ({ \ unsigned long d_ =3D (unsigned long)(hnd).p; \ - raw_clear_guest((void *)(d_ + (off) * sizeof(*(hnd).p)), \ + raw_clear_guest(_p(d_ + (off) * sizeof(*(hnd).p)), \ (nr) * sizeof(*(hnd).p)); \ }) =20 @@ -87,7 +87,7 @@ unsigned long s_ =3D (unsigned long)(hnd).p; \ typeof(*(ptr)) *_d =3D (ptr); \ raw_copy_from_guest(_d, \ - (const void *)(s_ + (off) * sizeof(*_d)), \ + _p(s_ + (off) * sizeof(*_d)), \ (nr) * sizeof(*_d)); \ }) =20 @@ -127,13 +127,13 @@ /* Check that the handle is not for a const type */ \ void *__maybe_unused _t =3D (hnd).p; \ (void)((hnd).p =3D=3D _s); \ - __raw_copy_to_guest((void *)(d_ + (off) * sizeof(*_s)), \ + __raw_copy_to_guest(_p(d_ + (off) * sizeof(*_s)), \ _s, (nr) * sizeof(*_s)); \ }) =20 #define __clear_guest_offset(hnd, off, nr) ({ \ unsigned long d_ =3D (unsigned long)(hnd).p; \ - __raw_clear_guest((void *)(d_ + (off) * sizeof(*(hnd).p)), \ + __raw_clear_guest(_p(d_ + (off) * sizeof(*(hnd).p)), \ (nr) * sizeof(*(hnd).p)); \ }) =20 @@ -141,7 +141,7 @@ unsigned long s_ =3D (unsigned long)(hnd).p; \ typeof(*(ptr)) *_d =3D (ptr); \ __raw_copy_from_guest(_d, \ - (const void *)(s_ + (off) * sizeof(*_d)), \ + _p(s_ + (off) * sizeof(*_d)), \ (nr) * sizeof(*_d)); \ }) =20 base-commit: 43d5c5d5f70b3f5419e7ef30399d23adf6ddfa8e --=20 2.39.2