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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 974A9C678DB for ; Thu, 23 Feb 2023 10:23:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233924AbjBWKXO (ORCPT ); Thu, 23 Feb 2023 05:23:14 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55228 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234214AbjBWKW6 (ORCPT ); Thu, 23 Feb 2023 05:22:58 -0500 Received: from mail-pj1-x1029.google.com (mail-pj1-x1029.google.com [IPv6:2607:f8b0:4864:20::1029]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 01DF12D66 for ; Thu, 23 Feb 2023 02:22:54 -0800 (PST) Received: by mail-pj1-x1029.google.com with SMTP id k21-20020a17090aaa1500b002376652e160so1129116pjq.0 for ; Thu, 23 Feb 2023 02:22:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=anyfinetworks-com.20210112.gappssmtp.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=8XdgTiTQNQEwsXE5pqovlVd84glWLCGpX2xXzua3LWo=; b=VSUKpsgMMB3wW4V/PL/BsM/fogLl/13whlKI52Bd29FJSvDxaM+KHBEcBBJ0lf2Skt s94Hco/mdtp9QSRaDMDdC2xam7ldKj1iYv0lWMBTkhBXalm3gBd0+C7/OeQ7vuVPb4Jr sqFGryW442ZIWkxq/nTLDXmlX36nsrmzua2/sgzayKhVIIH9dZlQ3/b1ekO6AuOIFoQl eb2tVsGAzmwNJQ6/eMSuWIym51Pma27tVy+R7RMCSvgU0zW8z/VSM3mcD75AwnsSlm3D i7GwpYj1gyabBmXQP4sObtEh909yV64c1/GhKjjqFZhNeuD1BBIdSCAsVHSW0qQ19/QG bxsQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=8XdgTiTQNQEwsXE5pqovlVd84glWLCGpX2xXzua3LWo=; b=HrZasL5ts5g/MLDNEjSRUDv8kLPaLkxw2yWzCe+DAykPvsQDxxaBuvAk5m1P//ifX2 o922bJN8ueNKDq+1kCwnc+Hbt337RQ32NDLbnUjDJ90ZfrGcVmxQ6qAz+UMOn8eE9R6P nT9CW5IS7rKnZD3DLHvOdHCbAhxMEp31RLXtgRzAncAWBjrZkypB2MI9aKLQYNnTQrdL vye6Zcg0wiPV1WarRYE2R56kZrzpQBAThjMUblBTfore8U3LLP37o9GtxUdWwPKAV9nM eGPxA6sJaeQ/cO7uVyj8x0a1ebLKUoxLpwpmKYiLQJXLxk7QogrLQqI+jFhumY/NAd62 gTgA== X-Gm-Message-State: AO0yUKUJD5byt8OB1GevRHzKCvHTqehLo26vbuDj1E3Vh0v57RXjKjTU yPfvAdkoOT97sNn2UKc7WNutDsLYG48JFa80lt0zng== X-Google-Smtp-Source: AK7set9I0Pd1vzjhdIfJFuY1Qt1ZAEkjuKoYDYuiisbN1VUQrOG44GsRAR3GmjhiWJl7kyBTulghkDn8DFnffgIEDVs= X-Received: by 2002:a17:90b:384d:b0:237:50b6:983c with SMTP id nl13-20020a17090b384d00b0023750b6983cmr1056123pjb.116.1677147774407; Thu, 23 Feb 2023 02:22:54 -0800 (PST) MIME-Version: 1.0 References: <20230222161222.11879-1-jiaxun.yang@flygoat.com> <20230222161222.11879-3-jiaxun.yang@flygoat.com> In-Reply-To: <20230222161222.11879-3-jiaxun.yang@flygoat.com> From: Johan Almbladh Date: Thu, 23 Feb 2023 11:22:43 +0100 Message-ID: Subject: Re: [PATCH 2/2] MIPS: ebpf jit: Implement R4000 workarounds To: Jiaxun Yang Cc: linux-mips@vger.kernel.org, linux-kernel@vger.kernel.org, tsbogend@alpha.franken.de, paulburton@kernel.org, bpf@vger.kernel.org, Alexei Starovoitov , Andrii Nakryiko , Daniel Borkmann Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Feb 22, 2023 at 5:12 PM Jiaxun Yang wrote: > > For R4000 erratas around multiplication and division instructions, > as our use of those instructions are always followed by mflo/mfhi > instructions, the only issue we need care is > > "MIPS R4000PC/SC Errata, Processor Revision 2.2 and 3.0" Errata 28: > "A double-word or a variable shift may give an incorrect result if > executed while an integer multiplication is in progress." > > We just emit a mfhi $0 to ensure the operation is completed after > every multiplication instruction accorading to workaround suggestion > in the document. > > Signed-off-by: Jiaxun Yang > --- > arch/mips/Kconfig | 4 +--- > arch/mips/net/bpf_jit_comp32.c | 4 ++++ > arch/mips/net/bpf_jit_comp64.c | 3 +++ > 3 files changed, 8 insertions(+), 3 deletions(-) > > diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig > index df0910e3895c..5ea07c833c5b 100644 > --- a/arch/mips/Kconfig > +++ b/arch/mips/Kconfig > @@ -63,9 +63,7 @@ config MIPS > select HAVE_DEBUG_STACKOVERFLOW > select HAVE_DMA_CONTIGUOUS > select HAVE_DYNAMIC_FTRACE > - select HAVE_EBPF_JIT if !CPU_MICROMIPS && \ > - !CPU_R4000_WORKAROUNDS && \ > - !CPU_R4400_WORKAROUNDS Is the R4400 errata also covered by this workaround? > + select HAVE_EBPF_JIT if !CPU_MICROMIPS > select HAVE_EXIT_THREAD > select HAVE_FAST_GUP > select HAVE_FTRACE_MCOUNT_RECORD > diff --git a/arch/mips/net/bpf_jit_comp32.c b/arch/mips/net/bpf_jit_comp32.c > index ace5db3fbd17..fee334544d2f 100644 > --- a/arch/mips/net/bpf_jit_comp32.c > +++ b/arch/mips/net/bpf_jit_comp32.c > @@ -446,6 +446,9 @@ static void emit_mul_i64(struct jit_context *ctx, const u8 dst[], s32 imm) > } else { > emit(ctx, multu, hi(dst), src); > emit(ctx, mflo, hi(dst)); > + /* Ensure multiplication is completed */ > + if (IS_ENABLED(CONFIG_CPU_R4000_WORKAROUNDS)) > + emit(ctx, mfhi, MIPS_R_ZERO); > } > > /* hi(dst) = hi(dst) - lo(dst) */ > @@ -504,6 +507,7 @@ static void emit_mul_r64(struct jit_context *ctx, > } else { > emit(ctx, multu, lo(dst), lo(src)); > emit(ctx, mflo, lo(dst)); > + /* No need for workaround because we have this mfhi */ > emit(ctx, mfhi, tmp); > } R4000 is a 64-bit CPU, so the 32-bit JIT implementation will not be used. From the Makefile: ifeq ($(CONFIG_32BIT),y) obj-$(CONFIG_BPF_JIT) += bpf_jit_comp32.o else obj-$(CONFIG_BPF_JIT) += bpf_jit_comp64.o endif > > diff --git a/arch/mips/net/bpf_jit_comp64.c b/arch/mips/net/bpf_jit_comp64.c > index 0e7c1bdcf914..5f5a93f997bc 100644 > --- a/arch/mips/net/bpf_jit_comp64.c > +++ b/arch/mips/net/bpf_jit_comp64.c > @@ -228,6 +228,9 @@ static void emit_alu_r64(struct jit_context *ctx, u8 dst, u8 src, u8 op) > } else { > emit(ctx, dmultu, dst, src); > emit(ctx, mflo, dst); > + /* Ensure multiplication is completed */ > + if (IS_ENABLED(CONFIG_CPU_R4000_WORKAROUNDS)) > + emit(ctx, mfhi, MIPS_R_ZERO); > } > break; > /* dst = dst / src */ > -- > 2.37.1 (Apple Git-137.1) >