Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp53714imw; Thu, 14 Jul 2022 20:26:06 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uNNi5Grr+2s9z9M5PyLHWKUg4uaO3oLUichur+nMBLzcDyYPNEycuoeIdoePFA/YvinbbL X-Received: by 2002:a17:902:e946:b0:16b:d4e1:a405 with SMTP id b6-20020a170902e94600b0016bd4e1a405mr11369381pll.16.1657855565914; Thu, 14 Jul 2022 20:26:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657855565; cv=none; d=google.com; s=arc-20160816; b=TPx9xFkxPvoVnkFlCvXmHTrnAa31TG5paNYJ+A3Sd8vSmulS8lxcun9kLDFy+Mu2kd 83vMKw3K7l1oImXmsFiPzY/zXWCZY7mZj29PPjZYAAZO9sH+av2jg/LdBuNaLoMi5MzV gyt9mLV0YfVyxgzaeWDmAOlGhSImqWeaVAPC9IjagN51t5GV2B/84gOt2hbfP8R9Giou hxWyNuyWorqeVuoFTO8etXbnt6UrzVRNoTpK9Cr1DgrkSBoGw8eT7Aht7uZWA1o8bF3Q MaYwbc7gEzoK4elUUCzypuAhxfkul+n7v0ZwBSht+gzCf/yzH23gaOAqPOJ+7t1+gdV/ 582g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=4fM+cF5RtQND30XeSmND5CvxpOPqchMJzUfdMpcxb4k=; b=KtpDTI+14XeeJu0/g7nfqxq6Ee4iBx2eNIu8jL7K0nxUUiChNHeUIVo4MtqiGPY9Fl 5rlEH583n4CjhyZ6BMxFL6bLr33/RKFMvKRsKKaDAqOHstN/fkeWk2Der8YQJONe3GWv tHCpBZ6QHHY/7DMVlowtRv1N52ebTnbzoSKaJW5F5TDXMY7efxxit3y4+ogJ/kN4T4JX D+Vup9EiJ3UPBK7vfIGYfS1hRnYOjx/JGGiu145CJAfk3G5HBu8UHjoJoF2AMlVb5QRz dlkPjGcTDhywzCg3+U1wAv+0FaMk/EYK6NNv6TcyWKzwc2FbPt0ACHdyzBloh/668qgp va4Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=oKw6mCZO; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z66-20020a626545000000b005251bed3f3asi3779222pfb.98.2022.07.14.20.25.49; Thu, 14 Jul 2022 20:26:05 -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; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=oKw6mCZO; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241289AbiGODUY (ORCPT + 99 others); Thu, 14 Jul 2022 23:20:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43228 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229809AbiGODUX (ORCPT ); Thu, 14 Jul 2022 23:20:23 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4767FA447 for ; Thu, 14 Jul 2022 20:20:22 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id CC5AA621EE for ; Fri, 15 Jul 2022 03:20:21 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 42CB6C341C6 for ; Fri, 15 Jul 2022 03:20:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1657855221; bh=r9nH0nnXki3fn2qUEx//h7cuqEVQBiYMXEgpzqbyJ5g=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=oKw6mCZOD1HPIbLdEpgbQaev8ZMcZVxjKSGNSOdQchcnAh9IwRz8aZ2io+E+MTbbs XcmIqOkLdbMkSErlBQNXmCN4tH1N8M/5uhNwn5IT0Kmiky4/q9Qmhqt5V75U7eniEm od+2dX50pYreYY7GoKdd23jyYFRPrlFJH0r5Lh71vaftCd8mhUuqbtRkv5VnYyG+nx 1Jr5VxxHNSn4Qt9Gsn9P+a75y1IMp6sMMBkO2CFQtG+DOX3Gif1PGBMreTHt/PN/zc rT5vLW7VBRTgIxnF15DbEyWLedboADMcTJUBusvin3BHOr002YDnkexTbxCWudGtpY Ki5496NqPPDSg== Received: by mail-vk1-f172.google.com with SMTP id 7so1648665vkq.0 for ; Thu, 14 Jul 2022 20:20:21 -0700 (PDT) X-Gm-Message-State: AJIora/YUVnTCcMhY84W75imyY0DZwDhPy4kwQz391zJzs8mhzFNvntf NNnPne1KteO5Xtze4GaCA0vmtXPMqTcRy2cqSYg= X-Received: by 2002:a1f:340f:0:b0:374:7b8a:378 with SMTP id b15-20020a1f340f000000b003747b8a0378mr4918379vka.37.1657855220231; Thu, 14 Jul 2022 20:20:20 -0700 (PDT) MIME-Version: 1.0 References: <20220714062550.4934-1-huqi@loongson.cn> <6896bb4c-5224-678f-e73c-fe95be41d196@loongson.cn> In-Reply-To: <6896bb4c-5224-678f-e73c-fe95be41d196@loongson.cn> From: Huacai Chen Date: Fri, 15 Jul 2022 11:20:07 +0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH] LoongArch: Fix missing fcsr in ptrace's fpr_set To: Qi Hu Cc: WANG Xuerui , Oleg Nesterov , Xu Li , loongarch@lists.linux.dev, LKML Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-7.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, 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 On Thu, Jul 14, 2022 at 10:07 PM Qi Hu wrote: > > > 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. Yes, you are right, thanks. Huacai > > Also like riscv, "count" is not checked in "riscv_fpr_set()". > > >> return err; > >> } > >> -- > >> 2.37.0 > >> >