From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f170.google.com (mail-pl1-f170.google.com [209.85.214.170]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E1292A920 for ; Fri, 27 Dec 2024 00:23:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.170 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735259011; cv=none; b=JSjIXrhWcs3U9BVss3ulWIT/KNtsY0z0XzrkXLR11YVIlJsBT5/KrPqR7/ELb8bFF5g2eB1xVbI9RUAPdYS7jEz+gq+AG7/5nM8u+hBpXhsfAFtx8MqfDrIAaEyRNWy0qF0XJWRi6nNXHtjJqZMzSkJ4wL05UjC3w61cmNH5zFw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735259011; c=relaxed/simple; bh=RjmESX1QcfzoOG/ifZILFYkxkqyTluMBYAu+dEk96Rk=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Bwn/OlU/6V4jlXxABUMhGRudz0tOiBc3Yd8NGh6meM/AoloxZMQQb0htXZWA/7JKHgGnJBT8fbQvtLRKH/yJ4Jb2yGo6sAWzMF+tH5ScgqzxI20BkwTGnuSuihldQgRFN+rkt4vAN2Is15Iu4KofV9ZxZM4kt76CjbXaA472dXA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=eIDlMCtl; arc=none smtp.client-ip=209.85.214.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="eIDlMCtl" Received: by mail-pl1-f170.google.com with SMTP id d9443c01a7336-219f6ca9a81so528265ad.1 for ; Thu, 26 Dec 2024 16:23:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1735259007; x=1735863807; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=wnK8GTp4kq3AREja2sD0O7Kb+4zQCe/fm63LSJLYU5k=; b=eIDlMCtlXiaRkdfND4rkTdj5lIlqezfcv0mDVh9jk1E4mgasxv01Gf8H0zu5AkqB2f N4XMvwUmiEGmkJCYXh0y00MJYmdSl/hEy6d4WpDT75Jt/HlcD0BK65W3aNppz4LQ2E98 qme4qcqj3iKMnxzk+V9O3jP4U+M0S6SgLvTsEB4pJ1y6kLlN2aGPtlDOoYgdNxdyY2As x8ZLbLErSMatrFOqETmvRR9JQj/LXRFULM8JDU8G/CTXNSNbAAlK9oE0DArIk/JYhJCv nJnunRcufCph6FaIpy/L6ASk84rAI1Yp1BzsY6fWysubdyGKXS7HlTgZz9f5jr5b6AsI GZZA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1735259007; x=1735863807; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=wnK8GTp4kq3AREja2sD0O7Kb+4zQCe/fm63LSJLYU5k=; b=ZsG/oFAmNtnlnGU8FvTJ8BkaLtgiMCc7rKEXE4psaqzZbQwN+iartWbMfNDeBwpF/M gz54fxffzYw2KQIh6CTinLJqiDYL04gmBDyf0TGwmgguBnPXxFJk2XiWGqbpKZZhUpF/ GNFBxyFOOH3r4ijAtarui0OBzvNt0s2T11ZBpDj6/OnTc2dhgewsyElDsPBXcqcnPhaE OFY6lpKuNr14vSs/21wu8RVGI08sSXwN2p+2qJb+wMj+D4aa0TE1EURplDTGNlg2vyfx MyU+VUK2lZtStXw4z74DWSr2rQ53e7mEZ4K7aseKu6hJG37lZItOb/SrmSlWAVBlbB9c BYmQ== X-Forwarded-Encrypted: i=1; AJvYcCXB1UpBgiKshyb92Q9TQT4IFg8o4L5Y2I52uGvS/H+VeBLvpQjQCI8n9dT2UA/fZcFbh4crvzaJ1nPBUco=@vger.kernel.org X-Gm-Message-State: AOJu0Ywt/+i2lz5kjdzeJnUjA3Z2OJUwucFRE4gKA7etJKB3SyiQhueh nsEjZ5qBzt+NUuaBXUbmIV5yklH/wd0M4GxXwhKrWYldd/0LH0MIDiELHuuBsw== X-Gm-Gg: ASbGncu1vKHLX3ZWrHQlaIDNYk/dFyFSsXEBQ8XuYe0lRk9TFw7eZELaGVetv+wv8r9 fCWDzX1CV26NLzl6/0Ru56+Yaq48VuiQM6lLMk5GKOkxEsD7alfa6tAe1/rN2V2TFvFNKahrQ0E jh05gyWcNmOetPVdid4FzCnc/whyzv7RYI+RLfT8P9Vvream1icbK3lFMghEN+naWH3TbMu45fU rz4OLskcB5n/1Lm0BxHHtH0cSq5FE0vKISZXjmlJWncBf8VJ8FOkss5m3dUK5yJiHdwI74flv4R a9LWNE0zCp7gcFIueU0= X-Google-Smtp-Source: AGHT+IHpHqj1gmmKbJ5wgeQtJmbecxZqinDCXpnpb8KG6ML+4CQGLd/qnQTT2vlVqTeJ+vFDw2fSfA== X-Received: by 2002:a17:903:2350:b0:20b:5e34:1850 with SMTP id d9443c01a7336-219e773876bmr10975425ad.23.1735259006920; Thu, 26 Dec 2024 16:23:26 -0800 (PST) Received: from google.com (40.155.125.34.bc.googleusercontent.com. [34.125.155.40]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2f2ed644816sm16394234a91.25.2024.12.26.16.23.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Dec 2024 16:23:26 -0800 (PST) Date: Fri, 27 Dec 2024 00:23:22 +0000 From: Peilin Ye To: Xu Kuohai Cc: bpf@vger.kernel.org, Alexei Starovoitov , Eduard Zingerman , Song Liu , Yonghong Song , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , "Paul E. McKenney" , Puranjay Mohan , Catalin Marinas , Will Deacon , Quentin Monnet , Mykola Lysenko , Shuah Khan , Josh Don , Barret Rhoden , Neel Natu , Benjamin Segall , David Vernet , Dave Marchevsky , linux-kernel@vger.kernel.org Subject: Re: [PATCH RFC bpf-next v1 2/4] bpf: Introduce load-acquire and store-release instructions Message-ID: References: <6ca65dc2916dba7490c4fd7a8b727b662138d606.1734742802.git.yepeilin@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: On Thu, Dec 26, 2024 at 11:07:10PM +0000, Peilin Ye wrote: > > > + if (BPF_ATOMIC_TYPE(insn->imm) == BPF_ATOMIC_LOAD) > > > + ptr = src; > > > + else > > > + ptr = dst; > > > + > > > + if (off) { > > > + emit_a64_mov_i(true, tmp, off, ctx); > > > + emit(A64_ADD(true, tmp, tmp, ptr), ctx); > > > > The mov and add instructions can be optimized to a single A64_ADD_I > > if is_addsub_imm(off) is true. > > Thanks! I'll try this. The following diff seems to work: --- a/arch/arm64/net/bpf_jit_comp.c +++ b/arch/arm64/net/bpf_jit_comp.c @@ -658,9 +658,15 @@ static int emit_atomic_load_store(const struct bpf_insn *insn, struct jit_ctx *c ptr = dst; if (off) { - emit_a64_mov_i(true, tmp, off, ctx); - emit(A64_ADD(true, tmp, tmp, ptr), ctx); - ptr = tmp; + if (is_addsub_imm(off)) { + emit(A64_ADD_I(true, ptr, ptr, off), ctx); + } else if (is_addsub_imm(-off)) { + emit(A64_SUB_I(true, ptr, ptr, -off), ctx); + } else { + emit_a64_mov_i(true, tmp, off, ctx); + emit(A64_ADD(true, tmp, tmp, ptr), ctx); + ptr = tmp; + } } if (arena) { emit(A64_ADD(true, tmp, ptr, arena_vm_base), ctx); I'll include it in the next version. I think the same thing can be done for emit_lse_atomic() and emit_ll_sc_atomic(); let me do that in a separate patch. Thanks, Peilin Ye