Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp2925935pxu; Mon, 7 Dec 2020 21:34:45 -0800 (PST) X-Google-Smtp-Source: ABdhPJwUfaHkzZHjWTVYdMVoBxniPvv7tnqm5sQ6jTubWTqzjZ0GzdY5Fj0IgpVBlQN0KdlgBKyP X-Received: by 2002:a50:f40e:: with SMTP id r14mr22362108edm.5.1607405685160; Mon, 07 Dec 2020 21:34:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1607405685; cv=none; d=google.com; s=arc-20160816; b=GZ9HKi/EgWyEGlbfqFE/IhOst5rg+zlWPNDLrGGqVUPoCgAkB4FcEw8aaOv9oYQxZT 7E8lIAKFd8r4aMMrZSuqj/QVUy02/GawJTEcoO9ynskwZBc3Kj4gO0y0k+PMUGaWCez9 XYL/MXj2OOrNuZUyo+sd9wr4hMISpwQzcGFvu8PbiTS5gAHz3FoxStUKPXtLgj+g7dGy RrV0o87qx4wqULtXVlt6X/WIDuaHE8hOd+3zCx/aRStttvwb3onSU2SdYibPnC4asuma mSSd/wMQpfhf4wA7IrLGcIpg0ZUjTZWGQtUmq1rizPvU38IjnHtEFgOBemh1fvAmOnjL yOXA== 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:subject :references:in-reply-to:message-id:cc:to:from:date:dkim-signature; bh=F/C3M7PpJplaz2NlfMsMr7Z2jIBADqhdF6BrYFQrE2U=; b=AS4SxjNB969PGx5BQl9DWU605T+7fSGXeIo7uBY5Xa8Kw8s31yHkYbF33Tog6VGRcB /BhH2umvLm1qOoeOAwKQbzAVxwCsCpcDPJTqSUKbiXMwkQmPUyVz73C/xYJb3OCYxX9G vij6zFDceRBx82URjqsJcMe8e3mnIvxcdmXpEqaL8YjTWKxI2T7HF47A0re15Cqrc8pW nBP8WeBtLBStVXeIkhOsXfeDvbgsZ6jipXDKJCN3DzIumErxy/n9HFeF+6g8mghFreD1 eY8YziALztK5Oeb1P3n4ZEpPElSidc/wcb1SYRvE4zYHgYWSgf8sGyi5nc2q6hAVAJlF ML4Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=uPiDefoQ; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h4si7613595ejk.480.2020.12.07.21.34.17; Mon, 07 Dec 2020 21:34:45 -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=@gmail.com header.s=20161025 header.b=uPiDefoQ; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726590AbgLHFca (ORCPT + 99 others); Tue, 8 Dec 2020 00:32:30 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39390 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726068AbgLHFc3 (ORCPT ); Tue, 8 Dec 2020 00:32:29 -0500 Received: from mail-oi1-x22a.google.com (mail-oi1-x22a.google.com [IPv6:2607:f8b0:4864:20::22a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E82CDC061749; Mon, 7 Dec 2020 21:31:48 -0800 (PST) Received: by mail-oi1-x22a.google.com with SMTP id s75so15168265oih.1; Mon, 07 Dec 2020 21:31:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:message-id:in-reply-to:references:subject :mime-version:content-transfer-encoding; bh=F/C3M7PpJplaz2NlfMsMr7Z2jIBADqhdF6BrYFQrE2U=; b=uPiDefoQYkKUSYVjpVcGFbjGGdgwvk2tmiacvGTPf1f1XKPLLEnQVTwTCx8tWNScnC 5j6c5sfjBEHrnhNhCj80/FWk0MTp670DUW5Dv4G2IUCx3Yd324y+YBTw3C7sot2KNTxS eCd3u/BKvQq6Lpsj9pg4Rx9/ID1ezkPBxSBAbr8Jo3UhV8nfB4LGtur/M6evKWpsYeYr Kta/pLzpmNREVmoWhp6gm736Rm4VmhVwhQGYxgwokNPamv1ZXQjxZyDMm48/vCgeZrty wSK63DtyX5nZNX5tTgWgFTkRVDrwHvF2voN8metmYSxDRY2JPRc2BNn9ZyShUI48DnYx jpbw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:message-id:in-reply-to :references:subject:mime-version:content-transfer-encoding; bh=F/C3M7PpJplaz2NlfMsMr7Z2jIBADqhdF6BrYFQrE2U=; b=Yj3+PodwHv4IHqN6pEM54QjgYmla+7zdSq5uCsHEPb4Cvl24ck0M70n8Ym7PhGiwEM vzu1lhXtqtk0n0+tKMP4cnBS3UMjgWFPhyMDHzbSKL7O2i78fvjezgJK40lHBrReqlJ7 PUTf0bC1sXMiQ6WDPT1Q3RgnJ3aiaTsn9xYWSiaEe43ePJY9m13B58ff4F/d+OiI6h+F gBeirQPdsfhEjYLHUkz2lKm7t+NTTxmAfAAXsIVTjy2pbJBiXtNwoNTqovKdePnu96Yl RITqXEgIIYSL55XKgvsfFmtVgdORhVpWK2Qb1jOBl93xr0O8JbKJsqsyQy+JxvfHGw4U K6og== X-Gm-Message-State: AOAM5324hFs+SPHM4q2CLyBpS9jqpRLl8Hhgtm9JNWLKOGg3PlsW+BwK 0K4Z0pOSaCCF7ZK1lEUH8Tc= X-Received: by 2002:aca:2411:: with SMTP id n17mr1539117oic.43.1607405508392; Mon, 07 Dec 2020 21:31:48 -0800 (PST) Received: from localhost ([184.21.204.5]) by smtp.gmail.com with ESMTPSA id k30sm2930191ool.34.2020.12.07.21.31.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Dec 2020 21:31:47 -0800 (PST) Date: Mon, 07 Dec 2020 21:31:40 -0800 From: John Fastabend To: Brendan Jackman , bpf@vger.kernel.org Cc: Alexei Starovoitov , Yonghong Song , Daniel Borkmann , KP Singh , Florent Revest , linux-kernel@vger.kernel.org, Jann Horn , Brendan Jackman Message-ID: <5fcf0fbcc8aa8_9ab320853@john-XPS-13-9370.notmuch> In-Reply-To: <20201207160734.2345502-7-jackmanb@google.com> References: <20201207160734.2345502-1-jackmanb@google.com> <20201207160734.2345502-7-jackmanb@google.com> Subject: RE: [PATCH bpf-next v4 06/11] bpf: Add BPF_FETCH field / create atomic_fetch_add instruction Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Brendan Jackman wrote: > The BPF_FETCH field can be set in bpf_insn.imm, for BPF_ATOMIC > instructions, in order to have the previous value of the > atomically-modified memory location loaded into the src register > after an atomic op is carried out. > > Suggested-by: Yonghong Song > Signed-off-by: Brendan Jackman > --- I like Yonghong suggestion #define BPF_ATOMIC_FETCH_ADD(SIZE, DST, SRC, OFF) \ BPF_ATOMIC(SIZE, DST, SRC, OFF, BPF_ADD | BPF_FETCH) otherwise LGTM. One observation to consider below. Acked-by: John Fastabend > arch/x86/net/bpf_jit_comp.c | 4 ++++ > include/linux/filter.h | 1 + > include/uapi/linux/bpf.h | 3 +++ > kernel/bpf/core.c | 13 +++++++++++++ > kernel/bpf/disasm.c | 7 +++++++ > kernel/bpf/verifier.c | 33 ++++++++++++++++++++++++--------- > tools/include/linux/filter.h | 11 +++++++++++ > tools/include/uapi/linux/bpf.h | 3 +++ > 8 files changed, 66 insertions(+), 9 deletions(-) [...] > @@ -3652,8 +3656,20 @@ static int check_atomic(struct bpf_verifier_env *env, int insn_idx, struct bpf_i > return err; > > /* check whether we can write into the same memory */ > - return check_mem_access(env, insn_idx, insn->dst_reg, insn->off, > - BPF_SIZE(insn->code), BPF_WRITE, -1, true); > + err = check_mem_access(env, insn_idx, insn->dst_reg, insn->off, > + BPF_SIZE(insn->code), BPF_WRITE, -1, true); > + if (err) > + return err; > + > + if (!(insn->imm & BPF_FETCH)) > + return 0; > + > + /* check and record load of old value into src reg */ > + err = check_reg_arg(env, insn->src_reg, DST_OP); This will mark the reg unknown. I think this is fine here. Might be nice to carry bounds through though if possible > + if (err) > + return err; > + > + return 0; > } >