Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp444852pxb; Thu, 19 Nov 2020 05:29:24 -0800 (PST) X-Google-Smtp-Source: ABdhPJxT9Xe1XSpFtcHY/CCSCrk6gaorEhXTbUhwXzWu2HYldvjoEDBgmW02QLDcURCYEOVOalku X-Received: by 2002:aa7:d408:: with SMTP id z8mr30131063edq.166.1605792563975; Thu, 19 Nov 2020 05:29:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605792563; cv=none; d=google.com; s=arc-20160816; b=lXHxf8ueR+YwyEbB06IJZ8vqZX+xkjw0QYiR71KGIghcmSWdAWDczXx0V9fdCMLEA0 F6NAYqZAHxgqzK6agfqWAc4nuL1RA8dSc6FPS1ROONFYJeJOK1PE5PFCnZzvYAJKVKha WBeeTU6W5tvlaXz8EFqEz3dazCdUhDZ6jKNX//HbW2Pga8z8hIGn9LQmJG5rH8FfzTl3 Vc6wyvVmpnfoBQMoENXm+tJPkT6NLCjsxtbmqn1k3ugB2i1xPg2iAG3OIrf0Kqkr8oBe 2ruyz3M+cOJI9H5BSP0A3rC5qAjJPKdiDF5Zwp5mHiU3VhATpNqBDIAvfW7Gb5IkkDtZ +q0w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=bYxGRSvumM3zLqLMM+ueQPMQIrM6akyobSDpYGM0pqc=; b=UokucxXobBj0lUhAPNmn/UvLRq409ySmHys8zEcwffn7mm8Z16zMiaOiVkhhCXHX1Q /w13RpB+p9Ac0GXDiWs1wueD8CTHQ1lA+dj/CiRGNon1HLWNzHd/2BQY6xrunn7yXLdG lt25fr0gaXHDpxBpQRzMIpO41lX901DLG7KNuYmSxPp31bPhROcv2tDu9O85mp59LQVJ cVjeOEUmv10PGa/GMKzviybuzOGX6ynmFpKFHDIhyQu4PvryXINtmR2Mxy+oYu555B2M AMpjW+omVN30YMNmYcFuGngJm9XDkrdGMJQoAWDZQoxN64/LAJFVUjVkpppUFqw6C35V rJ/w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h14si1347861eje.325.2020.11.19.05.29.01; Thu, 19 Nov 2020 05:29:23 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727304AbgKSNZz (ORCPT + 99 others); Thu, 19 Nov 2020 08:25:55 -0500 Received: from elvis.franken.de ([193.175.24.41]:43206 "EHLO elvis.franken.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727288AbgKSNZy (ORCPT ); Thu, 19 Nov 2020 08:25:54 -0500 Received: from uucp (helo=alpha) by elvis.franken.de with local-bsmtp (Exim 3.36 #1) id 1kfjK0-0004vb-00; Thu, 19 Nov 2020 13:45:56 +0100 Received: by alpha.franken.de (Postfix, from userid 1000) id EB989C01DD; Thu, 19 Nov 2020 13:36:36 +0100 (CET) Date: Thu, 19 Nov 2020 13:36:36 +0100 From: Thomas Bogendoerfer To: Jinyang He Cc: Huacai Chen , Jiaxun Yang , linux-mips@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 1/3] MIPS: KASLR: Correcte valid bits in apply_r_mips_26_rel Message-ID: <20201119123636.GA4936@alpha.franken.de> References: <1605752954-10368-1-git-send-email-hejinyang@loongson.cn> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1605752954-10368-1-git-send-email-hejinyang@loongson.cn> User-Agent: Mutt/1.10.1 (2018-07-13) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Nov 19, 2020 at 10:29:12AM +0800, Jinyang He wrote: > Apply_r_mips_26_rel() relocates instructions like j, jal and etc. These > instructions consist of 6bits function field and 26bits address field. > The value of target_addr as follows, > ================================================================= > | high 4bits | low 28bits | > ================================================================= > |the high 4bits of this PC | the low 26bits of instructions << 2| > ================================================================= > Thus, loc_orig and log_new both need high 4bits ranther than high 6bits. rather > Replace 0x3ffffff with 0xfffffff. > > Signed-off-by: Jinyang He > --- > arch/mips/kernel/relocate.c | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > > diff --git a/arch/mips/kernel/relocate.c b/arch/mips/kernel/relocate.c > index 3d80a51..709cfa0 100644 > --- a/arch/mips/kernel/relocate.c > +++ b/arch/mips/kernel/relocate.c > @@ -95,7 +95,7 @@ static int __init apply_r_mips_26_rel(u32 *loc_orig, u32 *loc_new, long offset) > > /* Original target address */ > target_addr <<= 2; > - target_addr += (unsigned long)loc_orig & ~0x03ffffff; > + target_addr += (unsigned long)loc_orig & ~0x0fffffff; how about using target_addr += (unsigned long)log_orig & 0xf0000000; which makes it IMHO even clearer what this does ? Thomas. -- Crap can work. Given enough thrust pigs will fly, but it's not necessarily a good idea. [ RFC1925, 2.3 ]