Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp592287imw; Thu, 14 Jul 2022 07:17:07 -0700 (PDT) X-Google-Smtp-Source: AGRyM1tlH8EvuKjFsc9CDbUmgAq5itSsS8nmO5s1CyYsgb0cVye/fbqanw1bJ7EE0TOOCgYJBmjj X-Received: by 2002:a17:907:1608:b0:72e:e254:7baa with SMTP id hb8-20020a170907160800b0072ee2547baamr2382312ejc.672.1657808227614; Thu, 14 Jul 2022 07:17:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657808227; cv=none; d=google.com; s=arc-20160816; b=uY/qho8FtKK45/xko2huw79eZK33slOJXkFL2wzbQPDaD0MekhPGV1GNgWR7AlrBo/ 7zVln7rwWuzt8ZgMzohXaJjommB2xB1EWehJaU/iTG6klsOqJAbJ+O1BN/6jYsoZ+Fh4 Yq2jGMS84gwDRfpgiXUk8PRHsNljOaNbddMerBlPPNG0pfwU2tVgoJ0XK5EWfDZNKGqw JSE/TJMfdt5IqXxjrV+QsHSgw68z2wI00jjMWNvi/2YrMbMxng+4Rw5T5cuZZKPJAun1 8BYwXAlxAX9XOL/f+cYHxPpCpYJ8tXxq9zfmTGracDRxlARtI4K/YGDasDq/V2/9tURp zfZQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id; bh=+l/O5p9AzlrifU90TuGiTnZqxkr7/WcP8ia7gg60De0=; b=LVb+7l7dP+uKKGxOTrVT3+X1tm4wBvQyZKUf56c/AssL3rRDO/HMuwsT7c3jmywBsb tQ/GHGrbboJo0vttCzgufM5NCvtguoh0D2w59HS3/IjxEzHDsB8AwIspIAzWHRkeJxN7 KbVWnrXhheMymHoAU584E5Fidc85QuA8IZcOtYNuUpVffOAAIhEQ2V8OT9omvOTdaYdV n1BwmwR7yYNkHWrXN+IzQVzeSfb/son67uWctukTtZ3MENbLwHw80HsMUeQReAIyLJu6 izfHhD4L5PXt+cipI8+eQVwBEVmcywm0VFmwFrNdllbNQkjxVKUhiyPCsAdRzHkxAGK5 FBgw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h11-20020a05640250cb00b0043a92a7096esi2628618edb.21.2022.07.14.07.16.43; Thu, 14 Jul 2022 07:17:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238243AbiGNOID (ORCPT + 99 others); Thu, 14 Jul 2022 10:08:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45146 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230190AbiGNOIC (ORCPT ); Thu, 14 Jul 2022 10:08:02 -0400 Received: from loongson.cn (mail.loongson.cn [114.242.206.163]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id B504828713 for ; Thu, 14 Jul 2022 07:08:00 -0700 (PDT) Received: from [10.90.50.23] (unknown [10.90.50.23]) by mail.loongson.cn (Coremail) with SMTP id AQAAf9Dxf+M4I9BiWmUeAA--.63010S3; Thu, 14 Jul 2022 22:07:53 +0800 (CST) Message-ID: <6896bb4c-5224-678f-e73c-fe95be41d196@loongson.cn> Date: Thu, 14 Jul 2022 22:07:52 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.11.0 Subject: Re: [PATCH] LoongArch: Fix missing fcsr in ptrace's fpr_set Content-Language: en-US To: Huacai Chen Cc: WANG Xuerui , Oleg Nesterov , Xu Li , loongarch@lists.linux.dev, LKML References: <20220714062550.4934-1-huqi@loongson.cn> From: Qi Hu In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-CM-TRANSID: AQAAf9Dxf+M4I9BiWmUeAA--.63010S3 X-Coremail-Antispam: 1UD129KBjvJXoW7tFyxXrWDGryxZw17Wry8Xwb_yoW8Zw1kpr ZxA3ZxGF48JrWrur9FqFnYvr1DXwnFgFyS9393t3WrArnFvws8JryDtF42vFWIy34rGayx ZrnF9FsayFnFq3DanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUvYb7Iv0xC_tr1lb4IE77IF4wAFF20E14v26r4j6ryUM7CY07I2 0VC2zVCF04k26cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28lY4IEw2IIxxk0rw A2F7IY1VAKz4vEj48ve4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_Gr0_Xr1l84ACjcxK6xII jxv20xvEc7CjxVAFwI0_Cr0_Gr1UM28EF7xvwVC2z280aVAFwI0_GcCE3s1l84ACjcxK6I 8E87Iv6xkF7I0E14v26rxl6s0DM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI 64kE6c02F40Ex7xfMcIj6xIIjxv20xvE14v26r1j6r18McIj6I8E87Iv67AKxVWUJVW8Jw Am72CE4IkC6x0Yz7v_Jr0_Gr1lF7xvr2IY64vIr41lc7I2V7IY0VAS07AlzVAYIcxG8wCY 02Avz4vE-syl42xK82IYc2Ij64vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1lx2IqxVAqx4 xG67AKxVWUJVWUGwC20s026x8GjcxK67AKxVWUGVWUWwC2zVAF1VAY17CE14v26r126r1D MIIYrxkI7VAKI48JMIIF0xvE2Ix0cI8IcVAFwI0_Jr0_JF4lIxAIcVC0I7IYx2IY6xkF7I 0E14v26r1j6r4UMIIF0xvE42xK8VAvwI8IcIk0rVWrZr1j6s0DMIIF0xvEx4A2jsIE14v2 6r1j6r4UMIIF0xvEx4A2jsIEc7CjxVAFwI0_Gr0_Gr1UYxBIdaVFxhVjvjDU0xZFpf9x07 j8GYLUUUUU= X-CM-SenderInfo: pkxtxqxorr0wxvrqhubq/1tbiAQAHCV3QvP1aPwABsn X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,NICE_REPLY_A, SPF_HELO_PASS,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 On 2022/7/14 21:12, Huacai Chen wrote: > Hi, > > On Thu, Jul 14, 2022 at 2:26 PM Qi Hu wrote: >> In file ptrace.c, function fpr_set does not copy fcsr data from ubuf >> to kbuf. That's the reason why fcsr cannot be modified by ptrace. >> >> This patch fixs this problem and allows users using ptrace to modify >> the fcsr. >> >> Signed-off-by: Qi Hu >> Signed-off-by: Xu Li >> --- >> arch/loongarch/kernel/ptrace.c | 12 +++++++----- >> 1 file changed, 7 insertions(+), 5 deletions(-) >> >> diff --git a/arch/loongarch/kernel/ptrace.c b/arch/loongarch/kernel/ptrace.c >> index e6ab87948e1d..dc2b82ea894c 100644 >> --- a/arch/loongarch/kernel/ptrace.c >> +++ b/arch/loongarch/kernel/ptrace.c >> @@ -193,7 +193,7 @@ static int fpr_set(struct task_struct *target, >> const void *kbuf, const void __user *ubuf) >> { >> const int fcc_start = NUM_FPU_REGS * sizeof(elf_fpreg_t); >> - const int fcc_end = fcc_start + sizeof(u64); >> + const int fcsr_start = fcc_start + sizeof(u64); >> int err; >> >> BUG_ON(count % sizeof(elf_fpreg_t)); >> @@ -209,10 +209,12 @@ static int fpr_set(struct task_struct *target, >> if (err) >> return err; >> >> - if (count > 0) >> - err |= user_regset_copyin(&pos, &count, &kbuf, &ubuf, >> - &target->thread.fpu.fcc, >> - fcc_start, fcc_end); >> + err |= user_regset_copyin(&pos, &count, &kbuf, &ubuf, >> + &target->thread.fpu.fcc, fcc_start, >> + fcc_start + sizeof(u64)); >> + err |= user_regset_copyin(&pos, &count, &kbuf, &ubuf, >> + &target->thread.fpu.fcsr, fcsr_start, >> + fcsr_start + sizeof(u32)); > You shouldn't remove (count > 0) here, because the above > user_regset_copyin() will modify count inside, and so "count == 0" is > possible. > > Huacai Yes, the "count" should be considered. But the "count" is checked at the beginning of the "user_regset_copyin()". So "count > 0" is useless, i think. Also like riscv, "count" is not checked in "riscv_fpr_set()". >> return err; >> } >> -- >> 2.37.0 >>