Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp946583pxb; Thu, 19 Nov 2020 18:52:20 -0800 (PST) X-Google-Smtp-Source: ABdhPJw68cF5JeZBV7sJvF2HsgU4nR3KG+pI19n5YURWtK+SxbN5taGkwnjbOAd9i0hkk8sSfjDx X-Received: by 2002:aa7:d351:: with SMTP id m17mr34217247edr.215.1605840740602; Thu, 19 Nov 2020 18:52:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605840740; cv=none; d=google.com; s=arc-20160816; b=nS5Pqjl1AgMnU5MvwJY9xt0llmayjvjpy7ipcn9qIKznKg+wDZ+tOEtJwUR+yojGoV qgdtmGG8WuIPBECNg8Aadx0vBWZbZM0XgCcUNYrw7ivYfHpEfDnNtT85W+AVqYqXOiWr auG3s5r9GrCaK4oGEFQZLm8W2JnzB011ysV+pNtbo0kv1+EZiwi1q7XBUOj7q70fwBT5 fSBi8ap18qXi8G6AIRaZnk+LkeuukqS26BPzBC3GQzPcqY0LKCnQhf3SofRCfV+YiRFU G+g59C5yvs7727Eg/8FevdNO+B8usUogVa7k0HH3y/jW7cWc+ccU6jfvmNXDbrhsVM2S aL7w== 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 :mime-version:user-agent:date:message-id:from:cc:references:to :subject; bh=4p6L/Sgl34sX8uvjsvv5ftiqtzDCmUWm0bI+QI+u+2g=; b=K4EYYhlzBSQmZm0RA2W9J4+RtOMWNqXgoKCWDUDoRDzqsnbjZlcBl2KPS1jqALkA9U 7Qug+o/mAB0v/8/cUTEgw2Y93lF6617nL7MC7FzKhbsPx9Lnsq949cCWaQOfkcP4WVz1 hfGKa4wiZVoJvh81h32+XVKjaWTnwzZNa6ImqufDwOdK92h/uvBz6cLuLdsW34t+PVE7 7QM4/jkADnsMrVCY3O7k3djK2fRctWl/FbnbwOTLEZerSXKAuLGcExbsPWIhIk6ijVBx 8XHzKDL0drL546JZiN3JPRGVmJ1FYIyT5DyYYBqvCq0XLmKkB9S7Wa8VC93uypEjWnWA PZBw== 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 qk3si1135709ejb.539.2020.11.19.18.51.56; Thu, 19 Nov 2020 18:52:20 -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 S1726192AbgKTCsM (ORCPT + 99 others); Thu, 19 Nov 2020 21:48:12 -0500 Received: from mail.loongson.cn ([114.242.206.163]:33682 "EHLO loongson.cn" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725937AbgKTCsM (ORCPT ); Thu, 19 Nov 2020 21:48:12 -0500 Received: from [10.130.0.170] (unknown [113.200.148.30]) by mail.loongson.cn (Coremail) with SMTP id AQAAf9AxitBnLrdfHlMTAA--.30966S3; Fri, 20 Nov 2020 10:48:07 +0800 (CST) Subject: Re: [PATCH 1/3] MIPS: KASLR: Correcte valid bits in apply_r_mips_26_rel To: Thomas Bogendoerfer References: <1605752954-10368-1-git-send-email-hejinyang@loongson.cn> <20201119123636.GA4936@alpha.franken.de> Cc: Huacai Chen , Jiaxun Yang , linux-mips@vger.kernel.org, linux-kernel@vger.kernel.org From: Jinyang He Message-ID: <0fbbdce0-1449-fb40-0a11-2cded0c3472b@loongson.cn> Date: Fri, 20 Nov 2020 10:48:07 +0800 User-Agent: Mozilla/5.0 (X11; Linux mips64; rv:45.0) Gecko/20100101 Thunderbird/45.4.0 MIME-Version: 1.0 In-Reply-To: <20201119123636.GA4936@alpha.franken.de> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-CM-TRANSID: AQAAf9AxitBnLrdfHlMTAA--.30966S3 X-Coremail-Antispam: 1UD129KBjvJXoW7ZF1rurW3Jry8urWkZF4xZwb_yoW8WrW3pr 9rJFyxGr4UJFyUKFyUJF15Jr1UJa1DXF17GF1kt34Ivwn8ZryDGF18Gr1xX3y0gr10kF17 XFyqgr1UAr4UAFUanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUvab7Iv0xC_Kw4lb4IE77IF4wAFF20E14v26r1j6r4UM7CY07I2 0VC2zVCF04k26cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28lY4IEw2IIxxk0rw A2F7IY1VAKz4vEj48ve4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_Xr0_Ar1l84ACjcxK6xII jxv20xvEc7CjxVAFwI0_Cr0_Gr1UM28EF7xvwVC2z280aVAFwI0_Gr1j6F4UJwA2z4x0Y4 vEx4A2jsIEc7CjxVAFwI0_Cr1j6rxdM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVAC Y4xI64kE6c02F40Ex7xfMcIj6xIIjxv20xvE14v26r106r15McIj6I8E87Iv67AKxVWUJV W8JwAm72CE4IkC6x0Yz7v_Jr0_Gr1lF7xvr2IY64vIr41lc7I2V7IY0VAS07AlzVAYIcxG 8wCY02Avz4vE14v_Gr1l42xK82IYc2Ij64vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1lx2 IqxVAqx4xG67AKxVWUJVWUGwC20s026x8GjcxK67AKxVWUGVWUWwC2zVAF1VAY17CE14v2 6r126r1DMIIYrxkI7VAKI48JMIIF0xvE2Ix0cI8IcVAFwI0_Jr0_JF4lIxAIcVC0I7IYx2 IY6xkF7I0E14v26r1j6r4UMIIF0xvE42xK8VAvwI8IcIk0rVW3JVWrJr1lIxAIcVC2z280 aVAFwI0_Jr0_Gr1lIxAIcVC2z280aVCY1x0267AKxVWUJVW8JbIYCTnIWIevJa73UjIFyT uYvjxUqR6zDUUUU X-CM-SenderInfo: pkhmx0p1dqwqxorr0wxvrqhubq/ Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, On 11/19/2020 08:36 PM, Thomas Bogendoerfer wrote: > 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 ? That sounds good. I'll send v2 later. Thanks, Jinyang. > Thomas. >