From patchwork Wed Nov 22 23:31:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Charlie Jenkins X-Patchwork-Id: 168632 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:6358:6f03:b0:164:83eb:24d7 with SMTP id r3csp1574582rwn; Wed, 22 Nov 2023 15:40:12 -0800 (PST) X-Google-Smtp-Source: AGHT+IGsH3JTkcowVtXeRyYC3w/xmGHoO83C/5NxEqFqqwSd3y6a3CPI46e1iE3tB9lUsjiDUGtJ X-Received: by 2002:a17:903:22cc:b0:1cf:5c99:75f8 with SMTP id y12-20020a17090322cc00b001cf5c9975f8mr4868127plg.65.1700696412086; Wed, 22 Nov 2023 15:40:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700696412; cv=none; d=google.com; s=arc-20160816; b=QE5kKpUoPPPOPXPJkXKf5R66fY6Ch3HlUkN2/ouzZc77IDl6nbrtn5ZK1jX4/W8ueA VzicTlvojdRS/Mgz1Qj1rH4dgh04cQiE/potApbGqLolHBcg2l3tLCkMU7UtobggBnYV R94nuj6+h+dX190J5uL8GBW5PE+cp06JlEvPZGsQ9nm+0EDnBN6Z3gvIQ6L/aJRAxaOu SAwVhd+f32cQDoYssRazK46qgl68yKtKFmd6x+ANEMXDT0N5qVEeBALvwPAAAgtJ0wqp PE54A3a1KOZ5z+C5C17hcjBNyO1Sov5b6GbimvlWz4R2cOTxheFl0MghAnb6OA8ZggPu qVtA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:in-reply-to:references:message-id :content-transfer-encoding:mime-version:subject:date:from :dkim-signature; bh=gC0EagfiP/+NcPX4p9Q3wRm4GjW6UI0uxIwHz/Ubo2M=; fh=EP5ONyipI0seBpYMvRCri1chfPMqLdQYI4ZkdC1FhcA=; b=DYUhWqfliYxcrHECxVKU+2c60AiYrhe+KpKb728ZRBdcsd2XwghhU8ic2EjemT3wY0 kUexAufwm8nq1V8oSZjmc5MeOvhk0lBqeVyyp9P4x/UjDx0peeYHaRhpCELp4Ar7tJeO 0lxBKrz0Goqll5QHJEwYvxdkZPde161PREZ1WWZk5Vr4Ex3g4A8RJb59lWKLmuuD9EoU wKgMLqs4IqlaITRp+t2JyEKBnmBG5karA9fKeVbpdLucah8GqgbePdp7KKeKVmc0yARj 5Z3nJHWl9nAZlfUvxUUB3Tru/KqPSoztIeCtTMeYuCpOUZ+viV3jL9owYN7OI79jYYfg o42g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=nwAI7fro; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id b1-20020a170903228100b001c6223663b3si454167plh.369.2023.11.22.15.40.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Nov 2023 15:40:12 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=nwAI7fro; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id ABBBB8288199; Wed, 22 Nov 2023 15:33:26 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235279AbjKVXdJ (ORCPT + 99 others); Wed, 22 Nov 2023 18:33:09 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41998 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232077AbjKVXcw (ORCPT ); Wed, 22 Nov 2023 18:32:52 -0500 Received: from mail-pf1-x42f.google.com (mail-pf1-x42f.google.com [IPv6:2607:f8b0:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 64E511FC6 for ; Wed, 22 Nov 2023 15:32:16 -0800 (PST) Received: by mail-pf1-x42f.google.com with SMTP id d2e1a72fcca58-6c115026985so363374b3a.1 for ; Wed, 22 Nov 2023 15:32:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1700695936; x=1701300736; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=gC0EagfiP/+NcPX4p9Q3wRm4GjW6UI0uxIwHz/Ubo2M=; b=nwAI7fro1hidD6Gqp96TuBC/bJXgwmis6t8bRi2snoOR4WYihrp7XN4E0Y2vullIqb 6WCJ5LdhfveugpqrT9eouS9dPzsKEGc3RzntVDC4K5tbioJ6NVuBuzH6ErR8fcZ5hWHN zQg9l1jBWsYBt7UM4hSW2BYz3kPcBz+8mg7mcPXBSk8CNoeFG03GzvgQM+d16YL6bnn+ mltiGrjB52X+95RyuqLEi6f2gBMUN9lMbIS+z0ITQ8ePVrGt2xS6+3UBcpHqXws/xQvG 38lxAPwDFDueoZQXmPBsP2poc15Aj42jkM7mC7y+Gvn6+t5KxXrRYVa+gH+0usIV03Ps 7BHQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700695936; x=1701300736; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=gC0EagfiP/+NcPX4p9Q3wRm4GjW6UI0uxIwHz/Ubo2M=; b=KmtR2nLyHTADaTm+/ALTHRyo28S0m2CETWv18xE2Aj1EzImodyRyjGYo/k+qEJwWKj DAAY9ITTNl5qnb+2XFoeeq9fbxKveohjNIE85c/t1TGIkyexmP76HtyPFIAYeVgv8JMx L8ySIypYSF63Z1LL9Q/FZVEjLeJfaippG9RSRM6UAawJ8BHXJNzG6Xdim0+vn8NKhGNx eDll2NfbGjyJ7EhObyzbj8jS9MVYkuf3JH43wIK39ZKl9cn646dWZux3GG29osl/Xapn 9z4ZSPtzJm4grs7N12RxD29e1eyEIt9VRx4HcZPP9gNcARVzTvUHBk9X9x/MyOJdwjJR FO2A== X-Gm-Message-State: AOJu0Yy8zif96rTN4uHduX3iX0tV3tSNgqSGRp1HRqIXAEXsRAdFg44X DsuFH9C7o3N7GooIiAMtZs8l8A== X-Received: by 2002:a05:6a20:8f06:b0:18b:817b:650e with SMTP id b6-20020a056a208f0600b0018b817b650emr1529177pzk.0.1700695935835; Wed, 22 Nov 2023 15:32:15 -0800 (PST) Received: from charlie.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id e22-20020aa78c56000000b006c875abecbcsm22603pfd.121.2023.11.22.15.32.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Nov 2023 15:32:15 -0800 (PST) From: Charlie Jenkins Date: Wed, 22 Nov 2023 15:31:41 -0800 Subject: [PATCH v3 1/2] riscv: Safely remove entries from relocation list MIME-Version: 1.0 Message-Id: <20231122-module_linking_freeing-v3-1-8e9e412a3305@rivosinc.com> References: <20231122-module_linking_freeing-v3-0-8e9e412a3305@rivosinc.com> In-Reply-To: <20231122-module_linking_freeing-v3-0-8e9e412a3305@rivosinc.com> To: Paul Walmsley , Palmer Dabbelt , Albert Ou , Ron Economos , Samuel Holland Cc: linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, Charlie Jenkins X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1700695933; l=7415; i=charlie@rivosinc.com; s=20231120; h=from:subject:message-id; bh=yUZcmL+95LInlulMXXAVr+R7MGLNBV7dJIAJYdqG7QQ=; b=CF5uoJo3PEzBYoN6vt5wunpr/MRm59Ve3tDnUUkzIv7lxuc7ReosIoPa5pRIJ5dv72msAewii M6THNE3AZPHD+VahMV34Kl+zciUHHeta0TMGzimA5GprDjiq/1BbnTF X-Developer-Key: i=charlie@rivosinc.com; a=ed25519; pk=t4RSWpMV1q5lf/NWIeR9z58bcje60/dbtxxmoSfBEcs= X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS, 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 lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Wed, 22 Nov 2023 15:33:26 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1783309440606995171 X-GMAIL-MSGID: 1783309440606995171 Use the safe versions of list and hlist iteration to safely remove entries from the module relocation lists. To allow mutliple threads to load modules concurrently, move relocation list pointers onto the stack rather than using global variables. Fixes: 8fd6c5142395 ("riscv: Add remaining module relocations") Reported-by: Ron Economos Closes: https://lore.kernel.org/linux-riscv/444de86a-7e7c-4de7-5d1d-c1c40eefa4ba@w6rz.net Signed-off-by: Charlie Jenkins --- arch/riscv/kernel/module.c | 93 ++++++++++++++++++++++++++++++++++------------ 1 file changed, 69 insertions(+), 24 deletions(-) diff --git a/arch/riscv/kernel/module.c b/arch/riscv/kernel/module.c index 56a8c78e9e21..fd9a5533518c 100644 --- a/arch/riscv/kernel/module.c +++ b/arch/riscv/kernel/module.c @@ -40,14 +40,16 @@ struct relocation_handlers { long buffer); }; -unsigned int initialize_relocation_hashtable(unsigned int num_relocations); -void process_accumulated_relocations(struct module *me); +unsigned int +initialize_relocation_hashtable(unsigned int num_relocations, + struct hlist_head **relocation_hashtable); +void process_accumulated_relocations(struct module *me, + struct hlist_head **relocation_hashtable, + struct list_head *used_buckets_list); int add_relocation_to_accumulate(struct module *me, int type, void *location, - unsigned int hashtable_bits, Elf_Addr v); - -struct hlist_head *relocation_hashtable; - -struct list_head used_buckets_list; + unsigned int hashtable_bits, Elf_Addr v, + struct hlist_head *relocation_hashtable, + struct list_head *used_buckets_list); /* * The auipc+jalr instruction pair can reach any PC-relative offset @@ -604,7 +606,9 @@ static const struct relocation_handlers reloc_handlers[] = { /* 192-255 nonstandard ABI extensions */ }; -void process_accumulated_relocations(struct module *me) +void process_accumulated_relocations(struct module *me, + struct hlist_head **relocation_hashtable, + struct list_head *used_buckets_list) { /* * Only ADD/SUB/SET/ULEB128 should end up here. @@ -624,18 +628,25 @@ void process_accumulated_relocations(struct module *me) * - Each relocation entry for a location address */ struct used_bucket *bucket_iter; + struct used_bucket *bucket_iter_tmp; struct relocation_head *rel_head_iter; + struct hlist_node *rel_head_iter_tmp; struct relocation_entry *rel_entry_iter; + struct relocation_entry *rel_entry_iter_tmp; int curr_type; void *location; long buffer; - list_for_each_entry(bucket_iter, &used_buckets_list, head) { - hlist_for_each_entry(rel_head_iter, bucket_iter->bucket, node) { + list_for_each_entry_safe(bucket_iter, bucket_iter_tmp, + used_buckets_list, head) { + hlist_for_each_entry_safe(rel_head_iter, rel_head_iter_tmp, + bucket_iter->bucket, node) { buffer = 0; location = rel_head_iter->location; - list_for_each_entry(rel_entry_iter, - rel_head_iter->rel_entry, head) { + list_for_each_entry_safe(rel_entry_iter, + rel_entry_iter_tmp, + rel_head_iter->rel_entry, + head) { curr_type = rel_entry_iter->type; reloc_handlers[curr_type].reloc_handler( me, &buffer, rel_entry_iter->value); @@ -648,11 +659,13 @@ void process_accumulated_relocations(struct module *me) kfree(bucket_iter); } - kfree(relocation_hashtable); + kfree(*relocation_hashtable); } int add_relocation_to_accumulate(struct module *me, int type, void *location, - unsigned int hashtable_bits, Elf_Addr v) + unsigned int hashtable_bits, Elf_Addr v, + struct hlist_head *relocation_hashtable, + struct list_head *used_buckets_list) { struct relocation_entry *entry; struct relocation_head *rel_head; @@ -661,6 +674,10 @@ int add_relocation_to_accumulate(struct module *me, int type, void *location, unsigned long hash; entry = kmalloc(sizeof(*entry), GFP_KERNEL); + + if (!entry) + return -ENOMEM; + INIT_LIST_HEAD(&entry->head); entry->type = type; entry->value = v; @@ -683,17 +700,29 @@ int add_relocation_to_accumulate(struct module *me, int type, void *location, if (!found) { rel_head = kmalloc(sizeof(*rel_head), GFP_KERNEL); + + if (!rel_head) + return -ENOMEM; + rel_head->rel_entry = kmalloc(sizeof(struct list_head), GFP_KERNEL); + + if (!rel_head->rel_entry) + return -ENOMEM; + INIT_LIST_HEAD(rel_head->rel_entry); rel_head->location = location; INIT_HLIST_NODE(&rel_head->node); if (!current_head->first) { bucket = kmalloc(sizeof(struct used_bucket), GFP_KERNEL); + + if (!bucket) + return -ENOMEM; + INIT_LIST_HEAD(&bucket->head); bucket->bucket = current_head; - list_add(&bucket->head, &used_buckets_list); + list_add(&bucket->head, used_buckets_list); } hlist_add_head(&rel_head->node, current_head); } @@ -704,7 +733,9 @@ int add_relocation_to_accumulate(struct module *me, int type, void *location, return 0; } -unsigned int initialize_relocation_hashtable(unsigned int num_relocations) +unsigned int +initialize_relocation_hashtable(unsigned int num_relocations, + struct hlist_head **relocation_hashtable) { /* Can safely assume that bits is not greater than sizeof(long) */ unsigned long hashtable_size = roundup_pow_of_two(num_relocations); @@ -720,12 +751,13 @@ unsigned int initialize_relocation_hashtable(unsigned int num_relocations) hashtable_size <<= should_double_size; - relocation_hashtable = kmalloc_array(hashtable_size, - sizeof(*relocation_hashtable), - GFP_KERNEL); - __hash_init(relocation_hashtable, hashtable_size); + *relocation_hashtable = kmalloc_array(hashtable_size, + sizeof(*relocation_hashtable), + GFP_KERNEL); + if (!*relocation_hashtable) + return -ENOMEM; - INIT_LIST_HEAD(&used_buckets_list); + __hash_init(*relocation_hashtable, hashtable_size); return hashtable_bits; } @@ -742,7 +774,17 @@ int apply_relocate_add(Elf_Shdr *sechdrs, const char *strtab, Elf_Addr v; int res; unsigned int num_relocations = sechdrs[relsec].sh_size / sizeof(*rel); - unsigned int hashtable_bits = initialize_relocation_hashtable(num_relocations); + struct hlist_head *relocation_hashtable; + struct list_head used_buckets_list; + unsigned int hashtable_bits; + + hashtable_bits = initialize_relocation_hashtable(num_relocations, + &relocation_hashtable); + + if (hashtable_bits < 0) + return hashtable_bits; + + INIT_LIST_HEAD(&used_buckets_list); pr_debug("Applying relocate section %u to %u\n", relsec, sechdrs[relsec].sh_info); @@ -823,14 +865,17 @@ int apply_relocate_add(Elf_Shdr *sechdrs, const char *strtab, } if (reloc_handlers[type].accumulate_handler) - res = add_relocation_to_accumulate(me, type, location, hashtable_bits, v); + res = add_relocation_to_accumulate( + me, type, location, hashtable_bits, v, + relocation_hashtable, &used_buckets_list); else res = handler(me, location, v); if (res) return res; } - process_accumulated_relocations(me); + process_accumulated_relocations(me, &relocation_hashtable, + &used_buckets_list); return 0; } From patchwork Wed Nov 22 23:31:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Charlie Jenkins X-Patchwork-Id: 168633 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:6358:6f03:b0:164:83eb:24d7 with SMTP id r3csp1574645rwn; Wed, 22 Nov 2023 15:40:25 -0800 (PST) X-Google-Smtp-Source: AGHT+IHA1HtVt+iguKSq7VCp1668w7ExCmSCwlydEAc6qtdDWvsjzapMTdLcT6yr7nLV+CGkP75z X-Received: by 2002:a05:6a20:9387:b0:18b:94c5:24c2 with SMTP id x7-20020a056a20938700b0018b94c524c2mr253582pzh.60.1700696422242; Wed, 22 Nov 2023 15:40:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700696422; cv=none; d=google.com; s=arc-20160816; b=WHwc2ig8mpxmmGUu0BVNkD+fA1xHB5eqcQj2aE+sgRP+LYyyvNWFG5AgUn9j8AMbx9 mFVdQWDkRXW7AM8bIxoGBVCFkIm09asBzgKD6ZaKwcrrmXZDO5/8h1YOVMEQCWO9w/CS l1mwehc5qtPvHZyZ2EXxlhzhldb5wkMCShhw/xTlFlG6P5XkLX8A48ZDCnQBThPMRJSv U6C86AhYVoT5uj65mznWuZ/imdXqo8mW7gt1iTNZGFCYN/CJz6z/kD7y0tpnIfIiTLL2 z9AeiTC7gIWmN4E3rUovB1VLlvw59fjD7WdiSEtQqKWDG1LYAtGwhq6Fftyq3oTwFedV mfZQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:in-reply-to:references:message-id :content-transfer-encoding:mime-version:subject:date:from :dkim-signature; bh=CTOEMFDe24CcawDbpqI8rRhvGeiKsZMYCpriyAZ9TQI=; fh=EP5ONyipI0seBpYMvRCri1chfPMqLdQYI4ZkdC1FhcA=; b=PPiqoC6kD/32HADwntu3iUkSt+4zLGUDgFyIGKrLcsnKpGA/0TXU6547In3zdpkbEe cRct2eeURVLfZ0RMW0QbjZHmDGNHU2v2jONUQuiVzyiSVCIe8HfJfMKrQKzo4V4+bb5y 4zKAA1vWYR6lZtghKM81pfcAOBZPNDCeIQtq9SUAsMfyH+eURazcdSPdEQM9X1VHXEO5 y1tV1P6b7NL+DHxUQbtCZOETtrItNkj+euGjxmszO8dwdJ88y5E1DknDqjYji7IiFkl+ T0e4s1Q4ur7AwvM43B1aZ/hd+x0Pn3x6sQaXSdW0pZ8UqInSUXJQwUEG58FKmHDMtbj5 Dofg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b="yq4/JRfa"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id w7-20020a17090aea0700b002805aa7b138si636868pjy.59.2023.11.22.15.40.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Nov 2023 15:40:22 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b="yq4/JRfa"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id D848182881BD; Wed, 22 Nov 2023 15:33:33 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232077AbjKVXdO (ORCPT + 99 others); Wed, 22 Nov 2023 18:33:14 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42004 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234675AbjKVXcx (ORCPT ); Wed, 22 Nov 2023 18:32:53 -0500 Received: from mail-pf1-x42c.google.com (mail-pf1-x42c.google.com [IPv6:2607:f8b0:4864:20::42c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CD45C10CB for ; Wed, 22 Nov 2023 15:32:17 -0800 (PST) Received: by mail-pf1-x42c.google.com with SMTP id d2e1a72fcca58-6cbc8199a2aso317189b3a.1 for ; Wed, 22 Nov 2023 15:32:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1700695937; x=1701300737; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=CTOEMFDe24CcawDbpqI8rRhvGeiKsZMYCpriyAZ9TQI=; b=yq4/JRfaBb4CRyLmq9pjTiCXW8nz2NeAGLTCuMxURiWE1L0HS+x+hO4RB0WzFK3pFJ gUiZ9kAOH0YMeO5aWnfboJD3xpcRpY8txMwIBokRbHc83FdC4qt1BMyGqOG4+k95t19l LMUN6/5XFck9jo2i1O+wKBZjuDwxdjUf3HzbNCDV/gEk6maY6LfdIA55sMdWi8hjlNNQ PX+V/mf2WCz6xhntL3YyPpz6/hJSgE2m/mTNRBGN+8/A1ta4PxaY+ludbr6casVn6OaX b03OY6ZNR/r6xPWMP0U+K/z10YkSlDxhwxp/3SNfza1uwVR7Pbbe6uSeSsUvJTcXnazc V7bQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700695937; x=1701300737; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=CTOEMFDe24CcawDbpqI8rRhvGeiKsZMYCpriyAZ9TQI=; b=Lu8BiqEgu2wZlgBXspPfhBFESSXFzdQ0jWO2Dye8l8OEba7auX9mhj8kxjy5oHJZhk l0AzPSD5+NPNsYuUVDC92Z9VHdlIHE27SkvyELoZgNu+DA8mxPvjYy+/6mavL4OEZeeU uyC2LfFUDfiGfXPXHx5cr9TgNr8gMCfjl9S04w382ShK+SpTAI+TgTsplrmc2+9g6Hbn aEsvNdH+LUPUmWaZzzHhRk01MYCEbTT3RF9zArPRJY0aLoDSabhjoHXOuzopf9qKXcoh PvPAMIksrUyeiDRsrisSmILqUIC85TEVD9iQps8GlmBAkYYaAIcf8HS3NgLj0bKgakoA QaPw== X-Gm-Message-State: AOJu0YySUZXNeQWS5rJpzCAVmszVi4lZlcgt/HlipnnmHpctUISqCNyG jnKfzXPhcZ0ZPWeVDclLxO4wDQ== X-Received: by 2002:a05:6a00:6c8e:b0:690:3b59:cc7b with SMTP id jc14-20020a056a006c8e00b006903b59cc7bmr4648756pfb.32.1700695936871; Wed, 22 Nov 2023 15:32:16 -0800 (PST) Received: from charlie.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id e22-20020aa78c56000000b006c875abecbcsm22603pfd.121.2023.11.22.15.32.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Nov 2023 15:32:16 -0800 (PST) From: Charlie Jenkins Date: Wed, 22 Nov 2023 15:31:42 -0800 Subject: [PATCH v3 2/2] riscv: Correct type casting in module loading MIME-Version: 1.0 Message-Id: <20231122-module_linking_freeing-v3-2-8e9e412a3305@rivosinc.com> References: <20231122-module_linking_freeing-v3-0-8e9e412a3305@rivosinc.com> In-Reply-To: <20231122-module_linking_freeing-v3-0-8e9e412a3305@rivosinc.com> To: Paul Walmsley , Palmer Dabbelt , Albert Ou , Ron Economos , Samuel Holland Cc: linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, Charlie Jenkins X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1700695933; l=1122; i=charlie@rivosinc.com; s=20231120; h=from:subject:message-id; bh=JEDtvtgEBmFqCKNc+NtpG6SnBh4nM+PNkCAzWthvfGI=; b=agKzcrFlKLjzZJouJQrrVp+E78ppa6q038/I46LaMQxzZRAByfrJC5J1zXsrBngNF8BddyoyG ULuT+Dr5K2OBcOy66Mu2Kl/sIi2+HtIaRq7LtTQ2aV/x88utv/NoJX/ X-Developer-Key: i=charlie@rivosinc.com; a=ed25519; pk=t4RSWpMV1q5lf/NWIeR9z58bcje60/dbtxxmoSfBEcs= X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS, 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 lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Wed, 22 Nov 2023 15:33:34 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1783309451441342005 X-GMAIL-MSGID: 1783309451441342005 Use __le16 with le16_to_cpu. Fixes: 8fd6c5142395 ("riscv: Add remaining module relocations") Signed-off-by: Charlie Jenkins Reviewed-by: Samuel Holland Tested-by: Samuel Holland --- arch/riscv/kernel/module.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/riscv/kernel/module.c b/arch/riscv/kernel/module.c index fd9a5533518c..b570988e7d43 100644 --- a/arch/riscv/kernel/module.c +++ b/arch/riscv/kernel/module.c @@ -66,7 +66,7 @@ static bool riscv_insn_valid_32bit_offset(ptrdiff_t val) static int riscv_insn_rmw(void *location, u32 keep, u32 set) { - u16 *parcel = location; + __le16 *parcel = location; u32 insn = (u32)le16_to_cpu(parcel[0]) | (u32)le16_to_cpu(parcel[1]) << 16; insn &= keep; @@ -79,7 +79,7 @@ static int riscv_insn_rmw(void *location, u32 keep, u32 set) static int riscv_insn_rvc_rmw(void *location, u16 keep, u16 set) { - u16 *parcel = location; + __le16 *parcel = location; u16 insn = le16_to_cpu(*parcel); insn &= keep;