From patchwork Thu Jul 13 16:49:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Duyck X-Patchwork-Id: 13312526 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 5CD9AC0015E for ; Thu, 13 Jul 2023 16:50:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-ID:Date:Cc:To:From :Subject:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=42hIy4D6I7ht4FQmUJVNDpgwKCWF9HV8ZIQN6gJAGUw=; b=jKgd88Jo50czWK +grk1gdqzOFazaRJ1oI3YeVofRPNvliFODMc19CO5X3AR7yM1NSgiII5MdyQchyTFj9VkMTL7OWjk VvumCErnFFCxSQe/Syjqj4JNSoZud+pKldaZKQ6fhXB7VKmkZ8n8LoGeXUVfGmSnyq5/XvXQ8FmSQ fDC6oIkutjlJWsu5qTjFkRlWy2m/v1UxzmBgry9HURRrTF3cF1Cu+tyumnNd+xGBCvtjaEQ6ILCIZ cVWX80wdzK88q3NVWqIEMjA4Wtqx9bT4KE6awhJAO685zKfFJVCzVPCn/0K6nUxU1hO61DW+rQcnt PHtx39XQP2T+JMLGCwIA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qJzVb-003weU-2E; Thu, 13 Jul 2023 16:49:39 +0000 Received: from mail-pf1-x42e.google.com ([2607:f8b0:4864:20::42e]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qJzVY-003wdJ-2o for linux-arm-kernel@lists.infradead.org; Thu, 13 Jul 2023 16:49:38 +0000 Received: by mail-pf1-x42e.google.com with SMTP id d2e1a72fcca58-666eef03ebdso605211b3a.1 for ; Thu, 13 Jul 2023 09:49:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1689266973; x=1691858973; h=content-transfer-encoding:mime-version:user-agent:message-id:date :cc:to:from:subject:from:to:cc:subject:date:message-id:reply-to; bh=brLFB/e/7Oi0GsJYQKM7Ftuw8LYNUfDkAuTAqWsvQ7M=; b=Bpm7AH5+MZQDXC1YhqXdmriKkr1YpuXICsupjW+P5fuHWR5vG+hLmD0ArFqSW0GsgO 3pRbaQdD+hyxx3/hXfqKAzaVF3vIpmKp8F6SUe/MGm7LeGzW53lWYVnGZMwcwgi39UX+ MgRmrOx/gNQ66Lebaa5mmem/JqLHm1cqw7WXSGre8WKSxsYhQVxquLcNv6eS8wkZH24i 1DBiwx0h9lJmV2B1SXITA/IfJMmwRvMG6zr6yGxyBa8/fVj/7fuYNQw7r3IQYf09q+dn 8y2J0mHdQO+Rt1eJaTCAQBazhLUJdcc1mWt5W/AmI5syq5mCqyDGfTzC4NkuGO3mbOgR PJYA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689266973; x=1691858973; h=content-transfer-encoding:mime-version:user-agent:message-id:date :cc:to:from:subject:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=brLFB/e/7Oi0GsJYQKM7Ftuw8LYNUfDkAuTAqWsvQ7M=; b=S28m2vsinc5TENvgyT9sSy7h2IE8EBJGj1X8qPoKqtj22+KklUaA9NWG5XxyVxdvXN 4BBXI5jGE2ZPZ5RC0KVkf+p1rPwba6u9se6Xb/ukdGcc5NHqYgEoeAqJ1Fz4FZrdZL1N Knl9zzEZh4K9mnWjy0Eu0ca3pHGi2wW3rLMkOh1osaIpWI8dBk9+xeRKzAO0C6KiQLPl IHw9ZvIXbENhpl9Bawck5H9TMgeMDmHnF7WI22f9VdRg5awY1Gy3l9unf62kDF3Kb1Uz YtzpnJpPVhIbr8QbJbLKPjg4RNSaIbXQK/jSAFGlqWj28vmNa89E+K3ZQ+a28DSk6Yay 4UYQ== X-Gm-Message-State: ABy/qLYaPdssV/LuZengrmdXSz73spvqMr6rI2+AHdlbiLMK+FQaAyHW T69nm/KMm4Al1I65sfjEhR9YZWIaEg4= X-Google-Smtp-Source: APBJJlE2/yOvvkT5TNtK8z3rt8q1rYhwXnU6AtA4Mbain02P9huskQ4mV2V63ozKdU06FH6qFSLsAg== X-Received: by 2002:a05:6a00:124b:b0:668:82fe:16e2 with SMTP id u11-20020a056a00124b00b0066882fe16e2mr1906844pfi.16.1689266973264; Thu, 13 Jul 2023 09:49:33 -0700 (PDT) Received: from ahduyck-xeon-server.home.arpa ([2605:59c8:448:b800:9e5c:8eff:fe4f:f2d0]) by smtp.gmail.com with ESMTPSA id 18-20020a056a00073200b006833b73c749sm2341955pfm.22.2023.07.13.09.49.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Jul 2023 09:49:32 -0700 (PDT) Subject: [PATCH bpf] bpf, arm64: Fix BTI type used for freplace attached functions From: Alexander Duyck To: bpf@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: xukuohai@huaweicloud.com Date: Thu, 13 Jul 2023 09:49:31 -0700 Message-ID: <168926677665.316237.9953845318337455525.stgit@ahduyck-xeon-server.home.arpa> User-Agent: StGit/1.5 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230713_094936_905332_5EC3D9B8 X-CRM114-Status: GOOD ( 12.61 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Alexander Duyck When running an freplace attached bpf program on an arm64 system w were seeing the following issue: Unhandled 64-bit el1h sync exception on CPU47, ESR 0x0000000036000003 -- BTI After a bit of work to track it down I determined that what appeared to be happening is that the 'bti c' at the start of the program was somehow being reached after a 'br' instruction. Further digging pointed me toward the fact that the function was attached via freplace. This in turn led me to build_plt which I believe is invoking the long jump which is triggering this error. To resolve it we can replace the 'bti c' with 'bti jc' and add a comment explaining why this has to be modified as such. Fixes: b2ad54e1533e ("bpf, arm64: Implement bpf_arch_text_poke() for arm64") Signed-off-by: Alexander Duyck Acked-by: Xu Kuohai --- arch/arm64/net/bpf_jit_comp.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/arch/arm64/net/bpf_jit_comp.c b/arch/arm64/net/bpf_jit_comp.c index 145b540ec34f..ec2174838f2a 100644 --- a/arch/arm64/net/bpf_jit_comp.c +++ b/arch/arm64/net/bpf_jit_comp.c @@ -322,7 +322,13 @@ static int build_prologue(struct jit_ctx *ctx, bool ebpf_from_cbpf) * */ - emit_bti(A64_BTI_C, ctx); + /* bpf function may be invoked by 3 instruction types: + * 1. bl, attached via freplace to bpf prog via short jump + * 2. br, attached via freplace to bpf prog via long jump + * 3. blr, working as a function pointer, used by emit_call. + * So BTI_JC should used here to support both br and blr. + */ + emit_bti(A64_BTI_JC, ctx); emit(A64_MOV(1, A64_R(9), A64_LR), ctx); emit(A64_NOP, ctx);