From patchwork Thu Nov 19 16:25:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Brazdil X-Patchwork-Id: 11918209 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.7 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT 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 5D2A8C63697 for ; Thu, 19 Nov 2020 16:26:38 +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 C85DF22240 for ; Thu, 19 Nov 2020 16:26:37 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="b3fWKip/"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="d5PO+tqR" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C85DF22240 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com 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-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=AH0ah2NpYZzZS/z6cFnQpEgFpA+Z0BXo5Fh5Rfezo7E=; b=b3fWKip/J6j7E5PIJZnB6YjtC XkXr6gA32Ezg3D5tKlm0nBFnfM+kPsPX4Q2PMJ8yNHuovmX4eLNwVAtzZbQtgAMVHRh1NyNFEmuoW XHTzm5qkwL0HaH6p+vV2EgHD645XhF45Ks6mI/QvDn/bsH4XzJ4ivKVvaOvz9+0MFkFcsAh8SIY7e oinKuDdLol3zbcN0uKP8uWf+bf1aw5CMV36nk+FVl5MTru5eKPOanxk/qlXhiOkIaNJsDgDlpE4k2 JLa0q53XvDgQ2cJ9PHyMXxEbZ0Gtdo7AAAdhmjzJnQF6b1cTTyyqlLqOwFA2UonSVM+rot9dK3sfi QBHE/BJlw==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kfml6-0004GZ-1A; Thu, 19 Nov 2020 16:26:08 +0000 Received: from mail-ed1-x544.google.com ([2a00:1450:4864:20::544]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kfmku-0004D3-Ka for linux-arm-kernel@lists.infradead.org; Thu, 19 Nov 2020 16:25:57 +0000 Received: by mail-ed1-x544.google.com with SMTP id t9so6453433edq.8 for ; Thu, 19 Nov 2020 08:25:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=4v/cI0W618Ll5oLWISpFhPxrIsIv3CzVb2jjngYJV1Y=; b=d5PO+tqR8NqolGIpflVwHQcaoSm8nizbEKWRPNduNGR++veNurs6hl8d+bpaVieFyx N/4qzptR0qOSoxQx7FQPsoe+iJswnHDVYtCadJO3C2slcCcPefUTQ+zOiNyarho+GJTQ eQVq93/itpn3uOMr/bNlKeAjhJZdy4EqJV6kjmkrHbofx2egXY3zQ+yRKs+a7dQtwgdK 4NoSRABTZAqopd6clg6Riim7meD6ewWkye8RYV/TV41uhgV3OcI7IOBtaWy6jDfV+Jfn HS8RCnV4PSHXaSeawTEOygjXqwZVK8R/FKpjfbB4tqH67KPho4pLvDzc9Uy4bjYb/kik IvoA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=4v/cI0W618Ll5oLWISpFhPxrIsIv3CzVb2jjngYJV1Y=; b=LZC83uQKqKlr7B8uBwBwRXxVrLh2sITZrlSlabRYJQc7Z16QP9nsF2eAxNOTJQYUXq SeHzQjOx5ACDt24qar4k2UUQ6bYij6Q2Av30zNgGXvlcbrDko5lSiMGKl1zEciWLd/ZH 3HnWYzLgkAldIVYQiyKzOkXsy+ZjQaYgaDYyXRN4+Q8ZkemOjfF0QGZgpIc1xNKegEGl 5Zhqwg3iCOnBo++gdujrszBrxjhAK4BrglZu9emTGeTteM6ira7MnYrtVpP2ZRczHhjW dFvlMTFsIuElwMP+mtHV7h9vLaugrOlvO1YhykdNB1LOBwnestui4aFKXC8J7TAInMlq iKTQ== X-Gm-Message-State: AOAM533hcV4FFWvIB+NaYui2481fIpg7ftHgIkQ8p7cuMxjUkX6Ep1BI pI8a5bvyoDEfuST5ei4OdqJi5aPJt1vPDw== X-Google-Smtp-Source: ABdhPJwsWb2PZ6sVei/sp7eotqJ6Uj+ntArrx/BCAAQKZymcK4INkpViSTd4Aa9KHDTnkjsffwkiyQ== X-Received: by 2002:a50:ccdb:: with SMTP id b27mr9198862edj.253.1605803154843; Thu, 19 Nov 2020 08:25:54 -0800 (PST) Received: from localhost ([2a01:4b00:8523:2d03:9843:cd3f:f36b:d55c]) by smtp.gmail.com with ESMTPSA id k2sm84334ejp.6.2020.11.19.08.25.53 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 19 Nov 2020 08:25:53 -0800 (PST) From: David Brazdil To: kvmarm@lists.cs.columbia.edu Subject: [RFC PATCH 3/6] kvm: arm64: Fix up RELR relocation in hyp code/data Date: Thu, 19 Nov 2020 16:25:40 +0000 Message-Id: <20201119162543.78001-4-dbrazdil@google.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201119162543.78001-1-dbrazdil@google.com> References: <20201119162543.78001-1-dbrazdil@google.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201119_112556_879515_10094378 X-CRM114-Status: GOOD ( 19.00 ) 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 , Marc Zyngier , linux-kernel@vger.kernel.org, James Morse , linux-arm-kernel@lists.infradead.org, Catalin Marinas , David Brazdil , Will Deacon , Ard Biesheuvel , Julien Thierry , Andrew Scull Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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. + */ + for (n = 0; rel < end && (*rel & BIT(0)); n++) { + unsigned i; + u64 bitmap = *(rel++); + + for (i = 1; i < 64; ++i) { + if ((bitmap & BIT(i))) + __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)