From: "Li, Pan2" <pan2.li@intel.com>
To: Jakub Jelinek <jakub@redhat.com>
Cc: "gcc-patches@gcc.gnu.org" <gcc-patches@gcc.gnu.org>,
"juzhe.zhong@rivai.ai" <juzhe.zhong@rivai.ai>,
"rdapp.gcc@gmail.com" <rdapp.gcc@gmail.com>,
"jeffreyalaw@gmail.com" <jeffreyalaw@gmail.com>,
"Wang, Yanzhang" <yanzhang.wang@intel.com>,
"kito.cheng@gmail.com" <kito.cheng@gmail.com>,
"rguenther@suse.de" <rguenther@suse.de>
Subject: RE: [PATCH] RISC-V: Fix out of range memory access of machine mode table
Date: Tue, 20 Jun 2023 07:50:00 +0000 [thread overview]
Message-ID: <MW5PR11MB5908BA7C575798400DFEEB13A95CA@MW5PR11MB5908.namprd11.prod.outlook.com> (raw)
In-Reply-To: <MW5PR11MB5908030BA3A188CDF9E308FBA95FA@MW5PR11MB5908.namprd11.prod.outlook.com>
Hi Jakub,
Thanks for reviewing but I am not quite sure if I fully understand how to fix 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 due 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
3. bp_pack_value/bp_unpack_value in lto_write_mode_table.
4. unsigned char *table = ggc_cleared_vec_alloc<unsigned char> (1 << 8) in lto_input_mode_table.
For 1. is safe to extend the size to MAX_MACHINE_MODE as the array only used as Boolean, aka streamer_mode_table[XXXmode] = 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 machine mode in array.
Pan
-----Original Message-----
From: Li, Pan2
Sent: Monday, June 19, 2023 9:36 PM
To: Jakub Jelinek <jakub@redhat.com>
Cc: gcc-patches@gcc.gnu.org; juzhe.zhong@rivai.ai; rdapp.gcc@gmail.com; jeffreyalaw@gmail.com; Wang, Yanzhang <yanzhang.wang@intel.com>; kito.cheng@gmail.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 PATCH v3.
Pan
-----Original Message-----
From: Jakub Jelinek <jakub@redhat.com>
Sent: Monday, June 19, 2023 5:17 PM
To: Li, Pan2 <pan2.li@intel.com>
Cc: gcc-patches@gcc.gnu.org; juzhe.zhong@rivai.ai; rdapp.gcc@gmail.com; jeffreyalaw@gmail.com; Wang, Yanzhang <yanzhang.wang@intel.com>; kito.cheng@gmail.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 *file_data)
> internal_error ("cannot read LTO mode table from %s",
> file_data->file_name);
>
> - unsigned char *table = ggc_cleared_vec_alloc<unsigned char> (1 << 8);
> + unsigned char *table = ggc_cleared_vec_alloc<unsigned char> (
> + 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] = 1;
> - bp_pack_enum (bp, machine_mode, 1 << 8, mode);
> + bp_pack_enum (bp, machine_mode, MAX_MACHINE_MODE, mode);
> }
>
> 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
next prev parent reply other threads:[~2023-06-20 7:50 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-06-19 8:07 [PATCH v1] RISC-V: Fix out of range memory access when lto mode init pan2.li
2023-06-19 8:16 ` Li, Pan2
2023-06-19 8:40 ` Richard Biener
2023-06-19 9:08 ` Li, Pan2
2023-06-19 9:10 ` Jakub Jelinek
2023-06-19 9:05 ` [PATCH] RISC-V: Fix out of range memory access of machine mode table pan2.li
2023-06-19 9:15 ` Richard Biener
2023-06-19 9:16 ` Jakub Jelinek
2023-06-19 13:35 ` Li, Pan2
2023-06-20 7:50 ` Li, Pan2 [this message]
2023-06-20 8:03 ` Jakub Jelinek
2023-06-20 14:08 ` Li, Pan2
2023-06-20 15:25 ` Jakub Jelinek
2023-06-21 6:59 ` Li, Pan2
2023-06-21 7:16 ` Jakub Jelinek
2023-06-21 7:23 ` Li, Pan2
2023-06-22 0:19 ` Li, Pan2
2023-06-28 18:37 ` Jeff Law
2023-06-21 7:58 ` [PATCH v3] Streamer: Fix out of range memory access of machine mode pan2.li
2023-06-22 15:26 ` Li, Pan2
2023-06-29 9:29 ` Thomas Schwinge
2023-06-29 9:33 ` juzhe.zhong
2023-06-29 9:47 ` Thomas Schwinge
2023-06-29 9:52 ` juzhe.zhong
2023-06-29 20:14 ` Thomas Schwinge
2023-06-30 1:26 ` juzhe.zhong
2023-06-30 1:39 ` Li, Pan2
2023-06-30 8:50 ` [v4] " Thomas Schwinge
2023-06-30 11:44 ` Li, Pan2
2023-07-04 11:26 ` Richard Biener
2023-07-04 12:40 ` Li, Pan2
2023-06-30 8:23 ` LTO: Capture 'lto_file_decl_data *file_data' in 'class lto_input_block' (was: [PATCH v3] Streamer: Fix out of range memory access of machine mode) Thomas Schwinge
2023-06-30 8:39 ` Richard Biener
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=MW5PR11MB5908BA7C575798400DFEEB13A95CA@MW5PR11MB5908.namprd11.prod.outlook.com \
--to=pan2.li@intel.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=jakub@redhat.com \
--cc=jeffreyalaw@gmail.com \
--cc=juzhe.zhong@rivai.ai \
--cc=kito.cheng@gmail.com \
--cc=rdapp.gcc@gmail.com \
--cc=rguenther@suse.de \
--cc=yanzhang.wang@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).