Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp1715319imm; Wed, 6 Jun 2018 22:29:20 -0700 (PDT) X-Google-Smtp-Source: ADUXVKKkdzRU7zSx92Vyekj89EcS7zVCHFMKsbU3fo5CcJ+C4gcdvYXipI5a+sEh5329Va59g5IL X-Received: by 2002:a63:9e0a:: with SMTP id s10-v6mr376530pgd.305.1528349360658; Wed, 06 Jun 2018 22:29:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528349360; cv=none; d=google.com; s=arc-20160816; b=kofLG3dvLHJJTU29QaHqvBhnBs1g6EUIk+2BvxMqV5newkVcpdGkOoXa4eCoQfz3B2 e1YlFcX0eRZLmufLJGCS+MVuuDadq8DeQmA/gfboXueusFI7I2WbFg48h478SlXlHayR NoRMke6vcIONEPNg69sO77aiyGmoagrtsu+NF+d1YJC6vuhSrVTGRkf4ZE8GbKr8Gtfy blNok7R4R3A7YuoCFTB9kmcC4lxyjTtDplgediZC5Q2eTLJ4LIFF+HFld0YvT+RWZY3K 8TmII6Hs27eR472mLtNXnSlk7cZ8EI61IwpD4P+0WXU//+qMlgNhLLG5XfimzeSqoJ2r YHMg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :mime-version:dkim-signature:dkim-signature :arc-authentication-results; bh=MzMzcczTKjT2/kZVVWUx/XHpA6Y/zy5aKbprw7xiKb0=; b=lElPoYGn3LfrGZlzuQMH6DCB0lMU4zcxAQd1KXLufaNMyHqZlgpX1fHqNm0cVtzytG AqnVWLSwtpw6q1rzgGBJcHEOEsGThgS5TuuKEF7m5Jlu8uaEyEF/nVE6RxRVWVtEL4oj d2ziuQ39dBUdHDZT8katqoxUymIQsrqOf5Cgkb3yvbGJk2aIy5zXfX654jSpavMfpw1K kKfPAO3rGXx65giHTWtNjOmURw+mVwoHwHk708jSpZX5LHfNMiLyHHiC/8yJbj4rVSZU bRfTC55TtFCMD70quc6J34KAUcWZyQgwlVqFyRZMcdAiChouzjT5ZASFHU+HWA0db4kb 6LLg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@google.com header.s=20161025 header.b=O35DTM2R; dkim=fail header.i=@chromium.org header.s=google header.b=bEXNBlGA; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id az9-v6si10691457plb.454.2018.06.06.22.28.54; Wed, 06 Jun 2018 22:29:20 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@google.com header.s=20161025 header.b=O35DTM2R; dkim=fail header.i=@chromium.org header.s=google header.b=bEXNBlGA; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752729AbeFGFPH (ORCPT + 99 others); Thu, 7 Jun 2018 01:15:07 -0400 Received: from mail-ua0-f196.google.com ([209.85.217.196]:35694 "EHLO mail-ua0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752519AbeFGFPG (ORCPT ); Thu, 7 Jun 2018 01:15:06 -0400 Received: by mail-ua0-f196.google.com with SMTP id s13-v6so2191013uad.2 for ; Wed, 06 Jun 2018 22:15:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:sender:from:date:message-id:subject:to:cc; bh=MzMzcczTKjT2/kZVVWUx/XHpA6Y/zy5aKbprw7xiKb0=; b=O35DTM2Rh7k4Wp5Vuni1all9Bdfbr1fszbDyi5Q85bwkWvF86wJi2cvIn2jLo6d0ZB ZhOLth1+5mLpsnyvzuKjR97F4CJRP/CSCHQfGBEqjHUH7elbLMluuXmDvam0oJsQttn5 lqJ3wmM/IWLsFXddtBA1In7fyBSJbUbaBYIqIc6XGrFb1ak5cwGTeu46XB+7mZC7AiSF gywpeJyU4rgIWrS6fFbD72094P5NzKvmx79ewScSWbAR7zj9fQBd6Et9B1TNt9iIIVPu c7FgqIbmdewXkoIwO5ITHqhr1KO6YayvR0xaRs+JiGlXZlCXlRRZrYwywipgkTDDdxq8 Ak1Q== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=mime-version:sender:from:date:message-id:subject:to:cc; bh=MzMzcczTKjT2/kZVVWUx/XHpA6Y/zy5aKbprw7xiKb0=; b=bEXNBlGA3o+4InWOt5+ZsqmOtQPUG3xTlF1sw+aJHCfkgclKaTAm+I45yuUVd38Ep4 VuJu5LjnzRhFicM32TIC+8ahZ4NJssjAXshiv4V+PvtoES4HyvfwB6XpirdiLf1O3L9f a26Ugd38MUawsvdvJ9MvS7Ut5pfnUU046Hsw0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:sender:from:date:message-id:subject :to:cc; bh=MzMzcczTKjT2/kZVVWUx/XHpA6Y/zy5aKbprw7xiKb0=; b=Xn6foFQYhOGTfJmDeD3GaEQgo8bRDOWBgbOW5ynb5kgWPlJuGe9qSDDrG4GkTMFt2y Awyehs4C/y5BOcUGWISRhjiDQH8glvxIgv9bOrNM2FReYVNTZgUMdeci8r1j71lUD+mD T6Pf6I4qeORT0k1e6C/iwjambCA0phC3Z1R9UpaC96lg5+/DuglaumQgmANqoSjHwYyX PcZXHlnx4FY2ovqQc0OPHDVa8t4mJ3TE12ip3Y5N+Fr514J20WQjvWyOWAUSwk9Zr6Rp k8VoCOxpdTiLT+ZsC7Bc6MBuw9iBZAxvu+F0hPhgSDHiRDkMRFA5HmxZRqSxxbDll381 7sIg== X-Gm-Message-State: APt69E1oZI5wdru9Lv8DXaxOwxXphV51e171UUu2FutUqJP4sEwzhGgD dJbkFKgiYd9t/o3dIWXEwQBfzaeDQQh7oVDY1zv9dw== X-Received: by 2002:a9f:2823:: with SMTP id c32-v6mr236786uac.193.1528348505262; Wed, 06 Jun 2018 22:15:05 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a1f:a085:0:0:0:0:0 with HTTP; Wed, 6 Jun 2018 22:15:04 -0700 (PDT) From: Kees Cook Date: Wed, 6 Jun 2018 22:15:04 -0700 X-Google-Sender-Auth: EBeFnWxRLfqYDYKbVE4inOSFZeU Message-ID: Subject: Re: nfp: bpf: perf event output helpers support To: Jakub Kicinski , Quentin Monnet , Daniel Borkmann , Network Development Cc: LKML Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org > nfp: bpf: perf event output helpers support > > Add support for the perf_event_output family of helpers. > > The implementation on the NFP will not match the host code exactly. > The state of the host map and rings is unknown to the device, hence > device can't return errors when rings are not installed. The device > simply packs the data into a firmware notification message and sends > it over to the host, returning success to the program. > > There is no notion of a host CPU on the device when packets are being > processed. Device will only offload programs which set BPF_F_CURRENT_CPU. > Still, if map index doesn't match CPU no error will be returned (see > above). > > Dropped/lost firmware notification messages will not cause "lost > events" event on the perf ring, they are only visible via device > error counters. > > Firmware notification messages may also get reordered in respect > to the packets which caused their generation. > > Signed-off-by: Jakub Kicinski > Reviewed-by: Quentin Monnet > Signed-off-by: Daniel Borkmann > > diff --git a/drivers/net/ethernet/netronome/nfp/bpf/offload.c b/drivers/net/ethernet/netronome/nfp/bpf/offload.c > index e3ead906cc60..4db0ac1e42a8 100644 > --- a/drivers/net/ethernet/netronome/nfp/bpf/offload.c > +++ b/drivers/net/ethernet/netronome/nfp/bpf/offload.c > @@ -441,6 +441,53 @@ int nfp_ndo_bpf(struct nfp_app *app, struct nfp_net *nn, struct netdev_bpf *bpf) > } > } > > +static unsigned long > +nfp_bpf_perf_event_copy(void *dst, const void *src, > + unsigned long off, unsigned long len) > +{ > + memcpy(dst, src + off, len); > + return 0; > +} > + > +int nfp_bpf_event_output(struct nfp_app_bpf *bpf, struct sk_buff *skb) > +{ > + struct cmsg_bpf_event *cbe = (void *)skb->data; > + u32 pkt_size, data_size; > + struct bpf_map *map; > + > + if (skb->len < sizeof(struct cmsg_bpf_event)) > + goto err_drop; > + > + pkt_size = be32_to_cpu(cbe->pkt_size); > + data_size = be32_to_cpu(cbe->data_size); > + map = (void *)(unsigned long)be64_to_cpu(cbe->map_ptr); > + > + if (skb->len < sizeof(struct cmsg_bpf_event) + pkt_size + data_size) > + goto err_drop; > + if (cbe->hdr.ver != CMSG_MAP_ABI_VERSION) > + goto err_drop; > + > + rcu_read_lock(); > + if (!rhashtable_lookup_fast(&bpf->maps_neutral, &map, > + nfp_bpf_maps_neutral_params)) { > + rcu_read_unlock(); > + pr_warn("perf event: dest map pointer %px not recognized, dropping event\n", > + map); Please don't use %px on kernel pointers unless you absolutely have to[1]. It seems like this value wouldn't be actionable here, so likely it's best to just remove its use entirely. -Kees [1] https://www.spinics.net/lists/kernel/msg2671068.html -- Kees Cook Pixel Security