From patchwork Wed Jan 16 23:06:38 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Machata X-Patchwork-Id: 1026263 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=mellanox.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=Mellanox.com header.i=@Mellanox.com header.b="YwxIIok+"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 43g2s43cQ3z9sBQ for ; Thu, 17 Jan 2019 10:06:48 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388180AbfAPXGr (ORCPT ); Wed, 16 Jan 2019 18:06:47 -0500 Received: from mail-eopbgr00050.outbound.protection.outlook.com ([40.107.0.50]:53954 "EHLO EUR02-AM5-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1731049AbfAPXGq (ORCPT ); Wed, 16 Jan 2019 18:06:46 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Mellanox.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=1sYYXIzHIXkA8VfMurS7wMvuG92Ns5KL8tejZz9MygE=; b=YwxIIok+QGeq9Zi2ED4a42ec/CNZsPfXB0aSQh0rH1O8LtlScTocZiunIfsUhyZT+K8EuffS4gPtXlIunh2ikSsqigQsrN+FLXU9S/Pud59eo3I9ABpoVZWU2kt2NguXN/0s8lCefkV7o9KkXEBcNn3nxv+LOhkyKq53ZPROvc4= Received: from DB3PR0502MB3946.eurprd05.prod.outlook.com (52.134.71.23) by DB3PR0502MB4058.eurprd05.prod.outlook.com (52.134.68.149) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1537.26; Wed, 16 Jan 2019 23:06:38 +0000 Received: from DB3PR0502MB3946.eurprd05.prod.outlook.com ([fe80::14e8:d98f:3ec2:3981]) by DB3PR0502MB3946.eurprd05.prod.outlook.com ([fe80::14e8:d98f:3ec2:3981%2]) with mapi id 15.20.1516.019; Wed, 16 Jan 2019 23:06:38 +0000 From: Petr Machata To: "netdev@vger.kernel.org" CC: "ivecera@redhat.com" , Jiri Pirko , Ido Schimmel , "davem@davemloft.net" Subject: [PATCH net-next 04/13] vxlan: Allow vetoing of FDB notifications Thread-Topic: [PATCH net-next 04/13] vxlan: Allow vetoing of FDB notifications Thread-Index: AQHUrfAiRRsR8zjWjUKrmI0WFDw2KQ== Date: Wed, 16 Jan 2019 23:06:38 +0000 Message-ID: <64781263f79d3669af32233ff9e190bc88516cb2.1547679599.git.petrm@mellanox.com> References: In-Reply-To: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: AM6PR03CA0035.eurprd03.prod.outlook.com (2603:10a6:20b::48) To DB3PR0502MB3946.eurprd05.prod.outlook.com (2603:10a6:8:e::23) authentication-results: spf=none (sender IP is ) smtp.mailfrom=petrm@mellanox.com; x-ms-exchange-messagesentrepresentingtype: 1 x-originating-ip: [78.45.160.211] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; DB3PR0502MB4058; 6:wtVem69NU/+SSojRvhbYYs1Xwlrp+nYKwcMupO1QS3Vryk59qIr0z7dCBWcIhBXbiJejKasgIJ9DzYcUcNe9d8uylBMdFjyCtTPoM7eayPdon0cnpJCYjtrs7F7qg9xf0oucf3PD9fHNYOFN2Mq7rRACwjK7ChaIwnLyyX0wn73qgtJGKeveQ8gmgXpSZ5rrBhzI48I7zjJ5JLHoUHaUK2PuFFY2m9Uh0Xxc/MAyV9nX+mLvVEr0wj3/maoRgjAJJIFXdE+RjK4IvIb5cU3E17UG37pJwtB3iHForrcjKoxsih5+LRiAIWDXFA/icgGb+nCDxYb0ndwa5g4yaWH9YqR3hWQdcnwXw5HuER9b6Nrte3t0+iDANJ07ipPrhazL6w24mGgx96eJqGcFHNztSkTiznTdb/oGd2wU12OcPxCE0zgqKG6g48jOt9du6RB1dTsKLMWxiRXXKCVqynXwJA==; 5:0pkSOJ7r4zijeJN/ZAJow6VGyMY50FnQ373JpnjVo/pOqdt3SBSXoyn1CVaoCwTC0sDk7Uam4lGcw09gFbrGmJdG9+TuMQ4jqO0BAoR47KlJepfeNfVzz9qP8T+FXruXjbsZL3TysycrUwRMVmNOW4pByIT0PoW6grEHPPec+xtu02DIMVyq6zmu8I5CfjqqyliYJpFN9EmmfCz3gQPhuA==; 7:3vuh616MDg0vfTp7ZegPDfl3SlQIT/mut04uqZw3hqnuIFoi4pjLyqZs293F5dmxMIx2StkrZofeQsuX6geHUmrVGlHvZrIo+41qxKY9x0u3+3nhvecQaKtGyKohBGe2I8GaMsHuUR+JrjuVXwPHmg== x-ms-office365-filtering-correlation-id: 6642efde-6745-48d3-55df-08d67c07438e x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600109)(711020)(4618075)(2017052603328)(7153060)(7193020); SRVR:DB3PR0502MB4058; x-ms-traffictypediagnostic: DB3PR0502MB4058: x-microsoft-antispam-prvs: x-forefront-prvs: 091949432C x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(39860400002)(136003)(366004)(396003)(376002)(346002)(189003)(199004)(71200400001)(106356001)(71190400001)(105586002)(118296001)(81166006)(2351001)(1730700003)(7736002)(14444005)(256004)(5660300001)(6436002)(8936002)(305945005)(6916009)(478600001)(14454004)(5640700003)(81156014)(8676002)(53936002)(68736007)(36756003)(6512007)(99286004)(186003)(52116002)(6506007)(6116002)(3846002)(486006)(76176011)(66066001)(2906002)(6486002)(25786009)(26005)(54906003)(446003)(316002)(476003)(2616005)(11346002)(386003)(97736004)(4326008)(2501003)(86362001)(102836004); DIR:OUT; SFP:1101; SCL:1; SRVR:DB3PR0502MB4058; H:DB3PR0502MB3946.eurprd05.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; received-spf: None (protection.outlook.com: mellanox.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: RFtIpeu+3UAULl5UymGmifqG9XKNt6b5ojCl9G1tmzIZIZ5ZG8NOgpQ0ovLDjPpCcJP6ta3RHybykN1KG3spSznucQnt8U1J3AZR3uJE1BSN/EMiKvGHgZYpu0Ifrc9UcHQ7FxNN8IFV184rz+aVFN6l+ZojWyp4wCYr69nc36lbNqkM96LhyOxEY4xXUjrBvaVkW6m+P9r9vfxaMM99bwB8PlAjzOPUeAYuioTnqmp9S2rQrfe7fxvb4shm/NMMZUCrNuxSk/fW1+0UYJGJEQQWywueeWUuLVuhp+wKnvYUgmPlxS+1cV+IA0Wqd2sj9MV0QGM0uQTbbfAc2TBI0nrT10UuMIOKylqf2L5nJZ249SrwnTByVoMgz4DE53XIIIsipVQQCwonnsLsoI11Pc+i8W3QnEKFssR7mADKLQg= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: Mellanox.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6642efde-6745-48d3-55df-08d67c07438e X-MS-Exchange-CrossTenant-originalarrivaltime: 16 Jan 2019 23:06:35.6078 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: a652971c-7d2e-4d9b-a6a4-d149256f461b X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB3PR0502MB4058 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Change vxlan_fdb_switchdev_call_notifiers() to return the result from calling switchdev notifiers. Propagate the error number up the stack. In vxlan_fdb_update_existing() and vxlan_fdb_update_create() add rollbacks to clean up the work that was done before the veto. Signed-off-by: Petr Machata --- drivers/net/vxlan.c | 64 ++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 46 insertions(+), 18 deletions(-) diff --git a/drivers/net/vxlan.c b/drivers/net/vxlan.c index 1c8d8c8e0961..92904ee16053 100644 --- a/drivers/net/vxlan.c +++ b/drivers/net/vxlan.c @@ -375,32 +375,38 @@ static void vxlan_fdb_switchdev_notifier_info(const struct vxlan_dev *vxlan, fdb_info->added_by_user = fdb->flags & NTF_VXLAN_ADDED_BY_USER; } -static void vxlan_fdb_switchdev_call_notifiers(struct vxlan_dev *vxlan, - struct vxlan_fdb *fdb, - struct vxlan_rdst *rd, - bool adding) +static int vxlan_fdb_switchdev_call_notifiers(struct vxlan_dev *vxlan, + struct vxlan_fdb *fdb, + struct vxlan_rdst *rd, + bool adding) { struct switchdev_notifier_vxlan_fdb_info info; enum switchdev_notifier_type notifier_type; + int ret; if (WARN_ON(!rd)) - return; + return 0; notifier_type = adding ? SWITCHDEV_VXLAN_FDB_ADD_TO_DEVICE : SWITCHDEV_VXLAN_FDB_DEL_TO_DEVICE; vxlan_fdb_switchdev_notifier_info(vxlan, fdb, rd, &info); - call_switchdev_notifiers(notifier_type, vxlan->dev, - &info.info); + ret = call_switchdev_notifiers(notifier_type, vxlan->dev, + &info.info); + return notifier_to_errno(ret); } -static void vxlan_fdb_notify(struct vxlan_dev *vxlan, struct vxlan_fdb *fdb, - struct vxlan_rdst *rd, int type, bool swdev_notify) +static int vxlan_fdb_notify(struct vxlan_dev *vxlan, struct vxlan_fdb *fdb, + struct vxlan_rdst *rd, int type, bool swdev_notify) { + int err; + if (swdev_notify) { switch (type) { case RTM_NEWNEIGH: - vxlan_fdb_switchdev_call_notifiers(vxlan, fdb, rd, - true); + err = vxlan_fdb_switchdev_call_notifiers(vxlan, fdb, rd, + true); + if (err) + return err; break; case RTM_DELNEIGH: vxlan_fdb_switchdev_call_notifiers(vxlan, fdb, rd, @@ -410,6 +416,7 @@ static void vxlan_fdb_notify(struct vxlan_dev *vxlan, struct vxlan_fdb *fdb, } __vxlan_fdb_notify(vxlan, fdb, rd, type); + return 0; } static void vxlan_ip_miss(struct net_device *dev, union vxlan_addr *ipa) @@ -868,7 +875,8 @@ static int vxlan_fdb_update_existing(struct vxlan_dev *vxlan, struct vxlan_rdst *rd = NULL; struct vxlan_rdst oldrd; int notify = 0; - int rc; + int rc = 0; + int err; /* Do not allow an externally learned entry to take over an entry added * by the user. @@ -915,10 +923,20 @@ static int vxlan_fdb_update_existing(struct vxlan_dev *vxlan, if (rd == NULL) rd = first_remote_rtnl(f); - vxlan_fdb_notify(vxlan, f, rd, RTM_NEWNEIGH, swdev_notify); + err = vxlan_fdb_notify(vxlan, f, rd, RTM_NEWNEIGH, + swdev_notify); + if (err) + goto err_notify; } return 0; + +err_notify: + if ((flags & NLM_F_REPLACE) && rc) + *rd = oldrd; + else if ((flags & NLM_F_APPEND) && rc) + list_del_rcu(&rd->list); + return err; } static int vxlan_fdb_update_create(struct vxlan_dev *vxlan, @@ -943,9 +961,16 @@ static int vxlan_fdb_update_create(struct vxlan_dev *vxlan, if (rc < 0) return rc; - vxlan_fdb_notify(vxlan, f, first_remote_rtnl(f), RTM_NEWNEIGH, - swdev_notify); + rc = vxlan_fdb_notify(vxlan, f, first_remote_rtnl(f), RTM_NEWNEIGH, + swdev_notify); + if (rc) + goto err_notify; + return 0; + +err_notify: + vxlan_fdb_destroy(vxlan, f, false, false); + return rc; } /* Add new entry to forwarding table -- assumes lock held */ @@ -3515,9 +3540,12 @@ static int __vxlan_dev_create(struct net *net, struct net_device *dev, goto errout; /* notify default fdb entry */ - if (f) - vxlan_fdb_notify(vxlan, f, first_remote_rtnl(f), RTM_NEWNEIGH, - true); + if (f) { + err = vxlan_fdb_notify(vxlan, f, first_remote_rtnl(f), + RTM_NEWNEIGH, true); + if (err) + goto errout; + } list_add(&vxlan->next, &vn->vxlan_list); return 0;