From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.8 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D495BC56201 for ; Tue, 24 Nov 2020 13:24:52 +0000 (UTC) Received: from mm01.cs.columbia.edu (mm01.cs.columbia.edu [128.59.11.253]) by mail.kernel.org (Postfix) with ESMTP id 271442076E for ; Tue, 24 Nov 2020 13:24:52 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=kernel.org header.i=@kernel.org header.b="iGIa9jId" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 271442076E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvmarm-bounces@lists.cs.columbia.edu Received: from localhost (localhost [127.0.0.1]) by mm01.cs.columbia.edu (Postfix) with ESMTP id BA10B4BD13; Tue, 24 Nov 2020 08:24:49 -0500 (EST) X-Virus-Scanned: at lists.cs.columbia.edu Authentication-Results: mm01.cs.columbia.edu (amavisd-new); dkim=softfail (fail, message has been altered) header.i=@kernel.org Received: from mm01.cs.columbia.edu ([127.0.0.1]) by localhost (mm01.cs.columbia.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id WHacITlxsQst; Tue, 24 Nov 2020 08:24:48 -0500 (EST) Received: from mm01.cs.columbia.edu (localhost [127.0.0.1]) by mm01.cs.columbia.edu (Postfix) with ESMTP id 9C2C14BD3F; Tue, 24 Nov 2020 08:24:48 -0500 (EST) Received: from localhost (localhost [127.0.0.1]) by mm01.cs.columbia.edu (Postfix) with ESMTP id 195594BD35 for ; Tue, 24 Nov 2020 08:24:47 -0500 (EST) X-Virus-Scanned: at lists.cs.columbia.edu Received: from mm01.cs.columbia.edu ([127.0.0.1]) by localhost (mm01.cs.columbia.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id nvvICNwtKvfJ for ; Tue, 24 Nov 2020 08:24:46 -0500 (EST) Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by mm01.cs.columbia.edu (Postfix) with ESMTPS id E77F54BD13 for ; Tue, 24 Nov 2020 08:24:45 -0500 (EST) Received: from disco-boy.misterjones.org (disco-boy.misterjones.org [51.254.78.96]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 9AA7C2083E; Tue, 24 Nov 2020 13:24:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1606224284; bh=SH24zETgIC2uK40KbauN9QWLDcUjyzI/5kjjC2KZ+fk=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=iGIa9jIdjELamK289FVflS130IVk3T6wNF0lychyIOHz/la2LUAeR+dXXgw+S/fO/ BEg6yoQMJSZXvXocSl0q/TtD30ZbGUmAgo+XcTO2xNUPIc0J1NQuIGHhwuVr9xXW2Y oaKFyn5dhtjsvcljxyT8+IrK9cSR6e0aJkeTowpY= Received: from disco-boy.misterjones.org ([51.254.78.96] helo=www.loen.fr) by disco-boy.misterjones.org with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94) (envelope-from ) id 1khYJG-00DFyo-I3; Tue, 24 Nov 2020 13:24:42 +0000 MIME-Version: 1.0 Date: Tue, 24 Nov 2020 13:24:42 +0000 From: Marc Zyngier To: David Brazdil Subject: Re: [RFC PATCH 3/6] kvm: arm64: Fix up RELR relocation in hyp code/data In-Reply-To: <20201119162543.78001-4-dbrazdil@google.com> References: <20201119162543.78001-1-dbrazdil@google.com> <20201119162543.78001-4-dbrazdil@google.com> User-Agent: Roundcube Webmail/1.4.9 Message-ID: X-Sender: maz@kernel.org X-SA-Exim-Connect-IP: 51.254.78.96 X-SA-Exim-Rcpt-To: dbrazdil@google.com, kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, james.morse@arm.com, julien.thierry.kdev@gmail.com, suzuki.poulose@arm.com, catalin.marinas@arm.com, will@kernel.org, mark.rutland@arm.com, ascull@google.com, ardb@kernel.org, kernel-team@android.com X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false Cc: kernel-team@android.com, Catalin Marinas , linux-kernel@vger.kernel.org, Ard Biesheuvel , linux-arm-kernel@lists.infradead.org, Will Deacon , kvmarm@lists.cs.columbia.edu X-BeenThere: kvmarm@lists.cs.columbia.edu X-Mailman-Version: 2.1.14 Precedence: list List-Id: Where KVM/ARM decisions are made List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="us-ascii"; Format="flowed" Errors-To: kvmarm-bounces@lists.cs.columbia.edu Sender: kvmarm-bounces@lists.cs.columbia.edu On 2020-11-19 16:25, David Brazdil wrote: > The arm64 kernel also supports packing of relocation data using the > RELR > format. Implement a parser of RELR data and fixup the relocations using > the same infra as RELA relocs. > > Signed-off-by: David Brazdil > --- > arch/arm64/kvm/va_layout.c | 41 ++++++++++++++++++++++++++++++++++++++ > 1 file changed, 41 insertions(+) > > diff --git a/arch/arm64/kvm/va_layout.c b/arch/arm64/kvm/va_layout.c > index b80fab974896..7f45a98eacfd 100644 > --- a/arch/arm64/kvm/va_layout.c > +++ b/arch/arm64/kvm/va_layout.c > @@ -145,6 +145,43 @@ static void __fixup_hyp_rela(void) > __fixup_hyp_rel(rel[i].r_offset); > } > > +#ifdef CONFIG_RELR > +static void __fixup_hyp_relr(void) > +{ > + u64 *rel, *end; > + > + rel = (u64*)(kimage_vaddr + __load_elf_u64(__relr_offset)); > + end = rel + (__load_elf_u64(__relr_size) / sizeof(*rel)); > + > + while (rel < end) { > + unsigned n; > + u64 addr = *(rel++); > + > + /* Address must not have the LSB set. */ > + BUG_ON(addr & BIT(0)); > + > + /* Fix up the first address of the chain. */ > + __fixup_hyp_rel(addr); > + > + /* > + * Loop over bitmaps, i.e. as long as words' LSB is 1. > + * Each bit (ordered from LSB to MSB) represents one word from > + * the last full address (exclusive). If the corresponding bit > + * is 1, there is a relative relocation on that word. > + */ What is the endianness of this bitmap? Is it guaranteed to be in CPU-endian format? > + for (n = 0; rel < end && (*rel & BIT(0)); n++) { > + unsigned i; > + u64 bitmap = *(rel++); nit: if you change this u64 for an unsigned long... > + > + for (i = 1; i < 64; ++i) { > + if ((bitmap & BIT(i))) > + __fixup_hyp_rel(addr + 8 * (63 * n + i)); > + } ... this can be written as: i = 1; for_each_set_bit_from(i, &bitmap, 64) __fixup_hyp_rel(addr + 8 * (63 * n + i)); > + } > + } > +} > +#endif > + > /* > * The kernel relocated pointers to kernel VA. Iterate over > relocations in > * the hypervisor ELF sections and convert them to hyp VA. This avoids > the > @@ -156,6 +193,10 @@ __init void kvm_fixup_hyp_relocations(void) > return; > > __fixup_hyp_rela(); > + > +#ifdef CONFIG_RELR > + __fixup_hyp_relr(); > +#endif > } > > static u32 compute_instruction(int n, u32 rd, u32 rn) Thanks, M. -- Jazz is not dead. It just smells funny... _______________________________________________ kvmarm mailing list kvmarm@lists.cs.columbia.edu https://lists.cs.columbia.edu/mailman/listinfo/kvmarm From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-14.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BC432C56201 for ; Tue, 24 Nov 2020 13:25:59 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 461B02076E for ; Tue, 24 Nov 2020 13:25:59 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="eGDc2pjb"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=kernel.org header.i=@kernel.org header.b="iGIa9jId" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 461B02076E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Type: Content-Transfer-Encoding:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:Message-ID:References:In-Reply-To:Subject:To:From: Date:MIME-Version:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=5MreFQQ1dpkXw5R+QuxcNG/mhoyNo5snrSLJSGmmJiA=; b=eGDc2pjb9LuaniPiHRNuP1P0v 13qexy0y1tyLFCHjhJ0CbFGhF4qLZncTbgsOnhHZ1/y8K7J9wjtmwv5+pweqWA60SAcU1wTqgjcha d3tRPw4hG7olYEFZmkkY2yQeFJ/L8GB2No5kIlk7xtJCJmkDTeW8HvB/QXtr15k1k1l62+jXqtqBG eK6dQm0fBsKV+aXKWez24xk27UUXXdO2ThdbYKwb+xRHtqqGtOjelhmbMeTqAl7FCNTUJ4tstP0Mo ctrIdmuzyFyd/B7K9TLijzEzkFUlA2zXrHZ6zDpqMzyTfx9kYO1ZL5PupAC8XHzx8qmgyO58B9SgR F0pYSkGrg==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1khYJM-0007Ya-Jq; Tue, 24 Nov 2020 13:24:48 +0000 Received: from mail.kernel.org ([198.145.29.99]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1khYJJ-0007Xw-Vn for linux-arm-kernel@lists.infradead.org; Tue, 24 Nov 2020 13:24:46 +0000 Received: from disco-boy.misterjones.org (disco-boy.misterjones.org [51.254.78.96]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 9AA7C2083E; Tue, 24 Nov 2020 13:24:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1606224284; bh=SH24zETgIC2uK40KbauN9QWLDcUjyzI/5kjjC2KZ+fk=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=iGIa9jIdjELamK289FVflS130IVk3T6wNF0lychyIOHz/la2LUAeR+dXXgw+S/fO/ BEg6yoQMJSZXvXocSl0q/TtD30ZbGUmAgo+XcTO2xNUPIc0J1NQuIGHhwuVr9xXW2Y oaKFyn5dhtjsvcljxyT8+IrK9cSR6e0aJkeTowpY= Received: from disco-boy.misterjones.org ([51.254.78.96] helo=www.loen.fr) by disco-boy.misterjones.org with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94) (envelope-from ) id 1khYJG-00DFyo-I3; Tue, 24 Nov 2020 13:24:42 +0000 MIME-Version: 1.0 Date: Tue, 24 Nov 2020 13:24:42 +0000 From: Marc Zyngier To: David Brazdil Subject: Re: [RFC PATCH 3/6] kvm: arm64: Fix up RELR relocation in hyp code/data In-Reply-To: <20201119162543.78001-4-dbrazdil@google.com> References: <20201119162543.78001-1-dbrazdil@google.com> <20201119162543.78001-4-dbrazdil@google.com> User-Agent: Roundcube Webmail/1.4.9 Message-ID: X-Sender: maz@kernel.org X-SA-Exim-Connect-IP: 51.254.78.96 X-SA-Exim-Rcpt-To: dbrazdil@google.com, kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, james.morse@arm.com, julien.thierry.kdev@gmail.com, suzuki.poulose@arm.com, catalin.marinas@arm.com, will@kernel.org, mark.rutland@arm.com, ascull@google.com, ardb@kernel.org, kernel-team@android.com X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201124_082446_180990_2ED83F1B X-CRM114-Status: GOOD ( 24.52 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , kernel-team@android.com, Suzuki K Poulose , Catalin Marinas , linux-kernel@vger.kernel.org, Ard Biesheuvel , James Morse , linux-arm-kernel@lists.infradead.org, Will Deacon , kvmarm@lists.cs.columbia.edu, Julien Thierry , Andrew Scull Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="us-ascii"; Format="flowed" Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On 2020-11-19 16:25, David Brazdil wrote: > The arm64 kernel also supports packing of relocation data using the > RELR > format. Implement a parser of RELR data and fixup the relocations using > the same infra as RELA relocs. > > Signed-off-by: David Brazdil > --- > arch/arm64/kvm/va_layout.c | 41 ++++++++++++++++++++++++++++++++++++++ > 1 file changed, 41 insertions(+) > > diff --git a/arch/arm64/kvm/va_layout.c b/arch/arm64/kvm/va_layout.c > index b80fab974896..7f45a98eacfd 100644 > --- a/arch/arm64/kvm/va_layout.c > +++ b/arch/arm64/kvm/va_layout.c > @@ -145,6 +145,43 @@ static void __fixup_hyp_rela(void) > __fixup_hyp_rel(rel[i].r_offset); > } > > +#ifdef CONFIG_RELR > +static void __fixup_hyp_relr(void) > +{ > + u64 *rel, *end; > + > + rel = (u64*)(kimage_vaddr + __load_elf_u64(__relr_offset)); > + end = rel + (__load_elf_u64(__relr_size) / sizeof(*rel)); > + > + while (rel < end) { > + unsigned n; > + u64 addr = *(rel++); > + > + /* Address must not have the LSB set. */ > + BUG_ON(addr & BIT(0)); > + > + /* Fix up the first address of the chain. */ > + __fixup_hyp_rel(addr); > + > + /* > + * Loop over bitmaps, i.e. as long as words' LSB is 1. > + * Each bit (ordered from LSB to MSB) represents one word from > + * the last full address (exclusive). If the corresponding bit > + * is 1, there is a relative relocation on that word. > + */ What is the endianness of this bitmap? Is it guaranteed to be in CPU-endian format? > + for (n = 0; rel < end && (*rel & BIT(0)); n++) { > + unsigned i; > + u64 bitmap = *(rel++); nit: if you change this u64 for an unsigned long... > + > + for (i = 1; i < 64; ++i) { > + if ((bitmap & BIT(i))) > + __fixup_hyp_rel(addr + 8 * (63 * n + i)); > + } ... this can be written as: i = 1; for_each_set_bit_from(i, &bitmap, 64) __fixup_hyp_rel(addr + 8 * (63 * n + i)); > + } > + } > +} > +#endif > + > /* > * The kernel relocated pointers to kernel VA. Iterate over > relocations in > * the hypervisor ELF sections and convert them to hyp VA. This avoids > the > @@ -156,6 +193,10 @@ __init void kvm_fixup_hyp_relocations(void) > return; > > __fixup_hyp_rela(); > + > +#ifdef CONFIG_RELR > + __fixup_hyp_relr(); > +#endif > } > > static u32 compute_instruction(int n, u32 rd, u32 rn) Thanks, M. -- Jazz is not dead. It just smells funny... _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8EB04C2D0E4 for ; Tue, 24 Nov 2020 13:24:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4F6BC2083E for ; Tue, 24 Nov 2020 13:24:56 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=kernel.org header.i=@kernel.org header.b="iGIa9jId" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388023AbgKXNYq (ORCPT ); Tue, 24 Nov 2020 08:24:46 -0500 Received: from mail.kernel.org ([198.145.29.99]:35054 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387608AbgKXNYp (ORCPT ); Tue, 24 Nov 2020 08:24:45 -0500 Received: from disco-boy.misterjones.org (disco-boy.misterjones.org [51.254.78.96]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 9AA7C2083E; Tue, 24 Nov 2020 13:24:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1606224284; bh=SH24zETgIC2uK40KbauN9QWLDcUjyzI/5kjjC2KZ+fk=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=iGIa9jIdjELamK289FVflS130IVk3T6wNF0lychyIOHz/la2LUAeR+dXXgw+S/fO/ BEg6yoQMJSZXvXocSl0q/TtD30ZbGUmAgo+XcTO2xNUPIc0J1NQuIGHhwuVr9xXW2Y oaKFyn5dhtjsvcljxyT8+IrK9cSR6e0aJkeTowpY= Received: from disco-boy.misterjones.org ([51.254.78.96] helo=www.loen.fr) by disco-boy.misterjones.org with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94) (envelope-from ) id 1khYJG-00DFyo-I3; Tue, 24 Nov 2020 13:24:42 +0000 MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII; format=flowed Content-Transfer-Encoding: 7bit Date: Tue, 24 Nov 2020 13:24:42 +0000 From: Marc Zyngier To: David Brazdil Cc: kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, James Morse , Julien Thierry , Suzuki K Poulose , Catalin Marinas , Will Deacon , Mark Rutland , Andrew Scull , Ard Biesheuvel , kernel-team@android.com Subject: Re: [RFC PATCH 3/6] kvm: arm64: Fix up RELR relocation in hyp code/data In-Reply-To: <20201119162543.78001-4-dbrazdil@google.com> References: <20201119162543.78001-1-dbrazdil@google.com> <20201119162543.78001-4-dbrazdil@google.com> User-Agent: Roundcube Webmail/1.4.9 Message-ID: X-Sender: maz@kernel.org X-SA-Exim-Connect-IP: 51.254.78.96 X-SA-Exim-Rcpt-To: dbrazdil@google.com, kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, james.morse@arm.com, julien.thierry.kdev@gmail.com, suzuki.poulose@arm.com, catalin.marinas@arm.com, will@kernel.org, mark.rutland@arm.com, ascull@google.com, ardb@kernel.org, kernel-team@android.com X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2020-11-19 16:25, David Brazdil wrote: > The arm64 kernel also supports packing of relocation data using the > RELR > format. Implement a parser of RELR data and fixup the relocations using > the same infra as RELA relocs. > > Signed-off-by: David Brazdil > --- > arch/arm64/kvm/va_layout.c | 41 ++++++++++++++++++++++++++++++++++++++ > 1 file changed, 41 insertions(+) > > diff --git a/arch/arm64/kvm/va_layout.c b/arch/arm64/kvm/va_layout.c > index b80fab974896..7f45a98eacfd 100644 > --- a/arch/arm64/kvm/va_layout.c > +++ b/arch/arm64/kvm/va_layout.c > @@ -145,6 +145,43 @@ static void __fixup_hyp_rela(void) > __fixup_hyp_rel(rel[i].r_offset); > } > > +#ifdef CONFIG_RELR > +static void __fixup_hyp_relr(void) > +{ > + u64 *rel, *end; > + > + rel = (u64*)(kimage_vaddr + __load_elf_u64(__relr_offset)); > + end = rel + (__load_elf_u64(__relr_size) / sizeof(*rel)); > + > + while (rel < end) { > + unsigned n; > + u64 addr = *(rel++); > + > + /* Address must not have the LSB set. */ > + BUG_ON(addr & BIT(0)); > + > + /* Fix up the first address of the chain. */ > + __fixup_hyp_rel(addr); > + > + /* > + * Loop over bitmaps, i.e. as long as words' LSB is 1. > + * Each bit (ordered from LSB to MSB) represents one word from > + * the last full address (exclusive). If the corresponding bit > + * is 1, there is a relative relocation on that word. > + */ What is the endianness of this bitmap? Is it guaranteed to be in CPU-endian format? > + for (n = 0; rel < end && (*rel & BIT(0)); n++) { > + unsigned i; > + u64 bitmap = *(rel++); nit: if you change this u64 for an unsigned long... > + > + for (i = 1; i < 64; ++i) { > + if ((bitmap & BIT(i))) > + __fixup_hyp_rel(addr + 8 * (63 * n + i)); > + } ... this can be written as: i = 1; for_each_set_bit_from(i, &bitmap, 64) __fixup_hyp_rel(addr + 8 * (63 * n + i)); > + } > + } > +} > +#endif > + > /* > * The kernel relocated pointers to kernel VA. Iterate over > relocations in > * the hypervisor ELF sections and convert them to hyp VA. This avoids > the > @@ -156,6 +193,10 @@ __init void kvm_fixup_hyp_relocations(void) > return; > > __fixup_hyp_rela(); > + > +#ifdef CONFIG_RELR > + __fixup_hyp_relr(); > +#endif > } > > static u32 compute_instruction(int n, u32 rd, u32 rn) Thanks, M. -- Jazz is not dead. It just smells funny...