From patchwork Tue Aug 7 23:32:49 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Aring X-Patchwork-Id: 10559353 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 08CF113BB for ; Tue, 7 Aug 2018 23:33:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E0F0C2A3DE for ; Tue, 7 Aug 2018 23:33:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D44AD2A3E6; Tue, 7 Aug 2018 23:33:13 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 31AD62A3DE for ; Tue, 7 Aug 2018 23:33:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726110AbeHHBt6 (ORCPT ); Tue, 7 Aug 2018 21:49:58 -0400 Received: from mail-io0-f194.google.com ([209.85.223.194]:37106 "EHLO mail-io0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726078AbeHHBt6 (ORCPT ); Tue, 7 Aug 2018 21:49:58 -0400 Received: by mail-io0-f194.google.com with SMTP id z19-v6so335578ioh.4 for ; Tue, 07 Aug 2018 16:33:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mojatatu-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id; bh=/8sQNmlivuxZhzcmfUw+DcRmFK2csxp8QaF/Y2eKJ3U=; b=nKjyj8cJ2gb0dI8rvKn2FuzHhi+sKzdxdv1v+wLlEoZbXeIKRXNRS3b1l8n1c/PP1S dGgsUPLu35mkNW9nkpABFZeu/7JNGABBOGXdo+JSH/0pDOjRAGHOPsTImrZmbuBwKEhn CwyPPY3pUnH0eEGvUYOTeeFRwm2VOFm+iZgnjSPTP09wVpmHDGmZwhmbNqthU/v0lsix 9PrUNRZqmwvIPxE6Nck1MmiepgGF3q12Ce7ZVBlSkfG1EZ1L//8+u2sWJJBim8aSsqsb fPew+zu2F7YxPwRPDOY2Y3b51aX4TkrIeli5dyJgRnqKmASs+8U7chFpkGr7WNDwqkb8 7Qeg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=/8sQNmlivuxZhzcmfUw+DcRmFK2csxp8QaF/Y2eKJ3U=; b=YQBSVwd8FSYymGBYY+PetdH8OpzkpjFK8cYtvgzzTxj46iWUSf7fZMbWVkBn/1TWR/ 4uMm1YdVukab5DZHS9Z70+e1CvBRTaGHW7/ia+jD6YhnI7zGCycXQEbbCn7QzuxBXK03 bZVPQwGTfnPGOqtuMmzwQG6KWod3eYk7La+L1cqc8Io9TnenNknToyRg2rs4OUXpHhuw IjgarTqHmxcYVYxsGhCMMcCK2lEtW30WXh89PKIlHgOowXEeQ5hHMHnCfZ9BgtEEuDC6 6KFNgjcWZMH+u6tg9im7RS59lwcWOviM57g017aQ4nbx3Fxjnc5fL9iVZocRMSKr7zrt 1VSA== X-Gm-Message-State: AOUpUlEJM1kKvusqyY7DCGUeteoGyNY/WMG3QOj7CT14UtvSX2BTmE0U 357jz0pP8uBOR3WFSpcleW6g/6WIy/g= X-Google-Smtp-Source: AA+uWPz6ZRdIkyAOtVubdAUsS4lXMwEBl+OD+XIUuOULEdI0evgIKwHOlplRMBOsIdZ2ZT3I2A/XGQ== X-Received: by 2002:a6b:dd5:: with SMTP id 204-v6mr427376ion.172.1533684791396; Tue, 07 Aug 2018 16:33:11 -0700 (PDT) Received: from x220t.lan ([64.26.149.125]) by smtp.gmail.com with ESMTPSA id p130-v6sm1311911itd.22.2018.08.07.16.33.10 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 07 Aug 2018 16:33:10 -0700 (PDT) From: Alexander Aring To: netdev@vger.kernel.org Cc: linux-wpan@vger.kernel.org, kernel@mojatatu.com, Alexander Aring , Stefan Schmidt Subject: [PATCH net-next] ieee802154: hwsim: fix rcu handling Date: Tue, 7 Aug 2018 19:32:49 -0400 Message-Id: <20180807233249.28572-1-aring@mojatatu.com> X-Mailer: git-send-email 2.11.0 Sender: linux-wpan-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wpan@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This patch adds missing rcu_assign_pointer()/rcu_dereference() to used rcu pointers. There was already a previous commit c5d99d2b35da ("ieee802154: hwsim: fix rcu address annotation"), but there was more which was pointed out on my side by using newest sparse version. Cc: Stefan Schmidt Fixes: f25da51fdc38 ("ieee802154: hwsim: add replacement for fakelb") Signed-off-by: Alexander Aring Signed-off-by: Stefan Schmidt --- After I installed finally the newest sparse version I found more what kbuild was pointed out. I hope I did it right, not sure if I really need rcu functionality in these case because protection by mutex but I make sparse silent. At some places the resource isn't a shared resource at this moment. Anyway in my case I want to use this driver to create easily multi-hop scenarios, if somebody report things (or I hit it) which smells like some memory in this area - I will try and help to fix it. Newest sparse version from git is happy now and I hope kbuild bot as well. I tested this patch with RPOVE_RCU enabled and tried to update these settings while heavy loading in rcu protected xmit hotpath is occured, without any issues so far. Sorry again. drivers/net/ieee802154/mac802154_hwsim.c | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/drivers/net/ieee802154/mac802154_hwsim.c b/drivers/net/ieee802154/mac802154_hwsim.c index f4e92054f7df..53f39435321e 100644 --- a/drivers/net/ieee802154/mac802154_hwsim.c +++ b/drivers/net/ieee802154/mac802154_hwsim.c @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include @@ -110,7 +111,7 @@ static int hwsim_hw_channel(struct ieee802154_hw *hw, u8 page, u8 channel) pib->page = page; pib->channel = channel; - pib_old = phy->pib; + pib_old = rtnl_dereference(phy->pib); rcu_assign_pointer(phy->pib, pib); kfree_rcu(pib_old, rcu); return 0; @@ -406,7 +407,7 @@ static struct hwsim_edge *hwsim_alloc_edge(struct hwsim_phy *endpoint, u8 lqi) } einfo->lqi = 0xff; - e->info = einfo; + rcu_assign_pointer(e->info, einfo); e->endpoint = endpoint; return e; @@ -414,7 +415,13 @@ static struct hwsim_edge *hwsim_alloc_edge(struct hwsim_phy *endpoint, u8 lqi) static void hwsim_free_edge(struct hwsim_edge *e) { - kfree_rcu(e->info, rcu); + struct hwsim_edge_info *einfo; + + rcu_read_lock(); + einfo = rcu_dereference(e->info); + rcu_read_unlock(); + + kfree_rcu(einfo, rcu); kfree_rcu(e, rcu); } @@ -796,7 +803,7 @@ static int hwsim_add_one(struct genl_info *info, struct device *dev, goto err_pib; } - phy->pib = pib; + rcu_assign_pointer(phy->pib, pib); phy->idx = idx; INIT_LIST_HEAD(&phy->edges); @@ -829,10 +836,17 @@ static int hwsim_add_one(struct genl_info *info, struct device *dev, static void hwsim_del(struct hwsim_phy *phy) { + struct hwsim_pib *pib; + hwsim_edge_unsubscribe_me(phy); list_del(&phy->list); - kfree_rcu(phy->pib, rcu); + + rcu_read_lock(); + pib = rcu_dereference(phy->pib); + rcu_read_unlock(); + + kfree_rcu(pib, rcu); ieee802154_unregister_hw(phy->hw); ieee802154_free_hw(phy->hw);