Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp577573pxb; Thu, 19 Nov 2020 08:31:02 -0800 (PST) X-Google-Smtp-Source: ABdhPJwLwTdEQGXa5RPCmR9GvlrWXVg7bOZ22YZ1eIfuBQswq9Ndkf1rtUGqAsAgJXr+I+MwNmas X-Received: by 2002:a17:906:d8ab:: with SMTP id qc11mr1107082ejb.64.1605803461908; Thu, 19 Nov 2020 08:31:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605803461; cv=none; d=google.com; s=arc-20160816; b=YRzkpAD8tJ9Dj0y03LIyHPc6KhRMgT4v4rq1opzLpM4DiwKO6WeE+81b59D6uChCRQ qU50lKA9Tt/P2a/cJ1QW8ocjlaXtoJzq+zSGouzQ46j5zzIBe5IoNVl0TgQl3aoqfW5f NKh4BnRUPGE7aWyp6LxqZipXz74FyRU3hjYaQrEVM7gqgQ/oW4Wx8RoSCzqks8E2cj9q +OVuoF5e0bwy8jFXKpLxLMgoOnpiC3puazhkpNTci8DkqgdmWdC4GzWHDZlXoLI2IiOe Hth4zj3ss2ij7f0IkQuqReEie/GUFkBMOtYxAbgmuPDmiL7hNQG/pjYnncDNrhCtatmW 1NvA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=4v/cI0W618Ll5oLWISpFhPxrIsIv3CzVb2jjngYJV1Y=; b=YdL4rv9nVWL5B9wgcrph9xNc8DUl2szWkpbj65XFPXIfGHpdsZKY05ZNC/cco8cHOx +0iwMhruYQ9yH4AvcJtFC0pMpnewB/qQM97JHl3+rZlAeG9xdDoA/sV6pPQsy1DfvY21 AN6f2qg3EGMnRDjKpLUYOCJbOw1xjqpNYZdyzctD0QsOqRjAUUogiyeZipXNQzLJTWOT Aq0mJ8gpuDL2sYL6SbBDMtS1npfHWzjuBL78Rjt/a8tG6OPrMYztvY7Q4I6ymdcOMoA+ Biiq7i/7qc4Z/UIcJXnfFwjG36V3RI/xxktsRWNU1J3VO/hYn/l05qy/NrHgtflFtRBw SU2A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=d5PO+tqR; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id q4si89574eji.62.2020.11.19.08.30.38; Thu, 19 Nov 2020 08:31:01 -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; dkim=pass header.i=@google.com header.s=20161025 header.b=d5PO+tqR; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728684AbgKSQZ5 (ORCPT + 99 others); Thu, 19 Nov 2020 11:25:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53764 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728011AbgKSQZ4 (ORCPT ); Thu, 19 Nov 2020 11:25:56 -0500 Received: from mail-ed1-x544.google.com (mail-ed1-x544.google.com [IPv6:2a00:1450:4864:20::544]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 749BFC0613CF for ; Thu, 19 Nov 2020 08:25:56 -0800 (PST) Received: by mail-ed1-x544.google.com with SMTP id l5so6431691edq.11 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=Ij1Wsdj1yPsJ/tpQG9dUrmH2+Dro4dI3RiK6lFf5k7r7dPX0iERDMNc86IDvt2svkl 2mVKPMW1kgY5gQUa0Uck+Ka6tkOGZWWt9tWJ8SgprIaExb6o02/2Lm2DTnfonK1W33B1 7yHbLkM0H87fQ9yHudYvFS1nGDTiuI3O5QKK7ox6zo7MLt8cRP0xKt9KiyInUojms+Xu KsWW64vlmasoBkl8P71w3IRgz7nd/CvEl8F6VDNT7dNTHkn/TVPycKekcWxMriFEJCqc lM1umZv5zckWGG8ux5zZ3jeMW0+h8u7vBBQksraaRiedeNpi+gZyrLdcZslFiYb7Xk0H bqoQ== X-Gm-Message-State: AOAM532KU35e4ih7UtJ/uendh5aGoDkUYU7T6Hdsvb3wJ+eLm2B1gHnf o5hLvVLjYHkTdhBBDJVmasw0LQ== 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 Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Marc Zyngier , James Morse , Julien Thierry , Suzuki K Poulose , Catalin Marinas , Will Deacon , Mark Rutland , Andrew Scull , Ard Biesheuvel , kernel-team@android.com, David Brazdil 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 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.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) -- 2.29.2.299.gdc1121823c-goog