From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by sourceware.org (Postfix) with ESMTPS id C2F0C3894C0B for ; Tue, 20 Jun 2023 07:50:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C2F0C3894C0B Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1687247406; x=1718783406; h=from:to:cc:subject:date:message-id:references: in-reply-to:content-transfer-encoding:mime-version; bh=v29ltjb90+0kCLsl3cJys/tIESpoTYxz/YOuLxbIKCw=; b=e+bBFMYm1FyTyab87GHqirh0hZzIM37CVJShuYsntfKYhj4Rd4FJVFEp RPGIQWsgYldDxqefvF9B9/PW85oz9o4LY+LJo4sS6hI0yX69edRLt7BTc bVseWlPWinVwyW8DZ5nJ8uI5GsuQDuEu3ZHwE4C/1z91fO0/uXzjYp1SO 36/4oyOE33/IhFZV/eZrZuYzZE468auNoOif1bJhQCgrBycAFwHwgXZAW t78O8UnTUz6lfMOMBKF774KJxPkPGBQTXPGmhAr87ZB8Yi47TWw3n63q8 YVvFf0wHPOpSwu1kh6uy+ukNRTsz4tYd1hfHD1BY4MVxdI/BQUJYAlZUM w==; X-IronPort-AV: E=McAfee;i="6600,9927,10746"; a="340134782" X-IronPort-AV: E=Sophos;i="6.00,256,1681196400"; d="scan'208";a="340134782" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Jun 2023 00:50:05 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10746"; a="713943990" X-IronPort-AV: E=Sophos;i="6.00,256,1681196400"; d="scan'208";a="713943990" Received: from fmsmsx601.amr.corp.intel.com ([10.18.126.81]) by orsmga002.jf.intel.com with ESMTP; 20 Jun 2023 00:50:05 -0700 Received: from fmsmsx612.amr.corp.intel.com (10.18.126.92) by fmsmsx601.amr.corp.intel.com (10.18.126.81) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.23; Tue, 20 Jun 2023 00:50:04 -0700 Received: from fmsmsx610.amr.corp.intel.com (10.18.126.90) by fmsmsx612.amr.corp.intel.com (10.18.126.92) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.23; Tue, 20 Jun 2023 00:50:04 -0700 Received: from fmsedg601.ED.cps.intel.com (10.1.192.135) by fmsmsx610.amr.corp.intel.com (10.18.126.90) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.23 via Frontend Transport; Tue, 20 Jun 2023 00:50:04 -0700 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (104.47.58.101) by edgegateway.intel.com (192.55.55.70) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.23; Tue, 20 Jun 2023 00:50:01 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=gNIekIMaLA2HyGp7oxV7RUsdM6g2GsK7OWm9bvzSsDfE0Pe/Bxyl/C2vjUJHDGAZaNW1dhC7APUcmGPncxpWNqvLeMG0WrnT7LXJ1T5jRC3EpnhlvKaKG1TS/1E9gCgTyAS+XlnO1nlldvciIENCstc0d0KJYqng1PMc+NoznLIiMvr9PiVYArgVdEy9/PzEm8d20sfnRcoJI8PNCu19+4xEOHuHPEMw+6D9fXvdakC5OhEVBYKftdRyJ9M1kTZEpjAom2CUBW/O/Tn8eS/kmTLhQgc4IAfeDjI5kSJuxp1zobIdfEcSD76ljSdT0p+5iWwMWe2kbrOcOvugcARRzA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=Ou/enCvmktT8gub5HKrcrJv/My8SkMqmL58Tio7QXAM=; b=SYNwBTxG8iT5FumMPt+tEN9vgoSv7OVYtz91+YK/h9Elltj4WF8UZZBVpZqNmN0wMmWawox0rqPUHWIWgo6ij3I387xmVTEG/KBaaAWO37mo7D/KlgQ5n62gX2QrEG5f2gQLApIYfFuiEzr5Lk4HhB1bFjg6UXPzEvX/mgDFtdY+ySqGYQeJAp+9vxfss/ho/iFku5r2ogXHlXa9TDF4PH3kzuaNHQu7DmunLQkqJph5wsZFo8XoRc79o9UmEJw9kdfB0+li4TM+LoFx6v94IRtDQbVU9MVG+gC7ozQExxsssKiUbQoGea18J5kE8/BCS/WJjnoZVU4wWGqfJs77aw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com; dkim=pass header.d=intel.com; arc=none Received: from MW5PR11MB5908.namprd11.prod.outlook.com (2603:10b6:303:194::10) by MW6PR11MB8309.namprd11.prod.outlook.com (2603:10b6:303:24c::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6455.32; Tue, 20 Jun 2023 07:50:00 +0000 Received: from MW5PR11MB5908.namprd11.prod.outlook.com ([fe80::127c:f4cc:e699:8f73]) by MW5PR11MB5908.namprd11.prod.outlook.com ([fe80::127c:f4cc:e699:8f73%6]) with mapi id 15.20.6500.036; Tue, 20 Jun 2023 07:50:00 +0000 From: "Li, Pan2" To: Jakub Jelinek CC: "gcc-patches@gcc.gnu.org" , "juzhe.zhong@rivai.ai" , "rdapp.gcc@gmail.com" , "jeffreyalaw@gmail.com" , "Wang, Yanzhang" , "kito.cheng@gmail.com" , "rguenther@suse.de" Subject: RE: [PATCH] RISC-V: Fix out of range memory access of machine mode table Thread-Topic: [PATCH] RISC-V: Fix out of range memory access of machine mode table Thread-Index: AQHZoo1G5H0Lv2r9XkuUWLbdvLdQGK+R2HQAgABIDhCAARQ0EA== Date: Tue, 20 Jun 2023 07:50:00 +0000 Message-ID: References: <20230619080710.1536456-1-pan2.li@intel.com> <20230619090548.1574008-1-pan2.li@intel.com> In-Reply-To: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=intel.com; x-ms-publictraffictype: Email x-ms-traffictypediagnostic: MW5PR11MB5908:EE_|MW6PR11MB8309:EE_ x-ms-office365-filtering-correlation-id: 8f98f765-5e09-4757-55d2-08db7162f30f x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: ZoJabcvV32m3mPYVHbi8QIEJB5R1x9jclFjZdXq9JqIPEuGA+b9e3ieEwSxhRfSDv+B9gQmfifxYFwzxoRqJhGpk+QWsSVRecuEvHeFy64SHFE3Vp4ci+GM5gVUbkKlNLrPquYAGgopZaYbjfo7VhSVHQCTZp+9h5siGMaxWx9KeA0s9Y4fzyOrcY3WlvJTZAxQYsknVmO7H67KEU6yW1Lp1B/aIttB563iHkGYfVDxOKiy0teROpU0QLKw+o8xwiirQp6YnOyhAOLVeS43t9uv+SXc0thtC9/kpX5gqqK6kDNmMa4Nx+NyF6lRRC/toY/0cPwv6Ys8b6t7Z1b5dZxP5GPkTz8j7+kmueqVqFPv2eTJWCchl0Y+CazEzbBJf20rpXsW6theaXM6LYHbG+96f7AHF8Q5Xb/t5GhPEpH05zBLEXkmr3H/1I5mH/xTLKVkTKOBYBiTXxKkIb8G74lDxp/5KdAYDrap8cD+7BKTs+5zwuk1GwyQeIEA83iyLx6SNIAYjT7TvAl/TcsmsxH6jThh3zeQ25XGqEHSyXhr+PR2sBDMdhlv4CxT7OFk7KAhu+YwC1bNq9tXhDVDjW/CSPQshmO32uderM2CmCJn1nfScaLxXn7G1BqGXdwsp x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:MW5PR11MB5908.namprd11.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(39860400002)(136003)(376002)(396003)(346002)(366004)(451199021)(6506007)(478600001)(26005)(53546011)(186003)(71200400001)(55016003)(7696005)(9686003)(2906002)(316002)(41300700001)(33656002)(38070700005)(86362001)(52536014)(122000001)(8676002)(82960400001)(5660300002)(38100700002)(83380400001)(66476007)(8936002)(54906003)(76116006)(66556008)(66446008)(4326008)(66946007)(6916009)(64756008);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?n8Z9LY+KHNdUkRlW1glWYgRtVh+BEEs9A1BRohykaxyhLfcdLnmJQ0c+W7Sk?= =?us-ascii?Q?XEINJGGFidf9PFMOMVtO+xotbBXpoh6WAR/v5eiESq5za349ltyvYkKh5P3L?= =?us-ascii?Q?MnKRPGMS6Kc01IGsPYomRqHef+qwCuHJdiii8gs2Oh92c95HnO6tRzidT4Cd?= =?us-ascii?Q?NUC8qhRpkD65Dm+9twLejzqWUlMTriWi+YP9mjkiZcK2pL4xaqXZK/ESjT4O?= =?us-ascii?Q?fbOsQZCHm/8vTKxP9HZLluGMT0BzttqXtOSnsYAvzVlnXIOkSG2c6eiVFARP?= =?us-ascii?Q?PtGWVnJ8seK3FaJjXN1aAdfrKGPGD1ThCYGunF5S+2OQy35zFmtctGDsZL9w?= =?us-ascii?Q?bJjp+ZESKS2OMaOXFgfVi8zBiSFLwFboKY1Za/5Sxzq+a5/OqNa5ODKR1lVv?= =?us-ascii?Q?XPg/EZT/BLCwrYtYLXWxdl/6UTMKGGm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pMJZgAjsGUwtIMeWQlISeSqKe4J+YxutLsbMl4cTiJJXYcus6aDDFf/q?= =?us-ascii?Q?16u6Grl76nVwmftYFx5PDGPNuNlDFOvfDZ2hKjaglM8AhDWWf3G65Yt+5JPV?= =?us-ascii?Q?KdJBOLMBRyUCPN6Pa6BC1nZRtvQ/9OIeNxRofXFc2hZrrDttG6I3H8OxhpjD?= =?us-ascii?Q?zh2wZRu6v2m7Ry9EkAWZKDdGOFXbqfUlGrHjNdD7LBm0R2BLSJLk+lur9J0M?= =?us-ascii?Q?utpwtj/2WytyDfNpcux1ZO0/ZM0dkRil8mglaMVD?= Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: MW5PR11MB5908.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8f98f765-5e09-4757-55d2-08db7162f30f X-MS-Exchange-CrossTenant-originalarrivaltime: 20 Jun 2023 07:50:00.1576 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 46c98d88-e344-4ed4-8496-4ed7712e255d X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: 2i2WznDOwzdbRhQf2mnQixrO7fwO3InaLi4dtgEjD50+k9Xv2Pb5sFR9Up7UDkwax1mAHFCFNN40i2plq53ZRQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW6PR11MB8309 X-OriginatorOrg: intel.com X-Spam-Status: No, score=-6.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_NONE,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Hi Jakub, Thanks for reviewing but I am not quite sure if I fully understand how to f= ix this issue. Could you please help to enlighten me more about this ? Currently for RISC-V, the memset has touched out of range memory already du= e to MAX_MACHINE_MODE > 256. And we may have below parts require adjusting. 1. streamer_mode_table. 2. bp_unpack_machine_mode/bp_pack_machine_mode=20 3. bp_pack_value/bp_unpack_value in lto_write_mode_table. 4. unsigned char *table =3D ggc_cleared_vec_alloc (1 << 8) i= n lto_input_mode_table. For 1. is safe to extend the size to MAX_MACHINE_MODE as the array only use= d as Boolean, aka streamer_mode_table[XXXmode] =3D 1. For 2 & 3. Keep 1 << 8 as is, or stream out the host MAX_MACHINE_MODE value= somewhere for underlying consuming? For 4, one possible approach is that extend unsigned char to unsigned short= , as well as 256 to MAX_MACHINE_MODE. Because it stores the actually machin= e mode in array. Pan -----Original Message----- From: Li, Pan2=20 Sent: Monday, June 19, 2023 9:36 PM To: Jakub Jelinek Cc: gcc-patches@gcc.gnu.org; juzhe.zhong@rivai.ai; rdapp.gcc@gmail.com; jef= freyalaw@gmail.com; Wang, Yanzhang ; kito.cheng@gm= ail.com; rguenther@suse.de Subject: RE: [PATCH] RISC-V: Fix out of range memory access of machine mode= table Thanks Jakub for reviewing, sorry for misleading and will have a try for PA= TCH v3. Pan -----Original Message----- From: Jakub Jelinek =20 Sent: Monday, June 19, 2023 5:17 PM To: Li, Pan2 Cc: gcc-patches@gcc.gnu.org; juzhe.zhong@rivai.ai; rdapp.gcc@gmail.com; jef= freyalaw@gmail.com; Wang, Yanzhang ; kito.cheng@gm= ail.com; rguenther@suse.de Subject: Re: [PATCH] RISC-V: Fix out of range memory access of machine mode= table On Mon, Jun 19, 2023 at 05:05:48PM +0800, pan2.li@intel.com wrote: > --- a/gcc/lto-streamer-in.cc > +++ b/gcc/lto-streamer-in.cc > @@ -1985,7 +1985,8 @@ lto_input_mode_table (struct lto_file_decl_data *fi= le_data) > internal_error ("cannot read LTO mode table from %s", > file_data->file_name); > =20 > - unsigned char *table =3D ggc_cleared_vec_alloc (1 << 8)= ; > + unsigned char *table =3D ggc_cleared_vec_alloc ( > + MAX_MACHINE_MODE); Incorrect formatting. And, see my other mail, this is wrong. > @@ -108,7 +108,7 @@ inline void > bp_pack_machine_mode (struct bitpack_d *bp, machine_mode mode) > { > streamer_mode_table[mode] =3D 1; > - bp_pack_enum (bp, machine_mode, 1 << 8, mode); > + bp_pack_enum (bp, machine_mode, MAX_MACHINE_MODE, mode); > } > =20 > inline machine_mode > @@ -116,7 +116,8 @@ bp_unpack_machine_mode (struct bitpack_d *bp) > { > return (machine_mode) > ((class lto_input_block *) > - bp->stream)->mode_table[bp_unpack_enum (bp, machine_mode, 1 << 8)]; > + bp->stream)->mode_table[bp_unpack_enum (bp, machine_mode, > + MAX_MACHINE_MODE)]; > } And these two are wrong as well. The value passed to bp_pack_enum has to match the one used on bp_unpack_enum. But that is not the case after your changes. You stream out with the host MAX_MACHINE_MODE, and stream in for normal LTO with the same value (ok), but for offloading targets (nvptx, amdgcn) with a different MAX_MACHINE_MODE. That will immediate result in LTO streaming being out of sync and ICEs all around. The reason for using 1 << 8 there was exactly to make it interoperable for offloading. What could be perhaps done is that you stream out the host MAX_MACHINE_MODE value somewhere and stream it in inside of lto_input_mode_table before you allocate the table. But, that streamed in host max_machine_mdoe has to be remembered somewhere and used e.g. in bp_unpack_machine_mode instead of MAX_MACHINE_MODE. Jakub