Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp508211imm; Wed, 18 Jul 2018 06:08:41 -0700 (PDT) X-Google-Smtp-Source: AAOMgpdsu7Cslcqu5WB6BX4ayAyBhL3YLmnIfE1WK0AHV7BQT8aikJ7aDa9rVGyEtzQSDq+XbSJo X-Received: by 2002:a62:3601:: with SMTP id d1-v6mr5140668pfa.41.1531919321728; Wed, 18 Jul 2018 06:08:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531919321; cv=none; d=google.com; s=arc-20160816; b=N5+e6SEhUiNA8bn7TvhuBQlokL6VEGyBX2Ekw7jtpWOhFE1ziGULv8PCyT0R6wkC8g R9W9dzlRzxNYESI86czLhCS88XVPYsKCDH3K/G3bb26ONYquy63t3Clnbr7dbcd47ixv N+nk7AAehXqVZ7/yAJ88d3otAc3ziYgdPM+Zrr+wefmfp9R12BZUcVVo6JIwMQqZ2TQm wAWREj76hmk/0ptqNaZrWu2R9Rx2aUvXVccQmeF+K9WdBS/Pv66+oPtY4PyuLVYgMkaP f4LW/Q10vi7H9+TZwgwskb5hR7kmt5UQDaOaeRzRD/WvQCYiHYtOpdqF5rNTg1YUdeP5 IjgQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:arc-authentication-results; bh=kvWgtXL8vl80F46i1xZ8FbPIZHrG6pgJza/RzHvltlw=; b=UpfOFZffvp2KgmMCpI7EbjJugckbZcNiogUUsR23ZtmBvbuQ/DYlhBIHU89hvbnDjb 7qEznF960fn/TpHy0qW0S7Z7a3tN0yLnHLJQY7WlDypAg1619DvqydQFA1lunT7Q7p7+ iQk8HYg8xfV3HxD00NhyyFXW4JrclFdaKi6ZQi7aOkmPtuMQQ8VF/h+dkfIZDtme3k8N MpkJQczOiKbaLrXNfHCYhe22MrrwyOt0dHqr5irWleYCY8sR9sh8iVQGrG5lEfQhuRV2 Z+0JAP2bPF0K8kRBwBZ4AStL/AfUe1D6GQmgxLoCDDd0lhu7EMSXwFgBd4sr41+QStu+ pw9g== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q16-v6si3481627pfi.183.2018.07.18.06.08.26; Wed, 18 Jul 2018 06:08:41 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730245AbeGRNpn (ORCPT + 99 others); Wed, 18 Jul 2018 09:45:43 -0400 Received: from www62.your-server.de ([213.133.104.62]:48548 "EHLO www62.your-server.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726258AbeGRNpn (ORCPT ); Wed, 18 Jul 2018 09:45:43 -0400 Received: from [78.46.172.3] (helo=sslproxy06.your-server.de) by www62.your-server.de with esmtpsa (TLSv1.2:DHE-RSA-AES256-GCM-SHA384:256) (Exim 4.85_2) (envelope-from ) id 1ffmBJ-00069x-1X; Wed, 18 Jul 2018 15:07:49 +0200 Received: from [62.203.87.61] (helo=linux.home) by sslproxy06.your-server.de with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.89) (envelope-from ) id 1ffmBI-000AbC-Lu; Wed, 18 Jul 2018 15:07:48 +0200 Subject: Re: [PATCH v2 bpf 3/5] bpf: bpf_prog_array_free() should take a generic non-rcu pointer To: Roman Gushchin Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-team@fb.com, Alexei Starovoitov References: <20180713194114.2711-1-guro@fb.com> <20180713194114.2711-3-guro@fb.com> <41b5f919-3155-5bd4-2774-84efd58650e2@iogearbox.net> <20180716225715.GB3898@castle.DHCP.thefacebook.com> <1a40b0a8-7440-f2d2-d743-64901b5d1bfe@iogearbox.net> <20180717225520.GA15643@castle.DHCP.thefacebook.com> From: Daniel Borkmann Message-ID: <90bc1d99-da1b-065a-cd4f-457b7f17a533@iogearbox.net> Date: Wed, 18 Jul 2018 15:07:48 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.3.0 MIME-Version: 1.0 In-Reply-To: <20180717225520.GA15643@castle.DHCP.thefacebook.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Authenticated-Sender: daniel@iogearbox.net X-Virus-Scanned: Clear (ClamAV 0.100.0/24760/Tue Jul 17 06:40:15 2018) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 07/18/2018 12:55 AM, Roman Gushchin wrote: > On Wed, Jul 18, 2018 at 12:38:50AM +0200, Daniel Borkmann wrote: >> On 07/17/2018 12:57 AM, Roman Gushchin wrote: >>> On Tue, Jul 17, 2018 at 12:30:18AM +0200, Daniel Borkmann wrote: >>>> On 07/13/2018 09:41 PM, Roman Gushchin wrote: >>>>> bpf_prog_array_free() should take a generic non-rcu pointer >>>>> as an argument, as freeing the objects assumes that we're >>>>> holding an exclusive rights on it. >>>>> >>>>> rcu_access_pointer() can be used to convert a __rcu pointer to >>>>> a generic pointer before passing it to bpf_prog_array_free(), >>>>> if necessary. >>>>> >>>>> This patch eliminates the following sparse warning: >>>>> kernel/bpf/core.c:1556:9: warning: incorrect type in argument 1 (different address spaces) >>>>> kernel/bpf/core.c:1556:9: expected struct callback_head *head >>>>> kernel/bpf/core.c:1556:9: got struct callback_head [noderef] * >>>>> >>>>> Fixes: 324bda9e6c5a ("bpf: multi program support for cgroup+bpf") >>>>> Signed-off-by: Roman Gushchin >>>>> Cc: Alexei Starovoitov >>>>> Cc: Daniel Borkmann >>>>> --- >>>>> drivers/media/rc/bpf-lirc.c | 6 +++--- >>>>> include/linux/bpf.h | 2 +- >>>>> kernel/bpf/cgroup.c | 11 ++++++----- >>>>> kernel/bpf/core.c | 5 ++--- >>>>> kernel/trace/bpf_trace.c | 8 ++++---- >>>>> 5 files changed, 16 insertions(+), 16 deletions(-) >>>>> >>>>> diff --git a/drivers/media/rc/bpf-lirc.c b/drivers/media/rc/bpf-lirc.c >>>>> index fcfab6635f9c..509b262aa0dc 100644 >>>>> --- a/drivers/media/rc/bpf-lirc.c >>>>> +++ b/drivers/media/rc/bpf-lirc.c >>>>> @@ -135,7 +135,7 @@ static int lirc_bpf_attach(struct rc_dev *rcdev, struct bpf_prog *prog) >>>>> goto unlock; >>>>> >>>>> rcu_assign_pointer(raw->progs, new_array); >>>>> - bpf_prog_array_free(old_array); >>>>> + bpf_prog_array_free(rcu_access_pointer(old_array)); >>>> >>>> Taking this one as an example, why can't we already do the rcu_dereference() on the >>>> 'old_array = raw->progs' where we fetch the old_array initially? Then we also wouldn't >>>> need the rcu_access_pointer() on bpf_prog_array_free() and yet another rcu_dereference() >>>> inside the bpf_prog_array_copy() from your later patch? >>> >>> We can, but then we have to change bpf_prog_array_copy() args annotation, >>> and also all places, where it's called. >>> IMO, basically all local variables and function args marked as __rcu >>> should be not marked as RCU, but fixing them all is beyond this patchset. >> >> Right, agree, the __rcu markings seem somewhat arbitrary. :-( I think we need to >> investigate this a bit deeper and do a proper audit on the whole bpf prog array's >> RCU handling (probably won't get to it in next two weeks but put onto backlog just >> in case it's still unresolved till then). That said, given this has been there for >> quite a while and it's rc5 now, I think we could start out on bpf-next with the >> obvious candidates which should be okay even if it ends up bigger. > > Totally agree. > >> First two from this series we could already take in if you prefer. > > That would be nice! Ok, done, applied 1+2 to bpf-next, thanks Roman!